From 6cb77465ab73f272214aaae5a60ffda4a6ef4239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Wed, 13 Jun 2018 16:39:43 +0100 Subject: [PATCH 001/225] elan: Add USB ID for TNP Nano USB Fingerprint Reader (04f3:0c26) The device works without any additional changes to the driver. https://www.amazon.co.uk/gp/product/B075955HY7/ --- libfprint/drivers/elan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 0ff16dcd..cef54395 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -603,6 +603,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static const struct usb_id id_table[] = { {.vendor = 0x04f3,.product = 0x0907}, + {.vendor = 0x04f3,.product = 0x0c26}, {0, 0, 0,}, }; From ff77cfc9b5f692026892229c265f6c16b5c23ea7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 18 Jun 2018 12:44:39 +0200 Subject: [PATCH 002/225] doc: Update more website links --- doc/libfprint-docs.xml | 2 +- doc/xml/meson.build | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index fd674ec4..e56f4b77 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -11,7 +11,7 @@ This document is the API reference for the libfprint library. The latest version of libfprint, as well as the latest version of - this API reference, is available online. + this API reference, is available online. diff --git a/doc/xml/meson.build b/doc/xml/meson.build index ea3ddf59..e35f7eeb 100644 --- a/doc/xml/meson.build +++ b/doc/xml/meson.build @@ -1,10 +1,10 @@ ent_conf = configuration_data() ent_conf.set('PACKAGE', 'libfprint') -ent_conf.set('PACKAGE_BUGREPORT', 'https://bugs.freedesktop.org/enter_bug.cgi?product=libfprint') +ent_conf.set('PACKAGE_BUGREPORT', 'https://gitlab.freedesktop.org/libfprint/libfprint/issues') ent_conf.set('PACKAGE_NAME', 'libfprint') ent_conf.set('PACKAGE_STRING', 'libfprint') ent_conf.set('PACKAGE_TARNAME', 'libfprint-' + meson.project_version()) -ent_conf.set('PACKAGE_URL', 'https://www.freedesktop.org/wiki/Software/fprint/libfprint/') +ent_conf.set('PACKAGE_URL', 'https://fprint.freedesktop.org/') ent_conf.set('PACKAGE_VERSION', meson.project_version()) ent_conf.set('PACKAGE_API_VERSION', '1.0') configure_file(input: 'gtkdocentities.ent.in', output: 'gtkdocentities.ent', configuration: ent_conf) From bb4d88866172f403ce6dfa44afdf755de9477da8 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 14 Jun 2018 10:37:21 +0200 Subject: [PATCH 003/225] elan: Fix typo in comment --- libfprint/drivers/elan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index cef54395..dff75a6d 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -102,7 +102,7 @@ static void elan_save_frame(struct fp_img_dev *dev) elandev->num_frames += 1; } -/* Transform raw sesnsor data to normalized 8-bit grayscale image. */ +/* Transform raw sensor data to normalized 8-bit grayscale image. */ static void elan_process_frame(unsigned short *raw_frame, GSList ** frames) { unsigned int frame_size = From c284858d06300d027f17997353ec260bcc59a320 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 19 Jun 2018 11:11:04 +0200 Subject: [PATCH 004/225] upekts: Fix enrollment never finishing on some upekts devices Add support for more device status codes, brought back from the now-removed UPEKE2 driver. See https://gitlab.freedesktop.org/libfprint/libfprint/blob/3bf55a3e0766ca90f5befc1ed161b1c83005a962/libfprint/drivers/upeke2.c#L1013 --- libfprint/drivers/upekts.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index a2bf971a..b448e364 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -1018,6 +1018,9 @@ static void e_handle_resp00(struct fp_dev *dev, unsigned char *data, case 0x0c: case 0x0d: case 0x0e: + case 0x26: + case 0x27: + case 0x2e: /* if we previously completed a non-last enrollment stage, we'll * get this code to indicate successful stage completion */ if (upekdev->enroll_passed) { From 056ea541ddc97f5806cffbd99a12dc87e4da3546 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 26 Jun 2018 14:52:26 +0200 Subject: [PATCH 005/225] poll: Fix fp_get_pollfds retval type fp_get_pollfds() is supposed to return a negative value on failure, but size_t is an unsigned integer. Use ssize_t instead. --- libfprint/fprint.h | 2 +- libfprint/poll.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libfprint/fprint.h b/libfprint/fprint.h index c927690b..be94a540 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -314,7 +314,7 @@ struct fp_pollfd { int fp_handle_events_timeout(struct timeval *timeout); int fp_handle_events(void); -size_t fp_get_pollfds(struct fp_pollfd **pollfds); +ssize_t fp_get_pollfds(struct fp_pollfd **pollfds); int fp_get_next_timeout(struct timeval *tv); /** diff --git a/libfprint/poll.c b/libfprint/poll.c index 8a007bc9..615ba40f 100644 --- a/libfprint/poll.c +++ b/libfprint/poll.c @@ -313,12 +313,12 @@ API_EXPORTED int fp_get_next_timeout(struct timeval *tv) * * Returns: the number of pollfds in the resultant list, or negative on error. */ -API_EXPORTED size_t fp_get_pollfds(struct fp_pollfd **pollfds) +API_EXPORTED ssize_t fp_get_pollfds(struct fp_pollfd **pollfds) { const struct libusb_pollfd **usbfds; const struct libusb_pollfd *usbfd; struct fp_pollfd *ret; - size_t cnt = 0; + ssize_t cnt = 0; size_t i = 0; usbfds = libusb_get_pollfds(fpi_usb_ctx); From b1ac865abdc017bb824aab452da37e026d3a9a4c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 3 Jul 2018 11:37:20 +0200 Subject: [PATCH 006/225] lib: Downgrade BUG* assertions to work-around crashes BUG() and BUG_ON() didn't use to assert, but only print an error if debugging was enabled. This was hiding a lot of state bugs in drivers, and transforming those into assertions causes crashes. Downgrade the assertion to only print a warning, and hope that those eventually get fixed in the drivers so we can re-enable them. Closes: #77 --- libfprint/fp_internal.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index b4d43e15..3611f76f 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -44,8 +44,14 @@ #define fp_warn g_warning #define fp_err g_error -#define BUG_ON(condition) g_assert(!(condition)) -#define BUG() g_assert_not_reached() +#define BUG_ON(condition) G_STMT_START \ + if (condition) { \ + char *s; \ + s = g_strconcat ("BUG: (", #condition, ")", NULL); \ + g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ + g_free (s); \ + } G_STMT_END +#define BUG() BUG_ON(1) enum fp_dev_state { DEV_STATE_INITIAL = 0, From 29d3541b7414b8b87c114d3af6de0a544e9954a3 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 16 Jul 2018 16:07:25 +0200 Subject: [PATCH 007/225] lib: Downgrade BUG* assertions to work-around crashes #2 Same as b1ac865abdc017bb824aab452da37e026d3a9a4c but for the drivers API. --- libfprint/drivers_api.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 2bf547a1..5eb844c4 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -42,8 +42,14 @@ #define fp_warn g_warning #define fp_err g_error -#define BUG_ON(condition) g_assert(!(condition)) -#define BUG() g_assert_not_reached() +#define BUG_ON(condition) G_STMT_START \ + if (condition) { \ + char *s; \ + s = g_strconcat ("BUG: (", #condition, ")", NULL); \ + g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ + g_free (s); \ + } G_STMT_END +#define BUG() BUG_ON(1) enum fp_dev_state { DEV_STATE_INITIAL = 0, From 19e7b217c1c460d0bf2bb1e722d49174e608f4de Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 16 Jul 2018 16:08:12 +0200 Subject: [PATCH 008/225] lib: Downgrade fp_err() to be non-fatal Similarly to b1ac865abdc017bb824aab452da37e026d3a9a4c, downgrade fp_err() to be non-fatal. A number of drivers would spit out an error when encountering this call, but not crash, carry on and most of the time recover. Make sure we don't assert in those cases. --- libfprint/drivers_api.h | 2 +- libfprint/fp_internal.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 5eb844c4..2679c778 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -40,7 +40,7 @@ #define fp_dbg g_debug #define fp_info g_debug #define fp_warn g_warning -#define fp_err g_error +#define fp_err g_warning #define BUG_ON(condition) G_STMT_START \ if (condition) { \ diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 3611f76f..e7501824 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -42,7 +42,7 @@ #define fp_dbg g_debug #define fp_info g_debug #define fp_warn g_warning -#define fp_err g_error +#define fp_err g_warning #define BUG_ON(condition) G_STMT_START \ if (condition) { \ From 22277c727723579a0c63abda17171acec05101c9 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 17 Jul 2018 13:24:35 +0200 Subject: [PATCH 009/225] build: Downgrade meson in CI script It failed to finish the build otherwise: https://github.com/mesonbuild/meson/issues/3892 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 05e83068..91bc1a94 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ variables: before_script: - - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES + - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES && rpm -Uvh --oldpackage https://kojipkgs.fedoraproject.org//packages/meson/0.46.1/2.fc29/noarch/meson-0.46.1-2.fc29.noarch.rpm build: From da95af0f48a247300457ecfe6be59e8284ce9df3 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 16 Jul 2018 16:15:21 +0200 Subject: [PATCH 010/225] 0.8.2 --- NEWS | 11 +++++++++++ meson.build | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 9291089b..91351eea 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,17 @@ This file lists notable changes in each release. For the full history of all changes, see ChangeLog. +2018-07-15: v0.8.2 release +* Drivers: + - Add USB ID for TNP Nano USB Fingerprint Reader + - Fix UPEKTS enrollment never finishing on some devices + +* Library: + - Fix fp_get_pollfds() retval type, a small ABI change + - Downgrade fatal errors to run-time warnings, as a number of drivers + used to throw silent errors and we made them fatal. Those will now + be visible warnings, hopefully helping with fixing them. + 2018-06-12: v0.8.1 release - Brown paperbag release to install the udev rules file in the correct directory if the udev pkg-config file doesn't have a trailing slash diff --git a/meson.build b/meson.build index 088bd112..c5c691d4 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('libfprint', [ 'c', 'cpp' ], - version: '0.8.1', + version: '0.8.2', license: 'LGPLv2.1+', default_options: [ 'buildtype=debugoptimized', From 626b0f1a8fbf2e3acf8f3d2de411141bc3f6e913 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 17 Jul 2018 16:02:26 +0200 Subject: [PATCH 011/225] lib: Include more standard headers for drivers to use Such as string.h and stdlib.h, to be able to compile on older toolchains like that of Fedora 27. --- libfprint/drivers_api.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 2679c778..cc844cd7 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -30,6 +30,8 @@ #include #include +#include +#include #include #include From c9abbec48a2c1db5a88a9fb60fc350514af3dcf2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 20 Jul 2018 12:22:50 +0200 Subject: [PATCH 012/225] build: Fix build with newer meson The gtk-doc meson helper regressed in that it didn't expect the libfprint.types file to not exist, as earlier versions did. Remove the --rebuild-types call so that it is not generated, and meson carries on compiling the rest of the library. See https://gitlab.gnome.org/GNOME/gtk-doc/issues/48 See https://github.com/mesonbuild/meson/issues/3892 See https://bugzilla.redhat.com/show_bug.cgi?id=1604585 --- .gitlab-ci.yml | 2 +- doc/meson.build | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 91bc1a94..05e83068 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ variables: before_script: - - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES && rpm -Uvh --oldpackage https://kojipkgs.fedoraproject.org//packages/meson/0.46.1/2.fc29/noarch/meson-0.46.1-2.fc29.noarch.rpm + - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES build: diff --git a/doc/meson.build b/doc/meson.build index 48358c8e..c2c1b772 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -54,7 +54,6 @@ gnome.gtkdoc('libfprint', content_files: content_files, expand_content_files: expand_content_files, scan_args: [ - '--rebuild-types', '--ignore-decorators=API_EXPORTED', '--ignore-headers=' + ' '.join(private_headers), ], From bccff4ffef07821355639bd2e2c2da1baca57749 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Tue, 16 Jan 2018 18:04:31 +0200 Subject: [PATCH 013/225] elan: Change command structs, support more devices Make each command a separate struct to get finer control over which commands are called on which devices. Update ssm's accordingly. Add sensor_reset and fuse_load commands. Support 0x0903, 0x0c03, 0x0c16, 0x0c1a, 0x0c26 --- libfprint/drivers/elan.c | 391 +++++++++++++++++++++++++++------------ libfprint/drivers/elan.h | 190 +++++++++---------- 2 files changed, 368 insertions(+), 213 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index dff75a6d..3a2a0b04 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -2,6 +2,7 @@ * Elan driver for libfprint * * Copyright (C) 2017 Igor Filatov + * Copyright (C) 2018 Sébastien Béchet * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,20 +39,29 @@ static struct fpi_frame_asmbl_ctx assembling_ctx = { }; struct elan_dev { - gboolean deactivating; + /* device config */ + unsigned short dev_type; + /* number of pixels to discard on left and right (along raw image height) + * because they have different intensity from the rest of the frame */ + unsigned char frame_margin; + /* end device config */ - const struct elan_cmd *cmds; - size_t cmds_len; - int cmd_idx; + /* commands */ + const struct elan_cmd *cmd; int cmd_timeout; struct libusb_transfer *cur_transfer; + /* end commands */ + /* state */ + gboolean deactivating; + unsigned char calib_atts_left; unsigned char *last_read; unsigned char frame_width; unsigned char frame_height; unsigned char raw_frame_width; int num_frames; GSList *frames; + /* end state */ }; static void elan_dev_reset(struct elan_dev *elandev) @@ -62,8 +72,7 @@ static void elan_dev_reset(struct elan_dev *elandev) elandev->deactivating = FALSE; - elandev->cmds = NULL; - elandev->cmd_idx = 0; + elandev->cmd = NULL; elandev->cmd_timeout = ELAN_CMD_TIMEOUT; g_free(elandev->last_read); @@ -86,13 +95,13 @@ static void elan_save_frame(struct fp_img_dev *dev) /* Raw images are vertical and perpendicular to swipe direction of a * normalized image, which means we need to make them horizontal before - * assembling. We also discard stirpes of ELAN_FRAME_MARGIN along raw + * assembling. We also discard stripes of 'frame_margin' along raw * height. */ for (int y = 0; y < raw_height; y++) - for (int x = ELAN_FRAME_MARGIN; - x < raw_width - ELAN_FRAME_MARGIN; x++) { + for (int x = elandev->frame_margin; + x < raw_width - elandev->frame_margin; x++) { int frame_idx = - y + (x - ELAN_FRAME_MARGIN) * raw_height; + y + (x - elandev->frame_margin) * raw_height; int raw_idx = x + y * raw_width; frame[frame_idx] = ((unsigned short *)elandev->last_read)[raw_idx]; @@ -161,16 +170,8 @@ static void elan_submit_image(struct fp_img_dev *dev) static void elan_cmd_done(struct fpi_ssm *ssm) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); - G_DEBUG_HERE(); - - elandev->cmd_idx += 1; - if (elandev->cmd_idx < elandev->cmds_len) - elan_run_next_cmd(ssm); - else - fpi_ssm_next_state(ssm); + fpi_ssm_next_state(ssm); } static void elan_cmd_cb(struct libusb_transfer *transfer) @@ -186,19 +187,16 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) switch (transfer->status) { case LIBUSB_TRANSFER_COMPLETED: if (transfer->length != transfer->actual_length) { - fp_dbg("unexpected transfer length"); + fp_dbg("transfer length error: expected %d, got %d", + transfer->length, transfer->actual_length); elan_dev_reset(elandev); fpi_ssm_mark_aborted(ssm, -EPROTO); } else if (transfer->endpoint & LIBUSB_ENDPOINT_IN) /* just finished receiving */ elan_cmd_done(ssm); - else { + else /* just finished sending */ - if (elandev->cmds[elandev->cmd_idx].response_len) - elan_cmd_read(ssm); - else - elan_cmd_done(ssm); - } + elan_cmd_read(ssm); break; case LIBUSB_TRANSFER_CANCELLED: fp_dbg("transfer cancelled"); @@ -206,7 +204,6 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) break; case LIBUSB_TRANSFER_TIMED_OUT: fp_dbg("transfer timed out"); - // elan_dev_reset(elandev); fpi_ssm_mark_aborted(ssm, -ETIMEDOUT); break; default: @@ -220,11 +217,17 @@ static void elan_cmd_read(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); - int response_len = elandev->cmds[elandev->cmd_idx].response_len; + int response_len = elandev->cmd->response_len; G_DEBUG_HERE(); - if (elandev->cmds[elandev->cmd_idx].cmd == read_cmds[0].cmd) + if (!(elandev->cmd->response_len)) { + fp_dbg("skipping read, not expecting anything"); + elan_cmd_done(ssm); + return; + } + + if (elandev->cmd->cmd == get_image_cmd.cmd) /* raw data has 2-byte "pixels" and the frame is vertical */ response_len = elandev->raw_frame_width * elandev->frame_width * 2; @@ -240,7 +243,7 @@ static void elan_cmd_read(struct fpi_ssm *ssm) elandev->last_read = g_malloc(response_len); libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), - elandev->cmds[elandev->cmd_idx].response_in, + elandev->cmd->response_in, elandev->last_read, response_len, elan_cmd_cb, ssm, elandev->cmd_timeout); transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; @@ -249,12 +252,21 @@ static void elan_cmd_read(struct fpi_ssm *ssm) fpi_ssm_mark_aborted(ssm, r); } -static void elan_run_next_cmd(struct fpi_ssm *ssm) +static void elan_run_cmd(struct fpi_ssm *ssm, const struct elan_cmd *cmd, + int cmd_timeout) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); - G_DEBUG_HERE(); + elandev->cmd = cmd; + if (cmd_timeout != -1) + elandev->cmd_timeout = cmd_timeout; + + if (!(cmd->devices & elandev->dev_type)) { + fp_dbg("skipping for this device"); + elan_cmd_done(ssm); + return; + } struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { @@ -264,31 +276,12 @@ static void elan_run_next_cmd(struct fpi_ssm *ssm) elandev->cur_transfer = transfer; libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), ELAN_EP_CMD_OUT, - (unsigned char *)elandev->cmds[elandev-> - cmd_idx].cmd, - ELAN_CMD_LEN, elan_cmd_cb, ssm, + (char *) cmd->cmd, ELAN_CMD_LEN, elan_cmd_cb, ssm, elandev->cmd_timeout); transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; int r = libusb_submit_transfer(transfer); if (r < 0) fpi_ssm_mark_aborted(ssm, r); - -} - -static void elan_run_cmds(struct fpi_ssm *ssm, const struct elan_cmd *cmds, - size_t cmds_len, int cmd_timeout) -{ - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); - - G_DEBUG_HERE(); - - elandev->cmds = cmds; - elandev->cmds_len = cmds_len; - elandev->cmd_idx = 0; - if (cmd_timeout != -1) - elandev->cmd_timeout = cmd_timeout; - elan_run_next_cmd(ssm); } enum deactivate_states { @@ -296,12 +289,13 @@ enum deactivate_states { DEACTIVATE_NUM_STATES, }; -static void elan_deactivate_run_state(struct fpi_ssm *ssm) +static void deactivate_run_state(struct fpi_ssm *ssm) { + G_DEBUG_HERE(); + switch (fpi_ssm_get_cur_state(ssm)) { case DEACTIVATE: - elan_run_cmds(ssm, deactivate_cmds, deactivate_cmds_len, - ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, &stop_cmd, ELAN_CMD_TIMEOUT); break; } } @@ -310,6 +304,8 @@ static void deactivate_complete(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + G_DEBUG_HERE(); + fpi_imgdev_deactivate_complete(dev); } @@ -321,50 +317,49 @@ static void elan_deactivate(struct fp_img_dev *dev) elan_dev_reset(elandev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), elan_deactivate_run_state, + struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), deactivate_run_state, DEACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, deactivate_complete); } enum capture_states { - CAPTURE_START, + CAPTURE_LED_ON, CAPTURE_WAIT_FINGER, CAPTURE_READ_DATA, - CAPTURE_SAVE_FRAME, + CAPTURE_CHECK_ENOUGH_FRAMES, CAPTURE_NUM_STATES, }; -static void elan_capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); switch (fpi_ssm_get_cur_state(ssm)) { - case CAPTURE_START: - elan_run_cmds(ssm, capture_start_cmds, capture_start_cmds_len, - ELAN_CMD_TIMEOUT); + case CAPTURE_LED_ON: + elan_run_cmd(ssm, &led_on_cmd, ELAN_CMD_TIMEOUT); break; case CAPTURE_WAIT_FINGER: - elan_run_cmds(ssm, capture_wait_finger_cmds, - capture_wait_finger_cmds_len, -1); + elan_run_cmd(ssm, &pre_scan_cmd, -1); break; case CAPTURE_READ_DATA: /* 0x55 - finger present - * 0xff - device not calibrated */ + * 0xff - device not calibrated (probably) */ if (elandev->last_read && elandev->last_read[0] == 0x55) { fpi_imgdev_report_finger_status(dev, TRUE); - elan_run_cmds(ssm, read_cmds, read_cmds_len, - ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); } else fpi_ssm_mark_aborted(ssm, FP_VERIFY_RETRY); break; - case CAPTURE_SAVE_FRAME: + case CAPTURE_CHECK_ENOUGH_FRAMES: elan_save_frame(dev); if (elandev->num_frames < ELAN_MAX_FRAMES) { /* quickly stop if finger is removed */ elandev->cmd_timeout = ELAN_FINGER_TIMEOUT; fpi_ssm_jump_to_state(ssm, CAPTURE_WAIT_FINGER); + } else { + fpi_ssm_next_state(ssm); } break; } @@ -392,9 +387,12 @@ static void capture_complete(struct fpi_ssm *ssm) if (elandev->num_frames >= ELAN_MIN_FRAMES) { elan_submit_image(dev); fpi_imgdev_report_finger_status(dev, FALSE); - } else + } else { + fp_dbg("swipe too short: want >= %d frames, got %d", + ELAN_MIN_FRAMES, elandev->num_frames); fpi_imgdev_session_error(dev, FP_VERIFY_RETRY_TOO_SHORT); + } /* other error * It says "...session_error" but repotring 1 during verification @@ -421,37 +419,98 @@ static void elan_capture(struct fp_img_dev *dev) elan_dev_reset(elandev); struct fpi_ssm *ssm = - fpi_ssm_new(fpi_imgdev_get_dev(dev), elan_capture_run_state, CAPTURE_NUM_STATES); + fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_complete); } +static void fpi_ssm_next_state_async(void *data) +{ + fpi_ssm_next_state((struct fpi_ssm *)data); +} + +/* this function needs last_read to be the calibration mean and at least + * one frame */ +static int elan_need_calibration(struct elan_dev *elandev) +{ + G_DEBUG_HERE(); + + if (elandev->dev_type & ELAN_0903) { + fp_dbg("don't know how to calibrate this device"); + return 0; + } + + unsigned short calib_mean = + elandev->last_read[0] * 0xff + elandev->last_read[1]; + unsigned short *bg_data = ((GSList *) elandev->frames)->data; + unsigned int bg_mean = 0, delta; + unsigned int frame_size = elandev->frame_width * elandev->frame_height; + + for (int i = 0; i < frame_size; i++) + bg_mean += bg_data[i]; + bg_mean /= frame_size; + + delta = + bg_mean > calib_mean ? bg_mean - calib_mean : calib_mean - bg_mean; + + fp_dbg("calibration mean: %d, bg mean: %d, delta: %d", calib_mean, + bg_mean, delta); + + return delta > ELAN_CALIBRATION_MAX_DELTA ? 1 : 0; +} + enum calibrate_states { - CALIBRATE_START_1, - CALIBRATE_READ_DATA_1, - CALIBRATE_END_1, - CALIBRATE_START_2, - CALIBRATE_READ_DATA_2, - CALIBRATE_END_2, + CALIBRATE_START, + CALIBRATE_CHECK_RESULT, + CALIBRATE_REPEAT, + CALIBRATE_GET_BACKGROUND, + CALIBRATE_SAVE_BACKGROUND, + CALIBRATE_GET_MEAN, CALIBRATE_NUM_STATES, }; -static void elan_calibrate_run_state(struct fpi_ssm *ssm) +static void calibrate_run_state(struct fpi_ssm *ssm) { + struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + + G_DEBUG_HERE(); + switch (fpi_ssm_get_cur_state(ssm)) { - case CALIBRATE_START_1: - case CALIBRATE_START_2: - elan_run_cmds(ssm, calibrate_start_cmds, - calibrate_start_cmds_len, ELAN_CMD_TIMEOUT); + case CALIBRATE_START: + elandev->calib_atts_left -= 1; + if (elandev->calib_atts_left) + elan_run_cmd(ssm, &run_calibration_cmd, + ELAN_CMD_TIMEOUT); + else { + fp_dbg("too many calibration attempts"); + fpi_ssm_mark_aborted(ssm, -1); + } break; - case CALIBRATE_READ_DATA_1: - case CALIBRATE_READ_DATA_2: - elan_run_cmds(ssm, read_cmds, read_cmds_len, ELAN_CMD_TIMEOUT); + case CALIBRATE_CHECK_RESULT: + /* 0x01 - retry, 0x03 - ok + * but some devices send other responses so in order to avoid needless + * retries we don't check 0x3 but only retry on 0x1 (need to wait 50 ms) */ + fp_dbg("calibration status: 0x%02x", elandev->last_read[0]); + if (elandev->last_read[0] == 0x01) { + if (!fpi_timeout_add(50, fpi_ssm_next_state_async, ssm)) + fpi_ssm_mark_aborted(ssm, -ETIME); + } else + fpi_ssm_jump_to_state(ssm, CALIBRATE_GET_BACKGROUND); + break; + case CALIBRATE_REPEAT: + fpi_ssm_jump_to_state(ssm, CALIBRATE_START); + break; + case CALIBRATE_GET_BACKGROUND: + elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); + break; + case CALIBRATE_SAVE_BACKGROUND: + elan_save_frame(dev); + fpi_ssm_next_state(ssm); + break; + case CALIBRATE_GET_MEAN: + elan_run_cmd(ssm, &get_calib_mean_cmd, ELAN_CMD_TIMEOUT); break; - case CALIBRATE_END_1: - case CALIBRATE_END_2: - elan_run_cmds(ssm, calibrate_end_cmds, calibrate_end_cmds_len, - ELAN_CMD_TIMEOUT); } } @@ -465,11 +524,14 @@ static void calibrate_complete(struct fpi_ssm *ssm) if (elandev->deactivating) elan_deactivate(dev); else if (fpi_ssm_get_error(ssm)) - fpi_imgdev_session_error(dev, fpi_ssm_get_error(ssm)); - else { fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); + else if (elan_need_calibration(elandev)) + elan_calibrate(dev); + else { + fpi_imgdev_activate_complete(dev, 0); elan_capture(dev); } + fpi_ssm_free(ssm); } @@ -480,48 +542,67 @@ static void elan_calibrate(struct fp_img_dev *dev) G_DEBUG_HERE(); elan_dev_reset(elandev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), elan_calibrate_run_state, + struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), calibrate_run_state, CALIBRATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, calibrate_complete); } enum activate_states { + ACTIVATE_GET_FW_VER, + ACTIVATE_PRINT_FW_VER, ACTIVATE_GET_SENSOR_DIM, ACTIVATE_SET_SENSOR_DIM, - ACTIVATE_START, - ACTIVATE_READ_DATA, - ACTIVATE_END, + ACTIVATE_CMD_1, + ACTIVATE_GET_BACKGROUND, + ACTIVATE_SAVE_BACKGROUND, + ACTIVATE_GET_MEAN, ACTIVATE_NUM_STATES, }; -static void elan_activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + G_DEBUG_HERE(); + switch (fpi_ssm_get_cur_state(ssm)) { + case ACTIVATE_GET_FW_VER: + elan_run_cmd(ssm, &get_fw_ver_cmd, ELAN_CMD_TIMEOUT); + break; + case ACTIVATE_PRINT_FW_VER: + fp_dbg("FW ver %d.%d", elandev->last_read[0], + elandev->last_read[1]); + fpi_ssm_next_state(ssm); + break; case ACTIVATE_GET_SENSOR_DIM: - elan_run_cmds(ssm, get_sensor_dim_cmds, get_sensor_dim_cmds_len, - ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, &get_sensor_dim_cmd, ELAN_CMD_TIMEOUT); break; case ACTIVATE_SET_SENSOR_DIM: elandev->frame_width = elandev->last_read[2]; elandev->raw_frame_width = elandev->last_read[0]; elandev->frame_height = - elandev->raw_frame_width - 2 * ELAN_FRAME_MARGIN; + elandev->raw_frame_width - 2 * elandev->frame_margin; + /* see elan_save_frame */ + fp_dbg("sensor dimensions, WxH: %dx%d", elandev->frame_width, + elandev->raw_frame_width); fpi_ssm_next_state(ssm); break; - case ACTIVATE_START: - elan_run_cmds(ssm, init_start_cmds, init_start_cmds_len, - ELAN_CMD_TIMEOUT); + case ACTIVATE_CMD_1: + /* TODO: find out what this does, if we need it */ + elan_run_cmd(ssm, &activate_cmd_1, ELAN_CMD_TIMEOUT); break; - case ACTIVATE_READ_DATA: - elan_run_cmds(ssm, read_cmds, read_cmds_len, ELAN_CMD_TIMEOUT); + case ACTIVATE_GET_BACKGROUND: + elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); + break; + case ACTIVATE_SAVE_BACKGROUND: + elan_save_frame(dev); + fpi_ssm_next_state(ssm); + break; + case ACTIVATE_GET_MEAN: + elan_run_cmd(ssm, &get_calib_mean_cmd, ELAN_CMD_TIMEOUT); break; - case ACTIVATE_END: - elan_run_cmds(ssm, init_end_cmds, init_end_cmds_len, - ELAN_CMD_TIMEOUT); } } @@ -535,13 +616,17 @@ static void activate_complete(struct fpi_ssm *ssm) if (elandev->deactivating) elan_deactivate(dev); else if (fpi_ssm_get_error(ssm)) - fpi_imgdev_session_error(dev, fpi_ssm_get_error(ssm)); - else + fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); + else if (elan_need_calibration(elandev)) elan_calibrate(dev); + else { + fpi_imgdev_activate_complete(dev, 0); + elan_capture(dev); + } fpi_ssm_free(ssm); } -static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) +static void elan_activate(struct fp_img_dev *dev) { struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -549,11 +634,9 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) elan_dev_reset(elandev); struct fpi_ssm *ssm = - fpi_ssm_new(fpi_imgdev_get_dev(dev), elan_activate_run_state, ACTIVATE_NUM_STATES); + fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_complete); - - return 0; } static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) @@ -571,10 +654,80 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) elandev = g_malloc0(sizeof(struct elan_dev)); fpi_imgdev_set_user_data(dev, elandev); + + /* common params */ + elandev->dev_type = driver_data; + elandev->calib_atts_left = ELAN_CALIBRATION_ATTEMPTS; + elandev->frame_margin = 0; + + switch (driver_data) { + case ELAN_0907: + elandev->frame_margin = 12; + break; + } + fpi_imgdev_open_complete(dev, 0); return 0; } +enum reset_sensor_states { + RESET_SENSOR_DO_RESET, + RESET_SENSOR_WAIT, + RESET_SENSOR_FUSE_LOAD, + RESET_SENSOR_STATUS, + RESET_SENSOR_NUM_STATES, +}; + +static void reset_sensor_run_state(struct fpi_ssm *ssm) +{ + switch (fpi_ssm_get_cur_state(ssm)) { + case RESET_SENSOR_DO_RESET: + elan_run_cmd(ssm, &reset_sensor_cmd, ELAN_CMD_TIMEOUT); + break; + case RESET_SENSOR_WAIT: + /* must wait 5 ms after sensor reset command */ + if (!fpi_timeout_add(5, fpi_ssm_next_state_async, ssm)) + fpi_ssm_mark_aborted(ssm, -ETIME); + break; + case RESET_SENSOR_FUSE_LOAD: + elan_run_cmd(ssm, &fuse_load_cmd, ELAN_CMD_TIMEOUT); + break; + case RESET_SENSOR_STATUS: + elan_run_cmd(ssm, &read_sensor_status_cmd, ELAN_CMD_TIMEOUT); + break; + } +} + +static void reset_sensor_complete(struct fpi_ssm *ssm) +{ + struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + + G_DEBUG_HERE(); + + if (elandev->deactivating) + elan_deactivate(dev); + else if (fpi_ssm_get_error(ssm)) + fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); + else + elan_activate(dev); + + fpi_ssm_free(ssm); +} + +static void elan_reset_sensor(struct fp_img_dev *dev) +{ + struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + + G_DEBUG_HERE(); + + elan_dev_reset(elandev); + struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), reset_sensor_run_state, + RESET_SENSOR_NUM_STATES); + fpi_ssm_set_user_data(ssm, dev); + fpi_ssm_start(ssm, reset_sensor_complete); +} + static void dev_deinit(struct fp_img_dev *dev) { struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -587,6 +740,12 @@ static void dev_deinit(struct fp_img_dev *dev) fpi_imgdev_close_complete(dev); } +static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) +{ + elan_reset_sensor(dev); + return 0; +} + static void dev_deactivate(struct fp_img_dev *dev) { struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -602,8 +761,12 @@ static void dev_deactivate(struct fp_img_dev *dev) } static const struct usb_id id_table[] = { - {.vendor = 0x04f3,.product = 0x0907}, - {.vendor = 0x04f3,.product = 0x0c26}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0903,.driver_data = ELAN_0903}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0907,.driver_data = ELAN_0907}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c03,.driver_data = ELAN_0C03}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c16,.driver_data = ELAN_0C16}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c1a,.driver_data = ELAN_0C1A}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c26,.driver_data = ELAN_0C26}, {0, 0, 0,}, }; diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index c929287a..74e9b3af 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -24,9 +24,17 @@ #include #include -/* number of pixels to discard on left and right (along raw image height) - * because they have different intensity from the rest of the frame */ -#define ELAN_FRAME_MARGIN 12 +#define ELAN_VENDOR_ID 0x04f3 + +/* supported devices */ +#define ELAN_0903 1 +#define ELAN_0907 (1 << 1) +#define ELAN_0C03 (1 << 2) +#define ELAN_0C16 (1 << 3) +#define ELAN_0C1A (1 << 4) +#define ELAN_0C26 (1 << 5) + +#define ELAN_ALL_DEVICES (ELAN_0903|ELAN_0907|ELAN_0C03|ELAN_0C16|ELAN_0C1A|ELAN_0C26) /* min and max frames in a capture */ #define ELAN_MIN_FRAMES 7 @@ -36,6 +44,13 @@ * while the finger is being lifted can be bad */ #define ELAN_SKIP_LAST_FRAMES 1 +/* max difference between background image mean and calibration mean +* (the response value of get_calib_mean_cmd)*/ +#define ELAN_CALIBRATION_MAX_DELTA 500 + +/* times to retry calibration */ +#define ELAN_CALIBRATION_ATTEMPTS 10 + #define ELAN_CMD_LEN 0x2 #define ELAN_EP_CMD_OUT (0x1 | LIBUSB_ENDPOINT_OUT) #define ELAN_EP_CMD_IN (0x3 | LIBUSB_ENDPOINT_IN) @@ -50,127 +65,104 @@ struct elan_cmd { unsigned char cmd[ELAN_CMD_LEN]; int response_len; int response_in; + unsigned short devices; }; -static const struct elan_cmd get_sensor_dim_cmds[] = { - { - .cmd = {0x00, 0x0c}, - .response_len = 0x4, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd get_sensor_dim_cmd = { + .cmd = {0x00, 0x0c}, + .response_len = 0x4, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, }; -static const size_t get_sensor_dim_cmds_len = -G_N_ELEMENTS(get_sensor_dim_cmds); - -static const struct elan_cmd init_start_cmds[] = { - { - .cmd = {0x40, 0x19}, - .response_len = 0x2, - .response_in = ELAN_EP_CMD_IN, - }, - { - .cmd = {0x40, 0x2a}, - .response_len = 0x2, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd get_fw_ver_cmd = { + .cmd = {0x40, 0x19}, + .response_len = 0x2, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, }; -static const size_t init_start_cmds_len = G_N_ELEMENTS(init_start_cmds); +/* unknown, returns 0x0 0x1 on 0907 */ +static const struct elan_cmd activate_cmd_1 = { + .cmd = {0x40, 0x2a}, + .response_len = 0x2, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_0907, +}; -static const struct elan_cmd read_cmds[] = { - /* raw frame sizes are calculated from image dimesions reported by the +static const struct elan_cmd get_image_cmd = { + .cmd = {0x00, 0x09}, + /* raw frame sizes are calculated from image dimensions reported by the * device */ - { - .cmd = {0x00, 0x09}, - .response_len = -1, - .response_in = ELAN_EP_IMG_IN, - }, + .response_len = -1, + .response_in = ELAN_EP_IMG_IN, + .devices = ELAN_ALL_DEVICES, }; -const size_t read_cmds_len = G_N_ELEMENTS(read_cmds); - -/* issued after data reads during init and calibration */ -static const struct elan_cmd init_end_cmds[] = { - { - .cmd = {0x40, 0x24}, - .response_len = 0x2, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd get_calib_mean_cmd = { + .cmd = {0x40, 0x24}, + .response_len = 0x2, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES & ~ELAN_0903, }; -static const size_t init_end_cmds_len = G_N_ELEMENTS(init_end_cmds); - -/* same command 2 times - * original driver may observe return value to determine how many times it - * should be repeated */ -static const struct elan_cmd calibrate_start_cmds[] = { - { - .cmd = {0x40, 0x23}, - .response_len = 0x1, - .response_in = ELAN_EP_CMD_IN, - }, - { - .cmd = {0x40, 0x23}, - .response_len = 0x1, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd reset_sensor_cmd = { + .cmd = {0x40, 0x11}, + .response_len = 0x0, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, }; -static const size_t calibrate_start_cmds_len = -G_N_ELEMENTS(calibrate_start_cmds); - -/* issued after data reads during init and calibration */ -static const struct elan_cmd calibrate_end_cmds[] = { - { - .cmd = {0x40, 0x24}, - .response_len = 0x2, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd fuse_load_cmd = { + .cmd = {0x40, 0x14}, + .response_len = 0x0, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, }; -static const size_t calibrate_end_cmds_len = -G_N_ELEMENTS(calibrate_end_cmds); - -static const struct elan_cmd capture_start_cmds[] = { - /* led on */ - { - .cmd = {0x40, 0x31}, - .response_len = 0x0, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd read_sensor_status_cmd = { + .cmd = {0x40, 0x13}, + .response_len = 0x1, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, }; -static size_t capture_start_cmds_len = G_N_ELEMENTS(capture_start_cmds); - -static const struct elan_cmd capture_wait_finger_cmds[] = { - /* wait for finger - * subsequent read will not complete until finger is placed on the reader */ - { - .cmd = {0x40, 0x3f}, - .response_len = 0x1, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd run_calibration_cmd = { + .cmd = {0x40, 0x23}, + .response_len = 0x1, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, }; -static size_t capture_wait_finger_cmds_len = -G_N_ELEMENTS(capture_wait_finger_cmds); - -static const struct elan_cmd deactivate_cmds[] = { - /* led off */ - { - .cmd = {0x00, 0x0b}, - .response_len = 0x0, - .response_in = ELAN_EP_CMD_IN, - }, +static const struct elan_cmd led_on_cmd = { + .cmd = {0x40, 0x31}, + .response_len = 0x0, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_0907, }; -static const size_t deactivate_cmds_len = G_N_ELEMENTS(deactivate_cmds); +/* wait for finger + * subsequent read will not complete until finger is placed on the reader */ +static const struct elan_cmd pre_scan_cmd = { + .cmd = {0x40, 0x3f}, + .response_len = 0x1, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, +}; -static void elan_cmd_cb(struct libusb_transfer *transfer); +/* led off, stop waiting for finger */ +static const struct elan_cmd stop_cmd = { + .cmd = {0x00, 0x0b}, + .response_len = 0x0, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, +}; + +static void elan_cmd_done(struct fpi_ssm *ssm); static void elan_cmd_read(struct fpi_ssm *ssm); -static void elan_run_next_cmd(struct fpi_ssm *ssm); +static void elan_calibrate(struct fp_img_dev *dev); static void elan_capture(struct fp_img_dev *dev); +static void elan_deactivate(struct fp_img_dev *dev); #endif From fba3e682ea633eecdee2936bee1dd4b046d52ee9 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Mon, 29 Jan 2018 21:48:12 +0200 Subject: [PATCH 014/225] elan: Remove supported devices from udev whitelist --- libfprint/fprint-list-udev-rules.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libfprint/fprint-list-udev-rules.c b/libfprint/fprint-list-udev-rules.c index f78ede19..de291f11 100644 --- a/libfprint/fprint-list-udev-rules.c +++ b/libfprint/fprint-list-udev-rules.c @@ -24,10 +24,6 @@ #include "fp_internal.h" static const struct usb_id whitelist_id_table[] = { - /* Unsupported (for now) Elantech finger print readers */ - { .vendor = 0x04f3, .product = 0x0c03 }, - { .vendor = 0x04f3, .product = 0x0c16 }, - { .vendor = 0x04f3, .product = 0x0c26 }, /* Unsupported (for now) Validity Sensors finger print readers */ { .vendor = 0x138a, .product = 0x0090 }, /* Found on e.g. Lenovo T460s */ { .vendor = 0x138a, .product = 0x0091 }, From 65bbdff3fc16383dc7be0255e53945eae20ffc66 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Thu, 9 Aug 2018 14:45:33 +0200 Subject: [PATCH 015/225] elan: Stop doing sensor reset, change calibration and frame logic Sensor reset code has been removed because it is not needed during normal operation. Calibration and frame processing logic has been improved according to recommendations from Elantech. --- libfprint/drivers/elan.c | 376 ++++++++++++++++++++++----------------- libfprint/drivers/elan.h | 70 ++++---- 2 files changed, 244 insertions(+), 202 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 3a2a0b04..f853cb0e 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -41,9 +41,8 @@ static struct fpi_frame_asmbl_ctx assembling_ctx = { struct elan_dev { /* device config */ unsigned short dev_type; - /* number of pixels to discard on left and right (along raw image height) - * because they have different intensity from the rest of the frame */ - unsigned char frame_margin; + unsigned short fw_ver; + void (*process_frame) (unsigned short *raw_frame, GSList ** frames); /* end device config */ /* commands */ @@ -54,8 +53,10 @@ struct elan_dev { /* state */ gboolean deactivating; - unsigned char calib_atts_left; unsigned char *last_read; + unsigned char calib_atts_left; + unsigned char calib_status; + unsigned short *background; unsigned char frame_width; unsigned char frame_height; unsigned char raw_frame_width; @@ -64,17 +65,23 @@ struct elan_dev { /* end state */ }; +int cmp_short(const void *a, const void *b) +{ + return (int)(*(short *)a - *(short *)b); +} + static void elan_dev_reset(struct elan_dev *elandev) { G_DEBUG_HERE(); BUG_ON(elandev->cur_transfer); - elandev->deactivating = FALSE; - elandev->cmd = NULL; elandev->cmd_timeout = ELAN_CMD_TIMEOUT; + elandev->deactivating = FALSE; + elandev->calib_status = 0; + g_free(elandev->last_read); elandev->last_read = NULL; @@ -83,36 +90,93 @@ static void elan_dev_reset(struct elan_dev *elandev) elandev->num_frames = 0; } -static void elan_save_frame(struct fp_img_dev *dev) +static void elan_save_frame(struct elan_dev *elandev, unsigned short *frame) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + G_DEBUG_HERE(); + unsigned char raw_height = elandev->frame_width; unsigned char raw_width = elandev->raw_frame_width; - unsigned short *frame = - g_malloc(elandev->frame_width * elandev->frame_height * 2); - - G_DEBUG_HERE(); /* Raw images are vertical and perpendicular to swipe direction of a * normalized image, which means we need to make them horizontal before * assembling. We also discard stripes of 'frame_margin' along raw * height. */ + unsigned char frame_margin = (raw_width - elandev->frame_height) / 2; for (int y = 0; y < raw_height; y++) - for (int x = elandev->frame_margin; - x < raw_width - elandev->frame_margin; x++) { - int frame_idx = - y + (x - elandev->frame_margin) * raw_height; + for (int x = frame_margin; x < raw_width - frame_margin; x++) { + int frame_idx = y + (x - frame_margin) * raw_height; int raw_idx = x + y * raw_width; frame[frame_idx] = ((unsigned short *)elandev->last_read)[raw_idx]; } +} + +static void elan_save_background(struct elan_dev *elandev) +{ + G_DEBUG_HERE(); + + g_free(elandev->background); + elandev->background = + g_malloc(elandev->frame_width * elandev->frame_height * + sizeof(short)); + elan_save_frame(elandev, elandev->background); +} + +/* save a frame as part of the fingerprint image + * background needs to have been captured for this routine to work + * Elantech recommends 2-step non-linear normalization in order to reduce + * 2^14 ADC resolution to 2^8 image: + * + * 1. background is subtracted (done here) + * + * 2. pixels are grouped in 3 groups by intensity and each group is mapped + * separately onto the normalized frame (done in elan_process_frame_*) + * ==== 16383 ____> ======== 255 + * / + * ----- lvl3 __/ + * 35% pixels + * + * ----- lvl2 --------> ======== 156 + * + * 30% pixels + * ----- lvl1 --------> ======== 99 + * + * 35% pixels + * ----- lvl0 __ + * \ + * ======== 0 \____> ======== 0 + * + * For some devices we don't do 2. but instead do a simple linear mapping + * because it seems to produce better results (or at least as good): + * ==== 16383 ___> ======== 255 + * / + * ------ max __/ + * + * + * ------ min __ + * \ + * ======== 0 \___> ======== 0 + */ +static void elan_save_img_frame(struct elan_dev *elandev) +{ + G_DEBUG_HERE(); + + unsigned int frame_size = elandev->frame_width * elandev->frame_height; + unsigned short *frame = g_malloc(frame_size * sizeof(short)); + elan_save_frame(elandev, frame); + + for (int i = 0; i < frame_size; i++) + if (elandev->background[i] > frame[i]) + frame[i] = 0; + else + frame[i] -= elandev->background[i]; elandev->frames = g_slist_prepend(elandev->frames, frame); elandev->num_frames += 1; } -/* Transform raw sensor data to normalized 8-bit grayscale image. */ -static void elan_process_frame(unsigned short *raw_frame, GSList ** frames) +static void elan_process_frame_linear(unsigned short *raw_frame, + GSList ** frames) { unsigned int frame_size = assembling_ctx.frame_width * assembling_ctx.frame_height; @@ -132,12 +196,42 @@ static void elan_process_frame(unsigned short *raw_frame, GSList ** frames) unsigned short px; for (int i = 0; i < frame_size; i++) { px = raw_frame[i]; - if (px <= min) - px = 0; - else if (px >= max) - px = 0xff; - else - px = (px - min) * 0xff / (max - min); + px = (px - min) * 0xff / (max - min); + frame->data[i] = (unsigned char)px; + } + + *frames = g_slist_prepend(*frames, frame); +} + +static void elan_process_frame_thirds(unsigned short *raw_frame, + GSList ** frames) +{ + G_DEBUG_HERE(); + + unsigned int frame_size = + assembling_ctx.frame_width * assembling_ctx.frame_height; + struct fpi_frame *frame = + g_malloc(frame_size + sizeof(struct fpi_frame)); + + unsigned short lvl0, lvl1, lvl2, lvl3; + unsigned short *sorted = g_malloc(frame_size * sizeof(short)); + memcpy(sorted, raw_frame, frame_size * sizeof(short)); + qsort(sorted, frame_size, sizeof(short), cmp_short); + lvl0 = sorted[0]; + lvl1 = sorted[frame_size * 3 / 10]; + lvl2 = sorted[frame_size * 65 / 100]; + lvl3 = sorted[frame_size - 1]; + g_free(sorted); + + unsigned short px; + for (int i = 0; i < frame_size; i++) { + px = raw_frame[i]; + if (lvl0 <= px && px < lvl1) + px = (px - lvl0) * 99 / (lvl1 - lvl0); + else if (lvl1 <= px && px < lvl2) + px = 99 + ((px - lvl1) * 56 / (lvl2 - lvl1)); + else // (lvl2 <= px && px <= lvl3) + px = 155 + ((px - lvl2) * 100 / (lvl3 - lvl2)); frame->data[i] = (unsigned char)px; } @@ -158,11 +252,13 @@ static void elan_submit_image(struct fp_img_dev *dev) assembling_ctx.frame_width = elandev->frame_width; assembling_ctx.frame_height = elandev->frame_height; assembling_ctx.image_width = elandev->frame_width * 3 / 2; - g_slist_foreach(elandev->frames, (GFunc) elan_process_frame, &frames); + g_slist_foreach(elandev->frames, (GFunc) elandev->process_frame, + &frames); fpi_do_movement_estimation(&assembling_ctx, frames, elandev->num_frames - ELAN_SKIP_LAST_FRAMES); - img = fpi_assemble_frames(&assembling_ctx, frames, - elandev->num_frames - ELAN_SKIP_LAST_FRAMES); + img = + fpi_assemble_frames(&assembling_ctx, frames, + elandev->num_frames - ELAN_SKIP_LAST_FRAMES); img->flags |= FP_IMG_PARTIAL; fpi_imgdev_image_captured(dev, img); @@ -221,7 +317,7 @@ static void elan_cmd_read(struct fpi_ssm *ssm) G_DEBUG_HERE(); - if (!(elandev->cmd->response_len)) { + if (elandev->cmd->response_len == ELAN_CMD_SKIP_READ) { fp_dbg("skipping read, not expecting anything"); elan_cmd_done(ssm); return; @@ -258,11 +354,14 @@ static void elan_run_cmd(struct fpi_ssm *ssm, const struct elan_cmd *cmd, struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + dbg_buf(cmd->cmd, 2); + elandev->cmd = cmd; if (cmd_timeout != -1) elandev->cmd_timeout = cmd_timeout; - if (!(cmd->devices & elandev->dev_type)) { + if (elandev->dev_type && cmd->devices + && !(cmd->devices & elandev->dev_type)) { fp_dbg("skipping for this device"); elan_cmd_done(ssm); return; @@ -353,7 +452,7 @@ static void capture_run_state(struct fpi_ssm *ssm) fpi_ssm_mark_aborted(ssm, FP_VERIFY_RETRY); break; case CAPTURE_CHECK_ENOUGH_FRAMES: - elan_save_frame(dev); + elan_save_img_frame(elandev); if (elandev->num_frames < ELAN_MAX_FRAMES) { /* quickly stop if finger is removed */ elandev->cmd_timeout = ELAN_FINGER_TIMEOUT; @@ -429,25 +528,19 @@ static void fpi_ssm_next_state_async(void *data) fpi_ssm_next_state((struct fpi_ssm *)data); } -/* this function needs last_read to be the calibration mean and at least - * one frame */ +/* this function needs to have elandev->background and elandev->last_read to be + * the calibration mean */ static int elan_need_calibration(struct elan_dev *elandev) { G_DEBUG_HERE(); - if (elandev->dev_type & ELAN_0903) { - fp_dbg("don't know how to calibrate this device"); - return 0; - } - unsigned short calib_mean = elandev->last_read[0] * 0xff + elandev->last_read[1]; - unsigned short *bg_data = ((GSList *) elandev->frames)->data; unsigned int bg_mean = 0, delta; unsigned int frame_size = elandev->frame_width * elandev->frame_height; for (int i = 0; i < frame_size; i++) - bg_mean += bg_data[i]; + bg_mean += elandev->background[i]; bg_mean /= frame_size; delta = @@ -460,12 +553,13 @@ static int elan_need_calibration(struct elan_dev *elandev) } enum calibrate_states { - CALIBRATE_START, - CALIBRATE_CHECK_RESULT, - CALIBRATE_REPEAT, CALIBRATE_GET_BACKGROUND, CALIBRATE_SAVE_BACKGROUND, CALIBRATE_GET_MEAN, + CALIBRATE_CHECK_NEEDED, + CALIBRATE_GET_STATUS, + CALIBRATE_CHECK_STATUS, + CALIBRATE_REPEAT_STATUS, CALIBRATE_NUM_STATES, }; @@ -477,40 +571,60 @@ static void calibrate_run_state(struct fpi_ssm *ssm) G_DEBUG_HERE(); switch (fpi_ssm_get_cur_state(ssm)) { - case CALIBRATE_START: - elandev->calib_atts_left -= 1; - if (elandev->calib_atts_left) - elan_run_cmd(ssm, &run_calibration_cmd, - ELAN_CMD_TIMEOUT); - else { - fp_dbg("too many calibration attempts"); - fpi_ssm_mark_aborted(ssm, -1); - } - break; - case CALIBRATE_CHECK_RESULT: - /* 0x01 - retry, 0x03 - ok - * but some devices send other responses so in order to avoid needless - * retries we don't check 0x3 but only retry on 0x1 (need to wait 50 ms) */ - fp_dbg("calibration status: 0x%02x", elandev->last_read[0]); - if (elandev->last_read[0] == 0x01) { - if (!fpi_timeout_add(50, fpi_ssm_next_state_async, ssm)) - fpi_ssm_mark_aborted(ssm, -ETIME); - } else - fpi_ssm_jump_to_state(ssm, CALIBRATE_GET_BACKGROUND); - break; - case CALIBRATE_REPEAT: - fpi_ssm_jump_to_state(ssm, CALIBRATE_START); - break; case CALIBRATE_GET_BACKGROUND: elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); break; case CALIBRATE_SAVE_BACKGROUND: - elan_save_frame(dev); - fpi_ssm_next_state(ssm); + elan_save_background(elandev); + if (elandev->fw_ver < ELAN_MIN_CALIBRATION_FW) { + fp_dbg("FW does not support calibration"); + fpi_ssm_mark_completed(ssm); + } else + fpi_ssm_next_state(ssm); break; case CALIBRATE_GET_MEAN: elan_run_cmd(ssm, &get_calib_mean_cmd, ELAN_CMD_TIMEOUT); break; + case CALIBRATE_CHECK_NEEDED: + if (elan_need_calibration(elandev)) { + elandev->calib_status = 0; + fpi_ssm_next_state(ssm); + } else + fpi_ssm_mark_completed(ssm); + break; + case CALIBRATE_GET_STATUS: + elandev->calib_atts_left -= 1; + if (elandev->calib_atts_left) + elan_run_cmd(ssm, &get_calib_status_cmd, + ELAN_CMD_TIMEOUT); + else { + fp_dbg("calibration failed"); + fpi_ssm_mark_aborted(ssm, -1); + } + break; + case CALIBRATE_CHECK_STATUS: + /* 0x01 - retry, 0x03 - ok + * It appears that when reading the response soon after 0x4023 the device + * can return 0x03, and only after some time (up to 100 ms) the response + * changes to 0x01. It stays that way for some time and then changes back + * to 0x03. Because of this we don't just expect 0x03, we want to see 0x01 + * first. This is to make sure that a full calibration loop has completed */ + fp_dbg("calibration status: 0x%02x", elandev->last_read[0]); + if (elandev->calib_status == 0x01 + && elandev->last_read[0] == 0x03) { + elandev->calib_status = 0x03; + fpi_ssm_jump_to_state(ssm, CALIBRATE_GET_BACKGROUND); + } else { + if (elandev->calib_status == 0x00 + && elandev->last_read[0] == 0x01) + elandev->calib_status = 0x01; + if (!fpi_timeout_add(50, fpi_ssm_next_state_async, ssm)) + fpi_ssm_mark_aborted(ssm, -ETIME); + } + break; + case CALIBRATE_REPEAT_STATUS: + fpi_ssm_jump_to_state(ssm, CALIBRATE_GET_STATUS); + break; } } @@ -525,8 +639,6 @@ static void calibrate_complete(struct fpi_ssm *ssm) elan_deactivate(dev); else if (fpi_ssm_get_error(ssm)) fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); - else if (elan_need_calibration(elandev)) - elan_calibrate(dev); else { fpi_imgdev_activate_complete(dev, 0); elan_capture(dev); @@ -542,6 +654,8 @@ static void elan_calibrate(struct fp_img_dev *dev) G_DEBUG_HERE(); elan_dev_reset(elandev); + elandev->calib_atts_left = ELAN_CALIBRATION_ATTEMPTS; + struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), calibrate_run_state, CALIBRATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -550,13 +664,10 @@ static void elan_calibrate(struct fp_img_dev *dev) enum activate_states { ACTIVATE_GET_FW_VER, - ACTIVATE_PRINT_FW_VER, + ACTIVATE_SET_FW_VER, ACTIVATE_GET_SENSOR_DIM, ACTIVATE_SET_SENSOR_DIM, ACTIVATE_CMD_1, - ACTIVATE_GET_BACKGROUND, - ACTIVATE_SAVE_BACKGROUND, - ACTIVATE_GET_MEAN, ACTIVATE_NUM_STATES, }; @@ -571,9 +682,10 @@ static void activate_run_state(struct fpi_ssm *ssm) case ACTIVATE_GET_FW_VER: elan_run_cmd(ssm, &get_fw_ver_cmd, ELAN_CMD_TIMEOUT); break; - case ACTIVATE_PRINT_FW_VER: - fp_dbg("FW ver %d.%d", elandev->last_read[0], - elandev->last_read[1]); + case ACTIVATE_SET_FW_VER: + elandev->fw_ver = + (elandev->last_read[0] << 8 | elandev->last_read[1]); + fp_dbg("FW ver 0x%04hx", elandev->fw_ver); fpi_ssm_next_state(ssm); break; case ACTIVATE_GET_SENSOR_DIM: @@ -582,9 +694,11 @@ static void activate_run_state(struct fpi_ssm *ssm) case ACTIVATE_SET_SENSOR_DIM: elandev->frame_width = elandev->last_read[2]; elandev->raw_frame_width = elandev->last_read[0]; - elandev->frame_height = - elandev->raw_frame_width - 2 * elandev->frame_margin; - /* see elan_save_frame */ + if (elandev->raw_frame_width < ELAN_MAX_FRAME_HEIGHT) + elandev->frame_height = elandev->raw_frame_width; + else + elandev->frame_height = ELAN_MAX_FRAME_HEIGHT; + /* see elan_save_frame for why it's width x raw_width */ fp_dbg("sensor dimensions, WxH: %dx%d", elandev->frame_width, elandev->raw_frame_width); fpi_ssm_next_state(ssm); @@ -593,16 +707,6 @@ static void activate_run_state(struct fpi_ssm *ssm) /* TODO: find out what this does, if we need it */ elan_run_cmd(ssm, &activate_cmd_1, ELAN_CMD_TIMEOUT); break; - case ACTIVATE_GET_BACKGROUND: - elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); - break; - case ACTIVATE_SAVE_BACKGROUND: - elan_save_frame(dev); - fpi_ssm_next_state(ssm); - break; - case ACTIVATE_GET_MEAN: - elan_run_cmd(ssm, &get_calib_mean_cmd, ELAN_CMD_TIMEOUT); - break; } } @@ -617,12 +721,9 @@ static void activate_complete(struct fpi_ssm *ssm) elan_deactivate(dev); else if (fpi_ssm_get_error(ssm)) fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); - else if (elan_need_calibration(elandev)) + else elan_calibrate(dev); - else { - fpi_imgdev_activate_complete(dev, 0); - elan_capture(dev); - } + fpi_ssm_free(ssm); } @@ -631,8 +732,8 @@ static void elan_activate(struct fp_img_dev *dev) struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); G_DEBUG_HERE(); - elan_dev_reset(elandev); + struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -657,12 +758,12 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) /* common params */ elandev->dev_type = driver_data; - elandev->calib_atts_left = ELAN_CALIBRATION_ATTEMPTS; - elandev->frame_margin = 0; + elandev->background = NULL; + elandev->process_frame = elan_process_frame_thirds; switch (driver_data) { case ELAN_0907: - elandev->frame_margin = 12; + elandev->process_frame = elan_process_frame_linear; break; } @@ -670,64 +771,6 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) return 0; } -enum reset_sensor_states { - RESET_SENSOR_DO_RESET, - RESET_SENSOR_WAIT, - RESET_SENSOR_FUSE_LOAD, - RESET_SENSOR_STATUS, - RESET_SENSOR_NUM_STATES, -}; - -static void reset_sensor_run_state(struct fpi_ssm *ssm) -{ - switch (fpi_ssm_get_cur_state(ssm)) { - case RESET_SENSOR_DO_RESET: - elan_run_cmd(ssm, &reset_sensor_cmd, ELAN_CMD_TIMEOUT); - break; - case RESET_SENSOR_WAIT: - /* must wait 5 ms after sensor reset command */ - if (!fpi_timeout_add(5, fpi_ssm_next_state_async, ssm)) - fpi_ssm_mark_aborted(ssm, -ETIME); - break; - case RESET_SENSOR_FUSE_LOAD: - elan_run_cmd(ssm, &fuse_load_cmd, ELAN_CMD_TIMEOUT); - break; - case RESET_SENSOR_STATUS: - elan_run_cmd(ssm, &read_sensor_status_cmd, ELAN_CMD_TIMEOUT); - break; - } -} - -static void reset_sensor_complete(struct fpi_ssm *ssm) -{ - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); - - G_DEBUG_HERE(); - - if (elandev->deactivating) - elan_deactivate(dev); - else if (fpi_ssm_get_error(ssm)) - fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); - else - elan_activate(dev); - - fpi_ssm_free(ssm); -} - -static void elan_reset_sensor(struct fp_img_dev *dev) -{ - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); - - G_DEBUG_HERE(); - - elan_dev_reset(elandev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), reset_sensor_run_state, - RESET_SENSOR_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); - fpi_ssm_start(ssm, reset_sensor_complete); -} - static void dev_deinit(struct fp_img_dev *dev) { struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -735,6 +778,7 @@ static void dev_deinit(struct fp_img_dev *dev) G_DEBUG_HERE(); elan_dev_reset(elandev); + g_free(elandev->background); g_free(elandev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); @@ -742,7 +786,8 @@ static void dev_deinit(struct fp_img_dev *dev) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - elan_reset_sensor(dev); + G_DEBUG_HERE(); + elan_activate(dev); return 0; } @@ -761,12 +806,17 @@ static void dev_deactivate(struct fp_img_dev *dev) } static const struct usb_id id_table[] = { - {.vendor = ELAN_VENDOR_ID,.product = 0x0903,.driver_data = ELAN_0903}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0903,.driver_data = + ELAN_ALL_DEVICES}, {.vendor = ELAN_VENDOR_ID,.product = 0x0907,.driver_data = ELAN_0907}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c03,.driver_data = ELAN_0C03}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c16,.driver_data = ELAN_0C16}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c1a,.driver_data = ELAN_0C1A}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c26,.driver_data = ELAN_0C26}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c03,.driver_data = + ELAN_ALL_DEVICES}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c16,.driver_data = + ELAN_ALL_DEVICES}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c1a,.driver_data = + ELAN_ALL_DEVICES}, + {.vendor = ELAN_VENDOR_ID,.product = 0x0c26,.driver_data = + ELAN_ALL_DEVICES}, {0, 0, 0,}, }; diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index 74e9b3af..2b73f23c 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -26,36 +26,42 @@ #define ELAN_VENDOR_ID 0x04f3 -/* supported devices */ -#define ELAN_0903 1 -#define ELAN_0907 (1 << 1) -#define ELAN_0C03 (1 << 2) -#define ELAN_0C16 (1 << 3) -#define ELAN_0C1A (1 << 4) -#define ELAN_0C26 (1 << 5) +/* a default device type */ +#define ELAN_ALL_DEVICES 0 -#define ELAN_ALL_DEVICES (ELAN_0903|ELAN_0907|ELAN_0C03|ELAN_0C16|ELAN_0C1A|ELAN_0C26) +/* devices with quirks */ +#define ELAN_0907 1 + +/* min FW version that supports calibration */ +#define ELAN_MIN_CALIBRATION_FW 0x0138 + +/* max difference between background image mean and calibration mean + * (the response value of get_calib_mean_cmd)*/ +#define ELAN_CALIBRATION_MAX_DELTA 500 + +/* times to retry reading calibration status during one session + * generally prevents calibration from looping indefinitely */ +#define ELAN_CALIBRATION_ATTEMPTS 10 /* min and max frames in a capture */ #define ELAN_MIN_FRAMES 7 #define ELAN_MAX_FRAMES 30 +/* crop frames to this height to improve stitching */ +#define ELAN_MAX_FRAME_HEIGHT 30 + /* number of frames to drop at the end of capture because frames captured * while the finger is being lifted can be bad */ #define ELAN_SKIP_LAST_FRAMES 1 -/* max difference between background image mean and calibration mean -* (the response value of get_calib_mean_cmd)*/ -#define ELAN_CALIBRATION_MAX_DELTA 500 - -/* times to retry calibration */ -#define ELAN_CALIBRATION_ATTEMPTS 10 - #define ELAN_CMD_LEN 0x2 #define ELAN_EP_CMD_OUT (0x1 | LIBUSB_ENDPOINT_OUT) #define ELAN_EP_CMD_IN (0x3 | LIBUSB_ENDPOINT_IN) #define ELAN_EP_IMG_IN (0x2 | LIBUSB_ENDPOINT_IN) +/* used as response length to tell the driver to skip reading response */ +#define ELAN_CMD_SKIP_READ 0 + /* usual command timeout and timeout for when we need to check if the finger is * still on the device */ #define ELAN_CMD_TIMEOUT 10000 @@ -99,27 +105,6 @@ static const struct elan_cmd get_image_cmd = { .devices = ELAN_ALL_DEVICES, }; -static const struct elan_cmd get_calib_mean_cmd = { - .cmd = {0x40, 0x24}, - .response_len = 0x2, - .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES & ~ELAN_0903, -}; - -static const struct elan_cmd reset_sensor_cmd = { - .cmd = {0x40, 0x11}, - .response_len = 0x0, - .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, -}; - -static const struct elan_cmd fuse_load_cmd = { - .cmd = {0x40, 0x14}, - .response_len = 0x0, - .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, -}; - static const struct elan_cmd read_sensor_status_cmd = { .cmd = {0x40, 0x13}, .response_len = 0x1, @@ -127,16 +112,23 @@ static const struct elan_cmd read_sensor_status_cmd = { .devices = ELAN_ALL_DEVICES, }; -static const struct elan_cmd run_calibration_cmd = { +static const struct elan_cmd get_calib_status_cmd = { .cmd = {0x40, 0x23}, .response_len = 0x1, .response_in = ELAN_EP_CMD_IN, .devices = ELAN_ALL_DEVICES, }; +static const struct elan_cmd get_calib_mean_cmd = { + .cmd = {0x40, 0x24}, + .response_len = 0x2, + .response_in = ELAN_EP_CMD_IN, + .devices = ELAN_ALL_DEVICES, +}; + static const struct elan_cmd led_on_cmd = { .cmd = {0x40, 0x31}, - .response_len = 0x0, + .response_len = ELAN_CMD_SKIP_READ, .response_in = ELAN_EP_CMD_IN, .devices = ELAN_0907, }; @@ -153,7 +145,7 @@ static const struct elan_cmd pre_scan_cmd = { /* led off, stop waiting for finger */ static const struct elan_cmd stop_cmd = { .cmd = {0x00, 0x0b}, - .response_len = 0x0, + .response_len = ELAN_CMD_SKIP_READ, .response_in = ELAN_EP_CMD_IN, .devices = ELAN_ALL_DEVICES, }; From b098399bbc0ae82750b59656a0b5bd03ca415a23 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Sun, 4 Feb 2018 17:18:07 +0200 Subject: [PATCH 016/225] elan: Support 0x0c01~0x0c33 --- libfprint/drivers/elan.c | 17 +-------- libfprint/drivers/elan.h | 77 ++++++++++++++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index f853cb0e..6c5052c9 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -805,27 +805,12 @@ static void dev_deactivate(struct fp_img_dev *dev) elan_deactivate(dev); } -static const struct usb_id id_table[] = { - {.vendor = ELAN_VENDOR_ID,.product = 0x0903,.driver_data = - ELAN_ALL_DEVICES}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0907,.driver_data = ELAN_0907}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c03,.driver_data = - ELAN_ALL_DEVICES}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c16,.driver_data = - ELAN_ALL_DEVICES}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c1a,.driver_data = - ELAN_ALL_DEVICES}, - {.vendor = ELAN_VENDOR_ID,.product = 0x0c26,.driver_data = - ELAN_ALL_DEVICES}, - {0, 0, 0,}, -}; - struct fp_img_driver elan_driver = { .driver = { .id = ELAN_ID, .name = FP_COMPONENT, .full_name = "ElanTech Fingerprint Sensor", - .id_table = id_table, + .id_table = elan_id_table, .scan_type = FP_SCAN_TYPE_SWIPE, }, .flags = 0, diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index 2b73f23c..132374f1 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -24,10 +24,10 @@ #include #include -#define ELAN_VENDOR_ID 0x04f3 +#define ELAN_VEND_ID 0x04f3 /* a default device type */ -#define ELAN_ALL_DEVICES 0 +#define ELAN_ALL_DEV 0 /* devices with quirks */ #define ELAN_0907 1 @@ -78,14 +78,14 @@ static const struct elan_cmd get_sensor_dim_cmd = { .cmd = {0x00, 0x0c}, .response_len = 0x4, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, }; static const struct elan_cmd get_fw_ver_cmd = { .cmd = {0x40, 0x19}, .response_len = 0x2, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, }; /* unknown, returns 0x0 0x1 on 0907 */ @@ -102,28 +102,28 @@ static const struct elan_cmd get_image_cmd = { * device */ .response_len = -1, .response_in = ELAN_EP_IMG_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, }; static const struct elan_cmd read_sensor_status_cmd = { .cmd = {0x40, 0x13}, .response_len = 0x1, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, }; static const struct elan_cmd get_calib_status_cmd = { .cmd = {0x40, 0x23}, .response_len = 0x1, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, }; static const struct elan_cmd get_calib_mean_cmd = { .cmd = {0x40, 0x24}, .response_len = 0x2, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, }; static const struct elan_cmd led_on_cmd = { @@ -139,7 +139,7 @@ static const struct elan_cmd pre_scan_cmd = { .cmd = {0x40, 0x3f}, .response_len = 0x1, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, }; /* led off, stop waiting for finger */ @@ -147,7 +147,64 @@ static const struct elan_cmd stop_cmd = { .cmd = {0x00, 0x0b}, .response_len = ELAN_CMD_SKIP_READ, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_ALL_DEVICES, + .devices = ELAN_ALL_DEV, +}; + +static const struct usb_id elan_id_table[] = { + {.vendor = ELAN_VEND_ID,.product = 0x0903,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0907,.driver_data = ELAN_0907}, + {.vendor = ELAN_VEND_ID,.product = 0x0c01,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c02,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c03,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c04,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c05,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c06,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c07,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c08,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c09,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c0a,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c0b,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c0c,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c0d,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c0e,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c0f,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c10,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c11,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c12,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c13,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c14,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c15,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c16,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c17,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c18,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c19,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c1a,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c1b,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c1c,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c1d,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c1e,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c1f,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c20,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c21,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c22,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c23,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c24,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c25,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c26,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c27,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c28,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c29,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c2a,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c2b,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c2c,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c2d,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c2e,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c2f,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c30,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c31,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c32,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c33,.driver_data = ELAN_ALL_DEV}, + {0, 0, 0,}, }; static void elan_cmd_done(struct fpi_ssm *ssm); From c3b1c982bc7bdbd01da86276e3454dff68273eb0 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Sun, 4 Feb 2018 17:57:27 +0200 Subject: [PATCH 017/225] elan: Set max frame height to 50, add note about performance Frame height is a loosely experience-backed guesstimation. 50 seems to be a good middle ground between swipe speed and quality. --- libfprint/drivers/elan.c | 17 +++++++++++++++++ libfprint/drivers/elan.h | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 6c5052c9..7cd01dcc 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -19,6 +19,23 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* + * The algorithm which libfprint uses to match fingerprints doesn't like small + * images like the ones these drivers produce. There's just not enough minutiae + * (recognizable print-specific points) on them for a reliable match. This means + * that unless another matching algo is found/implemented, these readers will + * not work as good with libfprint as they do with vendor drivers. + * + * To get bigger images the driver expects you to swipe the finger over the + * reader. This works quite well for readers with a rectangular 144x64 sensor. + * Worse than real swipe readers but good enough for day-to-day use. It needs + * a steady and relatively slow swipe. There are also square 96x96 sensors and + * I don't know whether they are in fact usable or not because I don't have one. + * I imagine they'd be less reliable because the resulting image is even + * smaller. If they can't be made usable with libfprint, I might end up dropping + * them because it's better than saying they work when they don't. + */ + #define FP_COMPONENT "elan" #include "drivers_api.h" diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index 132374f1..cfe5e306 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -48,7 +48,7 @@ #define ELAN_MAX_FRAMES 30 /* crop frames to this height to improve stitching */ -#define ELAN_MAX_FRAME_HEIGHT 30 +#define ELAN_MAX_FRAME_HEIGHT 50 /* number of frames to drop at the end of capture because frames captured * while the finger is being lifted can be bad */ From b28b006d617f2ff2c5c265245d0def14190bd980 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Mon, 5 Feb 2018 11:56:58 +0200 Subject: [PATCH 018/225] elan: Use IMGDEV_STATE_* events instead of pre-set capture path --- libfprint/drivers/elan.c | 158 ++++++++++++++++++++++++++------------- libfprint/drivers/elan.h | 4 +- 2 files changed, 109 insertions(+), 53 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 7cd01dcc..20e33adb 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -69,7 +69,8 @@ struct elan_dev { /* end commands */ /* state */ - gboolean deactivating; + enum fp_imgdev_state dev_state; + enum fp_imgdev_state dev_state_next; unsigned char *last_read; unsigned char calib_atts_left; unsigned char calib_status; @@ -96,7 +97,6 @@ static void elan_dev_reset(struct elan_dev *elandev) elandev->cmd = NULL; elandev->cmd_timeout = ELAN_CMD_TIMEOUT; - elandev->deactivating = FALSE; elandev->calib_status = 0; g_free(elandev->last_read); @@ -314,6 +314,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) case LIBUSB_TRANSFER_CANCELLED: fp_dbg("transfer cancelled"); fpi_ssm_mark_aborted(ssm, -ECANCELED); + elan_deactivate(dev); break; case LIBUSB_TRANSFER_TIMED_OUT: fp_dbg("transfer timed out"); @@ -377,8 +378,7 @@ static void elan_run_cmd(struct fpi_ssm *ssm, const struct elan_cmd *cmd, if (cmd_timeout != -1) elandev->cmd_timeout = cmd_timeout; - if (elandev->dev_type && cmd->devices - && !(cmd->devices & elandev->dev_type)) { + if (cmd->devices != ELAN_ALL_DEV && !(cmd->devices & elandev->dev_type)) { fp_dbg("skipping for this device"); elan_cmd_done(ssm); return; @@ -463,10 +463,11 @@ static void capture_run_state(struct fpi_ssm *ssm) /* 0x55 - finger present * 0xff - device not calibrated (probably) */ if (elandev->last_read && elandev->last_read[0] == 0x55) { - fpi_imgdev_report_finger_status(dev, TRUE); + if (elandev->dev_state == IMGDEV_STATE_AWAIT_FINGER_ON) + fpi_imgdev_report_finger_status(dev, TRUE); elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); } else - fpi_ssm_mark_aborted(ssm, FP_VERIFY_RETRY); + fpi_ssm_mark_aborted(ssm, -EBADMSG); break; case CAPTURE_CHECK_ENOUGH_FRAMES: elan_save_img_frame(elandev); @@ -481,11 +482,6 @@ static void capture_run_state(struct fpi_ssm *ssm) } } -static void elan_capture_async(void *data) -{ - elan_capture((struct fp_img_dev *)data); -} - static void capture_complete(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -493,36 +489,38 @@ static void capture_complete(struct fpi_ssm *ssm) G_DEBUG_HERE(); - if (elandev->deactivating) - elan_deactivate(dev); + if (fpi_ssm_get_error(ssm) == -ECANCELED) { + fpi_ssm_free(ssm); + return; + } /* either max frames captured or timed out waiting for the next frame */ - else if (!fpi_ssm_get_error(ssm) - || (fpi_ssm_get_error(ssm) == -ETIMEDOUT - && fpi_ssm_get_cur_state(ssm) == CAPTURE_WAIT_FINGER)) - if (elandev->num_frames >= ELAN_MIN_FRAMES) { + if (!fpi_ssm_get_error(ssm) + || (fpi_ssm_get_error(ssm) == -ETIMEDOUT + && fpi_ssm_get_cur_state(ssm) == CAPTURE_WAIT_FINGER)) + if (elandev->num_frames >= ELAN_MIN_FRAMES) elan_submit_image(dev); - fpi_imgdev_report_finger_status(dev, FALSE); - } else { + else { fp_dbg("swipe too short: want >= %d frames, got %d", ELAN_MIN_FRAMES, elandev->num_frames); - fpi_imgdev_session_error(dev, - FP_VERIFY_RETRY_TOO_SHORT); + fpi_imgdev_abort_scan(dev, FP_VERIFY_RETRY_TOO_SHORT); } /* other error - * It says "...session_error" but repotring 1 during verification - * makes it successful! */ + * It says "...abort_scan" but reporting 1 during verification makes it + * successful! */ else - fpi_imgdev_session_error(dev, FP_VERIFY_NO_MATCH); + fpi_imgdev_abort_scan(dev, fpi_ssm_get_error(ssm)); - /* When enrolling the lib won't restart the capture after a stage has - * 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. - * That's why we schedule elan_capture instead of running it directly. */ - if (fpi_dev_get_dev_state(fpi_imgdev_get_dev(dev)) == DEV_STATE_ENROLLING - && !fpi_timeout_add(10, elan_capture_async, dev)) - fpi_imgdev_session_error(dev, -ETIME); + /* this procedure must be called regardless of outcome because it advances + * dev_state to AWAIT_FINGER_ON under the hood... */ + fpi_imgdev_report_finger_status(dev, FALSE); + + /* ...but only on enroll! If verify or identify fails because of short swipe, + * we need to do it manually. It feels like libfprint or the application + * should know better if they want to retry, but they don't. */ + if (elandev->dev_state != IMGDEV_STATE_INACTIVE) + dev_change_state(dev, IMGDEV_STATE_AWAIT_FINGER_ON); fpi_ssm_free(ssm); } @@ -648,18 +646,12 @@ static void calibrate_run_state(struct fpi_ssm *ssm) static void calibrate_complete(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); G_DEBUG_HERE(); - if (elandev->deactivating) - elan_deactivate(dev); - else if (fpi_ssm_get_error(ssm)) + + if (fpi_ssm_get_error(ssm) != -ECANCELED) fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); - else { - fpi_imgdev_activate_complete(dev, 0); - elan_capture(dev); - } fpi_ssm_free(ssm); } @@ -730,16 +722,15 @@ static void activate_run_state(struct fpi_ssm *ssm) static void activate_complete(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); G_DEBUG_HERE(); - if (elandev->deactivating) - elan_deactivate(dev); - else if (fpi_ssm_get_error(ssm)) - fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); - else - elan_calibrate(dev); + if (fpi_ssm_get_error(ssm) != -ECANCELED) { + if (fpi_ssm_get_error(ssm)) + fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); + else + elan_calibrate(dev); + } fpi_ssm_free(ssm); } @@ -808,18 +799,80 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) return 0; } -static void dev_deactivate(struct fp_img_dev *dev) +static void elan_change_state(struct fp_img_dev *dev) +{ + struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + enum fp_imgdev_state next_state = elandev->dev_state_next; + + if (elandev->dev_state == next_state) { + fp_dbg("already in %d", next_state); + return; + } else + fp_dbg("changing to %d", next_state); + + switch (next_state) { + case IMGDEV_STATE_INACTIVE: + if (elandev->cur_transfer) + /* deactivation will complete in transfer callback */ + libusb_cancel_transfer(elandev->cur_transfer); + else + elan_deactivate(dev); + break; + case IMGDEV_STATE_AWAIT_FINGER_ON: + /* activation completed or another enroll stage started */ + elan_capture(dev); + break; + case IMGDEV_STATE_CAPTURE: + case IMGDEV_STATE_AWAIT_FINGER_OFF: + break; + } + + elandev->dev_state = next_state; +} + +static void elan_change_state_async(void *data) +{ + elan_change_state((struct fp_img_dev *)data); +} + +static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); G_DEBUG_HERE(); - elandev->deactivating = TRUE; + switch (state) { + case IMGDEV_STATE_INACTIVE: + case IMGDEV_STATE_AWAIT_FINGER_ON: + /* schedule state change instead of calling it directly to allow all actions + * related to the previous state to complete */ + elandev->dev_state_next = state; + if (!fpi_timeout_add(10, elan_change_state_async, dev)) { + fpi_imgdev_session_error(dev, -ETIME); + return -ETIME; + } + break; + case IMGDEV_STATE_CAPTURE: + case IMGDEV_STATE_AWAIT_FINGER_OFF: + /* TODO MAYBE: split capture ssm into smaller ssms and use these states */ + elandev->dev_state = state; + elandev->dev_state_next = state; + break; + default: + fp_err("unrecognized state %d", state); + fpi_imgdev_session_error(dev, -EINVAL); + return -EINVAL; + } - if (elandev->cur_transfer) - libusb_cancel_transfer(elandev->cur_transfer); - else - elan_deactivate(dev); + /* as of time of writing libfprint never checks the return value */ + return 0; +} + +static void dev_deactivate(struct fp_img_dev *dev) +{ + G_DEBUG_HERE(); + + dev_change_state(dev, IMGDEV_STATE_INACTIVE); } struct fp_img_driver elan_driver = { @@ -838,4 +891,5 @@ struct fp_img_driver elan_driver = { .close = dev_deinit, .activate = dev_activate, .deactivate = dev_deactivate, + .change_state = dev_change_state, }; diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index cfe5e306..9002a0e1 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -130,7 +130,7 @@ static const struct elan_cmd led_on_cmd = { .cmd = {0x40, 0x31}, .response_len = ELAN_CMD_SKIP_READ, .response_in = ELAN_EP_CMD_IN, - .devices = ELAN_0907, + .devices = ELAN_ALL_DEV, }; /* wait for finger @@ -214,4 +214,6 @@ static void elan_calibrate(struct fp_img_dev *dev); static void elan_capture(struct fp_img_dev *dev); static void elan_deactivate(struct fp_img_dev *dev); +static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state); + #endif From 75fe328f64f33b09e02d519e079efeb965af5a10 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Wed, 28 Feb 2018 11:36:33 +0200 Subject: [PATCH 019/225] elan: Don't rotate frames on 0x0c03 There has been a report that a 0x0c03 was installed straight (other readers so far have produced images that are 90 degrees rotated). There is no way for the dirver to know how a device is installed, so for now just make an exception. --- libfprint/drivers/elan.c | 60 ++++++++++++++++++++++++++-------------- libfprint/drivers/elan.h | 8 ++++-- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 20e33adb..cc54fb7a 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -77,7 +77,7 @@ struct elan_dev { unsigned short *background; unsigned char frame_width; unsigned char frame_height; - unsigned char raw_frame_width; + unsigned char raw_frame_height; int num_frames; GSList *frames; /* end state */ @@ -111,18 +111,33 @@ static void elan_save_frame(struct elan_dev *elandev, unsigned short *frame) { G_DEBUG_HERE(); - unsigned char raw_height = elandev->frame_width; - unsigned char raw_width = elandev->raw_frame_width; + /* so far 3 types of readers by sensor dimensions and orientation have been + * seen in the wild: + * 1. 144x64. Raw images are in portrait orientation while readers themselves + * are placed (e.g. built into a touchpad) in landscape orientation. These + * need to be rotated before assembling. + * 2. 96x96 rotated. Like the first type but square. Likewise, need to be + * rotated before assembling. + * 3. 96x96 normal. Square and need NOT be rotated. So far there's only been + * 1 report of a 0c03 of this type. Hopefully this type can be identified + * by device id (and manufacturers don't just install the readers as they + * please). + * we also discard stripes of 'frame_margin' from bottom and top because + * assembling works bad for tall frames */ - /* Raw images are vertical and perpendicular to swipe direction of a - * normalized image, which means we need to make them horizontal before - * assembling. We also discard stripes of 'frame_margin' along raw - * height. */ - unsigned char frame_margin = (raw_width - elandev->frame_height) / 2; - for (int y = 0; y < raw_height; y++) - for (int x = frame_margin; x < raw_width - frame_margin; x++) { - int frame_idx = y + (x - frame_margin) * raw_height; - int raw_idx = x + y * raw_width; + unsigned char frame_width = elandev->frame_width; + unsigned char frame_height = elandev->frame_height; + unsigned char raw_height = elandev->raw_frame_height; + unsigned char frame_margin = (raw_height - elandev->frame_height) / 2; + int frame_idx, raw_idx; + + for (int y = 0; y < frame_height; y++) + for (int x = 0; x < frame_width; x++) { + if (elandev->dev_type & ELAN_NOT_ROTATED) + raw_idx = x + (y + frame_margin) * frame_width; + else + raw_idx = frame_margin + y + x * raw_height; + frame_idx = x + y * frame_width; frame[frame_idx] = ((unsigned short *)elandev->last_read)[raw_idx]; } @@ -344,7 +359,7 @@ static void elan_cmd_read(struct fpi_ssm *ssm) if (elandev->cmd->cmd == get_image_cmd.cmd) /* raw data has 2-byte "pixels" and the frame is vertical */ response_len = - elandev->raw_frame_width * elandev->frame_width * 2; + elandev->raw_frame_height * elandev->frame_width * 2; struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { @@ -701,15 +716,20 @@ static void activate_run_state(struct fpi_ssm *ssm) elan_run_cmd(ssm, &get_sensor_dim_cmd, ELAN_CMD_TIMEOUT); break; case ACTIVATE_SET_SENSOR_DIM: - elandev->frame_width = elandev->last_read[2]; - elandev->raw_frame_width = elandev->last_read[0]; - if (elandev->raw_frame_width < ELAN_MAX_FRAME_HEIGHT) - elandev->frame_height = elandev->raw_frame_width; - else + /* see elan_save_frame for details */ + if (elandev->dev_type & ELAN_NOT_ROTATED) { + elandev->frame_width = elandev->last_read[0]; + elandev->frame_height = elandev->raw_frame_height = + elandev->last_read[2]; + } else { + elandev->frame_width = elandev->last_read[2]; + elandev->frame_height = elandev->raw_frame_height = + elandev->last_read[0]; + } + if (elandev->frame_height > ELAN_MAX_FRAME_HEIGHT) elandev->frame_height = ELAN_MAX_FRAME_HEIGHT; - /* see elan_save_frame for why it's width x raw_width */ fp_dbg("sensor dimensions, WxH: %dx%d", elandev->frame_width, - elandev->raw_frame_width); + elandev->raw_frame_height); fpi_ssm_next_state(ssm); break; case ACTIVATE_CMD_1: diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index 9002a0e1..7c4e81a2 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -30,7 +30,11 @@ #define ELAN_ALL_DEV 0 /* devices with quirks */ -#define ELAN_0907 1 +#define ELAN_0907 (1 << 0) +#define ELAN_0C03 (1 << 1) + +/* devices which don't require frame rotation before assembling */ +#define ELAN_NOT_ROTATED ELAN_0C03 /* min FW version that supports calibration */ #define ELAN_MIN_CALIBRATION_FW 0x0138 @@ -155,7 +159,7 @@ static const struct usb_id elan_id_table[] = { {.vendor = ELAN_VEND_ID,.product = 0x0907,.driver_data = ELAN_0907}, {.vendor = ELAN_VEND_ID,.product = 0x0c01,.driver_data = ELAN_ALL_DEV}, {.vendor = ELAN_VEND_ID,.product = 0x0c02,.driver_data = ELAN_ALL_DEV}, - {.vendor = ELAN_VEND_ID,.product = 0x0c03,.driver_data = ELAN_ALL_DEV}, + {.vendor = ELAN_VEND_ID,.product = 0x0c03,.driver_data = ELAN_0C03}, {.vendor = ELAN_VEND_ID,.product = 0x0c04,.driver_data = ELAN_ALL_DEV}, {.vendor = ELAN_VEND_ID,.product = 0x0c05,.driver_data = ELAN_ALL_DEV}, {.vendor = ELAN_VEND_ID,.product = 0x0c06,.driver_data = ELAN_ALL_DEV}, From 4ff97e7cbd737e207c5677f38627e516659d8b4e Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Thu, 1 Mar 2018 21:51:38 +0200 Subject: [PATCH 020/225] elan: Increase bz3 threshold to 24 Based on experience. Values more than 24 seem to work just after enrollment, but it becomes very hard to verify in a day or so. --- libfprint/drivers/elan.c | 52 ++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index cc54fb7a..97f4c349 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -41,6 +41,14 @@ #include "drivers_api.h" #include "elan.h" +#define dbg_buf(buf, len) \ + if (len == 1) \ + fp_dbg("%02hx", buf[0]); \ + else if (len == 2) \ + fp_dbg("%04hx", buf[0] << 8 | buf[1]); \ + else if (len > 2) \ + fp_dbg("%04hx... (%d bytes)", buf[0] << 8 | buf[1], len) + unsigned char elan_get_pixel(struct fpi_frame_asmbl_ctx *ctx, struct fpi_frame *frame, unsigned int x, unsigned int y) @@ -189,22 +197,32 @@ static void elan_save_background(struct elan_dev *elandev) * \ * ======== 0 \___> ======== 0 */ -static void elan_save_img_frame(struct elan_dev *elandev) +static int elan_save_img_frame(struct elan_dev *elandev) { G_DEBUG_HERE(); unsigned int frame_size = elandev->frame_width * elandev->frame_height; unsigned short *frame = g_malloc(frame_size * sizeof(short)); elan_save_frame(elandev, frame); + unsigned int sum = 0; - for (int i = 0; i < frame_size; i++) + for (int i = 0; i < frame_size; i++) { if (elandev->background[i] > frame[i]) frame[i] = 0; else frame[i] -= elandev->background[i]; + sum += frame[i]; + } + + if (sum == 0) { + fp_dbg + ("frame darker than background; finger present during calibration?"); + return -1; + } elandev->frames = g_slist_prepend(elandev->frames, frame); elandev->num_frames += 1; + return 0; } static void elan_process_frame_linear(unsigned short *raw_frame, @@ -280,6 +298,7 @@ static void elan_submit_image(struct fp_img_dev *dev) for (int i = 0; i < ELAN_SKIP_LAST_FRAMES; i++) elandev->frames = g_slist_next(elandev->frames); + elandev->num_frames -= ELAN_SKIP_LAST_FRAMES; assembling_ctx.frame_width = elandev->frame_width; assembling_ctx.frame_height = elandev->frame_height; @@ -287,10 +306,8 @@ static void elan_submit_image(struct fp_img_dev *dev) g_slist_foreach(elandev->frames, (GFunc) elandev->process_frame, &frames); fpi_do_movement_estimation(&assembling_ctx, frames, - elandev->num_frames - ELAN_SKIP_LAST_FRAMES); - img = - fpi_assemble_frames(&assembling_ctx, frames, - elandev->num_frames - ELAN_SKIP_LAST_FRAMES); + elandev->num_frames); + img = fpi_assemble_frames(&assembling_ctx, frames, elandev->num_frames); img->flags |= FP_IMG_PARTIAL; fpi_imgdev_image_captured(dev, img); @@ -319,12 +336,15 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) transfer->length, transfer->actual_length); elan_dev_reset(elandev); fpi_ssm_mark_aborted(ssm, -EPROTO); - } else if (transfer->endpoint & LIBUSB_ENDPOINT_IN) + } else if (transfer->endpoint & LIBUSB_ENDPOINT_IN) { /* just finished receiving */ + dbg_buf(elandev->last_read, transfer->actual_length); elan_cmd_done(ssm); - else + } else { /* just finished sending */ + G_DEBUG_HERE(); elan_cmd_read(ssm); + } break; case LIBUSB_TRANSFER_CANCELLED: fp_dbg("transfer cancelled"); @@ -466,6 +486,7 @@ static void capture_run_state(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + int r; switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_LED_ON: @@ -485,8 +506,10 @@ static void capture_run_state(struct fpi_ssm *ssm) fpi_ssm_mark_aborted(ssm, -EBADMSG); break; case CAPTURE_CHECK_ENOUGH_FRAMES: - elan_save_img_frame(elandev); - if (elandev->num_frames < ELAN_MAX_FRAMES) { + r = elan_save_img_frame(elandev); + if (r < 0) + fpi_ssm_mark_aborted(ssm, r); + else if (elandev->num_frames < ELAN_MAX_FRAMES) { /* quickly stop if finger is removed */ elandev->cmd_timeout = ELAN_FINGER_TIMEOUT; fpi_ssm_jump_to_state(ssm, CAPTURE_WAIT_FINGER); @@ -533,8 +556,11 @@ static void capture_complete(struct fpi_ssm *ssm) /* ...but only on enroll! If verify or identify fails because of short swipe, * we need to do it manually. It feels like libfprint or the application - * should know better if they want to retry, but they don't. */ - if (elandev->dev_state != IMGDEV_STATE_INACTIVE) + * should know better if they want to retry, but they don't. Unless we've + * been asked to deactivate, try to re-enter the capture loop. Since state + * change is async, there's still a chance to be deactivated by another + * pending event. */ + if (elandev->dev_state_next != IMGDEV_STATE_INACTIVE) dev_change_state(dev, IMGDEV_STATE_AWAIT_FINGER_ON); fpi_ssm_free(ssm); @@ -905,7 +931,7 @@ struct fp_img_driver elan_driver = { }, .flags = 0, - .bz3_threshold = 22, + .bz3_threshold = 24, .open = dev_init, .close = dev_deinit, From 9793d60c5af2f2d8fb6b4af835be433bb9d94d2f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 10 Aug 2018 13:45:06 +0200 Subject: [PATCH 021/225] elan: Remove unused string.h include --- libfprint/drivers/elan.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index 7c4e81a2..8a321b47 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -21,7 +21,6 @@ #ifndef __ELAN_H #define __ELAN_H -#include #include #define ELAN_VEND_ID 0x04f3 From 8553f2e41c41ab3f3df04638cc2c14e766ab84f0 Mon Sep 17 00:00:00 2001 From: Igor Filatov Date: Tue, 17 Jul 2018 09:02:47 +0300 Subject: [PATCH 022/225] elan: Send stop cmd and recalibrate after each capture This seems to fix the lock-up issue with 0903 --- libfprint/drivers/elan.c | 77 +++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 97f4c349..8457405a 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -435,32 +435,49 @@ static void elan_run_cmd(struct fpi_ssm *ssm, const struct elan_cmd *cmd, fpi_ssm_mark_aborted(ssm, r); } -enum deactivate_states { - DEACTIVATE, - DEACTIVATE_NUM_STATES, +enum stop_capture_states { + STOP_CAPTURE, + STOP_CAPTURE_NUM_STATES, }; -static void deactivate_run_state(struct fpi_ssm *ssm) +static void stop_capture_run_state(struct fpi_ssm *ssm) { G_DEBUG_HERE(); switch (fpi_ssm_get_cur_state(ssm)) { - case DEACTIVATE: + case STOP_CAPTURE: elan_run_cmd(ssm, &stop_cmd, ELAN_CMD_TIMEOUT); break; } } -static void deactivate_complete(struct fpi_ssm *ssm) +static void stop_capture_complete(struct fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + int error = fpi_ssm_get_error(ssm); G_DEBUG_HERE(); - fpi_imgdev_deactivate_complete(dev); + fpi_ssm_free(ssm); + + if (!error) { + fpi_imgdev_report_finger_status(dev, FALSE); + + /* If verify or identify fails because of short swipe, we need to restart + * capture manually. It feels like libfprint or the application should know + * better if they want to retry, but they don't. Unless we've been asked to + * deactivate, try to re-enter the capture loop. Since state change is + * async, there's still a chance to be deactivated by another pending + * event. */ + if (elandev->dev_state_next != IMGDEV_STATE_INACTIVE) + dev_change_state(dev, IMGDEV_STATE_AWAIT_FINGER_ON); + + } else if (error != -ECANCELED) + fpi_imgdev_abort_scan(dev, error); } -static void elan_deactivate(struct fp_img_dev *dev) +static void elan_stop_capture(struct fp_img_dev *dev) { struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -468,10 +485,11 @@ static void elan_deactivate(struct fp_img_dev *dev) elan_dev_reset(elandev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), deactivate_run_state, - DEACTIVATE_NUM_STATES); + struct fpi_ssm *ssm = + fpi_ssm_new(fpi_imgdev_get_dev(dev), stop_capture_run_state, + STOP_CAPTURE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); - fpi_ssm_start(ssm, deactivate_complete); + fpi_ssm_start(ssm, stop_capture_complete); } enum capture_states { @@ -550,19 +568,6 @@ static void capture_complete(struct fpi_ssm *ssm) else fpi_imgdev_abort_scan(dev, fpi_ssm_get_error(ssm)); - /* this procedure must be called regardless of outcome because it advances - * dev_state to AWAIT_FINGER_ON under the hood... */ - fpi_imgdev_report_finger_status(dev, FALSE); - - /* ...but only on enroll! If verify or identify fails because of short swipe, - * we need to do it manually. It feels like libfprint or the application - * should know better if they want to retry, but they don't. Unless we've - * been asked to deactivate, try to re-enter the capture loop. Since state - * change is async, there's still a chance to be deactivated by another - * pending event. */ - if (elandev->dev_state_next != IMGDEV_STATE_INACTIVE) - dev_change_state(dev, IMGDEV_STATE_AWAIT_FINGER_ON); - fpi_ssm_free(ssm); } @@ -692,7 +697,7 @@ static void calibrate_complete(struct fpi_ssm *ssm) if (fpi_ssm_get_error(ssm) != -ECANCELED) - fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); + elan_capture(dev); fpi_ssm_free(ssm); } @@ -772,10 +777,7 @@ static void activate_complete(struct fpi_ssm *ssm) G_DEBUG_HERE(); if (fpi_ssm_get_error(ssm) != -ECANCELED) { - if (fpi_ssm_get_error(ssm)) - fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); - else - elan_calibrate(dev); + fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); } fpi_ssm_free(ssm); @@ -825,6 +827,13 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) return 0; } +static void elan_deactivate(struct fp_img_dev *dev) +{ + G_DEBUG_HERE(); + + fpi_imgdev_deactivate_complete(dev); +} + static void dev_deinit(struct fp_img_dev *dev) { struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -866,11 +875,13 @@ static void elan_change_state(struct fp_img_dev *dev) break; case IMGDEV_STATE_AWAIT_FINGER_ON: /* activation completed or another enroll stage started */ - elan_capture(dev); + elan_calibrate(dev); break; case IMGDEV_STATE_CAPTURE: - case IMGDEV_STATE_AWAIT_FINGER_OFF: + /* not used */ break; + case IMGDEV_STATE_AWAIT_FINGER_OFF: + elan_stop_capture(dev); } elandev->dev_state = next_state; @@ -890,6 +901,7 @@ static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) switch (state) { case IMGDEV_STATE_INACTIVE: case IMGDEV_STATE_AWAIT_FINGER_ON: + case IMGDEV_STATE_AWAIT_FINGER_OFF: /* schedule state change instead of calling it directly to allow all actions * related to the previous state to complete */ elandev->dev_state_next = state; @@ -899,8 +911,7 @@ static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) } break; case IMGDEV_STATE_CAPTURE: - case IMGDEV_STATE_AWAIT_FINGER_OFF: - /* TODO MAYBE: split capture ssm into smaller ssms and use these states */ + /* TODO MAYBE: split capture ssm into smaller ssms and use this state */ elandev->dev_state = state; elandev->dev_state_next = state; break; From 703d9b2a0778a3bb2d488b7e053d14d25ac96133 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 24 Aug 2018 16:11:07 +0200 Subject: [PATCH 023/225] img: Remove remove_perimeter_pts setting It's gone in NBIS 5.0.0, and will need to be replaced after the update. --- libfprint/img.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libfprint/img.c b/libfprint/img.c index 2f195af4..b0cf9768 100644 --- a/libfprint/img.c +++ b/libfprint/img.c @@ -304,9 +304,6 @@ static int fpi_img_detect_minutiae(struct fp_img *img) return -EINVAL; } - /* Remove perimeter points from partial image */ - g_lfsparms_V2.remove_perimeter_pts = img->flags & FP_IMG_PARTIAL ? TRUE : FALSE; - /* 25.4 mm per inch */ timer = g_timer_new(); r = get_minutiae(&minutiae, &quality_map, &direction_map, From 770444af5547b0e0304e97648b17c6f828ef328c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 24 Aug 2018 19:43:22 +0200 Subject: [PATCH 024/225] nbis: Add script to update NBIS and apply changes NBIS is pretty complicated to update, seeing as we've made quite a few changes to get it to compile as a library. With those scripts, we can easily trim headers to remove functions we don't use, rename global variables, and do any sort of fixups that are necessary right now. In the future, removing unused NBIS functions might be as easy as updating that script, re-running it, and pushing the changes. Note that remove-function.lua is a very crude parser that only supports NBIS' style of declaration, with the return type on the same line as the function name. I wouldn't recommend trying to use it in another project. Callcatcher (https://github.com/caolanm/callcatcher) was also used to remove additional unused functions. --- libfprint/nbis/lfs.h.patch | 58 +++++++++ libfprint/nbis/remove-function.lua | 82 +++++++++++++ libfprint/nbis/update-from-nbis.sh | 181 +++++++++++++++++++++++++++++ 3 files changed, 321 insertions(+) create mode 100644 libfprint/nbis/lfs.h.patch create mode 100755 libfprint/nbis/remove-function.lua create mode 100755 libfprint/nbis/update-from-nbis.sh diff --git a/libfprint/nbis/lfs.h.patch b/libfprint/nbis/lfs.h.patch new file mode 100644 index 00000000..2be6ebf8 --- /dev/null +++ b/libfprint/nbis/lfs.h.patch @@ -0,0 +1,58 @@ +--- include/lfs.h 2018-08-24 15:31:54.535579623 +0200 ++++ include/lfs.h.orig 2018-08-24 15:31:48.781587933 +0200 +@@ -66,7 +43,7 @@ of the software. + + #include + #include +-#include /* Needed by to_type9.c */ ++#include + + /*************************************************************************/ + /* OUTPUT FILE EXTENSIONS */ +@@ -154,26 +131,8 @@ typedef struct rotgrids{ + #define DISAPPEARING 0 + #define APPEARING 1 + +-typedef struct minutia{ +- int x; +- int y; +- int ex; +- int ey; +- int direction; +- double reliability; +- int type; +- int appearing; +- int feature_id; +- int *nbrs; +- int *ridge_counts; +- int num_nbrs; +-} MINUTIA; +- +-typedef struct minutiae{ +- int alloc; +- int num; +- MINUTIA **list; +-} MINUTIAE; ++typedef struct fp_minutia MINUTIA; ++typedef struct fp_minutiae MINUTIAE; + + typedef struct feature_pattern{ + int type; +@@ -1185,17 +1185,6 @@ extern void bubble_sort_double_inc_2(double *, int *, const int); + extern void bubble_sort_double_dec_2(double *, int *, const int); + extern void bubble_sort_int_inc(int *, const int); + +-/* to_type9.c */ +-extern int minutiae2type_9(RECORD **, const int, MINUTIAE *, const int, +- const int, const double); +-extern int mintiae2field_12(FIELD **, MINUTIAE *, const int, const int, +- const double); +- +-/* update.c */ +-extern int update_ANSI_NIST_lfs_results(ANSI_NIST *, MINUTIAE *, +- unsigned char *, const int, const int, +- const int, const double, const int, const int); +- + /* util.c */ + extern int maxv(const int *, const int); + extern int minv(const int *, const int); diff --git a/libfprint/nbis/remove-function.lua b/libfprint/nbis/remove-function.lua new file mode 100755 index 00000000..408fb66b --- /dev/null +++ b/libfprint/nbis/remove-function.lua @@ -0,0 +1,82 @@ +#!/bin/lua + +function read_all(file) + local f = io.open(file, "r") + if not f then return nil end + local t = f:read("*all") + f:close() + return t +end + +function write_all(file, content) + local f = io.open(file, "w") + f:write(content) + f:close() +end + +-- From http://lua-users.org/wiki/SplitJoin +function split_lines(str) + local t = {} + local function helper(line) + table.insert(t, line) + return "" + end + helper((str:gsub("(.-)\r?\n", helper))) + return t +end + +function remove_func_content(func, content) + local lines = split_lines(content) + local res = {} + local in_func = false + local num_braces = 0 + local found_func = false + for k, v in ipairs(lines) do + if in_func == true then + local orig_braces = num_braces + local _, count = string.gsub(v, "{", "") + num_braces = num_braces + count + _, count = string.gsub(v, "}", "") + num_braces = num_braces - count + if orig_braces ~= 0 and num_braces == 0 then + print (func .. ' finished line '.. k) + in_func = false + end + elseif (v:match(' '..func..'%(%a+') or + v:match(' '..func..' %(%a+') or + v:match(' '..func..'%( %a+') or + v:match(' '..func..'%($')) and + not v:match('= '..func..'%(%a+') then + print (func .. ' started line ' .. k) + found_func = true + in_func = true + else + table.insert(res, v) + end + end + + if not found_func then + return nil + end + return table.concat(res, '\n') +end + +function remove_func_file(func, file) + content = read_all(file) + content = remove_func_content(func, content) + if not content then + error('Could not find function '..func..'() in '..file) + else + write_all(file, content) + end +end + +local func +for k, v in ipairs(arg) do + if k == 1 then + func = v + else + remove_func_file(func, v) + end +end + diff --git a/libfprint/nbis/update-from-nbis.sh b/libfprint/nbis/update-from-nbis.sh new file mode 100755 index 00000000..bd3a59b9 --- /dev/null +++ b/libfprint/nbis/update-from-nbis.sh @@ -0,0 +1,181 @@ +#!/bin/sh -e + +help() +{ + echo "Usage:" + echo " `basename $0` [NBIS directory]" + exit +} + +replace_global() +{ + if [ ! -f "$2" ] ; then + FILES=`find -name *.[ch]` + else + FILES=$2 + fi + sed -i "s/$1/g_$1/" $FILES +} + +rename_variable() +{ + if [ ! -f "$3" ] ; then + FILES=`find -name *.[ch]` + else + FILES=$3 + fi + sed -i "s/$1/$2/" $FILES +} + +remove_function() +{ + if [ ! -f "$2" ] ; then + FILES=`find -name *.[ch]` + else + FILES=$2 + fi + ./remove-function.lua $1 $FILES +} + +if [ $# -ne 1 ] ; then echo "*** Wrong number of arguments ***" ; help ; fi +if [ ! -d $1 ] ; then echo "*** $1 not a directory ***" ; help ; fi + +DIR="$1" + +if [ ! -d $DIR/bozorth3 ] ; then echo "*** $DIR not an NBIS source directory ***" ; help ; fi +if [ ! -d $DIR/mindtct ] ; then echo "*** $DIR not an NBIS source directory ***" ; help ; fi + +# Update files +for i in bozorth3/*.c ; do + cp -a $DIR/bozorth3/src/lib/bozorth3/`basename $i` bozorth3/ + chmod 0644 bozorth3/`basename $i` +done + +for i in mindtct/*.c chaincod.c getmin.c link.c xytreps.c; do + cp -a $DIR/mindtct/src/lib/mindtct/`basename $i` mindtct/ + chmod 0644 mindtct/`basename $i` +done + +for i in include/*.h mytime.h ; do + FILE=`basename $i` + ORIG=`find $DIR -name $FILE | grep -v misc/ | grep -v exports/` + + cp -a -f $ORIG include/ + chmod 0644 include/$FILE +done + +# Replace global variables +replace_global dft_coefs include/lfs.h +replace_global dft_coefs mindtct/globals.c +replace_global dft_coefs mindtct/maps.c +replace_global dft_coefs mindtct/detect.c +# Also does lfsparms_V2 +replace_global lfsparms include/lfs.h +replace_global lfsparms mindtct/globals.c +replace_global nbr8_dx +replace_global nbr8_dy +replace_global chaincodes_nbr8 +replace_global feature_patterns +rename_variable errorfp stderr + +# Remove command-line options globals +for i in m1_xyt max_minutiae min_computable_minutiae verbose_bozorth verbose_main verbose_load; do + sed -i "/$i/d" include/bozorth.h +done +rename_variable max_minutiae DEFAULT_BOZORTH_MINUTIAE +rename_variable m1_xyt 0 +rename_variable min_computable_minutiae MIN_COMPUTABLE_BOZORTH_MINUTIAE +rename_variable verbose_bozorth 0 +rename_variable verbose_main 0 +rename_variable verbose_load 0 +# Remove logging globals +for i in logfp avrdir dir_strength nvalid ; do + sed -i "/$i/d" mindtct/log.c + sed -i "/$i/d" include/log.h +done +# Remove an unused static variable +sed -i "/stack_pointer = stack/d" bozorth3/bz_sort.c +sed -i "/stack\[BZ_STACKSIZE\]/d" bozorth3/bz_sort.c + +# +extern int verbose_load; +# extern int verbose_threshold; +# +/* Global supporting error reporting */ +# +extern FILE *stderr; + +# Remove unused functions +patch -p0 < lfs.h.patch +remove_function binarize mindtct/binar.c +remove_function binarize_image mindtct/binar.c +remove_function isobinarize mindtct/binar.c +remove_function lfs_detect_minutiae mindtct/detect.c +remove_function bits_6to8 mindtct/imgutil.c +remove_function bozorth_main bozorth3/bz_drvrs.c +remove_function bz_load bozorth3/bz_io.c +remove_function bz_prune bozorth3/bz_io.c +remove_function get_next_file bozorth3/bz_io.c +remove_function get_score_filename bozorth3/bz_io.c +remove_function get_score_line bozorth3/bz_io.c +remove_function parse_line_range bozorth3/bz_io.c +remove_function set_gallery_filename bozorth3/bz_io.c +remove_function set_probe_filename bozorth3/bz_io.c +remove_function set_progname bozorth3/bz_io.c +remove_function detect_minutiae mindtct/minutia.c +remove_function dump_minutiae_pts mindtct/minutia.c +remove_function dump_minutiae mindtct/minutia.c +remove_function dump_reliable_minutiae_pts mindtct/minutia.c +remove_function scan4minutiae mindtct/minutia.c +remove_function scan4minutiae_horizontally mindtct/minutia.c +remove_function scan4minutiae_vertically mindtct/minutia.c +remove_function rescan4minutiae_horizontally mindtct/minutia.c +remove_function rescan4minutiae_vertically mindtct/minutia.c +remove_function process_horizontal_scan_minutia mindtct/minutia.c +remove_function process_vertical_scan_minutia mindtct/minutia.c +remove_function get_nbr_block_index mindtct/minutia.c +remove_function join_minutia mindtct/minutia.c +remove_function rescan_partial_horizontally mindtct/minutia.c +remove_function rescan_partial_vertically mindtct/minutia.c +remove_function adjust_high_curvature_minutia mindtct/minutia.c +remove_function adjust_horizontal_rescan mindtct/minutia.c +remove_function adjust_vertical_rescan mindtct/minutia.c +remove_function dump_shape mindtct/shape.c +remove_function flood_loop mindtct/loop.c +remove_function get_loop_list mindtct/loop.c +remove_function process_loop mindtct/loop.c +remove_function gen_imap mindtct/maps.c +remove_function gen_nmap mindtct/maps.c +remove_function gen_initial_imap mindtct/maps.c +remove_function smooth_imap mindtct/maps.c +remove_function get_max_padding mindtct/init.c +remove_function lfs2m1_minutia_XYT mindtct/xytreps.c +remove_function lfs2nist_format mindtct/xytreps.c +remove_function malloc_or_exit bozorth3/bz_alloc.c +remove_function malloc_or_return_error bozorth3/bz_alloc.c +remove_function reliability_fr_quality_map mindtct/quality.c +remove_function remove_false_minutia mindtct/remove.c +remove_function remove_pores mindtct/remove.c +remove_function remove_pointing_invblock mindtct/remove.c +remove_function remove_hooks_islands_lakes_overlaps mindtct/remove.c +remove_function remove_near_invblock mindtct/remove.c +remove_function remove_or_adjust_side_minutiae mindtct/remove.c +remove_function sort_quality_decreasing bozorth3/bz_sort.c +remove_function sort_order_decreasing bozorth3/bz_sort.c +remove_function qsort_decreasing bozorth3/bz_sort.c +remove_function partition_dec bozorth3/bz_sort.c +remove_function popstack bozorth3/bz_sort.c +remove_function pushstack bozorth3/bz_sort.c +remove_function select_pivot bozorth3/bz_sort.c +remove_function sort_indices_double_inc mindtct/sort.c +remove_function link_minutiae mindtct/link.c +remove_function create_link_table mindtct/link.c +remove_function order_link_table mindtct/link.c +remove_function process_link_table mindtct/link.c +remove_function update_link_table mindtct/link.c +remove_function link_score mindtct/link.c +remove_function remove_from_int_list mindtct/util.c + +# Remove trailing spaces +sed -i 's/[ \t]*$//' `find -name "*.[ch]"` + +# Remove usebsd.h +sed -i '/usebsd.h/d' `find -name "*.[ch]"` + From 9fb789dc787dbaa7caa0bc7dd2b9a1baa1f9a750 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 24 Aug 2018 19:48:53 +0200 Subject: [PATCH 025/225] nbis: Update to NBIS 5.0.0 This updates NBIS to its latest 5.0.0 version, dated 04/03/2015, from a 1.x version, dated 2007. Original sources are available at: https://www.nist.gov/itl/iad/image-group/products-and-services/image-group-open-source-server-nigos#Releases And full change log at: https://www.nist.gov/sites/default/files/documents/2016/12/14/changelog.txt --- libfprint/meson.build | 4 + libfprint/nbis/bozorth3/bozorth3.c | 114 +-- libfprint/nbis/bozorth3/bz_alloc.c | 119 +-- libfprint/nbis/bozorth3/bz_drvrs.c | 126 +-- libfprint/nbis/bozorth3/bz_gbls.c | 130 +-- libfprint/nbis/bozorth3/bz_io.c | 552 +---------- libfprint/nbis/bozorth3/bz_sort.c | 255 +---- libfprint/nbis/include/bozorth.h | 69 +- libfprint/nbis/include/bz_array.h | 54 +- libfprint/nbis/include/defs.h | 55 +- libfprint/nbis/include/lfs.h | 249 ++++- libfprint/nbis/include/log.h | 59 +- libfprint/nbis/include/morph.h | 55 +- libfprint/nbis/include/mytime.h | 106 ++ libfprint/nbis/include/sunrast.h | 55 +- libfprint/nbis/mindtct/binar.c | 135 ++- libfprint/nbis/mindtct/block.c | 60 +- libfprint/nbis/mindtct/chaincod.c | 211 ++++ libfprint/nbis/mindtct/contour.c | 516 +++++----- libfprint/nbis/mindtct/detect.c | 241 +++-- libfprint/nbis/mindtct/dft.c | 366 +++---- libfprint/nbis/mindtct/free.c | 56 +- libfprint/nbis/mindtct/getmin.c | 175 ++++ libfprint/nbis/mindtct/globals.c | 61 +- libfprint/nbis/mindtct/imgutil.c | 68 +- libfprint/nbis/mindtct/init.c | 84 +- libfprint/nbis/mindtct/line.c | 56 +- libfprint/nbis/mindtct/link.c | 254 +++++ libfprint/nbis/mindtct/log.c | 62 +- libfprint/nbis/mindtct/loop.c | 743 +++++--------- libfprint/nbis/mindtct/maps.c | 310 ++---- libfprint/nbis/mindtct/matchpat.c | 71 +- libfprint/nbis/mindtct/minutia.c | 1460 ++-------------------------- libfprint/nbis/mindtct/morph.c | 79 +- libfprint/nbis/mindtct/quality.c | 306 +++--- libfprint/nbis/mindtct/remove.c | 531 +++++----- libfprint/nbis/mindtct/ridges.c | 886 ++++++++--------- libfprint/nbis/mindtct/shape.c | 92 +- libfprint/nbis/mindtct/sort.c | 87 +- libfprint/nbis/mindtct/util.c | 81 +- libfprint/nbis/mindtct/xytreps.c | 136 +++ 41 files changed, 4165 insertions(+), 4964 deletions(-) create mode 100644 libfprint/nbis/include/mytime.h create mode 100644 libfprint/nbis/mindtct/chaincod.c create mode 100644 libfprint/nbis/mindtct/getmin.c create mode 100644 libfprint/nbis/mindtct/link.c create mode 100644 libfprint/nbis/mindtct/xytreps.c diff --git a/libfprint/meson.build b/libfprint/meson.build index 8689c9f2..fea424f8 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -30,14 +30,17 @@ nbis_sources = [ 'nbis/bozorth3/bz_sort.c', 'nbis/mindtct/binar.c', 'nbis/mindtct/block.c', + 'nbis/mindtct/chaincod.c', 'nbis/mindtct/contour.c', 'nbis/mindtct/detect.c', 'nbis/mindtct/dft.c', 'nbis/mindtct/free.c', + 'nbis/mindtct/getmin.c', 'nbis/mindtct/globals.c', 'nbis/mindtct/imgutil.c', 'nbis/mindtct/init.c', 'nbis/mindtct/line.c', + 'nbis/mindtct/link.c', 'nbis/mindtct/log.c', 'nbis/mindtct/loop.c', 'nbis/mindtct/maps.c', @@ -50,6 +53,7 @@ nbis_sources = [ 'nbis/mindtct/shape.c', 'nbis/mindtct/sort.c', 'nbis/mindtct/util.c', + 'nbis/mindtct/xytreps.c', ] aeslib = false diff --git a/libfprint/nbis/bozorth3/bozorth3.c b/libfprint/nbis/bozorth3/bozorth3.c index 54514e73..7724aea6 100644 --- a/libfprint/nbis/bozorth3/bozorth3.c +++ b/libfprint/nbis/bozorth3/bozorth3.c @@ -1,51 +1,43 @@ -/****************************************************************************** - -This file is part of the Export Control subset of the United States NIST -Biometric Image Software (NBIS) distribution: - http://fingerprint.nist.gov/NBIS/index.html - -It is our understanding that this falls within ECCN 3D980, which covers -software associated with the development, production or use of certain -equipment controlled in accordance with U.S. concerns about crime control -practices in specific countries. - -Therefore, this file should not be exported, or made available on fileservers, -except as allowed by U.S. export control laws. - -Do not remove this notice. - -******************************************************************************/ - -/* NOTE: Despite the above notice (which I have not removed), this file is - * being legally distributed within libfprint; the U.S. Export Administration - * Regulations do not place export restrictions upon distribution of - * "publicly available technology and software", as stated in EAR section - * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per - * the definition in section 734.7(a)(1). - * - * For further information, see https://fprint.freedesktop.org/us-export-control.html - */ - /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -89,9 +81,6 @@ identified are necessarily the best available for the purpose. #include #include -static const int verbose_bozorth = 0; -static const int m1_xyt = 0; - /***********************************************************************/ void bz_comp( int npoints, /* INPUT: # of points */ @@ -160,7 +149,7 @@ for ( k = 0; k < npoints - 1; k++ ) { else { double dz; - if ( m1_xyt ) + if ( 0 ) dz = ( 180.0F / PI_SINGLE ) * atanf( (float) -dy / (float) dx ); else dz = ( 180.0F / PI_SINGLE ) * atanf( (float) dy / (float) dx ); @@ -261,7 +250,7 @@ for ( k = 0; k < npoints - 1; k++ ) { if ( table_index == 19999 ) { #ifndef NOVERBOSE - if ( verbose_bozorth ) + if ( 0 ) printf( "bz_comp(): breaking loop to avoid table overflow\n" ); #endif goto COMP_END; @@ -392,7 +381,7 @@ static int * rtp[ ROT_SIZE_1 ]; /* extern int * scolpt[ SCOLPT_SIZE ]; INPUT */ /* extern int * fcolpt[ FCOLPT_SIZE ]; INPUT */ /* extern int colp[ COLP_SIZE_1 ][ COLP_SIZE_2 ]; OUTPUT */ -/* extern int verbose_bozorth; */ +/* extern int 0; */ /* extern FILE * stderr; */ /* extern char * get_progname( void ); */ /* extern char * get_probe_filename( void ); */ @@ -401,6 +390,7 @@ static int * rtp[ ROT_SIZE_1 ]; + st = 1; edge_pair_index = 0; rotptr = &rot[0][0]; @@ -570,7 +560,7 @@ for ( k = 1; k < probe_ptrlist_len; k++ ) { if ( edge_pair_index == 19999 ) { #ifndef NOVERBOSE - if ( verbose_bozorth ) + if ( 0 ) fprintf( stderr, "%s: bz_match(): WARNING: list is full, breaking loop early [p=%s; g=%s]\n", get_progname(), get_probe_filename(), get_gallery_filename() ); #endif @@ -652,13 +642,13 @@ int avv[ AVV_SIZE_1 ][ AVV_SIZE_2 ]; if ( pstruct->nrows < MIN_COMPUTABLE_BOZORTH_MINUTIAE ) { #ifndef NOVERBOSE if ( gstruct->nrows < MIN_COMPUTABLE_BOZORTH_MINUTIAE ) { - if ( verbose_bozorth ) + if ( 0 ) fprintf( stderr, "%s: bz_match_score(): both probe and gallery file have too few minutiae (%d,%d) to compute a real Bozorth match score; min. is %d [p=%s; g=%s]\n", get_progname(), pstruct->nrows, gstruct->nrows, MIN_COMPUTABLE_BOZORTH_MINUTIAE, get_probe_filename(), get_gallery_filename() ); } else { - if ( verbose_bozorth ) + if ( 0 ) fprintf( stderr, "%s: bz_match_score(): probe file has too few minutiae (%d) to compute a real Bozorth match score; min. is %d [p=%s; g=%s]\n", get_progname(), pstruct->nrows, MIN_COMPUTABLE_BOZORTH_MINUTIAE, @@ -672,7 +662,7 @@ if ( pstruct->nrows < MIN_COMPUTABLE_BOZORTH_MINUTIAE ) { if ( gstruct->nrows < MIN_COMPUTABLE_BOZORTH_MINUTIAE ) { #ifndef NOVERBOSE - if ( verbose_bozorth ) + if ( 0 ) fprintf( stderr, "%s: bz_match_score(): gallery file has too few minutiae (%d) to compute a real Bozorth match score; min. is %d [p=%s; g=%s]\n", get_progname(), gstruct->nrows, MIN_COMPUTABLE_BOZORTH_MINUTIAE, @@ -765,7 +755,7 @@ for ( k = 0; k < np - 1; k++ ) { } #ifndef NOVERBOSE - if ( verbose_bozorth ) + if ( 0 ) printf( "x1 %d %d %d %d %d %d\n", kx, colp[kx][0], colp[kx][1], colp[kx][2], colp[kx][3], colp[kx][4] ); #endif @@ -1167,7 +1157,7 @@ for ( k = 0; k < np - 1; k++ ) { if ( ll ) { - if ( m1_xyt ) + if ( 0 ) fi = ( 180.0F / PI_SINGLE ) * atanf( (float) -jj / (float) ll ); else fi = ( 180.0F / PI_SINGLE ) * atanf( (float) jj / (float) ll ); @@ -1187,7 +1177,7 @@ for ( k = 0; k < np - 1; k++ ) { jj += 360; } else { - if ( m1_xyt ) { + if ( 0 ) { if ( jj > 0 ) jj = -90; else @@ -1204,7 +1194,7 @@ for ( k = 0; k < np - 1; k++ ) { if ( kk ) { - if ( m1_xyt ) + if ( 0 ) fi = ( 180.0F / PI_SINGLE ) * atanf( (float) -j / (float) kk ); else fi = ( 180.0F / PI_SINGLE ) * atanf( (float) j / (float) kk ); @@ -1224,7 +1214,7 @@ for ( k = 0; k < np - 1; k++ ) { j += 360; } else { - if ( m1_xyt ) { + if ( 0 ) { if ( j > 0 ) j = -90; else @@ -1611,7 +1601,7 @@ if ( n ) { notfound = 1; #ifndef NOVERBOSE - if ( verbose_bozorth ) { + if ( 0 ) { int * llptr = lptr; printf( "bz_sift(): n: looking for l=%d in [", l ); for ( i = 0; i < lim; i++ ) { @@ -1657,7 +1647,7 @@ if ( t ) { notfound = 1; #ifndef NOVERBOSE - if ( verbose_bozorth ) { + if ( 0 ) { int * llptr = lptr; printf( "bz_sift(): t: looking for kz=%d in [", kz ); for ( i = 0; i < lim; i++ ) { diff --git a/libfprint/nbis/bozorth3/bz_alloc.c b/libfprint/nbis/bozorth3/bz_alloc.c index 5118282a..e4ac9918 100644 --- a/libfprint/nbis/bozorth3/bz_alloc.c +++ b/libfprint/nbis/bozorth3/bz_alloc.c @@ -1,51 +1,43 @@ -/****************************************************************************** - -This file is part of the Export Control subset of the United States NIST -Biometric Image Software (NBIS) distribution: - http://fingerprint.nist.gov/NBIS/index.html - -It is our understanding that this falls within ECCN 3D980, which covers -software associated with the development, production or use of certain -equipment controlled in accordance with U.S. concerns about crime control -practices in specific countries. - -Therefore, this file should not be exported, or made available on fileservers, -except as allowed by U.S. export control laws. - -Do not remove this notice. - -******************************************************************************/ - -/* NOTE: Despite the above notice (which I have not removed), this file is - * being legally distributed within libfprint; the U.S. Export Administration - * Regulations do not place export restrictions upon distribution of - * "publicly available technology and software", as stated in EAR section - * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per - * the definition in section 734.7(a)(1). - * - * For further information, see https://fprint.freedesktop.org/us-export-control.html - */ - /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -77,43 +69,6 @@ identified are necessarily the best available for the purpose. /***********************************************************************/ -char * malloc_or_exit( int nbytes, const char * what ) -{ -char * p; - -/* These are now externally defined in bozorth.h */ -/* extern FILE * stderr; */ -/* extern char * get_progname( void ); */ - - -p = malloc( (size_t) nbytes ); -if ( p == CNULL ) { - fprintf( stderr, "%s: ERROR: malloc() of %d bytes for %s failed: %s\n", - get_progname(), - nbytes, - what, - strerror( errno ) - ); - exit(1); -} -return p; -} /***********************************************************************/ /* returns CNULL on error */ -char * malloc_or_return_error( int nbytes, const char * what ) -{ -char * p; - -p = malloc( (size_t) nbytes ); -if ( p == CNULL ) { - fprintf( stderr, "%s: ERROR: malloc() of %d bytes for %s failed: %s\n", - get_progname(), - nbytes, - what, - strerror( errno ) - ); - return(CNULL); -} -return p; -} diff --git a/libfprint/nbis/bozorth3/bz_drvrs.c b/libfprint/nbis/bozorth3/bz_drvrs.c index 03f7171c..8904f0fc 100644 --- a/libfprint/nbis/bozorth3/bz_drvrs.c +++ b/libfprint/nbis/bozorth3/bz_drvrs.c @@ -1,51 +1,43 @@ -/****************************************************************************** - -This file is part of the Export Control subset of the United States NIST -Biometric Image Software (NBIS) distribution: - http://fingerprint.nist.gov/NBIS/index.html - -It is our understanding that this falls within ECCN 3D980, which covers -software associated with the development, production or use of certain -equipment controlled in accordance with U.S. concerns about crime control -practices in specific countries. - -Therefore, this file should not be exported, or made available on fileservers, -except as allowed by U.S. export control laws. - -Do not remove this notice. - -******************************************************************************/ - -/* NOTE: Despite the above notice (which I have not removed), this file is - * being legally distributed within libfprint; the U.S. Export Administration - * Regulations do not place export restrictions upon distribution of - * "publicly available technology and software", as stated in EAR section - * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per - * the definition in section 734.7(a)(1). - * - * For further information, see https://fprint.freedesktop.org/us-export-control.html - */ - /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -177,47 +169,3 @@ return bz_match_score( np, pstruct, gstruct ); /**************************************************************************/ -int bozorth_main( - struct xyt_struct * pstruct, - struct xyt_struct * gstruct - ) -{ -int ms; -int np; -int probe_len; -int gallery_len; - - - -#ifdef DEBUG - printf( "PROBE_INIT() called\n" ); -#endif -probe_len = bozorth_probe_init( pstruct ); - - -#ifdef DEBUG - printf( "GALLERY_INIT() called\n" ); -#endif -gallery_len = bozorth_gallery_init( gstruct ); - - -#ifdef DEBUG - printf( "BZ_MATCH() called\n" ); -#endif -np = bz_match( probe_len, gallery_len ); - - -#ifdef DEBUG - printf( "BZ_MATCH() returned %d edge pairs\n", np ); - printf( "COMPUTE() called\n" ); -#endif -ms = bz_match_score( np, pstruct, gstruct ); - - -#ifdef DEBUG - printf( "COMPUTE() returned %d\n", ms ); -#endif - - -return ms; -} diff --git a/libfprint/nbis/bozorth3/bz_gbls.c b/libfprint/nbis/bozorth3/bz_gbls.c index 0ecd081d..dd828dc3 100644 --- a/libfprint/nbis/bozorth3/bz_gbls.c +++ b/libfprint/nbis/bozorth3/bz_gbls.c @@ -1,51 +1,43 @@ -/****************************************************************************** - -This file is part of the Export Control subset of the United States NIST -Biometric Image Software (NBIS) distribution: - http://fingerprint.nist.gov/NBIS/index.html - -It is our understanding that this falls within ECCN 3D980, which covers -software associated with the development, production or use of certain -equipment controlled in accordance with U.S. concerns about crime control -practices in specific countries. - -Therefore, this file should not be exported, or made available on fileservers, -except as allowed by U.S. export control laws. - -Do not remove this notice. - -******************************************************************************/ - -/* NOTE: Despite the above notice (which I have not removed), this file is - * being legally distributed within libfprint; the U.S. Export Administration - * Regulations do not place export restrictions upon distribution of - * "publicly available technology and software", as stated in EAR section - * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per - * the definition in section 734.7(a)(1). - * - * For further information, see https://fprint.freedesktop.org/us-export-control.html - */ - /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -91,23 +83,45 @@ int yl[ YL_SIZE_1 ][ YL_SIZE_2 ]; /**************************************************************************/ /* Globals used significantly by sift() */ /**************************************************************************/ -int rq[ RQ_SIZE ] = {}; -int tq[ TQ_SIZE ] = {}; -int zz[ ZZ_SIZE ] = {}; +#ifdef TARGET_OS + int rq[ RQ_SIZE ]; + int tq[ TQ_SIZE ]; + int zz[ ZZ_SIZE ]; -int rx[ RX_SIZE ] = {}; -int mm[ MM_SIZE ] = {}; -int nn[ NN_SIZE ] = {}; + int rx[ RX_SIZE ]; + int mm[ MM_SIZE ]; + int nn[ NN_SIZE ]; -int qq[ QQ_SIZE ] = {}; + int qq[ QQ_SIZE ]; -int rk[ RK_SIZE ] = {}; + int rk[ RK_SIZE ]; -int cp[ CP_SIZE ] = {}; -int rp[ RP_SIZE ] = {}; + int cp[ CP_SIZE ]; + int rp[ RP_SIZE ]; -int rf[RF_SIZE_1][RF_SIZE_2] = {}; -int cf[CF_SIZE_1][CF_SIZE_2] = {}; + int rf[RF_SIZE_1][RF_SIZE_2]; + int cf[CF_SIZE_1][CF_SIZE_2]; -int y[20000] = {}; + int y[20000]; +#else + int rq[ RQ_SIZE ] = {}; + int tq[ TQ_SIZE ] = {}; + int zz[ ZZ_SIZE ] = {}; + + int rx[ RX_SIZE ] = {}; + int mm[ MM_SIZE ] = {}; + int nn[ NN_SIZE ] = {}; + + int qq[ QQ_SIZE ] = {}; + + int rk[ RK_SIZE ] = {}; + + int cp[ CP_SIZE ] = {}; + int rp[ RP_SIZE ] = {}; + + int rf[RF_SIZE_1][RF_SIZE_2] = {}; + int cf[CF_SIZE_1][CF_SIZE_2] = {}; + + int y[20000] = {}; +#endif diff --git a/libfprint/nbis/bozorth3/bz_io.c b/libfprint/nbis/bozorth3/bz_io.c index e5dc3bb9..5d2f8634 100644 --- a/libfprint/nbis/bozorth3/bz_io.c +++ b/libfprint/nbis/bozorth3/bz_io.c @@ -1,51 +1,43 @@ -/****************************************************************************** - -This file is part of the Export Control subset of the United States NIST -Biometric Image Software (NBIS) distribution: - http://fingerprint.nist.gov/NBIS/index.html - -It is our understanding that this falls within ECCN 3D980, which covers -software associated with the development, production or use of certain -equipment controlled in accordance with U.S. concerns about crime control -practices in specific countries. - -Therefore, this file should not be exported, or made available on fileservers, -except as allowed by U.S. export control laws. - -Do not remove this notice. - -******************************************************************************/ - -/* NOTE: Despite the above notice (which I have not removed), this file is - * being legally distributed within libfprint; the U.S. Export Administration - * Regulations do not place export restrictions upon distribution of - * "publicly available technology and software", as stated in EAR section - * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per - * the definition in section 734.7(a)(1). - * - * For further information, see https://fprint.freedesktop.org/us-export-control.html - */ - /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -57,6 +49,9 @@ identified are necessarily the best available for the purpose. MODIFICATIONS: Michael D. Garris (NIST) Stan Janet (NIST) DATE: 09/21/2004 + UPDATED: 01/11/2012 by Kenneth Ko + UPDATED: 03/08/2012 by Kenneth Ko + UPDATED: 07/10/2014 by Kenneth Ko Contains routines responsible for supporting command line processing, file and data input to, and output from the @@ -100,50 +95,7 @@ identified are necessarily the best available for the purpose. #include #include -static const int verbose_load = 0; -static const int verbose_main = 0; - /***********************************************************************/ -int parse_line_range( const char * sb, int * begin, int * end ) -{ -int ib, ie; -char * se; - - -if ( ! isdigit(*sb) ) - return -1; -ib = atoi( sb ); - -se = strchr( sb, '-' ); -if ( se != (char *) NULL ) { - se++; - if ( ! isdigit(*se) ) - return -2; - ie = atoi( se ); -} else { - ie = ib; -} - -if ( ib <= 0 ) { - if ( ie <= 0 ) { - return -3; - } else { - return -4; - } -} - -if ( ie <= 0 ) { - return -5; -} - -if ( ib > ie ) - return -6; - -*begin = ib; -*end = ie; - -return 0; -} /***********************************************************************/ @@ -153,25 +105,10 @@ static char * pfile; static char * gfile; /***********************************************************************/ -void set_progname( int use_pid, char * basename, pid_t pid ) -{ -if ( use_pid ) - sprintf( program_buffer, "%s pid %ld", basename, (long) pid ); -else - sprintf( program_buffer, "%s", basename ); -} /***********************************************************************/ -void set_probe_filename( char * filename ) -{ -pfile = filename; -} /***********************************************************************/ -void set_gallery_filename( char * filename ) -{ -gfile = filename; -} /***********************************************************************/ char * get_progname( void ) @@ -192,171 +129,15 @@ return gfile; } /***********************************************************************/ -char * get_next_file( - char * fixed_file, - FILE * list_fp, - FILE * mates_fp, - int * done_now, - int * done_afterwards, - char * line, - int argc, - char ** argv, - int * optind, - - int * lineno, - int begin, - int end - ) -{ -char * p; -FILE * fp; - - - -if ( fixed_file != (char *) NULL ) { - if ( verbose_main ) - fprintf( stderr, "returning fixed filename: %s\n", fixed_file ); - return fixed_file; -} - - -fp = list_fp; -if ( fp == (FILE *) NULL ) - fp = mates_fp; -if ( fp != (FILE *) NULL ) { - while (1) { - if ( fgets( line, MAX_LINE_LENGTH, fp ) == (char *) NULL ) { - *done_now = 1; - if ( verbose_main ) - fprintf( stderr, "returning NULL -- reached EOF\n" ); - return (char *) NULL; - } - ++*lineno; - - if ( begin <= 0 ) /* no line number range was specified */ - break; - if ( *lineno > end ) { - *done_now = 1; - if ( verbose_main ) - fprintf( stderr, "returning NULL -- current line (%d) > end line (%d)\n", - *lineno, end ); - return (char *) NULL; - } - if ( *lineno >= begin ) { - break; - } - /* Otherwise ( *lineno < begin ) so read another line */ - } - - p = strchr( line, '\n' ); - if ( p == (char *) NULL ) { - *done_now = 1; - if ( verbose_main ) - fprintf( stderr, "returning NULL -- missing newline character\n" ); - return (char *) NULL; - } - *p = '\0'; - - p = line; - if ( verbose_main ) - fprintf( stderr, "returning filename from next line: %s\n", p ); - return p; -} - - -p = argv[*optind]; -++*optind; -if ( *optind >= argc ) - *done_afterwards = 1; -if ( verbose_main ) - fprintf( stderr, "returning next argv: %s [done_afterwards=%d]\n", p, *done_afterwards ); -return p; -} /***********************************************************************/ /* returns CNULL on error */ -char * get_score_filename( const char * outdir, const char * listfile ) -{ -const char * basename; -int baselen; -int dirlen; -int extlen; -char * outfile; - -/* These are now exteranlly defined in bozorth.h */ -/* extern FILE * stderr; */ -/* extern char * get_progname( void ); */ - - - -basename = strrchr( listfile, '/' ); -if ( basename == CNULL ) { - basename = listfile; -} else { - ++basename; -} -baselen = strlen( basename ); -if ( baselen == 0 ) { - fprintf( stderr, "%s: ERROR: couldn't find basename of %s\n", get_progname(), listfile ); - return(CNULL); -} -dirlen = strlen( outdir ); -if ( dirlen == 0 ) { - fprintf( stderr, "%s: ERROR: illegal output directory %s\n", get_progname(), outdir ); - return(CNULL); -} - -extlen = strlen( SCOREFILE_EXTENSION ); -outfile = malloc_or_return_error( dirlen + baselen + extlen + 2, "output filename" ); -if ( outfile == CNULL) - return(CNULL); - -sprintf( outfile, "%s/%s%s", outdir, basename, SCOREFILE_EXTENSION ); - -return outfile; -} /***********************************************************************/ -char * get_score_line( - const char * probe_file, - const char * gallery_file, - int n, - int static_flag, - const char * fmt - ) -{ -int nchars; -char * bufptr; -static char linebuf[1024]; - -nchars = 0; -bufptr = &linebuf[0]; -while ( *fmt ) { - if ( nchars++ > 0 ) - *bufptr++ = ' '; - switch ( *fmt++ ) { - case 's': - sprintf( bufptr, "%d", n ); - break; - case 'p': - sprintf( bufptr, "%s", probe_file ); - break; - case 'g': - sprintf( bufptr, "%s", gallery_file ); - break; - default: - return (char *) NULL; - } - bufptr = strchr( bufptr, '\0' ); -} -*bufptr++ = '\n'; -*bufptr = '\0'; - -return static_flag ? &linebuf[0] : strdup( linebuf ); -} /************************************************************************ -Load a 3-4 column (X,Y,T[,Q]) set of minutiae from the specified file. +Load a 3-4 column (X,Y,T[,Q]) set of minutiae from the specified file +and return a XYT sturcture. Row 3's value is an angle which is normalized to the interval (-180,180]. A maximum of MAX_BOZORTH_MINUTIAE minutiae can be returned -- fewer if "DEFAULT_BOZORTH_MINUTIAE" is smaller. If the file contains more minutiae than are @@ -364,241 +145,14 @@ to be returned, the highest-quality minutiae are returned. *************************************************************************/ /***********************************************************************/ -struct xyt_struct * bz_load( const char * xyt_file ) -{ -int nminutiae; -int j; -int m; -int nargs_expected; -FILE * fp; -struct xyt_struct * s; -int * xptr; -int * yptr; -int * tptr; -int * qptr; -struct minutiae_struct c[MAX_FILE_MINUTIAE]; -int xvals_lng[MAX_FILE_MINUTIAE], /* Temporary lists to store all the minutaie from a file */ - yvals_lng[MAX_FILE_MINUTIAE], - tvals_lng[MAX_FILE_MINUTIAE], - qvals_lng[MAX_FILE_MINUTIAE]; -int order[MAX_FILE_MINUTIAE]; /* The ranked order, after sort, for each index */ -int xvals[MAX_BOZORTH_MINUTIAE], /* Temporary lists to hold input coordinates */ - yvals[MAX_BOZORTH_MINUTIAE], - tvals[MAX_BOZORTH_MINUTIAE], - qvals[MAX_BOZORTH_MINUTIAE]; -char xyt_line[ MAX_LINE_LENGTH ]; -/* This is now externally defined in bozorth.h */ -/* extern FILE * stderr; */ - - - -#define C1 0 -#define C2 1 - - - -fp = fopen( xyt_file, "r" ); -if ( fp == (FILE *) NULL ) { - fprintf( stderr, "%s: ERROR: fopen() of minutiae file \"%s\" failed: %s\n", - get_progname(), xyt_file, strerror(errno) ); - return XYT_NULL; -} - -nminutiae = 0; -nargs_expected = 0; -while ( fgets( xyt_line, sizeof xyt_line, fp ) != CNULL ) { - - m = sscanf( xyt_line, "%d %d %d %d", - &xvals_lng[nminutiae], - &yvals_lng[nminutiae], - &tvals_lng[nminutiae], - &qvals_lng[nminutiae] ); - if ( nminutiae == 0 ) { - if ( m != 3 && m != 4 ) { - fprintf( stderr, "%s: ERROR: sscanf() failed on line %u in minutiae file \"%s\"\n", - get_progname(), nminutiae+1, xyt_file ); - return XYT_NULL; - } - nargs_expected = m; - } else { - if ( m != nargs_expected ) { - fprintf( stderr, "%s: ERROR: inconsistent argument count on line %u of minutiae file \"%s\"\n", - get_progname(), nminutiae+1, xyt_file ); - return XYT_NULL; - } - } - if ( m == 3 ) - qvals_lng[nminutiae] = 1; - - - - if ( tvals_lng[nminutiae] > 180 ) - tvals_lng[nminutiae] -= 360; - - /* - if ( C1 ) { - c[nminutiae].col[0] = xvals_lng[nminutiae]; - c[nminutiae].col[1] = yvals_lng[nminutiae]; - c[nminutiae].col[2] = tvals_lng[nminutiae]; - c[nminutiae].col[3] = qvals_lng[nminutiae]; - } - */ - - ++nminutiae; - if ( nminutiae == MAX_FILE_MINUTIAE ) - break; -} - -if ( fclose(fp) != 0 ) { - fprintf( stderr, "%s: ERROR: fclose() of minutiae file \"%s\" failed: %s\n", - get_progname(), xyt_file, strerror(errno) ); - return XYT_NULL; -} - - - - -if ( nminutiae > DEFAULT_BOZORTH_MINUTIAE ) { - if ( verbose_load ) - fprintf( stderr, "%s: WARNING: bz_load(): trimming minutiae to the %d of highest quality\n", - get_progname(), DEFAULT_BOZORTH_MINUTIAE ); - - if ( verbose_load ) - fprintf( stderr, "Before quality sort:\n" ); - if ( sort_order_decreasing( qvals_lng, nminutiae, order )) { - fprintf( stderr, "%s: ERROR: sort failed and returned on error\n", get_progname()); - return XYT_NULL; - } - - for ( j = 0; j < nminutiae; j++ ) { - - if ( verbose_load ) - fprintf( stderr, " %3d: %3d %3d %3d ---> order = %3d\n", - j, xvals_lng[j], yvals_lng[j], qvals_lng[j], order[j] ); - - if ( j == 0 ) - continue; - if ( qvals_lng[order[j]] > qvals_lng[order[j-1]] ) { - fprintf( stderr, "%s: ERROR: sort failed: j=%d; qvals_lng[%d] > qvals_lng[%d]\n", - get_progname(), j, order[j], order[j-1] ); - return XYT_NULL; - } - } - - - if ( verbose_load ) - fprintf( stderr, "\nAfter quality sort:\n" ); - for ( j = 0; j < DEFAULT_BOZORTH_MINUTIAE; j++ ) { - xvals[j] = xvals_lng[order[j]]; - yvals[j] = yvals_lng[order[j]]; - tvals[j] = tvals_lng[order[j]]; - qvals[j] = qvals_lng[order[j]]; - if ( verbose_load ) - fprintf( stderr, " %3d: %3d %3d %3d\n", j, xvals[j], yvals[j], qvals[j] ); - } - - - if ( C1 ) { - if ( verbose_load ) - fprintf( stderr, "\nAfter qsort():\n" ); - qsort( (void *) &c, (size_t) nminutiae, sizeof(struct minutiae_struct), sort_quality_decreasing ); - for ( j = 0; j < nminutiae; j++ ) { - - if ( verbose_load ) - fprintf( stderr, "Q %3d: %3d %3d %3d\n", - j, c[j].col[0], c[j].col[1], c[j].col[3] ); - - if ( j > 0 && c[j].col[3] > c[j-1].col[3] ) { - fprintf( stderr, "%s: ERROR: sort failed: c[%d].col[3] > c[%d].col[3]\n", - get_progname(), j, j-1 ); - return XYT_NULL; - } - } - } - - if ( verbose_load ) - fprintf( stderr, "\n" ); - - xptr = xvals; - yptr = yvals; - tptr = tvals; - qptr = qvals; - - nminutiae = DEFAULT_BOZORTH_MINUTIAE; -} else{ - xptr = xvals_lng; - yptr = yvals_lng; - tptr = tvals_lng; - qptr = qvals_lng; -} - - - -for ( j=0; j < nminutiae; j++ ) { - c[j].col[0] = xptr[j]; - c[j].col[1] = yptr[j]; - c[j].col[2] = tptr[j]; - c[j].col[3] = qptr[j]; -} -qsort( (void *) &c, (size_t) nminutiae, sizeof(struct minutiae_struct), sort_x_y ); - - - - -if ( verbose_load ) { - fprintf( stderr, "\nSorted on increasing x, then increasing y\n" ); - for ( j = 0; j < nminutiae; j++ ) { - fprintf( stderr, "%d : %3d, %3d, %3d, %3d\n", j, c[j].col[0], c[j].col[1], c[j].col[2], c[j].col[3] ); - if ( j > 0 ) { - if ( c[j].col[0] < c[j-1].col[0] ) { - fprintf( stderr, "%s: ERROR: sort failed: c[%d].col[0]=%d > c[%d].col[0]=%d\n", - get_progname(), - j, c[j].col[0], j-1, c[j-1].col[0] - ); - return XYT_NULL; - } - if ( c[j].col[0] == c[j-1].col[0] && c[j].col[1] < c[j-1].col[1] ) { - fprintf( stderr, "%s: ERROR: sort failed: c[%d].col[0]=%d == c[%d].col[0]=%d; c[%d].col[0]=%d == c[%d].col[0]=%d\n", - get_progname(), - j, c[j].col[0], j-1, c[j-1].col[0], - j, c[j].col[1], j-1, c[j-1].col[1] - ); - return XYT_NULL; - } - } - } -} - - - -s = (struct xyt_struct *) malloc( sizeof( struct xyt_struct ) ); -if ( s == XYT_NULL ) { - fprintf( stderr, "%s: ERROR: malloc() failure while loading minutiae file \"%s\" failed: %s\n", - get_progname(), - xyt_file, - strerror(errno) - ); - return XYT_NULL; -} - - - -for ( j = 0; j < nminutiae; j++ ) { - s->xcol[j] = c[j].col[0]; - s->ycol[j] = c[j].col[1]; - s->thetacol[j] = c[j].col[2]; -} -s->nrows = nminutiae; - - - - -if ( verbose_load ) - fprintf( stderr, "Loaded %s\n", xyt_file ); - -return s; -} +/************************************************************************ +Load a XYTQ structure and return a XYT struct. +Row 3's value is an angle which is normalized to the interval (-180,180]. +A maximum of MAX_BOZORTH_MINUTIAE minutiae can be returned -- fewer if +"DEFAULT_BOZORTH_MINUTIAE" is smaller. If the file contains more minutiae than are +to be returned, the highest-quality minutiae are returned. +*************************************************************************/ /***********************************************************************/ #ifdef PARALLEL_SEARCH @@ -617,13 +171,13 @@ tv.tv_usec = 0; retval = select( fd+1, &rfds, NULL, NULL, &tv ); if ( retval < 0 ) { - perror( "select() failed" ); - return 0; + perror( "select() failed" ); + return 0; } if ( FD_ISSET( fd, &rfds ) ) { - /*fprintf( stderr, "data is available now.\n" );*/ - return 1; + /*fprintf( stderr, "data is available now.\n" );*/ + return 1; } /* fprintf( stderr, "no data is available\n" ); */ diff --git a/libfprint/nbis/bozorth3/bz_sort.c b/libfprint/nbis/bozorth3/bz_sort.c index 01371e5b..b51a82ed 100644 --- a/libfprint/nbis/bozorth3/bz_sort.c +++ b/libfprint/nbis/bozorth3/bz_sort.c @@ -1,51 +1,43 @@ -/****************************************************************************** - -This file is part of the Export Control subset of the United States NIST -Biometric Image Software (NBIS) distribution: - http://fingerprint.nist.gov/NBIS/index.html - -It is our understanding that this falls within ECCN 3D980, which covers -software associated with the development, production or use of certain -equipment controlled in accordance with U.S. concerns about crime control -practices in specific countries. - -Therefore, this file should not be exported, or made available on fileservers, -except as allowed by U.S. export control laws. - -Do not remove this notice. - -******************************************************************************/ - -/* NOTE: Despite the above notice (which I have not removed), this file is - * being legally distributed within libfprint; the U.S. Export Administration - * Regulations do not place export restrictions upon distribution of - * "publicly available technology and software", as stated in EAR section - * 734.3(b)(3)(i). libfprint qualifies as publicly available technology as per - * the definition in section 734.7(a)(1). - * - * For further information, see https://fprint.freedesktop.org/us-export-control.html - */ - /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -78,23 +70,10 @@ identified are necessarily the best available for the purpose. #include /* These are now externally defined in bozorth.h */ +/* extern FILE * stderr; */ /* extern char * get_progname( void ); */ /***********************************************************************/ -int sort_quality_decreasing( const void * a, const void * b ) -{ -struct minutiae_struct * af; -struct minutiae_struct * bf; - -af = (struct minutiae_struct *) a; -bf = (struct minutiae_struct *) b; - -if ( af->col[3] > bf->col[3] ) - return -1; -if ( af->col[3] < bf->col[3] ) - return 1; -return 0; -} /***********************************************************************/ int sort_x_y( const void * a, const void * b ) @@ -124,67 +103,18 @@ qsort_decreasing() - quicksort an array of integers in decreasing and Ted Zwiesler, 1986] ********************************************************/ /* Used by custom quicksort code below */ -static int stack[BZ_STACKSIZE]; -static int * stack_pointer = stack; /***********************************************************************/ /* return values: 0 == successful, 1 == error */ -static int popstack( int *popval ) -{ -if ( --stack_pointer < stack ) { - fprintf( stderr, "%s: ERROR: popstack(): stack underflow\n", get_progname() ); - return 1; -} - -*popval = *stack_pointer; -return 0; -} /***********************************************************************/ /* return values: 0 == successful, 1 == error */ -static int pushstack( int position ) -{ -*stack_pointer++ = position; -if ( stack_pointer > ( stack + BZ_STACKSIZE ) ) { - fprintf( stderr, "%s: ERROR: pushstack(): stack overflow\n", get_progname() ); - return 1; -} -return 0; -} /***********************************************************************/ /******************************************************************* select_pivot() selects a pivot from a list being sorted using the Singleton Method. *******************************************************************/ -static int select_pivot( struct cell v[], int left, int right ) -{ -int midpoint; - - -midpoint = ( left + right ) / 2; -if ( v[left].index <= v[midpoint].index ) { - if ( v[midpoint].index <= v[right].index ) { - return midpoint; - } else { - if ( v[right].index > v[left].index ) { - return right; - } else { - return left; - } - } -} else { - if ( v[left].index < v[right].index ) { - return left; - } else { - if ( v[right].index < v[midpoint].index ) { - return midpoint; - } else { - return right; - } - } -} -} /***********************************************************************/ /******************************************************** @@ -192,41 +122,6 @@ partition_dec() Inputs a pivot element making comparisons and swaps with other elements in a list, until pivot resides at its correct position in the list. ********************************************************/ -static void partition_dec( struct cell v[], int *llen, int *rlen, int *ll, int *lr, int *rl, int *rr, int p, int l, int r ) -{ -#define iswap(a,b) { int itmp = (a); a = (b); b = itmp; } - -*ll = l; -*rr = r; -while ( 1 ) { - if ( l < p ) { - if ( v[l].index < v[p].index ) { - iswap( v[l].index, v[p].index ) - iswap( v[l].item, v[p].item ) - p = l; - } else { - l++; - } - } else { - if ( r > p ) { - if ( v[r].index > v[p].index ) { - iswap( v[r].index, v[p].index ) - iswap( v[r].item, v[p].item ) - p = r; - l++; - } else { - r--; - } - } else { - *lr = p - 1; - *rl = p + 1; - *llen = *lr - *ll + 1; - *rlen = *rr - *rl + 1; - break; - } - } -} -} /***********************************************************************/ /******************************************************** @@ -236,80 +131,6 @@ sorted, a left subscript pointing to where the sort is to begin in the index ar subscript where to end. This module invokes a decreasing quick-sort sorting the index array from l to r. ********************************************************/ /* return values: 0 == successful, 1 == error */ -static int qsort_decreasing( struct cell v[], int left, int right ) -{ -int pivot; -int llen, rlen; -int lleft, lright, rleft, rright; - - -if ( pushstack( left )) - return 1; -if ( pushstack( right )) - return 2; -while ( stack_pointer != stack ) { - if (popstack(&right)) - return 3; - if (popstack(&left )) - return 4; - if ( right - left > 0 ) { - pivot = select_pivot( v, left, right ); - partition_dec( v, &llen, &rlen, &lleft, &lright, &rleft, &rright, pivot, left, right ); - if ( llen > rlen ) { - if ( pushstack( lleft )) - return 5; - if ( pushstack( lright )) - return 6; - if ( pushstack( rleft )) - return 7; - if ( pushstack( rright )) - return 8; - } else{ - if ( pushstack( rleft )) - return 9; - if ( pushstack( rright )) - return 10; - if ( pushstack( lleft )) - return 11; - if ( pushstack( lright )) - return 12; - } - } -} -return 0; -} /***********************************************************************/ /* return values: 0 == successful, 1 == error */ -int sort_order_decreasing( - int values[], /* INPUT: the unsorted values themselves */ - int num, /* INPUT: the number of values */ - int order[] /* OUTPUT: the order for each of the values if sorted */ - ) -{ -int i; -struct cell * cells; - - -cells = (struct cell *) malloc( num * sizeof(struct cell) ); -if ( cells == (struct cell *) NULL ){ - fprintf( stderr, "%s: ERROR: malloc(): struct cell\n", get_progname() ); - return 1; -} - -for( i = 0; i < num; i++ ) { - cells[i].index = values[i]; - cells[i].item = i; -} - -if ( qsort_decreasing( cells, 0, num-1 ) < 0) - return 2; - -for( i = 0; i < num; i++ ) { - order[i] = cells[i].item; -} - -free( (void *) cells ); - -return 0; -} diff --git a/libfprint/nbis/include/bozorth.h b/libfprint/nbis/include/bozorth.h index dbac4094..08ec4b1c 100644 --- a/libfprint/nbis/include/bozorth.h +++ b/libfprint/nbis/include/bozorth.h @@ -1,23 +1,43 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -163,7 +183,7 @@ struct cell { }; /**************************************************************************/ -/* In BZ_IO : Supports the loading and manipulation of XYT data */ +/* In BZ_IO : Supports the loading and manipulation of XYT and XYTQ data */ /**************************************************************************/ #define MAX_FILE_MINUTIAE 1000 /* bz_load() */ @@ -174,7 +194,17 @@ struct xyt_struct { int thetacol[ MAX_BOZORTH_MINUTIAE ]; }; +struct xytq_struct { + int nrows; + int xcol[ MAX_FILE_MINUTIAE ]; + int ycol[ MAX_FILE_MINUTIAE ]; + int thetacol[ MAX_FILE_MINUTIAE ]; + int qualitycol[ MAX_FILE_MINUTIAE ]; +}; + + #define XYT_NULL ( (struct xyt_struct *) NULL ) /* bz_load() */ +#define XYTQ_NULL ( (struct xytq_struct *) NULL ) /* bz_load() */ /**************************************************************************/ @@ -187,6 +217,8 @@ struct xyt_struct { /**************************************************************************/ /* Globals supporting command line options */ extern int verbose_threshold; +/* Global supporting error reporting */ +extern FILE *stderr; /**************************************************************************/ /* In: BZ_GBLS.C */ @@ -247,6 +279,7 @@ extern char *get_next_file(char *, FILE *, FILE *, int *, int *, char *, extern char *get_score_filename(const char *, const char *); extern char *get_score_line(const char *, const char *, int, int, const char *); extern struct xyt_struct *bz_load(const char *); +extern struct xyt_struct *bz_prune(struct xytq_struct *, int); extern int fd_readable(int); /* In: BZ_SORT.C */ extern int sort_quality_decreasing(const void *, const void *); diff --git a/libfprint/nbis/include/bz_array.h b/libfprint/nbis/include/bz_array.h index 19b7da09..296f6746 100644 --- a/libfprint/nbis/include/bz_array.h +++ b/libfprint/nbis/include/bz_array.h @@ -1,23 +1,43 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ diff --git a/libfprint/nbis/include/defs.h b/libfprint/nbis/include/defs.h index 1e982d04..f2953d36 100644 --- a/libfprint/nbis/include/defs.h +++ b/libfprint/nbis/include/defs.h @@ -1,23 +1,43 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -53,7 +73,6 @@ identified are necessarily the best available for the purpose. #define min(a, b) ((a) < (b) ? (a) : (b)) #define sround(x) ((int) (((x)<0) ? (x)-0.5 : (x)+0.5)) #define sround_uint(x) ((unsigned int) (((x)<0) ? (x)-0.5 : (x)+0.5)) -#define xor(a, b) (!(a && b) && (a || b)) #define align_to_16(_v_) ((((_v_)+15)>>4)<<4) #define align_to_32(_v_) ((((_v_)+31)>>5)<<5) #ifndef CHUNKS diff --git a/libfprint/nbis/include/lfs.h b/libfprint/nbis/include/lfs.h index 9ff01b22..ae7aee5c 100644 --- a/libfprint/nbis/include/lfs.h +++ b/libfprint/nbis/include/lfs.h @@ -1,23 +1,43 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ @@ -33,6 +53,9 @@ identified are necessarily the best available for the purpose. Comments added to guide changes to blocksize or number of detected directions. UPDATED: 03/11/2005 by MDG + UPDATED: 01/31/2008 by Kenneth Ko + UPDATED: 09/04/2008 by Kenneth Ko + UPDATED: 01/11/2012 by Kenneth Ko FILE: LFS.H @@ -160,7 +183,7 @@ typedef struct shape{ /* Parameters used by LFS for setting thresholds and */ /* defining testing criterion. */ -typedef struct lfsparms{ +typedef struct g_lfsparms{ /* Image Controls */ int pad_value; int join_line_radius; @@ -236,8 +259,6 @@ typedef struct lfsparms{ int pores_steps_bwd; double pores_min_dist2; double pores_max_ratio; - int remove_perimeter_pts; - int min_pp_distance; /* Ridge Counting Controls */ int max_nbrs; @@ -382,7 +403,7 @@ typedef struct lfsparms{ /* Thresholds and factors used by HO39. Renamed */ /* here to give more meaning. */ /* HO39 Name=Value */ -/* Minimum DFT power allowable in any one direction. */ +/* Minimum DFT power allowable in any one direction. */ #define POWMAX_MIN 100000.0 /* thrhf=1e5f */ /* Minimum normalized power allowable in any one */ @@ -587,9 +608,6 @@ typedef struct lfsparms{ /* contour points to be considered a pore. */ #define PORES_MAX_RATIO 2.25 -/* Points which are closer than this distance to scan perimeter will be removed */ -#define PERIMETER_PTS_DISTANCE 10 - /***** RIDGE COUNTING CONSTANTS *****/ @@ -689,15 +707,24 @@ typedef struct lfsparms{ /*************************************************************************/ /* binar.c */ +extern int binarize(unsigned char **, int *, int *, + unsigned char *, const int, const int, + int *, const int, const int, + const ROTGRIDS *, const LFSPARMS *); extern int binarize_V2(unsigned char **, int *, int *, unsigned char *, const int, const int, int *, const int, const int, const ROTGRIDS *, const LFSPARMS *); +extern int binarize_image(unsigned char **, int *, int *, + unsigned char *, const int, const int, + const int *, const int, const int, const int, + const ROTGRIDS *, const int); extern int binarize_image_V2(unsigned char **, int *, int *, unsigned char *, const int, const int, const int *, const int, const int, const int, const ROTGRIDS *); extern int dirbinarize(const unsigned char *, const int, const ROTGRIDS *); +extern int isobinarize(unsigned char *, const int, const int, const int); /* block.c */ extern int block_offsets(int **, int *, int *, const int, const int, @@ -709,9 +736,12 @@ extern int find_valid_block(int *, int *, int *, int *, int *, const int, const int); extern void set_margin_blocks(int *, const int, const int, const int); +/* chaincod.c */ +extern int chain_code_loop(int **, int *, const int *, const int *, const int); +extern int is_chain_clockwise(const int *, const int, const int); + /* contour.c */ -int allocate_contour(int **ocontour_x, int **ocontour_y, - int **ocontour_ex, int **ocontour_ey, const int ncontour); +extern int allocate_contour(int **, int **, int **, int **, const int); extern void free_contour(int *, int *, int *, int *); extern int get_high_curvature_contour(int **, int **, int **, int **, int *, const int, const int, const int, const int, const int, @@ -726,6 +756,11 @@ extern int trace_contour(int **, int **, int **, int **, int *, extern int search_contour(const int, const int, const int, const int, const int, const int, const int, const int, unsigned char *, const int, const int); +extern int next_contour_pixel(int *, int *, int *, int *, + const int, const int, const int, const int, const int, + unsigned char *, const int, const int); +extern int start_scan_nbr(const int, const int, const int, const int); +extern int next_scan_nbr(const int, const int); extern int min_contour_theta(int *, double *, const int, const int *, const int *, const int); extern void contour_limits(int *, int *, int *, int *, const int *, @@ -734,18 +769,29 @@ extern void fix_edge_pixel_pair(int *, int *, int *, int *, unsigned char *, const int, const int); /* detect.c */ -extern int get_minutiae(MINUTIAE **, int **, int **, int **, - int **, int **, int *, int *, - unsigned char **, int *, int *, int *, - unsigned char *, const int, const int, - const int, const double, const LFSPARMS *); +extern int lfs_detect_minutiae( MINUTIAE **, + int **, int **, int *, int *, + unsigned char **, int *, int *, + unsigned char *, const int, const int, + const LFSPARMS *); + +extern int lfs_detect_minutiae_V2(MINUTIAE **, + int **, int **, int **, int **, int *, int *, + unsigned char **, int *, int *, + unsigned char *, const int, const int, + const LFSPARMS *); /* dft.c */ extern int dft_dir_powers(double **, unsigned char *, const int, const int, const int, const DFTWAVES *, const ROTGRIDS *); +extern void sum_rot_block_rows(int *, const unsigned char *, const int *, + const int); +extern void dft_power(double *, const int *, const DFTWAVE *, const int); extern int dft_power_stats(int *, double *, int *, double *, double **, const int, const int, const int); +extern void get_max_norm(double *, int *, double *, const double *, const int); +extern int sort_dft_waves(int *, const double *, const double *, const int); /* free.c */ extern void free_dir2rad(DIR2RAD *); @@ -753,6 +799,13 @@ extern void free_dftwaves(DFTWAVES *); extern void free_rotgrids(ROTGRIDS *); extern void free_dir_powers(double **, const int); +/* getmin.c */ +extern int get_minutiae(MINUTIAE **, int **, int **, int **, + int **, int **, int *, int *, + unsigned char **, int *, int *, int *, + unsigned char *, const int, const int, + const int, const double, const LFSPARMS *); + /* imgutil.c */ extern void bits_6to8(unsigned char *, const int, const int); extern void bits_8to6(unsigned char *, const int, const int); @@ -771,15 +824,41 @@ extern int search_in_direction(int *, int *, int *, int *, const int, /* init.c */ extern int init_dir2rad(DIR2RAD **, const int); extern int init_dftwaves(DFTWAVES **, const double *, const int, const int); +extern int get_max_padding(const int, const int, const int, const int); extern int get_max_padding_V2(const int, const int, const int, const int); extern int init_rotgrids(ROTGRIDS **, const int, const int, const int, const double, const int, const int, const int, const int); extern int alloc_dir_powers(double ***, const int, const int); extern int alloc_power_stats(int **, double **, int **, double **, const int); +/* isempty.c */ +extern int is_image_empty(int *, const int, const int); +extern int is_qmap_empty(int *, const int, const int); + + /* line.c */ extern int line_points(int **, int **, int *, const int, const int, const int, const int); +extern int bresenham_line_points(int **, int **, int *, + const int, const int, const int, const int); + +/* link.c */ +extern int link_minutiae(MINUTIAE *, unsigned char *, const int, const int, + int *, const int, const int, const LFSPARMS *); +extern int create_link_table(int **, int **, int **, int *, int *, int *, + const int, const int, const MINUTIAE *, const int *, + int *, const int, const int, unsigned char *, + const int, const int, const LFSPARMS *); +extern int update_link_table(int *, int *, int *, int *, int *, int *, + const int, int *, int *, int *, int *, + const int, const int, const int); +extern int order_link_table(int *, int *, int *, const int, const int, + const int, const int, const MINUTIAE *, const int); +extern int process_link_table(const int *, const int *, const int *, + const int, const int, const int, const int, MINUTIAE *, + int *, unsigned char *, const int, const int, + const LFSPARMS *); +extern double link_score(const double, const double, const LFSPARMS *); /* loop.c */ extern int get_loop_list(int **, MINUTIAE *, const int, unsigned char *, @@ -799,8 +878,16 @@ extern int process_loop_V2(MINUTIAE *, const int *, const int *, const int *, const int *, const int, unsigned char *, const int, const int, int *, const LFSPARMS *); +extern void get_loop_aspect(int *, int *, double *, int *, int *, double *, + const int *, const int *, const int); extern int fill_loop(const int *, const int *, const int, unsigned char *, const int, const int); +extern void fill_partial_row(const int, const int, const int, const int, + unsigned char *, const int, const int); +extern void flood_loop(const int *, const int *, const int, + unsigned char *, const int, const int); +extern void flood_fill4(const int, const int, const int, + unsigned char *, const int, const int); /* maps.c */ extern int gen_image_maps(int **, int **, int **, int **, int *, int *, @@ -820,6 +907,10 @@ extern void smooth_direction_map(int *, int *, const int, const int, const DIR2RAD *, const LFSPARMS *); extern int gen_high_curve_map(int **, int *, const int, const int, const LFSPARMS *); +extern int gen_imap(int **, int *, int *, + unsigned char *, const int, const int, + const DIR2RAD *, const DFTWAVES *, const ROTGRIDS *, + const LFSPARMS *); extern int gen_initial_imap(int **, int *, const int, const int, unsigned char *, const int, const int, const DFTWAVES *, const ROTGRIDS *, const LFSPARMS *); @@ -850,6 +941,7 @@ extern void average_8nbr_dir(int *, double *, int *, int *, const int, extern int num_valid_8nbrs(int *, const int, const int, const int, const int); extern void smooth_imap(int *, const int, const int, const DIR2RAD *, const LFSPARMS *); +extern int gen_nmap(int **, int *, const int, const int, const LFSPARMS *); extern int vorticity(int *, const int, const int, const int, const int, const int); extern void accum_nbr_vorticity(int *, const int, const int, const int); @@ -868,6 +960,9 @@ extern void skip_repeated_vertical_pair(int *, const int, /* minutia.c */ extern int alloc_minutiae(MINUTIAE **, const int); extern int realloc_minutiae(MINUTIAE *, const int); +extern int detect_minutiae(MINUTIAE *, unsigned char *, const int, const int, + const int *, const int *, const int, const int, + const LFSPARMS *); extern int detect_minutiae_V2(MINUTIAE *, unsigned char *, const int, const int, int *, int *, int *, const int, const int, @@ -972,8 +1067,6 @@ extern int adjust_high_curvature_minutia_V2(int *, int *, int *, int *, MINUTIAE *, const LFSPARMS *); extern int get_low_curvature_direction(const int, const int, const int, const int); -void lfs2nist_minutia_XYT(int *ox, int *oy, int *ot, - const MINUTIA *minutia, const int iw, const int ih); /* quality.c */ extern int gen_quality_map(int **, int *, int *, int *, int *, @@ -981,6 +1074,12 @@ extern int gen_quality_map(int **, int *, int *, int *, int *, extern int combined_minutia_quality(MINUTIAE *, int *, const int, const int, const int, unsigned char *, const int, const int, const int, const double); +double grayscale_reliability(MINUTIA *, unsigned char *, + const int, const int, const int); +extern void get_neighborhood_stats(double *, double *, MINUTIA *, + unsigned char *, const int, const int, const int); +extern int reliability_fr_quality_map(MINUTIAE *, int *, const int, + const int, const int, const int, const int); /* remove.c */ extern int remove_false_minutia(MINUTIAE *, @@ -990,15 +1089,93 @@ extern int remove_false_minutia_V2(MINUTIAE *, unsigned char *, const int, const int, int *, int *, int *, const int, const int, const LFSPARMS *); +extern int remove_holes(MINUTIAE *, unsigned char *, const int, const int, + const LFSPARMS *); +extern int remove_hooks(MINUTIAE *, + unsigned char *, const int, const int, const LFSPARMS *); +extern int remove_hooks_islands_lakes_overlaps(MINUTIAE *, unsigned char *, + const int, const int, const LFSPARMS *); +extern int remove_islands_and_lakes(MINUTIAE *, + unsigned char *, const int, const int, const LFSPARMS *); +extern int remove_malformations(MINUTIAE *, + unsigned char *, const int, const int, + int *, const int, const int, const LFSPARMS *); +extern int remove_near_invblock(MINUTIAE *, int *, const int, const int, + const LFSPARMS *); +extern int remove_near_invblock_V2(MINUTIAE *, int *, + const int, const int, const LFSPARMS *); +extern int remove_pointing_invblock(MINUTIAE *, int *, const int, const int, + const LFSPARMS *); +extern int remove_pointing_invblock_V2(MINUTIAE *, + int *, const int, const int, const LFSPARMS *); +extern int remove_overlaps(MINUTIAE *, + unsigned char *, const int, const int, const LFSPARMS *); +extern int remove_pores(MINUTIAE *, + unsigned char *, const int, const int, + int *, const int, const int, const LFSPARMS *); +extern int remove_pores_V2(MINUTIAE *, + unsigned char *, const int, const int, + int *, int *, int *, const int, const int, + const LFSPARMS *); +extern int remove_or_adjust_side_minutiae(MINUTIAE *, unsigned char *, + const int, const int, const LFSPARMS *); +extern int remove_or_adjust_side_minutiae_V2(MINUTIAE *, + unsigned char *, const int, const int, + int *, const int, const int, const LFSPARMS *); + +/* results.c */ +extern int write_text_results(char *, const int, const int, const int, + const MINUTIAE *, int *, int *, int *, int *, int *, + const int, const int); +extern int write_minutiae_XYTQ(char *ofile, const int, + const MINUTIAE *, const int, const int); +extern void dump_map(FILE *, int *, const int, const int); +extern int drawimap(int *, const int, const int, unsigned char *, + const int, const int, const ROTGRIDS *, const int); +extern void drawimap2(int *, const int *, const int, const int, + unsigned char *, const int, const int, + const double, const int, const int); +extern void drawblocks(const int *, const int, const int, + unsigned char *, const int, const int, const int ); +extern int drawrotgrid(const ROTGRIDS *, const int, unsigned char *, + const int, const int, const int, const int); +extern void dump_link_table(FILE *, const int *, const int *, const int *, + const int, const int, const int, const MINUTIAE *); +extern int draw_direction_map(char *, int *, + int *, const int, const int, const int, + unsigned char *, const int, const int, const int); +extern int draw_TF_map(char *, int *, + int *, const int, const int, const int, + unsigned char *, const int, const int, const int); /* ridges.c */ extern int count_minutiae_ridges(MINUTIAE *, unsigned char *, const int, const int, const LFSPARMS *); +extern int count_minutia_ridges(const int, MINUTIAE *, + unsigned char *, const int, const int, + const LFSPARMS *); +extern int find_neighbors(int **, int *, const int, const int, MINUTIAE *); +extern int update_nbr_dists(int *, double *, int *, const int, + const int, const int, MINUTIAE *); +extern int insert_neighbor(const int, const int, const double, + int *, double *, int *, const int); +extern int sort_neighbors(int *, const int, const int, MINUTIAE *); +extern int ridge_count(const int, const int, MINUTIAE *, + unsigned char *, const int, const int, const LFSPARMS *); +extern int find_transition(int *, const int, const int, + const int *, const int *, const int, + unsigned char *, const int, const int); +extern int validate_ridge_crossing(const int, const int, + const int *, const int *, const int, + unsigned char *, const int, const int, const int); /* shape.c */ +extern int alloc_shape(SHAPE **, const int, const int, const int, const int); extern void free_shape(SHAPE *); +extern void dump_shape(FILE *, const SHAPE *); extern int shape_from_contour(SHAPE **, const int *, const int *, const int); +extern void sort_row_on_x(ROW *); /* sort.c */ extern int sort_indices_int_inc(int **, int *, const int); @@ -1023,6 +1200,12 @@ extern int line2direction(const int, const int, const int, const int, const int); extern int closest_dir_dist(const int, const int, const int); +/* xytreps.c */ +extern void lfs2nist_minutia_XYT(int *, int *, int *, + const MINUTIA *, const int, const int); +extern void lfs2m1_minutia_XYT(int *, int *, int *, const MINUTIA *); +extern void lfs2nist_format(MINUTIAE *, int, int); + /*************************************************************************/ /* EXTERNAL GLOBAL VARIABLE DEFINITIONS */ /*************************************************************************/ diff --git a/libfprint/nbis/include/log.h b/libfprint/nbis/include/log.h index a9cd6030..4fd7e75b 100644 --- a/libfprint/nbis/include/log.h +++ b/libfprint/nbis/include/log.h @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + #ifndef _LOG_H #define _LOG_H @@ -36,10 +57,6 @@ identified are necessarily the best available for the purpose. #define LOG_FILE "log.txt" #endif -extern FILE *g_logfp; -extern int g_avrdir; -extern float g_dir_strength; -extern int g_nvalid; extern int open_logfile(void); extern int close_logfile(void); diff --git a/libfprint/nbis/include/morph.h b/libfprint/nbis/include/morph.h index 782d331b..944bd2aa 100644 --- a/libfprint/nbis/include/morph.h +++ b/libfprint/nbis/include/morph.h @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + #ifndef __MORPH_H__ #define __MORPH_H__ diff --git a/libfprint/nbis/include/mytime.h b/libfprint/nbis/include/mytime.h new file mode 100644 index 00000000..e052a251 --- /dev/null +++ b/libfprint/nbis/include/mytime.h @@ -0,0 +1,106 @@ +/******************************************************************************* + +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. + +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. + +*******************************************************************************/ + + +#ifndef _MYTIME_H +#define _MYTIME_H + +/* this file needed to support timer and ticks */ +/* UPDATED: 03/16/2005 by MDG */ + +#ifdef TIMER +#include +#endif + +#ifdef __MSYS__ +#include +#else +#include +#endif + +#ifdef TIMER +#define set_timer(_timer_); \ + { \ + _timer_ = ticks(); +#else +#define set_timer(_timer_); +#endif + +#ifdef TIMER +#define time_accum(_timer_, _var_); \ + _var_ += (ticks() - _timer_)/(float)ticksPerSec(); \ + } +#else +#define time_accum(_timer_, _var_); +#endif + +#ifdef TIMER +#define print_time(_fp_, _fmt_, _var_); \ + fprintf(_fp_, _fmt_, _var_); +#else +#define print_time(_fp_, _fmt_, _var_); +#endif + +extern clock_t ticks(void); +extern int ticksPerSec(void); + +extern clock_t total_timer; +extern float total_time; + +extern clock_t imap_timer; +extern float imap_time; + +extern clock_t bin_timer; +extern float bin_time; + +extern clock_t minutia_timer; +extern float minutia_time; + +extern clock_t rm_minutia_timer; +extern float rm_minutia_time; + +extern clock_t ridge_count_timer; +extern float ridge_count_time; + +#endif + diff --git a/libfprint/nbis/include/sunrast.h b/libfprint/nbis/include/sunrast.h index 3d7deeaa..61c035f4 100644 --- a/libfprint/nbis/include/sunrast.h +++ b/libfprint/nbis/include/sunrast.h @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + #ifndef _SUNRAST_H #define _SUNRAST_H diff --git a/libfprint/nbis/mindtct/binar.c b/libfprint/nbis/mindtct/binar.c index 916d56e2..fb2be224 100644 --- a/libfprint/nbis/mindtct/binar.c +++ b/libfprint/nbis/mindtct/binar.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -36,16 +57,44 @@ identified are necessarily the best available for the purpose. *********************************************************************** ROUTINES: + binarize() binarize_V2() + binarize_image() binarize_image_V2() dirbinarize() + isobinarize() ***********************************************************************/ #include -#include #include +/************************************************************************* +************************************************************************** +#cat: binarize - Takes a padded grayscale input image and its associated ridge +#cat: direction flow NMAP and produces a binarized version of the +#cat: image. It then fills horizontal and vertical "holes" in the +#cat: binary image results. + + Input: + pdata - padded input grayscale image + pw - padded width (in pixels) of input image + ph - padded height (in pixels) of input image + nmap - 2-D vector of IMAP directions and other codes + mw - width (in blocks) of the NMAP + mh - height (in blocks) of the NMAP + dirbingrids - set of rotated grid offsets used for directional + binarization + lfsparms - parameters and thresholds for controlling LFS + Output: + optr - points to created (unpadded) binary image + ow - width of binary image + oh - height of binary image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: binarize_V2 - Takes a padded grayscale input image and its associated @@ -101,6 +150,32 @@ int binarize_V2(unsigned char **odata, int *ow, int *oh, return(0); } +/************************************************************************* +************************************************************************** +#cat: binarize_image - Takes a grayscale input image and its associated +#cat: NMAP and generates a binarized version of the image. + + Input: + pdata - padded input grayscale image + pw - padded width (in pixels) of input image + ph - padded height (in pixels) of input image + nmap - 2-D vector of IMAP directions and other codes + mw - width (in blocks) of the NMAP + mh - height (in blocks) of the NMAP + imap_blocksize - dimension (in pixels) of each NMAP block + dirbingrids - set of rotated grid offsets used for directional + binarization + isobin_grid_dim - dimension (in pixels) of grid used for isotropic + binarization + Output: + optr - points to binary image results + ow - points to binary image width + oh - points to binary image height + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: binarize_image_V2 - Takes a grayscale input image and its associated @@ -247,3 +322,27 @@ int dirbinarize(const unsigned char *pptr, const int idir, return(WHITE_PIXEL); } +/************************************************************************* +************************************************************************** +#cat: isobinarize - Determines the binary value of a grayscale pixel based +#cat: on comparing the grayscale value with a surrounding +#cat: neighborhood grid of pixels. If the current pixel (treated +#cat: as an average) is less than the sum of the pixels in +#cat: the neighborhood, then the binary value is set to BLACK, +#cat: otherwise it is set to WHITE. This binarization technique +#cat: is used when there is no VALID IMAP direction for the +#cat: block in which the current pixel resides. + + CAUTION: The image to which the input pixel points must be appropriately + padded to account for the radius of the neighborhood. Otherwise, + this routine may access "unkown" memory. + + Input: + pptr - pointer to curent grayscale pixel + pw - padded width (in pixels) of the grayscale image + ph - padded height (in pixels) of the grayscale image + isobin_grid_dim - dimension (in pixels) of the neighborhood + Return Code: + BLACK_PIXEL - pixel intensity for BLACK + WHITE_PIXEL - pixel intensity of WHITE +**************************************************************************/ diff --git a/libfprint/nbis/mindtct/block.c b/libfprint/nbis/mindtct/block.c index be0b3f97..761f332d 100644 --- a/libfprint/nbis/mindtct/block.c +++ b/libfprint/nbis/mindtct/block.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -44,8 +65,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include -#include #include /************************************************************************* @@ -86,7 +105,7 @@ int block_offsets(int **optr, int *ow, int *oh, int *blkoffs, bx, by, bw, bh, bi, bsize; int blkrow_start, blkrow_size, offset; int lastbw, lastbh; - int pad2, pw; + int pad2, pw, ph; /* Test if unpadded image is smaller than a single block */ if((iw < blocksize) || (ih < blocksize)){ @@ -99,6 +118,7 @@ int block_offsets(int **optr, int *ow, int *oh, /* Compute padded width and height of image */ pad2 = pad<<1; pw = iw + pad2; + ph = ih + pad2; /* Compute the number of columns and rows of blocks in the image. */ /* Take the ceiling to account for "leftovers" at the right and */ diff --git a/libfprint/nbis/mindtct/chaincod.c b/libfprint/nbis/mindtct/chaincod.c new file mode 100644 index 00000000..dd5d779c --- /dev/null +++ b/libfprint/nbis/mindtct/chaincod.c @@ -0,0 +1,211 @@ +/******************************************************************************* + +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. + +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. + +*******************************************************************************/ + + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: CHAINCODE.C + AUTHOR: Michael D. Garris + DATE: 05/11/1999 + + Contains routines responsible for generating and manipulating + chain codes as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + chain_code_loop() + is_chain_clockwise() +***********************************************************************/ + +#include +#include + +/************************************************************************* +************************************************************************** +#cat: chain_code_loop - Converts a feature's contour points into an +#cat: 8-connected chain code vector. This encoding represents +#cat: the direction taken between each adjacent point in the +#cat: contour. Chain codes may be used for many purposes, such +#cat: as computing the perimeter or area of an object, and they +#cat: may be used in object detection and recognition. + + Input: + contour_x - x-coord list for feature's contour points + contour_y - y-coord list for feature's contour points + ncontour - number of points in contour + Output: + ochain - resulting vector of chain codes + onchain - number of codes in chain + (same as number of points in contour) + Return Code: + Zero - chain code successful derived + Negative - system error +**************************************************************************/ +int chain_code_loop(int **ochain, int *onchain, + const int *contour_x, const int *contour_y, const int ncontour) +{ + int *chain; + int i, j, dx, dy; + + /* If we don't have at least 3 points in the contour ... */ + if(ncontour <= 3){ + /* Then we don't have a loop, so set chain length to 0 */ + /* and return without any allocations. */ + *onchain = 0; + return(0); + } + + /* Allocate chain code vector. It will be the same length as the */ + /* number of points in the contour. There will be one chain code */ + /* between each point on the contour including a code between the */ + /* last to the first point on the contour (completing the loop). */ + chain = (int *)malloc(ncontour * sizeof(int)); + /* If the allocation fails ... */ + if(chain == (int *)NULL){ + fprintf(stderr, "ERROR : chain_code_loop : malloc : chain\n"); + return(-170); + } + + /* For each neighboring point in the list (with "i" pointing to the */ + /* previous neighbor and "j" pointing to the next neighbor... */ + for(i = 0, j=1; i < ncontour-1; i++, j++){ + /* Compute delta in X between neighbors. */ + dx = contour_x[j] - contour_x[i]; + /* Compute delta in Y between neighbors. */ + dy = contour_y[j] - contour_y[i]; + /* Derive chain code index from neighbor deltas. */ + /* The deltas are on the range [-1..1], so to use them as indices */ + /* into the code list, they must first be incremented by one. */ + chain[i] = *(g_chaincodes_nbr8+((dy+1)*NBR8_DIM)+dx+1); + } + + /* Now derive chain code between last and first points in the */ + /* contour list. */ + dx = contour_x[0] - contour_x[i]; + dy = contour_y[0] - contour_y[i]; + chain[i] = *(g_chaincodes_nbr8+((dy+1)*NBR8_DIM)+dx+1); + + /* Store results to the output pointers. */ + *ochain = chain; + *onchain = ncontour; + + /* Return normally. */ + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: is_chain_clockwise - Takes an 8-connected chain code vector and +#cat: determines if the codes are ordered clockwise or +#cat: counter-clockwise. +#cat: The routine also requires a default return value be +#cat: specified in the case the the routine is not able to +#cat: definitively determine the chains direction. This allows +#cat: the default response to be application-specific. + + Input: + chain - chain code vector + nchain - number of codes in chain + default_ret - default return code (used when we can't tell the order) + Return Code: + TRUE - chain determined to be ordered clockwise + FALSE - chain determined to be ordered counter-clockwise + Default - could not determine the order of the chain +**************************************************************************/ +int is_chain_clockwise(const int *chain, const int nchain, + const int default_ret) +{ + int i, j, d, sum; + + /* Initialize turn-accumulator to 0. */ + sum = 0; + + /* Foreach neighboring code in chain, compute the difference in */ + /* direction and accumulate. Left-hand turns increment, whereas */ + /* right-hand decrement. */ + for(i = 0, j =1; i < nchain-1; i++, j++){ + /* Compute delta in neighbor direction. */ + d = chain[j] - chain[i]; + /* Make the delta the "inner" distance. */ + /* If delta >= 4, for example if chain_i==2 and chain_j==7 (which */ + /* means the contour went from a step up to step down-to-the-right) */ + /* then 5=(7-2) which is >=4, so -3=(5-8) which means that the */ + /* change in direction is a righ-hand turn of 3 units). */ + if(d >= 4) + d -= 8; + /* If delta <= -4, for example if chain_i==7 and chain_j==2 (which */ + /* means the contour went from a step down-to-the-right to step up) */ + /* then -5=(2-7) which is <=-4, so 3=(-5+8) which means that the */ + /* change in direction is a left-hand turn of 3 units). */ + else if (d <= -4) + d += 8; + + /* The delta direction is then accumulated. */ + sum += d; + } + + /* Now we need to add in the final delta direction between the last */ + /* and first codes in the chain. */ + d = chain[0] - chain[i]; + if(d >= 4) + d -= 8; + else if (d <= -4) + d += 8; + sum += d; + + /* If the final turn_accumulator == 0, then we CAN'T TELL the */ + /* direction of the chain code, so return the default return value. */ + if(sum == 0) + return(default_ret); + /* Otherwise, if the final turn-accumulator is positive ... */ + else if(sum > 0) + /* Then we had a greater amount of left-hand turns than right-hand */ + /* turns, so the chain is in COUNTER-CLOCKWISE order, so return FALSE. */ + return(FALSE); + /* Otherwise, the final turn-accumulator is negative ... */ + else + /* So we had a greater amount of right-hand turns than left-hand */ + /* turns, so the chain is in CLOCKWISE order, so return TRUE. */ + return(TRUE); +} diff --git a/libfprint/nbis/mindtct/contour.c b/libfprint/nbis/mindtct/contour.c index 92e77f50..689ffafb 100644 --- a/libfprint/nbis/mindtct/contour.c +++ b/libfprint/nbis/mindtct/contour.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -50,7 +71,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include /************************************************************************* @@ -591,236 +611,6 @@ int get_centered_contour(int **ocontour_x, int **ocontour_y, return(0); } -/************************************************************************* -************************************************************************** -#cat: start_scan_nbr - Takes a two pixel coordinates that are either -#cat: aligned north-to-south or east-to-west, and returns the -#cat: position the second pixel is in realtionship to the first. -#cat: The positions returned are based on 8-connectedness. -#cat: NOTE, this routine does NOT account for diagonal positions. - - Input: - x_prev - x-coord of first point - y_prev - y-coord of first point - x_next - x-coord of second point - y_next - y-coord of second point - Return Code: - NORTH - second pixel above first - SOUTH - second pixel below first - EAST - second pixel right of first - WEST - second pixel left of first -**************************************************************************/ -static int start_scan_nbr(const int x_prev, const int y_prev, - const int x_next, const int y_next) -{ - if((x_prev==x_next) && (y_next > y_prev)) - return(SOUTH); - else if ((x_prev==x_next) && (y_next < y_prev)) - return(NORTH); - else if ((x_next > x_prev) && (y_prev==y_next)) - return(EAST); - else if ((x_next < x_prev) && (y_prev==y_next)) - return(WEST); - - /* Added by MDG on 03-16-05 */ - /* Should never reach here. Added to remove compiler warning. */ - return(INVALID_DIR); /* -1 */ -} - -/************************************************************************* -************************************************************************** -#cat: next_scan_nbr - Advances the given 8-connected neighbor index -#cat: on location in the specifiec direction (clockwise or -#cat: counter-clockwise). - - Input: - nbr_i - current 8-connected neighbor index - scan_clock - direction in which the neighbor index is to be advanced - Return Code: - Next neighbor - 8-connected index of next neighbor -**************************************************************************/ -static int next_scan_nbr(const int nbr_i, const int scan_clock) -{ - int new_i; - - /* If scanning neighbors clockwise ... */ - if(scan_clock == SCAN_CLOCKWISE) - /* Advance one neighbor clockwise. */ - new_i = (nbr_i+1)%8; - /* Otherwise, scanning neighbors counter-clockwise ... */ - else - /* Advance one neighbor counter-clockwise. */ - /* There are 8 pixels in the neighborhood, so to */ - /* decrement with wrapping from 0 around to 7, add */ - /* the nieghbor index by 7 and mod with 8. */ - new_i = (nbr_i+7)%8; - - /* Return the new neighbor index. */ - return(new_i); -} - -/************************************************************************* -************************************************************************** -#cat: next_contour_pixel - Takes a pixel coordinate of a point determined -#cat: to be on the interior edge of a feature (ridge or valley- -#cat: ending), and attempts to locate a neighboring pixel on the -#cat: feature's contour. Neighbors of the current feature pixel -#cat: are searched in a specified direction (clockwise or counter- -#cat: clockwise) and the first pair of adjacent/neigboring pixels -#cat: found with the first pixel having the color of the feature -#cat: and the second the opposite color are returned as the next -#cat: point on the contour. One exception happens when the new -#cat: point is on an "exposed" corner. - - Input: - cur_x_loc - x-pixel coord of current point on feature's - interior contour - cur_y_loc - y-pixel coord of current point on feature's - interior contour - cur_x_edge - x-pixel coord of corresponding edge pixel - (exterior to feature) - cur_y_edge - y-pixel coord of corresponding edge pixel - (exterior to feature) - scan_clock - direction in which neighboring pixels are to be scanned - for the next contour pixel - bdata - binary image data (0==while & 1==black) - iw - width (in pixels) of image - ih - height (in pixels) of image - Output: - next_x_loc - x-pixel coord of next point on feature's interior contour - next_y_loc - y-pixel coord of next point on feature's interior contour - next_x_edge - x-pixel coord of corresponding edge (exterior to feature) - next_y_edge - y-pixel coord of corresponding edge (exterior to feature) - Return Code: - TRUE - next contour point found and returned - FALSE - next contour point NOT found -**************************************************************************/ -/*************************************************************************/ -static int next_contour_pixel(int *next_x_loc, int *next_y_loc, - int *next_x_edge, int *next_y_edge, - const int cur_x_loc, const int cur_y_loc, - const int cur_x_edge, const int cur_y_edge, - const int scan_clock, - unsigned char *bdata, const int iw, const int ih) -{ - int feature_pix, edge_pix; - int prev_nbr_pix, prev_nbr_x, prev_nbr_y; - int cur_nbr_pix, cur_nbr_x, cur_nbr_y; - int ni, nx, ny, npix; - int nbr_i, i; - - /* Get the feature's pixel value. */ - feature_pix = *(bdata + (cur_y_loc * iw) + cur_x_loc); - /* Get the feature's edge pixel value. */ - edge_pix = *(bdata + (cur_y_edge * iw) + cur_x_edge); - - /* Get the nieghbor position of the feature's edge pixel in relationship */ - /* to the feature's actual position. */ - /* REMEBER: The feature's position is always interior and on a ridge */ - /* ending (black pixel) or (for bifurcations) on a valley ending (white */ - /* pixel). The feature's edge pixel is an adjacent pixel to the feature */ - /* pixel that is exterior to the ridge or valley ending and opposite in */ - /* pixel value. */ - nbr_i = start_scan_nbr(cur_x_loc, cur_y_loc, cur_x_edge, cur_y_edge); - - /* Set current neighbor scan pixel to the feature's edge pixel. */ - cur_nbr_x = cur_x_edge; - cur_nbr_y = cur_y_edge; - cur_nbr_pix = edge_pix; - - /* Foreach pixel neighboring the feature pixel ... */ - for(i = 0; i < 8; i++){ - - /* Set current neighbor scan pixel to previous scan pixel. */ - prev_nbr_x = cur_nbr_x; - prev_nbr_y = cur_nbr_y; - prev_nbr_pix = cur_nbr_pix; - - /* Bump pixel neighbor index clockwise or counter-clockwise. */ - nbr_i = next_scan_nbr(nbr_i, scan_clock); - - /* Set current scan pixel to the new neighbor. */ - /* REMEMBER: the neighbors are being scanned around the original */ - /* feature point. */ - cur_nbr_x = cur_x_loc + g_nbr8_dx[nbr_i]; - cur_nbr_y = cur_y_loc + g_nbr8_dy[nbr_i]; - - /* If new neighbor is not within image boundaries... */ - if((cur_nbr_x < 0) || (cur_nbr_x >= iw) || - (cur_nbr_y < 0) || (cur_nbr_y >= ih)) - /* Return (FALSE==>Failure) if neighbor out of bounds. */ - return(FALSE); - - /* Get the new neighbor's pixel value. */ - cur_nbr_pix = *(bdata + (cur_nbr_y * iw) + cur_nbr_x); - - /* If the new neighbor's pixel value is the same as the feature's */ - /* pixel value AND the previous neighbor's pixel value is the same */ - /* as the features's edge, then we have "likely" found our next */ - /* contour pixel. */ - if((cur_nbr_pix == feature_pix) && (prev_nbr_pix == edge_pix)){ - - /* Check to see if current neighbor is on the corner of the */ - /* neighborhood, and if so, test to see if it is "exposed". */ - /* The neighborhood corners have odd neighbor indicies. */ - if(nbr_i % 2){ - /* To do this, look ahead one more neighbor pixel. */ - ni = next_scan_nbr(nbr_i, scan_clock); - nx = cur_x_loc + g_nbr8_dx[ni]; - ny = cur_y_loc + g_nbr8_dy[ni]; - /* If new neighbor is not within image boundaries... */ - if((nx < 0) || (nx >= iw) || - (ny < 0) || (ny >= ih)) - /* Return (FALSE==>Failure) if neighbor out of bounds. */ - return(FALSE); - npix = *(bdata + (ny * iw) + nx); - - /* If the next neighbor's value is also the same as the */ - /* feature's pixel, then corner is NOT exposed... */ - if(npix == feature_pix){ - /* Assign the current neighbor pair to the output pointers. */ - *next_x_loc = cur_nbr_x; - *next_y_loc = cur_nbr_y; - *next_x_edge = prev_nbr_x; - *next_y_edge = prev_nbr_y; - /* Return TRUE==>Success. */ - return(TRUE); - } - /* Otherwise, corner pixel is "exposed" so skip it. */ - else{ - /* Skip current corner neighbor by resetting it to the */ - /* next neighbor, which upon the iteration will immediately */ - /* become the previous neighbor. */ - cur_nbr_x = nx; - cur_nbr_y = ny; - cur_nbr_pix = npix; - /* Advance neighbor index. */ - nbr_i = ni; - /* Advance neighbor count. */ - i++; - } - } - /* Otherwise, current neighbor is not a corner ... */ - else{ - /* Assign the current neighbor pair to the output pointers. */ - *next_x_loc = cur_nbr_x; - *next_y_loc = cur_nbr_y; - *next_x_edge = prev_nbr_x; - *next_y_edge = prev_nbr_y; - /* Return TRUE==>Success. */ - return(TRUE); - } - } - } - - /* If we get here, then we did not find the next contour pixel */ - /* within the 8 neighbors of the current feature pixel so */ - /* return (FALSE==>Failure). */ - /* NOTE: This must mean we found a single isolated pixel. */ - /* Perhaps this should be filled? */ - return(FALSE); -} - /************************************************************************* ************************************************************************** #cat: trace_contour - Takes the pixel coordinate of a detected minutia @@ -1046,6 +836,236 @@ int search_contour(const int x_search, const int y_search, return(NOT_FOUND); } +/************************************************************************* +************************************************************************** +#cat: next_contour_pixel - Takes a pixel coordinate of a point determined +#cat: to be on the interior edge of a feature (ridge or valley- +#cat: ending), and attempts to locate a neighboring pixel on the +#cat: feature's contour. Neighbors of the current feature pixel +#cat: are searched in a specified direction (clockwise or counter- +#cat: clockwise) and the first pair of adjacent/neigboring pixels +#cat: found with the first pixel having the color of the feature +#cat: and the second the opposite color are returned as the next +#cat: point on the contour. One exception happens when the new +#cat: point is on an "exposed" corner. + + Input: + cur_x_loc - x-pixel coord of current point on feature's + interior contour + cur_y_loc - y-pixel coord of current point on feature's + interior contour + cur_x_edge - x-pixel coord of corresponding edge pixel + (exterior to feature) + cur_y_edge - y-pixel coord of corresponding edge pixel + (exterior to feature) + scan_clock - direction in which neighboring pixels are to be scanned + for the next contour pixel + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + next_x_loc - x-pixel coord of next point on feature's interior contour + next_y_loc - y-pixel coord of next point on feature's interior contour + next_x_edge - x-pixel coord of corresponding edge (exterior to feature) + next_y_edge - y-pixel coord of corresponding edge (exterior to feature) + Return Code: + TRUE - next contour point found and returned + FALSE - next contour point NOT found +**************************************************************************/ +/*************************************************************************/ +int next_contour_pixel(int *next_x_loc, int *next_y_loc, + int *next_x_edge, int *next_y_edge, + const int cur_x_loc, const int cur_y_loc, + const int cur_x_edge, const int cur_y_edge, + const int scan_clock, + unsigned char *bdata, const int iw, const int ih) +{ + int feature_pix, edge_pix; + int prev_nbr_pix, prev_nbr_x, prev_nbr_y; + int cur_nbr_pix, cur_nbr_x, cur_nbr_y; + int ni, nx, ny, npix; + int nbr_i, i; + + /* Get the feature's pixel value. */ + feature_pix = *(bdata + (cur_y_loc * iw) + cur_x_loc); + /* Get the feature's edge pixel value. */ + edge_pix = *(bdata + (cur_y_edge * iw) + cur_x_edge); + + /* Get the nieghbor position of the feature's edge pixel in relationship */ + /* to the feature's actual position. */ + /* REMEBER: The feature's position is always interior and on a ridge */ + /* ending (black pixel) or (for bifurcations) on a valley ending (white */ + /* pixel). The feature's edge pixel is an adjacent pixel to the feature */ + /* pixel that is exterior to the ridge or valley ending and opposite in */ + /* pixel value. */ + nbr_i = start_scan_nbr(cur_x_loc, cur_y_loc, cur_x_edge, cur_y_edge); + + /* Set current neighbor scan pixel to the feature's edge pixel. */ + cur_nbr_x = cur_x_edge; + cur_nbr_y = cur_y_edge; + cur_nbr_pix = edge_pix; + + /* Foreach pixel neighboring the feature pixel ... */ + for(i = 0; i < 8; i++){ + + /* Set current neighbor scan pixel to previous scan pixel. */ + prev_nbr_x = cur_nbr_x; + prev_nbr_y = cur_nbr_y; + prev_nbr_pix = cur_nbr_pix; + + /* Bump pixel neighbor index clockwise or counter-clockwise. */ + nbr_i = next_scan_nbr(nbr_i, scan_clock); + + /* Set current scan pixel to the new neighbor. */ + /* REMEMBER: the neighbors are being scanned around the original */ + /* feature point. */ + cur_nbr_x = cur_x_loc + g_nbr8_dx[nbr_i]; + cur_nbr_y = cur_y_loc + g_nbr8_dy[nbr_i]; + + /* If new neighbor is not within image boundaries... */ + if((cur_nbr_x < 0) || (cur_nbr_x >= iw) || + (cur_nbr_y < 0) || (cur_nbr_y >= ih)) + /* Return (FALSE==>Failure) if neighbor out of bounds. */ + return(FALSE); + + /* Get the new neighbor's pixel value. */ + cur_nbr_pix = *(bdata + (cur_nbr_y * iw) + cur_nbr_x); + + /* If the new neighbor's pixel value is the same as the feature's */ + /* pixel value AND the previous neighbor's pixel value is the same */ + /* as the features's edge, then we have "likely" found our next */ + /* contour pixel. */ + if((cur_nbr_pix == feature_pix) && (prev_nbr_pix == edge_pix)){ + + /* Check to see if current neighbor is on the corner of the */ + /* neighborhood, and if so, test to see if it is "exposed". */ + /* The neighborhood corners have odd neighbor indicies. */ + if(nbr_i % 2){ + /* To do this, look ahead one more neighbor pixel. */ + ni = next_scan_nbr(nbr_i, scan_clock); + nx = cur_x_loc + g_nbr8_dx[ni]; + ny = cur_y_loc + g_nbr8_dy[ni]; + /* If new neighbor is not within image boundaries... */ + if((nx < 0) || (nx >= iw) || + (ny < 0) || (ny >= ih)) + /* Return (FALSE==>Failure) if neighbor out of bounds. */ + return(FALSE); + npix = *(bdata + (ny * iw) + nx); + + /* If the next neighbor's value is also the same as the */ + /* feature's pixel, then corner is NOT exposed... */ + if(npix == feature_pix){ + /* Assign the current neighbor pair to the output pointers. */ + *next_x_loc = cur_nbr_x; + *next_y_loc = cur_nbr_y; + *next_x_edge = prev_nbr_x; + *next_y_edge = prev_nbr_y; + /* Return TRUE==>Success. */ + return(TRUE); + } + /* Otherwise, corner pixel is "exposed" so skip it. */ + else{ + /* Skip current corner neighbor by resetting it to the */ + /* next neighbor, which upon the iteration will immediately */ + /* become the previous neighbor. */ + cur_nbr_x = nx; + cur_nbr_y = ny; + cur_nbr_pix = npix; + /* Advance neighbor index. */ + nbr_i = ni; + /* Advance neighbor count. */ + i++; + } + } + /* Otherwise, current neighbor is not a corner ... */ + else{ + /* Assign the current neighbor pair to the output pointers. */ + *next_x_loc = cur_nbr_x; + *next_y_loc = cur_nbr_y; + *next_x_edge = prev_nbr_x; + *next_y_edge = prev_nbr_y; + /* Return TRUE==>Success. */ + return(TRUE); + } + } + } + + /* If we get here, then we did not find the next contour pixel */ + /* within the 8 neighbors of the current feature pixel so */ + /* return (FALSE==>Failure). */ + /* NOTE: This must mean we found a single isolated pixel. */ + /* Perhaps this should be filled? */ + return(FALSE); +} + +/************************************************************************* +************************************************************************** +#cat: start_scan_nbr - Takes a two pixel coordinates that are either +#cat: aligned north-to-south or east-to-west, and returns the +#cat: position the second pixel is in realtionship to the first. +#cat: The positions returned are based on 8-connectedness. +#cat: NOTE, this routine does NOT account for diagonal positions. + + Input: + x_prev - x-coord of first point + y_prev - y-coord of first point + x_next - x-coord of second point + y_next - y-coord of second point + Return Code: + NORTH - second pixel above first + SOUTH - second pixel below first + EAST - second pixel right of first + WEST - second pixel left of first +**************************************************************************/ +int start_scan_nbr(const int x_prev, const int y_prev, + const int x_next, const int y_next) +{ + if((x_prev==x_next) && (y_next > y_prev)) + return(SOUTH); + else if ((x_prev==x_next) && (y_next < y_prev)) + return(NORTH); + else if ((x_next > x_prev) && (y_prev==y_next)) + return(EAST); + else if ((x_next < x_prev) && (y_prev==y_next)) + return(WEST); + + /* Added by MDG on 03-16-05 */ + /* Should never reach here. Added to remove compiler warning. */ + return(INVALID_DIR); /* -1 */ +} + +/************************************************************************* +************************************************************************** +#cat: next_scan_nbr - Advances the given 8-connected neighbor index +#cat: on location in the specifiec direction (clockwise or +#cat: counter-clockwise). + + Input: + nbr_i - current 8-connected neighbor index + scan_clock - direction in which the neighbor index is to be advanced + Return Code: + Next neighbor - 8-connected index of next neighbor +**************************************************************************/ +int next_scan_nbr(const int nbr_i, const int scan_clock) +{ + int new_i; + + /* If scanning neighbors clockwise ... */ + if(scan_clock == SCAN_CLOCKWISE) + /* Advance one neighbor clockwise. */ + new_i = (nbr_i+1)%8; + /* Otherwise, scanning neighbors counter-clockwise ... */ + else + /* Advance one neighbor counter-clockwise. */ + /* There are 8 pixels in the neighborhood, so to */ + /* decrement with wrapping from 0 around to 7, add */ + /* the nieghbor index by 7 and mod with 8. */ + new_i = (nbr_i+7)%8; + + /* Return the new neighbor index. */ + return(new_i); +} + /************************************************************************* ************************************************************************** #cat: min_contour_theta - Takes a contour list and analyzes it locating the diff --git a/libfprint/nbis/mindtct/detect.c b/libfprint/nbis/mindtct/detect.c index deadf291..10ed85c5 100644 --- a/libfprint/nbis/mindtct/detect.c +++ b/libfprint/nbis/mindtct/detect.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -35,16 +56,46 @@ identified are necessarily the best available for the purpose. *********************************************************************** ROUTINES: + lfs_detect_minutiae() lfs_detect_minutiae_V2() - get_minutiae() ***********************************************************************/ #include -#include #include +#include #include +/************************************************************************* +#cat: lfs_detect_minutiae - Takes a grayscale fingerprint image (of arbitrary +#cat: size), and returns a map of directional ridge flow in the image +#cat: (2 versions), a binarized image designating ridges from valleys, +#cat: and a list of minutiae (including position, type, direction, +#cat: neighbors, and ridge counts to neighbors). + + Input: + idata - input 8-bit grayscale fingerprint image data + iw - width (in pixels) of the image + ih - height (in pixels) of the image + lfsparms - parameters and thresholds for controlling LFS + Output: + ominutiae - resulting list of minutiae + oimap - resulting IMAP + {invalid (-1) or valid ridge directions} + onmap - resulting NMAP + {invalid (-1), high-curvature (-2), blanked blocks {-3} or + valid ridge directions} + omw - width (in blocks) of image maps + omh - height (in blocks) of image maps + obdata - resulting binarized image + {0 = black pixel (ridge) and 255 = white pixel (valley)} + obw - width (in pixels) of the binary image + obh - height (in pixels) of the binary image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* #cat: lfs_detect_minutiae_V2 - Takes a grayscale fingerprint image (of #cat: arbitrary size), and returns a set of image block maps, @@ -81,7 +132,7 @@ identified are necessarily the best available for the purpose. Zero - successful completion Negative - system error **************************************************************************/ -static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, +int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, int **odmap, int **olcmap, int **olfmap, int **ohcmap, int *omw, int *omh, unsigned char **obdata, int *obw, int *obh, @@ -99,6 +150,8 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, int ret, maxpad; MINUTIAE *minutiae; + set_timer(total_timer); + /******************/ /* INITIALIZATION */ /******************/ @@ -181,6 +234,7 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, /******************/ /* MAPS */ /******************/ + set_timer(imap_timer); /* Generate block maps from the input image. */ if((ret = gen_image_maps(&direction_map, &low_contrast_map, @@ -200,9 +254,12 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, print2log("\nMAPS DONE\n"); + time_accum(imap_timer, imap_time); + /******************/ /* BINARIZARION */ /******************/ + set_timer(bin_timer); /* Initialize lookup table for pixel offsets to rotated grids */ /* used for directional binarization. */ @@ -254,9 +311,12 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, print2log("\nBINARIZATION DONE\n"); + time_accum(bin_timer, bin_time); + /******************/ /* DETECTION */ /******************/ + set_timer(minutia_timer); /* Convert 8-bit grayscale binary image [0,255] to */ /* 8-bit binary image [0,1]. */ @@ -281,6 +341,10 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, return(ret); } + time_accum(minutia_timer, minutia_time); + + set_timer(rm_minutia_timer); + if((ret = remove_false_minutia_V2(minutiae, bdata, iw, ih, direction_map, low_flow_map, high_curve_map, mw, mh, lfsparms))){ @@ -297,9 +361,13 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, print2log("\nMINUTIA DETECTION DONE\n"); + time_accum(rm_minutia_timer, rm_minutia_time); + /******************/ /* RIDGE COUNTS */ /******************/ + set_timer(ridge_count_timer); + if((ret = count_minutiae_ridges(minutiae, bdata, iw, ih, lfsparms))){ /* Free memory allocated to this point. */ free(pdata); @@ -314,6 +382,8 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, print2log("\nNEIGHBOR RIDGE COUNT DONE\n"); + time_accum(ridge_count_timer, ridge_count_time); + /******************/ /* WRAP-UP */ /******************/ @@ -337,6 +407,28 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, *obh = bh; *ominutiae = minutiae; + time_accum(total_timer, total_time); + + /******************/ + /* PRINT TIMINGS */ + /******************/ + /* These Timings will print when TIMER is defined. */ + /* print MAP generation timing statistics */ + print_time(stderr, "TIMER: MAPS time = %f (secs)\n", imap_time); + /* print binarization timing statistics */ + print_time(stderr, "TIMER: Binarization time = %f (secs)\n", bin_time); + /* print minutia detection timing statistics */ + print_time(stderr, "TIMER: Minutia Detection time = %f (secs)\n", + minutia_time); + /* print minutia removal timing statistics */ + print_time(stderr, "TIMER: Minutia Removal time = %f (secs)\n", + rm_minutia_time); + /* print neighbor ridge count timing statistics */ + print_time(stderr, "TIMER: Neighbor Ridge Counting time = %f (secs)\n", + ridge_count_time); + /* print total timing statistics */ + print_time(stderr, "TIMER: Total time = %f (secs)\n", total_time); + /* If LOG_REPORT defined, close log report file. */ if((ret = close_logfile())) return(ret); @@ -344,112 +436,3 @@ static int lfs_detect_minutiae_V2(MINUTIAE **ominutiae, return(0); } -/************************************************************************* -************************************************************************** -#cat: get_minutiae - Takes a grayscale fingerprint image, binarizes the input -#cat: image, and detects minutiae points using LFS Version 2. -#cat: The routine passes back the detected minutiae, the -#cat: binarized image, and a set of image quality maps. - - Input: - idata - grayscale fingerprint image data - iw - width (in pixels) of the grayscale image - ih - height (in pixels) of the grayscale image - id - pixel depth (in bits) of the grayscale image - ppmm - the scan resolution (in pixels/mm) of the grayscale image - lfsparms - parameters and thresholds for controlling LFS - Output: - ominutiae - points to a structure containing the - detected minutiae - oquality_map - resulting integrated image quality map - odirection_map - resulting direction map - olow_contrast_map - resulting low contrast map - olow_flow_map - resulting low ridge flow map - ohigh_curve_map - resulting high curvature map - omap_w - width (in blocks) of image maps - omap_h - height (in blocks) of image maps - obdata - points to binarized image data - obw - width (in pixels) of binarized image - obh - height (in pixels) of binarized image - obd - pixel depth (in bits) of binarized image - Return Code: - Zero - successful completion - Negative - system error -**************************************************************************/ -int get_minutiae(MINUTIAE **ominutiae, int **oquality_map, - int **odirection_map, int **olow_contrast_map, - int **olow_flow_map, int **ohigh_curve_map, - int *omap_w, int *omap_h, - unsigned char **obdata, int *obw, int *obh, int *obd, - unsigned char *idata, const int iw, const int ih, - const int id, const double ppmm, const LFSPARMS *lfsparms) -{ - int ret; - MINUTIAE *minutiae = NULL; - int *direction_map = NULL, *low_contrast_map = NULL, *low_flow_map = NULL; - int *high_curve_map = NULL, *quality_map = NULL; - int map_w = 0, map_h = 0; - unsigned char *bdata = NULL; - int bw = 0, bh = 0; - - /* If input image is not 8-bit grayscale ... */ - if(id != 8){ - fprintf(stderr, "ERROR : get_minutiae : input image pixel "); - fprintf(stderr, "depth = %d != 8.\n", id); - return(-2); - } - - /* Detect minutiae in grayscale fingerpeint image. */ - if((ret = lfs_detect_minutiae_V2(&minutiae, - &direction_map, &low_contrast_map, - &low_flow_map, &high_curve_map, - &map_w, &map_h, - &bdata, &bw, &bh, - idata, iw, ih, lfsparms))){ - return(ret); - } - - /* Build integrated quality map. */ - if((ret = gen_quality_map(&quality_map, - direction_map, low_contrast_map, - low_flow_map, high_curve_map, map_w, map_h))){ - free_minutiae(minutiae); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); - free(bdata); - return(ret); - } - - /* Assign reliability from quality map. */ - if((ret = combined_minutia_quality(minutiae, quality_map, map_w, map_h, - lfsparms->blocksize, - idata, iw, ih, id, ppmm))){ - free_minutiae(minutiae); - free(direction_map); - free(low_contrast_map); - free(low_flow_map); - free(high_curve_map); - free(quality_map); - free(bdata); - return(ret); - } - - /* Set output pointers. */ - *ominutiae = minutiae; - *oquality_map = quality_map; - *odirection_map = direction_map; - *olow_contrast_map = low_contrast_map; - *olow_flow_map = low_flow_map; - *ohigh_curve_map = high_curve_map; - *omap_w = map_w; - *omap_h = map_h; - *obdata = bdata; - *obw = bw; - *obh = bh; - *obd = id; - - /* Return normally. */ - return(0); -} diff --git a/libfprint/nbis/mindtct/dft.c b/libfprint/nbis/mindtct/dft.c index af136536..0cc490a3 100644 --- a/libfprint/nbis/mindtct/dft.c +++ b/libfprint/nbis/mindtct/dft.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -44,87 +65,8 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include -/************************************************************************* -************************************************************************** -#cat: sum_rot_block_rows - Computes a vector or pixel row sums by sampling -#cat: the current image block at a given orientation. The -#cat: sampling is conducted using a precomputed set of rotated -#cat: pixel offsets (called a grid) relative to the orgin of -#cat: the image block. - - Input: - blkptr - the pixel address of the origin of the current image block - grid_offsets - the rotated pixel offsets for a block-sized grid - rotated according to a specific orientation - blocksize - the width and height of the image block and thus the size - of the rotated grid - Output: - rowsums - the resulting vector of pixel row sums -**************************************************************************/ -static void sum_rot_block_rows(int *rowsums, const unsigned char *blkptr, - const int *grid_offsets, const int blocksize) -{ - int ix, iy, gi; - - /* Initialize rotation offset index. */ - gi = 0; - - /* For each row in block ... */ - for(iy = 0; iy < blocksize; iy++){ - /* The sums are accumlated along the rotated rows of the grid, */ - /* so initialize row sum to 0. */ - rowsums[iy] = 0; - /* Foreach column in block ... */ - for(ix = 0; ix < blocksize; ix++){ - /* Accumulate pixel value at rotated grid position in image */ - rowsums[iy] += *(blkptr + grid_offsets[gi]); - gi++; - } - } -} - -/************************************************************************* -************************************************************************** -#cat: dft_power - Computes the DFT power by applying a specific wave form -#cat: frequency to a vector of pixel row sums computed from a -#cat: specific orientation of the block image - - Input: - rowsums - accumulated rows of pixels from within a rotated grid - overlaying an input image block - wave - the wave form (cosine and sine components) at a specific - frequency - wavelen - the length of the wave form (must match the height of the - image block which is the length of the rowsum vector) - Output: - power - the computed DFT power for the given wave form at the - given orientation within the image block -**************************************************************************/ -static void dft_power(double *power, const int *rowsums, - const DFTWAVE *wave, const int wavelen) -{ - int i; - double cospart, sinpart; - - /* Initialize accumulators */ - cospart = 0.0; - sinpart = 0.0; - - /* Accumulate cos and sin components of DFT. */ - for(i = 0; i < wavelen; i++){ - /* Multiply each rotated row sum by its */ - /* corresponding cos or sin point in DFT wave. */ - cospart += (rowsums[i] * wave->cos[i]); - sinpart += (rowsums[i] * wave->sin[i]); - } - - /* Power is the sum of the squared cos and sin components */ - *power = (cospart * cospart) + (sinpart * sinpart); -} - /************************************************************************* ************************************************************************** #cat: dft_dir_powers - Conducts the DFT analysis on a block of image data. @@ -199,105 +141,80 @@ int dft_dir_powers(double **powers, unsigned char *pdata, /************************************************************************* ************************************************************************** -#cat: get_max_norm - Analyses a DFT power vector for a specific wave form -#cat: applied at different orientations (directions) to the -#cat: current image block. The routine retuns the maximum -#cat: power value in the vector, the direction at which the -#cat: maximum occurs, and a normalized power value. The -#cat: normalized power is computed as the maximum power divided -#cat: by the average power across all the directions. These -#cat: simple statistics are fundamental to the selection of -#cat: a dominant direction flow for the image block. +#cat: sum_rot_block_rows - Computes a vector or pixel row sums by sampling +#cat: the current image block at a given orientation. The +#cat: sampling is conducted using a precomputed set of rotated +#cat: pixel offsets (called a grid) relative to the orgin of +#cat: the image block. Input: - power_vector - the DFT power values derived form a specific wave form - applied at different directions - ndirs - the number of directions to which the wave form was applied + blkptr - the pixel address of the origin of the current image block + grid_offsets - the rotated pixel offsets for a block-sized grid + rotated according to a specific orientation + blocksize - the width and height of the image block and thus the size + of the rotated grid Output: - powmax - the maximum power value in the DFT power vector - powmax_dir - the direciton at which the maximum power value occured - pownorm - the normalized power corresponding to the maximum power + rowsums - the resulting vector of pixel row sums **************************************************************************/ -static void get_max_norm(double *powmax, int *powmax_dir, - double *pownorm, const double *power_vector, const int ndirs) +void sum_rot_block_rows(int *rowsums, const unsigned char *blkptr, + const int *grid_offsets, const int blocksize) { - int dir; - double max_v, powsum; - int max_i; - double powmean; + int ix, iy, gi; - /* Find max power value and store corresponding direction */ - max_v = power_vector[0]; - max_i = 0; + /* Initialize rotation offset index. */ + gi = 0; - /* Sum the total power in a block at a given direction */ - powsum = power_vector[0]; - - /* For each direction ... */ - for(dir = 1; dir < ndirs; dir++){ - powsum += power_vector[dir]; - if(power_vector[dir] > max_v){ - max_v = power_vector[dir]; - max_i = dir; + /* For each row in block ... */ + for(iy = 0; iy < blocksize; iy++){ + /* The sums are accumlated along the rotated rows of the grid, */ + /* so initialize row sum to 0. */ + rowsums[iy] = 0; + /* Foreach column in block ... */ + for(ix = 0; ix < blocksize; ix++){ + /* Accumulate pixel value at rotated grid position in image */ + rowsums[iy] += *(blkptr + grid_offsets[gi]); + gi++; } } - - *powmax = max_v; - *powmax_dir = max_i; - - /* Powmean is used as denominator for pownorm, so setting */ - /* a non-zero minimum avoids possible division by zero. */ - powmean = max(powsum, MIN_POWER_SUM)/(double)ndirs; - - *pownorm = *powmax / powmean; } /************************************************************************* ************************************************************************** -#cat: sort_dft_waves - Creates a ranked list of DFT wave form statistics -#cat: by sorting on the normalized squared maximum power. +#cat: dft_power - Computes the DFT power by applying a specific wave form +#cat: frequency to a vector of pixel row sums computed from a +#cat: specific orientation of the block image Input: - powmaxs - maximum DFT power for each wave form used to derive - statistics - pownorms - normalized maximum power corresponding to values in powmaxs - nstats - number of wave forms used to derive statistics (N Wave - 1) + rowsums - accumulated rows of pixels from within a rotated grid + overlaying an input image block + wave - the wave form (cosine and sine components) at a specific + frequency + wavelen - the length of the wave form (must match the height of the + image block which is the length of the rowsum vector) Output: - wis - sorted list of indices corresponding to the ranked set of - wave form statistics. These indices will be used as - indirect addresses when processing the power statistics - in descending order of "dominance" - Return Code: - Zero - successful completion - Negative - system error + power - the computed DFT power for the given wave form at the + given orientation within the image block **************************************************************************/ -static int sort_dft_waves(int *wis, const double *powmaxs, const double *pownorms, - const int nstats) +void dft_power(double *power, const int *rowsums, + const DFTWAVE *wave, const int wavelen) { int i; - double *pownorms2; + double cospart, sinpart; - /* Allocate normalized power^2 array */ - pownorms2 = (double *)malloc(nstats * sizeof(double)); - if(pownorms2 == (double *)NULL){ - fprintf(stderr, "ERROR : sort_dft_waves : malloc : pownorms2\n"); - return(-100); + /* Initialize accumulators */ + cospart = 0.0; + sinpart = 0.0; + + /* Accumulate cos and sin components of DFT. */ + for(i = 0; i < wavelen; i++){ + /* Multiply each rotated row sum by its */ + /* corresponding cos or sin point in DFT wave. */ + cospart += (rowsums[i] * wave->cos[i]); + sinpart += (rowsums[i] * wave->sin[i]); } - for(i = 0; i < nstats; i++){ - /* Wis will hold the sorted statistic indices when all is done. */ - wis[i] = i; - /* This is normalized squared max power. */ - pownorms2[i] = powmaxs[i] * pownorms[i]; - } - - /* Sort the statistic indices on the normalized squared power. */ - bubble_sort_double_dec_2(pownorms2, wis, nstats); - - /* Deallocate the working memory. */ - free(pownorms2); - - return(0); + /* Power is the sum of the squared cos and sin components */ + *power = (cospart * cospart) + (sinpart * sinpart); } /************************************************************************* @@ -356,3 +273,106 @@ int dft_power_stats(int *wis, double *powmaxs, int *powmax_dirs, return(0); } +/************************************************************************* +************************************************************************** +#cat: get_max_norm - Analyses a DFT power vector for a specific wave form +#cat: applied at different orientations (directions) to the +#cat: current image block. The routine retuns the maximum +#cat: power value in the vector, the direction at which the +#cat: maximum occurs, and a normalized power value. The +#cat: normalized power is computed as the maximum power divided +#cat: by the average power across all the directions. These +#cat: simple statistics are fundamental to the selection of +#cat: a dominant direction flow for the image block. + + Input: + power_vector - the DFT power values derived form a specific wave form + applied at different directions + ndirs - the number of directions to which the wave form was applied + Output: + powmax - the maximum power value in the DFT power vector + powmax_dir - the direciton at which the maximum power value occured + pownorm - the normalized power corresponding to the maximum power +**************************************************************************/ +void get_max_norm(double *powmax, int *powmax_dir, + double *pownorm, const double *power_vector, const int ndirs) +{ + int dir; + double max_v, powsum; + int max_i; + double powmean; + + /* Find max power value and store corresponding direction */ + max_v = power_vector[0]; + max_i = 0; + + /* Sum the total power in a block at a given direction */ + powsum = power_vector[0]; + + /* For each direction ... */ + for(dir = 1; dir < ndirs; dir++){ + powsum += power_vector[dir]; + if(power_vector[dir] > max_v){ + max_v = power_vector[dir]; + max_i = dir; + } + } + + *powmax = max_v; + *powmax_dir = max_i; + + /* Powmean is used as denominator for pownorm, so setting */ + /* a non-zero minimum avoids possible division by zero. */ + powmean = max(powsum, MIN_POWER_SUM)/(double)ndirs; + + *pownorm = *powmax / powmean; +} + +/************************************************************************* +************************************************************************** +#cat: sort_dft_waves - Creates a ranked list of DFT wave form statistics +#cat: by sorting on the normalized squared maximum power. + + Input: + powmaxs - maximum DFT power for each wave form used to derive + statistics + pownorms - normalized maximum power corresponding to values in powmaxs + nstats - number of wave forms used to derive statistics (N Wave - 1) + Output: + wis - sorted list of indices corresponding to the ranked set of + wave form statistics. These indices will be used as + indirect addresses when processing the power statistics + in descending order of "dominance" + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int sort_dft_waves(int *wis, const double *powmaxs, const double *pownorms, + const int nstats) +{ + int i; + double *pownorms2; + + /* Allocate normalized power^2 array */ + pownorms2 = (double *)malloc(nstats * sizeof(double)); + if(pownorms2 == (double *)NULL){ + fprintf(stderr, "ERROR : sort_dft_waves : malloc : pownorms2\n"); + return(-100); + } + + for(i = 0; i < nstats; i++){ + /* Wis will hold the sorted statistic indices when all is done. */ + wis[i] = i; + /* This is normalized squared max power. */ + pownorms2[i] = powmaxs[i] * pownorms[i]; + } + + /* Sort the statistic indices on the normalized squared power. */ + bubble_sort_double_dec_2(pownorms2, wis, nstats); + + /* Deallocate the working memory. */ + free(pownorms2); + + return(0); +} + diff --git a/libfprint/nbis/mindtct/free.c b/libfprint/nbis/mindtct/free.c index fd7612e4..adaeeb9a 100644 --- a/libfprint/nbis/mindtct/free.c +++ b/libfprint/nbis/mindtct/free.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -40,7 +61,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include /************************************************************************* diff --git a/libfprint/nbis/mindtct/getmin.c b/libfprint/nbis/mindtct/getmin.c new file mode 100644 index 00000000..08a087d8 --- /dev/null +++ b/libfprint/nbis/mindtct/getmin.c @@ -0,0 +1,175 @@ +/******************************************************************************* + +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. + +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. + +*******************************************************************************/ + + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: GETMIN.C + AUTHOR: Michael D. Garris + DATE: 09/10/2004 + UPDATED: 03/16/2005 by MDG + + Takes an 8-bit grayscale fingerpinrt image and detects minutiae + as part of the NIST Latent Fingerprint System (LFS), returning + minutiae with final reliabilities and maps including a merged + quality map. + +*********************************************************************** + ROUTINES: + get_minutiae() + +***********************************************************************/ + +#include +#include + +/************************************************************************* +************************************************************************** +#cat: get_minutiae - Takes a grayscale fingerprint image, binarizes the input +#cat: image, and detects minutiae points using LFS Version 2. +#cat: The routine passes back the detected minutiae, the +#cat: binarized image, and a set of image quality maps. + + Input: + idata - grayscale fingerprint image data + iw - width (in pixels) of the grayscale image + ih - height (in pixels) of the grayscale image + id - pixel depth (in bits) of the grayscale image + ppmm - the scan resolution (in pixels/mm) of the grayscale image + lfsparms - parameters and thresholds for controlling LFS + Output: + ominutiae - points to a structure containing the + detected minutiae + oquality_map - resulting integrated image quality map + odirection_map - resulting direction map + olow_contrast_map - resulting low contrast map + olow_flow_map - resulting low ridge flow map + ohigh_curve_map - resulting high curvature map + omap_w - width (in blocks) of image maps + omap_h - height (in blocks) of image maps + obdata - points to binarized image data + obw - width (in pixels) of binarized image + obh - height (in pixels) of binarized image + obd - pixel depth (in bits) of binarized image + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int get_minutiae(MINUTIAE **ominutiae, int **oquality_map, + int **odirection_map, int **olow_contrast_map, + int **olow_flow_map, int **ohigh_curve_map, + int *omap_w, int *omap_h, + unsigned char **obdata, int *obw, int *obh, int *obd, + unsigned char *idata, const int iw, const int ih, + const int id, const double ppmm, const LFSPARMS *lfsparms) +{ + int ret; + MINUTIAE *minutiae; + int *direction_map, *low_contrast_map, *low_flow_map; + int *high_curve_map, *quality_map; + int map_w, map_h; + unsigned char *bdata; + int bw, bh; + + /* If input image is not 8-bit grayscale ... */ + if(id != 8){ + fprintf(stderr, "ERROR : get_minutiae : input image pixel "); + fprintf(stderr, "depth = %d != 8.\n", id); + return(-2); + } + + /* Detect minutiae in grayscale fingerpeint image. */ + if((ret = lfs_detect_minutiae_V2(&minutiae, + &direction_map, &low_contrast_map, + &low_flow_map, &high_curve_map, + &map_w, &map_h, + &bdata, &bw, &bh, + idata, iw, ih, lfsparms))){ + return(ret); + } + + /* Build integrated quality map. */ + if((ret = gen_quality_map(&quality_map, + direction_map, low_contrast_map, + low_flow_map, high_curve_map, map_w, map_h))){ + free_minutiae(minutiae); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free(bdata); + return(ret); + } + + /* Assign reliability from quality map. */ + if((ret = combined_minutia_quality(minutiae, quality_map, map_w, map_h, + lfsparms->blocksize, + idata, iw, ih, id, ppmm))){ + free_minutiae(minutiae); + free(direction_map); + free(low_contrast_map); + free(low_flow_map); + free(high_curve_map); + free(quality_map); + free(bdata); + return(ret); + } + + /* Set output pointers. */ + *ominutiae = minutiae; + *oquality_map = quality_map; + *odirection_map = direction_map; + *olow_contrast_map = low_contrast_map; + *olow_flow_map = low_flow_map; + *ohigh_curve_map = high_curve_map; + *omap_w = map_w; + *omap_h = map_h; + *obdata = bdata; + *obw = bw; + *obh = bh; + *obd = id; + + /* Return normally. */ + return(0); +} diff --git a/libfprint/nbis/mindtct/globals.c b/libfprint/nbis/mindtct/globals.c index e17c7dc9..da10c152 100644 --- a/libfprint/nbis/mindtct/globals.c +++ b/libfprint/nbis/mindtct/globals.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -40,7 +61,7 @@ identified are necessarily the best available for the purpose. /*************************************************************************/ #ifdef LOG_REPORT -FILE *g_logfp; +FILE *logfp; #endif /* Constants (C) for defining 4 DFT frequencies, where */ @@ -129,8 +150,6 @@ LFSPARMS g_lfsparms = { PORES_STEPS_BWD, PORES_MIN_DIST2, PORES_MAX_RATIO, - FALSE, /* not removing perimeter points by default */ - PERIMETER_PTS_DISTANCE, /* Ridge Counting Controls */ MAX_NBRS, @@ -215,8 +234,6 @@ LFSPARMS g_lfsparms_V2 = { PORES_STEPS_BWD, PORES_MIN_DIST2, PORES_MAX_RATIO, - FALSE, /* not removing perimeter points by default */ - PERIMETER_PTS_DISTANCE, /* Ridge Counting Controls */ MAX_NBRS, diff --git a/libfprint/nbis/mindtct/imgutil.c b/libfprint/nbis/mindtct/imgutil.c index c4fa8689..50cf7666 100644 --- a/libfprint/nbis/mindtct/imgutil.c +++ b/libfprint/nbis/mindtct/imgutil.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -45,7 +66,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include #include @@ -65,18 +85,6 @@ identified are necessarily the best available for the purpose. Output: idata - contains the bit-shifted results **************************************************************************/ -void bits_6to8(unsigned char *idata, const int iw, const int ih) -{ - int i, isize; - unsigned char *iptr; - - isize = iw * ih; - iptr = idata; - for(i = 0; i < isize; i++){ - /* Multiply every pixel value by 4 so that [0..64) -> [0..255) */ - *iptr++ <<= 2; - } -} /************************************************************************* ************************************************************************** diff --git a/libfprint/nbis/mindtct/init.c b/libfprint/nbis/mindtct/init.c index 50dc0d7e..a7182790 100644 --- a/libfprint/nbis/mindtct/init.c +++ b/libfprint/nbis/mindtct/init.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -37,6 +58,7 @@ identified are necessarily the best available for the purpose. ROUTINES: init_dir2rad() init_dftwaves() + get_max_padding() get_max_padding_V2() init_rotgrids() alloc_dir_powers() @@ -44,7 +66,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include /************************************************************************* @@ -242,6 +263,33 @@ int init_dftwaves(DFTWAVES **optr, const double *dft_coefs, return(0); } +/************************************************************************* +************************************************************************** +#cat: get_max_padding - Deterines the maximum amount of image pixel padding +#cat: required by all LFS processes. Padding is currently +#cat: required by the rotated grids used in DFT analyses, +#cat: rotated grids used in directional binarization, +#cat: and in the grid used for isotropic binarization. +#cat: The NIST generalized code enables the parameters +#cat: governing these processes to be redefined, so a check +#cat: at runtime is required to determine which process +#cat: requires the most padding. By using the maximum as +#cat: the padding factor, all processes will run safely +#cat: with a single padding of the input image avoiding the +#cat: need to repad for further processes. + + Input: + imap_blocksize - the size (in pixels) of each IMAP block in the image + dirbin_grid_w - the width (in pixels) of the rotated grids used in + directional binarization + dirbin_grid_h - the height (in pixels) of the rotated grids used in + directional binarization + isobin_grid_dim - the dimension (in pixels) of the square grid used in + isotropic binarization + Return Code: + Non-negative - the maximum padding required for all processes +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: get_max_padding_V2 - Deterines the maximum amount of image pixel padding diff --git a/libfprint/nbis/mindtct/line.c b/libfprint/nbis/mindtct/line.c index 5d9a8ed5..07edf18d 100644 --- a/libfprint/nbis/mindtct/line.c +++ b/libfprint/nbis/mindtct/line.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -38,7 +59,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include /************************************************************************* diff --git a/libfprint/nbis/mindtct/link.c b/libfprint/nbis/mindtct/link.c new file mode 100644 index 00000000..22e568a9 --- /dev/null +++ b/libfprint/nbis/mindtct/link.c @@ -0,0 +1,254 @@ +/******************************************************************************* + +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. + +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. + +*******************************************************************************/ + + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: LINK.C + AUTHOR: Michael D. Garris + DATE: 08/02/1999 + UPDATED: 10/04/1999 Version 2 by MDG + UPDATED: 03/16/2005 by MDG + + Contains routines responsible for linking compatible minutiae + together as part of the NIST Latent Fingerprint System (LFS). + +*********************************************************************** + ROUTINES: + link_minutiae() + create_link_table() + update_link_table() + order_link_table() + process_link_table() + link_score() +***********************************************************************/ + +#include +#include +#include + +/************************************************************************* +************************************************************************** +#cat: link_minutiae - Clusters minutiae that are sufficiently close to each +#cat: other and have compatible directions to be considered part +#cat: of the same ridge or valley and then links them together. +#cat: In linking two minutia, the respective minutia features +#cat: in the image are joined by drawing pixels and the points +#cat: are removed from the list. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + nmap - IMAP ridge flow matrix with invalid, high-curvature, + and no-valid-neighbor regions identified + mw - width in blocks of the NMAP + mh - height in blocks of the NMAP + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + bdata - edited binary image with breaks in ridges and valleys filled + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: create_link_table - Builds a 2D minutia link table where each cell in the +#cat: table represents a potential linking of 2 different +#cat: minutia points. Minutia IDs are stored on each axes +#cat: and scores representing the degree of compatibility +#cat: between 2 minutia are stored in each cell. Note that +#cat: the table is sparsely filled with scores. + + Input: + tbldim - dimension of each axes of the link table + start - index position of starting minutia point in input list + minutiae - list of minutia + onloop - list of loop flags (on flag for each minutia point in list) + nmap - IMAP ridge flow matrix with invalid, high-curvature, + and no-valid-neighbor regions identified + mw - width in blocks of the NMAP + mh - height in blocks of the NMAP + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + olink_table - sparse 2D table containing scores of potentially + linked minutia pairs + ox_axis - minutia IDs registered along x-axis + oy_axis - minutia IDs registered along y-axis + onx_axis - number of minutia registered along x-axis + ony_axis - number of minutia registered along y-axis + on_entries - number of scores currently entered in the table + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: update_link_table - Takes the indices of 2 minutia and their link +#cat: compatibility score and updates the 2D link table. +#cat: The input minutia are registered to positions along +#cat: different axes, if they are not already in the table, +#cat: and a queue is maintained so that a cluster of +#cat: potentially linked points may be gathered. + + Input: + link_table - sparse 2D table containing scores of potentially linked + minutia pairs + x_axis - minutia IDs registered along x-axis + y_axis - minutia IDs registered along y-axis + nx_axis - number of minutia registered along x-axis + ny_axis - number of minutia registered along y-axis + n_entries - number of scores currently entered in the table + tbldim - dimension of each axes of the link table + queue - list of clustered minutiae yet to be used to locate + other compatible minutiae + head - head of the queue + tail - tail of the queue + inqueue - flag for each minutia point in minutiae list to signify if + it has been clustered with the points in this current link + table + first - index position of first minutia of current link pair + second - index position of second minutia of current link pair + score - degree of link compatibility of current link pair + Output: + link_table - updated sparse 2D table containing scores of potentially + linked minutia pairs + x_axis - updated minutia IDs registered along x-axis + y_axis - updated minutia IDs registered along y-axis + nx_axis - updated number of minutia registered along x-axis + ny_axis - updated number of minutia registered along y-axis + n_entries - updated number of scores currently entered in the table + queue - updated list of clustered minutiae yet to be used to locate + other compatible minutiae + tail - updated tail of the queue + inqueue - updated list of flags, one for each minutia point in + minutiae list to signify if it has been clustered with + the points in this current link table + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: order_link_table - Puts the link table in sorted order based on x and +#cat: then y-axis entries. These minutia are sorted based +#cat: on their point of perpendicular intersection with a +#cat: line running from the origin at an angle equal to the +#cat: average direction of all entries in the link table. + + Input: + link_table - sparse 2D table containing scores of potentially linked + minutia pairs + x_axis - minutia IDs registered along x-axis + y_axis - minutia IDs registered along y-axis + nx_axis - number of minutia registered along x-axis + ny_axis - number of minutia registered along y-axis + n_entries - number of scores currently entered in the table + tbldim - dimension of each axes of the link table + minutiae - list of minutia + ndirs - number of IMAP directions (in semicircle) + Output: + link_table - sorted sparse 2D table containing scores of potentially + linked minutia pairs + x_axis - sorted minutia IDs registered along x-axis + y_axis - sorted minutia IDs registered along y-axis + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: process_link_table - Processes the link table deciding which minutia +#cat: pairs in the table should be linked (ie. joined in +#cat: the image and removed from the minutiae list (and +#cat: from onloop). + + Input: + link_table - sparse 2D table containing scores of potentially linked + minutia pairs + x_axis - minutia IDs registered along x-axis + y_axis - minutia IDs registered along y-axis + nx_axis - number of minutia registered along x-axis + ny_axis - number of minutia registered along y-axis + n_entries - number of scores currently entered in the table + tbldim - dimension of each axes of the link table + minutiae - list of minutia + onloop - list of flags signifying which minutia lie on small lakes + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + onloop - updated loop flags + bdata - edited image with minutia features joined + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: link_score - Takes 2 parameters, a 'join angle' and a 'join distance' +#cat: computed between 2 minutia and combines these to compute +#cat: a score representing the degree of link compatibility +#cat: between the 2 minutiae. + + Input: + jointheta - angle measured between 2 minutiae + joindist - distance between 2 minutiae + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Score - degree of link compatibility +**************************************************************************/ + diff --git a/libfprint/nbis/mindtct/log.c b/libfprint/nbis/mindtct/log.c index d3aafbf9..b1dcaadf 100644 --- a/libfprint/nbis/mindtct/log.c +++ b/libfprint/nbis/mindtct/log.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -42,17 +63,12 @@ identified are necessarily the best available for the purpose. /* If logging is on, declare global file pointer and supporting */ /* global variable for logging intermediate results. */ -FILE *logfp; -int avrdir; -float dir_strength; -int nvalid; /***************************************************************************/ /***************************************************************************/ int open_logfile() { #ifdef LOG_REPORT - if((logfp = fopen(LOG_FILE, "wb")) == NULL){ fprintf(stderr, "ERROR : open_logfile : fopen : %s\n", LOG_FILE); return(-1); } @@ -69,7 +85,6 @@ void print2log(char *fmt, ...) va_list ap; va_start(ap, fmt); - vfprintf(logfp, fmt, ap); va_end(ap); #endif } @@ -79,7 +94,6 @@ void print2log(char *fmt, ...) int close_logfile() { #ifdef LOG_REPORT - if(fclose(logfp)){ fprintf(stderr, "ERROR : close_logfile : fclose : %s\n", LOG_FILE); return(-1); } diff --git a/libfprint/nbis/mindtct/loop.c b/libfprint/nbis/mindtct/loop.c index 3792b88d..847c43f7 100644 --- a/libfprint/nbis/mindtct/loop.c +++ b/libfprint/nbis/mindtct/loop.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -36,8 +57,6 @@ identified are necessarily the best available for the purpose. *********************************************************************** ROUTINES: - chain_code_loop() - is_chain_clockwise() get_loop_list() on_loop() on_island_lake() @@ -48,161 +67,13 @@ identified are necessarily the best available for the purpose. get_loop_aspect() fill_loop() fill_partial_row() + flood_loop() + flood_fill4() ***********************************************************************/ #include -#include #include -/************************************************************************* -************************************************************************** -#cat: chain_code_loop - Converts a feature's contour points into an -#cat: 8-connected chain code vector. This encoding represents -#cat: the direction taken between each adjacent point in the -#cat: contour. Chain codes may be used for many purposes, such -#cat: as computing the perimeter or area of an object, and they -#cat: may be used in object detection and recognition. - - Input: - contour_x - x-coord list for feature's contour points - contour_y - y-coord list for feature's contour points - ncontour - number of points in contour - Output: - ochain - resulting vector of chain codes - onchain - number of codes in chain - (same as number of points in contour) - Return Code: - Zero - chain code successful derived - Negative - system error -**************************************************************************/ -static int chain_code_loop(int **ochain, int *onchain, - const int *contour_x, const int *contour_y, const int ncontour) -{ - int *chain; - int i, j, dx, dy; - - /* If we don't have at least 3 points in the contour ... */ - if(ncontour <= 3){ - /* Then we don't have a loop, so set chain length to 0 */ - /* and return without any allocations. */ - *onchain = 0; - return(0); - } - - /* Allocate chain code vector. It will be the same length as the */ - /* number of points in the contour. There will be one chain code */ - /* between each point on the contour including a code between the */ - /* last to the first point on the contour (completing the loop). */ - chain = (int *)malloc(ncontour * sizeof(int)); - /* If the allocation fails ... */ - if(chain == (int *)NULL){ - fprintf(stderr, "ERROR : chain_code_loop : malloc : chain\n"); - return(-170); - } - - /* For each neighboring point in the list (with "i" pointing to the */ - /* previous neighbor and "j" pointing to the next neighbor... */ - for(i = 0, j=1; i < ncontour-1; i++, j++){ - /* Compute delta in X between neighbors. */ - dx = contour_x[j] - contour_x[i]; - /* Compute delta in Y between neighbors. */ - dy = contour_y[j] - contour_y[i]; - /* Derive chain code index from neighbor deltas. */ - /* The deltas are on the range [-1..1], so to use them as indices */ - /* into the code list, they must first be incremented by one. */ - chain[i] = *(g_chaincodes_nbr8+((dy+1)*NBR8_DIM)+dx+1); - } - - /* Now derive chain code between last and first points in the */ - /* contour list. */ - dx = contour_x[0] - contour_x[i]; - dy = contour_y[0] - contour_y[i]; - chain[i] = *(g_chaincodes_nbr8+((dy+1)*NBR8_DIM)+dx+1); - - /* Store results to the output pointers. */ - *ochain = chain; - *onchain = ncontour; - - /* Return normally. */ - return(0); -} - -/************************************************************************* -************************************************************************** -#cat: is_chain_clockwise - Takes an 8-connected chain code vector and -#cat: determines if the codes are ordered clockwise or -#cat: counter-clockwise. -#cat: The routine also requires a default return value be -#cat: specified in the case the the routine is not able to -#cat: definitively determine the chains direction. This allows -#cat: the default response to be application-specific. - - Input: - chain - chain code vector - nchain - number of codes in chain - default_ret - default return code (used when we can't tell the order) - Return Code: - TRUE - chain determined to be ordered clockwise - FALSE - chain determined to be ordered counter-clockwise - Default - could not determine the order of the chain -**************************************************************************/ -static int is_chain_clockwise(const int *chain, const int nchain, - const int default_ret) -{ - int i, j, d, sum; - - /* Initialize turn-accumulator to 0. */ - sum = 0; - - /* Foreach neighboring code in chain, compute the difference in */ - /* direction and accumulate. Left-hand turns increment, whereas */ - /* right-hand decrement. */ - for(i = 0, j =1; i < nchain-1; i++, j++){ - /* Compute delta in neighbor direction. */ - d = chain[j] - chain[i]; - /* Make the delta the "inner" distance. */ - /* If delta >= 4, for example if chain_i==2 and chain_j==7 (which */ - /* means the contour went from a step up to step down-to-the-right) */ - /* then 5=(7-2) which is >=4, so -3=(5-8) which means that the */ - /* change in direction is a righ-hand turn of 3 units). */ - if(d >= 4) - d -= 8; - /* If delta <= -4, for example if chain_i==7 and chain_j==2 (which */ - /* means the contour went from a step down-to-the-right to step up) */ - /* then -5=(2-7) which is <=-4, so 3=(-5+8) which means that the */ - /* change in direction is a left-hand turn of 3 units). */ - else if (d <= -4) - d += 8; - - /* The delta direction is then accumulated. */ - sum += d; - } - - /* Now we need to add in the final delta direction between the last */ - /* and first codes in the chain. */ - d = chain[0] - chain[i]; - if(d >= 4) - d -= 8; - else if (d <= -4) - d += 8; - sum += d; - - /* If the final turn_accumulator == 0, then we CAN'T TELL the */ - /* direction of the chain code, so return the default return value. */ - if(sum == 0) - return(default_ret); - /* Otherwise, if the final turn-accumulator is positive ... */ - else if(sum > 0) - /* Then we had a greater amount of left-hand turns than right-hand */ - /* turns, so the chain is in COUNTER-CLOCKWISE order, so return FALSE. */ - return(FALSE); - /* Otherwise, the final turn-accumulator is negative ... */ - else - /* So we had a greater amount of right-hand turns than left-hand */ - /* turns, so the chain is in CLOCKWISE order, so return TRUE. */ - return(TRUE); -} - /************************************************************************* ************************************************************************** #cat: get_loop_list - Takes a list of minutia points and determines which @@ -228,78 +99,6 @@ static int is_chain_clockwise(const int *chain, const int nchain, Zero - successful completion Negative - system error **************************************************************************/ -int get_loop_list(int **oonloop, MINUTIAE *minutiae, const int loop_len, - unsigned char *bdata, const int iw, const int ih) -{ - int i, ret; - int *onloop; - MINUTIA *minutia; - - /* Allocate a list of onloop flags (one for each minutia in list). */ - onloop = (int *)malloc(minutiae->num * sizeof(int)); - if(onloop == (int *)NULL){ - fprintf(stderr, "ERROR : get_loop_list : malloc : onloop\n"); - return(-320); - } - - i = 0; - /* Foreach minutia remaining in list ... */ - while(i < minutiae->num){ - /* Assign a temporary pointer. */ - minutia = minutiae->list[i]; - /* If current minutia is a bifurcation ... */ - if(minutia->type == BIFURCATION){ - /* Check to see if it is on a loop of specified length. */ - ret = on_loop(minutia, loop_len, bdata, iw, ih); - /* If minutia is on a loop... */ - if(ret == LOOP_FOUND){ - /* Then set the onloop flag to TRUE. */ - onloop[i] = TRUE; - /* Advance to next minutia in the list. */ - i++; - } - /* If on loop test IGNORED ... */ - else if (ret == IGNORE){ - /* Remove the current minutia from the list. */ - if((ret = remove_minutia(i, minutiae))){ - /* Deallocate working memory. */ - free(onloop); - /* Return error code. */ - return(ret); - } - /* No need to advance because next minutia has "slid" */ - /* into position pointed to by 'i'. */ - } - /* If the minutia is NOT on a loop... */ - else if (ret == FALSE){ - /* Then set the onloop flag to FALSE. */ - onloop[i] = FALSE; - /* Advance to next minutia in the list. */ - i++; - } - /* Otherwise, an ERROR occurred while looking for loop. */ - else{ - /* Deallocate working memory. */ - free(onloop); - /* Return error code. */ - return(ret); - } - } - /* Otherwise, the current minutia is a ridge-ending... */ - else{ - /* Ridge-endings will never be on a loop, so set flag to FALSE. */ - onloop[i] = FALSE; - /* Advance to next minutia in the list. */ - i++; - } - } - - /* Store flag list to output pointer. */ - *oonloop = onloop; - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -558,7 +357,7 @@ int on_hook(const MINUTIA *minutia1, const MINUTIA *minutia2, /* If trace had an error in following the contour ... */ if(ret != 0) return(ret); - + /* Otherwise, the trace successfully followed the contour, but did */ /* not encounter the 2nd minutia point within the specified number */ @@ -648,107 +447,6 @@ int is_loop_clockwise(const int *contour_x, const int *contour_y, return(ret); } -/************************************************************************* -************************************************************************** -#cat: get_loop_aspect - Takes a contour list (determined to form a complete -#cat: loop) and measures the loop's aspect (the largest and smallest -#cat: distances across the loop) and returns the points on the -#cat: loop where these distances occur. - - Input: - contour_x - x-coord list for loop's contour points - contour_y - y-coord list for loop's contour points - ncontour - number of points in contour - Output: - omin_fr - contour point index where minimum aspect occurs - omin_to - opposite contour point index where minimum aspect occurs - omin_dist - the minimum distance across the loop - omax_fr - contour point index where maximum aspect occurs - omax_to - contour point index where maximum aspect occurs - omax_dist - the maximum distance across the loop -**************************************************************************/ -static void get_loop_aspect(int *omin_fr, int *omin_to, double *omin_dist, - int *omax_fr, int *omax_to, double *omax_dist, - const int *contour_x, const int *contour_y, const int ncontour) -{ - int halfway, limit; - int i, j; - double dist; - double min_dist, max_dist; - int min_i, max_i, min_j, max_j; - - /* Compute half the perimeter of the loop. */ - halfway = ncontour>>1; - - /* Take opposite points on the contour and walk half way */ - /* around the loop. */ - i = 0; - j = halfway; - /* Compute squared distance between opposite points on loop. */ - dist = squared_distance(contour_x[i], contour_y[i], - contour_x[j], contour_y[j]); - - /* Initialize running minimum and maximum distances along loop. */ - min_dist = dist; - min_i = i; - min_j = j; - max_dist = dist; - max_i = i; - max_j = j; - /* Bump to next pair of opposite points. */ - i++; - /* Make sure j wraps around end of list. */ - j++; - j %= ncontour; - - /* If the loop is of even length, then we only need to walk half */ - /* way around as the other half will be exactly redundant. If */ - /* the loop is of odd length, then the second half will not be */ - /* be exactly redundant and the difference "may" be meaningful. */ - /* If execution speed is an issue, then probably get away with */ - /* walking only the fist half of the loop under ALL conditions. */ - - /* If loop has odd length ... */ - if(ncontour % 2) - /* Walk the loop's entire perimeter. */ - limit = ncontour; - /* Otherwise the loop has even length ... */ - else - /* Only walk half the perimeter. */ - limit = halfway; - - /* While we have not reached our perimeter limit ... */ - while(i < limit){ - /* Compute squared distance between opposite points on loop. */ - dist = squared_distance(contour_x[i], contour_y[i], - contour_x[j], contour_y[j]); - /* Check the running minimum and maximum distances. */ - if(dist < min_dist){ - min_dist = dist; - min_i = i; - min_j = j; - } - if(dist > max_dist){ - max_dist = dist; - max_i = i; - max_j = j; - } - /* Bump to next pair of opposite points. */ - i++; - /* Make sure j wraps around end of list. */ - j++; - j %= ncontour; - } - - /* Assign minimum and maximum distances to output pointers. */ - *omin_fr = min_i; - *omin_to = min_j; - *omin_dist = min_dist; - *omax_fr = max_i; - *omax_to = max_j; - *omax_dist = max_dist; -} - /************************************************************************* ************************************************************************** #cat: process_loop - Takes a contour list that has been determined to form @@ -776,131 +474,6 @@ static void get_loop_aspect(int *omin_fr, int *omin_to, double *omin_dist, Zero - loop processed successfully Negative - system error **************************************************************************/ -int process_loop(MINUTIAE *minutiae, - const int *contour_x, const int *contour_y, - const int *contour_ex, const int *contour_ey, const int ncontour, - unsigned char *bdata, const int iw, const int ih, - const LFSPARMS *lfsparms) -{ - int idir, type, appearing; - double min_dist, max_dist; - int min_fr, max_fr, min_to, max_to; - int mid_x, mid_y, mid_pix; - int feature_pix; - int ret; - MINUTIA *minutia; - - /* If contour is empty, then just return. */ - if(ncontour <= 0) - return(0); - - /* If loop is large enough ... */ - if(ncontour > lfsparms->min_loop_len){ - /* Get pixel value of feature's interior. */ - feature_pix = *(bdata + (contour_y[0] * iw) + contour_x[0]); - - /* Get the aspect dimensions of the loop in units of */ - /* squared distance. */ - get_loop_aspect(&min_fr, &min_to, &min_dist, - &max_fr, &max_to, &max_dist, - contour_x, contour_y, ncontour); - - /* If loop passes aspect ratio tests ... loop is sufficiently */ - /* narrow or elongated ... */ - if((min_dist < lfsparms->min_loop_aspect_dist) || - ((max_dist/min_dist) >= lfsparms->min_loop_aspect_ratio)){ - - /* Update minutiae list with opposite points of max distance */ - /* on the loop. */ - - /* First, check if interior point has proper pixel value. */ - mid_x = (contour_x[max_fr]+contour_x[max_to])>>1; - mid_y = (contour_y[max_fr]+contour_y[max_to])>>1; - mid_pix = *(bdata + (mid_y * iw) + mid_x); - /* If interior point is the same as the feature... */ - if(mid_pix == feature_pix){ - - /* 1. Treat maximum distance point as a potential minutia. */ - - /* Compute direction from maximum loop point to its */ - /* opposite point. */ - idir = line2direction(contour_x[max_fr], contour_y[max_fr], - contour_x[max_to], contour_y[max_to], - lfsparms->num_directions); - /* Get type of minutia: BIFURCATION or RIDGE_ENDING. */ - type = minutia_type(feature_pix); - /* Determine if minutia is appearing or disappearing. */ - if((appearing = is_minutia_appearing( - contour_x[max_fr], contour_y[max_fr], - contour_ex[max_fr], contour_ey[max_fr])) < 0){ - /* Return system error code. */ - return(appearing); - } - /* Create new minutia object. */ - if((ret = create_minutia(&minutia, - contour_x[max_fr], contour_y[max_fr], - contour_ex[max_fr], contour_ey[max_fr], - idir, DEFAULT_RELIABILITY, - type, appearing, LOOP_ID))){ - /* Return system error code. */ - return(ret); - } - /* Update the minutiae list with potential new minutia. */ - ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); - - /* If minuitia IGNORED and not added to the minutia list ... */ - if(ret == IGNORE) - /* Deallocate the minutia. */ - free_minutia(minutia); - - /* 2. Treat point opposite of maximum distance point as */ - /* a potential minutia. */ - - /* Flip the direction 180 degrees. Make sure new direction */ - /* is on the range [0..(ndirsX2)]. */ - idir += lfsparms->num_directions; - idir %= (lfsparms->num_directions<<1); - - /* The type of minutia will stay the same. */ - - /* Determine if minutia is appearing or disappearing. */ - if((appearing = is_minutia_appearing( - contour_x[max_to], contour_y[max_to], - contour_ex[max_to], contour_ey[max_to])) < 0){ - /* Return system error code. */ - return(appearing); - } - /* Create new minutia object. */ - if((ret = create_minutia(&minutia, - contour_x[max_to], contour_y[max_to], - contour_ex[max_to], contour_ey[max_to], - idir, DEFAULT_RELIABILITY, - type, appearing, LOOP_ID))){ - /* Return system error code. */ - return(ret); - } - /* Update the minutiae list with potential new minutia. */ - ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); - - /* If minuitia IGNORED and not added to the minutia list ... */ - if(ret == IGNORE) - /* Deallocate the minutia. */ - free_minutia(minutia); - - /* Done successfully processing this loop, so return normally. */ - return(0); - - } /* Otherwise, loop interior has problems. */ - } /* Otherwise, loop is not the right shape for minutiae. */ - } /* Otherwise, loop's perimeter is too small for minutiae. */ - - /* If we get here, we have a loop that is assumed to not contain */ - /* minutiae, so remove the loop from the image. */ - ret = fill_loop(contour_x, contour_y, ncontour, bdata, iw, ih); - - /* Return either an error code from fill_loop or return normally. */ - return(ret); -} /************************************************************************* ************************************************************************** @@ -936,6 +509,7 @@ int process_loop_V2(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, int *plow_flow_map, const LFSPARMS *lfsparms) { + int halfway; int idir, type, appearing; double min_dist, max_dist; int min_fr, max_fr, min_to, max_to; @@ -955,6 +529,9 @@ int process_loop_V2(MINUTIAE *minutiae, /* Get pixel value of feature's interior. */ feature_pix = *(bdata + (contour_y[0] * iw) + contour_x[0]); + /* Compute half the perimeter of the loop. */ + halfway = ncontour>>1; + /* Get the aspect dimensions of the loop in units of */ /* squared distance. */ get_loop_aspect(&min_fr, &min_to, &min_dist, @@ -1087,39 +664,103 @@ int process_loop_V2(MINUTIAE *minutiae, /************************************************************************* ************************************************************************** -#cat: fill_partial_row - Fills a specified range of contiguous pixels on -#cat: a specified row of an 8-bit pixel image with a specified -#cat: pixel value. NOTE, the pixel coordinates are assumed to -#cat: be within the image boundaries. +#cat: get_loop_aspect - Takes a contour list (determined to form a complete +#cat: loop) and measures the loop's aspect (the largest and smallest +#cat: distances across the loop) and returns the points on the +#cat: loop where these distances occur. Input: - fill_pix - pixel value to fill with (should be on range [0..255] - frx - x-pixel coord where fill should begin - tox - x-pixel coord where fill should end (inclusive) - y - y-pixel coord of current row being filled - bdata - 8-bit image data - iw - width (in pixels) of image - ih - height (in pixels) of image + contour_x - x-coord list for loop's contour points + contour_y - y-coord list for loop's contour points + ncontour - number of points in contour Output: - bdata - 8-bit image data with partial row filled. + omin_fr - contour point index where minimum aspect occurs + omin_to - opposite contour point index where minimum aspect occurs + omin_dist - the minimum distance across the loop + omax_fr - contour point index where maximum aspect occurs + omax_to - contour point index where maximum aspect occurs + omax_dist - the maximum distance across the loop **************************************************************************/ -static void fill_partial_row(const int fill_pix, const int frx, const int tox, - const int y, unsigned char *bdata, const int iw, const int ih) +void get_loop_aspect(int *omin_fr, int *omin_to, double *omin_dist, + int *omax_fr, int *omax_to, double *omax_dist, + const int *contour_x, const int *contour_y, const int ncontour) { - int x; - unsigned char *bptr; + int halfway, limit; + int i, j; + double dist; + double min_dist, max_dist; + int min_i, max_i, min_j, max_j; - /* Set pixel pointer to starting x-coord on current row. */ - bptr = bdata+(y*iw)+frx; + /* Compute half the perimeter of the loop. */ + halfway = ncontour>>1; - /* Foreach pixel between starting and ending x-coord on row */ - /* (including the end points) ... */ - for(x = frx; x <= tox; x++){ - /* Set current pixel with fill pixel value. */ - *bptr = fill_pix; - /* Bump to next pixel in the row. */ - bptr++; + /* Take opposite points on the contour and walk half way */ + /* around the loop. */ + i = 0; + j = halfway; + /* Compute squared distance between opposite points on loop. */ + dist = squared_distance(contour_x[i], contour_y[i], + contour_x[j], contour_y[j]); + + /* Initialize running minimum and maximum distances along loop. */ + min_dist = dist; + min_i = i; + min_j = j; + max_dist = dist; + max_i = i; + max_j = j; + /* Bump to next pair of opposite points. */ + i++; + /* Make sure j wraps around end of list. */ + j++; + j %= ncontour; + + /* If the loop is of even length, then we only need to walk half */ + /* way around as the other half will be exactly redundant. If */ + /* the loop is of odd length, then the second half will not be */ + /* be exactly redundant and the difference "may" be meaningful. */ + /* If execution speed is an issue, then probably get away with */ + /* walking only the fist half of the loop under ALL conditions. */ + + /* If loop has odd length ... */ + if(ncontour % 2) + /* Walk the loop's entire perimeter. */ + limit = ncontour; + /* Otherwise the loop has even length ... */ + else + /* Only walk half the perimeter. */ + limit = halfway; + + /* While we have not reached our perimeter limit ... */ + while(i < limit){ + /* Compute squared distance between opposite points on loop. */ + dist = squared_distance(contour_x[i], contour_y[i], + contour_x[j], contour_y[j]); + /* Check the running minimum and maximum distances. */ + if(dist < min_dist){ + min_dist = dist; + min_i = i; + min_j = j; + } + if(dist > max_dist){ + max_dist = dist; + max_i = i; + max_j = j; + } + /* Bump to next pair of opposite points. */ + i++; + /* Make sure j wraps around end of list. */ + j++; + j %= ncontour; } + + /* Assign minimum and maximum distances to output pointers. */ + *omin_fr = min_i; + *omin_to = min_j; + *omin_dist = min_dist; + *omax_fr = max_i; + *omax_to = max_j; + *omax_dist = max_dist; } /************************************************************************* @@ -1253,3 +894,119 @@ int fill_loop(const int *contour_x, const int *contour_y, return(0); } +/************************************************************************* +************************************************************************** +#cat: fill_partial_row - Fills a specified range of contiguous pixels on +#cat: a specified row of an 8-bit pixel image with a specified +#cat: pixel value. NOTE, the pixel coordinates are assumed to +#cat: be within the image boundaries. + + Input: + fill_pix - pixel value to fill with (should be on range [0..255] + frx - x-pixel coord where fill should begin + tox - x-pixel coord where fill should end (inclusive) + y - y-pixel coord of current row being filled + bdata - 8-bit image data + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + bdata - 8-bit image data with partial row filled. +**************************************************************************/ +void fill_partial_row(const int fill_pix, const int frx, const int tox, + const int y, unsigned char *bdata, const int iw, const int ih) +{ + int x; + unsigned char *bptr; + + /* Set pixel pointer to starting x-coord on current row. */ + bptr = bdata+(y*iw)+frx; + + /* Foreach pixel between starting and ending x-coord on row */ + /* (including the end points) ... */ + for(x = frx; x <= tox; x++){ + /* Set current pixel with fill pixel value. */ + *bptr = fill_pix; + /* Bump to next pixel in the row. */ + bptr++; + } +} + +/************************************************************************* +************************************************************************** +#cat: flood_loop - Fills a given contour (determined to form a complete loop) +#cat: with a specified pixel value using a recursive flood-fill +#cat: technique. +#cat: NOTE, this fill approach will NOT always work with the +#cat: contours generated in this application because they +#cat: are NOT guaranteed to be ENTIRELY surrounded by 8-connected +#cat: pixels not equal to the fill pixel value. This is unfortunate +#cat: because the flood-fill is a simple algorithm that will handle +#cat: complex/concaved shapes. + + Input: + contour_x - x-coord list for loop's contour points + contour_y - y-coord list for loop's contour points + ncontour - number of points in contour + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + bdata - binary image data with loop filled +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: flood_fill4 - Recursively floods a region of an 8-bit pixel image with a +#cat: specified pixel value given a starting (seed) point. The +#cat: recursion is based neighbors being 4-connected. + + Input: + fill_pix - 8-bit pixel value to be filled with (on range [0..255] + x - starting x-pixel coord + y - starting y-pixel coord + bdata - 8-bit pixel image data + iw - width (in pixels) of image + ih - height (in pixels) of image + Output: + bdata - 8-bit pixel image data with region filled +**************************************************************************/ +void flood_fill4(const int fill_pix, const int x, const int y, + unsigned char *bdata, const int iw, const int ih) +{ + unsigned char *pptr; + int y_north, y_south, x_east, x_west; + + /* Get address of current pixel. */ + pptr = bdata + (y*iw) + x; + /* If pixel needs to be filled ... */ + if(*pptr != fill_pix){ + /* Fill the current pixel. */ + *pptr = fill_pix; + + /* Recursively invoke flood on the pixel's 4 neighbors. */ + /* Test to make sure neighbors are within image boudaries */ + /* before invoking each flood. */ + y_north = y-1; + y_south = y+1; + x_west = x-1; + x_east = x+1; + + /* Invoke North */ + if(y_north >= 0) + flood_fill4(fill_pix, x, y_north, bdata, iw, ih); + + /* Invoke East */ + if(x_east < iw) + flood_fill4(fill_pix, x_east, y, bdata, iw, ih); + + /* Invoke South */ + if(y_south < ih) + flood_fill4(fill_pix, x, y_south, bdata, iw, ih); + + /* Invoke West */ + if(x_west >= 0) + flood_fill4(fill_pix, x_west, y, bdata, iw, ih); + } + + /* Otherwise, there is nothing to be done. */ +} diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index 43929a4b..5cd031b4 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -46,6 +67,7 @@ identified are necessarily the best available for the purpose. pixelize_map() smooth_direction_map() gen_high_curve_map() + gen_imap() gen_initial_imap() primary_dir_test() secondary_fork_test() @@ -58,6 +80,7 @@ identified are necessarily the best available for the purpose. average_8nbr_dir() num_valid_8nbrs() smooth_imap() + gen_nmap() vorticity() accum_nbr_vorticity() curvature() @@ -65,8 +88,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include -#include #include #include #include @@ -307,10 +328,6 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, xmaxlimit = pw - dftgrids->pad - lfsparms->windowsize - 1; ymaxlimit = ph - dftgrids->pad - lfsparms->windowsize - 1; - /* max limits should not be negative */ - xmaxlimit = MAX(xmaxlimit, 0); - ymaxlimit = MAX(ymaxlimit, 0); - /* Foreach block in image ... */ for(bi = 0; bi < bsize; bi++){ /* Adjust block offset from pointing to block origin to pointing */ @@ -393,9 +410,9 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, { int _w; fprintf(logfp, " Power\n"); for(_w = 0; _w < nstats; _w++){ - /* Add 1 to wis[w] to create index to original dft_coefs[] */ + /* Add 1 to wis[w] to create index to original g_dft_coefs[] */ fprintf(logfp, " wis[%d] %d %12.3f %2d %9.3f %12.3f\n", - _w, wis[_w]+1, + _w, wis[_w]+1, powmaxs[wis[_w]], powmax_dirs[wis[_w]], pownorms[wis[_w]], powers[0][powmax_dirs[wis[_w]]]); } @@ -647,7 +664,7 @@ int morph_TF_map(int *tfmap, const int mw, const int mh, unsigned char *cimage, *mimage, *cptr; int *mptr; int i; - + /* Convert TRUE/FALSE map into a binary byte image. */ cimage = (unsigned char *)malloc(mw*mh); @@ -925,13 +942,37 @@ int gen_high_curve_map(int **ohcmap, int *direction_map, } /* bx */ } /* by */ - /* Assign High Curvature Map to output pointer. */ + /* Assign High Curvature Map to output pointer. */ *ohcmap = high_curve_map; /* Return normally. */ return(0); } +/************************************************************************* +************************************************************************** +#cat: gen_imap - Computes an IMAP, which is a 2D vector of integer directions, +#cat: where each direction represents the dominant ridge flow in +#cat: a block of the input grayscale image. This routine will +#cat: generate an IMAP for arbitrarily sized, non-square, images. + + Input: + pdata - padded input image data (8 bits [0..256) grayscale) + pw - padded width (in pixels) of the input image + ph - padded height (in pixels) of the input image + dir2rad - lookup table for converting integer directions + dftwaves - structure containing the DFT wave forms + dftgrids - structure containing the rotated pixel grid offsets + lfsparms - parameters and thresholds for controlling LFS + Output: + optr - points to the created IMAP + ow - width (in blocks) of the IMAP + oh - height (in blocks) of the IMAP + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: gen_initial_imap - Creates an initial IMAP from the given input image. @@ -959,126 +1000,6 @@ int gen_high_curve_map(int **ohcmap, int *direction_map, Zero - successful completion Negative - system error **************************************************************************/ -int gen_initial_imap(int **optr, int *blkoffs, const int mw, const int mh, - unsigned char *pdata, const int pw, const int ph, - const DFTWAVES *dftwaves, const ROTGRIDS *dftgrids, - const LFSPARMS *lfsparms) -{ - int *imap; - int bi, bsize, blkdir; - int *wis, *powmax_dirs; - double **powers, *powmaxs, *pownorms; - int nstats; - int ret; /* return code */ - - print2log("INITIAL MAP\n"); - - /* Compute total number of blocks in IMAP */ - bsize = mw * mh; - - /* Allocate IMAP memory */ - imap = (int *)malloc(bsize * sizeof(int)); - if(imap == (int *)NULL){ - fprintf(stderr, "ERROR : gen_initial_imap : malloc : imap\n"); - return(-70); - } - - /* Allocate DFT directional power vectors */ - if((ret = alloc_dir_powers(&powers, dftwaves->nwaves, dftgrids->ngrids))){ - /* Free memory allocated to this point. */ - free(imap); - return(ret); - } - - /* Allocate DFT power statistic arrays */ - /* Compute length of statistics arrays. Statistics not needed */ - /* for the first DFT wave, so the length is number of waves - 1. */ - nstats = dftwaves->nwaves - 1; - if((ret = alloc_power_stats(&wis, &powmaxs, &powmax_dirs, - &pownorms, nstats))){ - /* Free memory allocated to this point. */ - free(imap); - free_dir_powers(powers, dftwaves->nwaves); - return(ret); - } - - /* Initialize the imap to -1 */ - memset(imap, INVALID_DIR, bsize * sizeof(int)); - - /* Foreach block in imap ... */ - for(bi = 0; bi < bsize; bi++){ - - print2log(" BLOCK %2d (%2d, %2d)\n", bi, bi%mw, bi/mw); - - /* Compute DFT powers */ - if((ret = dft_dir_powers(powers, pdata, blkoffs[bi], pw, ph, - dftwaves, dftgrids))){ - /* Free memory allocated to this point. */ - free(imap); - free_dir_powers(powers, dftwaves->nwaves); - free(wis); - free(powmaxs); - free(powmax_dirs); - free(pownorms); - return(ret); - } - - /* Compute DFT power statistics, skipping first applied DFT */ - /* wave. This is dependent on how the primary and secondary */ - /* direction tests work below. */ - if((ret = dft_power_stats(wis, powmaxs, powmax_dirs, pownorms, powers, - 1, dftwaves->nwaves, dftgrids->ngrids))){ - /* Free memory allocated to this point. */ - free(imap); - free_dir_powers(powers, dftwaves->nwaves); - free(wis); - free(powmaxs); - free(powmax_dirs); - free(pownorms); - return(ret); - } - -#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ - { int _w; - fprintf(logfp, " Power\n"); - for(_w = 0; _w < nstats; _w++){ - /* Add 1 to wis[w] to create index to original dft_coefs[] */ - fprintf(logfp, " wis[%d] %d %12.3f %2d %9.3f %12.3f\n", - _w, wis[_w]+1, - powmaxs[wis[_w]], powmax_dirs[wis[_w]], pownorms[wis[_w]], - powers[0][powmax_dirs[wis[_w]]]); - } - } -#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ - - /* Conduct primary direction test */ - blkdir = primary_dir_test(powers, wis, powmaxs, powmax_dirs, - pownorms, nstats, lfsparms); - - if(blkdir != INVALID_DIR) - imap[bi] = blkdir; - else{ - /* Conduct secondary (fork) direction test */ - blkdir = secondary_fork_test(powers, wis, powmaxs, powmax_dirs, - pownorms, nstats, lfsparms); - if(blkdir != INVALID_DIR) - imap[bi] = blkdir; - } - - /* Otherwise current block direction in IMAP remains INVALID */ - - } /* bi */ - - /* Deallocate working memory */ - free_dir_powers(powers, dftwaves->nwaves); - free(wis); - free(powmaxs); - free(powmax_dirs); - free(pownorms); - - *optr = imap; - return(0); -} /************************************************************************* ************************************************************************** @@ -1093,7 +1014,7 @@ int gen_initial_imap(int **optr, int *blkoffs, const int mw, const int mh, powmaxs - maximum power for each of the highest N-1 frequencies powmax_dirs - directions associated with each of the N-1 maximum powers pownorms - normalized power for each of the highest N-1 frequencies - nstats - N-1 wave frequencies (where N is the length of dft_coefs) + nstats - N-1 wave frequencies (where N is the length of g_dft_coefs) lfsparms - parameters and thresholds for controlling LFS Return Code: Zero or Positive - The selected IMAP integer direction @@ -1120,7 +1041,7 @@ int primary_dir_test(double **powers, const int *wis, (powers[0][powmax_dirs[wis[w]]] <= lfsparms->powmax_max)){ #ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ - /* Add 1 to wis[w] to create index to original dft_coefs[] */ + /* Add 1 to wis[w] to create index to original g_dft_coefs[] */ fprintf(logfp, " Selected Wave = %d\n", wis[w]+1); fprintf(logfp, @@ -1177,7 +1098,7 @@ int primary_dir_test(double **powers, const int *wis, powmaxs - maximum power for each of the highest N-1 frequencies powmax_dirs - directions associated with each of the N-1 maximum powers pownorms - normalized power for each of the highest N-1 frequencies - nstats - N-1 wave frequencies (where N is the length of dft_coefs) + nstats - N-1 wave frequencies (where N is the length of g_dft_coefs) lfsparms - parameters and thresholds for controlling LFS Return Code: Zero or Positive - The selected IMAP integer direction @@ -2022,76 +1943,29 @@ int num_valid_8nbrs(int *imap, const int mx, const int my, Output: imap - vector of smoothed input values **************************************************************************/ -void smooth_imap(int *imap, const int mw, const int mh, - const DIR2RAD *dir2rad, const LFSPARMS *lfsparms) -{ - int mx, my; - int *iptr; - int avrdir, nvalid; - double dir_strength; - print2log("SMOOTH MAP\n"); +/************************************************************************* +************************************************************************** +#cat: gen_nmap - Computes an NMAP from its associated 2D vector of integer +#cat: directions (IMAP). Each value in the NMAP either represents +#cat: a direction of dominant ridge flow in a block of the input +#cat: grayscale image, or it contains a codes describing why such +#cat: a direction was not procuded. +#cat: For example, blocks near areas of high-curvature (such as +#cat: with cores and deltas) will not produce reliable IMAP +#cat: directions. - iptr = imap; - for(my = 0; my < mh; my++){ - for(mx = 0; mx < mw; mx++){ - /* Compute average direction from neighbors, returning the */ - /* number of valid neighbors used in the computation, and */ - /* the "strength" of the average direction. */ - average_8nbr_dir(&avrdir, &dir_strength, &nvalid, - imap, mx, my, mw, mh, dir2rad); - - /* If average direction strength is strong enough */ - /* (Ex. thresh==0.2)... */ - if(dir_strength >= lfsparms->dir_strength_min){ - /* If IMAP direction is valid ... */ - if(*iptr != INVALID_DIR){ - /* Conduct valid neighbor test (Ex. thresh==3)... */ - if(nvalid >= lfsparms->rmv_valid_nbr_min){ - -#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ - fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", - mx+(my*mw), mx, my); - fprintf(logfp, " Average NBR : %2d %6.3f %d\n", - avrdir, dir_strength, nvalid); - fprintf(logfp, " 1. Valid NBR (%d >= %d)\n", - nvalid, lfsparms->rmv_valid_nbr_min); - fprintf(logfp, " Valid Direction = %d\n", *iptr); - fprintf(logfp, " Smoothed Direction = %d\n", avrdir); -#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ - - /* Reassign valid IMAP direction with average direction. */ - *iptr = avrdir; - } - } - /* Otherwise IMAP direction is invalid ... */ - else{ - /* Even if IMAP value is invalid, if number of valid */ - /* neighbors is big enough (Ex. thresh==7)... */ - if(nvalid >= lfsparms->smth_valid_nbr_min){ - -#ifdef LOG_REPORT /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ - fprintf(logfp, " BLOCK %2d (%2d, %2d)\n", - mx+(my*mw), mx, my); - fprintf(logfp, " Average NBR : %2d %6.3f %d\n", - avrdir, dir_strength, nvalid); - fprintf(logfp, " 2. Invalid NBR (%d >= %d)\n", - nvalid, lfsparms->smth_valid_nbr_min); - fprintf(logfp, " Invalid Direction = %d\n", *iptr); - fprintf(logfp, " Smoothed Direction = %d\n", avrdir); -#endif /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ - - /* Assign invalid IMAP direction with average direction. */ - *iptr = avrdir; - } - } - } - - /* Bump to next IMAP direction. */ - iptr++; - } - } -} + Input: + imap - associated input vector of IMAP directions + mw - the width (in blocks) of the IMAP + mh - the height (in blocks) of the IMAP + lfsparms - parameters and thresholds for controlling LFS + Output: + optr - points to the created NMAP + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ /************************************************************************* ************************************************************************** diff --git a/libfprint/nbis/mindtct/matchpat.c b/libfprint/nbis/mindtct/matchpat.c index 04bb27b8..290d00c5 100644 --- a/libfprint/nbis/mindtct/matchpat.c +++ b/libfprint/nbis/mindtct/matchpat.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -46,14 +67,14 @@ identified are necessarily the best available for the purpose. /************************************************************************* ************************************************************************** -#cat: match_1st_pair - Determines which of the feature_patterns[] have their +#cat: match_1st_pair - Determines which of the g_feature_patterns[] have their #cat: first pixel pair match the specified pixel pair. Input: p1 - first pixel value of pair p2 - second pixel value of pair Output: - possible - list of matching feature_patterns[] indices + possible - list of matching g_feature_patterns[] indices nposs - number of matches Return Code: nposs - number of matches @@ -84,16 +105,16 @@ int match_1st_pair(unsigned char p1, unsigned char p2, /************************************************************************* ************************************************************************** -#cat: match_2nd_pair - Determines which of the passed feature_patterns[] have +#cat: match_2nd_pair - Determines which of the passed g_feature_patterns[] have #cat: their second pixel pair match the specified pixel pair. Input: p1 - first pixel value of pair p2 - second pixel value of pair - possible - list of potentially-matching feature_patterns[] indices + possible - list of potentially-matching g_feature_patterns[] indices nposs - number of potential matches Output: - possible - list of matching feature_patterns[] indices + possible - list of matching g_feature_patterns[] indices nposs - number of matches Return Code: nposs - number of matches @@ -132,16 +153,16 @@ int match_2nd_pair(unsigned char p1, unsigned char p2, /************************************************************************* ************************************************************************** -#cat: match_3rd_pair - Determines which of the passed feature_patterns[] have +#cat: match_3rd_pair - Determines which of the passed g_feature_patterns[] have #cat: their third pixel pair match the specified pixel pair. Input: p1 - first pixel value of pair p2 - second pixel value of pair - possible - list of potentially-matching feature_patterns[] indices + possible - list of potentially-matching g_feature_patterns[] indices nposs - number of potential matches Output: - possible - list of matching feature_patterns[] indices + possible - list of matching g_feature_patterns[] indices nposs - number of matches Return Code: nposs - number of matches diff --git a/libfprint/nbis/mindtct/minutia.c b/libfprint/nbis/mindtct/minutia.c index 497336b1..ca0d551c 100644 --- a/libfprint/nbis/mindtct/minutia.c +++ b/libfprint/nbis/mindtct/minutia.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -37,6 +58,7 @@ identified are necessarily the best available for the purpose. ROUTINES: alloc_minutiae() realloc_minutiae() + detect_minutiae() detect_minutiae_V2() update_minutiae() update_minutiae_V2() @@ -73,30 +95,26 @@ identified are necessarily the best available for the purpose. adjust_high_curvature_minutia() adjust_high_curvature_minutia_V2() get_low_curvature_direction() - lfs2nist_minutia_XYT() ***********************************************************************/ #include -#include #include - - /************************************************************************* ************************************************************************** #cat: alloc_minutiae - Allocates and initializes a minutia list based on the #cat: specified maximum number of minutiae to be detected. Input: - max_minutiae - number of minutia to be allocated in list + DEFAULT_BOZORTH_MINUTIAE - number of minutia to be allocated in list Output: ominutiae - points to the allocated minutiae list Return Code: Zero - successful completion Negative - system error **************************************************************************/ -int alloc_minutiae(MINUTIAE **ominutiae, const int max_minutiae) +int alloc_minutiae(MINUTIAE **ominutiae, const int DEFAULT_BOZORTH_MINUTIAE) { MINUTIAE *minutiae; @@ -105,13 +123,13 @@ int alloc_minutiae(MINUTIAE **ominutiae, const int max_minutiae) fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae\n"); exit(-430); } - minutiae->list = (MINUTIA **)malloc(max_minutiae * sizeof(MINUTIA *)); + minutiae->list = (MINUTIA **)malloc(DEFAULT_BOZORTH_MINUTIAE * sizeof(MINUTIA *)); if(minutiae->list == (MINUTIA **)NULL){ fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae->list\n"); exit(-431); } - minutiae->alloc = max_minutiae; + minutiae->alloc = DEFAULT_BOZORTH_MINUTIAE; minutiae->num = 0; *ominutiae = minutiae; @@ -126,7 +144,7 @@ int alloc_minutiae(MINUTIAE **ominutiae, const int max_minutiae) Input: minutiae - previously allocated list of minutiae points - max_minutiae - number of minutia to be allocated in list + DEFAULT_BOZORTH_MINUTIAE - number of minutia to be allocated in list Output: minutiae - extended list of minutiae points Return Code: @@ -146,6 +164,29 @@ int realloc_minutiae(MINUTIAE *minutiae, const int incr_minutiae) return(0); } +/************************************************************************* +************************************************************************** +#cat: detect_minutiae - Takes a binary image and its associated IMAP and +#cat: NMAP matrices and scans each image block for potential +#cat: minutia points. + + Input: + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + imap - matrix of ridge flow directions + nmap - IMAP augmented with blocks of HIGH-CURVATURE and + blocks which have no neighboring valid directions. + mw - width (in blocks) of IMAP and NMAP matrices. + mh - height (in blocks) of IMAP and NMAP matrices. + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - points to a list of detected minutia structures + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: detect_minutiae_V2 - Takes a binary image and its associated @@ -666,40 +707,6 @@ int rm_dup_minutiae(MINUTIAE *minutiae) Output: fpout - open file pointer **************************************************************************/ -void dump_minutiae(FILE *fpout, const MINUTIAE *minutiae) -{ - int i, j; - - fprintf(fpout, "\n%d Minutiae Detected\n\n", minutiae->num); - - for(i = 0; i < minutiae->num; i++){ - /* Precision of reliablity added one decimal position */ - /* on 09-13-04 */ - fprintf(fpout, "%4d : %4d, %4d : %2d : %6.3f :", i, - minutiae->list[i]->x, minutiae->list[i]->y, - minutiae->list[i]->direction, minutiae->list[i]->reliability); - if(minutiae->list[i]->type == RIDGE_ENDING) - fprintf(fpout, "RIG : "); - else - fprintf(fpout, "BIF : "); - - if(minutiae->list[i]->appearing) - fprintf(fpout, "APP : "); - else - fprintf(fpout, "DIS : "); - - fprintf(fpout, "%2d ", minutiae->list[i]->feature_id); - - for(j = 0; j < minutiae->list[i]->num_nbrs; j++){ - fprintf(fpout, ": %4d,%4d; %2d ", - minutiae->list[minutiae->list[i]->nbrs[j]]->x, - minutiae->list[minutiae->list[i]->nbrs[j]]->y, - minutiae->list[i]->ridge_counts[j]); - } - - fprintf(fpout, "\n"); - } -} /************************************************************************* ************************************************************************** @@ -712,20 +719,6 @@ void dump_minutiae(FILE *fpout, const MINUTIAE *minutiae) Output: fpout - open file pointer **************************************************************************/ -void dump_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae) -{ - int i; - - /* First line in the output file contians the number of minutia */ - /* points to be written to the file. */ - fprintf(fpout, "%d\n", minutiae->num); - - /* Foreach minutia in list... */ - for(i = 0; i < minutiae->num; i++){ - /* Write the minutia's coordinate point to the file pointer. */ - fprintf(fpout, "%4d %4d\n", minutiae->list[i]->x, minutiae->list[i]->y); - } -} /************************************************************************* @@ -741,32 +734,6 @@ void dump_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae) Output: fpout - open file pointer **************************************************************************/ -void dump_reliable_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae, - const double reliability) -{ - int i, count; - - /* First count the number of qualifying minutiae so that the */ - /* MFS header may be written. */ - count = 0; - /* Foreach minutia in list... */ - for(i = 0; i < minutiae->num; i++){ - if(minutiae->list[i]->reliability == reliability) - count++; - } - - /* First line in the output file contians the number of minutia */ - /* points to be written to the file. */ - fprintf(fpout, "%d\n", count); - - /* Foreach minutia in list... */ - for(i = 0; i < minutiae->num; i++){ - if(minutiae->list[i]->reliability == reliability) - /* Write the minutia's coordinate point to the file pointer. */ - fprintf(fpout, "%4d %4d\n", - minutiae->list[i]->x, minutiae->list[i]->y); - } -} /************************************************************************* ************************************************************************** @@ -782,7 +749,7 @@ void dump_reliable_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae, reliability - floating point measure of minutia's reliability type - type of the minutia (ridge-ending or bifurcation) appearing - designates the minutia as appearing or disappearing - feature_id - index of minutia's matching feature_patterns[] + feature_id - index of minutia's matching g_feature_patterns[] Output: ominutia - ponter to an allocated and initialized minutia structure Return Code: @@ -927,119 +894,6 @@ int remove_minutia(const int index, MINUTIAE *minutiae) Zero - successful completion Negative - system error **************************************************************************/ -int join_minutia(const MINUTIA *minutia1, const MINUTIA *minutia2, - unsigned char *bdata, const int iw, const int ih, - const int with_boundary, const int line_radius) -{ - int dx_gte_dy, delta_x, delta_y; - int *x_list, *y_list, num; - int minutia_pix, boundary_pix; - int i, j, ret; - int x1, y1, x2, y2; - - /* Compute X and Y deltas between minutia points. */ - delta_x = abs(minutia1->x - minutia2->x); - delta_y = abs(minutia1->y - minutia2->y); - - /* Set flag based on |DX| >= |DY|. */ - /* If flag is true then add additional pixel width to the join line */ - /* by adding pixels neighboring top and bottom. */ - /* If flag is false then add additional pixel width to the join line */ - /* by adding pixels neighboring left and right. */ - if(delta_x >= delta_y) - dx_gte_dy = 1; - else - dx_gte_dy = 0; - - /* Compute points along line segment between the two minutia points. */ - if((ret = line_points(&x_list, &y_list, &num, - minutia1->x, minutia1->y, minutia2->x, minutia2->y))) - /* If error with line routine, return error code. */ - return(ret); - - /* Determine pixel color of minutia and boundary. */ - if(minutia1->type == RIDGE_ENDING){ - /* To connect 2 ridge-endings, draw black. */ - minutia_pix = 1; - boundary_pix = 0; - } - else{ - /* To connect 2 bifurcations, draw white. */ - minutia_pix = 0; - boundary_pix = 1; - } - - /* Foreach point on line connecting the minutiae points ... */ - for(i = 1; i < num-1; i++){ - /* Draw minutia pixel at current point on line. */ - *(bdata+(y_list[i]*iw)+x_list[i]) = minutia_pix; - - /* Initialize starting corrdinates for adding width to the */ - /* join line to the current point on the line. */ - x1 = x_list[i]; - y1 = y_list[i]; - x2 = x1; - y2 = y1; - /* Foreach pixel of added radial width ... */ - for(j = 0; j < line_radius; j++){ - - /* If |DX|>=|DY|, we want to add width to line by writing */ - /* to pixels neighboring above and below. */ - /* x1 -= (0=(1-1)); y1 -= 1 ==> ABOVE */ - /* x2 += (0=(1-1)); y2 += 1 ==> BELOW */ - /* If |DX|<|DY|, we want to add width to line by writing */ - /* to pixels neighboring left and right. */ - /* x1 -= (1=(1-0)); y1 -= 0 ==> LEFT */ - /* x2 += (1=(1-0)); y2 += 0 ==> RIGHT */ - - /* Advance 1st point along width dimension. */ - x1 -= (1 - dx_gte_dy); - y1 -= dx_gte_dy; - /* If pixel 1st point is within image boundaries ... */ - if((x1 >= 0) && (x1 < iw) && - (y1 >= 0) && (y1 < ih)) - /* Write the pixel ABOVE or LEFT. */ - *(bdata+(y1*iw)+x1) = minutia_pix; - - /* Advance 2nd point along width dimension. */ - x2 += (1 - dx_gte_dy); - y2 += dx_gte_dy; - /* If pixel 2nd point is within image boundaries ... */ - if((x2 >= 0) && (x2 < iw) && - /* Write the pixel BELOW or RIGHT. */ - (y2 >= 0) && (y2 < ih)) - *(bdata+(y2*iw)+x2) = minutia_pix; - } - - /* If boundary flag is set ... draw the boundary pixels.*/ - if(with_boundary){ - /* Advance 1st point along width dimension. */ - x1 -= (1 - dx_gte_dy); - y1 -= dx_gte_dy; - /* If pixel 1st point is within image boundaries ... */ - if((x1 >= 0) && (x1 < iw) && - (y1 >= 0) && (y1 < ih)) - /* Write the pixel ABOVE or LEFT of opposite color. */ - *(bdata+(y1*iw)+x1) = boundary_pix; - - /* Advance 2nd point along width dimension. */ - x2 += (1 - dx_gte_dy); - y2 += dx_gte_dy; - /* If pixel 2nd point is within image boundaries ... */ - if((x2 >= 0) && (x2 < iw) && - (y2 >= 0) && (y2 < ih)) - /* Write the pixel BELOW or RIGHT of opposite color. */ - *(bdata+(y2*iw)+x2) = boundary_pix; - } - } - - /* Deallocate points along connecting line. */ - free(x_list); - free(y_list); - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -1178,61 +1032,6 @@ int choose_scan_direction(const int imapval, const int ndirs) Zero - successful completion Negative - system error **************************************************************************/ -int scan4minutiae(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const int *imap, const int *nmap, - const int blk_x, const int blk_y, const int mw, const int mh, - const int scan_x, const int scan_y, - const int scan_w, const int scan_h, const int scan_dir, - const LFSPARMS *lfsparms) -{ - int blk_i, ret; - - /* Compute block index from block coordinates. */ - blk_i = (blk_y*mw) + blk_x; - - /* Conduct primary scan for minutiae horizontally. */ - if(scan_dir == SCAN_HORIZONTAL){ - - if((ret = scan4minutiae_horizontally(minutiae, bdata, iw, ih, - imap[blk_i], nmap[blk_i], - scan_x, scan_y, scan_w, scan_h, lfsparms))){ - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - } - - /* Rescan block vertically. */ - if((ret = rescan4minutiae_vertically(minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))){ - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - } - } - - /* Otherwise, conduct primary scan for minutiae vertically. */ - else{ - if((ret = scan4minutiae_vertically(minutiae, bdata, iw, ih, - imap[blk_i], nmap[blk_i], - scan_x, scan_y, scan_w, scan_h, lfsparms))){ - /* Return resulting code. */ - return(ret); - } - - /* Rescan block horizontally. */ - if((ret = rescan4minutiae_horizontally(minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))){ - /* Return resulting code. */ - return(ret); - } - } - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -1262,116 +1061,6 @@ int scan4minutiae(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -int scan4minutiae_horizontally(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const int imapval, const int nmapval, - const int scan_x, const int scan_y, - const int scan_w, const int scan_h, - const LFSPARMS *lfsparms) -{ - int sx, sy, ex, ey, cx, cy, x2; - unsigned char *p1ptr, *p2ptr; - int possible[NFEATURES], nposs; - int ret; - - /* NOTE!!! Minutia that "straddle" region boundaries may be missed! */ - - /* If possible, overlap left and right of current scan region */ - /* by 2 pixel columns to help catch some minutia that straddle the */ - /* the scan region boundaries. */ - sx = max(0, scan_x-2); - ex = min(iw, scan_x+scan_w+2); - - /* If possible, overlap the scan region below by 1 pixel row. */ - sy = scan_y; - ey = min(ih, scan_y+scan_h+1); - - /* For now, we will not adjust for IMAP edge, as the binary image */ - /* was properly padded at its edges so as not to cause anomallies. */ - - /* Start at first row in region. */ - cy = sy; - /* While second scan row not outside the bottom of the scan region... */ - while(cy+1 < ey){ - /* Start at beginning of new scan row in region. */ - cx = sx; - /* While not at end of region's current scan row. */ - while(cx < ex){ - /* Get pixel pair from current x position in current and next */ - /* scan rows. */ - p1ptr = bdata+(cy*iw)+cx; - p2ptr = bdata+((cy+1)*iw)+cx; - /* If scan pixel pair matches first pixel pair of */ - /* 1 or more features... */ - if(match_1st_pair(*p1ptr, *p2ptr, possible, &nposs)){ - /* Bump forward to next scan pixel pair. */ - cx++; - p1ptr++; - p2ptr++; - /* If not at end of region's current scan row... */ - if(cx < ex){ - /* If scan pixel pair matches second pixel pair of */ - /* 1 or more features... */ - if(match_2nd_pair(*p1ptr, *p2ptr, possible, &nposs)){ - /* Store current x location. */ - x2 = cx; - /* Skip repeated pixel pairs. */ - skip_repeated_horizontal_pair(&cx, ex, &p1ptr, &p2ptr, - iw, ih); - /* If not at end of region's current scan row... */ - if(cx < ex){ - /* If scan pixel pair matches third pixel pair of */ - /* a single feature... */ - if(match_3rd_pair(*p1ptr, *p2ptr, possible, &nposs)){ - /* Process detected minutia point. */ - if((ret = process_horizontal_scan_minutia(minutiae, - cx, cy, x2, possible[0], - bdata, iw, ih, - imapval, nmapval, lfsparms))){ - /* Return code may be: */ - /* 1. ret< 0 (implying system error) */ - /* 2. ret==IGNORE (ignore current feature) */ - if(ret < 0) - return(ret); - /* Otherwise, IGNORE and continue. */ - } - } - - /* Set up to resume scan. */ - /* Test to see if 3rd pair can slide into 2nd pair. */ - /* The values of the 2nd pair MUST be different. */ - /* If 3rd pair values are different ... */ - if(*p1ptr != *p2ptr){ - /* Set next first pair to last of repeated */ - /* 2nd pairs, ie. back up one pair. */ - cx--; - } - - /* Otherwise, 3rd pair can't be a 2nd pair, so */ - /* keep pointing to 3rd pair so that it is used */ - /* in the next first pair test. */ - - } /* Else, at end of current scan row. */ - } - - /* Otherwise, 2nd pair failed, so keep pointing to it */ - /* so that it is used in the next first pair test. */ - - } /* Else, at end of current scan row. */ - } - /* Otherwise, 1st pair failed... */ - else{ - /* Bump forward to next pixel pair. */ - cx++; - } - } /* While not at end of current scan row. */ - /* Bump forward to next scan row. */ - cy++; - } /* While not out of scan rows. */ - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -1497,7 +1186,7 @@ int scan4minutiae_horizontally_V2(MINUTIAE *minutiae, /************************************************************************* ************************************************************************** -#cat: scan4minutiae_vertically - Scans a specified region of binary image data +#cat: scan4minutiae_vertically - Scans a specified region of binary image data #cat: vertically, detecting potential minutiae points. #cat: Minutia detected via the vetical scan process are #cat: by nature horizontally oriented (orthogonal to the scan). @@ -1523,116 +1212,6 @@ int scan4minutiae_horizontally_V2(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -int scan4minutiae_vertically(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const int imapval, const int nmapval, - const int scan_x, const int scan_y, - const int scan_w, const int scan_h, - const LFSPARMS *lfsparms) -{ - int sx, sy, ex, ey, cx, cy, y2; - unsigned char *p1ptr, *p2ptr; - int possible[NFEATURES], nposs; - int ret; - - /* NOTE!!! Minutia that "straddle" region boundaries may be missed! */ - - /* If possible, overlap scan region to the right by 1 pixel column. */ - sx = scan_x; - ex = min(iw, scan_x+scan_w+1); - - /* If possible, overlap top and bottom of current scan region */ - /* by 2 pixel rows to help catch some minutia that straddle the */ - /* the scan region boundaries. */ - sy = max(0, scan_y-2); - ey = min(ih, scan_y+scan_h+2); - - /* For now, we will not adjust for IMAP edge, as the binary image */ - /* was properly padded at its edges so as not to cause anomalies. */ - - /* Start at first column in region. */ - cx = sx; - /* While second scan column not outside the right of the region ... */ - while(cx+1 < ex){ - /* Start at beginning of new scan column in region. */ - cy = sy; - /* While not at end of region's current scan column. */ - while(cy < ey){ - /* Get pixel pair from current y position in current and next */ - /* scan columns. */ - p1ptr = bdata+(cy*iw)+cx; - p2ptr = p1ptr+1; - /* If scan pixel pair matches first pixel pair of */ - /* 1 or more features... */ - if(match_1st_pair(*p1ptr, *p2ptr, possible, &nposs)){ - /* Bump forward to next scan pixel pair. */ - cy++; - p1ptr+=iw; - p2ptr+=iw; - /* If not at end of region's current scan column... */ - if(cy < ey){ - /* If scan pixel pair matches second pixel pair of */ - /* 1 or more features... */ - if(match_2nd_pair(*p1ptr, *p2ptr, possible, &nposs)){ - /* Store current y location. */ - y2 = cy; - /* Skip repeated pixel pairs. */ - skip_repeated_vertical_pair(&cy, ey, &p1ptr, &p2ptr, - iw, ih); - /* If not at end of region's current scan column... */ - if(cy < ey){ - /* If scan pixel pair matches third pixel pair of */ - /* a single feature... */ - if(match_3rd_pair(*p1ptr, *p2ptr, possible, &nposs)){ - /* Process detected minutia point. */ - if((ret = process_vertical_scan_minutia(minutiae, - cx, cy, y2, possible[0], - bdata, iw, ih, - imapval, nmapval, lfsparms))){ - /* Return code may be: */ - /* 1. ret< 0 (implying system error) */ - /* 2. ret==IGNORE (ignore current feature) */ - if(ret < 0) - return(ret); - /* Otherwise, IGNORE and continue. */ - } - } - - /* Set up to resume scan. */ - /* Test to see if 3rd pair can slide into 2nd pair. */ - /* The values of the 2nd pair MUST be different. */ - /* If 3rd pair values are different ... */ - if(*p1ptr != *p2ptr){ - /* Set next first pair to last of repeated */ - /* 2nd pairs, ie. back up one pair. */ - cy--; - } - - /* Otherwise, 3rd pair can't be a 2nd pair, so */ - /* keep pointing to 3rd pair so that it is used */ - /* in the next first pair test. */ - - } /* Else, at end of current scan row. */ - } - - /* Otherwise, 2nd pair failed, so keep pointing to it */ - /* so that it is used in the next first pair test. */ - - } /* Else, at end of current scan column. */ - } - /* Otherwise, 1st pair failed... */ - else{ - /* Bump forward to next pixel pair. */ - cy++; - } - } /* While not at end of current scan column. */ - /* Bump forward to next scan column. */ - cx++; - } /* While not out of scan columns. */ - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -1785,62 +1364,6 @@ int scan4minutiae_vertically_V2(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -int rescan4minutiae_horizontally(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const int *imap, const int *nmap, - const int blk_x, const int blk_y, - const int mw, const int mh, - const int scan_x, const int scan_y, - const int scan_w, const int scan_h, - const LFSPARMS *lfsparms) -{ - int blk_i, ret; - - /* Compute block index from block coordinates. */ - blk_i = (blk_y*mw)+blk_x; - - /* If high-curve block... */ - if(nmap[blk_i] == HIGH_CURVATURE){ - /* Rescan entire block in orthogonal direction. */ - if((ret = scan4minutiae_horizontally(minutiae, bdata, iw, ih, - imap[blk_i], nmap[blk_i], - scan_x, scan_y, scan_w, scan_h, lfsparms))) - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - } - /* Otherwise, block is low-curvature. */ - else{ - /* 1. Rescan horizontally to the North. */ - if((ret = rescan_partial_horizontally(NORTH, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - - /* 2. Rescan horizontally to the East. */ - if((ret = rescan_partial_horizontally(EAST, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - return(ret); - - /* 3. Rescan horizontally to the South. */ - if((ret = rescan_partial_horizontally(SOUTH, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - return(ret); - - /* 4. Rescan horizontally to the West. */ - if((ret = rescan_partial_horizontally(WEST, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - return(ret); - } /* End low-curvature rescan. */ - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -1871,62 +1394,6 @@ int rescan4minutiae_horizontally(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -int rescan4minutiae_vertically(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const int *imap, const int *nmap, - const int blk_x, const int blk_y, - const int mw, const int mh, - const int scan_x, const int scan_y, - const int scan_w, const int scan_h, - const LFSPARMS *lfsparms) -{ - int blk_i, ret; - - /* Compute block index from block coordinates. */ - blk_i = (blk_y*mw)+blk_x; - - /* If high-curve block... */ - if(nmap[blk_i] == HIGH_CURVATURE){ - /* Rescan entire block in orthogonal direction. */ - if((ret = scan4minutiae_vertically(minutiae, bdata, iw, ih, - imap[blk_i], nmap[blk_i], - scan_x, scan_y, scan_w, scan_h, lfsparms))) - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - } - /* Otherwise, block is low-curvature. */ - else{ - /* 1. Rescan vertically to the North. */ - if((ret = rescan_partial_vertically(NORTH, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - - /* 2. Rescan vertically to the East. */ - if((ret = rescan_partial_vertically(EAST, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - return(ret); - - /* 3. Rescan vertically to the South. */ - if((ret = rescan_partial_vertically(SOUTH, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - return(ret); - - /* 4. Rescan vertically to the West. */ - if((ret = rescan_partial_vertically(WEST, minutiae, bdata, iw, ih, - imap, nmap, blk_x, blk_y, mw, mh, - scan_x, scan_y, scan_w, scan_h, lfsparms))) - return(ret); - } /* End low-curvature rescan. */ - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -1957,70 +1424,6 @@ int rescan4minutiae_vertically(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -int rescan_partial_horizontally(const int nbr_dir, MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const int *imap, const int *nmap, - const int blk_x, const int blk_y, - const int mw, const int mh, - const int scan_x, const int scan_y, - const int scan_w, const int scan_h, - const LFSPARMS *lfsparms) -{ - int nblk_i, blk_i; - int rescan_dir; - int rescan_x, rescan_y, rescan_w, rescan_h; - int ret; - - /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ - ret = get_nbr_block_index(&nblk_i, nbr_dir, blk_x, blk_y, mw, mh); - /* Will return: */ - /* 1. Neighbor index found == FOUND */ - /* 2. Neighbor not found == NOT_FOUND */ - /* 3. System error < 0 */ - - /* If system error ... */ - if(ret < 0) - /* Return the error code. */ - return(ret); - - /* If neighbor not found ... */ - if(ret == NOT_FOUND) - /* Nothing to do, so return normally. */ - return(0); - - /* Otherwise, neighboring block found ... */ - - /* If neighbor block is VALID... */ - if(imap[nblk_i] != INVALID_DIR){ - - /* Compute block index from current (not neighbor) block coordinates. */ - blk_i = (blk_y*mw)+blk_x; - - /* Select feature scan direction based on neighbor IMAP. */ - rescan_dir = choose_scan_direction(imap[nblk_i], - lfsparms->num_directions); - /* If new scan direction is HORIZONTAL... */ - if(rescan_dir == SCAN_HORIZONTAL){ - /* Adjust scan_x, scan_y, scan_w, scan_h for rescan. */ - if((ret = adjust_horizontal_rescan(nbr_dir, &rescan_x, &rescan_y, - &rescan_w, &rescan_h, - scan_x, scan_y, scan_w, scan_h, lfsparms->blocksize))) - /* Return system error code. */ - return(ret); - /* Rescan specified region in block vertically. */ - /* Pass IMAP direction for the block, NOT its neighbor. */ - if((ret = scan4minutiae_horizontally(minutiae, bdata, iw, ih, - imap[blk_i], nmap[blk_i], - rescan_x, rescan_y, rescan_w, rescan_h, lfsparms))) - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - } /* Otherwise, block has already been scanned vertically. */ - } /* Otherwise, neighbor has INVALID IMAP, so ignore rescan. */ - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -2051,70 +1454,6 @@ int rescan_partial_horizontally(const int nbr_dir, MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -int rescan_partial_vertically(const int nbr_dir, MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const int *imap, const int *nmap, - const int blk_x, const int blk_y, - const int mw, const int mh, - const int scan_x, const int scan_y, - const int scan_w, const int scan_h, - const LFSPARMS *lfsparms) -{ - int nblk_i, blk_i; - int rescan_dir; - int rescan_x, rescan_y, rescan_w, rescan_h; - int ret; - - /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ - ret = get_nbr_block_index(&nblk_i, nbr_dir, blk_x, blk_y, mw, mh); - /* Will return: */ - /* 1. Neighbor index found == FOUND */ - /* 2. Neighbor not found == NOT_FOUND */ - /* 3. System error < 0 */ - - /* If system error ... */ - if(ret < 0) - /* Return the error code. */ - return(ret); - - /* If neighbor not found ... */ - if(ret == NOT_FOUND) - /* Nothing to do, so return normally. */ - return(0); - - /* Otherwise, neighboring block found ... */ - - /* If neighbor block is VALID... */ - if(imap[nblk_i] != INVALID_DIR){ - - /* Compute block index from current (not neighbor) block coordinates. */ - blk_i = (blk_y*mw)+blk_x; - - /* Select feature scan direction based on neighbor IMAP. */ - rescan_dir = choose_scan_direction(imap[nblk_i], - lfsparms->num_directions); - /* If new scan direction is VERTICAL... */ - if(rescan_dir == SCAN_VERTICAL){ - /* Adjust scan_x, scan_y, scan_w, scan_h for rescan. */ - if((ret = adjust_vertical_rescan(nbr_dir, &rescan_x, &rescan_y, - &rescan_w, &rescan_h, - scan_x, scan_y, scan_w, scan_h, lfsparms->blocksize))) - /* Return system error code. */ - return(ret); - /* Rescan specified region in block vertically. */ - /* Pass IMAP direction for the block, NOT its neighbor. */ - if((ret = scan4minutiae_vertically(minutiae, bdata, iw, ih, - imap[blk_i], nmap[blk_i], - rescan_x, rescan_y, rescan_w, rescan_h, lfsparms))) - /* Return code may be: */ - /* 1. ret<0 (implying system error) */ - return(ret); - } /* Otherwise, block has already been scanned horizontally. */ - } /* Otherwise, neighbor has INVALID IMAP, so ignore rescan. */ - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -2134,56 +1473,6 @@ int rescan_partial_vertically(const int nbr_dir, MINUTIAE *minutiae, FOUND - neighbor index exists and returned Negative - system error **************************************************************************/ -int get_nbr_block_index(int *oblk_i, const int nbr_dir, - const int blk_x, const int blk_y, const int mw, const int mh) -{ - int nx, ny, ni; - - switch(nbr_dir){ - case NORTH: - /* If neighbor doesn't exist above... */ - if((ny = blk_y-1) < 0) - /* Done, so return normally. */ - return(NOT_FOUND); - /* Get neighbor's block index. */ - ni = (ny*mw)+blk_x; - break; - case EAST: - /* If neighbor doesn't exist to the right... */ - if((nx = blk_x+1) >= mw) - /* Done, so return normally. */ - return(NOT_FOUND); - /* Get neighbor's block index. */ - ni = (blk_y*mw)+nx; - break; - case SOUTH: - /* If neighbor doesn't exist below... */ - if((ny = blk_y+1) >= mh) - /* Return normally. */ - return(NOT_FOUND); - /* Get neighbor's block index. */ - ni = (ny*mw)+blk_x; - break; - case WEST: - /* If neighbor doesn't exist to the left... */ - if((nx = blk_x-1) < 0) - /* Return normally. */ - return(NOT_FOUND); - /* Get neighbor's block index. */ - ni = (blk_y*mw)+nx; - break; - default: - fprintf(stderr, - "ERROR : get_nbr_block_index : illegal neighbor direction\n"); - return(-200); - } - - /* Assign output pointer. */ - *oblk_i = ni; - - /* Return neighbor FOUND. */ - return(FOUND); -} /************************************************************************* ************************************************************************** @@ -2206,126 +1495,6 @@ int get_nbr_block_index(int *oblk_i, const int nbr_dir, Zero - successful completion Negative - system error **************************************************************************/ -int adjust_horizontal_rescan(const int nbr_dir, int *rescan_x, int *rescan_y, - int *rescan_w, int *rescan_h, const int scan_x, const int scan_y, - const int scan_w, const int scan_h, const int blocksize) -{ - int half_blocksize, qtr_blocksize; - - /* Compute half of blocksize. */ - half_blocksize = blocksize>>1; - /* Compute quarter of blocksize. */ - qtr_blocksize = blocksize>>2; - - /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ - switch(nbr_dir){ - case NORTH: - /* - ************************* - * RESCAN NORTH * - * AREA * - ************************* - | | - | | - | | - | | - | | - | | - ------------------------- - */ - /* Rescan origin stays the same. */ - *rescan_x = scan_x; - *rescan_y = scan_y; - /* Rescan width stays the same. */ - *rescan_w = scan_w; - /* Rescan height is reduced to "qtr_blocksize" */ - /* if scan_h is larger. */ - *rescan_h = min(qtr_blocksize, scan_h); - break; - case EAST: - /* - ------------************* - | * * - | * * - | * E R * - | * A E * - | * S S * - | * T C * - | * A * - | * N * - | * * - | * * - ------------************* - */ - /* Rescan x-orign is set to half_blocksize from right edge of */ - /* block if scan width is larger. */ - *rescan_x = max(scan_x+scan_w-half_blocksize, scan_x); - /* Rescan y-origin stays the same. */ - *rescan_y = scan_y; - /* Rescan width is reduced to "half_blocksize" */ - /* if scan width is larger. */ - *rescan_w = min(half_blocksize, scan_w); - /* Rescan height stays the same. */ - *rescan_h = scan_h; - break; - case SOUTH: - /* - ------------------------- - | | - | | - | | - | | - | | - | | - ************************* - * RESCAN SOUTH * - * AREA * - ************************* - */ - /* Rescan x-origin stays the same. */ - *rescan_x = scan_x; - /* Rescan y-orign is set to qtr_blocksize from bottom edge of */ - /* block if scan height is larger. */ - *rescan_y = max(scan_y+scan_h-qtr_blocksize, scan_y); - /* Rescan width stays the same. */ - *rescan_w = scan_w; - /* Rescan height is reduced to "qtr_blocksize" */ - /* if scan height is larger. */ - *rescan_h = min(qtr_blocksize, scan_h); - break; - case WEST: - /* - *************------------ - * * | - * * | - * W R * | - * E E * | - * S S * | - * T C * | - * A * | - * N * | - * * | - * * | - *************------------ - */ - /* Rescan origin stays the same. */ - *rescan_x = scan_x; - *rescan_y = scan_y; - /* Rescan width is reduced to "half_blocksize" */ - /* if scan width is larger. */ - *rescan_w = min(half_blocksize, scan_w); - /* Rescan height stays the same. */ - *rescan_h = scan_h; - break; - default: - fprintf(stderr, - "ERROR : adjust_horizontal_rescan : illegal neighbor direction\n"); - return(-210); - } - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -2348,128 +1517,6 @@ int adjust_horizontal_rescan(const int nbr_dir, int *rescan_x, int *rescan_y, Zero - successful completion Negative - system error **************************************************************************/ -int adjust_vertical_rescan(const int nbr_dir, int *rescan_x, int *rescan_y, - int *rescan_w, int *rescan_h, const int scan_x, const int scan_y, - const int scan_w, const int scan_h, const int blocksize) -{ - int half_blocksize, qtr_blocksize; - - /* Compute half of blocksize. */ - half_blocksize = blocksize>>1; - /* Compute quarter of blocksize. */ - qtr_blocksize = blocksize>>2; - - /* Neighbor will either be NORTH, SOUTH, EAST, OR WEST. */ - switch(nbr_dir){ - case NORTH: - /* - ************************* - * * - * RESCAN NORTH * - * AREA * - * * - ************************* - | | - | | - | | - | | - | | - ------------------------- - */ - /* Rescan origin stays the same. */ - *rescan_x = scan_x; - *rescan_y = scan_y; - /* Rescan width stays the same. */ - *rescan_w = scan_w; - /* Rescan height is reduced to "half_blocksize" */ - /* if scan_h is larger. */ - *rescan_h = min(half_blocksize, scan_h); - break; - case EAST: - /* - ------------------******* - | * * - | * * - | * E R * - | * A E * - | * S S * - | * T C * - | * A * - | * N * - | * * - | * * - ------------------******* - */ - /* Rescan x-orign is set to qtr_blocksize from right edge of */ - /* block if scan width is larger. */ - *rescan_x = max(scan_x+scan_w-qtr_blocksize, scan_x); - /* Rescan y-origin stays the same. */ - *rescan_y = scan_y; - /* Rescan width is reduced to "qtr_blocksize" */ - /* if scan width is larger. */ - *rescan_w = min(qtr_blocksize, scan_w); - /* Rescan height stays the same. */ - *rescan_h = scan_h; - break; - case SOUTH: - /* - ------------------------- - | | - | | - | | - | | - | | - ************************* - * * - * RESCAN SOUTH * - * AREA * - * * - ************************* - */ - /* Rescan x-origin stays the same. */ - *rescan_x = scan_x; - /* Rescan y-orign is set to half_blocksize from bottom edge of */ - /* block if scan height is larger. */ - *rescan_y = max(scan_y+scan_h-half_blocksize, scan_y); - /* Rescan width stays the same. */ - *rescan_w = scan_w; - /* Rescan height is reduced to "half_blocksize" */ - /* if scan height is larger. */ - *rescan_h = min(half_blocksize, scan_h); - break; - case WEST: - /* - *******------------------ - * * | - * * | - * W R * | - * E E * | - * S S * | - * T C * | - * A * | - * N * | - * * | - * * | - *******------------------ - */ - /* Rescan origin stays the same. */ - *rescan_x = scan_x; - *rescan_y = scan_y; - /* Rescan width is reduced to "qtr_blocksize" */ - /* if scan width is larger. */ - *rescan_w = min(qtr_blocksize, scan_w); - /* Rescan height stays the same. */ - *rescan_h = scan_h; - break; - default: - fprintf(stderr, - "ERROR : adjust_vertical_rescan : illegal neighbor direction\n"); - return(-220); - } - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -2484,7 +1531,7 @@ int adjust_vertical_rescan(const int nbr_dir, int *rescan_x, int *rescan_y, cx - x-pixel coord where 3rd pattern pair of mintuia was detected cy - y-pixel coord where 3rd pattern pair of mintuia was detected y2 - y-pixel coord where 2nd pattern pair of mintuia was detected - feature_id - type of minutia (ex. index into feature_patterns[] list) + feature_id - type of minutia (ex. index into g_feature_patterns[] list) bdata - binary image data (0==while & 1==black) iw - width (in pixels) of image ih - height (in pixels) of image @@ -2498,81 +1545,6 @@ int adjust_vertical_rescan(const int nbr_dir, int *rescan_x, int *rescan_y, IGNORE - minutia is to be ignored Negative - system error **************************************************************************/ -int process_horizontal_scan_minutia(MINUTIAE *minutiae, - const int cx, const int cy, - const int x2, const int feature_id, - unsigned char *bdata, const int iw, const int ih, - const int imapval, const int nmapval, - const LFSPARMS *lfsparms) -{ - MINUTIA *minutia; - int x_loc, y_loc; - int x_edge, y_edge; - int idir, ret; - - /* Set x location of minutia point to be half way between */ - /* first position of second feature pair and position of */ - /* third feature pair. */ - x_loc = (cx + x2)>>1; - - /* Set same x location to neighboring edge pixel. */ - x_edge = x_loc; - - /* Feature location should always point to either ending */ - /* of ridge or (for bifurcations) ending of valley. */ - /* So, if detected feature is APPEARING... */ - if(g_feature_patterns[feature_id].appearing){ - /* Set y location to second scan row. */ - y_loc = cy+1; - /* Set y location of neighboring edge pixel to the first scan row. */ - y_edge = cy; - } - /* Otherwise, feature is DISAPPEARING... */ - else{ - /* Set y location to first scan row. */ - y_loc = cy; - /* Set y location of neighboring edge pixel to the second scan row. */ - y_edge = cy+1; - } - - /* If current minutia is in a high-curvature block... */ - if(nmapval == HIGH_CURVATURE){ - /* Adjust location and direction locally. */ - if((ret = adjust_high_curvature_minutia(&idir, &x_loc, &y_loc, - &x_edge, &y_edge, x_loc, y_loc, x_edge, y_edge, - bdata, iw, ih, minutiae, lfsparms))){ - /* Could be a system error or IGNORE minutia. */ - return(ret); - } - /* Otherwise, we have our high-curvature minutia attributes. */ - } - /* Otherwise, minutia is in fairly low-curvature block... */ - else{ - /* Get minutia direction based on current IMAP value. */ - idir = get_low_curvature_direction(SCAN_HORIZONTAL, - g_feature_patterns[feature_id].appearing, - imapval, lfsparms->num_directions); - } - - /* Create a minutia object based on derived attributes. */ - if((ret = create_minutia(&minutia, x_loc, y_loc, x_edge, y_edge, idir, - DEFAULT_RELIABILITY, - g_feature_patterns[feature_id].type, - g_feature_patterns[feature_id].appearing, feature_id))) - /* Return system error. */ - return(ret); - - /* Update the minutiae list with potential new minutia. */ - ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); - - /* If minuitia IGNORED and not added to the minutia list ... */ - if(ret == IGNORE) - /* Deallocate the minutia. */ - free_minutia(minutia); - - /* Otherwise, return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -2587,7 +1559,7 @@ int process_horizontal_scan_minutia(MINUTIAE *minutiae, cx - x-pixel coord where 3rd pattern pair of mintuia was detected cy - y-pixel coord where 3rd pattern pair of mintuia was detected y2 - y-pixel coord where 2nd pattern pair of mintuia was detected - feature_id - type of minutia (ex. index into feature_patterns[] list) + feature_id - type of minutia (ex. index into g_feature_patterns[] list) bdata - binary image data (0==while & 1==black) iw - width (in pixels) of image ih - height (in pixels) of image @@ -2626,7 +1598,7 @@ int process_horizontal_scan_minutia_V2(MINUTIAE *minutiae, /* Feature location should always point to either ending */ /* of ridge or (for bifurcations) ending of valley. */ - /* So, if detected feature is APPEARING... */ + /* So, if detected feature is APPEARING... */ if(g_feature_patterns[feature_id].appearing){ /* Set y location to second scan row. */ y_loc = cy+1; @@ -2711,7 +1683,7 @@ int process_horizontal_scan_minutia_V2(MINUTIAE *minutiae, cx - x-pixel coord where 3rd pattern pair of mintuia was detected cy - y-pixel coord where 3rd pattern pair of mintuia was detected x2 - x-pixel coord where 2nd pattern pair of mintuia was detected - feature_id - type of minutia (ex. index into feature_patterns[] list) + feature_id - type of minutia (ex. index into g_feature_patterns[] list) bdata - binary image data (0==while & 1==black) iw - width (in pixels) of image ih - height (in pixels) of image @@ -2725,80 +1697,6 @@ int process_horizontal_scan_minutia_V2(MINUTIAE *minutiae, IGNORE - minutia is to be ignored Negative - system error **************************************************************************/ -int process_vertical_scan_minutia(MINUTIAE *minutiae, - const int cx, const int cy, - const int y2, const int feature_id, - unsigned char *bdata, const int iw, const int ih, - const int imapval, const int nmapval, - const LFSPARMS *lfsparms) -{ - MINUTIA *minutia; - int x_loc, y_loc; - int x_edge, y_edge; - int idir, ret; - - /* Feature location should always point to either ending */ - /* of ridge or (for bifurcations) ending of valley. */ - /* So, if detected feature is APPEARING... */ - if(g_feature_patterns[feature_id].appearing){ - /* Set x location to second scan column. */ - x_loc = cx+1; - /* Set x location of neighboring edge pixel to the first scan column. */ - x_edge = cx; - } - /* Otherwise, feature is DISAPPEARING... */ - else{ - /* Set x location to first scan column. */ - x_loc = cx; - /* Set x location of neighboring edge pixel to the second scan column. */ - x_edge = cx+1; - } - - /* Set y location of minutia point to be half way between */ - /* first position of second feature pair and position of */ - /* third feature pair. */ - y_loc = (cy + y2)>>1; - /* Set same y location to neighboring edge pixel. */ - y_edge = y_loc; - - /* If current minutia is in a high-curvature block... */ - if(nmapval == HIGH_CURVATURE){ - /* Adjust location and direction locally. */ - if((ret = adjust_high_curvature_minutia(&idir, &x_loc, &y_loc, - &x_edge, &y_edge, x_loc, y_loc, x_edge, y_edge, - bdata, iw, ih, minutiae, lfsparms))){ - /* Could be a system error or IGNORE minutia. */ - return(ret); - } - /* Otherwise, we have our high-curvature minutia attributes. */ - } - /* Otherwise, minutia is in fairly low-curvature block... */ - else{ - /* Get minutia direction based on current IMAP value. */ - idir = get_low_curvature_direction(SCAN_VERTICAL, - g_feature_patterns[feature_id].appearing, - imapval, lfsparms->num_directions); - } - - /* Create a minutia object based on derived attributes. */ - if((ret = create_minutia(&minutia, x_loc, y_loc, x_edge, y_edge, idir, - DEFAULT_RELIABILITY, - g_feature_patterns[feature_id].type, - g_feature_patterns[feature_id].appearing, feature_id))) - /* Return system error. */ - return(ret); - - /* Update the minutiae list with potential new minutia. */ - ret = update_minutiae(minutiae, minutia, bdata, iw, ih, lfsparms); - - /* If minuitia IGNORED and not added to the minutia list ... */ - if(ret == IGNORE) - /* Deallocate the minutia. */ - free_minutia(minutia); - - /* Otherwise, return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -2813,7 +1711,7 @@ int process_vertical_scan_minutia(MINUTIAE *minutiae, cx - x-pixel coord where 3rd pattern pair of mintuia was detected cy - y-pixel coord where 3rd pattern pair of mintuia was detected x2 - x-pixel coord where 2nd pattern pair of mintuia was detected - feature_id - type of minutia (ex. index into feature_patterns[] list) + feature_id - type of minutia (ex. index into g_feature_patterns[] list) bdata - binary image data (0==while & 1==black) iw - width (in pixels) of image ih - height (in pixels) of image @@ -2844,7 +1742,7 @@ int process_vertical_scan_minutia_V2(MINUTIAE *minutiae, /* Feature location should always point to either ending */ /* of ridge or (for bifurcations) ending of valley. */ - /* So, if detected feature is APPEARING... */ + /* So, if detected feature is APPEARING... */ if(g_feature_patterns[feature_id].appearing){ /* Set x location to second scan column. */ x_loc = cx+1; @@ -2884,7 +1782,7 @@ int process_vertical_scan_minutia_V2(MINUTIAE *minutiae, /* Could be a system error or IGNORE minutia. */ return(ret); } - /* Otherwise, we have our high-curvature minutia attributes. */ + /* Otherwise, we have our high-curvature minutia attributes. */ } /* Otherwise, minutia is in fairly low-curvature block... */ else{ @@ -2959,167 +1857,6 @@ int process_vertical_scan_minutia_V2(MINUTIAE *minutiae, IGNORE - minutia point is to be ignored Negative - system error **************************************************************************/ -int adjust_high_curvature_minutia(int *oidir, int *ox_loc, int *oy_loc, - int *ox_edge, int *oy_edge, - const int x_loc, const int y_loc, - const int x_edge, const int y_edge, - unsigned char *bdata, const int iw, const int ih, - MINUTIAE *minutiae, const LFSPARMS *lfsparms) -{ - int ret; - int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour; - int min_i; - double min_theta; - int feature_pix; - int mid_x, mid_y, mid_pix; - int idir; - int half_contour, angle_edge; - - /* Set variable from parameter structure. */ - half_contour = lfsparms->high_curve_half_contour; - - /* Set edge length for computing contour's angle of curvature */ - /* to one quarter of desired pixel length of entire contour. */ - /* Ex. If half_contour==14, then contour length==29=(2X14)+1 */ - /* and angle_edge==7=(14/2). */ - angle_edge = half_contour>>1; - - /* Get the pixel value of current feature. */ - feature_pix = *(bdata + (y_loc * iw) + x_loc); - - /* Extract feature's contour. */ - if((ret = get_high_curvature_contour(&contour_x, &contour_y, - &contour_ex, &contour_ey, &ncontour, half_contour, - x_loc, y_loc, x_edge, y_edge, bdata, iw, ih))){ - /* Returns with: */ - /* 1. Successful or empty contour == 0 */ - /* If contour is empty, then contour lists are not allocated. */ - /* 2. Contour forms loop == LOOP_FOUND */ - /* 3. Sysetm error < 0 */ - - /* If the contour forms a loop... */ - if(ret == LOOP_FOUND){ - - /* If the order of the contour is clockwise, then the loops's */ - /* contour pixels are outside the corresponding edge pixels. We */ - /* definitely do NOT want to fill based on the feature pixel in */ - /* this case, because it is OUTSIDE the loop. For now we will */ - /* ignore the loop and the minutia that triggered its tracing. */ - /* It is likely that other minutia on the loop will be */ - /* detected that create a contour on the "inside" of the loop. */ - /* There is another issue here that could be addressed ... */ - /* It seems that many/multiple minutia are often detected within */ - /* the same loop, which currently requires retracing the loop, */ - /* locating minutia on opposite ends of the major axis of the */ - /* loop, and then determining that the minutia have already been */ - /* entered into the minutiae list upon processing the very first */ - /* minutia detected in the loop. There is a lot of redundant */ - /* work being done here! */ - /* Is_loop_clockwise takes a default value to be returned if the */ - /* routine is unable to determine the direction of the contour. */ - /* In this case, we want to IGNORE the loop if we can't tell its */ - /* direction so that we do not inappropriately fill the loop, so */ - /* we are passing the default value TRUE. */ - if((ret = is_loop_clockwise(contour_x, contour_y, ncontour, TRUE))){ - /* Deallocate contour lists. */ - free_contour(contour_x, contour_y, contour_ex, contour_ey); - /* If we had a system error... */ - if(ret < 0) - /* Return the error code. */ - return(ret); - /* Otherwise, loop is clockwise, so return IGNORE. */ - return(IGNORE); - } - - /* Otherwise, process the clockwise-ordered contour of the loop */ - /* as it may contain minutia. If no minutia found, then it is */ - /* filled in. */ - ret = process_loop(minutiae, contour_x, contour_y, - contour_ex, contour_ey, ncontour, - bdata, iw, ih, lfsparms); - /* Returns with: */ - /* 1. Successful processing of loop == 0 */ - /* 2. System error < 0 */ - - /* Deallocate contour lists. */ - free_contour(contour_x, contour_y, contour_ex, contour_ey); - - /* If loop processed successfully ... */ - if(ret == 0) - /* Then either a minutia pair was extracted or the loop was */ - /* filled. Either way we want to IGNORE the minutia that */ - /* started the whole loop processing in the beginning. */ - return(IGNORE); - - /* Otherwise, there was a system error. */ - /* Return the resulting code. */ - return(ret); - } - - /* Otherwise not a loop, so get_high_curvature_contour incurred */ - /* a system error. Return the error code. */ - return(ret); - } - - /* If contour is empty ... then contour lists were not allocated, so */ - /* simply return IGNORE. The contour comes back empty when there */ - /* were not a sufficient number of points found on the contour. */ - if(ncontour == 0) - return(IGNORE); - - /* Otherwise, there are contour points to process. */ - - /* Given the contour, determine the point of highest curvature */ - /* (ie. forming the minimum angle between contour walls). */ - if((ret = min_contour_theta(&min_i, &min_theta, angle_edge, - contour_x, contour_y, ncontour))){ - /* Deallocate contour lists. */ - free_contour(contour_x, contour_y, contour_ex, contour_ey); - /* Returns IGNORE or system error. Either way */ - /* free the contour and return the code. */ - return(ret); - } - - /* If the minimum theta found along the contour is too large... */ - if(min_theta >= lfsparms->max_high_curve_theta){ - /* Deallocate contour lists. */ - free_contour(contour_x, contour_y, contour_ex, contour_ey); - /* Reject the high-curvature minutia, and return IGNORE. */ - return(IGNORE); - } - - /* Test to see if interior of curvature is OK. Compute midpoint */ - /* between left and right points symmetrically distant (angle_edge */ - /* pixels) from the contour's point of minimum theta. */ - mid_x = (contour_x[min_i-angle_edge] + contour_x[min_i+angle_edge])>>1; - mid_y = (contour_y[min_i-angle_edge] + contour_y[min_i+angle_edge])>>1; - mid_pix = *(bdata + (mid_y * iw) + mid_x); - /* If the interior pixel value is not the same as the feature's... */ - if(mid_pix != feature_pix){ - /* Deallocate contour lists. */ - free_contour(contour_x, contour_y, contour_ex, contour_ey); - /* Reject the high-curvature minutia and return IGNORE. */ - return(IGNORE); - } - - /* Compute new direction based on line connecting adjusted feature */ - /* location and the midpoint in the feature's interior. */ - idir = line2direction(contour_x[min_i], contour_y[min_i], - mid_x, mid_y, lfsparms->num_directions); - - /* Set minutia location to minimum theta position on the contour. */ - *oidir = idir; - *ox_loc = contour_x[min_i]; - *oy_loc = contour_y[min_i]; - *ox_edge = contour_ex[min_i]; - *oy_edge = contour_ey[min_i]; - - /* Deallocate contour buffers. */ - free_contour(contour_x, contour_y, contour_ex, contour_ey); - - /*Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -3464,48 +2201,3 @@ int get_low_curvature_direction(const int scan_dir, const int appearing, return(idir); } -/************************************************************************* -************************************************************************** -#cat: lfs2nist_minutia_XYT - Converts XYT minutiae attributes in LFS native -#cat: representation to NIST internal representation - - Input: - minutia - LFS minutia structure containing attributes to be converted - Output: - ox - NIST internal based x-pixel coordinate - oy - NIST internal based y-pixel coordinate - ot - NIST internal based minutia direction/orientation - Return Code: - Zero - successful completion - Negative - system error -**************************************************************************/ -void lfs2nist_minutia_XYT(int *ox, int *oy, int *ot, - const MINUTIA *minutia, const int iw, const int ih) -{ - int x, y, t; - float degrees_per_unit; - - /* XYT's according to NIST internal rep: */ - /* 1. pixel coordinates with origin bottom-left */ - /* 2. orientation in degrees on range [0..360] */ - /* with 0 pointing east and increasing counter */ - /* clockwise (same as M1) */ - /* 3. direction pointing out and away from the */ - /* ridge ending or bifurcation valley */ - /* (opposite direction from M1) */ - - x = minutia->x; - y = ih - minutia->y; - - degrees_per_unit = 180 / (float)NUM_DIRECTIONS; - - t = (270 - sround(minutia->direction * degrees_per_unit)) % 360; - if(t < 0){ - t += 360; - } - - *ox = x; - *oy = y; - *ot = t; -} - diff --git a/libfprint/nbis/mindtct/morph.c b/libfprint/nbis/mindtct/morph.c index d4ec85f3..41978f1e 100644 --- a/libfprint/nbis/mindtct/morph.c +++ b/libfprint/nbis/mindtct/morph.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -69,13 +90,13 @@ void erode_charimage_2(unsigned char *inp, unsigned char *out, { int row, col; unsigned char *itr = inp, *otr = out; - + memcpy(out, inp, iw*ih); - + /* for true pixels. kill pixel if there is at least one false neighbor */ for ( row = 0 ; row < ih ; row++ ) for ( col = 0 ; col < iw ; col++ ) - { + { if (*itr) /* erode only operates on true pixels */ { /* more efficient with C's left to right evaluation of */ @@ -87,7 +108,7 @@ void erode_charimage_2(unsigned char *inp, unsigned char *out, *otr = 0; } itr++ ; otr++; - } + } } /************************************************************************* @@ -109,13 +130,13 @@ void dilate_charimage_2(unsigned char *inp, unsigned char *out, { int row, col; unsigned char *itr = inp, *otr = out; - + memcpy(out, inp, iw*ih); - + /* for all pixels. set pixel if there is at least one true neighbor */ for ( row = 0 ; row < ih ; row++ ) for ( col = 0 ; col < iw ; col++ ) - { + { if (!*itr) /* pixel is already true, neighbors irrelevant */ { /* more efficient with C's left to right evaluation of */ @@ -127,7 +148,7 @@ void dilate_charimage_2(unsigned char *inp, unsigned char *out, *otr = 1; } itr++ ; otr++; - } + } } /************************************************************************* @@ -151,7 +172,7 @@ char get_south8_2(char *ptr, const int row, const int iw, const int ih, { if (row >= ih-1) /* catch case where image is undefined southwards */ return failcode; /* use plane geometry and return code. */ - else + return *(ptr+iw); } @@ -175,7 +196,7 @@ char get_north8_2(char *ptr, const int row, const int iw, { if (row < 1) /* catch case where image is undefined northwards */ return failcode; /* use plane geometry and return code. */ - else + return *(ptr-iw); } @@ -199,7 +220,7 @@ char get_east8_2(char *ptr, const int col, const int iw, { if (col >= iw-1) /* catch case where image is undefined eastwards */ return failcode; /* use plane geometry and return code. */ - else + return *(ptr+ 1); } @@ -221,6 +242,6 @@ char get_west8_2(char *ptr, const int col, const int failcode) { if (col < 1) /* catch case where image is undefined westwards */ return failcode; /* use plane geometry and return code. */ - else + return *(ptr- 1); } diff --git a/libfprint/nbis/mindtct/quality.c b/libfprint/nbis/mindtct/quality.c index 5dcabc2a..db2bc5c2 100644 --- a/libfprint/nbis/mindtct/quality.c +++ b/libfprint/nbis/mindtct/quality.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -39,12 +60,11 @@ identified are necessarily the best available for the purpose. combined_minutia_quality() grayscale_reliability() get_neighborhood_stats() + reliability_fr_quality_map() ***********************************************************************/ #include -#include -#include #include #include @@ -172,120 +192,6 @@ int gen_quality_map(int **oqmap, int *direction_map, int *low_contrast_map, return(0); } -/*********************************************************************** -************************************************************************ -#cat: get_neighborhood_stats - Given a minutia point, computes the mean -#cat: and stdev of the 8-bit grayscale pixels values in a -#cat: surrounding neighborhood with specified radius. - - Code originally written by Austin Hicklin for FBI ATU - Modified by Michael D. Garris (NIST) Sept. 25, 2000 - - Input: - minutia - structure containing detected minutia - idata - 8-bit grayscale fingerprint image - iw - width (in pixels) of the image - ih - height (in pixels) of the image - radius_pix - pixel radius of surrounding neighborhood - Output: - mean - mean of neighboring pixels - stdev - standard deviation of neighboring pixels -************************************************************************/ -static void get_neighborhood_stats(double *mean, double *stdev, MINUTIA *minutia, - unsigned char *idata, const int iw, const int ih, - const int radius_pix) -{ - int i, x, y, rows, cols; - int n = 0, sumX = 0, sumXX = 0; - int histogram[256]; - - /* Zero out histogram. */ - memset(histogram, 0, 256 * sizeof(int)); - - /* Set minutia's coordinate variables. */ - x = minutia->x; - y = minutia->y; - - - /* If minutiae point is within sampleboxsize distance of image border, */ - /* a value of 0 reliability is returned. */ - if ((x < radius_pix) || (x > iw-radius_pix-1) || - (y < radius_pix) || (y > ih-radius_pix-1)) { - *mean = 0.0; - *stdev = 0.0; - return; - - } - - /* Foreach row in neighborhood ... */ - for(rows = y - radius_pix; - rows <= y + radius_pix; - rows++){ - /* Foreach column in neighborhood ... */ - for(cols = x - radius_pix; - cols <= x + radius_pix; - cols++){ - /* Bump neighbor's pixel value bin in histogram. */ - histogram[*(idata+(rows * iw)+cols)]++; - } - } - - /* Foreach grayscale pixel bin ... */ - for(i = 0; i < 256; i++){ - if(histogram[i]){ - /* Accumulate Sum(X[i]) */ - sumX += (i * histogram[i]); - /* Accumulate Sum(X[i]^2) */ - sumXX += (i * i * histogram[i]); - /* Accumulate N samples */ - n += histogram[i]; - } - } - - /* Mean = Sum(X[i])/N */ - *mean = sumX/(double)n; - /* Stdev = sqrt((Sum(X[i]^2)/N) - Mean^2) */ - *stdev = sqrt((sumXX/(double)n) - ((*mean)*(*mean))); -} - -/*********************************************************************** -************************************************************************ -#cat: grayscale_reliability - Given a minutia point, computes a reliability -#cat: measure from the stdev and mean of its pixel neighborhood. - - Code originally written by Austin Hicklin for FBI ATU - Modified by Michael D. Garris (NIST) Sept. 25, 2000 - - GrayScaleReliability - reasonable reliability heuristic, returns - 0.0 .. 1.0 based on stdev and Mean of a localized histogram where - "ideal" stdev is >=64; "ideal" Mean is 127. In a 1 ridge radius - (11 pixels), if the bytevalue (shade of gray) in the image has a - stdev of >= 64 & a mean of 127, returns 1.0 (well defined - light & dark areas in equal proportions). - - Input: - minutia - structure containing detected minutia - idata - 8-bit grayscale fingerprint image - iw - width (in pixels) of the image - ih - height (in pixels) of the image - radius_pix - pixel radius of surrounding neighborhood - Return Value: - reliability - computed reliability measure -************************************************************************/ -static double grayscale_reliability(MINUTIA *minutia, unsigned char *idata, - const int iw, const int ih, const int radius_pix) -{ - double mean, stdev; - double reliability; - - get_neighborhood_stats(&mean, &stdev, minutia, idata, iw, ih, radius_pix); - - reliability = min((stdev>IDEALSTDEV ? 1.0 : stdev/(double)IDEALSTDEV), - (1.0-(fabs(mean-IDEALMEAN)/(double)IDEALMEAN))); - - return(reliability); -} - /*********************************************************************** ************************************************************************ #cat: combined_minutia_quality - Combines quality measures derived from @@ -391,3 +297,137 @@ int combined_minutia_quality(MINUTIAE *minutiae, return(0); } + +/*********************************************************************** +************************************************************************ +#cat: grayscale_reliability - Given a minutia point, computes a reliability +#cat: measure from the stdev and mean of its pixel neighborhood. + + Code originally written by Austin Hicklin for FBI ATU + Modified by Michael D. Garris (NIST) Sept. 25, 2000 + + GrayScaleReliability - reasonable reliability heuristic, returns + 0.0 .. 1.0 based on stdev and Mean of a localized histogram where + "ideal" stdev is >=64; "ideal" Mean is 127. In a 1 ridge radius + (11 pixels), if the bytevalue (shade of gray) in the image has a + stdev of >= 64 & a mean of 127, returns 1.0 (well defined + light & dark areas in equal proportions). + + Input: + minutia - structure containing detected minutia + idata - 8-bit grayscale fingerprint image + iw - width (in pixels) of the image + ih - height (in pixels) of the image + radius_pix - pixel radius of surrounding neighborhood + Return Value: + reliability - computed reliability measure +************************************************************************/ +double grayscale_reliability(MINUTIA *minutia, unsigned char *idata, + const int iw, const int ih, const int radius_pix) +{ + double mean, stdev; + double reliability; + + get_neighborhood_stats(&mean, &stdev, minutia, idata, iw, ih, radius_pix); + + reliability = min((stdev>IDEALSTDEV ? 1.0 : stdev/(double)IDEALSTDEV), + (1.0-(fabs(mean-IDEALMEAN)/(double)IDEALMEAN))); + + return(reliability); +} + + +/*********************************************************************** +************************************************************************ +#cat: get_neighborhood_stats - Given a minutia point, computes the mean +#cat: and stdev of the 8-bit grayscale pixels values in a +#cat: surrounding neighborhood with specified radius. + + Code originally written by Austin Hicklin for FBI ATU + Modified by Michael D. Garris (NIST) Sept. 25, 2000 + + Input: + minutia - structure containing detected minutia + idata - 8-bit grayscale fingerprint image + iw - width (in pixels) of the image + ih - height (in pixels) of the image + radius_pix - pixel radius of surrounding neighborhood + Output: + mean - mean of neighboring pixels + stdev - standard deviation of neighboring pixels +************************************************************************/ +void get_neighborhood_stats(double *mean, double *stdev, MINUTIA *minutia, + unsigned char *idata, const int iw, const int ih, + const int radius_pix) +{ + int i, x, y, rows, cols; + int n = 0, sumX = 0, sumXX = 0; + int histogram[256]; + + /* Zero out histogram. */ + memset(histogram, 0, 256 * sizeof(int)); + + /* Set minutia's coordinate variables. */ + x = minutia->x; + y = minutia->y; + + + /* If minutiae point is within sampleboxsize distance of image border, */ + /* a value of 0 reliability is returned. */ + if ((x < radius_pix) || (x > iw-radius_pix-1) || + (y < radius_pix) || (y > ih-radius_pix-1)) { + *mean = 0.0; + *stdev = 0.0; + return; + + } + + /* Foreach row in neighborhood ... */ + for(rows = y - radius_pix; + rows <= y + radius_pix; + rows++){ + /* Foreach column in neighborhood ... */ + for(cols = x - radius_pix; + cols <= x + radius_pix; + cols++){ + /* Bump neighbor's pixel value bin in histogram. */ + histogram[*(idata+(rows * iw)+cols)]++; + } + } + + /* Foreach grayscale pixel bin ... */ + for(i = 0; i < 256; i++){ + if(histogram[i]){ + /* Accumulate Sum(X[i]) */ + sumX += (i * histogram[i]); + /* Accumulate Sum(X[i]^2) */ + sumXX += (i * i * histogram[i]); + /* Accumulate N samples */ + n += histogram[i]; + } + } + + /* Mean = Sum(X[i])/N */ + *mean = sumX/(double)n; + /* Stdev = sqrt((Sum(X[i]^2)/N) - Mean^2) */ + *stdev = sqrt((sumXX/(double)n) - ((*mean)*(*mean))); +} + +/*********************************************************************** +************************************************************************ +#cat: reliability_fr_quality_map - Takes a set of minutiae and assigns +#cat: each one a reliability measure based on 1 of 5 possible +#cat: quality levels from its location in a quality map. + + Input: + minutiae - structure contining the detected minutia + quality_map - map with blocks assigned 1 of 5 quality levels + map_w - width (in blocks) of the map + map_h - height (in blocks) of the map + blocksize - size (in pixels) of each block in the map + Output: + minutiae - updated reliability members + Return Code: + Zero - successful completion + Negative - system error +************************************************************************/ diff --git a/libfprint/nbis/mindtct/remove.c b/libfprint/nbis/mindtct/remove.c index 6863ecf3..faa6607e 100644 --- a/libfprint/nbis/mindtct/remove.c +++ b/libfprint/nbis/mindtct/remove.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -35,15 +56,21 @@ identified are necessarily the best available for the purpose. *********************************************************************** ROUTINES: + remove_false_minutia() remove_false_minutia_V2() remove_holes() remove_hooks() + remove_hooks_islands_overlaps() remove_islands_and_lakes() remove_malformations() - remove_near_invblock_V2() + remove_near_invblocks() + remove_near_invblocks_V2() + remove_pointing_invblock() remove_pointing_invblock_V2() remove_overlaps() + remove_pores() remove_pores_V2() + remove_or_adjust_side_minutiae() remove_or_adjust_side_minutiae_V2() ***********************************************************************/ @@ -52,6 +79,125 @@ identified are necessarily the best available for the purpose. #include #include +/************************************************************************* +************************************************************************** +#cat: remove_false_minutia - Takes a list of true and false minutiae and +#cat: attempts to detect and remove the false minutiae based +#cat: on a series of tests. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + nmap - IMAP ridge flow matrix with invalid, high-curvature, + and no-valid-neighbor regions identified + mw - width in blocks of the NMAP + mh - height in blocks of the NMAP + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: remove_false_minutia_V2 - Takes a list of true and false minutiae and +#cat: attempts to detect and remove the false minutiae based +#cat: on a series of tests. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + direction_map - map of image blocks containing directional ridge flow + low_flow_map - map of image blocks flagged as LOW RIDGE FLOW + high_curve_map - map of image blocks flagged as HIGH CURVATURE + mw - width in blocks of the maps + mh - height in blocks of the maps + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int remove_false_minutia_V2(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + int *direction_map, int *low_flow_map, int *high_curve_map, + const int mw, const int mh, const LFSPARMS *lfsparms) +{ + int ret; + + /* 1. Sort minutiae points top-to-bottom and left-to-right. */ + if((ret = sort_minutiae_y_x(minutiae, iw, ih))){ + return(ret); + } + + /* 2. Remove minutiae on lakes (filled with white pixels) and */ + /* islands (filled with black pixels), both defined by a pair of */ + /* minutia points. */ + if((ret = remove_islands_and_lakes(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 3. Remove minutiae on holes in the binary image defined by a */ + /* single point. */ + if((ret = remove_holes(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 4. Remove minutiae that point sufficiently close to a block with */ + /* INVALID direction. */ + if((ret = remove_pointing_invblock_V2(minutiae, direction_map, mw, mh, + lfsparms))){ + return(ret); + } + + /* 5. Remove minutiae that are sufficiently close to a block with */ + /* INVALID direction. */ + if((ret = remove_near_invblock_V2(minutiae, direction_map, mw, mh, + lfsparms))){ + return(ret); + } + + /* 6. Remove or adjust minutiae that reside on the side of a ridge */ + /* or valley. */ + if((ret = remove_or_adjust_side_minutiae_V2(minutiae, bdata, iw, ih, + direction_map, mw, mh, lfsparms))){ + return(ret); + } + + /* 7. Remove minutiae that form a hook on the side of a ridge or valley. */ + if((ret = remove_hooks(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 8. Remove minutiae that are on opposite sides of an overlap. */ + if((ret = remove_overlaps(minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } + + /* 9. Remove minutiae that are "irregularly" shaped. */ + if((ret = remove_malformations(minutiae, bdata, iw, ih, + low_flow_map, mw, mh, lfsparms))){ + return(ret); + } + + /* 10. Remove minutiae that form long, narrow, loops in the */ + /* "unreliable" regions in the binary image. */ + if((ret = remove_pores_V2(minutiae, bdata, iw, ih, + direction_map, low_flow_map, high_curve_map, + mw, mh, lfsparms))){ + return(ret); + } + + return(0); +} + /************************************************************************* ************************************************************************** #cat: remove_holes - Removes minutia points on small loops around valleys. @@ -68,7 +214,7 @@ identified are necessarily the best available for the purpose. Zero - successful completion Negative - system error **************************************************************************/ -static int remove_holes(MINUTIAE *minutiae, +int remove_holes(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, const LFSPARMS *lfsparms) { @@ -139,7 +285,7 @@ static int remove_holes(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_hooks(MINUTIAE *minutiae, +int remove_hooks(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, const LFSPARMS *lfsparms) { @@ -341,6 +487,29 @@ static int remove_hooks(MINUTIAE *minutiae, return(0); } +/************************************************************************* +************************************************************************** +#cat: remove_hooks_islands_lakes_overlaps - Removes minutia points on hooks, +#cat: islands, lakes, and overlaps and fills in small small +#cat: loops in the binary image and joins minutia features in +#cat: the image on opposite sides of an overlap. So, this +#cat: routine not only prunes minutia points but it edits the +#cat: binary input image as well. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + bdata - edited binary image with loops filled and overlaps removed + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: remove_islands_and_lakes - Takes a list of true and false minutiae and @@ -362,7 +531,7 @@ static int remove_hooks(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_islands_and_lakes(MINUTIAE *minutiae, +int remove_islands_and_lakes(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, const LFSPARMS *lfsparms) { @@ -616,7 +785,7 @@ static int remove_islands_and_lakes(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_malformations(MINUTIAE *minutiae, +int remove_malformations(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, int *low_flow_map, const int mw, const int mh, const LFSPARMS *lfsparms) @@ -647,7 +816,7 @@ static int remove_malformations(MINUTIAE *minutiae, /* Return error code. */ return(ret); } - + /* If trace was not possible OR loop found OR */ /* contour is incomplete ... */ if((ret == IGNORE) || @@ -803,6 +972,26 @@ static int remove_malformations(MINUTIAE *minutiae, return(0); } +/************************************************************************* +************************************************************************** +#cat: remove_near_invblocks - Removes minutia points from the given list +#cat: that are sufficiently close to a block with invalid +#cat: ridge flow or to the edge of the image. + + Input: + minutiae - list of true and false minutiae + nmap - IMAP ridge flow matrix with invalid, high-curvature, + and no-valid-neighbor regions identified + mw - width in blocks of the NMAP + mh - height in blocks of the NMAP + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: remove_near_invblocks_V2 - Removes minutia points from the given list @@ -821,7 +1010,7 @@ static int remove_malformations(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_near_invblock_V2(MINUTIAE *minutiae, int *direction_map, +int remove_near_invblock_V2(MINUTIAE *minutiae, int *direction_map, const int mw, const int mh, const LFSPARMS *lfsparms) { int i, ret; @@ -1032,6 +1221,26 @@ static int remove_near_invblock_V2(MINUTIAE *minutiae, int *direction_map, return(0); } +/************************************************************************* +************************************************************************** +#cat: remove_pointing_invblock - Removes minutia points that are relatively +#cat: close in the direction opposite the minutia to an NMAP +#cat: block with invalid ridge flow. + + Input: + minutiae - list of true and false minutiae + nmap - IMAP ridge flow matrix with invalid, high-curvature, + and no-valid-neighbor regions identified + mw - width in blocks of the NMAP + mh - height in blocks of the NMAP + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: remove_pointing_invblock_V2 - Removes minutia points that are relatively @@ -1050,7 +1259,7 @@ static int remove_near_invblock_V2(MINUTIAE *minutiae, int *direction_map, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_pointing_invblock_V2(MINUTIAE *minutiae, +int remove_pointing_invblock_V2(MINUTIAE *minutiae, int *direction_map, const int mw, const int mh, const LFSPARMS *lfsparms) { @@ -1140,7 +1349,7 @@ static int remove_pointing_invblock_V2(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_overlaps(MINUTIAE *minutiae, +int remove_overlaps(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, const LFSPARMS *lfsparms) { @@ -1350,32 +1559,20 @@ static int remove_overlaps(MINUTIAE *minutiae, return(0); } -static void mark_minutiae_in_range(MINUTIAE *minutiae, int *to_remove, int x, int y, - const LFSPARMS *lfsparms) -{ - int i, dist; - for (i = 0; i < minutiae->num; i++) { - if (to_remove[i]) - continue; - dist = (int)sqrt((x - minutiae->list[i]->x) * (x - minutiae->list[i]->x) + - (y - minutiae->list[i]->y) * (y - minutiae->list[i]->y)); - if (dist < lfsparms->min_pp_distance) { - to_remove[i] = 1; - } - } -} - /************************************************************************* ************************************************************************** -#cat: remove_perimeter_pts - Takes a list of true and false minutiae and -#cat: attempts to detect and remove those false minutiae that -#cat: belong to image edge +#cat: remove_pores - Attempts to detect and remove minutia points located on +#cat: pore-shaped valleys. Input: minutiae - list of true and false minutiae bdata - binary image data (0==while & 1==black) iw - width (in pixels) of image ih - height (in pixels) of image + nmap - IMAP ridge flow matrix with invalid, high-curvature, + and no-valid-neighbor regions identified + mw - width in blocks of the NMAP + mh - height in blocks of the NMAP lfsparms - parameters and thresholds for controlling LFS Output: minutiae - list of pruned minutiae @@ -1383,125 +1580,6 @@ static void mark_minutiae_in_range(MINUTIAE *minutiae, int *to_remove, int x, in Zero - successful completion Negative - system error **************************************************************************/ -static int remove_perimeter_pts(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const LFSPARMS *lfsparms) -{ - int i, j, ret, *to_remove; - int *left, *left_up, *left_down; - int *right, *right_up, *right_down; - int removed = 0; - int left_min, right_max; - - if (!lfsparms->remove_perimeter_pts) - return(0); - - to_remove = calloc(minutiae->num, sizeof(int)); - left = calloc(ih, sizeof(int)); - left_up = calloc(ih, sizeof(int)); - left_down = calloc(ih, sizeof(int)); - right = calloc(ih, sizeof(int)); - right_up = calloc(ih, sizeof(int)); - right_down = calloc(ih, sizeof(int)); - - /* Pass downwards */ - left_min = iw - 1; - right_max = 0; - for (i = 0; i < ih; i++) { - for (j = 0; j < left_min; j++) { - if ((bdata[i * iw + j] != 0)) { - left_min = j; - break; - } - } - if (left_min == (iw - 1)) - left_down[i] = -1; - else - left_down[i] = left_min; - for (j = iw - 1; j >= right_max; j--) { - if ((bdata[i * iw + j] != 0)) { - right_max = j; - break; - } - } - if (right_max == 0) - right_down[i] = -1; - else - right_down[i] = right_max; - } - - /* Pass upwards */ - left_min = iw - 1; - right_max = 0; - for (i = ih - 1; i >= 0; i--) { - for (j = 0; j < left_min; j++) { - if ((bdata[i * iw + j] != 0)) { - left_min = j; - break; - } - } - if (left_min == (iw - 1)) - left_up[i] = -1; - else - left_up[i] = left_min; - for (j = iw - 1; j >= right_max; j--) { - if ((bdata[i * iw + j] != 0)) { - right_max = j; - break; - } - } - if (right_max == 0) - right_up[i] = -1; - else - right_up[i] = right_max; - } - - /* Merge */ - left_min = left_down[ih - 1]; - right_max = right_down[ih - 1]; - for (i = 0; i < ih; i++) { - if (left_down[i] != left_min) - left[i] = left_down[i]; - else - left[i] = left_up[i]; - - if (right_down[i] != right_max) - right[i] = right_down[i]; - else - right[i] = right_up[i]; - } - free(left_up); - free(left_down); - free(right_up); - free(right_down); - - /* Mark minitiae close to the edge */ - for (i = 0; i < ih; i++) { - if (left[i] != -1) - mark_minutiae_in_range(minutiae, to_remove, left[i], i, lfsparms); - if (right[i] != -1) - mark_minutiae_in_range(minutiae, to_remove, right[i], i, lfsparms); - } - - free(left); - free(right); - - for (i = minutiae->num - 1; i >= 0; i--) { - /* If the current minutia index is flagged for removal ... */ - if (to_remove[i]){ - removed ++; - /* Remove the minutia from the minutiae list. */ - if((ret = remove_minutia(i, minutiae))){ - free(to_remove); - return(ret); - } - } - } - - free(to_remove); - - return (0); -} /************************************************************************* ************************************************************************** @@ -1527,7 +1605,7 @@ static int remove_perimeter_pts(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_pores_V2(MINUTIAE *minutiae, +int remove_pores_V2(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, int *direction_map, int *low_flow_map, int *high_curve_map, const int mw, const int mh, @@ -1777,7 +1855,7 @@ static int remove_pores_V2(MINUTIAE *minutiae, /* counter-clockwise scan and step along a */ /* specified number of steps (ex. 8). */ ret = trace_contour(&contour_x, &contour_y, - &contour_ex, &contour_ey, &ncontour, + &contour_ex, &contour_ey, &ncontour, lfsparms->pores_steps_bwd, qx, qy, qx, qy, qex, qey, SCAN_COUNTER_CLOCKWISE, bdata, iw, ih); @@ -1896,6 +1974,26 @@ static int remove_pores_V2(MINUTIAE *minutiae, return(0); } +/************************************************************************* +************************************************************************** +#cat: remove_or_adjust_side_minutiae - Removes loops or minutia points that +#cat: are not on complete contours of specified length. If the +#cat: contour is complete, then the minutia is adjusted based +#cat: on a minmax analysis of the rotated y-coords of the contour. + + Input: + minutiae - list of true and false minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Output: + minutiae - list of pruned minutiae + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ + /************************************************************************* ************************************************************************** #cat: remove_or_adjust_side_minutiae_V2 - Removes loops or minutia points that @@ -1918,7 +2016,7 @@ static int remove_pores_V2(MINUTIAE *minutiae, Zero - successful completion Negative - system error **************************************************************************/ -static int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, +int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, int *direction_map, const int mw, const int mh, const LFSPARMS *lfsparms) @@ -2164,104 +2262,3 @@ static int remove_or_adjust_side_minutiae_V2(MINUTIAE *minutiae, return(0); } -/************************************************************************* -************************************************************************** -#cat: remove_false_minutia_V2 - Takes a list of true and false minutiae and -#cat: attempts to detect and remove the false minutiae based -#cat: on a series of tests. - - Input: - minutiae - list of true and false minutiae - bdata - binary image data (0==while & 1==black) - iw - width (in pixels) of image - ih - height (in pixels) of image - direction_map - map of image blocks containing directional ridge flow - low_flow_map - map of image blocks flagged as LOW RIDGE FLOW - high_curve_map - map of image blocks flagged as HIGH CURVATURE - mw - width in blocks of the maps - mh - height in blocks of the maps - lfsparms - parameters and thresholds for controlling LFS - Output: - minutiae - list of pruned minutiae - Return Code: - Zero - successful completion - Negative - system error -**************************************************************************/ -int remove_false_minutia_V2(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - int *direction_map, int *low_flow_map, int *high_curve_map, - const int mw, const int mh, const LFSPARMS *lfsparms) -{ - int ret; - - /* 1. Sort minutiae points top-to-bottom and left-to-right. */ - if((ret = sort_minutiae_y_x(minutiae, iw, ih))){ - return(ret); - } - - /* 2. Remove minutiae on lakes (filled with white pixels) and */ - /* islands (filled with black pixels), both defined by a pair of */ - /* minutia points. */ - if((ret = remove_islands_and_lakes(minutiae, bdata, iw, ih, lfsparms))){ - return(ret); - } - - /* 3. Remove minutiae on holes in the binary image defined by a */ - /* single point. */ - if((ret = remove_holes(minutiae, bdata, iw, ih, lfsparms))){ - return(ret); - } - - /* 4. Remove minutiae that point sufficiently close to a block with */ - /* INVALID direction. */ - if((ret = remove_pointing_invblock_V2(minutiae, direction_map, mw, mh, - lfsparms))){ - return(ret); - } - - /* 5. Remove minutiae that are sufficiently close to a block with */ - /* INVALID direction. */ - if((ret = remove_near_invblock_V2(minutiae, direction_map, mw, mh, - lfsparms))){ - return(ret); - } - - /* 6. Remove or adjust minutiae that reside on the side of a ridge */ - /* or valley. */ - if((ret = remove_or_adjust_side_minutiae_V2(minutiae, bdata, iw, ih, - direction_map, mw, mh, lfsparms))){ - return(ret); - } - - /* 7. Remove minutiae that form a hook on the side of a ridge or valley. */ - if((ret = remove_hooks(minutiae, bdata, iw, ih, lfsparms))){ - return(ret); - } - - /* 8. Remove minutiae that are on opposite sides of an overlap. */ - if((ret = remove_overlaps(minutiae, bdata, iw, ih, lfsparms))){ - return(ret); - } - - /* 9. Remove minutiae that are "irregularly" shaped. */ - if((ret = remove_malformations(minutiae, bdata, iw, ih, - low_flow_map, mw, mh, lfsparms))){ - return(ret); - } - - /* 10. Remove minutiae that form long, narrow, loops in the */ - /* "unreliable" regions in the binary image. */ - if((ret = remove_pores_V2(minutiae, bdata, iw, ih, - direction_map, low_flow_map, high_curve_map, - mw, mh, lfsparms))){ - return(ret); - } - - /* 11. Remove minutiae on image edge */ - if((ret = remove_perimeter_pts(minutiae, bdata, iw, ih, lfsparms))) { - return (ret); - } - - return(0); -} - diff --git a/libfprint/nbis/mindtct/ridges.c b/libfprint/nbis/mindtct/ridges.c index 9fb110f2..b5b7f2c4 100644 --- a/libfprint/nbis/mindtct/ridges.c +++ b/libfprint/nbis/mindtct/ridges.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -52,156 +73,135 @@ identified are necessarily the best available for the purpose. /************************************************************************* ************************************************************************** -#cat: insert_neighbor - Takes a minutia index and its squared distance to a -#cat: primary minutia point, and inserts them in the specified -#cat: position of their respective lists, shifting previously -#cat: stored values down and off the lists as necessary. +#cat: count_minutiae_ridges - Takes a list of minutiae, and for each one, +#cat: determines its closest neighbors and counts the number +#cat: of interveining ridges between the minutia point and +#cat: each of its neighbors. Input: - pos - postions where values are to be inserted in lists - nbr_index - index of minutia being inserted - nbr_dist2 - squared distance of minutia to its primary point - nbr_list - current list of nearest neighbor minutia indices - nbr_sqr_dists - corresponding squared euclidean distance of each - neighbor to the primary minutia point - nnbrs - number of neighbors currently in the list - max_nbrs - maximum number of closest neighbors to be returned + minutiae - list of minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS Output: - nbr_list - updated list of nearest neighbor indices - nbr_sqr_dists - updated list of nearest neighbor distances - nnbrs - number of neighbors in the update lists + minutiae - list of minutiae augmented with neighbors and ridge counts Return Code: - Zero - successful completion - Negative - system error + Zero - successful completion + Negative - system error **************************************************************************/ -static int insert_neighbor(const int pos, const int nbr_index, const double nbr_dist2, - int *nbr_list, double *nbr_sqr_dists, - int *nnbrs, const int max_nbrs) +int count_minutiae_ridges(MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) { + int ret; int i; - /* If the desired insertion position is beyond one passed the last */ - /* neighbor in the lists OR greater than equal to the maximum ... */ - /* NOTE: pos is zero-oriented while nnbrs and max_nbrs are 1-oriented. */ - if((pos > *nnbrs) || - (pos >= max_nbrs)){ - fprintf(stderr, - "ERROR : insert_neighbor : insertion point exceeds lists\n"); - return(-480); + print2log("\nFINDING NBRS AND COUNTING RIDGES:\n"); + + /* Sort minutia points on x then y (column-oriented). */ + if((ret = sort_minutiae_x_y(minutiae, iw, ih))){ + return(ret); } - /* If the neighbor lists are NOT full ... */ - if(*nnbrs < max_nbrs){ - /* Then we have room to shift everything down to make room for new */ - /* neighbor and increase the number of neighbors stored by 1. */ - i = *nnbrs-1; - (*nnbrs)++; - } - /* Otherwise, the neighbors lists are full ... */ - else if(*nnbrs == max_nbrs) - /* So, we must bump the last neighbor in the lists off to make */ - /* room for the new neighbor (ignore last neighbor in lists). */ - i = *nnbrs-2; - /* Otherwise, there is a list overflow error condition */ - /* (shouldn't ever happen, but just in case) ... */ - else{ - fprintf(stderr, - "ERROR : insert_neighbor : overflow in neighbor lists\n"); - return(-481); + /* Remove any duplicate minutia points from the list. */ + if((ret = rm_dup_minutiae(minutiae))){ + return(ret); } - /* While we havn't reached the desired insertion point ... */ - while(i >= pos){ - /* Shift the current neighbor down the list 1 positon. */ - nbr_list[i+1] = nbr_list[i]; - nbr_sqr_dists[i+1] = nbr_sqr_dists[i]; - i--; + /* Foreach remaining sorted minutia in list ... */ + for(i = 0; i < minutiae->num-1; i++){ + /* Located neighbors and count number of ridges in between. */ + /* NOTE: neighbor and ridge count results are stored in */ + /* minutiae->list[i]. */ + if((ret = count_minutia_ridges(i, minutiae, bdata, iw, ih, lfsparms))){ + return(ret); + } } - /* We are now ready to put our new neighbor in the position where */ - /* we shifted everything down from to make room. */ - nbr_list[pos] = nbr_index; - nbr_sqr_dists[pos] = nbr_dist2; - /* Return normally. */ return(0); } /************************************************************************* ************************************************************************** -#cat: update_nbr_dists - Takes the current list of neighbors along with a -#cat: primary minutia and a potential new neighbor, and -#cat: determines if the new neighbor is sufficiently close -#cat: to be added to the list of nearest neighbors. If added, -#cat: it is placed in the list in its proper order based on -#cat: squared distance to the primary point. +#cat: count_minutia_ridges - Takes a minutia, and determines its closest +#cat: neighbors and counts the number of interveining ridges +#cat: between the minutia point and each of its neighbors. Input: - nbr_list - current list of nearest neighbor minutia indices - nbr_sqr_dists - corresponding squared euclidean distance of each - neighbor to the primary minutia point - nnbrs - number of neighbors currently in the list - max_nbrs - maximum number of closest neighbors to be returned - first - index of the primary minutia point - second - index of the secondary (new neighbor) point - minutiae - list of minutiae + minutia - input minutia + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS Output: - nbr_list - updated list of nearest neighbor indices - nbr_sqr_dists - updated list of nearest neighbor distances - nnbrs - number of neighbors in the update lists + minutiae - minutia augmented with neighbors and ridge counts Return Code: - Zero - successful completion - Negative - system error + Zero - successful completion + Negative - system error **************************************************************************/ -static int update_nbr_dists(int *nbr_list, double *nbr_sqr_dists, - int *nnbrs, const int max_nbrs, - const int first, const int second, MINUTIAE *minutiae) +int count_minutia_ridges(const int first, MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) { - double dist2; - MINUTIA *minutia1, *minutia2; - int pos, last_nbr; + int i, ret, *nbr_list, *nbr_nridges, nnbrs; - /* Compute position of maximum last neighbor stored. */ - last_nbr = max_nbrs - 1; + /* Find up to the maximum number of qualifying neighbors. */ + if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs, + first, minutiae))){ + free(nbr_list); + return(ret); + } - /* Assigne temporary minutia pointers. */ - minutia1 = minutiae->list[first]; - minutia2 = minutiae->list[second]; + print2log("NBRS FOUND: %d,%d = %d\n", minutiae->list[first]->x, + minutiae->list[first]->y, nnbrs); - /* Compute squared euclidean distance between minutia pair. */ - dist2 = squared_distance(minutia1->x, minutia1->y, - minutia2->x, minutia2->y); - - /* If maximum number of neighbors not yet stored in lists OR */ - /* if the squared distance to current secondary is less */ - /* than the largest stored neighbor distance ... */ - if((*nnbrs < max_nbrs) || - (dist2 < nbr_sqr_dists[last_nbr])){ - - /* Find insertion point in neighbor lists. */ - pos = find_incr_position_dbl(dist2, nbr_sqr_dists, *nnbrs); - /* If the position returned is >= maximum list length (this should */ - /* never happen, but just in case) ... */ - if(pos >= max_nbrs){ - fprintf(stderr, - "ERROR : update_nbr_dists : illegal position for new neighbor\n"); - return(-470); - } - /* Insert the new neighbor into the neighbor lists at the */ - /* specified location. */ - if(insert_neighbor(pos, second, dist2, - nbr_list, nbr_sqr_dists, nnbrs, max_nbrs)) - return(-471); - - /* Otherwise, neighbor inserted successfully, so return normally. */ + /* If no neighors found ... */ + if(nnbrs == 0){ + /* Then no list returned and no ridges to count. */ return(0); } - /* Otherwise, the new neighbor is not sufficiently close to be */ - /* added or inserted into the neighbor lists, so ignore the neighbor */ - /* and return normally. */ - else - return(0); + /* Sort neighbors on delta dirs. */ + if((ret = sort_neighbors(nbr_list, nnbrs, first, minutiae))){ + free(nbr_list); + return(ret); + } + + /* Count ridges between first and neighbors. */ + /* List of ridge counts, one for each neighbor stored. */ + nbr_nridges = (int *)malloc(nnbrs * sizeof(int)); + if(nbr_nridges == (int *)NULL){ + free(nbr_list); + fprintf(stderr, "ERROR : count_minutia_ridges : malloc : nbr_nridges\n"); + return(-450); + } + + /* Foreach neighbor found and sorted in list ... */ + for(i = 0; i < nnbrs; i++){ + /* Count the ridges between the primary minutia and the neighbor. */ + ret = ridge_count(first, nbr_list[i], minutiae, bdata, iw, ih, lfsparms); + /* If system error ... */ + if(ret < 0){ + /* Deallocate working memories. */ + free(nbr_list); + free(nbr_nridges); + /* Return error code. */ + return(ret); + } + + /* Otherwise, ridge count successful, so store ridge count to list. */ + nbr_nridges[i] = ret; + } + + /* Assign neighbor indices and ridge counts to primary minutia. */ + minutiae->list[first]->nbrs = nbr_list; + minutiae->list[first]->ridge_counts = nbr_nridges; + minutiae->list[first]->num_nbrs = nnbrs; + + /* Return normally. */ + return(0); } /************************************************************************* @@ -224,7 +224,7 @@ static int update_nbr_dists(int *nbr_list, double *nbr_sqr_dists, Zero - successful completion Negative - system error **************************************************************************/ -static int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, +int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, const int first, MINUTIAE *minutiae) { int ret, second, last_nbr; @@ -312,6 +312,160 @@ static int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, return(0); } +/************************************************************************* +************************************************************************** +#cat: update_nbr_dists - Takes the current list of neighbors along with a +#cat: primary minutia and a potential new neighbor, and +#cat: determines if the new neighbor is sufficiently close +#cat: to be added to the list of nearest neighbors. If added, +#cat: it is placed in the list in its proper order based on +#cat: squared distance to the primary point. + + Input: + nbr_list - current list of nearest neighbor minutia indices + nbr_sqr_dists - corresponding squared euclidean distance of each + neighbor to the primary minutia point + nnbrs - number of neighbors currently in the list + max_nbrs - maximum number of closest neighbors to be returned + first - index of the primary minutia point + second - index of the secondary (new neighbor) point + minutiae - list of minutiae + Output: + nbr_list - updated list of nearest neighbor indices + nbr_sqr_dists - updated list of nearest neighbor distances + nnbrs - number of neighbors in the update lists + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int update_nbr_dists(int *nbr_list, double *nbr_sqr_dists, + int *nnbrs, const int max_nbrs, + const int first, const int second, MINUTIAE *minutiae) +{ + double dist2; + MINUTIA *minutia1, *minutia2; + int pos, last_nbr; + + /* Compute position of maximum last neighbor stored. */ + last_nbr = max_nbrs - 1; + + /* Assigne temporary minutia pointers. */ + minutia1 = minutiae->list[first]; + minutia2 = minutiae->list[second]; + + /* Compute squared euclidean distance between minutia pair. */ + dist2 = squared_distance(minutia1->x, minutia1->y, + minutia2->x, minutia2->y); + + /* If maximum number of neighbors not yet stored in lists OR */ + /* if the squared distance to current secondary is less */ + /* than the largest stored neighbor distance ... */ + if((*nnbrs < max_nbrs) || + (dist2 < nbr_sqr_dists[last_nbr])){ + + /* Find insertion point in neighbor lists. */ + pos = find_incr_position_dbl(dist2, nbr_sqr_dists, *nnbrs); + /* If the position returned is >= maximum list length (this should */ + /* never happen, but just in case) ... */ + if(pos >= max_nbrs){ + fprintf(stderr, + "ERROR : update_nbr_dists : illegal position for new neighbor\n"); + return(-470); + } + /* Insert the new neighbor into the neighbor lists at the */ + /* specified location. */ + if(insert_neighbor(pos, second, dist2, + nbr_list, nbr_sqr_dists, nnbrs, max_nbrs)) + return(-471); + + /* Otherwise, neighbor inserted successfully, so return normally. */ + return(0); + } + /* Otherwise, the new neighbor is not sufficiently close to be */ + /* added or inserted into the neighbor lists, so ignore the neighbor */ + /* and return normally. */ + else + return(0); + +} + +/************************************************************************* +************************************************************************** +#cat: insert_neighbor - Takes a minutia index and its squared distance to a +#cat: primary minutia point, and inserts them in the specified +#cat: position of their respective lists, shifting previously +#cat: stored values down and off the lists as necessary. + + Input: + pos - postions where values are to be inserted in lists + nbr_index - index of minutia being inserted + nbr_dist2 - squared distance of minutia to its primary point + nbr_list - current list of nearest neighbor minutia indices + nbr_sqr_dists - corresponding squared euclidean distance of each + neighbor to the primary minutia point + nnbrs - number of neighbors currently in the list + max_nbrs - maximum number of closest neighbors to be returned + Output: + nbr_list - updated list of nearest neighbor indices + nbr_sqr_dists - updated list of nearest neighbor distances + nnbrs - number of neighbors in the update lists + Return Code: + Zero - successful completion + Negative - system error +**************************************************************************/ +int insert_neighbor(const int pos, const int nbr_index, const double nbr_dist2, + int *nbr_list, double *nbr_sqr_dists, + int *nnbrs, const int max_nbrs) +{ + int i; + + /* If the desired insertion position is beyond one passed the last */ + /* neighbor in the lists OR greater than equal to the maximum ... */ + /* NOTE: pos is zero-oriented while nnbrs and max_nbrs are 1-oriented. */ + if((pos > *nnbrs) || + (pos >= max_nbrs)){ + fprintf(stderr, + "ERROR : insert_neighbor : insertion point exceeds lists\n"); + return(-480); + } + + /* If the neighbor lists are NOT full ... */ + if(*nnbrs < max_nbrs){ + /* Then we have room to shift everything down to make room for new */ + /* neighbor and increase the number of neighbors stored by 1. */ + i = *nnbrs-1; + (*nnbrs)++; + } + /* Otherwise, the neighbors lists are full ... */ + else if(*nnbrs == max_nbrs) + /* So, we must bump the last neighbor in the lists off to make */ + /* room for the new neighbor (ignore last neighbor in lists). */ + i = *nnbrs-2; + /* Otherwise, there is a list overflow error condition */ + /* (shouldn't ever happen, but just in case) ... */ + else{ + fprintf(stderr, + "ERROR : insert_neighbor : overflow in neighbor lists\n"); + return(-481); + } + + /* While we havn't reached the desired insertion point ... */ + while(i >= pos){ + /* Shift the current neighbor down the list 1 positon. */ + nbr_list[i+1] = nbr_list[i]; + nbr_sqr_dists[i+1] = nbr_sqr_dists[i]; + i--; + } + + /* We are now ready to put our new neighbor in the position where */ + /* we shifted everything down from to make room. */ + nbr_list[pos] = nbr_index; + nbr_sqr_dists[pos] = nbr_dist2; + + /* Return normally. */ + return(0); +} + /************************************************************************* ************************************************************************** #cat: sort_neighbors - Takes a list of primary minutia and its neighboring @@ -331,7 +485,7 @@ static int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, Zero - successful completion Negative - system error **************************************************************************/ -static int sort_neighbors(int *nbr_list, const int nnbrs, const int first, +int sort_neighbors(int *nbr_list, const int nnbrs, const int first, MINUTIAE *minutiae) { double *join_thetas, theta; @@ -369,7 +523,164 @@ static int sort_neighbors(int *nbr_list, const int nnbrs, const int first, free(join_thetas); /* Return normally. */ - return(0); + return(0); +} + +/************************************************************************* +************************************************************************** +#cat: ridge_count - Takes a pair of minutiae, and counts the number of +#cat: ridges crossed along the linear trajectory connecting +#cat: the 2 points in the image. + + Input: + first - index of primary minutia + second - index of secondary (neighbor) minutia + minutiae - list of minutiae + bdata - binary image data (0==while & 1==black) + iw - width (in pixels) of image + ih - height (in pixels) of image + lfsparms - parameters and thresholds for controlling LFS + Return Code: + Zero or Positive - number of ridges counted + Negative - system error +**************************************************************************/ +int ridge_count(const int first, const int second, MINUTIAE *minutiae, + unsigned char *bdata, const int iw, const int ih, + const LFSPARMS *lfsparms) +{ + MINUTIA *minutia1, *minutia2; + int i, ret, found; + int *xlist, *ylist, num; + int ridge_count, ridge_start, ridge_end; + int prevpix, curpix; + + minutia1 = minutiae->list[first]; + minutia2 = minutiae->list[second]; + + /* If the 2 mintuia have identical pixel coords ... */ + if((minutia1->x == minutia2->x) && + (minutia1->y == minutia2->y)) + /* Then zero ridges between points. */ + return(0); + + /* Compute linear trajectory of contiguous pixels between first */ + /* and second minutia points. */ + if((ret = line_points(&xlist, &ylist, &num, + minutia1->x, minutia1->y, minutia2->x, minutia2->y))){ + return(ret); + } + + /* It there are no points on the line trajectory, then no ridges */ + /* to count (this should not happen, but just in case) ... */ + if(num == 0){ + free(xlist); + free(ylist); + return(0); + } + + /* Find first pixel opposite type along linear trajectory from */ + /* first minutia. */ + prevpix = *(bdata+(ylist[0]*iw)+xlist[0]); + i = 1; + found = FALSE; + while(i < num){ + curpix = *(bdata+(ylist[i]*iw)+xlist[i]); + if(curpix != prevpix){ + found = TRUE; + break; + } + i++; + } + + /* If opposite pixel not found ... then no ridges to count */ + if(!found){ + free(xlist); + free(ylist); + return(0); + } + + /* Ready to count ridges, so initialize counter to 0. */ + ridge_count = 0; + + print2log("RIDGE COUNT: %d,%d to %d,%d ", minutia1->x, minutia1->y, + minutia2->x, minutia2->y); + + /* While not at the end of the trajectory ... */ + while(i < num){ + /* If 0-to-1 transition not found ... */ + if(!find_transition(&i, 0, 1, xlist, ylist, num, bdata, iw, ih)){ + /* Then we are done looking for ridges. */ + free(xlist); + free(ylist); + + print2log("\n"); + + /* Return number of ridges counted to this point. */ + return(ridge_count); + } + /* Otherwise, we found a new ridge start transition, so store */ + /* its location (the location of the 1 in 0-to-1 transition). */ + ridge_start = i; + + print2log(": RS %d,%d ", xlist[i], ylist[i]); + + /* If 1-to-0 transition not found ... */ + if(!find_transition(&i, 1, 0, xlist, ylist, num, bdata, iw, ih)){ + /* Then we are done looking for ridges. */ + free(xlist); + free(ylist); + + print2log("\n"); + + /* Return number of ridges counted to this point. */ + return(ridge_count); + } + /* Otherwise, we found a new ridge end transition, so store */ + /* its location (the location of the 0 in 1-to-0 transition). */ + ridge_end = i; + + print2log("; RE %d,%d ", xlist[i], ylist[i]); + + /* Conduct the validation, tracing the contour of the ridge */ + /* from the ridge ending point a specified number of steps */ + /* scanning for neighbors clockwise and counter-clockwise. */ + /* If the ridge starting point is encounted during the trace */ + /* then we can assume we do not have a valid ridge crossing */ + /* and instead we are walking on and off the edge of the */ + /* side of a ridge. */ + ret = validate_ridge_crossing(ridge_start, ridge_end, + xlist, ylist, num, bdata, iw, ih, + lfsparms->max_ridge_steps); + + /* If system error ... */ + if(ret < 0){ + free(xlist); + free(ylist); + /* Return the error code. */ + return(ret); + } + + print2log("; V%d ", ret); + + /* If validation result is TRUE ... */ + if(ret){ + /* Then assume we have found a valid ridge crossing and bump */ + /* the ridge counter. */ + ridge_count++; + } + + /* Otherwise, ignore the current ridge start and end transitions */ + /* and go back and search for new ridge start. */ + } + + /* Deallocate working memories. */ + free(xlist); + free(ylist); + + print2log("\n"); + + /* Return the number of ridges counted. */ + return(ridge_count); } /************************************************************************* @@ -395,7 +706,7 @@ static int sort_neighbors(int *nbr_list, const int nnbrs, const int first, TRUE - pixel pair transition found FALSE - pixel pair transition not found **************************************************************************/ -static int find_transition(int *iptr, const int pix1, const int pix2, +int find_transition(int *iptr, const int pix1, const int pix2, const int *xlist, const int *ylist, const int num, unsigned char *bdata, const int iw, const int ih) { @@ -456,7 +767,7 @@ static int find_transition(int *iptr, const int pix1, const int pix2, FALSE - ridge corssing INVALID Negative - system error **************************************************************************/ -static int validate_ridge_crossing(const int ridge_start, const int ridge_end, +int validate_ridge_crossing(const int ridge_start, const int ridge_end, const int *xlist, const int *ylist, const int num, unsigned char *bdata, const int iw, const int ih, const int max_ridge_steps) @@ -482,7 +793,7 @@ static int validate_ridge_crossing(const int ridge_start, const int ridge_end, /* position is on the white (of a black to white transition) and */ /* the ridge start is on the black (of a black to white trans), */ /* so the edge trace needs to look for the what pixel (not the */ - /* black one) of the ridge start transition. */ + /* black one) of the ridge start transition. */ ret = trace_contour(&contour_x, &contour_y, &contour_ex, &contour_ey, &ncontour, max_ridge_steps, @@ -535,298 +846,7 @@ static int validate_ridge_crossing(const int ridge_start, const int ridge_end, /* Otherwise, second trace returned IGNORE or ridge start found. */ } /* Otherwise, first trace returned IGNORE or ridge start found. */ - + /* If we get here, then we failed to validate a ridge crossing. */ return(FALSE); } - -/************************************************************************* -************************************************************************** -#cat: ridge_count - Takes a pair of minutiae, and counts the number of -#cat: ridges crossed along the linear trajectory connecting -#cat: the 2 points in the image. - - Input: - first - index of primary minutia - second - index of secondary (neighbor) minutia - minutiae - list of minutiae - bdata - binary image data (0==while & 1==black) - iw - width (in pixels) of image - ih - height (in pixels) of image - lfsparms - parameters and thresholds for controlling LFS - Return Code: - Zero or Positive - number of ridges counted - Negative - system error -**************************************************************************/ -static int ridge_count(const int first, const int second, MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const LFSPARMS *lfsparms) -{ - MINUTIA *minutia1, *minutia2; - int i, ret, found; - int *xlist, *ylist, num; - int ridge_cnt, ridge_start, ridge_end; - int prevpix, curpix; - - minutia1 = minutiae->list[first]; - minutia2 = minutiae->list[second]; - - /* If the 2 mintuia have identical pixel coords ... */ - if((minutia1->x == minutia2->x) && - (minutia1->y == minutia2->y)) - /* Then zero ridges between points. */ - return(0); - - /* Compute linear trajectory of contiguous pixels between first */ - /* and second minutia points. */ - if((ret = line_points(&xlist, &ylist, &num, - minutia1->x, minutia1->y, minutia2->x, minutia2->y))){ - return(ret); - } - - /* It there are no points on the line trajectory, then no ridges */ - /* to count (this should not happen, but just in case) ... */ - if(num == 0){ - free(xlist); - free(ylist); - return(0); - } - - /* Find first pixel opposite type along linear trajectory from */ - /* first minutia. */ - prevpix = *(bdata+(ylist[0]*iw)+xlist[0]); - i = 1; - found = FALSE; - while(i < num){ - curpix = *(bdata+(ylist[i]*iw)+xlist[i]); - if(curpix != prevpix){ - found = TRUE; - break; - } - i++; - } - - /* If opposite pixel not found ... then no ridges to count */ - if(!found){ - free(xlist); - free(ylist); - return(0); - } - - /* Ready to count ridges, so initialize counter to 0. */ - ridge_cnt = 0; - - print2log("RIDGE COUNT: %d,%d to %d,%d ", minutia1->x, minutia1->y, - minutia2->x, minutia2->y); - - /* While not at the end of the trajectory ... */ - while(i < num){ - /* If 0-to-1 transition not found ... */ - if(!find_transition(&i, 0, 1, xlist, ylist, num, bdata, iw, ih)){ - /* Then we are done looking for ridges. */ - free(xlist); - free(ylist); - - print2log("\n"); - - /* Return number of ridges counted to this point. */ - return(ridge_cnt); - } - /* Otherwise, we found a new ridge start transition, so store */ - /* its location (the location of the 1 in 0-to-1 transition). */ - ridge_start = i; - - print2log(": RS %d,%d ", xlist[i], ylist[i]); - - /* If 1-to-0 transition not found ... */ - if(!find_transition(&i, 1, 0, xlist, ylist, num, bdata, iw, ih)){ - /* Then we are done looking for ridges. */ - free(xlist); - free(ylist); - - print2log("\n"); - - /* Return number of ridges counted to this point. */ - return(ridge_cnt); - } - /* Otherwise, we found a new ridge end transition, so store */ - /* its location (the location of the 0 in 1-to-0 transition). */ - ridge_end = i; - - print2log("; RE %d,%d ", xlist[i], ylist[i]); - - /* Conduct the validation, tracing the contour of the ridge */ - /* from the ridge ending point a specified number of steps */ - /* scanning for neighbors clockwise and counter-clockwise. */ - /* If the ridge starting point is encounted during the trace */ - /* then we can assume we do not have a valid ridge crossing */ - /* and instead we are walking on and off the edge of the */ - /* side of a ridge. */ - ret = validate_ridge_crossing(ridge_start, ridge_end, - xlist, ylist, num, bdata, iw, ih, - lfsparms->max_ridge_steps); - - /* If system error ... */ - if(ret < 0){ - free(xlist); - free(ylist); - /* Return the error code. */ - return(ret); - } - - print2log("; V%d ", ret); - - /* If validation result is TRUE ... */ - if(ret){ - /* Then assume we have found a valid ridge crossing and bump */ - /* the ridge counter. */ - ridge_cnt++; - } - - /* Otherwise, ignore the current ridge start and end transitions */ - /* and go back and search for new ridge start. */ - } - - /* Deallocate working memories. */ - free(xlist); - free(ylist); - - print2log("\n"); - - /* Return the number of ridges counted. */ - return(ridge_cnt); -} - -/************************************************************************* -************************************************************************** -#cat: count_minutia_ridges - Takes a minutia, and determines its closest -#cat: neighbors and counts the number of interveining ridges -#cat: between the minutia point and each of its neighbors. - - Input: - minutia - input minutia - bdata - binary image data (0==while & 1==black) - iw - width (in pixels) of image - ih - height (in pixels) of image - lfsparms - parameters and thresholds for controlling LFS - Output: - minutiae - minutia augmented with neighbors and ridge counts - Return Code: - Zero - successful completion - Negative - system error -**************************************************************************/ -static int count_minutia_ridges(const int first, MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const LFSPARMS *lfsparms) -{ - int i, ret, *nbr_list = NULL, *nbr_nridges, nnbrs; - - /* Find up to the maximum number of qualifying neighbors. */ - if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs, - first, minutiae))){ - free(nbr_list); - return(ret); - } - - print2log("NBRS FOUND: %d,%d = %d\n", minutiae->list[first]->x, - minutiae->list[first]->y, nnbrs); - - /* If no neighors found ... */ - if(nnbrs == 0){ - /* Then no list returned and no ridges to count. */ - return(0); - } - - /* Sort neighbors on delta dirs. */ - if((ret = sort_neighbors(nbr_list, nnbrs, first, minutiae))){ - free(nbr_list); - return(ret); - } - - /* Count ridges between first and neighbors. */ - /* List of ridge counts, one for each neighbor stored. */ - nbr_nridges = (int *)malloc(nnbrs * sizeof(int)); - if(nbr_nridges == (int *)NULL){ - free(nbr_list); - fprintf(stderr, "ERROR : count_minutia_ridges : malloc : nbr_nridges\n"); - return(-450); - } - - /* Foreach neighbor found and sorted in list ... */ - for(i = 0; i < nnbrs; i++){ - /* Count the ridges between the primary minutia and the neighbor. */ - ret = ridge_count(first, nbr_list[i], minutiae, bdata, iw, ih, lfsparms); - /* If system error ... */ - if(ret < 0){ - /* Deallocate working memories. */ - free(nbr_list); - free(nbr_nridges); - /* Return error code. */ - return(ret); - } - - /* Otherwise, ridge count successful, so store ridge count to list. */ - nbr_nridges[i] = ret; - } - - /* Assign neighbor indices and ridge counts to primary minutia. */ - minutiae->list[first]->nbrs = nbr_list; - minutiae->list[first]->ridge_counts = nbr_nridges; - minutiae->list[first]->num_nbrs = nnbrs; - - /* Return normally. */ - return(0); -} - -/************************************************************************* -************************************************************************** -#cat: count_minutiae_ridges - Takes a list of minutiae, and for each one, -#cat: determines its closest neighbors and counts the number -#cat: of interveining ridges between the minutia point and -#cat: each of its neighbors. - - Input: - minutiae - list of minutiae - bdata - binary image data (0==while & 1==black) - iw - width (in pixels) of image - ih - height (in pixels) of image - lfsparms - parameters and thresholds for controlling LFS - Output: - minutiae - list of minutiae augmented with neighbors and ridge counts - Return Code: - Zero - successful completion - Negative - system error -**************************************************************************/ -int count_minutiae_ridges(MINUTIAE *minutiae, - unsigned char *bdata, const int iw, const int ih, - const LFSPARMS *lfsparms) -{ - int ret; - int i; - - print2log("\nFINDING NBRS AND COUNTING RIDGES:\n"); - - /* Sort minutia points on x then y (column-oriented). */ - if((ret = sort_minutiae_x_y(minutiae, iw, ih))){ - return(ret); - } - - /* Remove any duplicate minutia points from the list. */ - if((ret = rm_dup_minutiae(minutiae))){ - return(ret); - } - - /* Foreach remaining sorted minutia in list ... */ - for(i = 0; i < minutiae->num-1; i++){ - /* Located neighbors and count number of ridges in between. */ - /* NOTE: neighbor and ridge count results are stored in */ - /* minutiae->list[i]. */ - if((ret = count_minutia_ridges(i, minutiae, bdata, iw, ih, lfsparms))){ - return(ret); - } - } - - /* Return normally. */ - return(0); -} - diff --git a/libfprint/nbis/mindtct/shape.c b/libfprint/nbis/mindtct/shape.c index 4e8ea8fd..f189a998 100644 --- a/libfprint/nbis/mindtct/shape.c +++ b/libfprint/nbis/mindtct/shape.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -36,12 +57,12 @@ identified are necessarily the best available for the purpose. ROUTINES: alloc_shape() free_shape() + dump_shape() shape_from_contour() sort_row_on_x() ***********************************************************************/ #include -#include #include /************************************************************************* @@ -60,7 +81,7 @@ identified are necessarily the best available for the purpose. Zero - Shape successfully allocated and initialized Negative - System error **************************************************************************/ -static int alloc_shape(SHAPE **oshape, const int xmin, const int ymin, +int alloc_shape(SHAPE **oshape, const int xmin, const int ymin, const int xmax, const int ymax) { SHAPE *shape; @@ -180,21 +201,14 @@ void free_shape(SHAPE *shape) /************************************************************************* ************************************************************************** -#cat: sort_row_on_x - Takes a row structure and sorts its points left-to- -#cat: right on X. +#cat: dump_shape - Takes an initialized shape structure and dumps its contents +#cat: as formatted text to the specified open file pointer. Input: - row - row structure to be sorted + shape - shape structure to be dumped Output: - row - row structure with points in sorted order + fpout - open file pointer to be written to **************************************************************************/ -static void sort_row_on_x(ROW *row) -{ - /* Conduct a simple increasing bubble sort on the x-coords */ - /* in the given row. A bubble sort is satisfactory as the */ - /* number of points will be relatively small. */ - bubble_sort_int_inc(row->xs, row->npts); -} /************************************************************************* ************************************************************************** @@ -270,3 +284,21 @@ int shape_from_contour(SHAPE **oshape, const int *contour_x, return(0); } +/************************************************************************* +************************************************************************** +#cat: sort_row_on_x - Takes a row structure and sorts its points left-to- +#cat: right on X. + + Input: + row - row structure to be sorted + Output: + row - row structure with points in sorted order +**************************************************************************/ +void sort_row_on_x(ROW *row) +{ + /* Conduct a simple increasing bubble sort on the x-coords */ + /* in the given row. A bubble sort is satisfactory as the */ + /* number of points will be relatively small. */ + bubble_sort_int_inc(row->xs, row->npts); +} + diff --git a/libfprint/nbis/mindtct/sort.c b/libfprint/nbis/mindtct/sort.c index 3a0f47c9..9080ce0d 100644 --- a/libfprint/nbis/mindtct/sort.c +++ b/libfprint/nbis/mindtct/sort.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -43,7 +64,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include /************************************************************************* @@ -104,29 +124,6 @@ int sort_indices_int_inc(int **optr, int *ranks, const int num) Zero - successful completion Negative - system error **************************************************************************/ -int sort_indices_double_inc(int **optr, double *ranks, const int num) -{ - int *order; - int i; - - /* Allocate list of sequential indices. */ - order = (int *)malloc(num * sizeof(int)); - if(order == (int *)NULL){ - fprintf(stderr, "ERROR : sort_indices_double_inc : malloc : order\n"); - return(-400); - } - /* Initialize list of sequential indices. */ - for(i = 0; i < num; i++) - order[i] = i; - - /* Sort the indicies into rank order. */ - bubble_sort_double_inc_2(ranks, order, num); - - /* Set output pointer to the resulting order of sorted indices. */ - *optr = order; - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -176,7 +173,7 @@ void bubble_sort_int_inc_2(int *ranks, int *items, const int len) } /* Decrement the ending index. */ n--; - } + } } /************************************************************************* @@ -228,7 +225,7 @@ void bubble_sort_double_inc_2(double *ranks, int *items, const int len) } /* Decrement the ending index. */ n--; - } + } } /*************************************************************************** @@ -271,7 +268,7 @@ void bubble_sort_double_dec_2(double *ranks, int *items, const int len) } } n--; - } + } } /************************************************************************* @@ -315,6 +312,6 @@ void bubble_sort_int_inc(int *ranks, const int len) } /* Decrement the ending index. */ n--; - } + } } diff --git a/libfprint/nbis/mindtct/util.c b/libfprint/nbis/mindtct/util.c index a4e98da9..1662e629 100644 --- a/libfprint/nbis/mindtct/util.c +++ b/libfprint/nbis/mindtct/util.c @@ -1,26 +1,47 @@ /******************************************************************************* -License: -This software was developed at the National Institute of Standards and -Technology (NIST) by employees of the Federal Government in the course -of their official duties. Pursuant to title 17 Section 105 of the -United States Code, this software is not subject to copyright protection -and is in the public domain. NIST assumes no responsibility whatsoever for -its use by other parties, and makes no guarantees, expressed or implied, -about its quality, reliability, or any other characteristic. +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. -Disclaimer: -This software was developed to promote biometric standards and biometric -technology testing for the Federal Government in accordance with the USA -PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act. -Specific hardware and software products identified in this software were used -in order to perform the software development. In no case does such -identification imply recommendation or endorsement by the National Institute -of Standards and Technology, nor does it imply that the products and equipment -identified are necessarily the best available for the purpose. +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. *******************************************************************************/ + /*********************************************************************** LIBRARY: LFS - NIST Latent Fingerprint System @@ -47,7 +68,6 @@ identified are necessarily the best available for the purpose. ***********************************************************************/ #include -#include #include /************************************************************************* @@ -142,7 +162,7 @@ int minmaxs(int **ominmax_val, int **ominmax_type, int **ominmax_i, int i, diff, state, start, loc; int *minmax_val, *minmax_type, *minmax_i, minmax_alloc, minmax_num; - + /* Determine maximum length for allocation of buffers. */ /* If there are fewer than 3 items ... */ if(num < 3){ @@ -427,27 +447,6 @@ int in_int_list(const int item, const int *list, const int len) Zero - successful completion Negative - system error **************************************************************************/ -int remove_from_int_list(const int index, int *list, const int num) -{ - int fr, to; - - /* Make sure the requested index is within range. */ - if((index < 0) && (index >= num)){ - fprintf(stderr, "ERROR : remove_from_int_list : index out of range\n"); - return(-370); - } - - /* Slide the remaining list of integers up over top of the */ - /* position of the integer being removed. */ - for(to = index, fr = index+1; fr < num; to++, fr++) - list[to] = list[fr]; - - /* NOTE: Decrementing the number of integers remaining in the list is */ - /* the responsibility of the caller! */ - - /* Return normally. */ - return(0); -} /************************************************************************* ************************************************************************** @@ -561,7 +560,7 @@ int line2direction(const int fx, const int fy, /* Make sure on range [0..(ndirsX2)]. */ idir %= full_ndirs; - /* Return the integer direction. */ + /* Return the integer direction. */ return(idir); } diff --git a/libfprint/nbis/mindtct/xytreps.c b/libfprint/nbis/mindtct/xytreps.c new file mode 100644 index 00000000..7310f98b --- /dev/null +++ b/libfprint/nbis/mindtct/xytreps.c @@ -0,0 +1,136 @@ +/******************************************************************************* + +License: +This software and/or related materials was developed at the National Institute +of Standards and Technology (NIST) by employees of the Federal Government +in the course of their official duties. Pursuant to title 17 Section 105 +of the United States Code, this software is not subject to copyright +protection and is in the public domain. + +This software and/or related materials have been determined to be not subject +to the EAR (see Part 734.3 of the EAR for exact details) because it is +a publicly available technology and software, and is freely distributed +to any interested party with no licensing requirements. Therefore, it is +permissible to distribute this software as a free download from the internet. + +Disclaimer: +This software and/or related materials was developed to promote biometric +standards and biometric technology testing for the Federal Government +in accordance with the USA PATRIOT Act and the Enhanced Border Security +and Visa Entry Reform Act. Specific hardware and software products identified +in this software were used in order to perform the software development. +In no case does such identification imply recommendation or endorsement +by the National Institute of Standards and Technology, nor does it imply that +the products and equipment identified are necessarily the best available +for the purpose. + +This software and/or related materials are provided "AS-IS" without warranty +of any kind including NO WARRANTY OF PERFORMANCE, MERCHANTABILITY, +NO WARRANTY OF NON-INFRINGEMENT OF ANY 3RD PARTY INTELLECTUAL PROPERTY +or FITNESS FOR A PARTICULAR PURPOSE or for any purpose whatsoever, for the +licensed product, however used. In no event shall NIST be liable for any +damages and/or costs, including but not limited to incidental or consequential +damages of any kind, including economic damage or injury to property and lost +profits, regardless of whether NIST shall be advised, have reason to know, +or in fact shall know of the possibility. + +By using this software, you agree to bear all risk relating to quality, +use and performance of the software and/or related materials. You agree +to hold the Government harmless from any claim arising from your use +of the software. + +*******************************************************************************/ + + +/*********************************************************************** + LIBRARY: LFS - NIST Latent Fingerprint System + + FILE: XYTREPS.C + AUTHOR: Michael D. Garris + DATE: 09/16/2004 + UPDATED: 01/11/2012 + + Contains routines useful in converting minutiae in LFS "native" + representation into other representations, such as + M1 (ANSI INCITS 378-2004) & NIST internal representations. + +*********************************************************************** + ROUTINES: + lfs2nist_minutia_XTY() + lfs2m1_minutia_XTY() + lfs2nist_format() + +***********************************************************************/ + +#include +#include + +/************************************************************************* +************************************************************************** +#cat: lfs2nist_minutia_XYT - Converts XYT minutiae attributes in LFS native +#cat: representation to NIST internal representation + + Input: + minutia - LFS minutia structure containing attributes to be converted + Output: + ox - NIST internal based x-pixel coordinate + oy - NIST internal based y-pixel coordinate + ot - NIST internal based minutia direction/orientation +**************************************************************************/ +void lfs2nist_minutia_XYT(int *ox, int *oy, int *ot, + const MINUTIA *minutia, const int iw, const int ih) +{ + int x, y, t; + float degrees_per_unit; + + /* XYT's according to NIST internal rep: */ + /* 1. pixel coordinates with origin bottom-left */ + /* 2. orientation in degrees on range [0..360] */ + /* with 0 pointing east and increasing counter */ + /* clockwise (same as M1) */ + /* 3. direction pointing out and away from the */ + /* ridge ending or bifurcation valley */ + /* (opposite direction from M1) */ + + x = minutia->x; + y = ih - minutia->y; + + degrees_per_unit = 180 / (float)NUM_DIRECTIONS; + + t = (270 - sround(minutia->direction * degrees_per_unit)) % 360; + if(t < 0){ + t += 360; + } + + *ox = x; + *oy = y; + *ot = t; +} + +/************************************************************************* +************************************************************************** +#cat: lfs2m1_minutia_XYT - Converts XYT minutiae attributes in LFS native +#cat: representation to M1 (ANSI INCITS 378-2004) representation + + Input: + minutia - LFS minutia structure containing attributes to be converted + Output: + ox - M1 based x-pixel coordinate + oy - M1 based y-pixel coordinate + ot - M1 based minutia direction/orientation +**************************************************************************/ + +/************************************************************************* +************************************************************************** +#cat: lfs2nist_format - Takes a minutiae data structure and converts +#cat: the XYT minutiae attributes in LFS native +#cat: representation to NIST internal representation + Input: + iminutiae - minutiae data structure + iw - width (in pixels) of the grayscale image + ih - height (in pixels) of the grayscale image + Output: + iminutiae - overwrite each minutia element in the minutiae data + sturcture convernt to nist internal minutiae format +**************************************************************************/ + From 0cd37b0142c6642c90275ca31c566e03edd5e5bc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 27 Aug 2018 13:29:03 +0200 Subject: [PATCH 026/225] block: Remove unused variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mindtct/block.c: In function ‘block_offsets’: mindtct/block.c:108:18: warning: variable ‘ph’ set but not used [-Wunused-but-set-variable] int pad2, pw, ph; ^~ --- libfprint/nbis/mindtct/block.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libfprint/nbis/mindtct/block.c b/libfprint/nbis/mindtct/block.c index 761f332d..f530f94d 100644 --- a/libfprint/nbis/mindtct/block.c +++ b/libfprint/nbis/mindtct/block.c @@ -105,7 +105,7 @@ int block_offsets(int **optr, int *ow, int *oh, int *blkoffs, bx, by, bw, bh, bi, bsize; int blkrow_start, blkrow_size, offset; int lastbw, lastbh; - int pad2, pw, ph; + int pad2, pw; /* Test if unpadded image is smaller than a single block */ if((iw < blocksize) || (ih < blocksize)){ @@ -115,10 +115,9 @@ int block_offsets(int **optr, int *ow, int *oh, return(-80); } - /* Compute padded width and height of image */ + /* Compute padded width of image */ pad2 = pad<<1; pw = iw + pad2; - ph = ih + pad2; /* Compute the number of columns and rows of blocks in the image. */ /* Take the ceiling to account for "leftovers" at the right and */ From 688a133f3f1ac33741aa3aad12da78a7b6ffa560 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 27 Aug 2018 13:48:57 +0200 Subject: [PATCH 027/225] morph: Fix misleading indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mindtct/morph.c: In function ‘get_south8_2’: mindtct/morph.c:173:4: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] if (row >= ih-1) /* catch case where image is undefined southwards */ ^~ mindtct/morph.c:176:7: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ return *(ptr+iw); ^~~~~~ mindtct/morph.c: In function ‘get_north8_2’: mindtct/morph.c:197:4: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] if (row < 1) /* catch case where image is undefined northwards */ ^~ mindtct/morph.c:200:7: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ return *(ptr-iw); ^~~~~~ mindtct/morph.c: In function ‘get_east8_2’: mindtct/morph.c:221:4: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] if (col >= iw-1) /* catch case where image is undefined eastwards */ ^~ mindtct/morph.c:224:7: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ return *(ptr+ 1); ^~~~~~ mindtct/morph.c: In function ‘get_west8_2’: mindtct/morph.c:243:4: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] if (col < 1) /* catch case where image is undefined westwards */ ^~ mindtct/morph.c:246:7: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ return *(ptr- 1); ^~~~~~ --- libfprint/nbis/mindtct/morph.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libfprint/nbis/mindtct/morph.c b/libfprint/nbis/mindtct/morph.c index 41978f1e..1399b0d8 100644 --- a/libfprint/nbis/mindtct/morph.c +++ b/libfprint/nbis/mindtct/morph.c @@ -173,7 +173,7 @@ char get_south8_2(char *ptr, const int row, const int iw, const int ih, if (row >= ih-1) /* catch case where image is undefined southwards */ return failcode; /* use plane geometry and return code. */ - return *(ptr+iw); + return *(ptr+iw); } /************************************************************************* @@ -197,7 +197,7 @@ char get_north8_2(char *ptr, const int row, const int iw, if (row < 1) /* catch case where image is undefined northwards */ return failcode; /* use plane geometry and return code. */ - return *(ptr-iw); + return *(ptr-iw); } /************************************************************************* @@ -221,7 +221,7 @@ char get_east8_2(char *ptr, const int col, const int iw, if (col >= iw-1) /* catch case where image is undefined eastwards */ return failcode; /* use plane geometry and return code. */ - return *(ptr+ 1); + return *(ptr+ 1); } /************************************************************************* @@ -243,5 +243,5 @@ char get_west8_2(char *ptr, const int col, const int failcode) if (col < 1) /* catch case where image is undefined westwards */ return failcode; /* use plane geometry and return code. */ - return *(ptr- 1); + return *(ptr- 1); } From 489afea6055ed05c5f28b345d515bbcc9eb996fa Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 27 Aug 2018 17:59:30 +0200 Subject: [PATCH 028/225] lib: Remove unused fpi_dev_get_dev_state() This internal-only function was never used. --- libfprint/core.c | 6 ------ libfprint/drivers_api.h | 1 - 2 files changed, 7 deletions(-) diff --git a/libfprint/core.c b/libfprint/core.c index 2c42ad51..f035c8c6 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -566,12 +566,6 @@ 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: * @drv: the driver diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index cc844cd7..d3e3c96d 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -84,7 +84,6 @@ void fpi_dev_set_user_data (struct fp_dev *dev, void *user_data); 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); 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); enum fp_imgdev_state { IMGDEV_STATE_INACTIVE, From 528f3556eaf5a7d4df6eb43ad0e79e8f04083fea Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 27 Aug 2018 18:01:45 +0200 Subject: [PATCH 029/225] vfs301: Use vfs301_proto_deinit() Even though it does nothing, make sure to use it so it's useful once it does something. --- libfprint/drivers/vfs301.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index a34ee31c..45be8b36 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -216,6 +216,10 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) /* Deactivate device */ static void dev_deactivate(struct fp_img_dev *dev) { + vfs301_dev_t *vdev; + + vdev = fpi_imgdev_get_user_data(dev); + vfs301_proto_deinit(fpi_imgdev_get_usb_dev(dev), vdev); fpi_imgdev_deactivate_complete(dev); } From 821cbae1878d9754ea0779fe13da873c09875d9f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 27 Aug 2018 13:54:29 +0200 Subject: [PATCH 030/225] loop: Remove unused variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mindtct/loop.c: In function ‘process_loop_V2’: mindtct/loop.c:713:8: warning: variable ‘halfway’ set but not used [-Wunused-but-set-variable] int halfway; ^~~~~~~ --- libfprint/nbis/mindtct/loop.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libfprint/nbis/mindtct/loop.c b/libfprint/nbis/mindtct/loop.c index 847c43f7..2142d181 100644 --- a/libfprint/nbis/mindtct/loop.c +++ b/libfprint/nbis/mindtct/loop.c @@ -509,7 +509,6 @@ int process_loop_V2(MINUTIAE *minutiae, unsigned char *bdata, const int iw, const int ih, int *plow_flow_map, const LFSPARMS *lfsparms) { - int halfway; int idir, type, appearing; double min_dist, max_dist; int min_fr, max_fr, min_to, max_to; @@ -529,9 +528,6 @@ int process_loop_V2(MINUTIAE *minutiae, /* Get pixel value of feature's interior. */ feature_pix = *(bdata + (contour_y[0] * iw) + contour_x[0]); - /* Compute half the perimeter of the loop. */ - halfway = ncontour>>1; - /* Get the aspect dimensions of the loop in units of */ /* squared distance. */ get_loop_aspect(&min_fr, &min_to, &min_dist, From 350b0a38e23436daeb26bf0833ccdaa7069d35bc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 14:03:02 +0200 Subject: [PATCH 031/225] drivers: De-duplicate udf_crc() helper Was in both the upektc_img and upekts drivers --- libfprint/drivers/upek_proto.c | 66 ++++++++++++++++++++++++++++++++++ libfprint/drivers/upek_proto.h | 24 +++++++++++++ libfprint/drivers/upektc_img.c | 45 +---------------------- libfprint/drivers/upekts.c | 43 +--------------------- libfprint/meson.build | 4 +-- 5 files changed, 94 insertions(+), 88 deletions(-) create mode 100644 libfprint/drivers/upek_proto.c create mode 100644 libfprint/drivers/upek_proto.h diff --git a/libfprint/drivers/upek_proto.c b/libfprint/drivers/upek_proto.c new file mode 100644 index 00000000..0ecc4b13 --- /dev/null +++ b/libfprint/drivers/upek_proto.c @@ -0,0 +1,66 @@ +/* + * LGPL CRC code copied from GStreamer-0.10.10: + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) 2004,2006 Thomas Vander Stichele + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version + * 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "upek_proto.h" + +static const uint16_t crc_table[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +uint16_t +udf_crc(unsigned char *buffer, size_t size) +{ + uint16_t crc = 0; + while (size--) + crc = (uint16_t) ((crc << 8) ^ + crc_table[((crc >> 8) & 0x00ff) ^ *buffer++]); + return crc; +} diff --git a/libfprint/drivers/upek_proto.h b/libfprint/drivers/upek_proto.h new file mode 100644 index 00000000..2c3a617d --- /dev/null +++ b/libfprint/drivers/upek_proto.h @@ -0,0 +1,24 @@ +/* + * LGPL CRC code copied from GStreamer-0.10.10: + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) 2004,2006 Thomas Vander Stichele + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version + * 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +uint16_t udf_crc(unsigned char *buffer, size_t size); diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index f0f2f18c..814707d0 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -20,6 +20,7 @@ #define FP_COMPONENT "upektc_img" #include "drivers_api.h" +#include "upek_proto.h" #include "aeslib.h" #include "upektc_img.h" @@ -51,50 +52,6 @@ struct upektc_img_dev { /****** HELPERS ******/ -static const uint16_t crc_table[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 -}; - -static uint16_t udf_crc(unsigned char *buffer, size_t size) -{ - uint16_t crc = 0; - while (size--) - crc = (uint16_t) ((crc << 8) ^ - crc_table[((crc >> 8) & 0x00ff) ^ *buffer++]); - return crc; -} - static void upektc_img_cmd_fix_seq(unsigned char *cmd_buf, unsigned char seq) { uint8_t byte; diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index b448e364..0858959e 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -28,6 +28,7 @@ #define FP_COMPONENT "upekts" #include "drivers_api.h" +#include "upek_proto.h" #define EP_IN (1 | LIBUSB_ENDPOINT_IN) #define EP_OUT (2 | LIBUSB_ENDPOINT_OUT) @@ -43,49 +44,7 @@ struct upekts_dev { uint8_t seq; /* FIXME: improve/automate seq handling */ }; -static const uint16_t crc_table[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 -}; -static uint16_t udf_crc(unsigned char *buffer, size_t size) -{ - uint16_t crc = 0; - while (size--) - crc = (uint16_t) ((crc << 8) ^ - crc_table[((crc >> 8) & 0x00ff) ^ *buffer++]); - return crc; -} /* * MESSAGE FORMAT diff --git a/libfprint/meson.build b/libfprint/meson.build index fea424f8..c97dcf86 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -66,7 +66,7 @@ foreach driver: drivers drivers_sources += [ 'drivers/upekts.c' ] endif if driver == 'upektc' - drivers_sources += [ 'drivers/upektc.c', 'drivers/upektc.h' ] + drivers_sources += [ 'drivers/upektc.c', 'drivers/upektc.h', 'drivers/upek_proto.c', 'drivers/upek_proto.h' ] endif if driver == 'upeksonly' drivers_sources += [ 'drivers/upeksonly.c', 'drivers/upeksonly.h' ] @@ -122,7 +122,7 @@ foreach driver: drivers drivers_sources += [ 'drivers/vfs5011.c', 'drivers/vfs5011_proto.h' ] endif if driver == 'upektc_img' - drivers_sources += [ 'drivers/upektc_img.c', 'drivers/upektc_img.h' ] + drivers_sources += [ 'drivers/upektc_img.c', 'drivers/upektc_img.h', 'drivers/upek_proto.c', 'drivers/upek_proto.h' ] endif if driver == 'etes603' drivers_sources += [ 'drivers/etes603.c' ] From fb192f706cb6c0b16c8c568fcf88e7c046327da0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 14:45:49 +0200 Subject: [PATCH 032/225] lib: Remove unused fp_dev_state from drivers API --- libfprint/drivers_api.h | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index d3e3c96d..ad73f506 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -53,30 +53,6 @@ } G_STMT_END #define BUG() BUG_ON(1) -enum fp_dev_state { - DEV_STATE_INITIAL = 0, - DEV_STATE_ERROR, - DEV_STATE_INITIALIZING, - DEV_STATE_INITIALIZED, - DEV_STATE_DEINITIALIZING, - DEV_STATE_DEINITIALIZED, - DEV_STATE_ENROLL_STARTING, - DEV_STATE_ENROLLING, - DEV_STATE_ENROLL_STOPPING, - DEV_STATE_VERIFY_STARTING, - DEV_STATE_VERIFYING, - DEV_STATE_VERIFY_DONE, - DEV_STATE_VERIFY_STOPPING, - DEV_STATE_IDENTIFY_STARTING, - DEV_STATE_IDENTIFYING, - DEV_STATE_IDENTIFY_DONE, - DEV_STATE_IDENTIFY_STOPPING, - DEV_STATE_CAPTURE_STARTING, - DEV_STATE_CAPTURING, - DEV_STATE_CAPTURE_DONE, - DEV_STATE_CAPTURE_STOPPING, -}; - struct fp_dev; libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); void *fpi_dev_get_user_data (struct fp_dev *dev); From daed05755acdced0ded7f99b99bc4294b4e8edbd Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 14:46:25 +0200 Subject: [PATCH 033/225] lib: Remove unused fp_imgdev_verify_state from drivers API --- libfprint/drivers_api.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index ad73f506..2aba675d 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -86,11 +86,6 @@ enum fp_imgdev_enroll_state { IMG_ACQUIRE_STATE_DEACTIVATING, }; -enum fp_imgdev_verify_state { - IMG_VERIFY_STATE_NONE = 0, - IMG_VERIFY_STATE_ACTIVATING -}; - struct fp_img_dev; libusb_device_handle *fpi_imgdev_get_usb_dev(struct fp_img_dev *dev); void fpi_imgdev_set_user_data(struct fp_img_dev *imgdev, From b4819701b42940edc811c6ac31c06601dec29460 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 15:42:57 +0200 Subject: [PATCH 034/225] doc: Fix warning about fp_print_data It was listed twice in the sections declaration. --- doc/libfprint-sections.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 77cb0c38..e3d1bb8d 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -94,7 +94,6 @@ fp_async_capture_stop print_data fp_finger fp_print_data -fp_print_data fp_print_data_get_data fp_print_data_from_data fp_print_data_save From 065c0b6202440d0aca75552b656a79ef3d434e05 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 15:44:26 +0200 Subject: [PATCH 035/225] fdu2000: This comment is not API docs So format it in a way that gtk-doc doesn't think it's API docs. --- libfprint/drivers/fdu2000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/drivers/fdu2000.c b/libfprint/drivers/fdu2000.c index bdd2983d..87d78549 100644 --- a/libfprint/drivers/fdu2000.c +++ b/libfprint/drivers/fdu2000.c @@ -215,7 +215,7 @@ read: p += sizeof SOL + 4; int j; for (j = 0; j < RAW_IMAGE_WIDTH; j++) { - /** + /* * Convert from 4 to 8 bits * The SECUGEN-FDU2000 has 4 lines of data, so we need to join 2 bytes into 1 */ From bb27ca5720cb46badb0a32e0848b67079bd724b8 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 15:45:18 +0200 Subject: [PATCH 036/225] lib: Work-around gtk-doc's handling of the short type gtk-doc thinks "short" is only a modifier, not a type of its own (short == short int). This work-around does not change the ABI. See https://gitlab.gnome.org/GNOME/gtk-doc/issues/44 --- libfprint/fprint.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libfprint/fprint.h b/libfprint/fprint.h index be94a540..7ec48cf1 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -304,12 +304,12 @@ void fp_img_free(struct fp_img *img); * @fd: a file descriptor * @events: Event flags to poll for from `` * - * A structure representing a file descriptor and the events to poll + * A structure representing a file descriptor and the @events to poll * for, as returned by fp_get_pollfds(). */ struct fp_pollfd { int fd; - short events; + short int events; }; int fp_handle_events_timeout(struct timeval *timeout); @@ -326,7 +326,7 @@ int fp_get_next_timeout(struct timeval *tv); * event source is added. The @events argument is a flag as defined in * `` such as `POLLIN`, or `POLLOUT`. See fp_set_pollfd_notifiers(). */ -typedef void (*fp_pollfd_added_cb)(int fd, short events); +typedef void (*fp_pollfd_added_cb)(int fd, short int events); /** * fp_pollfd_removed_cb: From d3a1b86ea40e1c16bb6670771249dd0445a0e7ee Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 15:56:32 +0200 Subject: [PATCH 037/225] doc: Fix warnings about user_data Such as: warning: Parameter description for *::user_data is missing in source code comment block. --- libfprint/async.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/async.c b/libfprint/async.c index 7051ee70..aba78b7b 100644 --- a/libfprint/async.c +++ b/libfprint/async.c @@ -40,7 +40,7 @@ void fpi_drvcb_open_complete(struct fp_dev *dev, int status) * fp_async_dev_open: * @ddev: * @callback: - * @user_data + * @user_data: * * Returns: */ @@ -103,7 +103,7 @@ void fpi_drvcb_close_complete(struct fp_dev *dev) * fp_async_dev_close: * @dev: * @callback: - * @user_data + * @user_data: */ API_EXPORTED void fp_async_dev_close(struct fp_dev *dev, fp_operation_stop_cb callback, void *user_data) From 1d453b5732f52933450c7192860d97e40cf68655 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 15:57:46 +0200 Subject: [PATCH 038/225] doc: Fix warning about fp_capture_result The enum values need to be documented before the enum itself, otherwise this warning is thrown: warning: Value descriptions for fp_capture_result are missing in source code comment block. --- libfprint/fprint.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 7ec48cf1..26248cc3 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -163,11 +163,10 @@ int fp_dev_supports_dscv_print(struct fp_dev *dev, struct fp_dscv_print *print) /** * fp_capture_result: - * Whether a capture failed or completed. - * * @FP_CAPTURE_COMPLETE: Capture completed successfully, the capture data has been returned to the caller. * @FP_CAPTURE_FAIL: Capture failed * + * Whether a capture failed or completed. */ enum fp_capture_result { FP_CAPTURE_COMPLETE = 0, From 6345835b02aa79eca642b1cf16110c74695d9303 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Sep 2018 15:58:23 +0200 Subject: [PATCH 039/225] doc: %NULL changes --- libfprint/core.c | 2 +- libfprint/img.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/core.c b/libfprint/core.c index f035c8c6..1cb82cca 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -248,7 +248,7 @@ static struct fp_dscv_dev *discover_dev(libusb_device *udev) * Scans the system and returns a list of discovered devices. This is your * entry point into finding a fingerprint reader to operate. * - * Returns: a %NULL-terminated list of discovered devices. Must be freed with + * Returns: a nul-terminated list of discovered devices. Must be freed with * fp_dscv_devs_free() after use. */ API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void) diff --git a/libfprint/img.c b/libfprint/img.c index b0cf9768..90f4cd4a 100644 --- a/libfprint/img.c +++ b/libfprint/img.c @@ -87,7 +87,7 @@ struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize) /** * fp_img_free: - * @img: the image to destroy. If NULL, function simply returns. + * @img: the image to destroy. If %NULL, function simply returns. * * Frees an image. Must be called when you are finished working with an image. */ From cafa05dab5b6f724d4cc830980b828015f57e991 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 13:21:43 +0200 Subject: [PATCH 040/225] doc: Add include to each section rather than globally So that we can document internal driver APIs and mention the correct include. --- doc/libfprint-sections.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index e3d1bb8d..a4294953 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -1,6 +1,6 @@ -fprint.h
+fprint.h events Initialisation and events handling fp_set_debug @@ -17,6 +17,7 @@ fp_set_pollfd_notifiers
+fprint.h discovery Device discovery fp_dscv_dev @@ -32,6 +33,7 @@ fp_dscv_dev_for_dscv_print
+fprint.h drv fp_driver fp_driver_get_name @@ -41,6 +43,7 @@ fp_driver_get_scan_type
+fprint.h dev fp_dev fp_scan_type @@ -91,6 +94,7 @@ fp_async_capture_stop
+fprint.h print_data fp_finger fp_print_data @@ -106,6 +110,7 @@ fp_print_data_get_devtype
+fprint.h dscv_print fp_dscv_print fp_discover_prints @@ -117,6 +122,7 @@ fp_dscv_print_delete
+fprint.h img fp_img fp_minutia @@ -131,5 +137,6 @@ fp_img_get_minutiae
+fprint.h poll
From 5ae2ef540776646e035a7d9fe3512a08c4aa8916 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 12:39:16 +0200 Subject: [PATCH 041/225] lib: Split off fpi_ssm functions Rename drv.c to something more fitting to its contents, and move state machine code to its own header. --- libfprint/drivers_api.h | 30 +---------------- libfprint/fp_internal.h | 34 ------------------- libfprint/{drv.c => fpi-ssm.c} | 16 +++++++++ libfprint/fpi-ssm.h | 60 ++++++++++++++++++++++++++++++++++ libfprint/meson.build | 3 +- 5 files changed, 79 insertions(+), 64 deletions(-) rename libfprint/{drv.c => fpi-ssm.c} (93%) create mode 100644 libfprint/fpi-ssm.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 2aba675d..02fe43ca 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -36,6 +36,7 @@ #include #include "fprint.h" +#include "fpi-ssm.h" #include "assembling.h" #include "drivers/driver_ids.h" @@ -211,35 +212,6 @@ struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data); void fpi_timeout_cancel(struct fpi_timeout *timeout); -/* async drv <--> lib comms */ - -struct fpi_ssm; -typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm); -typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm); - -/* sequential state machine: state machine that iterates sequentially over - * a predefined series of states. can be aborted by either completion or - * abortion error conditions. */ - -/* for library and drivers */ -struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, - int nr_states); -void fpi_ssm_free(struct fpi_ssm *machine); -void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback); -void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child); - -/* for drivers */ -void fpi_ssm_next_state(struct fpi_ssm *machine); -void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state); -void fpi_ssm_mark_completed(struct fpi_ssm *machine); -void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error); -struct fp_dev *fpi_ssm_get_dev(struct fpi_ssm *machine); -void fpi_ssm_set_user_data(struct fpi_ssm *machine, - void *user_data); -void *fpi_ssm_get_user_data(struct fpi_ssm *machine); -int fpi_ssm_get_error(struct fpi_ssm *machine); -int fpi_ssm_get_cur_state(struct fpi_ssm *machine); - void fpi_drvcb_open_complete(struct fp_dev *dev, int status); void fpi_drvcb_close_complete(struct fp_dev *dev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index e7501824..48a25182 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -348,40 +348,6 @@ void fpi_poll_exit(void); typedef void (*fpi_timeout_fn)(void *data); -/* async drv <--> lib comms */ - -struct fpi_ssm; -typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm); -typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm); - -/* sequential state machine: state machine that iterates sequentially over - * a predefined series of states. can be aborted by either completion or - * abortion error conditions. */ -struct fpi_ssm { - struct fp_dev *dev; - struct fpi_ssm *parentsm; - void *priv; - int nr_states; - int cur_state; - gboolean completed; - int error; - ssm_completed_fn callback; - ssm_handler_fn handler; -}; - - -/* for library and drivers */ -struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, - int nr_states); -void fpi_ssm_free(struct fpi_ssm *machine); -void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback); - -/* for drivers */ -void fpi_ssm_next_state(struct fpi_ssm *machine); -void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state); -void fpi_ssm_mark_completed(struct fpi_ssm *machine); -void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error); - void fpi_drvcb_open_complete(struct fp_dev *dev, int status); void fpi_drvcb_close_complete(struct fp_dev *dev); diff --git a/libfprint/drv.c b/libfprint/fpi-ssm.c similarity index 93% rename from libfprint/drv.c rename to libfprint/fpi-ssm.c index d5507453..03aaf6e5 100644 --- a/libfprint/drv.c +++ b/libfprint/fpi-ssm.c @@ -20,6 +20,7 @@ #define FP_COMPONENT "drv" #include "fp_internal.h" +#include "fpi-ssm.h" #include #include @@ -68,6 +69,21 @@ * successful completion. */ +/* sequential state machine: state machine that iterates sequentially over + * a predefined series of states. can be aborted by either completion or + * abortion error conditions. */ +struct fpi_ssm { + struct fp_dev *dev; + struct fpi_ssm *parentsm; + void *priv; + int nr_states; + int cur_state; + gboolean completed; + int error; + ssm_completed_fn callback; + ssm_handler_fn handler; +}; + /* Allocate a new ssm */ struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, int nr_states) diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h new file mode 100644 index 00000000..ddb41953 --- /dev/null +++ b/libfprint/fpi-ssm.h @@ -0,0 +1,60 @@ +/* + * Driver API definitions + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_SSM_H__ +#define __FPI_SSM_H__ + +#include +#include +#include +#include +#include +#include + +/* async drv <--> lib comms */ + +struct fpi_ssm; +typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm); +typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm); + +/* sequential state machine: state machine that iterates sequentially over + * a predefined series of states. can be aborted by either completion or + * abortion error conditions. */ + +/* for library and drivers */ +struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, + int nr_states); +void fpi_ssm_free(struct fpi_ssm *machine); +void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback); +void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child); + +/* for drivers */ +void fpi_ssm_next_state(struct fpi_ssm *machine); +void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state); +void fpi_ssm_mark_completed(struct fpi_ssm *machine); +void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error); +struct fp_dev *fpi_ssm_get_dev(struct fpi_ssm *machine); +void fpi_ssm_set_user_data(struct fpi_ssm *machine, + void *user_data); +void *fpi_ssm_get_user_data(struct fpi_ssm *machine); +int fpi_ssm_get_error(struct fpi_ssm *machine); +int fpi_ssm_get_cur_state(struct fpi_ssm *machine); + +#endif diff --git a/libfprint/meson.build b/libfprint/meson.build index c97dcf86..0a9ed021 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -4,7 +4,8 @@ libfprint_sources = [ 'async.c', 'core.c', 'data.c', - 'drv.c', + 'fpi-ssm.c', + 'fpi-ssm.h', 'img.c', 'imgdev.c', 'poll.c', From 48b9e6c5175b9006b5a73514c32b9958ef91d9b5 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 13:11:37 +0200 Subject: [PATCH 042/225] lib: Typedef fpi_ssm --- libfprint/drivers/aes1610.c | 20 ++++----- libfprint/drivers/aes2501.c | 24 +++++------ libfprint/drivers/aes2550.c | 26 ++++++------ libfprint/drivers/aesx660.c | 42 +++++++++---------- libfprint/drivers/elan.c | 34 +++++++-------- libfprint/drivers/elan.h | 4 +- libfprint/drivers/etes603.c | 38 ++++++++--------- libfprint/drivers/upeksonly.c | 58 +++++++++++++------------- libfprint/drivers/upektc.c | 22 +++++----- libfprint/drivers/upektc_img.c | 36 ++++++++-------- libfprint/drivers/upekts.c | 76 +++++++++++++++++----------------- libfprint/drivers/uru4000.c | 50 +++++++++++----------- libfprint/drivers/vcom5s.c | 22 +++++----- libfprint/drivers/vfs0050.c | 44 ++++++++++---------- libfprint/drivers/vfs101.c | 50 +++++++++++----------- libfprint/drivers/vfs301.c | 18 ++++---- libfprint/drivers/vfs5011.c | 30 +++++++------- libfprint/fpi-ssm.c | 36 ++++++++-------- libfprint/fpi-ssm.h | 32 +++++++------- 19 files changed, 331 insertions(+), 331 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index f307a3bc..46d75c5c 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -101,7 +101,7 @@ static void stub_capture_stop_cb(struct fp_img_dev *dev, int result, void *user_ /* check that read succeeded but ignore all data */ static void generic_ignore_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); @@ -117,7 +117,7 @@ static void generic_ignore_data_cb(struct libusb_transfer *transfer) static void generic_write_regv_cb(struct fp_img_dev *dev, int result, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; if (result == 0) fpi_ssm_next_state(ssm); else @@ -126,7 +126,7 @@ static void generic_write_regv_cb(struct fp_img_dev *dev, int result, /* 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) +static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; @@ -557,7 +557,7 @@ enum capture_states { static void capture_read_strip_cb(struct libusb_transfer *transfer) { unsigned char *stripdata; - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); unsigned char *data = transfer->buffer; @@ -643,7 +643,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -690,7 +690,7 @@ static void capture_run_state(struct fpi_ssm *ssm) }; } -static void capture_sm_complete(struct fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -708,7 +708,7 @@ static void capture_sm_complete(struct fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; if (aesdev->deactivating) { complete_deactivation(dev); @@ -738,7 +738,7 @@ enum activate_states { ACTIVATE_NUM_STATES, }; -static void activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -753,7 +753,7 @@ static void activate_run_state(struct fpi_ssm *ssm) } /* jump to finger detection */ -static void activate_sm_complete(struct fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); @@ -767,7 +767,7 @@ static void activate_sm_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); aesdev->read_regs_retry_count = 0; diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index 87879a46..e736a9e2 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -180,7 +180,7 @@ static int regval_from_dump(unsigned char *data, uint8_t target) static void generic_write_regv_cb(struct fp_img_dev *dev, int result, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; if (result == 0) fpi_ssm_next_state(ssm); else @@ -190,7 +190,7 @@ 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(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); @@ -205,7 +205,7 @@ static void generic_ignore_data_cb(struct libusb_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) +static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; @@ -436,7 +436,7 @@ enum capture_states { static void capture_read_strip_cb(struct libusb_transfer *transfer) { unsigned char *stripdata; - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); unsigned char *data = transfer->buffer; @@ -520,7 +520,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -571,7 +571,7 @@ static void capture_run_state(struct fpi_ssm *ssm) }; } -static void capture_sm_complete(struct fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -589,7 +589,7 @@ static void capture_sm_complete(struct fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; if (aesdev->deactivating) { complete_deactivation(dev); @@ -713,7 +713,7 @@ enum activate_states { void activate_read_regs_cb(struct fp_img_dev *dev, int status, unsigned char *regs, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); if (status != 0) { @@ -730,14 +730,14 @@ void activate_read_regs_cb(struct fp_img_dev *dev, int status, static void activate_init3_cb(struct fp_img_dev *dev, int result, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; if (result == 0) fpi_ssm_jump_to_state(ssm, READ_REGS); else fpi_ssm_mark_aborted(ssm, result); } -static void activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -791,7 +791,7 @@ static void activate_run_state(struct fpi_ssm *ssm) } } -static void activate_sm_complete(struct fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); @@ -805,7 +805,7 @@ static void activate_sm_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); aesdev->read_regs_retry_count = 0; diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index ab4acaab..0fc9eb92 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -200,7 +200,7 @@ enum capture_states { }; /* Returns number of processed bytes */ -static int process_strip_data(struct fpi_ssm *ssm, unsigned char *data) +static int process_strip_data(fpi_ssm *ssm, unsigned char *data) { unsigned char *stripdata; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -231,7 +231,7 @@ static int process_strip_data(struct fpi_ssm *ssm, unsigned char *data) static void capture_reqs_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -244,7 +244,7 @@ static void capture_reqs_cb(struct libusb_transfer *transfer) static void capture_set_idle_reqs_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -272,7 +272,7 @@ static void capture_set_idle_reqs_cb(struct libusb_transfer *transfer) static void capture_read_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); unsigned char *data = transfer->buffer; @@ -323,7 +323,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r; @@ -386,7 +386,7 @@ static void capture_run_state(struct fpi_ssm *ssm) }; } -static void capture_sm_complete(struct fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -404,7 +404,7 @@ static void capture_sm_complete(struct fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; if (aesdev->deactivating) { complete_deactivation(dev); @@ -444,7 +444,7 @@ enum activate_states { static void init_reqs_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -457,7 +457,7 @@ static void init_reqs_cb(struct libusb_transfer *transfer) static void init_read_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); @@ -472,7 +472,7 @@ static void init_read_data_cb(struct libusb_transfer *transfer) * need more info for implementaion */ static void calibrate_read_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); @@ -483,7 +483,7 @@ static void calibrate_read_data_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r; @@ -568,7 +568,7 @@ static void activate_run_state(struct fpi_ssm *ssm) } } -static void activate_sm_complete(struct fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); @@ -581,7 +581,7 @@ static void activate_sm_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_sm_complete); diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index e443e219..bb9709d2 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -37,7 +37,7 @@ static void complete_deactivation(struct fp_img_dev *dev); #define min(a, b) (((a) < (b)) ? (a) : (b)) -static void aesX660_send_cmd_timeout(struct fpi_ssm *ssm, const unsigned char *cmd, +static void aesX660_send_cmd_timeout(fpi_ssm *ssm, const unsigned char *cmd, size_t cmd_len, libusb_transfer_cb_fn callback, int timeout) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -60,13 +60,13 @@ static void aesX660_send_cmd_timeout(struct fpi_ssm *ssm, const unsigned char *c } } -static void aesX660_send_cmd(struct fpi_ssm *ssm, const unsigned char *cmd, +static void aesX660_send_cmd(fpi_ssm *ssm, const unsigned char *cmd, size_t cmd_len, libusb_transfer_cb_fn callback) { return aesX660_send_cmd_timeout(ssm, cmd, cmd_len, callback, BULK_TIMEOUT); } -static void aesX660_read_response(struct fpi_ssm *ssm, size_t buf_len, +static void aesX660_read_response(fpi_ssm *ssm, size_t buf_len, libusb_transfer_cb_fn callback) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -95,7 +95,7 @@ static void aesX660_read_response(struct fpi_ssm *ssm, size_t buf_len, static void aesX660_send_cmd_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -110,7 +110,7 @@ static void aesX660_send_cmd_cb(struct libusb_transfer *transfer) static void aesX660_read_calibrate_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; unsigned char *data = transfer->buffer; if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || @@ -143,7 +143,7 @@ enum finger_det_states { static void finger_det_read_fd_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); unsigned char *data = transfer->buffer; @@ -184,7 +184,7 @@ out: static void finger_det_set_idle_cmd_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -195,7 +195,7 @@ static void finger_det_set_idle_cmd_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void finger_det_sm_complete(struct fpi_ssm *ssm) +static void finger_det_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -215,7 +215,7 @@ static void finger_det_sm_complete(struct fpi_ssm *ssm) } } -static void finger_det_run_state(struct fpi_ssm *ssm) +static void finger_det_run_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { case FINGER_DET_SEND_LED_CMD: @@ -239,7 +239,7 @@ static void finger_det_run_state(struct fpi_ssm *ssm) static void start_finger_detection(struct fp_img_dev *dev) { - struct fpi_ssm *ssm; + fpi_ssm *ssm; struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); if (aesdev->deactivating) { @@ -263,7 +263,7 @@ enum capture_states { }; /* Returns number of processed bytes */ -static int process_stripe_data(struct fpi_ssm *ssm, unsigned char *data) +static int process_stripe_data(fpi_ssm *ssm, unsigned char *data) { struct fpi_frame *stripe; unsigned char *stripdata; @@ -294,7 +294,7 @@ static int process_stripe_data(struct fpi_ssm *ssm, unsigned char *data) static void capture_set_idle_cmd_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -320,7 +320,7 @@ static void capture_set_idle_cmd_cb(struct libusb_transfer *transfer) static void capture_read_stripe_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); unsigned char *data = transfer->buffer; @@ -371,7 +371,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -400,7 +400,7 @@ static void capture_run_state(struct fpi_ssm *ssm) } } -static void capture_sm_complete(struct fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -420,7 +420,7 @@ static void capture_sm_complete(struct fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; if (aesdev->deactivating) { complete_deactivation(dev); @@ -448,7 +448,7 @@ enum activate_states { static void activate_read_id_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); unsigned char *data = transfer->buffer; @@ -499,7 +499,7 @@ out: static void activate_read_init_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); unsigned char *data = transfer->buffer; @@ -534,7 +534,7 @@ out: libusb_free_transfer(transfer); } -static void activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); @@ -580,7 +580,7 @@ static void activate_run_state(struct fpi_ssm *ssm) } } -static void activate_sm_complete(struct fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int err = fpi_ssm_get_error(ssm); @@ -594,7 +594,7 @@ static void activate_sm_complete(struct fpi_ssm *ssm) int aesX660_dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_sm_complete); diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 8457405a..d8a24a63 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -313,7 +313,7 @@ static void elan_submit_image(struct fp_img_dev *dev) fpi_imgdev_image_captured(dev, img); } -static void elan_cmd_done(struct fpi_ssm *ssm) +static void elan_cmd_done(fpi_ssm *ssm) { G_DEBUG_HERE(); fpi_ssm_next_state(ssm); @@ -321,7 +321,7 @@ static void elan_cmd_done(struct fpi_ssm *ssm) static void elan_cmd_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -362,7 +362,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) } } -static void elan_cmd_read(struct fpi_ssm *ssm) +static void elan_cmd_read(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -401,7 +401,7 @@ static void elan_cmd_read(struct fpi_ssm *ssm) fpi_ssm_mark_aborted(ssm, r); } -static void elan_run_cmd(struct fpi_ssm *ssm, const struct elan_cmd *cmd, +static void elan_run_cmd(fpi_ssm *ssm, const struct elan_cmd *cmd, int cmd_timeout) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -440,7 +440,7 @@ enum stop_capture_states { STOP_CAPTURE_NUM_STATES, }; -static void stop_capture_run_state(struct fpi_ssm *ssm) +static void stop_capture_run_state(fpi_ssm *ssm) { G_DEBUG_HERE(); @@ -451,7 +451,7 @@ static void stop_capture_run_state(struct fpi_ssm *ssm) } } -static void stop_capture_complete(struct fpi_ssm *ssm) +static void stop_capture_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -485,7 +485,7 @@ static void elan_stop_capture(struct fp_img_dev *dev) elan_dev_reset(elandev); - struct fpi_ssm *ssm = + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), stop_capture_run_state, STOP_CAPTURE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -500,7 +500,7 @@ enum capture_states { CAPTURE_NUM_STATES, }; -static void capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -538,7 +538,7 @@ static void capture_run_state(struct fpi_ssm *ssm) } } -static void capture_complete(struct fpi_ssm *ssm) +static void capture_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -578,7 +578,7 @@ static void elan_capture(struct fp_img_dev *dev) G_DEBUG_HERE(); elan_dev_reset(elandev); - struct fpi_ssm *ssm = + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_complete); @@ -586,7 +586,7 @@ static void elan_capture(struct fp_img_dev *dev) static void fpi_ssm_next_state_async(void *data) { - fpi_ssm_next_state((struct fpi_ssm *)data); + fpi_ssm_next_state((fpi_ssm *)data); } /* this function needs to have elandev->background and elandev->last_read to be @@ -624,7 +624,7 @@ enum calibrate_states { CALIBRATE_NUM_STATES, }; -static void calibrate_run_state(struct fpi_ssm *ssm) +static void calibrate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -689,7 +689,7 @@ static void calibrate_run_state(struct fpi_ssm *ssm) } } -static void calibrate_complete(struct fpi_ssm *ssm) +static void calibrate_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -711,7 +711,7 @@ static void elan_calibrate(struct fp_img_dev *dev) elan_dev_reset(elandev); elandev->calib_atts_left = ELAN_CALIBRATION_ATTEMPTS; - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), calibrate_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), calibrate_run_state, CALIBRATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, calibrate_complete); @@ -726,7 +726,7 @@ enum activate_states { ACTIVATE_NUM_STATES, }; -static void activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); @@ -770,7 +770,7 @@ static void activate_run_state(struct fpi_ssm *ssm) } } -static void activate_complete(struct fpi_ssm *ssm) +static void activate_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -790,7 +790,7 @@ static void elan_activate(struct fp_img_dev *dev) G_DEBUG_HERE(); elan_dev_reset(elandev); - struct fpi_ssm *ssm = + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_complete); diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index 8a321b47..fc36bb54 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -210,8 +210,8 @@ static const struct usb_id elan_id_table[] = { {0, 0, 0,}, }; -static void elan_cmd_done(struct fpi_ssm *ssm); -static void elan_cmd_read(struct fpi_ssm *ssm); +static void elan_cmd_done(fpi_ssm *ssm); +static void elan_cmd_read(fpi_ssm *ssm); static void elan_calibrate(struct fp_img_dev *dev); static void elan_capture(struct fp_img_dev *dev); diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index fdaf7f20..2c61f17e 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -669,7 +669,7 @@ static int async_tx(struct fp_img_dev *idev, unsigned int ep, void *cb, static void async_tx_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -699,7 +699,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) } } -static void m_exit_state(struct fpi_ssm *ssm) +static void m_exit_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -727,7 +727,7 @@ err: fpi_ssm_mark_aborted(ssm, -EIO); } -static void m_exit_complete(struct fpi_ssm *ssm) +static void m_exit_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -742,14 +742,14 @@ static void m_exit_complete(struct fpi_ssm *ssm) static void m_exit_start(struct fp_img_dev *idev) { - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_exit_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_exit_state, EXIT_NUM_STATES); fp_dbg("Switching device to idle mode"); fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, m_exit_complete); } -static void m_capture_state(struct fpi_ssm *ssm) +static void m_capture_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -830,7 +830,7 @@ err: fpi_ssm_mark_aborted(ssm, -EIO); } -static void m_capture_complete(struct fpi_ssm *ssm) +static void m_capture_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -852,7 +852,7 @@ static void m_capture_complete(struct fpi_ssm *ssm) } } -static void m_finger_state(struct fpi_ssm *ssm) +static void m_finger_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -948,13 +948,13 @@ err: fpi_ssm_mark_aborted(ssm, -EIO); } -static void m_finger_complete(struct fpi_ssm *ssm) +static void m_finger_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); if (!fpi_ssm_get_error(ssm)) { - struct fpi_ssm *ssm_cap; + fpi_ssm *ssm_cap; ssm_cap = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_capture_state, CAP_NUM_STATES); fpi_ssm_set_user_data(ssm_cap, idev); @@ -973,7 +973,7 @@ static void m_finger_complete(struct fpi_ssm *ssm) static void m_start_fingerdetect(struct fp_img_dev *idev) { - struct fpi_ssm *ssmf; + fpi_ssm *ssmf; ssmf = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_finger_state, FGR_NUM_STATES); fpi_ssm_set_user_data(ssmf, idev); fpi_ssm_start(ssmf, m_finger_complete); @@ -982,7 +982,7 @@ static void m_start_fingerdetect(struct fp_img_dev *idev) /* * Tune value of VRT and VRB for contrast and brightness. */ -static void m_tunevrb_state(struct fpi_ssm *ssm) +static void m_tunevrb_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -1134,7 +1134,7 @@ err: fpi_ssm_mark_aborted(ssm, -EIO); } -static void m_tunevrb_complete(struct fpi_ssm *ssm) +static void m_tunevrb_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -1156,7 +1156,7 @@ static void m_tunevrb_complete(struct fpi_ssm *ssm) * This function tunes the DCoffset value and adjusts the gain value if * required. */ -static void m_tunedc_state(struct fpi_ssm *ssm) +static void m_tunedc_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -1259,11 +1259,11 @@ err: } -static void m_tunedc_complete(struct fpi_ssm *ssm) +static void m_tunedc_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); if (!fpi_ssm_get_error(ssm)) { - struct fpi_ssm *ssm_tune; + fpi_ssm *ssm_tune; ssm_tune = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_tunevrb_state, TUNEVRB_NUM_STATES); fpi_ssm_set_user_data(ssm_tune, idev); @@ -1278,7 +1278,7 @@ static void m_tunedc_complete(struct fpi_ssm *ssm) fpi_ssm_free(ssm); } -static void m_init_state(struct fpi_ssm *ssm) +static void m_init_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); @@ -1379,11 +1379,11 @@ err: } -static void m_init_complete(struct fpi_ssm *ssm) +static void m_init_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); if (!fpi_ssm_get_error(ssm)) { - struct fpi_ssm *ssm_tune; + fpi_ssm *ssm_tune; ssm_tune = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_tunedc_state, TUNEDC_NUM_STATES); fpi_ssm_set_user_data(ssm_tune, idev); @@ -1401,7 +1401,7 @@ static void m_init_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) { struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; g_assert(dev); diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 9cccb865..ff22bd66 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -81,7 +81,7 @@ struct sonly_dev { int dev_model; int img_width; - struct fpi_ssm *loopsm; + fpi_ssm *loopsm; struct libusb_transfer *img_transfer[NUM_BULK_TRANSFERS]; struct img_transfer_data *img_transfer_data; int num_flying; @@ -100,7 +100,7 @@ struct sonly_dev { enum sonly_kill_transfers_action killing_transfers; int kill_status_code; union { - struct fpi_ssm *kill_ssm; + fpi_ssm *kill_ssm; void (*kill_cb)(struct fp_img_dev *dev); }; }; @@ -520,7 +520,7 @@ static void img_data_cb(struct libusb_transfer *transfer) /***** STATE MACHINE HELPERS *****/ struct write_regs_data { - struct fpi_ssm *ssm; + fpi_ssm *ssm; struct libusb_transfer *transfer; const struct sonly_regwrite *regs; size_t num_regs; @@ -574,7 +574,7 @@ static void write_regs_cb(struct libusb_transfer *transfer) write_regs_iterate(wrdata); } -static void sm_write_regs(struct fpi_ssm *ssm, +static void sm_write_regs(fpi_ssm *ssm, const struct sonly_regwrite *regs, size_t num_regs) { struct write_regs_data *wrdata = g_malloc(sizeof(*wrdata)); @@ -605,7 +605,7 @@ static void sm_write_regs(struct fpi_ssm *ssm, static void sm_write_reg_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; g_free(transfer->buffer); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); @@ -614,7 +614,7 @@ static void sm_write_reg_cb(struct libusb_transfer *transfer) } -static void sm_write_reg(struct fpi_ssm *ssm, uint8_t reg, uint8_t value) +static void sm_write_reg(fpi_ssm *ssm, uint8_t reg, uint8_t value) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); @@ -647,7 +647,7 @@ static void sm_write_reg(struct fpi_ssm *ssm, uint8_t reg, uint8_t value) static void sm_read_reg_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -662,7 +662,7 @@ static void sm_read_reg_cb(struct libusb_transfer *transfer) g_free(transfer->buffer); } -static void sm_read_reg(struct fpi_ssm *ssm, uint8_t reg) +static void sm_read_reg(fpi_ssm *ssm, uint8_t reg) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); @@ -693,7 +693,7 @@ static void sm_read_reg(struct fpi_ssm *ssm, uint8_t reg) static void sm_await_intr_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -713,7 +713,7 @@ static void sm_await_intr_cb(struct libusb_transfer *transfer) fpi_ssm_next_state(ssm); } -static void sm_await_intr(struct fpi_ssm *ssm) +static void sm_await_intr(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); @@ -763,7 +763,7 @@ enum awfsm_1000_states { AWFSM_1000_NUM_STATES, }; -static void awfsm_2016_run_state(struct fpi_ssm *ssm) +static void awfsm_2016_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -810,7 +810,7 @@ static void awfsm_2016_run_state(struct fpi_ssm *ssm) } } -static void awfsm_1000_run_state(struct fpi_ssm *ssm) +static void awfsm_1000_run_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { case AWFSM_1000_WRITEV_1: @@ -851,7 +851,7 @@ enum capsm_1001_states { CAPSM_1001_NUM_STATES, }; -static void capsm_fire_bulk(struct fpi_ssm *ssm) +static void capsm_fire_bulk(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -881,7 +881,7 @@ static void capsm_fire_bulk(struct fpi_ssm *ssm) fpi_ssm_next_state(ssm); } -static void capsm_2016_run_state(struct fpi_ssm *ssm) +static void capsm_2016_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -913,7 +913,7 @@ static void capsm_2016_run_state(struct fpi_ssm *ssm) } } -static void capsm_1000_run_state(struct fpi_ssm *ssm) +static void capsm_1000_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -939,7 +939,7 @@ static void capsm_1000_run_state(struct fpi_ssm *ssm) } } -static void capsm_1001_run_state(struct fpi_ssm *ssm) +static void capsm_1001_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -994,7 +994,7 @@ enum deinitsm_1001_states { DEINITSM_1001_NUM_STATES, }; -static void deinitsm_2016_run_state(struct fpi_ssm *ssm) +static void deinitsm_2016_run_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_2016_WRITEV: @@ -1003,7 +1003,7 @@ static void deinitsm_2016_run_state(struct fpi_ssm *ssm) } } -static void deinitsm_1000_run_state(struct fpi_ssm *ssm) +static void deinitsm_1000_run_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_1000_WRITEV: @@ -1012,7 +1012,7 @@ static void deinitsm_1000_run_state(struct fpi_ssm *ssm) } } -static void deinitsm_1001_run_state(struct fpi_ssm *ssm) +static void deinitsm_1001_run_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_1001_WRITEV: @@ -1048,7 +1048,7 @@ enum initsm_1001_states { INITSM_1001_NUM_STATES, }; -static void initsm_2016_run_state(struct fpi_ssm *ssm) +static void initsm_2016_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -1078,7 +1078,7 @@ static void initsm_2016_run_state(struct fpi_ssm *ssm) } } -static void initsm_1000_run_state(struct fpi_ssm *ssm) +static void initsm_1000_run_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_1000_WRITEV_1: @@ -1087,7 +1087,7 @@ static void initsm_1000_run_state(struct fpi_ssm *ssm) } } -static void initsm_1001_run_state(struct fpi_ssm *ssm) +static void initsm_1001_run_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_1001_WRITEV_1: @@ -1120,7 +1120,7 @@ enum loopsm_states { LOOPSM_NUM_STATES, }; -static void loopsm_run_state(struct fpi_ssm *ssm) +static void loopsm_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -1139,7 +1139,7 @@ static void loopsm_run_state(struct fpi_ssm *ssm) if (sdev->deactivating) { fpi_ssm_mark_completed(ssm); } else { - struct fpi_ssm *awfsm = NULL; + fpi_ssm *awfsm = NULL; switch (sdev->dev_model) { case UPEKSONLY_2016: awfsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), awfsm_2016_run_state, @@ -1167,7 +1167,7 @@ static void loopsm_run_state(struct fpi_ssm *ssm) } break; case LOOPSM_RUN_CAPSM: ; - struct fpi_ssm *capsm = NULL; + fpi_ssm *capsm = NULL; switch (sdev->dev_model) { case UPEKSONLY_2016: capsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capsm_2016_run_state, @@ -1188,7 +1188,7 @@ static void loopsm_run_state(struct fpi_ssm *ssm) case LOOPSM_CAPTURE: break; case LOOPSM_RUN_DEINITSM: ; - struct fpi_ssm *deinitsm = NULL; + fpi_ssm *deinitsm = NULL; switch (sdev->dev_model) { case UPEKSONLY_2016: deinitsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), deinitsm_2016_run_state, @@ -1248,7 +1248,7 @@ static void dev_deactivate(struct fp_img_dev *dev) cancel_img_transfers(dev); } -static void loopsm_complete(struct fpi_ssm *ssm) +static void loopsm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -1267,7 +1267,7 @@ static void loopsm_complete(struct fpi_ssm *ssm) } } -static void initsm_complete(struct fpi_ssm *ssm) +static void initsm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); @@ -1286,7 +1286,7 @@ static void initsm_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm = NULL; + fpi_ssm *ssm = NULL; int i; sdev->deactivating = FALSE; diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index ffa31f33..d94a3fcc 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -56,7 +56,7 @@ enum activate_states { ACTIVATE_NUM_STATES, }; -static void upektc_next_init_cmd(struct fpi_ssm *ssm) +static void upektc_next_init_cmd(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -70,7 +70,7 @@ static void upektc_next_init_cmd(struct fpi_ssm *ssm) static void write_init_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -88,7 +88,7 @@ static void write_init_cb(struct libusb_transfer *transfer) static void read_init_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_COMPLETED) upektc_next_init_cmd(ssm); @@ -98,7 +98,7 @@ static void read_init_data_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -148,7 +148,7 @@ static void activate_run_state(struct fpi_ssm *ssm) } } -static void activate_sm_complete(struct fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); @@ -283,7 +283,7 @@ enum capture_states { static void capture_cmd_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -296,7 +296,7 @@ static void capture_cmd_cb(struct libusb_transfer *transfer) static void capture_read_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); unsigned char *data = transfer->buffer; struct fp_img *img; @@ -321,7 +321,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -370,7 +370,7 @@ static void capture_run_state(struct fpi_ssm *ssm) }; } -static void capture_sm_complete(struct fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -388,7 +388,7 @@ static void capture_sm_complete(struct fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; if (upekdev->deactivating) { complete_deactivation(dev); @@ -404,7 +404,7 @@ static void start_capture(struct fp_img_dev *dev) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); upekdev->init_idx = 0; diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 814707d0..424b9eca 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -71,7 +71,7 @@ static void upektc_img_cmd_update_crc(unsigned char *cmd_buf, size_t size) cmd_buf[size - 1] = (crc & 0xff00) >> 8; } -static void upektc_img_submit_req(struct fpi_ssm *ssm, +static void upektc_img_submit_req(fpi_ssm *ssm, const unsigned char *buf, size_t buf_size, unsigned char seq, libusb_transfer_cb_fn cb) { @@ -103,7 +103,7 @@ static void upektc_img_submit_req(struct fpi_ssm *ssm, } } -static void upektc_img_read_data(struct fpi_ssm *ssm, size_t buf_size, size_t buf_offset, libusb_transfer_cb_fn cb) +static void upektc_img_read_data(fpi_ssm *ssm, size_t buf_size, size_t buf_offset, libusb_transfer_cb_fn cb) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -144,7 +144,7 @@ enum capture_states { static void capture_reqs_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || (transfer->length != transfer->actual_length)) { @@ -181,7 +181,7 @@ static int upektc_img_process_image_frame(unsigned char *image_buf, unsigned cha static void capture_read_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); unsigned char *data = upekdev->response; @@ -304,7 +304,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) } } -static void capture_run_state(struct fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -341,7 +341,7 @@ static void capture_run_state(struct fpi_ssm *ssm) }; } -static void capture_sm_complete(struct fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -361,7 +361,7 @@ static void capture_sm_complete(struct fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; upekdev->image_size = 0; @@ -380,7 +380,7 @@ enum deactivate_states { static void deactivate_reqs_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -393,7 +393,7 @@ static void deactivate_reqs_cb(struct libusb_transfer *transfer) /* TODO: process response properly */ static void deactivate_read_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_mark_completed(ssm); @@ -402,7 +402,7 @@ static void deactivate_read_data_cb(struct libusb_transfer *transfer) } } -static void deactivate_run_state(struct fpi_ssm *ssm) +static void deactivate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -419,7 +419,7 @@ static void deactivate_run_state(struct fpi_ssm *ssm) }; } -static void deactivate_sm_complete(struct fpi_ssm *ssm) +static void deactivate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); @@ -440,7 +440,7 @@ static void deactivate_sm_complete(struct fpi_ssm *ssm) static void start_deactivation(struct fp_img_dev *dev) { struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; upekdev->image_size = 0; @@ -467,7 +467,7 @@ enum activate_states { static void init_reqs_ctrl_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); @@ -478,7 +478,7 @@ static void init_reqs_ctrl_cb(struct libusb_transfer *transfer) static void init_reqs_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -491,7 +491,7 @@ static void init_reqs_cb(struct libusb_transfer *transfer) /* TODO: process response properly */ static void init_read_data_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); @@ -500,7 +500,7 @@ static void init_read_data_cb(struct libusb_transfer *transfer) } } -static void activate_run_state(struct fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -564,7 +564,7 @@ static void activate_run_state(struct fpi_ssm *ssm) } } -static void activate_sm_complete(struct fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int err = fpi_ssm_get_error(ssm); @@ -580,7 +580,7 @@ static void activate_sm_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); upekdev->seq = 0; diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index 0858959e..af383eb1 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -484,7 +484,7 @@ enum initsm_states { INITSM_NUM_STATES, }; -static void initsm_read_msg_response_cb(struct fpi_ssm *ssm, +static void initsm_read_msg_response_cb(fpi_ssm *ssm, enum read_msg_status status, uint8_t seq, unsigned char expect_subcmd, unsigned char subcmd) { @@ -513,7 +513,7 @@ static void read28_0b_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, 0x0b, subcmd); } @@ -521,7 +521,7 @@ static void read28_0c_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, 0x0c, subcmd); } @@ -529,7 +529,7 @@ static void read28_08_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, 0x08, subcmd); } @@ -537,7 +537,7 @@ static void read28_07_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, 0x07, subcmd); } @@ -545,11 +545,11 @@ static void read28_06_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, 0x06, subcmd); } -static void initsm_read_msg_cmd_cb(struct fpi_ssm *ssm, +static void initsm_read_msg_cmd_cb(fpi_ssm *ssm, enum read_msg_status status, uint8_t expect_seq, uint8_t seq) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); @@ -579,19 +579,19 @@ static void read_msg05_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_cmd_cb((struct fpi_ssm *) user_data, status, 5, seq); + initsm_read_msg_cmd_cb((fpi_ssm *) user_data, status, 5, seq); } static void read_msg03_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_cmd_cb((struct fpi_ssm *) user_data, status, 3, seq); + initsm_read_msg_cmd_cb((fpi_ssm *) user_data, status, 3, seq); } static void ctrl400_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; /* FIXME check length? */ if (transfer->status == LIBUSB_TRANSFER_COMPLETED) fpi_ssm_next_state(ssm); @@ -601,7 +601,7 @@ static void ctrl400_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void initsm_read_msg_handler(struct fpi_ssm *ssm, +static void initsm_read_msg_handler(fpi_ssm *ssm, read_msg_cb_fn callback) { int r = read_msg_async(fpi_ssm_get_dev(ssm), callback, ssm); @@ -613,7 +613,7 @@ static void initsm_read_msg_handler(struct fpi_ssm *ssm, static void initsm_send_msg_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_COMPLETED && transfer->length == transfer->actual_length) { fp_dbg("state %d completed", fpi_ssm_get_cur_state(ssm)); @@ -626,7 +626,7 @@ static void initsm_send_msg_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void initsm_send_msg28_handler(struct fpi_ssm *ssm, +static void initsm_send_msg28_handler(fpi_ssm *ssm, unsigned char subcmd, const unsigned char *data, uint16_t innerlen) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); @@ -649,7 +649,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(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); @@ -736,7 +736,7 @@ static void initsm_run_state(struct fpi_ssm *ssm) } } -static struct fpi_ssm *initsm_new(struct fp_dev *dev) +static fpi_ssm *initsm_new(struct fp_dev *dev) { return fpi_ssm_new(dev, initsm_run_state, INITSM_NUM_STATES); } @@ -749,7 +749,7 @@ enum deinitsm_states { static void send_resp07_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); else if (transfer->length != transfer->actual_length) @@ -763,7 +763,7 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); if (status == READ_MSG_ERROR) { @@ -784,7 +784,7 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, fpi_ssm_next_state(ssm); } -static void deinitsm_state_handler(struct fpi_ssm *ssm) +static void deinitsm_state_handler(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; @@ -816,7 +816,7 @@ static void deinitsm_state_handler(struct fpi_ssm *ssm) } } -static struct fpi_ssm *deinitsm_new(struct fp_dev *dev) +static fpi_ssm *deinitsm_new(struct fp_dev *dev) { return fpi_ssm_new(dev, deinitsm_state_handler, DEINITSM_NUM_STATES); } @@ -868,9 +868,9 @@ enum enroll_start_sm_states { }; /* Called when the device initialization state machine completes */ -static void enroll_start_sm_cb_initsm(struct fpi_ssm *initsm) +static void enroll_start_sm_cb_initsm(fpi_ssm *initsm) { - struct fpi_ssm *enroll_start_ssm = fpi_ssm_get_user_data(initsm); + fpi_ssm *enroll_start_ssm = fpi_ssm_get_user_data(initsm); int error = fpi_ssm_get_error(initsm); fpi_ssm_free(initsm); @@ -883,7 +883,7 @@ static void enroll_start_sm_cb_initsm(struct fpi_ssm *initsm) /* called when enroll init URB has completed */ static void enroll_start_sm_cb_init(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); else if (transfer->length != transfer->actual_length) @@ -898,7 +898,7 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev, unsigned char *data, size_t data_len, void *user_data) { struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; if (status != READ_MSG_RESPONSE) { fp_err("expected response, got %d seq=%x", status, seq); @@ -916,14 +916,14 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev, } } -static void enroll_start_sm_run_state(struct fpi_ssm *ssm) +static void enroll_start_sm_run_state(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; switch (fpi_ssm_get_cur_state(ssm)) { case RUN_INITSM: ; - struct fpi_ssm *initsm = initsm_new(dev); + fpi_ssm *initsm = initsm_new(dev); fpi_ssm_set_user_data(initsm, ssm); fpi_ssm_start(initsm, enroll_start_sm_cb_initsm); break; @@ -1112,7 +1112,7 @@ static void enroll_iterate(struct fp_dev *dev) } } -static void enroll_started(struct fpi_ssm *ssm) +static void enroll_started(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); fpi_drvcb_enroll_started(dev, fpi_ssm_get_error(ssm)); @@ -1128,7 +1128,7 @@ static int enroll_start(struct fp_dev *dev) struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); /* do_init state machine first */ - struct fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state, + fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state, ENROLL_START_NUM_STATES); upekdev->enroll_passed = FALSE; @@ -1136,7 +1136,7 @@ static int enroll_start(struct fp_dev *dev) return 0; } -static void enroll_stop_deinit_cb(struct fpi_ssm *ssm) +static void enroll_stop_deinit_cb(fpi_ssm *ssm) { /* don't really care about errors */ fpi_drvcb_enroll_stopped(fpi_ssm_get_dev(ssm)); @@ -1145,12 +1145,12 @@ static void enroll_stop_deinit_cb(struct fpi_ssm *ssm) static int enroll_stop(struct fp_dev *dev) { - struct fpi_ssm *ssm = deinitsm_new(dev); + fpi_ssm *ssm = deinitsm_new(dev); fpi_ssm_start(ssm, enroll_stop_deinit_cb); return 0; } -static void verify_stop_deinit_cb(struct fpi_ssm *ssm) +static void verify_stop_deinit_cb(fpi_ssm *ssm) { /* don't really care about errors */ fpi_drvcb_verify_stopped(fpi_ssm_get_dev(ssm)); @@ -1159,7 +1159,7 @@ static void verify_stop_deinit_cb(struct fpi_ssm *ssm) static void do_verify_stop(struct fp_dev *dev) { - struct fpi_ssm *ssm = deinitsm_new(dev); + fpi_ssm *ssm = deinitsm_new(dev); fpi_ssm_start(ssm, verify_stop_deinit_cb); } @@ -1176,9 +1176,9 @@ enum { }; /* Called when the device initialization state machine completes */ -static void verify_start_sm_cb_initsm(struct fpi_ssm *initsm) +static void verify_start_sm_cb_initsm(fpi_ssm *initsm) { - struct fpi_ssm *verify_start_ssm = fpi_ssm_get_user_data(initsm); + fpi_ssm *verify_start_ssm = fpi_ssm_get_user_data(initsm); int err; err = fpi_ssm_get_error(initsm); @@ -1191,7 +1191,7 @@ static void verify_start_sm_cb_initsm(struct fpi_ssm *initsm) static void verify_init_2803_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); else if (transfer->length != transfer->actual_length) @@ -1201,14 +1201,14 @@ static void verify_init_2803_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void verify_start_sm_run_state(struct fpi_ssm *ssm) +static void verify_start_sm_run_state(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; switch (fpi_ssm_get_cur_state(ssm)) { case VERIFY_RUN_INITSM: ; - struct fpi_ssm *initsm = initsm_new(dev); + fpi_ssm *initsm = initsm_new(dev); fpi_ssm_set_user_data(initsm, ssm); fpi_ssm_start(initsm, verify_start_sm_cb_initsm); break; @@ -1391,7 +1391,7 @@ static void verify_iterate(struct fp_dev *dev) } } -static void verify_started(struct fpi_ssm *ssm) +static void verify_started(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); @@ -1408,7 +1408,7 @@ static void verify_started(struct fpi_ssm *ssm) static int verify_start(struct fp_dev *dev) { struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); - struct fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state, + fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state, VERIFY_NUM_STATES); upekdev->stop_verify = FALSE; fpi_ssm_start(ssm, verify_started); diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 080edf72..6c7097ed 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -306,7 +306,7 @@ static int read_regs(struct fp_img_dev *dev, uint16_t first_reg, static void response_cb(struct fp_img_dev *dev, int status, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; if (status == 0) fpi_ssm_next_state(ssm); else @@ -316,7 +316,7 @@ static void response_cb(struct fp_img_dev *dev, int status, void *user_data) static void challenge_cb(struct fp_img_dev *dev, int status, uint16_t num_regs, unsigned char *data, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); unsigned char *respdata; PK11Context *ctx; @@ -354,7 +354,7 @@ static void challenge_cb(struct fp_img_dev *dev, int status, * authentication scheme, where the device challenges the authenticity of the * driver. */ -static void sm_do_challenge_response(struct fpi_ssm *ssm) +static void sm_do_challenge_response(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r; @@ -508,7 +508,7 @@ static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) static void sm_write_reg_cb(struct fp_img_dev *dev, int result, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; if (result) fpi_ssm_mark_aborted(ssm, result); @@ -516,7 +516,7 @@ static void sm_write_reg_cb(struct fp_img_dev *dev, int result, void *user_data) fpi_ssm_next_state(ssm); } -static void sm_write_regs(struct fpi_ssm *ssm, uint16_t first_reg, uint16_t num_regs, +static void sm_write_regs(fpi_ssm *ssm, uint16_t first_reg, uint16_t num_regs, void *data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -525,7 +525,7 @@ static void sm_write_regs(struct fpi_ssm *ssm, uint16_t first_reg, uint16_t num_ fpi_ssm_mark_aborted(ssm, r); } -static void sm_write_reg(struct fpi_ssm *ssm, uint16_t reg, +static void sm_write_reg(fpi_ssm *ssm, uint16_t reg, unsigned char value) { sm_write_regs(ssm, reg, 1, &value); @@ -534,7 +534,7 @@ static void sm_write_reg(struct fpi_ssm *ssm, uint16_t reg, static void sm_read_reg_cb(struct fp_img_dev *dev, int result, uint16_t num_regs, unsigned char *data, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); if (result) { @@ -546,7 +546,7 @@ static void sm_read_reg_cb(struct fp_img_dev *dev, int result, } } -static void sm_read_regs(struct fpi_ssm *ssm, uint16_t reg, uint16_t num_regs) +static void sm_read_regs(fpi_ssm *ssm, uint16_t reg, uint16_t num_regs) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -563,12 +563,12 @@ static void sm_read_regs(struct fpi_ssm *ssm, uint16_t reg, uint16_t num_regs) fpi_ssm_mark_aborted(ssm, r); } -static void sm_read_reg(struct fpi_ssm *ssm, uint16_t reg) +static void sm_read_reg(fpi_ssm *ssm, uint16_t reg) { sm_read_regs(ssm, reg, 1); } -static void sm_set_hwstat(struct fpi_ssm *ssm, unsigned char value) +static void sm_set_hwstat(fpi_ssm *ssm, unsigned char value) { fp_dbg("set %02x", value); sm_write_reg(ssm, REG_HWSTAT, value); @@ -587,7 +587,7 @@ enum imaging_states { static void image_transfer_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { fp_dbg("cancelled"); @@ -687,7 +687,7 @@ static int calc_dev2(struct uru4k_image *img) return res / IMAGE_WIDTH; } -static void imaging_run_state(struct fpi_ssm *ssm) +static void imaging_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -810,7 +810,7 @@ static void imaging_run_state(struct fpi_ssm *ssm) } } -static void imaging_complete(struct fpi_ssm *ssm) +static void imaging_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -862,7 +862,7 @@ enum rebootpwr_states { static void rebootpwr_pause_cb(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -874,7 +874,7 @@ static void rebootpwr_pause_cb(void *data) } } -static void rebootpwr_run_state(struct fpi_ssm *ssm) +static void rebootpwr_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -939,7 +939,7 @@ enum powerup_states { static void powerup_pause_cb(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -953,7 +953,7 @@ static void powerup_pause_cb(void *data) } } -static void powerup_run_state(struct fpi_ssm *ssm) +static void powerup_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -1024,7 +1024,7 @@ enum init_states { static void init_scanpwr_irq_cb(struct fp_img_dev *dev, int status, uint16_t type, void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); if (status) @@ -1042,7 +1042,7 @@ static void init_scanpwr_irq_cb(struct fp_img_dev *dev, int status, static void init_scanpwr_timeout(void *user_data) { - struct fpi_ssm *ssm = user_data; + fpi_ssm *ssm = user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -1058,7 +1058,7 @@ static void init_scanpwr_timeout(void *user_data) } } -static void init_run_state(struct fpi_ssm *ssm) +static void init_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); @@ -1075,7 +1075,7 @@ static void init_run_state(struct fpi_ssm *ssm) fpi_ssm_jump_to_state(ssm, INIT_CHECK_HWSTAT_POWERDOWN); break; case INIT_REBOOT_POWER: ; - struct fpi_ssm *rebootsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), rebootpwr_run_state, + fpi_ssm *rebootsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), rebootpwr_run_state, REBOOTPWR_NUM_STATES); fpi_ssm_set_user_data(rebootsm, dev); fpi_ssm_start_subsm(ssm, rebootsm); @@ -1094,7 +1094,7 @@ static void init_run_state(struct fpi_ssm *ssm) urudev->irq_cb_data = ssm; urudev->irq_cb = init_scanpwr_irq_cb; - struct fpi_ssm *powerupsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), powerup_run_state, + fpi_ssm *powerupsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), powerup_run_state, POWERUP_NUM_STATES); fpi_ssm_set_user_data(powerupsm, dev); fpi_ssm_start_subsm(ssm, powerupsm); @@ -1138,7 +1138,7 @@ static void init_run_state(struct fpi_ssm *ssm) } } -static void activate_initsm_complete(struct fpi_ssm *ssm) +static void activate_initsm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r = fpi_ssm_get_error(ssm); @@ -1160,7 +1160,7 @@ static void activate_initsm_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; int r; r = start_irq_handler(dev); @@ -1196,7 +1196,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static int execute_state_change(struct fp_img_dev *dev) { struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; switch (urudev->activate_state) { case IMGDEV_STATE_INACTIVE: diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index cbd03751..e54a7f39 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -74,7 +74,7 @@ enum v5s_cmd { static void sm_write_reg_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); @@ -85,7 +85,7 @@ static void sm_write_reg_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void sm_write_reg(struct fpi_ssm *ssm, unsigned char reg, +static void sm_write_reg(fpi_ssm *ssm, unsigned char reg, unsigned char value) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -113,7 +113,7 @@ static void sm_write_reg(struct fpi_ssm *ssm, unsigned char reg, static void sm_exec_cmd_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_aborted(ssm, -EIO); @@ -124,7 +124,7 @@ static void sm_exec_cmd_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void sm_exec_cmd(struct fpi_ssm *ssm, unsigned char cmd, +static void sm_exec_cmd(fpi_ssm *ssm, unsigned char cmd, unsigned char param) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -187,11 +187,11 @@ static gboolean finger_is_present(unsigned char *data) /***** IMAGE ACQUISITION *****/ -static void capture_iterate(struct fpi_ssm *ssm); +static void capture_iterate(fpi_ssm *ssm); static void capture_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -218,7 +218,7 @@ out: libusb_free_transfer(transfer); } -static void capture_iterate(struct fpi_ssm *ssm) +static void capture_iterate(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -243,7 +243,7 @@ static void capture_iterate(struct fpi_ssm *ssm) } -static void sm_do_capture(struct fpi_ssm *ssm) +static void sm_do_capture(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -265,7 +265,7 @@ enum loop_states { LOOP_NUM_STATES, }; -static void loop_run_state(struct fpi_ssm *ssm) +static void loop_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -293,7 +293,7 @@ static void loop_run_state(struct fpi_ssm *ssm) } } -static void loopsm_complete(struct fpi_ssm *ssm) +static void loopsm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -314,7 +314,7 @@ static void loopsm_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), loop_run_state, + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), loop_run_state, LOOP_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); vdev->deactivating = FALSE; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index dcf5d693..dd6fb3d5 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -27,7 +27,7 @@ /* Callback for async_write */ static void async_write_callback(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); int transferred = transfer->actual_length, error = @@ -51,7 +51,7 @@ static void async_write_callback(struct libusb_transfer *transfer) } /* Send data to EP1, the only out endpoint */ -static void async_write(struct fpi_ssm *ssm, void *data, int len) +static void async_write(fpi_ssm *ssm, void *data, int len) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); @@ -67,7 +67,7 @@ static void async_write(struct fpi_ssm *ssm, void *data, int len) /* Callback for async_read */ static void async_read_callback(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); int transferred = transfer->actual_length, error = @@ -93,7 +93,7 @@ static void async_read_callback(struct libusb_transfer *transfer) } /* Receive data from the given ep and compare with expected */ -static void async_read(struct fpi_ssm *ssm, int ep, void *data, int len) +static void async_read(fpi_ssm *ssm, int ep, void *data, int len) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); @@ -119,7 +119,7 @@ static void async_read(struct fpi_ssm *ssm, int ep, void *data, int len) /* Callback for async_read */ static void async_abort_callback(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); int transferred = transfer->actual_length, error = transfer->status; @@ -147,7 +147,7 @@ static void async_abort_callback(struct libusb_transfer *transfer) } /* Receive data from the given ep and compare with expected */ -static void async_abort(struct fpi_ssm *ssm, int ep) +static void async_abort(fpi_ssm *ssm, int ep) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); @@ -279,7 +279,7 @@ static void submit_image(struct fp_img_dev *idev) /* Proto functions */ /* SSM loop for clear_ep2 */ -static void clear_ep2_ssm(struct fpi_ssm *ssm) +static void clear_ep2_ssm(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -307,17 +307,17 @@ static void clear_ep2_ssm(struct fpi_ssm *ssm) } /* Send command to clear EP2 */ -static void clear_ep2(struct fpi_ssm *ssm) +static void clear_ep2(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct fpi_ssm *subsm = + fpi_ssm *subsm = fpi_ssm_new(fpi_imgdev_get_dev(idev), clear_ep2_ssm, SUBSM1_STATES); fpi_ssm_set_user_data(subsm, idev); fpi_ssm_start_subsm(ssm, subsm); } -static void send_control_packet_ssm(struct fpi_ssm *ssm) +static void send_control_packet_ssm(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); @@ -385,11 +385,11 @@ static void send_control_packet_ssm(struct fpi_ssm *ssm) } /* Send device state control packet */ -static void send_control_packet(struct fpi_ssm *ssm) +static void send_control_packet(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct fpi_ssm *subsm = + fpi_ssm *subsm = fpi_ssm_new(fpi_imgdev_get_dev(idev), send_control_packet_ssm, SUBSM2_STATES); fpi_ssm_set_user_data(subsm, idev); fpi_ssm_start_subsm(ssm, subsm); @@ -406,7 +406,7 @@ static void clear_data(struct vfs_dev_t *vdev) /* After receiving interrupt from EP3 */ static void interrupt_callback(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); @@ -466,7 +466,7 @@ static void interrupt_callback(struct libusb_transfer *transfer) static void receive_callback(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); @@ -494,7 +494,7 @@ static void receive_callback(struct libusb_transfer *transfer) /* Stub to keep SSM alive when waiting an interrupt */ static void wait_interrupt(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); @@ -506,19 +506,19 @@ static void wait_interrupt(void *data) /* SSM stub to prepare device to another scan after orange light was on */ static void another_scan(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; fpi_ssm_jump_to_state(ssm, SSM_TURN_ON); } /* Another SSM stub to continue after waiting for probable vdev->active changes */ static void scan_completed(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; fpi_ssm_next_state(ssm); } /* Main SSM loop */ -static void activate_ssm(struct fpi_ssm *ssm) +static void activate_ssm(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); @@ -671,7 +671,7 @@ static void activate_ssm(struct fpi_ssm *ssm) /* Driver functions */ /* Callback for dev_activate ssm */ -static void dev_activate_callback(struct fpi_ssm *ssm) +static void dev_activate_callback(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); @@ -691,7 +691,7 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) vdev->need_report = 1; vdev->ssm_active = 1; - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), activate_ssm, SSM_STATES); + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), activate_ssm, SSM_STATES); fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, dev_activate_callback); return 0; @@ -713,7 +713,7 @@ static void dev_deactivate(struct fp_img_dev *idev) } /* Callback for dev_open ssm */ -static void dev_open_callback(struct fpi_ssm *ssm) +static void dev_open_callback(fpi_ssm *ssm) { /* Notify open complete */ fpi_imgdev_open_complete(fpi_ssm_get_user_data(ssm), 0); @@ -738,7 +738,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) fpi_imgdev_set_user_data(idev, vdev); /* Clearing previous device state */ - struct fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), activate_ssm, SSM_STATES); + fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), activate_ssm, SSM_STATES); fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, dev_open_callback); return 0; diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 3304b1f9..6a7d4fb7 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -199,7 +199,7 @@ static int result_code(struct fp_img_dev *dev, int result) /* Callback of asynchronous send */ static void async_send_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -242,7 +242,7 @@ out: } /* Submit asynchronous send */ -static void async_send(struct fpi_ssm *ssm) +static void async_send(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -283,7 +283,7 @@ static void async_send(struct fpi_ssm *ssm) /* Callback of asynchronous recv */ static void async_recv_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -329,7 +329,7 @@ out: } /* Submit asynchronous recv */ -static void async_recv(struct fpi_ssm *ssm) +static void async_recv(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -362,12 +362,12 @@ static void async_recv(struct fpi_ssm *ssm) } } -static void async_load(struct fpi_ssm *ssm); +static void async_load(fpi_ssm *ssm); /* Callback of asynchronous load */ static void async_load_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -430,7 +430,7 @@ out: } /* Submit asynchronous load */ -static void async_load(struct fpi_ssm *ssm) +static void async_load(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -470,7 +470,7 @@ static void async_load(struct fpi_ssm *ssm) /* Callback of asynchronous sleep */ static void async_sleep_cb(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -481,7 +481,7 @@ static void async_sleep_cb(void *data) } /* Submit asynchronous sleep */ -static void async_sleep(unsigned int msec, struct fpi_ssm *ssm) +static void async_sleep(unsigned int msec, fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -507,7 +507,7 @@ enum }; /* Exec swap sequential state machine */ -static void m_swap_state(struct fpi_ssm *ssm) +static void m_swap_state(fpi_ssm *ssm) { switch (fpi_ssm_get_cur_state(ssm)) { @@ -524,11 +524,11 @@ static void m_swap_state(struct fpi_ssm *ssm) } /* Start swap sequential state machine */ -static void m_swap(struct fpi_ssm *ssm, unsigned char *data, size_t length) +static void m_swap(fpi_ssm *ssm, unsigned char *data, size_t length) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *subsm; + fpi_ssm *subsm; /* Prepare data for sending */ memcpy(vdev->buffer, data, length); @@ -542,7 +542,7 @@ static void m_swap(struct fpi_ssm *ssm, unsigned char *data, size_t length) } /* Retrieve fingerprint image */ -static void vfs_get_print(struct fpi_ssm *ssm, unsigned int param, int type) +static void vfs_get_print(fpi_ssm *ssm, unsigned int param, int type) { unsigned char data[2][0x0e] = { { 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, @@ -562,7 +562,7 @@ static void vfs_get_print(struct fpi_ssm *ssm, unsigned int param, int type) } /* Set a parameter value on the device */ -static void vfs_set_param(struct fpi_ssm *ssm, unsigned int param, unsigned int value) +static void vfs_set_param(fpi_ssm *ssm, unsigned int param, unsigned int value) { unsigned char data[0x0a] = { 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -579,7 +579,7 @@ static void vfs_set_param(struct fpi_ssm *ssm, unsigned int param, unsigned int } /* Abort previous print */ -static void vfs_abort_print(struct fpi_ssm *ssm) +static void vfs_abort_print(fpi_ssm *ssm) { unsigned char data[0x06] = { 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00 }; @@ -590,7 +590,7 @@ static void vfs_abort_print(struct fpi_ssm *ssm) } /* Poke a value on a region */ -static void vfs_poke(struct fpi_ssm *ssm, unsigned int addr, unsigned int value, unsigned int size) +static void vfs_poke(fpi_ssm *ssm, unsigned int addr, unsigned int value, unsigned int size) { unsigned char data[0x0f] = { 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -612,7 +612,7 @@ static void vfs_poke(struct fpi_ssm *ssm, unsigned int addr, unsigned int value, } /* Get current finger state */ -static void vfs_get_finger_state(struct fpi_ssm *ssm) +static void vfs_get_finger_state(fpi_ssm *ssm) { unsigned char data[0x06] = { 0x00, 0x00, 0x00, 0x00, 0x16, 0x00 }; @@ -623,7 +623,7 @@ static void vfs_get_finger_state(struct fpi_ssm *ssm) } /* Load raw image from reader */ -static void vfs_img_load(struct fpi_ssm *ssm) +static void vfs_img_load(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -754,7 +754,7 @@ static void img_copy(struct vfs101_dev *vdev, struct fp_img *img) } /* Extract fingerpint image from raw data */ -static void img_extract(struct fpi_ssm *ssm) +static void img_extract(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -912,7 +912,7 @@ enum }; /* Exec loop sequential state machine */ -static void m_loop_state(struct fpi_ssm *ssm) +static void m_loop_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -1120,7 +1120,7 @@ static void m_loop_state(struct fpi_ssm *ssm) } /* Complete loop sequential state machine */ -static void m_loop_complete(struct fpi_ssm *ssm) +static void m_loop_complete(fpi_ssm *ssm) { /* Free sequential state machine */ fpi_ssm_free(ssm); @@ -1176,7 +1176,7 @@ enum }; /* Exec init sequential state machine */ -static void m_init_state(struct fpi_ssm *ssm) +static void m_init_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); @@ -1417,11 +1417,11 @@ static void m_init_state(struct fpi_ssm *ssm) } /* Complete init sequential state machine */ -static void m_init_complete(struct fpi_ssm *ssm) +static void m_init_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm_loop; + fpi_ssm *ssm_loop; if (!fpi_ssm_get_error(ssm) && vdev->active) { @@ -1442,7 +1442,7 @@ static void m_init_complete(struct fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); - struct fpi_ssm *ssm; + fpi_ssm *ssm; /* Check if already active */ if (vdev->active) diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 45be8b36..3d17b750 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -29,13 +29,13 @@ /* Callback of asynchronous sleep */ static void async_sleep_cb(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; fpi_ssm_next_state(ssm); } /* Submit asynchronous sleep */ -static void async_sleep(unsigned int msec, struct fpi_ssm *ssm) +static void async_sleep(unsigned int msec, fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct fpi_timeout *timeout; @@ -51,7 +51,7 @@ static void async_sleep(unsigned int msec, struct fpi_ssm *ssm) } } -static int submit_image(struct fpi_ssm *ssm) +static int submit_image(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); vfs301_dev_t *vdev = fpi_imgdev_get_user_data(dev); @@ -103,7 +103,7 @@ enum }; /* Exec loop sequential state machine */ -static void m_loop_state(struct fpi_ssm *ssm) +static void m_loop_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); vfs301_dev_t *vdev = fpi_imgdev_get_user_data(dev); @@ -161,14 +161,14 @@ static void m_loop_state(struct fpi_ssm *ssm) } /* Complete loop sequential state machine */ -static void m_loop_complete(struct fpi_ssm *ssm) +static void m_loop_complete(fpi_ssm *ssm) { /* Free sequential state machine */ fpi_ssm_free(ssm); } /* Exec init sequential state machine */ -static void m_init_state(struct fpi_ssm *ssm) +static void m_init_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); vfs301_dev_t *vdev = fpi_imgdev_get_user_data(dev); @@ -181,10 +181,10 @@ static void m_init_state(struct fpi_ssm *ssm) } /* Complete init sequential state machine */ -static void m_init_complete(struct fpi_ssm *ssm) +static void m_init_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct fpi_ssm *ssm_loop; + fpi_ssm *ssm_loop; if (!fpi_ssm_get_error(ssm)) { /* Notify activate complete */ @@ -203,7 +203,7 @@ static void m_init_complete(struct fpi_ssm *ssm) /* Activate device */ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct fpi_ssm *ssm; + fpi_ssm *ssm; /* Start init ssm */ ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), m_init_state, 1); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 8b460acf..44d21aad 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -75,7 +75,7 @@ static void start_scan(struct fp_img_dev *dev); static void async_send_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct usbexchange_data *data = fpi_ssm_get_user_data(ssm); struct usb_action *action; @@ -119,7 +119,7 @@ out: static void async_recv_cb(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = transfer->user_data; + fpi_ssm *ssm = transfer->user_data; struct usbexchange_data *data = fpi_ssm_get_user_data(ssm); struct usb_action *action; @@ -171,7 +171,7 @@ out: libusb_free_transfer(transfer); } -static void usbexchange_loop(struct fpi_ssm *ssm) +static void usbexchange_loop(fpi_ssm *ssm) { struct usbexchange_data *data = fpi_ssm_get_user_data(ssm); if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) { @@ -233,10 +233,10 @@ static void usbexchange_loop(struct fpi_ssm *ssm) } } -static void usb_exchange_async(struct fpi_ssm *ssm, +static void usb_exchange_async(fpi_ssm *ssm, struct usbexchange_data *data) { - struct fpi_ssm *subsm = fpi_ssm_new(fpi_imgdev_get_dev(data->device), + fpi_ssm *subsm = fpi_ssm_new(fpi_imgdev_get_dev(data->device), usbexchange_loop, data->stepcount); fpi_ssm_set_user_data(subsm, data); @@ -395,7 +395,7 @@ static int process_chunk(struct vfs5011_data *data, int transferred) return 0; } -void submit_image(struct fpi_ssm *ssm, struct vfs5011_data *data) +void submit_image(fpi_ssm *ssm, struct vfs5011_data *data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct fp_img *img; @@ -422,7 +422,7 @@ void submit_image(struct fpi_ssm *ssm, struct vfs5011_data *data) static void chunk_capture_callback(struct libusb_transfer *transfer) { - struct fpi_ssm *ssm = (struct fpi_ssm *)transfer->user_data; + fpi_ssm *ssm = (fpi_ssm *)transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; @@ -452,7 +452,7 @@ static void chunk_capture_callback(struct libusb_transfer *transfer) static int capture_chunk_async(struct vfs5011_data *data, libusb_device_handle *handle, int nline, - int timeout, struct fpi_ssm *ssm) + int timeout, fpi_ssm *ssm) { fp_dbg("capture_chunk_async: capture %d lines, already have %d", nline, data->lines_recorded); @@ -472,7 +472,7 @@ static int capture_chunk_async(struct vfs5011_data *data, static void async_sleep_cb(void *data) { - struct fpi_ssm *ssm = data; + fpi_ssm *ssm = data; fpi_ssm_next_state(ssm); } @@ -665,7 +665,7 @@ struct usb_action vfs5011_initiate_capture[] = { /* ====================== lifprint interface ======================= */ -static void activate_loop(struct fpi_ssm *ssm) +static void activate_loop(fpi_ssm *ssm) { enum {READ_TIMEOUT = 0}; @@ -742,7 +742,7 @@ static void activate_loop(struct fpi_ssm *ssm) } } -static void activate_loop_complete(struct fpi_ssm *ssm) +static void activate_loop_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; @@ -772,7 +772,7 @@ static void activate_loop_complete(struct fpi_ssm *ssm) } -static void open_loop(struct fpi_ssm *ssm) +static void open_loop(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; @@ -793,7 +793,7 @@ static void open_loop(struct fpi_ssm *ssm) }; } -static void open_loop_complete(struct fpi_ssm *ssm) +static void open_loop_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; @@ -829,7 +829,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) return r; } - struct fpi_ssm *ssm; + fpi_ssm *ssm; ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), open_loop, DEV_OPEN_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, open_loop_complete); @@ -853,7 +853,7 @@ static void dev_close(struct fp_img_dev *dev) static void start_scan(struct fp_img_dev *dev) { struct vfs5011_data *data; - struct fpi_ssm *ssm; + fpi_ssm *ssm; data = fpi_imgdev_get_user_data(dev); data->loop_running = TRUE; diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 03aaf6e5..02669894 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -74,7 +74,7 @@ * abortion error conditions. */ struct fpi_ssm { struct fp_dev *dev; - struct fpi_ssm *parentsm; + fpi_ssm *parentsm; void *priv; int nr_states; int cur_state; @@ -85,10 +85,10 @@ struct fpi_ssm { }; /* Allocate a new ssm */ -struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, +fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, int nr_states) { - struct fpi_ssm *machine; + fpi_ssm *machine; BUG_ON(nr_states < 1); machine = g_malloc0(sizeof(*machine)); @@ -100,26 +100,26 @@ struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, } struct fp_dev * -fpi_ssm_get_dev(struct fpi_ssm *machine) +fpi_ssm_get_dev(fpi_ssm *machine) { return machine->dev; } void -fpi_ssm_set_user_data(struct fpi_ssm *machine, +fpi_ssm_set_user_data(fpi_ssm *machine, void *user_data) { machine->priv = user_data; } void * -fpi_ssm_get_user_data(struct fpi_ssm *machine) +fpi_ssm_get_user_data(fpi_ssm *machine) { return machine->priv; } /* Free a ssm */ -void fpi_ssm_free(struct fpi_ssm *machine) +void fpi_ssm_free(fpi_ssm *machine) { if (!machine) return; @@ -127,14 +127,14 @@ void fpi_ssm_free(struct fpi_ssm *machine) } /* Invoke the state handler */ -static void __ssm_call_handler(struct fpi_ssm *machine) +static void __ssm_call_handler(fpi_ssm *machine) { fp_dbg("%p entering state %d", machine, machine->cur_state); machine->handler(machine); } /* Start a ssm. You can also restart a completed or aborted ssm. */ -void fpi_ssm_start(struct fpi_ssm *ssm, ssm_completed_fn callback) +void fpi_ssm_start(fpi_ssm *ssm, ssm_completed_fn callback) { BUG_ON(!ssm->completed); ssm->callback = callback; @@ -144,9 +144,9 @@ void fpi_ssm_start(struct fpi_ssm *ssm, ssm_completed_fn callback) __ssm_call_handler(ssm); } -static void __subsm_complete(struct fpi_ssm *ssm) +static void __subsm_complete(fpi_ssm *ssm) { - struct fpi_ssm *parent = ssm->parentsm; + fpi_ssm *parent = ssm->parentsm; BUG_ON(!parent); if (ssm->error) fpi_ssm_mark_aborted(parent, ssm->error); @@ -159,14 +159,14 @@ static void __subsm_complete(struct fpi_ssm *ssm) * parent will be advanced to the next state. if the child aborts, the parent * will be aborted with the same error code. the child will be automatically * freed upon completion/abortion. */ -void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child) +void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child) { child->parentsm = parent; fpi_ssm_start(child, __subsm_complete); } /* Mark a ssm as completed successfully. */ -void fpi_ssm_mark_completed(struct fpi_ssm *machine) +void fpi_ssm_mark_completed(fpi_ssm *machine) { BUG_ON(machine->completed); machine->completed = TRUE; @@ -176,7 +176,7 @@ void fpi_ssm_mark_completed(struct fpi_ssm *machine) } /* Mark a ssm as aborted with error. */ -void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error) +void fpi_ssm_mark_aborted(fpi_ssm *machine, int error) { fp_dbg("error %d from state %d", error, machine->cur_state); BUG_ON(error == 0); @@ -185,7 +185,7 @@ void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error) } /* Iterate to next state of a ssm */ -void fpi_ssm_next_state(struct fpi_ssm *machine) +void fpi_ssm_next_state(fpi_ssm *machine) { BUG_ON(machine->completed); machine->cur_state++; @@ -196,7 +196,7 @@ void fpi_ssm_next_state(struct fpi_ssm *machine) } } -void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state) +void fpi_ssm_jump_to_state(fpi_ssm *machine, int state) { BUG_ON(machine->completed); BUG_ON(state >= machine->nr_states); @@ -204,12 +204,12 @@ void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state) __ssm_call_handler(machine); } -int fpi_ssm_get_cur_state(struct fpi_ssm *machine) +int fpi_ssm_get_cur_state(fpi_ssm *machine) { return machine->cur_state; } -int fpi_ssm_get_error(struct fpi_ssm *machine) +int fpi_ssm_get_error(fpi_ssm *machine) { return machine->error; } diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index ddb41953..ebc6b71d 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -30,31 +30,31 @@ /* async drv <--> lib comms */ -struct fpi_ssm; -typedef void (*ssm_completed_fn)(struct fpi_ssm *ssm); -typedef void (*ssm_handler_fn)(struct fpi_ssm *ssm); +typedef struct fpi_ssm fpi_ssm; +typedef void (*ssm_completed_fn)(fpi_ssm *ssm); +typedef void (*ssm_handler_fn)(fpi_ssm *ssm); /* sequential state machine: state machine that iterates sequentially over * a predefined series of states. can be aborted by either completion or * abortion error conditions. */ /* for library and drivers */ -struct fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, +fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, int nr_states); -void fpi_ssm_free(struct fpi_ssm *machine); -void fpi_ssm_start(struct fpi_ssm *machine, ssm_completed_fn callback); -void fpi_ssm_start_subsm(struct fpi_ssm *parent, struct fpi_ssm *child); +void fpi_ssm_free(fpi_ssm *machine); +void fpi_ssm_start(fpi_ssm *machine, ssm_completed_fn callback); +void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child); /* for drivers */ -void fpi_ssm_next_state(struct fpi_ssm *machine); -void fpi_ssm_jump_to_state(struct fpi_ssm *machine, int state); -void fpi_ssm_mark_completed(struct fpi_ssm *machine); -void fpi_ssm_mark_aborted(struct fpi_ssm *machine, int error); -struct fp_dev *fpi_ssm_get_dev(struct fpi_ssm *machine); -void fpi_ssm_set_user_data(struct fpi_ssm *machine, +void fpi_ssm_next_state(fpi_ssm *machine); +void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); +void fpi_ssm_mark_completed(fpi_ssm *machine); +void fpi_ssm_mark_aborted(fpi_ssm *machine, int error); +struct fp_dev *fpi_ssm_get_dev(fpi_ssm *machine); +void fpi_ssm_set_user_data(fpi_ssm *machine, void *user_data); -void *fpi_ssm_get_user_data(struct fpi_ssm *machine); -int fpi_ssm_get_error(struct fpi_ssm *machine); -int fpi_ssm_get_cur_state(struct fpi_ssm *machine); +void *fpi_ssm_get_user_data(fpi_ssm *machine); +int fpi_ssm_get_error(fpi_ssm *machine); +int fpi_ssm_get_cur_state(fpi_ssm *machine); #endif From 10e934e234cde597c92b27282dd7549995a7f7da Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 13:11:51 +0200 Subject: [PATCH 043/225] lib: Add fpi_ssm API documentation --- doc/libfprint-docs.xml | 5 +- doc/libfprint-sections.txt | 22 +++++ libfprint/fpi-ssm.c | 166 ++++++++++++++++++++++++++++++------- libfprint/fpi-ssm.h | 31 +++++-- 4 files changed, 183 insertions(+), 41 deletions(-) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index e56f4b77..8f8622d3 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -24,7 +24,7 @@ - API Documentation + Library API Documentation @@ -36,11 +36,10 @@ - API Index diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index a4294953..332a8fa7 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -140,3 +140,25 @@ fp_img_get_minutiae fprint.h poll + +
+fpi-ssm.h +fpi-ssm +fpi_ssm +ssm_completed_fn +ssm_handler_fn + +fpi_ssm_new +fpi_ssm_free +fpi_ssm_start +fpi_ssm_start_subsm + +fpi_ssm_next_state +fpi_ssm_jump_to_state +fpi_ssm_mark_completed +fpi_ssm_mark_aborted +fpi_ssm_set_user_data +fpi_ssm_get_user_data +fpi_ssm_get_error +fpi_ssm_get_cur_state +
diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 02669894..aa6ad933 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -25,27 +25,31 @@ #include #include -/* SSM: sequential state machine +/** + * SECTION:fpi-ssm + * @title: Sequential state machine + * * Asynchronous driver design encourages some kind of state machine behind it. * In most cases, the state machine is entirely linear - you only go to the - * next state, you never jump or go backwards. The SSM functions help you + * next state, you never jump or go backwards. The #fpi_ssm functions help you * implement such a machine. * - * e.g. S1 --> S2 --> S3 --> S4 - * S1 is the start state + * e.g. `S1` ↦ `S2` ↦ `S3` ↦ `S4` + * + * `S1` is the start state * There is also an implicit error state and an implicit accepting state * (both with implicit edges from every state). * * You can also jump to any arbitrary state (while marking completion of the * current state) while the machine is running. In other words there are - * implicit edges linking one state to every other state. OK, we're stretching - * the "state machine" description at this point. + * implicit edges linking one state to every other state. * - * To create a ssm, you pass a state handler function and the total number of - * states (4 in the above example). + * To create an #fpi_ssm, you pass a state handler function and the total number of + * states (4 in the above example) to fpi_ssm_new(). Note that the state numbers + * start at zero, making them match the first value in a C enumeration. * - * To start a ssm, you pass in a completion callback function which gets - * called when the ssm completes (both on error and on failure). + * To start a ssm, you pass in a completion callback function to fpi_ssm_start() + * which gets called when the ssm completes (both on error and on failure). * * To iterate to the next state, call fpi_ssm_next_state(). It is legal to * attempt to iterate beyond the final state - this is equivalent to marking @@ -57,21 +61,20 @@ * To mark failed completion of a SSM, call fpi_ssm_mark_aborted() from any * state. You must pass a non-zero error code. * - * Your state handling function looks at ssm->cur_state in order to determine - * the current state and hence which operations to perform (a switch statement - * is appropriate). - * Typically, the state handling function fires off an asynchronous libusb - * transfer, and the callback function iterates the machine to the next state - * upon success (or aborts the machine on transfer failure). + * Your state handling function looks at the return value of + * fpi_ssm_get_cur_state() in order to determine the current state and hence + * which operations to perform (a switch statement is appropriate). * - * Your completion callback should examine ssm->error in order to determine - * whether the ssm completed or failed. An error code of zero indicates - * successful completion. + * Typically, the state handling function fires off an asynchronous + * communication with the device (such as a libsub transfer), and the + * callback function iterates the machine to the next state + * upon success (or aborts the machine on failure). + * + * Your completion callback should examine the return value of + * fpi_ssm_get_error() in order to determine whether the #fpi_ssm completed or + * failed. An error code of zero indicates successful completion. */ -/* sequential state machine: state machine that iterates sequentially over - * a predefined series of states. can be aborted by either completion or - * abortion error conditions. */ struct fpi_ssm { struct fp_dev *dev; fpi_ssm *parentsm; @@ -84,7 +87,17 @@ struct fpi_ssm { ssm_handler_fn handler; }; -/* Allocate a new ssm */ +/** + * fpi_ssm_new: + * @dev: a #fp_dev fingerprint device + * @handler: the callback function + * @nr_states: the number of states + * + * Allocate a new ssm, with @nr_states states. The @handler callback + * will be called after each state transition. + * + * Returns: a new #fpi_ssm state machine + */ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, int nr_states) { @@ -99,12 +112,29 @@ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, return machine; } +/** + * fpi_ssm_get_dev: + * @machine: an #fpi_ssm state machine + * + * Returns the #fp_dev attached to the #fpi_ssm as passed + * in fpi_ssm_new(). + * + * Returns: a struct #fp_dev + */ struct fp_dev * fpi_ssm_get_dev(fpi_ssm *machine) { return machine->dev; } +/** + * fpi_ssm_set_user_data: + * @machine: an #fpi_ssm state machine + * @user_data: a pointer to user data + * + * Set a user data pointer in the #fpi_ssm structure, to be + * retrieved with fpi_ssm_get_user_data() at a later point. + */ void fpi_ssm_set_user_data(fpi_ssm *machine, void *user_data) @@ -112,13 +142,28 @@ fpi_ssm_set_user_data(fpi_ssm *machine, machine->priv = user_data; } +/** + * fpi_ssm_get_user_data: + * @machine: an #fpi_ssm state machine + * + * Retrieve the pointer to user data set with + * fpi_ssm_set_user_data(). + * + * Returns: a pointer + */ void * fpi_ssm_get_user_data(fpi_ssm *machine) { return machine->priv; } -/* Free a ssm */ +/** + * fpi_ssm_free: + * @machine: an #fpi_ssm state machine + * + * Frees a state machine. This does not call any error or success + * callbacks, so you need to do this yourself. + */ void fpi_ssm_free(fpi_ssm *machine) { if (!machine) @@ -133,7 +178,15 @@ static void __ssm_call_handler(fpi_ssm *machine) machine->handler(machine); } -/* Start a ssm. You can also restart a completed or aborted ssm. */ +/** + * fpi_ssm_start: + * @ssm: an #fpi_ssm state machine + * @callback: the #ssm_completed_fn callback to call on completion + * + * Starts a state machine. You can also use this function to restart + * a completed or aborted state machine. The @callback will be called + * on completion. + */ void fpi_ssm_start(fpi_ssm *ssm, ssm_completed_fn callback) { BUG_ON(!ssm->completed); @@ -155,17 +208,30 @@ static void __subsm_complete(fpi_ssm *ssm) fpi_ssm_free(ssm); } -/* start a SSM as a child of another. if the child completes successfully, the - * parent will be advanced to the next state. if the child aborts, the parent - * will be aborted with the same error code. the child will be automatically - * freed upon completion/abortion. */ +/** + * fpi_ssm_start_subsm: + * @parent: an #fpi_ssm state machine + * @child: an #fpi_ssm state machine + * + * Starts a state machine as a child of another. if the child completes + * successfully, the parent will be advanced to the next state. if the + * child aborts, the parent will be aborted with the same error code. + * + * The child will be automatically freed upon completion or abortion. + */ void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child) { child->parentsm = parent; fpi_ssm_start(child, __subsm_complete); } -/* Mark a ssm as completed successfully. */ +/** + * fpi_ssm_mark_completed: + * @machine: an #fpi_ssm state machine + * + * Mark a ssm as completed successfully. The callback set when creating + * the state machine with fpi_ssm_new() will be called synchronously. + */ void fpi_ssm_mark_completed(fpi_ssm *machine) { BUG_ON(machine->completed); @@ -175,7 +241,13 @@ void fpi_ssm_mark_completed(fpi_ssm *machine) machine->callback(machine); } -/* Mark a ssm as aborted with error. */ +/** + * fpi_ssm_mark_aborted: + * @machine: an #fpi_ssm state machine + * @error: the error code + * + * Mark a state machine as aborted with error. + */ void fpi_ssm_mark_aborted(fpi_ssm *machine, int error) { fp_dbg("error %d from state %d", error, machine->cur_state); @@ -184,7 +256,14 @@ void fpi_ssm_mark_aborted(fpi_ssm *machine, int error) fpi_ssm_mark_completed(machine); } -/* Iterate to next state of a ssm */ +/** + * fpi_ssm_next_state: + * @machine: an #fpi_ssm state machine + * + * Iterate to next state of a state machine. If the current state is the + * last state, then the state machine will be marked as completed, as + * if calling fpi_ssm_mark_completed(). + */ void fpi_ssm_next_state(fpi_ssm *machine) { BUG_ON(machine->completed); @@ -196,6 +275,12 @@ void fpi_ssm_next_state(fpi_ssm *machine) } } +/** + * fpi_ssm_jump_to_state: + * @machine: an #fpi_ssm state machine + * @state: the state to jump to + * + */ void fpi_ssm_jump_to_state(fpi_ssm *machine, int state) { BUG_ON(machine->completed); @@ -204,11 +289,28 @@ void fpi_ssm_jump_to_state(fpi_ssm *machine, int state) __ssm_call_handler(machine); } +/** + * fpi_ssm_get_cur_state: + * @machine: an #fpi_ssm state machine + * + * Returns the value of the current state. Note that states are + * 0-indexed, so a value of 0 means “the first state”. + * + * Returns: the current state. + */ int fpi_ssm_get_cur_state(fpi_ssm *machine) { return machine->cur_state; } +/** + * fpi_ssm_get_error: + * @machine: an #fpi_ssm state machine + * + * Returns the error code set by fpi_ssm_mark_aborted(). + * + * Returns: a error code + */ int fpi_ssm_get_error(fpi_ssm *machine) { return machine->error; diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index ebc6b71d..37a626bb 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -30,19 +30,38 @@ /* async drv <--> lib comms */ +/** + * fpi_ssm: + * + * Sequential state machine that iterates sequentially over + * a predefined series of states. Can be aborted by either completion or + * abortion error conditions. + */ typedef struct fpi_ssm fpi_ssm; -typedef void (*ssm_completed_fn)(fpi_ssm *ssm); -typedef void (*ssm_handler_fn)(fpi_ssm *ssm); -/* sequential state machine: state machine that iterates sequentially over - * a predefined series of states. can be aborted by either completion or - * abortion error conditions. */ +/** + * ssm_completed_fn: + * @ssm: a #fpi_ssm state machine + * + * The callback called when a state machine completes successfully, + * as set when calling fpi_ssm_start(). + */ +typedef void (*ssm_completed_fn)(fpi_ssm *ssm); + +/** + * ssm_handler_fn: + * @ssm: a #fpi_ssm state machine + * + * The callback called when a state machine transitions from one + * state to the next, as set when calling fpi_ssm_new(). + */ +typedef void (*ssm_handler_fn)(fpi_ssm *ssm); /* for library and drivers */ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, int nr_states); void fpi_ssm_free(fpi_ssm *machine); -void fpi_ssm_start(fpi_ssm *machine, ssm_completed_fn callback); +void fpi_ssm_start(fpi_ssm *ssm, ssm_completed_fn callback); void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child); /* for drivers */ From 603aab0a81a7a4fe87d28ea6d5504a1d9d6d7b8a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 16:29:26 +0200 Subject: [PATCH 044/225] lib: Rename fpi_ssm_mark_aborted to fpi_ssm_mark_failed --- doc/libfprint-sections.txt | 2 +- libfprint/drivers/aes1610.c | 20 ++++----- libfprint/drivers/aes2501.c | 26 ++++++------ libfprint/drivers/aes2550.c | 42 +++++++++---------- libfprint/drivers/aesx660.c | 34 ++++++++-------- libfprint/drivers/elan.c | 24 +++++------ libfprint/drivers/etes603.c | 16 ++++---- libfprint/drivers/upeksonly.c | 26 ++++++------ libfprint/drivers/upektc.c | 26 ++++++------ libfprint/drivers/upektc_img.c | 30 +++++++------- libfprint/drivers/upekts.c | 74 +++++++++++++++++----------------- libfprint/drivers/uru4000.c | 40 +++++++++--------- libfprint/drivers/vcom5s.c | 18 ++++----- libfprint/drivers/vfs0050.c | 26 ++++++------ libfprint/drivers/vfs101.c | 38 ++++++++--------- libfprint/drivers/vfs301.c | 2 +- libfprint/drivers/vfs5011.c | 34 ++++++++-------- libfprint/fpi-ssm.c | 20 ++++----- libfprint/fpi-ssm.h | 6 +-- 19 files changed, 252 insertions(+), 252 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 332a8fa7..1f99e5a1 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -156,7 +156,7 @@ fpi_ssm_start_subsm fpi_ssm_next_state fpi_ssm_jump_to_state fpi_ssm_mark_completed -fpi_ssm_mark_aborted +fpi_ssm_mark_failed fpi_ssm_set_user_data fpi_ssm_get_user_data fpi_ssm_get_error diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index 46d75c5c..fe5de8db 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -104,9 +104,9 @@ static void generic_ignore_data_cb(struct libusb_transfer *transfer) fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else if (transfer->length != transfer->actual_length) - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); else fpi_ssm_next_state(ssm); @@ -121,7 +121,7 @@ static void generic_write_regv_cb(struct fp_img_dev *dev, int result, if (result == 0) fpi_ssm_next_state(ssm); else - fpi_ssm_mark_aborted(ssm, result); + fpi_ssm_mark_failed(ssm, result); } /* read the specified number of bytes from the IN endpoint but throw them @@ -134,7 +134,7 @@ static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -147,7 +147,7 @@ static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -564,10 +564,10 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer) int sum, i; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } else if (transfer->length != transfer->actual_length) { - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } @@ -594,7 +594,7 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer) } if (sum < 0) { - fpi_ssm_mark_aborted(ssm, sum); + fpi_ssm_mark_failed(ssm, sum); goto out; } fp_dbg("sum=%d", sum); @@ -672,7 +672,7 @@ static void capture_run_state(fpi_ssm *ssm) unsigned char *data; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -684,7 +684,7 @@ static void capture_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } break; }; diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index e736a9e2..ea626474 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -184,7 +184,7 @@ static void generic_write_regv_cb(struct fp_img_dev *dev, int result, if (result == 0) fpi_ssm_next_state(ssm); else - fpi_ssm_mark_aborted(ssm, result); + fpi_ssm_mark_failed(ssm, result); } /* check that read succeeded but ignore all data */ @@ -193,9 +193,9 @@ static void generic_ignore_data_cb(struct libusb_transfer *transfer) fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else if (transfer->length != transfer->actual_length) - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); else fpi_ssm_next_state(ssm); @@ -213,7 +213,7 @@ static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -225,7 +225,7 @@ static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -444,23 +444,23 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer) int threshold; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } else if (transfer->length != transfer->actual_length) { - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } threshold = regval_from_dump(data + 1 + 192*8 + 1 + 16*2 + 1 + 8, AES2501_REG_DATFMT); if (threshold < 0) { - fpi_ssm_mark_aborted(ssm, threshold); + fpi_ssm_mark_failed(ssm, threshold); goto out; } sum = sum_histogram_values(data + 1 + 192*8, threshold & 0x0f); if (sum < 0) { - fpi_ssm_mark_aborted(ssm, sum); + fpi_ssm_mark_failed(ssm, sum); goto out; } fp_dbg("sum=%d", sum); @@ -553,7 +553,7 @@ static void capture_run_state(fpi_ssm *ssm) unsigned char *data; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -565,7 +565,7 @@ static void capture_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } break; }; @@ -717,7 +717,7 @@ void activate_read_regs_cb(struct fp_img_dev *dev, int status, struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); if (status != 0) { - fpi_ssm_mark_aborted(ssm, status); + fpi_ssm_mark_failed(ssm, status); } else { fp_dbg("reg 0xaf = %x", regs[0x5f]); if (regs[0x5f] != 0x6b || ++aesdev->read_regs_retry_count == 13) @@ -734,7 +734,7 @@ static void activate_init3_cb(struct fp_img_dev *dev, int result, if (result == 0) fpi_ssm_jump_to_state(ssm, READ_REGS); else - fpi_ssm_mark_aborted(ssm, result); + fpi_ssm_mark_failed(ssm, result); } static void activate_run_state(fpi_ssm *ssm) diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 0fc9eb92..1916aa15 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -237,7 +237,7 @@ static void capture_reqs_cb(struct libusb_transfer *transfer) (transfer->length == transfer->actual_length)) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -265,7 +265,7 @@ static void capture_set_idle_reqs_cb(struct libusb_transfer *transfer) /* marking machine complete will re-trigger finger detection loop */ fpi_ssm_mark_completed(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -280,7 +280,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fp_dbg("request is not completed, %d", transfer->status); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } @@ -293,7 +293,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) r = process_strip_data(ssm, data); if (r < 0) { fp_dbg("Processing strip data failed: %d", r); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } aesdev->heartbeat_cnt = 0; @@ -333,7 +333,7 @@ static void capture_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, capture_reqs, @@ -341,7 +341,7 @@ static void capture_run_state(fpi_ssm *ssm) r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); } } break; @@ -351,7 +351,7 @@ static void capture_run_state(fpi_ssm *ssm) unsigned char *data; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -363,7 +363,7 @@ static void capture_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } break; @@ -371,7 +371,7 @@ static void capture_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, capture_set_idle_reqs, @@ -379,7 +379,7 @@ static void capture_run_state(fpi_ssm *ssm) r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); } } break; @@ -450,7 +450,7 @@ static void init_reqs_cb(struct libusb_transfer *transfer) (transfer->length == transfer->actual_length)) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -462,7 +462,7 @@ static void init_read_data_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } g_free(transfer->buffer); libusb_free_transfer(transfer); @@ -477,7 +477,7 @@ static void calibrate_read_data_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } g_free(transfer->buffer); libusb_free_transfer(transfer); @@ -493,7 +493,7 @@ static void activate_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, init_reqs, @@ -501,7 +501,7 @@ static void activate_run_state(fpi_ssm *ssm) r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); } } break; @@ -511,7 +511,7 @@ static void activate_run_state(fpi_ssm *ssm) unsigned char *data; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -523,7 +523,7 @@ static void activate_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } break; @@ -531,7 +531,7 @@ static void activate_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, calibrate_reqs, @@ -539,7 +539,7 @@ static void activate_run_state(fpi_ssm *ssm) r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); } } break; @@ -549,7 +549,7 @@ static void activate_run_state(fpi_ssm *ssm) unsigned char *data; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -561,7 +561,7 @@ static void activate_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } break; diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index bb9709d2..15852552 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -45,7 +45,7 @@ static void aesX660_send_cmd_timeout(fpi_ssm *ssm, const unsigned char *cmd, int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -56,7 +56,7 @@ static void aesX660_send_cmd_timeout(fpi_ssm *ssm, const unsigned char *cmd, if (r < 0) { fp_dbg("failed to submit transfer\n"); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); } } @@ -75,7 +75,7 @@ static void aesX660_read_response(fpi_ssm *ssm, size_t buf_len, int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -89,7 +89,7 @@ static void aesX660_read_response(fpi_ssm *ssm, size_t buf_len, fp_dbg("Failed to submit rx transfer: %d\n", r); g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -103,7 +103,7 @@ static void aesX660_send_cmd_cb(struct libusb_transfer *transfer) } else { fp_dbg("tx transfer status: %d, actual_len: %.4x\n", transfer->status, transfer->actual_length); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -115,13 +115,13 @@ static void aesX660_read_calibrate_data_cb(struct libusb_transfer *transfer) if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || (transfer->length != transfer->actual_length)) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } /* Calibrate response was read correctly? */ if (data[AESX660_RESPONSE_TYPE_OFFSET] != AESX660_CALIBRATE_RESPONSE) { fp_dbg("Bogus calibrate response: %.2x\n", data[0]); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } @@ -159,13 +159,13 @@ static void finger_det_read_fd_data_cb(struct libusb_transfer *transfer) if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || (transfer->length != transfer->actual_length)) { fp_dbg("Failed to read FD data\n"); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } if (data[AESX660_RESPONSE_TYPE_OFFSET] != AESX660_FINGER_DET_RESPONSE) { fp_dbg("Bogus FD response: %.2x\n", data[0]); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } @@ -190,7 +190,7 @@ static void finger_det_set_idle_cmd_cb(struct libusb_transfer *transfer) (transfer->length == transfer->actual_length)) { fpi_ssm_mark_completed(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -313,7 +313,7 @@ static void capture_set_idle_cmd_cb(struct libusb_transfer *transfer) fpi_imgdev_report_finger_status(dev, FALSE); fpi_ssm_mark_completed(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -328,7 +328,7 @@ static void capture_read_stripe_data_cb(struct libusb_transfer *transfer) size_t copied, actual_len = transfer->actual_length; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } @@ -456,7 +456,7 @@ static void activate_read_id_cb(struct libusb_transfer *transfer) if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || (transfer->length != transfer->actual_length)) { fp_dbg("read_id cmd failed\n"); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } /* ID was read correctly */ @@ -465,7 +465,7 @@ static void activate_read_id_cb(struct libusb_transfer *transfer) data[4], data[3], data[5], data[6], data[7]); } else { fp_dbg("Bogus read ID response: %.2x\n", data[AESX660_RESPONSE_TYPE_OFFSET]); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } @@ -487,7 +487,7 @@ static void activate_read_id_cb(struct libusb_transfer *transfer) break; default: fp_dbg("Failed to init device! init status: %.2x\n", data[7]); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); break; } @@ -509,14 +509,14 @@ static void activate_read_init_cb(struct libusb_transfer *transfer) if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || (transfer->length != transfer->actual_length)) { fp_dbg("read_init transfer status: %d, actual_len: %d\n", transfer->status, transfer->actual_length); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } /* ID was read correctly */ if (data[0] != 0x42 || data[3] != 0x01) { fp_dbg("Bogus read init response: %.2x %.2x\n", data[0], data[3]); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } aesdev->init_cmd_idx++; diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index d8a24a63..a3b3e538 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -335,7 +335,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) fp_dbg("transfer length error: expected %d, got %d", transfer->length, transfer->actual_length); elan_dev_reset(elandev); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); } else if (transfer->endpoint & LIBUSB_ENDPOINT_IN) { /* just finished receiving */ dbg_buf(elandev->last_read, transfer->actual_length); @@ -348,17 +348,17 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) break; case LIBUSB_TRANSFER_CANCELLED: fp_dbg("transfer cancelled"); - fpi_ssm_mark_aborted(ssm, -ECANCELED); + fpi_ssm_mark_failed(ssm, -ECANCELED); elan_deactivate(dev); break; case LIBUSB_TRANSFER_TIMED_OUT: fp_dbg("transfer timed out"); - fpi_ssm_mark_aborted(ssm, -ETIMEDOUT); + fpi_ssm_mark_failed(ssm, -ETIMEDOUT); break; default: fp_dbg("transfer failed: %d", transfer->status); elan_dev_reset(elandev); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -383,7 +383,7 @@ static void elan_cmd_read(fpi_ssm *ssm) struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } elandev->cur_transfer = transfer; @@ -398,7 +398,7 @@ static void elan_cmd_read(fpi_ssm *ssm) transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; int r = libusb_submit_transfer(transfer); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } static void elan_run_cmd(fpi_ssm *ssm, const struct elan_cmd *cmd, @@ -421,7 +421,7 @@ static void elan_run_cmd(fpi_ssm *ssm, const struct elan_cmd *cmd, struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } elandev->cur_transfer = transfer; @@ -432,7 +432,7 @@ static void elan_run_cmd(fpi_ssm *ssm, const struct elan_cmd *cmd, transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; int r = libusb_submit_transfer(transfer); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } enum stop_capture_states { @@ -521,12 +521,12 @@ static void capture_run_state(fpi_ssm *ssm) fpi_imgdev_report_finger_status(dev, TRUE); elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); } else - fpi_ssm_mark_aborted(ssm, -EBADMSG); + fpi_ssm_mark_failed(ssm, -EBADMSG); break; case CAPTURE_CHECK_ENOUGH_FRAMES: r = elan_save_img_frame(elandev); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); else if (elandev->num_frames < ELAN_MAX_FRAMES) { /* quickly stop if finger is removed */ elandev->cmd_timeout = ELAN_FINGER_TIMEOUT; @@ -660,7 +660,7 @@ static void calibrate_run_state(fpi_ssm *ssm) ELAN_CMD_TIMEOUT); else { fp_dbg("calibration failed"); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } break; case CALIBRATE_CHECK_STATUS: @@ -680,7 +680,7 @@ static void calibrate_run_state(fpi_ssm *ssm) && elandev->last_read[0] == 0x01) elandev->calib_status = 0x01; if (!fpi_timeout_add(50, fpi_ssm_next_state_async, ssm)) - fpi_ssm_mark_aborted(ssm, -ETIME); + fpi_ssm_mark_failed(ssm, -ETIME); } break; case CALIBRATE_REPEAT_STATUS: diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index 2c61f17e..2e2799ba 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -676,7 +676,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fp_warn("transfer is not completed (status=%d)", transfer->status); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); libusb_free_transfer(transfer); } else { unsigned char endpoint = transfer->endpoint; @@ -691,7 +691,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) length, actual_length); /* Chained with the answer */ if (async_tx(idev, EP_IN, async_tx_cb, ssm)) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } else if (endpoint == EP_IN) { dev->ans_len = actual_length; fpi_ssm_next_state(ssm); @@ -724,7 +724,7 @@ static void m_exit_state(fpi_ssm *ssm) return; err: - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } static void m_exit_complete(fpi_ssm *ssm) @@ -827,7 +827,7 @@ static void m_capture_state(fpi_ssm *ssm) return; err: - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } static void m_capture_complete(fpi_ssm *ssm) @@ -945,7 +945,7 @@ static void m_finger_state(fpi_ssm *ssm) return; err: - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } static void m_finger_complete(fpi_ssm *ssm) @@ -1131,7 +1131,7 @@ static void m_tunevrb_state(fpi_ssm *ssm) return; err: - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } static void m_tunevrb_complete(fpi_ssm *ssm) @@ -1255,7 +1255,7 @@ static void m_tunedc_state(fpi_ssm *ssm) return; err: - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } @@ -1375,7 +1375,7 @@ static void m_init_state(fpi_ssm *ssm) return; err: - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index ff22bd66..62a61a15 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -180,7 +180,7 @@ static void last_transfer_killed(struct fp_img_dev *dev) switch (sdev->killing_transfers) { case ABORT_SSM: fp_dbg("abort ssm error %d", sdev->kill_status_code); - fpi_ssm_mark_aborted(sdev->kill_ssm, sdev->kill_status_code); + fpi_ssm_mark_failed(sdev->kill_ssm, sdev->kill_status_code); return; case ITERATE_SSM: fp_dbg("iterate ssm"); @@ -534,7 +534,7 @@ static void write_regs_finished(struct write_regs_data *wrdata, int result) if (result == 0) fpi_ssm_next_state(wrdata->ssm); else - fpi_ssm_mark_aborted(wrdata->ssm, result); + fpi_ssm_mark_failed(wrdata->ssm, result); g_free(wrdata); } @@ -584,7 +584,7 @@ static void sm_write_regs(fpi_ssm *ssm, wrdata->transfer = libusb_alloc_transfer(0); if (!wrdata->transfer) { g_free(wrdata); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -608,7 +608,7 @@ static void sm_write_reg_cb(struct libusb_transfer *transfer) fpi_ssm *ssm = transfer->user_data; g_free(transfer->buffer); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else fpi_ssm_next_state(ssm); @@ -622,7 +622,7 @@ static void sm_write_reg(fpi_ssm *ssm, uint8_t reg, uint8_t value) int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -641,7 +641,7 @@ static void sm_write_reg(fpi_ssm *ssm, uint8_t reg, uint8_t value) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -652,7 +652,7 @@ static void sm_read_reg_cb(struct libusb_transfer *transfer) struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } else { sdev->read_reg_result = libusb_control_transfer_get_data(transfer)[0]; fp_dbg("read reg result = %02x", sdev->read_reg_result); @@ -670,7 +670,7 @@ static void sm_read_reg(fpi_ssm *ssm, uint8_t reg) int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -687,7 +687,7 @@ static void sm_read_reg(fpi_ssm *ssm, uint8_t reg) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -699,7 +699,7 @@ static void sm_await_intr_cb(struct libusb_transfer *transfer) if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { g_free(transfer->buffer); - fpi_ssm_mark_aborted(ssm, transfer->status); + fpi_ssm_mark_failed(ssm, transfer->status); return; } @@ -721,7 +721,7 @@ static void sm_await_intr(fpi_ssm *ssm) int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -737,7 +737,7 @@ static void sm_await_intr(fpi_ssm *ssm) if (r < 0) { libusb_free_transfer(transfer); g_free(data); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -861,7 +861,7 @@ static void capsm_fire_bulk(fpi_ssm *ssm) if (r < 0) { if (i == 0) { /* first one failed: easy peasy */ - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); return; } diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index d94a3fcc..e70d204b 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -81,7 +81,7 @@ static void write_init_cb(struct libusb_transfer *transfer) else upektc_next_init_cmd(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -93,7 +93,7 @@ static void read_init_data_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_COMPLETED) upektc_next_init_cmd(ssm); else - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); g_free(transfer->buffer); libusb_free_transfer(transfer); } @@ -109,7 +109,7 @@ static void activate_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_out, @@ -118,7 +118,7 @@ static void activate_run_state(fpi_ssm *ssm) r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); } } break; @@ -128,7 +128,7 @@ static void activate_run_state(fpi_ssm *ssm) unsigned char *data; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -141,7 +141,7 @@ static void activate_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } break; @@ -289,7 +289,7 @@ static void capture_cmd_cb(struct libusb_transfer *transfer) (transfer->length == transfer->actual_length)) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } libusb_free_transfer(transfer); } @@ -303,11 +303,11 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fp_dbg("request is not completed, %d", transfer->status); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } else if (transfer->length != transfer->actual_length) { fp_dbg("expected %d, sent %d bytes", transfer->length, transfer->actual_length); - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); goto out; } @@ -332,7 +332,7 @@ static void capture_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_out, @@ -341,7 +341,7 @@ static void capture_run_state(fpi_ssm *ssm) r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); } } break; @@ -351,7 +351,7 @@ static void capture_run_state(fpi_ssm *ssm) unsigned char *data; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -363,7 +363,7 @@ static void capture_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } break; diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 424b9eca..495b6790 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -83,7 +83,7 @@ static void upektc_img_submit_req(fpi_ssm *ssm, BUG_ON(buf_size > MAX_CMD_SIZE); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -99,7 +99,7 @@ static void upektc_img_submit_req(fpi_ssm *ssm, r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -111,7 +111,7 @@ static void upektc_img_read_data(fpi_ssm *ssm, size_t buf_size, size_t buf_offse int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -125,7 +125,7 @@ static void upektc_img_read_data(fpi_ssm *ssm, size_t buf_size, size_t buf_offse r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -148,7 +148,7 @@ static void capture_reqs_cb(struct libusb_transfer *transfer) if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || (transfer->length != transfer->actual_length)) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } switch (fpi_ssm_get_cur_state(ssm)) { @@ -190,7 +190,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fp_dbg("request is not completed, %d", transfer->status); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } @@ -291,7 +291,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) break; default: fp_err("Uknown response!\n"); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); break; } break; @@ -300,7 +300,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) break; default: fp_err("Not handled response!\n"); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -386,7 +386,7 @@ static void deactivate_reqs_cb(struct libusb_transfer *transfer) (transfer->length == transfer->actual_length)) { fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -398,7 +398,7 @@ static void deactivate_read_data_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_mark_completed(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -472,7 +472,7 @@ static void init_reqs_ctrl_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -484,7 +484,7 @@ static void init_reqs_cb(struct libusb_transfer *transfer) (transfer->length == transfer->actual_length)) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -496,7 +496,7 @@ static void init_read_data_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_next_state(ssm); } else { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -516,7 +516,7 @@ static void activate_run_state(fpi_ssm *ssm) transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER | @@ -531,7 +531,7 @@ static void activate_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } break; diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index af383eb1..283ab019 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -494,15 +494,15 @@ static void initsm_read_msg_response_cb(fpi_ssm *ssm, if (status != READ_MSG_RESPONSE) { fp_err("expected response, got %d seq=%x in state %d", status, seq, fpi_ssm_get_cur_state(ssm)); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } else if (subcmd != expect_subcmd) { fp_warn("expected response to subcmd 0x%02x, got response to %02x in " "state %d", expect_subcmd, subcmd, fpi_ssm_get_cur_state(ssm)); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } else if (seq != upekdev->seq) { fp_err("expected response to cmd seq=%02x, got response to %02x " "in state %d", upekdev->seq, seq, fpi_ssm_get_cur_state(ssm)); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } else { fp_dbg("state %d completed", fpi_ssm_get_cur_state(ssm)); fpi_ssm_next_state(ssm); @@ -556,19 +556,19 @@ static void initsm_read_msg_cmd_cb(fpi_ssm *ssm, struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); if (status == READ_MSG_ERROR) { - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); return; } else if (status != READ_MSG_CMD) { fp_err("expected command, got %d seq=%x in state %d", status, seq, fpi_ssm_get_cur_state(ssm)); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); return; } upekdev->seq = seq; if (seq != expect_seq) { fp_err("expected seq=%x, got %x in state %d", expect_seq, seq, fpi_ssm_get_cur_state(ssm)); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); return; } @@ -596,7 +596,7 @@ static void ctrl400_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_COMPLETED) fpi_ssm_next_state(ssm); else - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); g_free(transfer->buffer); libusb_free_transfer(transfer); } @@ -607,7 +607,7 @@ static void initsm_read_msg_handler(fpi_ssm *ssm, int r = read_msg_async(fpi_ssm_get_dev(ssm), callback, ssm); if (r < 0) { fp_err("async read msg failed in state %d", fpi_ssm_get_cur_state(ssm)); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -621,7 +621,7 @@ static void initsm_send_msg_cb(struct libusb_transfer *transfer) } else { fp_err("failed, state=%d rqlength=%d actual_length=%d", fpi_ssm_get_cur_state(ssm), transfer->length, transfer->actual_length); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } libusb_free_transfer(transfer); } @@ -636,7 +636,7 @@ static void initsm_send_msg28_handler(fpi_ssm *ssm, transfer = alloc_send_cmd28_transfer(dev, subcmd, data, innerlen, initsm_send_msg_cb, ssm); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -645,7 +645,7 @@ static void initsm_send_msg28_handler(fpi_ssm *ssm, fp_err("urb submission failed error %d in state %d", r, fpi_ssm_get_cur_state(ssm)); g_free(transfer->buffer); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -662,7 +662,7 @@ static void initsm_run_state(fpi_ssm *ssm) transfer = libusb_alloc_transfer(0); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -676,7 +676,7 @@ static void initsm_run_state(fpi_ssm *ssm) if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } break; case READ_MSG03: @@ -686,7 +686,7 @@ static void initsm_run_state(fpi_ssm *ssm) transfer = alloc_send_cmdresponse_transfer(dev, ++upekdev->seq, init_resp03, sizeof(init_resp03), initsm_send_msg_cb, ssm); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -694,7 +694,7 @@ static void initsm_run_state(fpi_ssm *ssm) if (r < 0) { g_free(transfer->buffer); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } break; case READ_MSG05: @@ -751,9 +751,9 @@ static void send_resp07_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else if (transfer->length != transfer->actual_length) - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); else fpi_ssm_next_state(ssm); libusb_free_transfer(transfer); @@ -767,17 +767,17 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); if (status == READ_MSG_ERROR) { - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); return; } else if (status != READ_MSG_CMD) { fp_err("expected command, got %d seq=%x", status, seq); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); return; } upekdev->seq = seq; if (seq != 1) { fp_err("expected seq=1, got %x", seq); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); return; } @@ -797,7 +797,7 @@ static void deinitsm_state_handler(fpi_ssm *ssm) transfer = alloc_send_cmdresponse_transfer(dev, 0x07, &dummy, 1, send_resp07_cb, ssm); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -805,13 +805,13 @@ static void deinitsm_state_handler(fpi_ssm *ssm) if (r < 0) { g_free(transfer->buffer); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } break; case READ_MSG01: ; r = read_msg_async(dev, read_msg01_cb, ssm); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); break; } } @@ -875,7 +875,7 @@ static void enroll_start_sm_cb_initsm(fpi_ssm *initsm) fpi_ssm_free(initsm); if (error) - fpi_ssm_mark_aborted(enroll_start_ssm, error); + fpi_ssm_mark_failed(enroll_start_ssm, error); else fpi_ssm_next_state(enroll_start_ssm); } @@ -885,9 +885,9 @@ static void enroll_start_sm_cb_init(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else if (transfer->length != transfer->actual_length) - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); else fpi_ssm_next_state(ssm); libusb_free_transfer(transfer); @@ -902,15 +902,15 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev, if (status != READ_MSG_RESPONSE) { fp_err("expected response, got %d seq=%x", status, seq); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } else if (subcmd != 0) { fp_warn("expected response to subcmd 0, got response to %02x", subcmd); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } else if (seq != upekdev->seq) { fp_err("expected response to cmd seq=%02x, got response to %02x", upekdev->seq, seq); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } else { fpi_ssm_next_state(ssm); } @@ -932,7 +932,7 @@ static void enroll_start_sm_run_state(fpi_ssm *ssm) transfer = alloc_send_cmd28_transfer(dev, 0x02, enroll_init, sizeof(enroll_init), enroll_start_sm_cb_init, ssm); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -940,7 +940,7 @@ static void enroll_start_sm_run_state(fpi_ssm *ssm) if (r < 0) { g_free(transfer->buffer); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } break; case READ_ENROLL_MSG28: ; @@ -950,7 +950,7 @@ static void enroll_start_sm_run_state(fpi_ssm *ssm) * include a 30 01 poll somewhere? */ r = read_msg_async(dev, enroll_start_sm_cb_msg28, ssm); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); break; } } @@ -1183,7 +1183,7 @@ static void verify_start_sm_cb_initsm(fpi_ssm *initsm) err = fpi_ssm_get_error(initsm); if (err) - fpi_ssm_mark_aborted(verify_start_ssm, err); + fpi_ssm_mark_failed(verify_start_ssm, err); else fpi_ssm_next_state(verify_start_ssm); fpi_ssm_free(initsm); @@ -1193,9 +1193,9 @@ static void verify_init_2803_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else if (transfer->length != transfer->actual_length) - fpi_ssm_mark_aborted(ssm, -EPROTO); + fpi_ssm_mark_failed(ssm, -EPROTO); else fpi_ssm_next_state(ssm); libusb_free_transfer(transfer); @@ -1225,7 +1225,7 @@ static void verify_start_sm_run_state(fpi_ssm *ssm) verify_init_2803_cb, ssm); g_free(data); if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); break; } @@ -1233,7 +1233,7 @@ static void verify_start_sm_run_state(fpi_ssm *ssm) if (r < 0) { g_free(transfer->buffer); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } break; } diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 6c7097ed..fddd4110 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -310,7 +310,7 @@ static void response_cb(struct fp_img_dev *dev, int status, void *user_data) if (status == 0) fpi_ssm_next_state(ssm); else - fpi_ssm_mark_aborted(ssm, status); + fpi_ssm_mark_failed(ssm, status); } static void challenge_cb(struct fp_img_dev *dev, int status, @@ -324,7 +324,7 @@ static void challenge_cb(struct fp_img_dev *dev, int status, r = status; if (status != 0) { - fpi_ssm_mark_aborted(ssm, status); + fpi_ssm_mark_failed(ssm, status); return; } @@ -346,7 +346,7 @@ static void challenge_cb(struct fp_img_dev *dev, int status, g_free(respdata); } if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } /* @@ -362,7 +362,7 @@ static void sm_do_challenge_response(fpi_ssm *ssm) G_DEBUG_HERE(); r = read_regs(dev, REG_CHALLENGE, CR_LENGTH, challenge_cb, ssm); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } /***** INTERRUPT HANDLING *****/ @@ -511,7 +511,7 @@ static void sm_write_reg_cb(struct fp_img_dev *dev, int result, void *user_data) fpi_ssm *ssm = user_data; if (result) - fpi_ssm_mark_aborted(ssm, result); + fpi_ssm_mark_failed(ssm, result); else fpi_ssm_next_state(ssm); } @@ -522,7 +522,7 @@ static void sm_write_regs(fpi_ssm *ssm, uint16_t first_reg, uint16_t num_regs, struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r = write_regs(dev, first_reg, num_regs, data, sm_write_reg_cb, ssm); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } static void sm_write_reg(fpi_ssm *ssm, uint16_t reg, @@ -538,7 +538,7 @@ static void sm_read_reg_cb(struct fp_img_dev *dev, int result, struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); if (result) { - fpi_ssm_mark_aborted(ssm, result); + fpi_ssm_mark_failed(ssm, result); } else { memcpy(urudev->last_reg_rd, data, num_regs); fp_dbg("reg value %x", urudev->last_reg_rd[0]); @@ -553,14 +553,14 @@ static void sm_read_regs(fpi_ssm *ssm, uint16_t reg, uint16_t num_regs) int r; if (num_regs > sizeof(urudev->last_reg_rd)) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } fp_dbg("read %d regs at %x", num_regs, reg); r = read_regs(dev, reg, num_regs, sm_read_reg_cb, ssm); if (r < 0) - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } static void sm_read_reg(fpi_ssm *ssm, uint16_t reg) @@ -591,10 +591,10 @@ static void image_transfer_cb(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { fp_dbg("cancelled"); - fpi_ssm_mark_aborted(ssm, -ECANCELED); + fpi_ssm_mark_failed(ssm, -ECANCELED); } else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fp_dbg("error"); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } else { fpi_ssm_next_state(ssm); } @@ -706,7 +706,7 @@ static void imaging_run_state(fpi_ssm *ssm) urudev->img_data, sizeof(struct uru4k_image), image_transfer_cb, ssm, 0); r = libusb_submit_transfer(urudev->img_transfer); if (r < 0) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); break; case IMAGING_SEND_INDEX: fp_dbg("hw header lines %d", img->num_lines); @@ -868,7 +868,7 @@ static void rebootpwr_pause_cb(void *data) if (!--urudev->rebootpwr_ctr) { fp_err("could not reboot device power"); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } else { fpi_ssm_jump_to_state(ssm, REBOOTPWR_GET_HWSTAT); } @@ -896,7 +896,7 @@ static void rebootpwr_run_state(fpi_ssm *ssm) break; case REBOOTPWR_PAUSE: if (fpi_timeout_add(10, rebootpwr_pause_cb, ssm) == NULL) - fpi_ssm_mark_aborted(ssm, -ETIME); + fpi_ssm_mark_failed(ssm, -ETIME); break; } } @@ -945,7 +945,7 @@ static void powerup_pause_cb(void *data) if (!--urudev->powerup_ctr) { fp_err("could not power device up"); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } else if (!urudev->profile->auth_cr) { fpi_ssm_jump_to_state(ssm, POWERUP_SET_HWSTAT); } else { @@ -979,7 +979,7 @@ static void powerup_run_state(fpi_ssm *ssm) break; case POWERUP_PAUSE: if (fpi_timeout_add(10, powerup_pause_cb, ssm) == NULL) - fpi_ssm_mark_aborted(ssm, -ETIME); + fpi_ssm_mark_failed(ssm, -ETIME); break; case POWERUP_CHALLENGE_RESPONSE: sm_do_challenge_response(ssm); @@ -1028,7 +1028,7 @@ static void init_scanpwr_irq_cb(struct fp_img_dev *dev, int status, struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); if (status) - fpi_ssm_mark_aborted(ssm, status); + fpi_ssm_mark_failed(ssm, status); else if (type != IRQDATA_SCANPWR_ON) fp_dbg("ignoring interrupt"); else if (fpi_ssm_get_cur_state(ssm) != INIT_AWAIT_SCAN_POWER) { @@ -1052,7 +1052,7 @@ static void init_scanpwr_timeout(void *user_data) if (++urudev->scanpwr_irq_timeouts >= 3) { fp_err("powerup timed out 3 times, giving up"); - fpi_ssm_mark_aborted(ssm, -ETIMEDOUT); + fpi_ssm_mark_failed(ssm, -ETIMEDOUT); } else { fpi_ssm_jump_to_state(ssm, INIT_GET_HWSTAT); } @@ -1088,7 +1088,7 @@ static void init_run_state(fpi_ssm *ssm) break; case INIT_POWERUP: ; if (!IRQ_HANDLER_IS_RUNNING(urudev)) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); break; } urudev->irq_cb_data = ssm; @@ -1111,7 +1111,7 @@ static void init_run_state(fpi_ssm *ssm) urudev->scanpwr_irq_timeout = fpi_timeout_add(300, init_scanpwr_timeout, ssm); if (!urudev->scanpwr_irq_timeout) { - fpi_ssm_mark_aborted(ssm, -ETIME); + fpi_ssm_mark_failed(ssm, -ETIME); break; } break; diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index e54a7f39..539ffadf 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -77,7 +77,7 @@ static void sm_write_reg_cb(struct libusb_transfer *transfer) fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else fpi_ssm_next_state(ssm); @@ -94,7 +94,7 @@ static void sm_write_reg(fpi_ssm *ssm, unsigned char reg, int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -107,7 +107,7 @@ static void sm_write_reg(fpi_ssm *ssm, unsigned char reg, if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -116,7 +116,7 @@ static void sm_exec_cmd_cb(struct libusb_transfer *transfer) fpi_ssm *ssm = transfer->user_data; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); else fpi_ssm_next_state(ssm); @@ -133,7 +133,7 @@ static void sm_exec_cmd(fpi_ssm *ssm, unsigned char cmd, int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -146,7 +146,7 @@ static void sm_exec_cmd(fpi_ssm *ssm, unsigned char cmd, if (r < 0) { g_free(data); libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } @@ -196,7 +196,7 @@ static void capture_cb(struct libusb_transfer *transfer) struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } @@ -227,7 +227,7 @@ static void capture_iterate(fpi_ssm *ssm) int r; if (!transfer) { - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -238,7 +238,7 @@ static void capture_iterate(fpi_ssm *ssm) r = libusb_submit_transfer(transfer); if (r < 0) { libusb_free_transfer(transfer); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } } diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index dd6fb3d5..54b24f9a 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -36,14 +36,14 @@ static void async_write_callback(struct libusb_transfer *transfer) if (error != 0) { fp_err("USB write transfer: %s", libusb_error_name(error)); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } if (transferred != len) { fp_err("Written only %d of %d bytes", transferred, len); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } @@ -78,14 +78,14 @@ static void async_read_callback(struct libusb_transfer *transfer) fp_err("USB read transfer on endpoint %d: %s", ep - 0x80, libusb_error_name(error)); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } if (transferred != len) { fp_err("Received %d instead of %d bytes", transferred, len); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } @@ -134,7 +134,7 @@ static void async_abort_callback(struct libusb_transfer *transfer) if (error != 0) { fp_err("USB write transfer: %s", libusb_error_name(error)); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } @@ -302,7 +302,7 @@ static void clear_ep2_ssm(fpi_ssm *ssm) default: fp_err("Unknown SUBSM1 state"); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -363,7 +363,7 @@ static void send_control_packet_ssm(fpi_ssm *ssm) (vdev->interrupt, empty_interrupt, VFS_INTERRUPT_SIZE)) { fp_err("Unknown SUBSM2 state"); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); break; } async_abort(ssm, 3); @@ -380,7 +380,7 @@ static void send_control_packet_ssm(fpi_ssm *ssm) default: fp_err("Unknown SUBSM2 state"); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } @@ -423,7 +423,7 @@ static void interrupt_callback(struct libusb_transfer *transfer) fp_err("USB read interrupt transfer: %s", libusb_error_name(error)); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } @@ -432,7 +432,7 @@ static void interrupt_callback(struct libusb_transfer *transfer) fp_err("Unknown interrupt size %d", transferred); /* Abort ssm */ fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } @@ -461,7 +461,7 @@ static void interrupt_callback(struct libusb_transfer *transfer) /* Abort ssm */ fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } static void receive_callback(struct libusb_transfer *transfer) @@ -476,7 +476,7 @@ static void receive_callback(struct libusb_transfer *transfer) fp_err("USB read transfer: %s", libusb_error_name(error)); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } @@ -664,7 +664,7 @@ static void activate_ssm(fpi_ssm *ssm) default: fp_err("Unknown state"); fpi_imgdev_session_error(idev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 6a7d4fb7..d57b4fcd 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -214,7 +214,7 @@ static void async_send_cb(struct libusb_transfer *transfer) /* Transfer not completed, return IO error */ fp_err("transfer not completed, status = %d", transfer->status); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } @@ -224,7 +224,7 @@ static void async_send_cb(struct libusb_transfer *transfer) fp_err("length mismatch, got %d, expected %d", transfer->actual_length, transfer->length); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } } @@ -255,7 +255,7 @@ static void async_send(fpi_ssm *ssm) /* Allocation transfer failed, return no memory error */ fp_err("allocation of usb transfer failed"); fpi_imgdev_session_error(dev, -ENOMEM); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -275,7 +275,7 @@ static void async_send(fpi_ssm *ssm) libusb_free_transfer(vdev->transfer); fp_err("submit of usb transfer failed"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } } @@ -298,7 +298,7 @@ static void async_recv_cb(struct libusb_transfer *transfer) /* Transfer not completed, return IO error */ fp_err("transfer not completed, status = %d", transfer->status); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } @@ -308,7 +308,7 @@ static void async_recv_cb(struct libusb_transfer *transfer) fp_err("seqnum mismatch, got %04x, expected %04x", get_seqnum(vdev->buffer[1], vdev->buffer[0]), vdev->seqnum); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } } @@ -342,7 +342,7 @@ static void async_recv(fpi_ssm *ssm) /* Allocation transfer failed, return no memory error */ fp_err("allocation of usb transfer failed"); fpi_imgdev_session_error(dev, -ENOMEM); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -357,7 +357,7 @@ static void async_recv(fpi_ssm *ssm) libusb_free_transfer(vdev->transfer); fp_err("submit of usb transfer failed"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } } @@ -382,7 +382,7 @@ static void async_load_cb(struct libusb_transfer *transfer) /* Transfer not completed */ fp_err("transfer not completed, status = %d, length = %d", transfer->status, vdev->length); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } @@ -391,7 +391,7 @@ static void async_load_cb(struct libusb_transfer *transfer) /* Received incomplete frame, return protocol error */ fp_err("received incomplete frame"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } } @@ -406,7 +406,7 @@ static void async_load_cb(struct libusb_transfer *transfer) /* Buffer full, image too large, return no memory error */ fp_err("buffer full, image too large"); fpi_imgdev_session_error(dev, -ENOMEM); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); goto out; } else @@ -444,7 +444,7 @@ static void async_load(fpi_ssm *ssm) /* Allocation transfer failed, return no memory error */ fp_err("allocation of usb transfer failed"); fpi_imgdev_session_error(dev, -ENOMEM); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } @@ -462,7 +462,7 @@ static void async_load(fpi_ssm *ssm) libusb_free_transfer(vdev->transfer); fp_err("submit of usb transfer failed"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); return; } } @@ -494,7 +494,7 @@ static void async_sleep(unsigned int msec, fpi_ssm *ssm) /* Failed to add timeout */ fp_err("failed to add timeout"); fpi_imgdev_session_error(dev, -ETIME); - fpi_ssm_mark_aborted(ssm, -ETIME); + fpi_ssm_mark_failed(ssm, -ETIME); } } @@ -961,7 +961,7 @@ static void m_loop_state(fpi_ssm *ssm) /* Unknown state */ fp_err("unknown device state 0x%02x", vdev->buffer[0x0a]); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); break; } break; @@ -1018,7 +1018,7 @@ static void m_loop_state(fpi_ssm *ssm) /* reach max loop counter, return protocol error */ fp_err("finger not removed from the scanner"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } else @@ -1108,7 +1108,7 @@ static void m_loop_state(fpi_ssm *ssm) /* reach max loop counter, return protocol error */ fp_err("waiting abort reach max loop counter"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } break; @@ -1237,7 +1237,7 @@ static void m_init_state(fpi_ssm *ssm) /* reach max loop counter, return protocol error */ fp_err("waiting abort reach max loop counter"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } break; @@ -1273,7 +1273,7 @@ static void m_init_state(fpi_ssm *ssm) /* reach max loop counter, return protocol error */ fp_err("finger not removed from the scanner"); fpi_imgdev_session_error(dev, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); } } else diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 3d17b750..403bd363 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -47,7 +47,7 @@ static void async_sleep(unsigned int msec, fpi_ssm *ssm) /* Failed to add timeout */ fp_err("failed to add timeout"); fpi_imgdev_session_error(dev, -ETIME); - fpi_ssm_mark_aborted(ssm, -ETIME); + fpi_ssm_mark_failed(ssm, -ETIME); } } diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 44d21aad..f1e3d99c 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -82,7 +82,7 @@ static void async_send_cb(struct libusb_transfer *transfer) if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) { fp_err("Radiation detected!"); fpi_imgdev_session_error(data->device, -EINVAL); - fpi_ssm_mark_aborted(ssm, -EINVAL); + fpi_ssm_mark_failed(ssm, -EINVAL); goto out; } @@ -90,7 +90,7 @@ static void async_send_cb(struct libusb_transfer *transfer) if (action->type != ACTION_SEND) { fp_err("Radiation detected!"); fpi_imgdev_session_error(data->device, -EINVAL); - fpi_ssm_mark_aborted(ssm, -EINVAL); + fpi_ssm_mark_failed(ssm, -EINVAL); goto out; } @@ -98,7 +98,7 @@ static void async_send_cb(struct libusb_transfer *transfer) /* Transfer not completed, return IO error */ fp_err("transfer not completed, status = %d", transfer->status); fpi_imgdev_session_error(data->device, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } if (transfer->length != transfer->actual_length) { @@ -106,7 +106,7 @@ static void async_send_cb(struct libusb_transfer *transfer) fp_err("length mismatch, got %d, expected %d", transfer->actual_length, transfer->length); fpi_imgdev_session_error(data->device, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } @@ -127,14 +127,14 @@ static void async_recv_cb(struct libusb_transfer *transfer) /* Transfer not completed, return IO error */ fp_err("transfer not completed, status = %d", transfer->status); fpi_imgdev_session_error(data->device, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) { fp_err("Radiation detected!"); fpi_imgdev_session_error(data->device, -EINVAL); - fpi_ssm_mark_aborted(ssm, -EINVAL); + fpi_ssm_mark_failed(ssm, -EINVAL); goto out; } @@ -142,7 +142,7 @@ static void async_recv_cb(struct libusb_transfer *transfer) if (action->type != ACTION_RECEIVE) { fp_err("Radiation detected!"); fpi_imgdev_session_error(data->device, -EINVAL); - fpi_ssm_mark_aborted(ssm, -EINVAL); + fpi_ssm_mark_failed(ssm, -EINVAL); goto out; } @@ -152,14 +152,14 @@ static void async_recv_cb(struct libusb_transfer *transfer) transfer->actual_length, action->correct_reply_size); fpi_imgdev_session_error(data->device, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } if (memcmp(transfer->buffer, action->data, action->correct_reply_size) != 0) { fp_dbg("Wrong reply:"); fpi_imgdev_session_error(data->device, -EIO); - fpi_ssm_mark_aborted(ssm, -EIO); + fpi_ssm_mark_failed(ssm, -EIO); goto out; } } else @@ -178,7 +178,7 @@ static void usbexchange_loop(fpi_ssm *ssm) 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_aborted(ssm, -EINVAL); + fpi_ssm_mark_failed(ssm, -EINVAL); return; } @@ -193,7 +193,7 @@ static void usbexchange_loop(fpi_ssm *ssm) if (transfer == NULL) { fp_err("Failed to allocate transfer"); fpi_imgdev_session_error(data->device, -ENOMEM); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(data->device), @@ -209,7 +209,7 @@ static void usbexchange_loop(fpi_ssm *ssm) if (transfer == NULL) { fp_err("Failed to allocate transfer"); fpi_imgdev_session_error(data->device, -ENOMEM); - fpi_ssm_mark_aborted(ssm, -ENOMEM); + fpi_ssm_mark_failed(ssm, -ENOMEM); return; } libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(data->device), @@ -222,14 +222,14 @@ static void usbexchange_loop(fpi_ssm *ssm) default: fp_err("Bug detected: invalid action %d", action->type); fpi_imgdev_session_error(data->device, -EINVAL); - fpi_ssm_mark_aborted(ssm, -EINVAL); + fpi_ssm_mark_failed(ssm, -EINVAL); return; } if (ret != 0) { fp_err("USB transfer error: %s", strerror(ret)); fpi_imgdev_session_error(data->device, ret); - fpi_ssm_mark_aborted(ssm, ret); + fpi_ssm_mark_failed(ssm, ret); } } @@ -441,7 +441,7 @@ static void chunk_capture_callback(struct libusb_transfer *transfer) } else { if (!data->deactivating) { fp_err("Failed to capture data"); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } else { fpi_ssm_mark_completed(ssm); } @@ -712,7 +712,7 @@ static void activate_loop(fpi_ssm *ssm) if (r != 0) { fp_err("Failed to capture data"); fpi_imgdev_session_error(dev, r); - fpi_ssm_mark_aborted(ssm, r); + fpi_ssm_mark_failed(ssm, r); } break; @@ -723,7 +723,7 @@ static void activate_loop(fpi_ssm *ssm) /* Failed to add timeout */ fp_err("failed to add timeout"); fpi_imgdev_session_error(dev, -1); - fpi_ssm_mark_aborted(ssm, -1); + fpi_ssm_mark_failed(ssm, -1); } break; diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index aa6ad933..da3a0625 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -58,7 +58,7 @@ * To mark successful completion of a SSM, either iterate beyond the final * state or call fpi_ssm_mark_completed() from any state. * - * To mark failed completion of a SSM, call fpi_ssm_mark_aborted() from any + * To mark failed completion of a SSM, call fpi_ssm_mark_failed() from any * state. You must pass a non-zero error code. * * Your state handling function looks at the return value of @@ -68,7 +68,7 @@ * Typically, the state handling function fires off an asynchronous * communication with the device (such as a libsub transfer), and the * callback function iterates the machine to the next state - * upon success (or aborts the machine on failure). + * upon success (or fails). * * Your completion callback should examine the return value of * fpi_ssm_get_error() in order to determine whether the #fpi_ssm completed or @@ -184,7 +184,7 @@ static void __ssm_call_handler(fpi_ssm *machine) * @callback: the #ssm_completed_fn callback to call on completion * * Starts a state machine. You can also use this function to restart - * a completed or aborted state machine. The @callback will be called + * a completed or failed state machine. The @callback will be called * on completion. */ void fpi_ssm_start(fpi_ssm *ssm, ssm_completed_fn callback) @@ -202,7 +202,7 @@ static void __subsm_complete(fpi_ssm *ssm) fpi_ssm *parent = ssm->parentsm; BUG_ON(!parent); if (ssm->error) - fpi_ssm_mark_aborted(parent, ssm->error); + fpi_ssm_mark_failed(parent, ssm->error); else fpi_ssm_next_state(parent); fpi_ssm_free(ssm); @@ -215,9 +215,9 @@ static void __subsm_complete(fpi_ssm *ssm) * * Starts a state machine as a child of another. if the child completes * successfully, the parent will be advanced to the next state. if the - * child aborts, the parent will be aborted with the same error code. + * child fails, the parent will be marked as failed with the same error code. * - * The child will be automatically freed upon completion or abortion. + * The child will be automatically freed upon completion or failure. */ void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child) { @@ -242,13 +242,13 @@ void fpi_ssm_mark_completed(fpi_ssm *machine) } /** - * fpi_ssm_mark_aborted: + * fpi_ssm_mark_failed: * @machine: an #fpi_ssm state machine * @error: the error code * - * Mark a state machine as aborted with error. + * Mark a state machine as failed with @error as the error code. */ -void fpi_ssm_mark_aborted(fpi_ssm *machine, int error) +void fpi_ssm_mark_failed(fpi_ssm *machine, int error) { fp_dbg("error %d from state %d", error, machine->cur_state); BUG_ON(error == 0); @@ -307,7 +307,7 @@ int fpi_ssm_get_cur_state(fpi_ssm *machine) * fpi_ssm_get_error: * @machine: an #fpi_ssm state machine * - * Returns the error code set by fpi_ssm_mark_aborted(). + * Returns the error code set by fpi_ssm_mark_failed(). * * Returns: a error code */ diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 37a626bb..73ee2cab 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -34,8 +34,8 @@ * fpi_ssm: * * Sequential state machine that iterates sequentially over - * a predefined series of states. Can be aborted by either completion or - * abortion error conditions. + * a predefined series of states. Can be terminated by either completion or + * failure error conditions. */ typedef struct fpi_ssm fpi_ssm; @@ -68,7 +68,7 @@ void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child); void fpi_ssm_next_state(fpi_ssm *machine); void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); void fpi_ssm_mark_completed(fpi_ssm *machine); -void fpi_ssm_mark_aborted(fpi_ssm *machine, int error); +void fpi_ssm_mark_failed(fpi_ssm *machine, int error); struct fp_dev *fpi_ssm_get_dev(fpi_ssm *machine); void fpi_ssm_set_user_data(fpi_ssm *machine, void *user_data); From efee7262b60a7caa640519cfeb5047c12608c192 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 17:15:20 +0200 Subject: [PATCH 045/225] lib: Split off timeout helpers And rename poll.c to fpi-poll.c --- libfprint/drivers_api.h | 10 +--------- libfprint/fp_internal.h | 4 +--- libfprint/{poll.c => fpi-poll.c} | 1 + libfprint/fpi-poll.h | 26 ++++++++++++++++++++++++++ libfprint/meson.build | 3 ++- 5 files changed, 31 insertions(+), 13 deletions(-) rename libfprint/{poll.c => fpi-poll.c} (99%) create mode 100644 libfprint/fpi-poll.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 02fe43ca..cba678a9 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -37,6 +37,7 @@ #include "fprint.h" #include "fpi-ssm.h" +#include "fpi-poll.h" #include "assembling.h" #include "drivers/driver_ids.h" @@ -203,15 +204,6 @@ struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize); struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); -/* polling and timeouts */ - -typedef void (*fpi_timeout_fn)(void *data); - -struct fpi_timeout; -struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, - void *data); -void fpi_timeout_cancel(struct fpi_timeout *timeout); - void fpi_drvcb_open_complete(struct fp_dev *dev, int status); void fpi_drvcb_close_complete(struct fp_dev *dev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 48a25182..9aa03f27 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -341,13 +341,11 @@ int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print, struct fp_print_data **gallery, int match_threshold, size_t *match_offset); struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); -/* polling and timeouts */ +/* polling */ void fpi_poll_init(void); void fpi_poll_exit(void); -typedef void (*fpi_timeout_fn)(void *data); - void fpi_drvcb_open_complete(struct fp_dev *dev, int status); void fpi_drvcb_close_complete(struct fp_dev *dev); diff --git a/libfprint/poll.c b/libfprint/fpi-poll.c similarity index 99% rename from libfprint/poll.c rename to libfprint/fpi-poll.c index 615ba40f..b572e56e 100644 --- a/libfprint/poll.c +++ b/libfprint/fpi-poll.c @@ -20,6 +20,7 @@ #define FP_COMPONENT "poll" #include "fp_internal.h" +#include "fpi-poll.h" #include #include diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h new file mode 100644 index 00000000..be2de9c3 --- /dev/null +++ b/libfprint/fpi-poll.h @@ -0,0 +1,26 @@ +/* + * Polling/timing management + * Copyright (C) 2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +typedef void (*fpi_timeout_fn)(void *data); + +struct fpi_timeout; +struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, + void *data); +void fpi_timeout_cancel(struct fpi_timeout *timeout); diff --git a/libfprint/meson.build b/libfprint/meson.build index 0a9ed021..c6d1ac9b 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -6,9 +6,10 @@ libfprint_sources = [ 'data.c', 'fpi-ssm.c', 'fpi-ssm.h', + 'fpi-poll.h', + 'fpi-poll.c', 'img.c', 'imgdev.c', - 'poll.c', 'sync.c', 'assembling.c', 'assembling.h', From 969eefc81f29bbf6c7993b8fb0f7ca179f69e001 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 17:33:25 +0200 Subject: [PATCH 046/225] lib: Add fpi_timeout API documentation --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 9 +++++++++ libfprint/fpi-poll.c | 33 +++++++++++++++++++++++++++++++-- libfprint/fpi-poll.h | 12 ++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index 8f8622d3..c4e34451 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -39,6 +39,7 @@ Writing Drivers + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 1f99e5a1..91310b93 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -162,3 +162,12 @@ fpi_ssm_get_user_data fpi_ssm_get_error fpi_ssm_get_cur_state + +
+fpi-poll.h +fpi-poll +fpi_timeout +fpi_timeout_fn +fpi_timeout_add +fpi_timeout_cancel +
diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index b572e56e..cd6f9ba0 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -64,6 +64,15 @@ * your main loop. */ +/** + * SECTION:fpi-poll + * @title: Timeouts + * + * Helper functions to schedule a function call to be made after a timeout. This + * is useful to avoid making blocking calls while waiting for hardware to answer + * for example. + */ + /* this is a singly-linked list of pending timers, sorted with the timer that * is expiring soonest at the head. */ static GSList *active_timers = NULL; @@ -93,9 +102,22 @@ static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) return 0; } -/* A timeout is the asynchronous equivalent of sleeping. You create a timeout +/** + * fpi_timeout_add: + * @msec: the time before calling the function, in milliseconds (1/1000ths of a second) + * @callback: function to callback + * @data: data to pass to @callback + * + * A timeout is the asynchronous equivalent of sleeping. You create a timeout * saying that you'd like to have a function invoked at a certain time in - * the future. */ + * the future. + * + * Note that you should hold onto the return value of this function to cancel it + * use fpi_timeout_cancel(), otherwise the callback could be called while the driver + * is being torn down. %NULL is returned on failure. + * + * Returns: an #fpi_timeout structure + */ struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data) { @@ -129,6 +151,13 @@ struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, return timeout; } +/** + * fpi_timeout_cancel: + * @timeout: an #fpi_timeout structure + * + * Cancels a timeout scheduled with fpi_timeout_add(), and frees the + * @timeout structure. + */ void fpi_timeout_cancel(struct fpi_timeout *timeout) { G_DEBUG_HERE(); diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index be2de9c3..3f857040 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -18,8 +18,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/** + * fpi_timeout_fn: + * @data: the data passed to fpi_timeout_add() + * + * The prototype of the callback function for fpi_timeout_add(). + */ typedef void (*fpi_timeout_fn)(void *data); +/** + * fpi_timeout: + * + * An opaque structure representing a scheduled function call, created with + * fpi_timeout_add(). + */ struct fpi_timeout; struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data); From 2946dabd244bfc4d06ff6691d9cc236cbf72f3cb Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 5 Sep 2018 17:34:59 +0200 Subject: [PATCH 047/225] lib: Typedef fpi_timeout --- libfprint/drivers/uru4000.c | 2 +- libfprint/drivers/vfs101.c | 2 +- libfprint/drivers/vfs301.c | 2 +- libfprint/drivers/vfs5011.c | 2 +- libfprint/fpi-poll.c | 10 +++++----- libfprint/fpi-poll.h | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index fddd4110..cad94fa4 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -135,7 +135,7 @@ struct uru4k_dev { unsigned char powerup_hwstat; int scanpwr_irq_timeouts; - struct fpi_timeout *scanpwr_irq_timeout; + fpi_timeout *scanpwr_irq_timeout; int fwfixer_offset; unsigned char fwfixer_value; diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index d57b4fcd..a2ac6b9c 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -106,7 +106,7 @@ struct vfs101_dev int ignore_error; /* Timeout */ - struct fpi_timeout *timeout; + fpi_timeout *timeout; /* Loop counter */ int counter; diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 403bd363..66806aef 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -38,7 +38,7 @@ static void async_sleep_cb(void *data) static void async_sleep(unsigned int msec, fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct fpi_timeout *timeout; + fpi_timeout *timeout; /* Add timeout */ timeout = fpi_timeout_add(msec, async_sleep_cb, ssm); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index f1e3d99c..93deb053 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -672,7 +672,7 @@ static void activate_loop(fpi_ssm *ssm) struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; int r; - struct fpi_timeout *timeout; + fpi_timeout *timeout; data = fpi_imgdev_get_user_data(dev); diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index cd6f9ba0..5c6fc960 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -89,8 +89,8 @@ struct fpi_timeout { static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) { - struct fpi_timeout *a = (struct fpi_timeout *) _a; - struct fpi_timeout *b = (struct fpi_timeout *) _b; + fpi_timeout *a = (fpi_timeout *) _a; + fpi_timeout *b = (fpi_timeout *) _b; struct timeval *tv_a = &a->expiry; struct timeval *tv_b = &b->expiry; @@ -118,12 +118,12 @@ static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) * * Returns: an #fpi_timeout structure */ -struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, +fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data) { struct timespec ts; struct timeval add_msec; - struct fpi_timeout *timeout; + fpi_timeout *timeout; int r; fp_dbg("in %dms", msec); @@ -158,7 +158,7 @@ struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, * Cancels a timeout scheduled with fpi_timeout_add(), and frees the * @timeout structure. */ -void fpi_timeout_cancel(struct fpi_timeout *timeout) +void fpi_timeout_cancel(fpi_timeout *timeout) { G_DEBUG_HERE(); active_timers = g_slist_remove(active_timers, timeout); diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 3f857040..34c25204 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -32,7 +32,7 @@ typedef void (*fpi_timeout_fn)(void *data); * An opaque structure representing a scheduled function call, created with * fpi_timeout_add(). */ -struct fpi_timeout; -struct fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, +typedef struct fpi_timeout fpi_timeout; +fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, void *data); -void fpi_timeout_cancel(struct fpi_timeout *timeout); +void fpi_timeout_cancel(fpi_timeout *timeout); From de5b4e7dcbe080ced18c25a128f965f58ce48bc1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 6 Sep 2018 13:23:13 +0200 Subject: [PATCH 048/225] lib: Split off logging helpers --- libfprint/drivers_api.h | 21 +------------------ libfprint/fp_internal.h | 20 +----------------- libfprint/fpi-log.h | 45 +++++++++++++++++++++++++++++++++++++++++ libfprint/meson.build | 1 + 4 files changed, 48 insertions(+), 39 deletions(-) create mode 100644 libfprint/fpi-log.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index cba678a9..bd0bdd7d 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -22,12 +22,6 @@ #define __DRIVERS_API_H__ #include - -#ifdef FP_COMPONENT -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "libfprint-"FP_COMPONENT -#endif - #include #include #include @@ -36,25 +30,12 @@ #include #include "fprint.h" +#include "fpi-log.h" #include "fpi-ssm.h" #include "fpi-poll.h" #include "assembling.h" #include "drivers/driver_ids.h" -#define fp_dbg g_debug -#define fp_info g_debug -#define fp_warn g_warning -#define fp_err g_warning - -#define BUG_ON(condition) G_STMT_START \ - if (condition) { \ - char *s; \ - s = g_strconcat ("BUG: (", #condition, ")", NULL); \ - g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ - g_free (s); \ - } G_STMT_END -#define BUG() BUG_ON(1) - struct fp_dev; libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); void *fpi_dev_get_user_data (struct fp_dev *dev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 9aa03f27..3336cac1 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -22,37 +22,19 @@ #include -#ifdef FP_COMPONENT -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "libfprint-"FP_COMPONENT -#endif - #include #include #include #include #include "fprint.h" +#include "fpi-log.h" #include "drivers/driver_ids.h" #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define fp_dbg g_debug -#define fp_info g_debug -#define fp_warn g_warning -#define fp_err g_warning - -#define BUG_ON(condition) G_STMT_START \ - if (condition) { \ - char *s; \ - s = g_strconcat ("BUG: (", #condition, ")", NULL); \ - g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ - g_free (s); \ - } G_STMT_END -#define BUG() BUG_ON(1) - enum fp_dev_state { DEV_STATE_INITIAL = 0, DEV_STATE_ERROR, diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h new file mode 100644 index 00000000..38d720cb --- /dev/null +++ b/libfprint/fpi-log.h @@ -0,0 +1,45 @@ +/* + * Logging + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_LOG_H__ +#define __FPI_LOG_H__ + +#ifdef FP_COMPONENT +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "libfprint-"FP_COMPONENT +#endif + +#include + +#define fp_dbg g_debug +#define fp_info g_debug +#define fp_warn g_warning +#define fp_err g_warning + +#define BUG_ON(condition) G_STMT_START \ + if (condition) { \ + char *s; \ + s = g_strconcat ("BUG: (", #condition, ")", NULL); \ + g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ + g_free (s); \ + } G_STMT_END +#define BUG() BUG_ON(1) + +#endif diff --git a/libfprint/meson.build b/libfprint/meson.build index c6d1ac9b..ceacc359 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -4,6 +4,7 @@ libfprint_sources = [ 'async.c', 'core.c', 'data.c', + 'fpi-log.h', 'fpi-ssm.c', 'fpi-ssm.h', 'fpi-poll.h', From fc66919e1fb69acbc435ec103fa0d9ba34e3cc3f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 6 Sep 2018 14:42:33 +0200 Subject: [PATCH 049/225] lib: Make BUG_ON() use fp_err() So that when we change fp_err() to an assertion, BUG_ON() is changed as well. --- libfprint/fpi-log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h index 38d720cb..a21f4e1b 100644 --- a/libfprint/fpi-log.h +++ b/libfprint/fpi-log.h @@ -37,7 +37,7 @@ if (condition) { \ char *s; \ s = g_strconcat ("BUG: (", #condition, ")", NULL); \ - g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ + fp_err ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ g_free (s); \ } G_STMT_END #define BUG() BUG_ON(1) From 3cb3b1d63ae09a6cea2667e03c0cc0ad19555100 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 6 Sep 2018 14:43:10 +0200 Subject: [PATCH 050/225] lib: Add Logging API documentation --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 11 ++++++++ libfprint/fpi-log.h | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index c4e34451..5ca17221 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -38,6 +38,7 @@ Writing Drivers + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 91310b93..3cc33b49 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -141,6 +141,17 @@ fp_img_get_minutiae poll +
+fpi-log.h +fpi-log +fp_dbg +fp_info +fp_warn +fp_err +BUG_ON +BUG +
+
fpi-ssm.h fpi-ssm diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h index a21f4e1b..d9f354e8 100644 --- a/libfprint/fpi-log.h +++ b/libfprint/fpi-log.h @@ -21,6 +21,19 @@ #ifndef __FPI_LOG_H__ #define __FPI_LOG_H__ +/** + * SECTION:fpi-log + * @title: Logging + * + * Logging in libfprint is handled through GLib's logging system, and behave the same + * way as in the GLib [Message Output and Debugging Functions](https://developer.gnome.org/glib/stable/glib-Message-Logging.html) + * documentation. + * + * You should include `fpi-log.h` as early as possible in your sources, just after + * setting the `FP_COMPONENT` define to a string unique to your sources. This will + * set the suffix of the `G_LOG_DOMAIN` used for printing. + */ + #ifdef FP_COMPONENT #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "libfprint-"FP_COMPONENT @@ -28,11 +41,43 @@ #include +/** + * fp_dbg: + * + * Same as g_debug(). + * + */ #define fp_dbg g_debug + +/** + * fp_info: + * + * Same as g_debug(). + */ #define fp_info g_debug + +/** + * fp_warn: + * + * Same as g_warning(). + */ #define fp_warn g_warning + +/** + * fp_err: + * + * Same as g_warning(). In the future, this might be changed to a + * g_assert() instead, so bear this in mind when adding those calls + * to your driver. + */ #define fp_err g_warning +/** + * BUG_ON: + * @condition: the condition to check + * + * Uses fp_err() to print an error if the @condition is true. + */ #define BUG_ON(condition) G_STMT_START \ if (condition) { \ char *s; \ @@ -40,6 +85,12 @@ fp_err ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ g_free (s); \ } G_STMT_END + +/** + * BUG: + * + * Same as BUG_ON() but is always true. + */ #define BUG() BUG_ON(1) #endif From 170da7fec18878e38871d8b413d7793bccac3c46 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 14 Sep 2018 17:19:30 +0200 Subject: [PATCH 051/225] lib: Move fp_dev definition and helpers to separate header --- libfprint/drivers_api.h | 3 +-- libfprint/fp_internal.h | 1 + libfprint/fpi-dev.c | 21 +++++++++++++++++++++ libfprint/fpi-dev.h | 28 ++++++++++++++++++++++++++++ libfprint/meson.build | 2 ++ libfprint/sync.c | 1 + 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 libfprint/fpi-dev.c create mode 100644 libfprint/fpi-dev.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index bd0bdd7d..67caad5c 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -33,10 +33,10 @@ #include "fpi-log.h" #include "fpi-ssm.h" #include "fpi-poll.h" +#include "fpi-dev.h" #include "assembling.h" #include "drivers/driver_ids.h" -struct fp_dev; libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); void *fpi_dev_get_user_data (struct fp_dev *dev); void fpi_dev_set_user_data (struct fp_dev *dev, void *user_data); @@ -69,7 +69,6 @@ enum fp_imgdev_enroll_state { IMG_ACQUIRE_STATE_DEACTIVATING, }; -struct fp_img_dev; libusb_device_handle *fpi_imgdev_get_usb_dev(struct fp_img_dev *dev); void fpi_imgdev_set_user_data(struct fp_img_dev *imgdev, void *user_data); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 3336cac1..e84f5206 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -29,6 +29,7 @@ #include "fprint.h" #include "fpi-log.h" +#include "fpi-dev.h" #include "drivers/driver_ids.h" #define container_of(ptr, type, member) ({ \ diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c new file mode 100644 index 00000000..6a188d25 --- /dev/null +++ b/libfprint/fpi-dev.c @@ -0,0 +1,21 @@ +/* + * fp_dev types manipulation + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "fp_internal.h" +#include diff --git a/libfprint/fpi-dev.h b/libfprint/fpi-dev.h new file mode 100644 index 00000000..2edbeb98 --- /dev/null +++ b/libfprint/fpi-dev.h @@ -0,0 +1,28 @@ +/* + * fp_dev types manipulation + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +struct fp_dev; + +/** + * fp_img_dev: + * + * #fp_img_dev is an opaque structure type. You must access it using the + * appropriate functions. + */ +struct fp_img_dev; diff --git a/libfprint/meson.build b/libfprint/meson.build index ceacc359..c593dae9 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -4,6 +4,8 @@ libfprint_sources = [ 'async.c', 'core.c', 'data.c', + 'fpi-dev.c', + 'fpi-dev.h', 'fpi-log.h', 'fpi-ssm.c', 'fpi-ssm.h', diff --git a/libfprint/sync.c b/libfprint/sync.c index c194f5ca..8f71b6ea 100644 --- a/libfprint/sync.c +++ b/libfprint/sync.c @@ -20,6 +20,7 @@ #define FP_COMPONENT "sync" #include "fp_internal.h" +#include "fpi-dev.h" #include #include From 161c3ccf1cbf48cdf56ffa75fd03f423df8d4398 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 14 Sep 2018 17:30:01 +0200 Subject: [PATCH 052/225] lib: Link fp_dev to fp_img_dev and back So it's easy to switch between the 2 structs, and remove fp_img_dev->dev direct access, as well as fp_dev->priv "user data" usage. --- libfprint/core.c | 2 +- libfprint/fp_internal.h | 6 +++- libfprint/fpi-dev.c | 31 ++++++++++++++++ libfprint/fpi-dev.h | 3 ++ libfprint/img.c | 6 ++-- libfprint/imgdev.c | 79 +++++++++++++++++++++-------------------- 6 files changed, 83 insertions(+), 44 deletions(-) diff --git a/libfprint/core.c b/libfprint/core.c index 1cb82cca..90dfc8c4 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -622,7 +622,7 @@ static struct fp_img_dev *dev_to_img_dev(struct fp_dev *dev) { if (dev->drv->type != DRIVER_IMAGING) return NULL; - return dev->priv; + return dev->img_dev; } /** diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index e84f5206..1e747b20 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -68,6 +68,9 @@ struct fp_dev { uint32_t devtype; void *priv; + /* only valid if drv->type == DRIVER_IMAGING */ + struct fp_img_dev *img_dev; + int nr_enroll_stages; /* read-only to drivers */ @@ -136,8 +139,9 @@ enum fp_imgdev_verify_state { }; struct fp_img_dev { - struct fp_dev *dev; libusb_device_handle *udev; + struct fp_dev *parent; + enum fp_imgdev_action action; int action_state; diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index 6a188d25..416e8d30 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -19,3 +19,34 @@ #include "fp_internal.h" #include + +/** + * FP_DEV: + * @dev: a struct #fp_img_dev + * + * Returns the struct #fp_dev associated with @dev, or %NULL on failure. + */ +struct fp_dev * +FP_DEV(struct fp_img_dev *dev) +{ + struct fp_img_dev *imgdev; + + g_return_val_if_fail (dev, NULL); + imgdev = (struct fp_img_dev *) dev; + return imgdev->parent; +} + +/** + * FP_IMG_DEV: + * @dev: a struct #fp_dev representing an imaging device. + * + * Returns: a struct #fp_img_dev or %NULL on failure. + */ +struct fp_img_dev * +FP_IMG_DEV(struct fp_dev *dev) +{ + g_return_val_if_fail (dev, NULL); + g_return_val_if_fail (dev->drv, NULL); + g_return_val_if_fail (dev->drv->type != DRIVER_IMAGING, NULL); + return dev->img_dev; +} diff --git a/libfprint/fpi-dev.h b/libfprint/fpi-dev.h index 2edbeb98..d21e14b4 100644 --- a/libfprint/fpi-dev.h +++ b/libfprint/fpi-dev.h @@ -26,3 +26,6 @@ struct fp_dev; * appropriate functions. */ struct fp_img_dev; + +struct fp_dev *FP_DEV (struct fp_img_dev *dev); +struct fp_img_dev *FP_IMG_DEV (struct fp_dev *dev); diff --git a/libfprint/img.c b/libfprint/img.c index 90f4cd4a..26f9ef7f 100644 --- a/libfprint/img.c +++ b/libfprint/img.c @@ -58,7 +58,7 @@ struct fp_img *fpi_img_new(size_t length) struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev) { - struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(FP_DEV(imgdev)->drv); int width = imgdrv->img_width; int height = imgdrv->img_height; struct fp_img *img = fpi_img_new(width * height); @@ -349,7 +349,7 @@ int fpi_img_to_print_data(struct fp_img_dev *imgdev, struct fp_img *img, /* FIXME: space is wasted if we dont hit the max minutiae count. would * be good to make this dynamic. */ - print = fpi_print_data_new(imgdev->dev); + print = fpi_print_data_new(FP_DEV(imgdev)); item = fpi_print_data_item_new(sizeof(struct xyt_struct)); print->type = PRINT_DATA_NBIS_MINUTIAE; minutiae_to_xyt(img->minutiae, img->width, img->height, item->data); @@ -555,7 +555,7 @@ fpi_imgdev_get_user_data(struct fp_img_dev *imgdev) struct fp_dev * fpi_imgdev_get_dev(struct fp_img_dev *imgdev) { - return imgdev->dev; + return FP_DEV(imgdev); } enum fp_imgdev_enroll_state diff --git a/libfprint/imgdev.c b/libfprint/imgdev.c index 030109b9..8d983538 100644 --- a/libfprint/imgdev.c +++ b/libfprint/imgdev.c @@ -33,9 +33,11 @@ static int img_dev_open(struct fp_dev *dev, unsigned long driver_data) struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(dev->drv); int r = 0; - imgdev->dev = dev; + /* Set up back pointers */ + dev->img_dev = imgdev; + imgdev->parent = dev; + imgdev->enroll_stage = 0; - dev->priv = imgdev; dev->nr_enroll_stages = IMG_ENROLL_STAGES; /* for consistency in driver code, allow udev access through imgdev */ @@ -57,30 +59,29 @@ err: void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status) { - fpi_drvcb_open_complete(imgdev->dev, status); + fpi_drvcb_open_complete(FP_DEV(imgdev), status); } static void img_dev_close(struct fp_dev *dev) { - struct fp_img_dev *imgdev = dev->priv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(dev->drv); if (imgdrv->close) - imgdrv->close(imgdev); + imgdrv->close(dev->img_dev); else fpi_drvcb_close_complete(dev); } void fpi_imgdev_close_complete(struct fp_img_dev *imgdev) { - fpi_drvcb_close_complete(imgdev->dev); + fpi_drvcb_close_complete(FP_DEV(imgdev)); g_free(imgdev); } static int dev_change_state(struct fp_img_dev *imgdev, enum fp_imgdev_state state) { - struct fp_driver *drv = imgdev->dev->drv; + struct fp_driver *drv = FP_DEV(imgdev)->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); if (!imgdrv->change_state) @@ -92,7 +93,7 @@ static int dev_change_state(struct fp_img_dev *imgdev, * image after freeing the old one. */ static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img) { - struct fp_driver *drv = imgdev->dev->drv; + struct fp_driver *drv = FP_DEV(imgdev)->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); struct fp_img *img = *_img; @@ -150,7 +151,7 @@ void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, if (r == FP_ENROLL_COMPLETE) { imgdev->enroll_data = NULL; } - fpi_drvcb_enroll_stage_completed(imgdev->dev, r, + fpi_drvcb_enroll_stage_completed(FP_DEV(imgdev), r, r == FP_ENROLL_COMPLETE ? data : NULL, img); /* the callback can cancel enrollment, so recheck current @@ -163,18 +164,18 @@ void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, } break; case IMG_ACTION_VERIFY: - fpi_drvcb_report_verify_result(imgdev->dev, r, img); + fpi_drvcb_report_verify_result(FP_DEV(imgdev), r, img); imgdev->action_result = 0; fp_print_data_free(data); break; case IMG_ACTION_IDENTIFY: - fpi_drvcb_report_identify_result(imgdev->dev, r, + fpi_drvcb_report_identify_result(FP_DEV(imgdev), r, imgdev->identify_match_offset, img); imgdev->action_result = 0; fp_print_data_free(data); break; case IMG_ACTION_CAPTURE: - fpi_drvcb_report_capture_result(imgdev->dev, r, img); + fpi_drvcb_report_capture_result(FP_DEV(imgdev), r, img); imgdev->action_result = 0; break; default: @@ -185,14 +186,14 @@ void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, static void verify_process_img(struct fp_img_dev *imgdev) { - struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(FP_DEV(imgdev)->drv); int match_score = imgdrv->bz3_threshold; int r; if (match_score == 0) match_score = BOZORTH3_DEFAULT_THRESHOLD; - r = fpi_img_compare_print_data(imgdev->dev->verify_data, + r = fpi_img_compare_print_data(FP_DEV(imgdev)->verify_data, imgdev->acquire_data); if (r >= match_score) @@ -205,7 +206,7 @@ static void verify_process_img(struct fp_img_dev *imgdev) static void identify_process_img(struct fp_img_dev *imgdev) { - struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv); + struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(FP_DEV(imgdev)->drv); int match_score = imgdrv->bz3_threshold; size_t match_offset; int r; @@ -214,7 +215,7 @@ static void identify_process_img(struct fp_img_dev *imgdev) match_score = BOZORTH3_DEFAULT_THRESHOLD; r = fpi_img_compare_print_data_to_gallery(imgdev->acquire_data, - imgdev->dev->identify_gallery, match_score, &match_offset); + FP_DEV(imgdev)->identify_gallery, match_score, &match_offset); imgdev->action_result = r; imgdev->identify_match_offset = match_offset; @@ -272,7 +273,7 @@ void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img) switch (imgdev->action) { case IMG_ACTION_ENROLL: if (!imgdev->enroll_data) { - imgdev->enroll_data = fpi_print_data_new(imgdev->dev); + imgdev->enroll_data = fpi_print_data_new(FP_DEV(imgdev)); } BUG_ON(g_slist_length(print->prints) != 1); /* Move print data from acquire data into enroll_data */ @@ -283,7 +284,7 @@ void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img) fp_print_data_free(imgdev->acquire_data); imgdev->acquire_data = NULL; imgdev->enroll_stage++; - if (imgdev->enroll_stage == imgdev->dev->nr_enroll_stages) + if (imgdev->enroll_stage == FP_DEV(imgdev)->nr_enroll_stages) imgdev->action_result = FP_ENROLL_COMPLETE; else imgdev->action_result = FP_ENROLL_PASS; @@ -313,16 +314,16 @@ void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error) BUG_ON(error == 0); switch (imgdev->action) { case IMG_ACTION_ENROLL: - fpi_drvcb_enroll_stage_completed(imgdev->dev, error, NULL, NULL); + fpi_drvcb_enroll_stage_completed(FP_DEV(imgdev), error, NULL, NULL); break; case IMG_ACTION_VERIFY: - fpi_drvcb_report_verify_result(imgdev->dev, error, NULL); + fpi_drvcb_report_verify_result(FP_DEV(imgdev), error, NULL); break; case IMG_ACTION_IDENTIFY: - fpi_drvcb_report_identify_result(imgdev->dev, error, 0, NULL); + fpi_drvcb_report_identify_result(FP_DEV(imgdev), error, 0, NULL); break; case IMG_ACTION_CAPTURE: - fpi_drvcb_report_capture_result(imgdev->dev, error, NULL); + fpi_drvcb_report_capture_result(FP_DEV(imgdev), error, NULL); break; default: fp_err("unhandled action %d", imgdev->action); @@ -336,16 +337,16 @@ void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status) switch (imgdev->action) { case IMG_ACTION_ENROLL: - fpi_drvcb_enroll_started(imgdev->dev, status); + fpi_drvcb_enroll_started(FP_DEV(imgdev), status); break; case IMG_ACTION_VERIFY: - fpi_drvcb_verify_started(imgdev->dev, status); + fpi_drvcb_verify_started(FP_DEV(imgdev), status); break; case IMG_ACTION_IDENTIFY: - fpi_drvcb_identify_started(imgdev->dev, status); + fpi_drvcb_identify_started(FP_DEV(imgdev), status); break; case IMG_ACTION_CAPTURE: - fpi_drvcb_capture_started(imgdev->dev, status); + fpi_drvcb_capture_started(FP_DEV(imgdev), status); break; default: fp_err("unhandled action %d", imgdev->action); @@ -364,16 +365,16 @@ void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev) switch (imgdev->action) { case IMG_ACTION_ENROLL: - fpi_drvcb_enroll_stopped(imgdev->dev); + fpi_drvcb_enroll_stopped(FP_DEV(imgdev)); break; case IMG_ACTION_VERIFY: - fpi_drvcb_verify_stopped(imgdev->dev); + fpi_drvcb_verify_stopped(FP_DEV(imgdev)); break; case IMG_ACTION_IDENTIFY: - fpi_drvcb_identify_stopped(imgdev->dev); + fpi_drvcb_identify_stopped(FP_DEV(imgdev)); break; case IMG_ACTION_CAPTURE: - fpi_drvcb_capture_stopped(imgdev->dev); + fpi_drvcb_capture_stopped(FP_DEV(imgdev)); break; default: fp_err("unhandled action %d", imgdev->action); @@ -386,7 +387,7 @@ void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev) int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev) { - struct fp_driver *drv = imgdev->dev->drv; + struct fp_driver *drv = FP_DEV(imgdev)->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); int width = imgdrv->img_width; @@ -398,7 +399,7 @@ int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev) int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev) { - struct fp_driver *drv = imgdev->dev->drv; + struct fp_driver *drv = FP_DEV(imgdev)->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); int height = imgdrv->img_height; @@ -410,7 +411,7 @@ int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev) static int dev_activate(struct fp_img_dev *imgdev, enum fp_imgdev_state state) { - struct fp_driver *drv = imgdev->dev->drv; + struct fp_driver *drv = FP_DEV(imgdev)->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); if (!imgdrv->activate) @@ -420,7 +421,7 @@ static int dev_activate(struct fp_img_dev *imgdev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *imgdev) { - struct fp_driver *drv = imgdev->dev->drv; + struct fp_driver *drv = FP_DEV(imgdev)->drv; struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(drv); if (!imgdrv->deactivate) @@ -430,7 +431,7 @@ static void dev_deactivate(struct fp_img_dev *imgdev) static int generic_acquire_start(struct fp_dev *dev, int action) { - struct fp_img_dev *imgdev = dev->priv; + struct fp_img_dev *imgdev = dev->img_dev; int r; fp_dbg("action %d", action); imgdev->action = action; @@ -484,7 +485,7 @@ static int img_dev_capture_start(struct fp_dev *dev) static int img_dev_enroll_stop(struct fp_dev *dev) { - struct fp_img_dev *imgdev = dev->priv; + struct fp_img_dev *imgdev = dev->img_dev; BUG_ON(imgdev->action != IMG_ACTION_ENROLL); generic_acquire_stop(imgdev); return 0; @@ -492,7 +493,7 @@ static int img_dev_enroll_stop(struct fp_dev *dev) static int img_dev_verify_stop(struct fp_dev *dev, gboolean iterating) { - struct fp_img_dev *imgdev = dev->priv; + struct fp_img_dev *imgdev = dev->img_dev; BUG_ON(imgdev->action != IMG_ACTION_VERIFY); generic_acquire_stop(imgdev); return 0; @@ -500,7 +501,7 @@ static int img_dev_verify_stop(struct fp_dev *dev, gboolean iterating) static int img_dev_identify_stop(struct fp_dev *dev, gboolean iterating) { - struct fp_img_dev *imgdev = dev->priv; + struct fp_img_dev *imgdev = dev->img_dev; BUG_ON(imgdev->action != IMG_ACTION_IDENTIFY); generic_acquire_stop(imgdev); imgdev->identify_match_offset = 0; @@ -509,7 +510,7 @@ static int img_dev_identify_stop(struct fp_dev *dev, gboolean iterating) static int img_dev_capture_stop(struct fp_dev *dev) { - struct fp_img_dev *imgdev = dev->priv; + struct fp_img_dev *imgdev = dev->img_dev; BUG_ON(imgdev->action != IMG_ACTION_CAPTURE); generic_acquire_stop(imgdev); return 0; From 4dc8aa6dfadb3db974b516dd019a7d42d6c70b10 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Sep 2018 01:01:40 +0200 Subject: [PATCH 053/225] docs: Add fpi-dev helpers to API docs --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 9 +++++++++ libfprint/fpi-dev.c | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index 5ca17221..6d705e53 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -39,6 +39,7 @@ Writing Drivers + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 3cc33b49..8e33b1d4 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -182,3 +182,12 @@ fpi_timeout_fn fpi_timeout_add fpi_timeout_cancel
+ +
+fpi-dev.h +fpi-dev +fp_img_dev + +FP_DEV +FP_IMG_DEV +
diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index 416e8d30..0eb80387 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -20,6 +20,15 @@ #include "fp_internal.h" #include +/** + * SECTION:fpi-dev + * @title: Device structures + * + * Those macros and functions will help get access to and from struct #fp_dev, + * and struct #fp_img_dev types, as well as get and set the instance struct + * data, eg. the structure containing the data specific to each driver. + */ + /** * FP_DEV: * @dev: a struct #fp_img_dev From 0b7477e72cb3c7199e6183329bad272627b5013f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 14 Sep 2018 17:32:10 +0200 Subject: [PATCH 054/225] lib: Use fp_dev to access USB device Instead of having own own pointer in fp_img_dev --- libfprint/aeslib.c | 2 +- libfprint/fp_internal.h | 1 - libfprint/img.c | 2 +- libfprint/imgdev.c | 3 --- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/libfprint/aeslib.c b/libfprint/aeslib.c index 61811ade..16cc903a 100644 --- a/libfprint/aeslib.c +++ b/libfprint/aeslib.c @@ -87,7 +87,7 @@ static int do_write_regv(struct write_regv_data *wdata, int upper_bound) data[data_offset++] = regwrite->value; } - libusb_fill_bulk_transfer(transfer, wdata->imgdev->udev, EP_OUT, data, + libusb_fill_bulk_transfer(transfer, FP_DEV(wdata->imgdev)->udev, EP_OUT, data, alloc_size, write_regv_trf_complete, wdata, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 1e747b20..28fda532 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -139,7 +139,6 @@ enum fp_imgdev_verify_state { }; struct fp_img_dev { - libusb_device_handle *udev; struct fp_dev *parent; enum fp_imgdev_action action; diff --git a/libfprint/img.c b/libfprint/img.c index 26f9ef7f..f49c7163 100644 --- a/libfprint/img.c +++ b/libfprint/img.c @@ -536,7 +536,7 @@ API_EXPORTED struct fp_minutia **fp_img_get_minutiae(struct fp_img *img, libusb_device_handle * fpi_imgdev_get_usb_dev(struct fp_img_dev *dev) { - return dev->udev; + return FP_DEV(dev)->udev; } void diff --git a/libfprint/imgdev.c b/libfprint/imgdev.c index 8d983538..605f6ce5 100644 --- a/libfprint/imgdev.c +++ b/libfprint/imgdev.c @@ -40,9 +40,6 @@ static int img_dev_open(struct fp_dev *dev, unsigned long driver_data) imgdev->enroll_stage = 0; dev->nr_enroll_stages = IMG_ENROLL_STAGES; - /* for consistency in driver code, allow udev access through imgdev */ - imgdev->udev = dev->udev; - if (imgdrv->open) { r = imgdrv->open(imgdev, driver_data); if (r) From 2e50ff5e7cf478bacac74ff14470527d0727afc2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 14 Sep 2018 17:36:47 +0200 Subject: [PATCH 055/225] lib: Add some TODO items to fp_dev struct --- libfprint/fp_internal.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 28fda532..d7627ff0 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -64,15 +64,19 @@ struct fp_driver **fprint_get_drivers (void); struct fp_dev { struct fp_driver *drv; - libusb_device_handle *udev; uint32_t devtype; - void *priv; /* only valid if drv->type == DRIVER_IMAGING */ struct fp_img_dev *img_dev; int nr_enroll_stages; + /* FIXME: This will eventually have a bus type */ + libusb_device_handle *udev; + + /* FIXME: Remove, should be the driver private data */ + void *priv; + /* read-only to drivers */ struct fp_print_data *verify_data; @@ -153,6 +157,7 @@ struct fp_img_dev { /* FIXME: better place to put this? */ size_t identify_match_offset; + /* FIXME: Remove */ void *priv; }; From 4f75e63e25decf0d1cba094f20b1373629e1ee18 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 14 Sep 2018 18:37:21 +0200 Subject: [PATCH 056/225] lib: Remove fp_dev->priv Not precise enough, and it was only used in upekts to get/set the instance private struct and keep it around, so add a new, more precisely defined field to fp_dev for that. --- doc/libfprint-sections.txt | 2 ++ libfprint/core.c | 13 ------------- libfprint/drivers/upekts.c | 34 +++++++++++++++++----------------- libfprint/drivers_api.h | 2 -- libfprint/fp_internal.h | 5 ++--- libfprint/fpi-dev.c | 37 +++++++++++++++++++++++++++++++++++++ libfprint/fpi-dev.h | 4 ++++ 7 files changed, 62 insertions(+), 35 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 8e33b1d4..2b30ffdc 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -190,4 +190,6 @@ fp_img_dev FP_DEV FP_IMG_DEV +fp_dev_set_instance_data +FP_INSTANCE_DATA diff --git a/libfprint/core.c b/libfprint/core.c index 90dfc8c4..373ed3df 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -534,19 +534,6 @@ 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) { diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index 283ab019..7d650252 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -137,7 +137,7 @@ static struct libusb_transfer *alloc_send_cmd28_transfer(struct fp_dev *dev, uint16_t _innerlen = innerlen; size_t len = innerlen + 6; unsigned char *buf = g_malloc0(len); - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); uint8_t seq = upekdev->seq + CMD_SEQ_INCREMENT; struct libusb_transfer *ret; @@ -489,7 +489,7 @@ static void initsm_read_msg_response_cb(fpi_ssm *ssm, unsigned char expect_subcmd, unsigned char subcmd) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (status != READ_MSG_RESPONSE) { fp_err("expected response, got %d seq=%x in state %d", status, seq, @@ -553,7 +553,7 @@ static void initsm_read_msg_cmd_cb(fpi_ssm *ssm, enum read_msg_status status, uint8_t expect_seq, uint8_t seq) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (status == READ_MSG_ERROR) { fpi_ssm_mark_failed(ssm, -1); @@ -652,7 +652,7 @@ static void initsm_send_msg28_handler(fpi_ssm *ssm, static void initsm_run_state(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); struct libusb_transfer *transfer; int r; @@ -764,7 +764,7 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, void *user_data) { fpi_ssm *ssm = user_data; - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (status == READ_MSG_ERROR) { fpi_ssm_mark_failed(ssm, -1); @@ -834,7 +834,7 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data) upekdev = g_malloc(sizeof(*upekdev)); upekdev->seq = 0xf0; /* incremented to 0x00 before first cmd */ - fpi_dev_set_user_data(dev, upekdev); + fp_dev_set_instance_data(dev, upekdev); fpi_dev_set_nr_enroll_stages(dev, 3); fpi_drvcb_open_complete(dev, 0); @@ -843,10 +843,10 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data) static void dev_exit(struct fp_dev *dev) { - void *user_data; + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); + libusb_release_interface(fpi_dev_get_usb_dev(dev), 0); - user_data = fpi_dev_get_user_data(dev); - g_free(user_data); + g_free(upekdev); fpi_drvcb_close_complete(dev); } @@ -897,7 +897,7 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); fpi_ssm *ssm = user_data; if (status != READ_MSG_RESPONSE) { @@ -960,7 +960,7 @@ static void enroll_iterate(struct fp_dev *dev); static void e_handle_resp00(struct fp_dev *dev, unsigned char *data, size_t data_len) { - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); unsigned char status; int result = 0; @@ -1125,7 +1125,7 @@ static void enroll_started(fpi_ssm *ssm) static int enroll_start(struct fp_dev *dev) { - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); /* do_init state machine first */ fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state, @@ -1319,7 +1319,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, void *user_data) { - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (msgstat != READ_MSG_RESPONSE) { fp_err("expected response, got %d seq=%x", msgstat, seq); @@ -1358,7 +1358,7 @@ static void verify_wr2800_cb(struct libusb_transfer *transfer) static void verify_iterate(struct fp_dev *dev) { - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (upekdev->stop_verify) { do_verify_stop(dev); @@ -1394,7 +1394,7 @@ static void verify_iterate(struct fp_dev *dev) static void verify_started(fpi_ssm *ssm) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); fpi_drvcb_verify_started(dev, fpi_ssm_get_error(ssm)); if (!fpi_ssm_get_error(ssm)) { @@ -1407,7 +1407,7 @@ static void verify_started(fpi_ssm *ssm) static int verify_start(struct fp_dev *dev) { - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state, VERIFY_NUM_STATES); upekdev->stop_verify = FALSE; @@ -1417,7 +1417,7 @@ static int verify_start(struct fp_dev *dev) static int verify_stop(struct fp_dev *dev, gboolean iterating) { - struct upekts_dev *upekdev = fpi_dev_get_user_data(dev); + struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (!iterating) do_verify_stop(dev); diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 67caad5c..32c0a392 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -38,8 +38,6 @@ #include "drivers/driver_ids.h" libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); -void *fpi_dev_get_user_data (struct fp_dev *dev); -void fpi_dev_set_user_data (struct fp_dev *dev, void *user_data); 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); struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index d7627ff0..fb1d5a8b 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -68,15 +68,14 @@ struct fp_dev { /* only valid if drv->type == DRIVER_IMAGING */ struct fp_img_dev *img_dev; + /* Link to the instance specific struct */ + void *instance_data; int nr_enroll_stages; /* FIXME: This will eventually have a bus type */ libusb_device_handle *udev; - /* FIXME: Remove, should be the driver private data */ - void *priv; - /* read-only to drivers */ struct fp_print_data *verify_data; diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index 0eb80387..ffaff268 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -59,3 +59,40 @@ FP_IMG_DEV(struct fp_dev *dev) g_return_val_if_fail (dev->drv->type != DRIVER_IMAGING, NULL); return dev->img_dev; } + +/** + * fp_dev_set_instance_data: + * @dev: a struct #fp_dev + * @instance_data: a pointer to the instance data + * + * Set the instance data for a struct #fp_dev. This is usually a structure + * private to the driver used to keep state and pass it as user_data to + * asynchronous functions. + * + * The core does not do any memory management for this data, so the driver + * itself will have to create and free its own structure when appropriate. + */ +void +fp_dev_set_instance_data (struct fp_dev *dev, + void *instance_data) +{ + g_return_if_fail (dev); + g_return_if_fail (instance_data != NULL); + g_return_if_fail (dev->instance_data == NULL); + + dev->instance_data = instance_data; +} + +/** + * FP_INSTANCE_DATA: + * @dev: a struct #fp_dev + * + * Returns the instance data set using fp_dev_set_instance_data(). + */ +void * +FP_INSTANCE_DATA (struct fp_dev *dev) +{ + g_return_val_if_fail (dev, NULL); + + return dev->instance_data; +} diff --git a/libfprint/fpi-dev.h b/libfprint/fpi-dev.h index d21e14b4..dc0cd60f 100644 --- a/libfprint/fpi-dev.h +++ b/libfprint/fpi-dev.h @@ -29,3 +29,7 @@ struct fp_img_dev; struct fp_dev *FP_DEV (struct fp_img_dev *dev); struct fp_img_dev *FP_IMG_DEV (struct fp_dev *dev); + +void fp_dev_set_instance_data (struct fp_dev *dev, + void *instance_data); +void *FP_INSTANCE_DATA (struct fp_dev *dev); From 058f91909dcf3cd47f86d4a42e683630e5a1b332 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Sep 2018 00:45:42 +0200 Subject: [PATCH 057/225] lib: Remove fp_img_dev->priv And use the new instance data helper. --- libfprint/drivers/aes1610.c | 20 +++++++-------- libfprint/drivers/aes1660.c | 4 +-- libfprint/drivers/aes2501.c | 22 ++++++++-------- libfprint/drivers/aes2550.c | 20 +++++++-------- libfprint/drivers/aes2660.c | 4 +-- libfprint/drivers/aes3500.c | 4 +-- libfprint/drivers/aes3k.c | 8 +++--- libfprint/drivers/aes4000.c | 4 +-- libfprint/drivers/aesx660.c | 28 ++++++++++----------- libfprint/drivers/elan.c | 34 ++++++++++++------------- libfprint/drivers/etes603.c | 34 ++++++++++++------------- libfprint/drivers/upeksonly.c | 46 +++++++++++++++++----------------- libfprint/drivers/upektc.c | 30 +++++++++++----------- libfprint/drivers/upektc_img.c | 28 ++++++++++----------- libfprint/drivers/uru4000.c | 40 ++++++++++++++--------------- libfprint/drivers/vcom5s.c | 18 ++++++------- libfprint/drivers/vfs0050.c | 28 ++++++++++----------- libfprint/drivers/vfs101.c | 38 ++++++++++++++-------------- libfprint/drivers/vfs301.c | 12 ++++----- libfprint/drivers/vfs5011.c | 20 +++++++-------- libfprint/drivers_api.h | 3 --- libfprint/fp_internal.h | 3 --- libfprint/img.c | 13 ---------- 23 files changed, 221 insertions(+), 240 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index fe5de8db..d3303288 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -247,7 +247,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, void *user_da static void start_finger_detection(struct fp_img_dev *dev) { - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (aesdev->deactivating) { complete_deactivation(dev); @@ -559,7 +559,7 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer) unsigned char *stripdata; fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; int sum, i; @@ -646,7 +646,7 @@ out: static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -693,7 +693,7 @@ static void capture_run_state(fpi_ssm *ssm) static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); if (aesdev->deactivating) @@ -707,7 +707,7 @@ static void capture_sm_complete(fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; if (aesdev->deactivating) { @@ -766,7 +766,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -777,7 +777,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *dev) { - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* FIXME: audit cancellation points, probably need more, specifically * in error handling paths? */ aesdev->deactivating = TRUE; @@ -785,7 +785,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static void complete_deactivation(struct fp_img_dev *dev) { - struct aes1610_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); /* FIXME: if we're in the middle of a scan, we should cancel the scan. @@ -812,7 +812,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } aesdev = g_malloc0(sizeof(struct aes1610_dev)); - fpi_imgdev_set_user_data(dev, aesdev); + fp_dev_set_instance_data(FP_DEV(dev), aesdev); fpi_imgdev_open_complete(dev, 0); return 0; } @@ -820,7 +820,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { struct aes1610_dev *aesdev; - aesdev = fpi_imgdev_get_user_data(dev); + aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/aes1660.c b/libfprint/drivers/aes1660.c index bebbf5aa..c502a015 100644 --- a/libfprint/drivers/aes1660.c +++ b/libfprint/drivers/aes1660.c @@ -47,7 +47,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } aesdev = g_malloc0(sizeof(struct aesX660_dev)); - fpi_imgdev_set_user_data(dev, aesdev); + fp_dev_set_instance_data(FP_DEV(dev), aesdev); aesdev->buffer = g_malloc0(AES1660_FRAME_SIZE + AESX660_HEADER_SIZE); aesdev->init_seqs[0] = aes1660_init_1; aesdev->init_seqs_len[0] = G_N_ELEMENTS(aes1660_init_1); @@ -64,7 +64,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev->buffer); g_free(aesdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index ea626474..3fea5111 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -346,7 +346,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, static void start_finger_detection(struct fp_img_dev *dev) { - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); if (aesdev->deactivating) { @@ -438,7 +438,7 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer) unsigned char *stripdata; fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; int sum; int threshold; @@ -523,7 +523,7 @@ out: static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -574,7 +574,7 @@ static void capture_run_state(fpi_ssm *ssm) static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); if (aesdev->deactivating) @@ -588,7 +588,7 @@ static void capture_sm_complete(fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; if (aesdev->deactivating) { @@ -714,7 +714,7 @@ void activate_read_regs_cb(struct fp_img_dev *dev, int status, unsigned char *regs, void *user_data) { fpi_ssm *ssm = user_data; - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (status != 0) { fpi_ssm_mark_failed(ssm, status); @@ -804,7 +804,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -815,7 +815,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *dev) { - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* FIXME: audit cancellation points, probably need more, specifically * in error handling paths? */ aesdev->deactivating = TRUE; @@ -823,7 +823,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static void complete_deactivation(struct fp_img_dev *dev) { - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); /* FIXME: if we're in the middle of a scan, we should cancel the scan. @@ -849,14 +849,14 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } aesdev = g_malloc0(sizeof(struct aes2501_dev)); - fpi_imgdev_set_user_data(dev, aesdev); + fp_dev_set_instance_data(FP_DEV(dev), aesdev); fpi_imgdev_open_complete(dev, 0); return 0; } static void dev_deinit(struct fp_img_dev *dev) { - struct aes2501_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 1916aa15..8862f6f8 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -149,7 +149,7 @@ exit_free_transfer: static void start_finger_detection(struct fp_img_dev *dev) { int r; - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct libusb_transfer *transfer; G_DEBUG_HERE(); @@ -204,7 +204,7 @@ static int process_strip_data(fpi_ssm *ssm, unsigned char *data) { unsigned char *stripdata; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct fpi_frame *stripe; int len; @@ -246,7 +246,7 @@ static void capture_set_idle_reqs_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length) && @@ -274,7 +274,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; int r; @@ -389,7 +389,7 @@ static void capture_run_state(fpi_ssm *ssm) static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fp_dbg("Capture completed"); if (aesdev->deactivating) @@ -403,7 +403,7 @@ static void capture_sm_complete(fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; if (aesdev->deactivating) { @@ -590,14 +590,14 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *dev) { - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); aesdev->deactivating = TRUE; } static void complete_deactivation(struct fp_img_dev *dev) { - struct aes2550_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); aesdev->deactivating = FALSE; @@ -620,7 +620,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } aes2550_dev = g_malloc0(sizeof(struct aes2550_dev)); - fpi_imgdev_set_user_data(dev, aes2550_dev); + fp_dev_set_instance_data(FP_DEV(dev), aes2550_dev); fpi_imgdev_open_complete(dev, 0); return 0; } @@ -628,7 +628,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { struct aes2550_dev *aesdev; - aesdev = fpi_imgdev_get_user_data(dev); + aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/aes2660.c b/libfprint/drivers/aes2660.c index 99646839..67844419 100644 --- a/libfprint/drivers/aes2660.c +++ b/libfprint/drivers/aes2660.c @@ -47,7 +47,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } aesdev = g_malloc0(sizeof(struct aesX660_dev)); - fpi_imgdev_set_user_data(dev, aesdev); + fp_dev_set_instance_data(FP_DEV(dev), aesdev); aesdev->buffer = g_malloc0(AES2660_FRAME_SIZE + AESX660_HEADER_SIZE); /* No scaling for AES2660 */ aesdev->init_seqs[0] = aes2660_init_1; @@ -66,7 +66,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { struct aesX660_dev *aesdev; - aesdev = fpi_imgdev_get_user_data(dev); + aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev->buffer); g_free(aesdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); diff --git a/libfprint/drivers/aes3500.c b/libfprint/drivers/aes3500.c index 5d32f8ab..43d14867 100644 --- a/libfprint/drivers/aes3500.c +++ b/libfprint/drivers/aes3500.c @@ -129,7 +129,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } aesdev = g_malloc0(sizeof(struct aes3k_dev)); - fpi_imgdev_set_user_data(dev, aesdev); + fp_dev_set_instance_data(FP_DEV(dev), aesdev); if (!aesdev) return -ENOMEM; @@ -148,7 +148,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { - struct aes3k_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/aes3k.c b/libfprint/drivers/aes3k.c index d64efda8..e05fc8fe 100644 --- a/libfprint/drivers/aes3k.c +++ b/libfprint/drivers/aes3k.c @@ -63,7 +63,7 @@ static void aes3k_assemble_image(unsigned char *input, size_t width, size_t heig static void img_cb(struct libusb_transfer *transfer) { struct fp_img_dev *dev = transfer->user_data; - struct aes3k_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *ptr = transfer->buffer; struct fp_img *tmp; struct fp_img *img; @@ -112,7 +112,7 @@ err: static void do_capture(struct fp_img_dev *dev) { - struct aes3k_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data; int r; @@ -144,14 +144,14 @@ static void init_reqs_cb(struct fp_img_dev *dev, int result, void *user_data) int aes3k_dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct aes3k_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); aes_write_regv(dev, aesdev->init_reqs, aesdev->init_reqs_len, init_reqs_cb, NULL); return 0; } void aes3k_dev_deactivate(struct fp_img_dev *dev) { - struct aes3k_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* FIXME: should wait for cancellation to complete before returning * from deactivation, otherwise app may legally exit before we've diff --git a/libfprint/drivers/aes4000.c b/libfprint/drivers/aes4000.c index c26dc64a..419d791f 100644 --- a/libfprint/drivers/aes4000.c +++ b/libfprint/drivers/aes4000.c @@ -126,7 +126,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } aesdev = g_malloc0(sizeof(struct aes3k_dev)); - fpi_imgdev_set_user_data(dev, aesdev); + fp_dev_set_instance_data(FP_DEV(dev), aesdev); if (!aesdev) return -ENOMEM; @@ -145,7 +145,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { - struct aes3k_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index 15852552..af6498c7 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -145,7 +145,7 @@ static void finger_det_read_fd_data_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; aesdev->fd_data_transfer = NULL; @@ -198,7 +198,7 @@ static void finger_det_set_idle_cmd_cb(struct libusb_transfer *transfer) static void finger_det_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); fp_dbg("Finger detection completed"); @@ -240,7 +240,7 @@ static void finger_det_run_state(fpi_ssm *ssm) static void start_finger_detection(struct fp_img_dev *dev) { fpi_ssm *ssm; - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (aesdev->deactivating) { complete_deactivation(dev); @@ -268,7 +268,7 @@ static int process_stripe_data(fpi_ssm *ssm, unsigned char *data) struct fpi_frame *stripe; unsigned char *stripdata; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); stripe = g_malloc(aesdev->assembling_ctx->frame_width * FRAME_HEIGHT / 2 + sizeof(struct fpi_frame)); /* 4 bpp */ stripdata = stripe->data; @@ -296,7 +296,7 @@ static void capture_set_idle_cmd_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -322,7 +322,7 @@ static void capture_read_stripe_data_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; int finger_missing = 0; size_t copied, actual_len = transfer->actual_length; @@ -374,7 +374,7 @@ out: static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_SEND_LED_CMD: @@ -403,7 +403,7 @@ static void capture_run_state(fpi_ssm *ssm) static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); fp_dbg("Capture completed"); @@ -419,7 +419,7 @@ static void capture_sm_complete(fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; if (aesdev->deactivating) { @@ -450,7 +450,7 @@ static void activate_read_id_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) || @@ -501,7 +501,7 @@ static void activate_read_init_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; fp_dbg("read_init_cb\n"); @@ -537,7 +537,7 @@ out: static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case ACTIVATE_SET_IDLE: @@ -603,7 +603,7 @@ int aesX660_dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) void aesX660_dev_deactivate(struct fp_img_dev *dev) { - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (aesdev->fd_data_transfer) libusb_cancel_transfer(aesdev->fd_data_transfer); @@ -613,7 +613,7 @@ void aesX660_dev_deactivate(struct fp_img_dev *dev) static void complete_deactivation(struct fp_img_dev *dev) { - struct aesX660_dev *aesdev = fpi_imgdev_get_user_data(dev); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); aesdev->deactivating = FALSE; diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index a3b3e538..8f8203b2 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -290,7 +290,7 @@ static void elan_process_frame_thirds(unsigned short *raw_frame, static void elan_submit_image(struct fp_img_dev *dev) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); GSList *frames = NULL; struct fp_img *img; @@ -323,7 +323,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -365,7 +365,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) static void elan_cmd_read(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); int response_len = elandev->cmd->response_len; G_DEBUG_HERE(); @@ -405,7 +405,7 @@ static void elan_run_cmd(fpi_ssm *ssm, const struct elan_cmd *cmd, int cmd_timeout) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); dbg_buf(cmd->cmd, 2); @@ -454,7 +454,7 @@ static void stop_capture_run_state(fpi_ssm *ssm) static void stop_capture_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); int error = fpi_ssm_get_error(ssm); G_DEBUG_HERE(); @@ -479,7 +479,7 @@ static void stop_capture_complete(fpi_ssm *ssm) static void elan_stop_capture(struct fp_img_dev *dev) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -503,7 +503,7 @@ enum capture_states { static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -541,7 +541,7 @@ static void capture_run_state(fpi_ssm *ssm) static void capture_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -573,7 +573,7 @@ static void capture_complete(fpi_ssm *ssm) static void elan_capture(struct fp_img_dev *dev) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -627,7 +627,7 @@ enum calibrate_states { static void calibrate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -704,7 +704,7 @@ static void calibrate_complete(fpi_ssm *ssm) static void elan_calibrate(struct fp_img_dev *dev) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -729,7 +729,7 @@ enum activate_states { static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -785,7 +785,7 @@ static void activate_complete(fpi_ssm *ssm) static void elan_activate(struct fp_img_dev *dev) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); elan_dev_reset(elandev); @@ -810,7 +810,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } elandev = g_malloc0(sizeof(struct elan_dev)); - fpi_imgdev_set_user_data(dev, elandev); + fp_dev_set_instance_data(FP_DEV(dev), elandev); /* common params */ elandev->dev_type = driver_data; @@ -836,7 +836,7 @@ static void elan_deactivate(struct fp_img_dev *dev) static void dev_deinit(struct fp_img_dev *dev) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -856,7 +856,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) static void elan_change_state(struct fp_img_dev *dev) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); enum fp_imgdev_state next_state = elandev->dev_state_next; if (elandev->dev_state == next_state) { @@ -894,7 +894,7 @@ static void elan_change_state_async(void *data) static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct elan_dev *elandev = fpi_imgdev_get_user_data(dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index 2e2799ba..741daeb3 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -639,7 +639,7 @@ enum { static int async_tx(struct fp_img_dev *idev, unsigned int ep, void *cb, void *cb_arg) { - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *buffer; int length; @@ -671,7 +671,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fp_warn("transfer is not completed (status=%d)", @@ -702,7 +702,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) static void m_exit_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); switch (fpi_ssm_get_cur_state(ssm)) { case EXIT_SET_REGS_REQ: @@ -752,7 +752,7 @@ static void m_exit_start(struct fp_img_dev *idev) static void m_capture_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -833,7 +833,7 @@ err: static void m_capture_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (fpi_ssm_get_error(ssm)) { if (fpi_imgdev_get_action_state(idev) != IMG_ACQUIRE_STATE_DEACTIVATING) { @@ -855,7 +855,7 @@ static void m_capture_complete(fpi_ssm *ssm) static void m_finger_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -951,7 +951,7 @@ err: static void m_finger_complete(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_cap; @@ -985,7 +985,7 @@ static void m_start_fingerdetect(struct fp_img_dev *idev) static void m_tunevrb_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); float hist[5]; if (dev->is_active == FALSE) { @@ -1143,7 +1143,7 @@ static void m_tunevrb_complete(fpi_ssm *ssm) fp_dbg("Tuning is done. Starting finger detection."); m_start_fingerdetect(idev); } else { - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); fp_err("Error while tuning VRT"); dev->is_active = FALSE; reset_param(dev); @@ -1159,7 +1159,7 @@ static void m_tunevrb_complete(fpi_ssm *ssm) static void m_tunedc_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -1269,7 +1269,7 @@ static void m_tunedc_complete(fpi_ssm *ssm) fpi_ssm_set_user_data(ssm_tune, idev); fpi_ssm_start(ssm_tune, m_tunevrb_complete); } else { - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); fp_err("Error while tuning DCOFFSET"); dev->is_active = FALSE; reset_param(dev); @@ -1281,7 +1281,7 @@ static void m_tunedc_complete(fpi_ssm *ssm) static void m_init_state(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -1389,7 +1389,7 @@ static void m_init_complete(fpi_ssm *ssm) fpi_ssm_set_user_data(ssm_tune, idev); fpi_ssm_start(ssm_tune, m_tunedc_complete); } else { - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); fp_err("Error initializing the device"); dev->is_active = FALSE; reset_param(dev); @@ -1400,7 +1400,7 @@ static void m_init_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) { - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); fpi_ssm *ssm; g_assert(dev); @@ -1433,7 +1433,7 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *idev) { - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); fp_dbg("deactivating"); @@ -1450,7 +1450,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) struct etes603_dev *dev; dev = g_malloc0(sizeof(struct etes603_dev)); - fpi_imgdev_set_user_data(idev, dev); + fp_dev_set_instance_data(FP_DEV(idev), dev); dev->req = g_malloc(sizeof(struct egis_msg)); dev->ans = g_malloc(FE_SIZE); @@ -1468,7 +1468,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) static void dev_close(struct fp_img_dev *idev) { - struct etes603_dev *dev = fpi_imgdev_get_user_data(idev); + struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); g_free(dev->req); g_free(dev->ans); diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 62a61a15..69aaa0a8 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -176,7 +176,7 @@ static void free_img_transfers(struct sonly_dev *sdev) static void last_transfer_killed(struct fp_img_dev *dev) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (sdev->killing_transfers) { case ABORT_SSM: fp_dbg("abort ssm error %d", sdev->kill_status_code); @@ -197,7 +197,7 @@ static void last_transfer_killed(struct fp_img_dev *dev) static void cancel_img_transfers(struct fp_img_dev *dev) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int i; if (sdev->num_flying == 0) { @@ -224,7 +224,7 @@ static gboolean is_capturing(struct sonly_dev *sdev) static void handoff_img(struct fp_img_dev *dev) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct fp_img *img; GSList *elem = sdev->rows; @@ -252,7 +252,7 @@ static void handoff_img(struct fp_img_dev *dev) static void row_complete(struct fp_img_dev *dev) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); sdev->rowbuf_offset = -1; if (sdev->num_rows > 0) { @@ -340,7 +340,7 @@ static void row_complete(struct fp_img_dev *dev) /* add data to row buffer */ static void add_to_rowbuf(struct fp_img_dev *dev, unsigned char *data, int size) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); memcpy(sdev->rowbuf + sdev->rowbuf_offset, data, size); sdev->rowbuf_offset += size; @@ -374,7 +374,7 @@ static int rowbuf_remaining(struct sonly_dev *sdev) static void handle_packet(struct fp_img_dev *dev, unsigned char *data) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); uint16_t seqnum = data[0] << 8 | data[1]; int abs_base_addr; int for_rowbuf; @@ -470,7 +470,7 @@ static void img_data_cb(struct libusb_transfer *transfer) { struct img_transfer_data *idata = transfer->user_data; struct fp_img_dev *dev = idata->dev; - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int i; idata->flying = FALSE; @@ -649,7 +649,7 @@ static void sm_read_reg_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_mark_failed(ssm, -EIO); @@ -695,7 +695,7 @@ static void sm_await_intr_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { g_free(transfer->buffer); @@ -766,7 +766,7 @@ enum awfsm_1000_states { static void awfsm_2016_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case AWFSM_2016_WRITEV_1: @@ -854,7 +854,7 @@ enum capsm_1001_states { static void capsm_fire_bulk(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int i; for (i = 0; i < NUM_BULK_TRANSFERS; i++) { int r = libusb_submit_transfer(sdev->img_transfer[i]); @@ -884,7 +884,7 @@ static void capsm_fire_bulk(fpi_ssm *ssm) static void capsm_2016_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case CAPSM_2016_INIT: @@ -916,7 +916,7 @@ static void capsm_2016_run_state(fpi_ssm *ssm) static void capsm_1000_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case CAPSM_1000_INIT: @@ -942,7 +942,7 @@ static void capsm_1000_run_state(fpi_ssm *ssm) static void capsm_1001_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case CAPSM_1001_INIT: @@ -1051,7 +1051,7 @@ enum initsm_1001_states { static void initsm_2016_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_2016_WRITEV_1: @@ -1123,7 +1123,7 @@ enum loopsm_states { static void loopsm_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case LOOPSM_RUN_AWFSM: ; @@ -1218,7 +1218,7 @@ static void loopsm_run_state(fpi_ssm *ssm) static void deactivate_done(struct fp_img_dev *dev) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); free_img_transfers(sdev); @@ -1235,7 +1235,7 @@ static void deactivate_done(struct fp_img_dev *dev) static void dev_deactivate(struct fp_img_dev *dev) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (!sdev->capturing) { deactivate_done(dev); @@ -1251,7 +1251,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static void loopsm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); @@ -1270,7 +1270,7 @@ static void loopsm_complete(fpi_ssm *ssm) static void initsm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); @@ -1285,7 +1285,7 @@ static void initsm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct sonly_dev *sdev = fpi_imgdev_get_user_data(dev); + struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = NULL; int i; @@ -1333,7 +1333,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data); static void dev_deinit(struct fp_img_dev *dev) { void *user_data; - user_data = fpi_imgdev_get_user_data(dev); + user_data = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(user_data); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); @@ -1400,7 +1400,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } sdev = g_malloc0(sizeof(struct sonly_dev)); - fpi_imgdev_set_user_data(dev, sdev); + fp_dev_set_instance_data(FP_DEV(dev), sdev); sdev->dev_model = (int)driver_data; switch (driver_data) { case UPEKSONLY_1000: diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index e70d204b..4fd7901a 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -59,7 +59,7 @@ enum activate_states { static void upektc_next_init_cmd(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); upekdev->init_idx += 1; if (upekdev->init_idx == upekdev->setup_commands_len) @@ -72,7 +72,7 @@ static void write_init_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) && (transfer->length == transfer->actual_length)) { @@ -101,7 +101,7 @@ static void read_init_data_cb(struct libusb_transfer *transfer) static void activate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -181,7 +181,7 @@ static int finger_present(unsigned char *img, size_t len, int sum_threshold) static void finger_det_data_cb(struct libusb_transfer *transfer) { struct fp_img_dev *dev = transfer->user_data; - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { @@ -214,7 +214,7 @@ static void finger_det_cmd_cb(struct libusb_transfer *t) unsigned char *data; int r; struct fp_img_dev *dev = t->user_data; - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (t->status != LIBUSB_TRANSFER_COMPLETED) { fp_dbg("req transfer status %d\n", t->status); @@ -249,7 +249,7 @@ exit_free_transfer: static void start_finger_detection(struct fp_img_dev *dev) { int r; - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct libusb_transfer *transfer; G_DEBUG_HERE(); @@ -324,7 +324,7 @@ out: static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -373,7 +373,7 @@ static void capture_run_state(fpi_ssm *ssm) static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fp_dbg("Capture completed"); if (upekdev->deactivating) @@ -387,7 +387,7 @@ static void capture_sm_complete(fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; if (upekdev->deactivating) { @@ -403,7 +403,7 @@ static void start_capture(struct fp_img_dev *dev) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -414,14 +414,14 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *dev) { - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); upekdev->deactivating = TRUE; } static void complete_deactivation(struct fp_img_dev *dev) { - struct upektc_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); upekdev->deactivating = FALSE; @@ -441,7 +441,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } upekdev = g_malloc0(sizeof(struct upektc_dev)); - fpi_imgdev_set_user_data(dev, upekdev); + fp_dev_set_instance_data(FP_DEV(dev), upekdev); switch (driver_data) { case UPEKTC_2015: upekdev->ep_in = UPEKTC_EP_IN; @@ -460,7 +460,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) default: fp_err("Device variant %lu is not known\n", driver_data); g_free(upekdev); - fpi_imgdev_set_user_data(dev, NULL); + fp_dev_set_instance_data(FP_DEV(dev), NULL); return -ENODEV; break; } @@ -471,7 +471,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { void *user_data; - user_data = fpi_imgdev_get_user_data(dev); + user_data = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(user_data); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 495b6790..5296c468 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -76,7 +76,7 @@ static void upektc_img_submit_req(fpi_ssm *ssm, libusb_transfer_cb_fn cb) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct libusb_transfer *transfer = libusb_alloc_transfer(0); int r; @@ -107,7 +107,7 @@ static void upektc_img_read_data(fpi_ssm *ssm, size_t buf_size, size_t buf_offse { struct libusb_transfer *transfer = libusb_alloc_transfer(0); struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; if (!transfer) { @@ -183,7 +183,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = upekdev->response; struct fp_img *img; size_t response_size; @@ -307,7 +307,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) static void capture_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_INIT_CAPTURE: @@ -344,7 +344,7 @@ static void capture_run_state(fpi_ssm *ssm) static void capture_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); fp_dbg("Capture completed, %d", err); @@ -360,7 +360,7 @@ static void capture_sm_complete(fpi_ssm *ssm) static void start_capture(struct fp_img_dev *dev) { - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; upekdev->image_size = 0; @@ -405,7 +405,7 @@ static void deactivate_read_data_cb(struct libusb_transfer *transfer) static void deactivate_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case DEACTIVATE_DEINIT: @@ -422,7 +422,7 @@ static void deactivate_run_state(fpi_ssm *ssm) static void deactivate_sm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); fp_dbg("Deactivate completed"); @@ -439,7 +439,7 @@ static void deactivate_sm_complete(fpi_ssm *ssm) static void start_deactivation(struct fp_img_dev *dev) { - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; upekdev->image_size = 0; @@ -504,7 +504,7 @@ static void activate_run_state(fpi_ssm *ssm) { struct libusb_transfer *transfer; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(idev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(idev)); struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; @@ -579,7 +579,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -590,7 +590,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *dev) { - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); upekdev->deactivating = TRUE; } @@ -608,14 +608,14 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } upekdev = g_malloc0(sizeof(struct upektc_img_dev)); - fpi_imgdev_set_user_data(dev, upekdev); + fp_dev_set_instance_data(FP_DEV(dev), upekdev); fpi_imgdev_open_complete(dev, 0); return 0; } static void dev_deinit(struct fp_img_dev *dev) { - struct upektc_img_dev *upekdev = fpi_imgdev_get_user_data(dev); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(upekdev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index cad94fa4..dae2685e 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -317,7 +317,7 @@ static void challenge_cb(struct fp_img_dev *dev, int status, uint16_t num_regs, unsigned char *data, void *user_data) { fpi_ssm *ssm = user_data; - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *respdata; PK11Context *ctx; int r, outlen; @@ -374,7 +374,7 @@ static int start_irq_handler(struct fp_img_dev *dev); static void irq_handler(struct libusb_transfer *transfer) { struct fp_img_dev *dev = transfer->user_data; - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *data = transfer->buffer; uint16_t type; int r = 0; @@ -426,7 +426,7 @@ out: static int start_irq_handler(struct fp_img_dev *dev) { - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; int r; @@ -450,7 +450,7 @@ static int start_irq_handler(struct fp_img_dev *dev) static void stop_irq_handler(struct fp_img_dev *dev, irqs_stopped_cb_fn cb) { - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); struct libusb_transfer *transfer = urudev->irq_transfer; if (transfer) { libusb_cancel_transfer(transfer); @@ -484,7 +484,7 @@ static void change_state_write_reg_cb(struct fp_img_dev *dev, int status, static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (state) { case IMGDEV_STATE_INACTIVE: @@ -535,7 +535,7 @@ static void sm_read_reg_cb(struct fp_img_dev *dev, int result, uint16_t num_regs, unsigned char *data, void *user_data) { fpi_ssm *ssm = user_data; - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); if (result) { fpi_ssm_mark_failed(ssm, result); @@ -549,7 +549,7 @@ static void sm_read_reg_cb(struct fp_img_dev *dev, int result, static void sm_read_regs(fpi_ssm *ssm, uint16_t reg, uint16_t num_regs) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; if (num_regs > sizeof(urudev->last_reg_rd)) { @@ -690,7 +690,7 @@ static int calc_dev2(struct uru4k_image *img) static void imaging_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); struct uru4k_image *img = urudev->img_data; struct fp_img *fpimg; uint32_t key; @@ -813,7 +813,7 @@ static void imaging_run_state(fpi_ssm *ssm) static void imaging_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); @@ -864,7 +864,7 @@ static void rebootpwr_pause_cb(void *data) { fpi_ssm *ssm = data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); if (!--urudev->rebootpwr_ctr) { fp_err("could not reboot device power"); @@ -877,7 +877,7 @@ static void rebootpwr_pause_cb(void *data) static void rebootpwr_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case REBOOTPWR_SET_HWSTAT: @@ -941,7 +941,7 @@ static void powerup_pause_cb(void *data) { fpi_ssm *ssm = data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); if (!--urudev->powerup_ctr) { fp_err("could not power device up"); @@ -956,7 +956,7 @@ static void powerup_pause_cb(void *data) static void powerup_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case POWERUP_INIT: @@ -1025,7 +1025,7 @@ static void init_scanpwr_irq_cb(struct fp_img_dev *dev, int status, uint16_t type, void *user_data) { fpi_ssm *ssm = user_data; - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); if (status) fpi_ssm_mark_failed(ssm, status); @@ -1044,7 +1044,7 @@ static void init_scanpwr_timeout(void *user_data) { fpi_ssm *ssm = user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); fp_warn("powerup timed out"); urudev->irq_cb = NULL; @@ -1061,7 +1061,7 @@ static void init_scanpwr_timeout(void *user_data) static void init_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case INIT_GET_HWSTAT: @@ -1159,7 +1159,7 @@ static void activate_initsm_complete(fpi_ssm *ssm) * call. */ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; int r; @@ -1195,7 +1195,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static int execute_state_change(struct fp_img_dev *dev) { - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; switch (urudev->activate_state) { @@ -1351,7 +1351,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } urudev->param = PK11_ParamFromIV(urudev->cipher, NULL); - fpi_imgdev_set_user_data(dev, urudev); + fp_dev_set_instance_data(FP_DEV(dev), urudev); fpi_imgdev_open_complete(dev, 0); out: @@ -1361,7 +1361,7 @@ out: static void dev_deinit(struct fp_img_dev *dev) { - struct uru4k_dev *urudev = fpi_imgdev_get_user_data(dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); if (urudev->symkey) PK11_FreeSymKey (urudev->symkey); if (urudev->param) diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index 539ffadf..8a0f157d 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -193,7 +193,7 @@ static void capture_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); + struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_mark_failed(ssm, -EIO); @@ -221,7 +221,7 @@ out: static void capture_iterate(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); + struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int iteration = vdev->capture_iteration; struct libusb_transfer *transfer = libusb_alloc_transfer(0); int r; @@ -246,7 +246,7 @@ static void capture_iterate(fpi_ssm *ssm) static void sm_do_capture(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); + struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); vdev->capture_img = fpi_img_new_for_imgdev(dev); @@ -268,7 +268,7 @@ enum loop_states { static void loop_run_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); + struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case LOOP_SET_CONTRAST: @@ -296,7 +296,7 @@ static void loop_run_state(fpi_ssm *ssm) static void loopsm_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); + struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); @@ -313,7 +313,7 @@ static void loopsm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); + struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), loop_run_state, LOOP_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); @@ -326,7 +326,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) static void dev_deactivate(struct fp_img_dev *dev) { - struct v5s_dev *vdev = fpi_imgdev_get_user_data(dev); + struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); if (vdev->loop_running) vdev->deactivating = TRUE; else @@ -339,7 +339,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) struct v5s_dev *v5s_dev; v5s_dev = g_malloc0(sizeof(struct v5s_dev)); - fpi_imgdev_set_user_data(dev, v5s_dev); + fp_dev_set_instance_data(FP_DEV(dev), v5s_dev); r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); if (r < 0) @@ -354,7 +354,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_deinit(struct fp_img_dev *dev) { struct v5s_dev *v5s_dev; - v5s_dev = fpi_imgdev_get_user_data(dev); + v5s_dev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(v5s_dev); libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 54b24f9a..2cf46600 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -55,7 +55,7 @@ static void async_write(fpi_ssm *ssm, void *data, int len) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); vdev->transfer = libusb_alloc_transfer(0); vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; @@ -97,7 +97,7 @@ static void async_read(fpi_ssm *ssm, int ep, void *data, int len) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); ep |= LIBUSB_ENDPOINT_IN; @@ -151,7 +151,7 @@ static void async_abort(fpi_ssm *ssm, int ep) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); int len = VFS_USB_BUFFER_SIZE; unsigned char *data = g_malloc(VFS_USB_BUFFER_SIZE); @@ -259,7 +259,7 @@ static struct fp_img *prepare_image(struct vfs_dev_t *vdev) /* Processes and submits image after fingerprint received */ static void submit_image(struct fp_img_dev *idev) { - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); /* We were not asked to submit image actually */ if (!vdev->active) @@ -320,7 +320,7 @@ static void clear_ep2(fpi_ssm *ssm) static void send_control_packet_ssm(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); short result; unsigned char *commit_result = NULL; @@ -408,7 +408,7 @@ static void interrupt_callback(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); char *interrupt = vdev->interrupt; int error = transfer->status, transferred = transfer->actual_length; @@ -468,7 +468,7 @@ static void receive_callback(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); int transferred = transfer->actual_length, error = transfer->status; @@ -496,7 +496,7 @@ static void wait_interrupt(void *data) { fpi_ssm *ssm = data; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); /* Keep sleeping while this flag is on */ if (vdev->wait_interrupt) @@ -522,7 +522,7 @@ static void activate_ssm(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); switch (fpi_ssm_get_cur_state(ssm)) { case SSM_INITIAL_ABORT_1: @@ -674,7 +674,7 @@ static void activate_ssm(fpi_ssm *ssm) static void dev_activate_callback(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); vdev->ssm_active = 0; @@ -684,7 +684,7 @@ static void dev_activate_callback(fpi_ssm *ssm) /* Activate device */ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) { - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); /* Initialize flags */ vdev->active = 1; @@ -700,7 +700,7 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) /* Deactivate device */ static void dev_deactivate(struct fp_img_dev *idev) { - struct vfs_dev_t *vdev = fpi_imgdev_get_user_data(idev); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); if (!vdev->ssm_active) { fpi_imgdev_deactivate_complete(idev); @@ -735,7 +735,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) /* Initialize private structure */ vdev = g_malloc0(sizeof(struct vfs_dev_t)); - fpi_imgdev_set_user_data(idev, vdev); + fp_dev_set_instance_data(FP_DEV(idev), vdev); /* Clearing previous device state */ fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), activate_ssm, SSM_STATES); @@ -750,7 +750,7 @@ static void dev_close(struct fp_img_dev *idev) struct vfs_dev_t *vdev; /* Release private structure */ - vdev = fpi_imgdev_get_user_data(idev); + vdev = FP_INSTANCE_DATA(FP_DEV(idev)); g_free(vdev); /* Release usb interface */ diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index a2ac6b9c..0d4d2922 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -201,7 +201,7 @@ static void async_send_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Cleanup transfer */ vdev->transfer = NULL; @@ -245,7 +245,7 @@ out: static void async_send(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; /* Allocation of transfer */ @@ -285,7 +285,7 @@ static void async_recv_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Cleanup transfer */ vdev->transfer = NULL; @@ -332,7 +332,7 @@ out: static void async_recv(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; /* Allocation of transfer */ @@ -369,7 +369,7 @@ static void async_load_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Cleanup transfer */ vdev->transfer = NULL; @@ -433,7 +433,7 @@ out: static void async_load(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *buffer; int r; @@ -472,7 +472,7 @@ static void async_sleep_cb(void *data) { fpi_ssm *ssm = data; struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Cleanup timeout */ vdev->timeout = NULL; @@ -484,7 +484,7 @@ static void async_sleep_cb(void *data) static void async_sleep(unsigned int msec, fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Add timeout */ vdev->timeout = fpi_timeout_add(msec, async_sleep_cb, ssm); @@ -527,7 +527,7 @@ static void m_swap_state(fpi_ssm *ssm) static void m_swap(fpi_ssm *ssm, unsigned char *data, size_t length) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *subsm; /* Prepare data for sending */ @@ -626,7 +626,7 @@ static void vfs_get_finger_state(fpi_ssm *ssm) static void vfs_img_load(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -644,7 +644,7 @@ static void vfs_img_load(fpi_ssm *ssm) /* Check if action is completed */ static int action_completed(struct fp_img_dev *dev) { - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); if ((fpi_imgdev_get_action(dev) == IMG_ACTION_ENROLL) && (vdev->enroll_stage < fpi_dev_get_nr_enroll_stages(fpi_imgdev_get_dev(dev)))) @@ -757,7 +757,7 @@ static void img_copy(struct vfs101_dev *vdev, struct fp_img *img) static void img_extract(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct fp_img *img; /* Screen image to remove noise and find top and bottom line */ @@ -915,7 +915,7 @@ enum static void m_loop_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Check action state */ if (!vdev->active) @@ -1179,7 +1179,7 @@ enum static void m_init_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Check action state */ if (!vdev->active) @@ -1420,7 +1420,7 @@ static void m_init_state(fpi_ssm *ssm) static void m_init_complete(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm_loop; if (!fpi_ssm_get_error(ssm) && vdev->active) @@ -1441,7 +1441,7 @@ static void m_init_complete(fpi_ssm *ssm) /* Activate device */ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; /* Check if already active */ @@ -1474,7 +1474,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) /* Deactivate device */ static void dev_deactivate(struct fp_img_dev *dev) { - struct vfs101_dev *vdev = fpi_imgdev_get_user_data(dev); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Reset active state */ vdev->active = FALSE; @@ -1505,7 +1505,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) /* Initialize private structure */ vdev = g_malloc0(sizeof(struct vfs101_dev)); vdev->seqnum = -1; - fpi_imgdev_set_user_data(dev, vdev); + fp_dev_set_instance_data(FP_DEV(dev), vdev); /* Notify open complete */ fpi_imgdev_open_complete(dev, 0); @@ -1519,7 +1519,7 @@ static void dev_close(struct fp_img_dev *dev) struct vfs101_dev *vdev; /* Release private structure */ - vdev = fpi_imgdev_get_user_data(dev); + vdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(vdev); /* Release usb interface */ diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 66806aef..177075bf 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -54,7 +54,7 @@ static void async_sleep(unsigned int msec, fpi_ssm *ssm) static int submit_image(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - vfs301_dev_t *vdev = fpi_imgdev_get_user_data(dev); + vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int height; struct fp_img *img; @@ -106,7 +106,7 @@ enum static void m_loop_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - vfs301_dev_t *vdev = fpi_imgdev_get_user_data(dev); + vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case M_REQUEST_PRINT: @@ -171,7 +171,7 @@ static void m_loop_complete(fpi_ssm *ssm) static void m_init_state(fpi_ssm *ssm) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - vfs301_dev_t *vdev = fpi_imgdev_get_user_data(dev); + vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_assert(fpi_ssm_get_cur_state(ssm) == 0); @@ -218,7 +218,7 @@ static void dev_deactivate(struct fp_img_dev *dev) { vfs301_dev_t *vdev; - vdev = fpi_imgdev_get_user_data(dev); + vdev = FP_INSTANCE_DATA(FP_DEV(dev)); vfs301_proto_deinit(fpi_imgdev_get_usb_dev(dev), vdev); fpi_imgdev_deactivate_complete(dev); } @@ -238,7 +238,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) /* Initialize private structure */ vdev = g_malloc0(sizeof(vfs301_dev_t)); - fpi_imgdev_set_user_data(dev, vdev); + fp_dev_set_instance_data(FP_DEV(dev), vdev); vdev->scanline_buf = malloc(0); vdev->scanline_count = 0; @@ -254,7 +254,7 @@ static void dev_close(struct fp_img_dev *dev) vfs301_dev_t *vdev; /* Release private structure */ - vdev = fpi_imgdev_get_user_data(dev); + vdev = FP_INSTANCE_DATA(FP_DEV(dev)); free(vdev->scanline_buf); g_free(vdev); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 93deb053..df0552ec 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -426,7 +426,7 @@ static void chunk_capture_callback(struct libusb_transfer *transfer) struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) || (transfer->status == LIBUSB_TRANSFER_TIMED_OUT)) { @@ -674,7 +674,7 @@ static void activate_loop(fpi_ssm *ssm) int r; fpi_timeout *timeout; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); fp_dbg("main_loop: state %d", fpi_ssm_get_cur_state(ssm)); @@ -748,7 +748,7 @@ static void activate_loop_complete(fpi_ssm *ssm) struct vfs5011_data *data; int r = fpi_ssm_get_error(ssm); - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); fp_dbg("finishing"); if (data->init_sequence.receive_buf != NULL) @@ -777,7 +777,7 @@ static void open_loop(fpi_ssm *ssm) struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case DEV_OPEN_START: @@ -798,7 +798,7 @@ static void open_loop_complete(fpi_ssm *ssm) struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(data->init_sequence.receive_buf); data->init_sequence.receive_buf = NULL; @@ -815,7 +815,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) data = (struct vfs5011_data *)g_malloc0(sizeof(*data)); data->capture_buffer = (unsigned char *)g_malloc0(CAPTURE_LINES * VFS5011_LINE_SIZE); - fpi_imgdev_set_user_data(dev, data); + fp_dev_set_instance_data(FP_DEV(dev), data); r = libusb_reset_device(fpi_imgdev_get_usb_dev(dev)); if (r != 0) { @@ -841,7 +841,7 @@ static void dev_close(struct fp_img_dev *dev) { libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); struct vfs5011_data *data; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); if (data != NULL) { g_free(data->capture_buffer); g_slist_free_full(data->rows, g_free); @@ -855,7 +855,7 @@ static void start_scan(struct fp_img_dev *dev) struct vfs5011_data *data; fpi_ssm *ssm; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); data->loop_running = TRUE; fp_dbg("creating ssm"); ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_loop, DEV_ACTIVATE_NUM_STATES); @@ -869,7 +869,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct vfs5011_data *data; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); fp_dbg("device initialized"); data->deactivating = FALSE; @@ -883,7 +883,7 @@ static void dev_deactivate(struct fp_img_dev *dev) int r; struct vfs5011_data *data; - data = fpi_imgdev_get_user_data(dev); + data = FP_INSTANCE_DATA(FP_DEV(dev)); if (data->loop_running) { data->deactivating = TRUE; if (data->flying_transfer) { diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 32c0a392..a7994b8c 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -68,9 +68,6 @@ enum fp_imgdev_enroll_state { }; libusb_device_handle *fpi_imgdev_get_usb_dev(struct fp_img_dev *dev); -void fpi_imgdev_set_user_data(struct fp_img_dev *imgdev, - void *user_data); -void *fpi_imgdev_get_user_data(struct fp_img_dev *imgdev); struct fp_dev *fpi_imgdev_get_dev(struct fp_img_dev *imgdev); enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev); enum fp_imgdev_action fpi_imgdev_get_action(struct fp_img_dev *imgdev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index fb1d5a8b..aac8f60e 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -155,9 +155,6 @@ struct fp_img_dev { /* FIXME: better place to put this? */ size_t identify_match_offset; - - /* FIXME: Remove */ - void *priv; }; int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev); diff --git a/libfprint/img.c b/libfprint/img.c index f49c7163..ff46f01b 100644 --- a/libfprint/img.c +++ b/libfprint/img.c @@ -539,19 +539,6 @@ fpi_imgdev_get_usb_dev(struct fp_img_dev *dev) return FP_DEV(dev)->udev; } -void -fpi_imgdev_set_user_data(struct fp_img_dev *imgdev, - void *user_data) -{ - imgdev->priv = user_data; -} - -void * -fpi_imgdev_get_user_data(struct fp_img_dev *imgdev) -{ - return imgdev->priv; -} - struct fp_dev * fpi_imgdev_get_dev(struct fp_img_dev *imgdev) { From 57b38a2876e8deec422bef9b80bee6195042de8d Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Sep 2018 00:50:44 +0200 Subject: [PATCH 058/225] lib: Remove fpi_imgdev_get_dev() This is now handled by FP_DEV() --- libfprint/drivers/aes1610.c | 4 ++-- libfprint/drivers/aes2501.c | 4 ++-- libfprint/drivers/aes2550.c | 4 ++-- libfprint/drivers/aesx660.c | 6 +++--- libfprint/drivers/elan.c | 8 ++++---- libfprint/drivers/etes603.c | 14 +++++++------- libfprint/drivers/upeksonly.c | 24 ++++++++++++------------ libfprint/drivers/upektc.c | 4 ++-- libfprint/drivers/upektc_img.c | 6 +++--- libfprint/drivers/uru4000.c | 8 ++++---- libfprint/drivers/vcom5s.c | 2 +- libfprint/drivers/vfs0050.c | 8 ++++---- libfprint/drivers/vfs101.c | 8 ++++---- libfprint/drivers/vfs301.c | 4 ++-- libfprint/drivers/vfs5011.c | 10 +++++----- libfprint/drivers_api.h | 1 - libfprint/img.c | 6 ------ 17 files changed, 57 insertions(+), 64 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index d3303288..5b6db2f3 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -715,7 +715,7 @@ static void start_capture(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); G_DEBUG_HERE(); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); @@ -767,7 +767,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); aesdev->read_regs_retry_count = 0; diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index 3fea5111..95a9ccb5 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -599,7 +599,7 @@ static void start_capture(struct fp_img_dev *dev) aesdev->no_finger_cnt = 0; /* Reset gain */ strip_scan_reqs[4].value = AES2501_ADREFHI_MAX_VALUE; - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); G_DEBUG_HERE(); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); @@ -805,7 +805,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); aesdev->read_regs_retry_count = 0; diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 8862f6f8..227a3ba5 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -412,7 +412,7 @@ static void start_capture(struct fp_img_dev *dev) } aesdev->heartbeat_cnt = 0; - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); G_DEBUG_HERE(); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); @@ -581,7 +581,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_sm_complete); diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index af6498c7..b36a3b05 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -247,7 +247,7 @@ static void start_finger_detection(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), finger_det_run_state, FINGER_DET_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), finger_det_run_state, FINGER_DET_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, finger_det_sm_complete); } @@ -427,7 +427,7 @@ static void start_capture(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); G_DEBUG_HERE(); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); @@ -594,7 +594,7 @@ static void activate_sm_complete(fpi_ssm *ssm) int aesX660_dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_sm_complete); diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 8f8203b2..5ea64248 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -486,7 +486,7 @@ static void elan_stop_capture(struct fp_img_dev *dev) elan_dev_reset(elandev); fpi_ssm *ssm = - fpi_ssm_new(fpi_imgdev_get_dev(dev), stop_capture_run_state, + fpi_ssm_new(FP_DEV(dev), stop_capture_run_state, STOP_CAPTURE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, stop_capture_complete); @@ -579,7 +579,7 @@ static void elan_capture(struct fp_img_dev *dev) elan_dev_reset(elandev); fpi_ssm *ssm = - fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); + fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_complete); } @@ -711,7 +711,7 @@ static void elan_calibrate(struct fp_img_dev *dev) elan_dev_reset(elandev); elandev->calib_atts_left = ELAN_CALIBRATION_ATTEMPTS; - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), calibrate_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), calibrate_run_state, CALIBRATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, calibrate_complete); @@ -791,7 +791,7 @@ static void elan_activate(struct fp_img_dev *dev) elan_dev_reset(elandev); fpi_ssm *ssm = - fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, ACTIVATE_NUM_STATES); + fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_complete); } diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index 741daeb3..c958ef1d 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -742,7 +742,7 @@ static void m_exit_complete(fpi_ssm *ssm) static void m_exit_start(struct fp_img_dev *idev) { - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_exit_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), m_exit_state, EXIT_NUM_STATES); fp_dbg("Switching device to idle mode"); fpi_ssm_set_user_data(ssm, idev); @@ -955,7 +955,7 @@ static void m_finger_complete(fpi_ssm *ssm) if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_cap; - ssm_cap = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_capture_state, + ssm_cap = fpi_ssm_new(FP_DEV(idev), m_capture_state, CAP_NUM_STATES); fpi_ssm_set_user_data(ssm_cap, idev); fpi_ssm_start(ssm_cap, m_capture_complete); @@ -974,7 +974,7 @@ static void m_finger_complete(fpi_ssm *ssm) static void m_start_fingerdetect(struct fp_img_dev *idev) { fpi_ssm *ssmf; - ssmf = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_finger_state, FGR_NUM_STATES); + ssmf = fpi_ssm_new(FP_DEV(idev), m_finger_state, FGR_NUM_STATES); fpi_ssm_set_user_data(ssmf, idev); fpi_ssm_start(ssmf, m_finger_complete); } @@ -1264,7 +1264,7 @@ static void m_tunedc_complete(fpi_ssm *ssm) struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_tune; - ssm_tune = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_tunevrb_state, + ssm_tune = fpi_ssm_new(FP_DEV(idev), m_tunevrb_state, TUNEVRB_NUM_STATES); fpi_ssm_set_user_data(ssm_tune, idev); fpi_ssm_start(ssm_tune, m_tunevrb_complete); @@ -1384,7 +1384,7 @@ static void m_init_complete(fpi_ssm *ssm) struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_tune; - ssm_tune = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_tunedc_state, + ssm_tune = fpi_ssm_new(FP_DEV(idev), m_tunedc_state, TUNEDC_NUM_STATES); fpi_ssm_set_user_data(ssm_tune, idev); fpi_ssm_start(ssm_tune, m_tunedc_complete); @@ -1416,7 +1416,7 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) if (dev->dcoffset == 0) { fp_dbg("Tuning device..."); - ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_init_state, INIT_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(idev), m_init_state, INIT_NUM_STATES); fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, m_init_complete); } else { @@ -1424,7 +1424,7 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) "VRB=0x%02X,GAIN=0x%02X).", dev->dcoffset, dev->vrt, dev->vrb, dev->gain); fpi_imgdev_activate_complete(idev, 0); - ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), m_finger_state, FGR_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(idev), m_finger_state, FGR_NUM_STATES); fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, m_finger_complete); } diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 69aaa0a8..ad69b72e 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -1142,11 +1142,11 @@ static void loopsm_run_state(fpi_ssm *ssm) fpi_ssm *awfsm = NULL; switch (sdev->dev_model) { case UPEKSONLY_2016: - awfsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), awfsm_2016_run_state, + awfsm = fpi_ssm_new(FP_DEV(dev), awfsm_2016_run_state, AWFSM_2016_NUM_STATES); break; case UPEKSONLY_1000: - awfsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), awfsm_1000_run_state, + awfsm = fpi_ssm_new(FP_DEV(dev), awfsm_1000_run_state, AWFSM_1000_NUM_STATES); break; } @@ -1170,15 +1170,15 @@ static void loopsm_run_state(fpi_ssm *ssm) fpi_ssm *capsm = NULL; switch (sdev->dev_model) { case UPEKSONLY_2016: - capsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capsm_2016_run_state, + capsm = fpi_ssm_new(FP_DEV(dev), capsm_2016_run_state, CAPSM_2016_NUM_STATES); break; case UPEKSONLY_1000: - capsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capsm_1000_run_state, + capsm = fpi_ssm_new(FP_DEV(dev), capsm_1000_run_state, CAPSM_1000_NUM_STATES); break; case UPEKSONLY_1001: - capsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capsm_1001_run_state, + capsm = fpi_ssm_new(FP_DEV(dev), capsm_1001_run_state, CAPSM_1001_NUM_STATES); break; } @@ -1191,15 +1191,15 @@ static void loopsm_run_state(fpi_ssm *ssm) fpi_ssm *deinitsm = NULL; switch (sdev->dev_model) { case UPEKSONLY_2016: - deinitsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), deinitsm_2016_run_state, + deinitsm = fpi_ssm_new(FP_DEV(dev), deinitsm_2016_run_state, DEINITSM_2016_NUM_STATES); break; case UPEKSONLY_1000: - deinitsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), deinitsm_1000_run_state, + deinitsm = fpi_ssm_new(FP_DEV(dev), deinitsm_1000_run_state, DEINITSM_1000_NUM_STATES); break; case UPEKSONLY_1001: - deinitsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), deinitsm_1001_run_state, + deinitsm = fpi_ssm_new(FP_DEV(dev), deinitsm_1001_run_state, DEINITSM_1001_NUM_STATES); break; } @@ -1278,7 +1278,7 @@ static void initsm_complete(fpi_ssm *ssm) if (r != 0) return; - sdev->loopsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), loopsm_run_state, LOOPSM_NUM_STATES); + sdev->loopsm = fpi_ssm_new(FP_DEV(dev), loopsm_run_state, LOOPSM_NUM_STATES); fpi_ssm_set_user_data(sdev->loopsm, dev); fpi_ssm_start(sdev->loopsm, loopsm_complete); } @@ -1314,13 +1314,13 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) switch (sdev->dev_model) { case UPEKSONLY_2016: - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), initsm_2016_run_state, INITSM_2016_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), initsm_2016_run_state, INITSM_2016_NUM_STATES); break; case UPEKSONLY_1000: - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), initsm_1000_run_state, INITSM_1000_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), initsm_1000_run_state, INITSM_1000_NUM_STATES); break; case UPEKSONLY_1001: - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), initsm_1001_run_state, INITSM_1001_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), initsm_1001_run_state, INITSM_1001_NUM_STATES); break; } fpi_ssm_set_user_data(ssm, dev); diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index 4fd7901a..ff669fff 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -395,7 +395,7 @@ static void start_capture(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); G_DEBUG_HERE(); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); @@ -404,7 +404,7 @@ static void start_capture(struct fp_img_dev *dev) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); upekdev->init_idx = 0; diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 5296c468..4f143449 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -365,7 +365,7 @@ static void start_capture(struct fp_img_dev *dev) upekdev->image_size = 0; - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); } @@ -444,7 +444,7 @@ static void start_deactivation(struct fp_img_dev *dev) upekdev->image_size = 0; - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), deactivate_run_state, DEACTIVATE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), deactivate_run_state, DEACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, deactivate_sm_complete); } @@ -580,7 +580,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); upekdev->seq = 0; diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index dae2685e..fc2218d4 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -1075,7 +1075,7 @@ static void init_run_state(fpi_ssm *ssm) fpi_ssm_jump_to_state(ssm, INIT_CHECK_HWSTAT_POWERDOWN); break; case INIT_REBOOT_POWER: ; - fpi_ssm *rebootsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), rebootpwr_run_state, + fpi_ssm *rebootsm = fpi_ssm_new(FP_DEV(dev), rebootpwr_run_state, REBOOTPWR_NUM_STATES); fpi_ssm_set_user_data(rebootsm, dev); fpi_ssm_start_subsm(ssm, rebootsm); @@ -1094,7 +1094,7 @@ static void init_run_state(fpi_ssm *ssm) urudev->irq_cb_data = ssm; urudev->irq_cb = init_scanpwr_irq_cb; - fpi_ssm *powerupsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), powerup_run_state, + fpi_ssm *powerupsm = fpi_ssm_new(FP_DEV(dev), powerup_run_state, POWERUP_NUM_STATES); fpi_ssm_set_user_data(powerupsm, dev); fpi_ssm_start_subsm(ssm, powerupsm); @@ -1169,7 +1169,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) urudev->scanpwr_irq_timeouts = 0; urudev->activate_state = state; - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), init_run_state, INIT_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), init_run_state, INIT_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, activate_initsm_complete); return 0; @@ -1223,7 +1223,7 @@ static int execute_state_change(struct fp_img_dev *dev) urudev->img_data = g_malloc(sizeof(struct uru4k_image)); urudev->img_enc_seed = rand(); - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), imaging_run_state, IMAGING_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), imaging_run_state, IMAGING_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, imaging_complete); diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index 8a0f157d..2176d7a6 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -314,7 +314,7 @@ static void loopsm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), loop_run_state, + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), loop_run_state, LOOP_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); vdev->deactivating = FALSE; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 2cf46600..0dbc09e1 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -312,7 +312,7 @@ static void clear_ep2(fpi_ssm *ssm) struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); fpi_ssm *subsm = - fpi_ssm_new(fpi_imgdev_get_dev(idev), clear_ep2_ssm, SUBSM1_STATES); + fpi_ssm_new(FP_DEV(idev), clear_ep2_ssm, SUBSM1_STATES); fpi_ssm_set_user_data(subsm, idev); fpi_ssm_start_subsm(ssm, subsm); } @@ -390,7 +390,7 @@ static void send_control_packet(fpi_ssm *ssm) struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); fpi_ssm *subsm = - fpi_ssm_new(fpi_imgdev_get_dev(idev), send_control_packet_ssm, SUBSM2_STATES); + fpi_ssm_new(FP_DEV(idev), send_control_packet_ssm, SUBSM2_STATES); fpi_ssm_set_user_data(subsm, idev); fpi_ssm_start_subsm(ssm, subsm); } @@ -691,7 +691,7 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) vdev->need_report = 1; vdev->ssm_active = 1; - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), activate_ssm, SSM_STATES); + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), activate_ssm, SSM_STATES); fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, dev_activate_callback); return 0; @@ -738,7 +738,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) fp_dev_set_instance_data(FP_DEV(idev), vdev); /* Clearing previous device state */ - fpi_ssm *ssm = fpi_ssm_new(fpi_imgdev_get_dev(idev), activate_ssm, SSM_STATES); + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), activate_ssm, SSM_STATES); fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, dev_open_callback); return 0; diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 0d4d2922..90dd0fcf 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -536,7 +536,7 @@ static void m_swap(fpi_ssm *ssm, unsigned char *data, size_t length) vdev->length = length; /* Start swap ssm */ - subsm = fpi_ssm_new(fpi_imgdev_get_dev(dev), m_swap_state, M_SWAP_NUM_STATES); + subsm = fpi_ssm_new(FP_DEV(dev), m_swap_state, M_SWAP_NUM_STATES); fpi_ssm_set_user_data(subsm, dev); fpi_ssm_start_subsm(ssm, subsm); } @@ -647,7 +647,7 @@ static int action_completed(struct fp_img_dev *dev) struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); if ((fpi_imgdev_get_action(dev) == IMG_ACTION_ENROLL) && - (vdev->enroll_stage < fpi_dev_get_nr_enroll_stages(fpi_imgdev_get_dev(dev)))) + (vdev->enroll_stage < fpi_dev_get_nr_enroll_stages(FP_DEV(dev)))) /* Enroll not completed, return false */ return FALSE; @@ -1429,7 +1429,7 @@ static void m_init_complete(fpi_ssm *ssm) fpi_imgdev_activate_complete(dev, 0); /* Start loop ssm */ - ssm_loop = fpi_ssm_new(fpi_imgdev_get_dev(dev), m_loop_state, M_LOOP_NUM_STATES); + ssm_loop = fpi_ssm_new(FP_DEV(dev), m_loop_state, M_LOOP_NUM_STATES); fpi_ssm_set_user_data(ssm_loop, dev); fpi_ssm_start(ssm_loop, m_loop_complete); } @@ -1464,7 +1464,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) vdev->enroll_stage = 0; /* Start init ssm */ - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), m_init_state, M_INIT_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), m_init_state, M_INIT_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, m_init_complete); diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 177075bf..4ebaa5c6 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -191,7 +191,7 @@ static void m_init_complete(fpi_ssm *ssm) fpi_imgdev_activate_complete(dev, 0); /* Start loop ssm */ - ssm_loop = fpi_ssm_new(fpi_imgdev_get_dev(dev), m_loop_state, M_LOOP_NUM_STATES); + ssm_loop = fpi_ssm_new(FP_DEV(dev), m_loop_state, M_LOOP_NUM_STATES); fpi_ssm_set_user_data(ssm_loop, dev); fpi_ssm_start(ssm_loop, m_loop_complete); } @@ -206,7 +206,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) fpi_ssm *ssm; /* Start init ssm */ - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), m_init_state, 1); + ssm = fpi_ssm_new(FP_DEV(dev), m_init_state, 1); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, m_init_complete); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index df0552ec..f8dd36f2 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -236,9 +236,9 @@ static void usbexchange_loop(fpi_ssm *ssm) static void usb_exchange_async(fpi_ssm *ssm, struct usbexchange_data *data) { - fpi_ssm *subsm = fpi_ssm_new(fpi_imgdev_get_dev(data->device), - usbexchange_loop, - data->stepcount); + fpi_ssm *subsm = fpi_ssm_new(FP_DEV(data->device), + usbexchange_loop, + data->stepcount); fpi_ssm_set_user_data(subsm, data); fpi_ssm_start_subsm(ssm, subsm); } @@ -830,7 +830,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) } fpi_ssm *ssm; - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), open_loop, DEV_OPEN_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), open_loop, DEV_OPEN_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, open_loop_complete); @@ -858,7 +858,7 @@ static void start_scan(struct fp_img_dev *dev) data = FP_INSTANCE_DATA(FP_DEV(dev)); data->loop_running = TRUE; fp_dbg("creating ssm"); - ssm = fpi_ssm_new(fpi_imgdev_get_dev(dev), activate_loop, DEV_ACTIVATE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), activate_loop, DEV_ACTIVATE_NUM_STATES); fpi_ssm_set_user_data(ssm, dev); fp_dbg("starting ssm"); fpi_ssm_start(ssm, activate_loop_complete); diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index a7994b8c..8fe73697 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -68,7 +68,6 @@ enum fp_imgdev_enroll_state { }; libusb_device_handle *fpi_imgdev_get_usb_dev(struct fp_img_dev *dev); -struct fp_dev *fpi_imgdev_get_dev(struct fp_img_dev *imgdev); enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev); enum fp_imgdev_action fpi_imgdev_get_action(struct fp_img_dev *imgdev); int fpi_imgdev_get_action_result(struct fp_img_dev *imgdev); diff --git a/libfprint/img.c b/libfprint/img.c index ff46f01b..22e289be 100644 --- a/libfprint/img.c +++ b/libfprint/img.c @@ -539,12 +539,6 @@ fpi_imgdev_get_usb_dev(struct fp_img_dev *dev) return FP_DEV(dev)->udev; } -struct fp_dev * -fpi_imgdev_get_dev(struct fp_img_dev *imgdev) -{ - return FP_DEV(imgdev); -} - enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev) { From 3f64b2ea5a7c1cdac17591e250e11fd207cbd712 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Sep 2018 00:53:25 +0200 Subject: [PATCH 059/225] lib: Remove fpi_imgdev_get_usb_dev() We now use fpi_get_usb_dev(FP_DEV()) instead. --- libfprint/drivers/aes1610.c | 8 ++++---- libfprint/drivers/aes1660.c | 4 ++-- libfprint/drivers/aes2501.c | 10 +++++----- libfprint/drivers/aes2550.c | 22 +++++++++++----------- libfprint/drivers/aes2660.c | 4 ++-- libfprint/drivers/aes3500.c | 4 ++-- libfprint/drivers/aes3k.c | 2 +- libfprint/drivers/aes4000.c | 4 ++-- libfprint/drivers/aesx660.c | 4 ++-- libfprint/drivers/elan.c | 8 ++++---- libfprint/drivers/etes603.c | 6 +++--- libfprint/drivers/fdu2000.c | 28 ++++++++++++++-------------- libfprint/drivers/upeksonly.c | 14 +++++++------- libfprint/drivers/upektc.c | 16 ++++++++-------- libfprint/drivers/upektc_img.c | 8 ++++---- libfprint/drivers/uru4000.c | 14 +++++++------- libfprint/drivers/vcom5s.c | 10 +++++----- libfprint/drivers/vfs0050.c | 12 ++++++------ libfprint/drivers/vfs101.c | 10 +++++----- libfprint/drivers/vfs301.c | 16 ++++++++-------- libfprint/drivers/vfs5011.c | 12 ++++++------ libfprint/drivers_api.h | 1 - libfprint/img.c | 6 ------ 23 files changed, 108 insertions(+), 115 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index 5b6db2f3..cc62dbf5 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -233,7 +233,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, void *user_da } data = g_malloc(19); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, 19, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 19, finger_det_data_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -677,7 +677,7 @@ static void capture_run_state(fpi_ssm *ssm) } data = g_malloc(665); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, 665, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 665, capture_read_strip_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -805,7 +805,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct aes1610_dev *aesdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -822,7 +822,7 @@ static void dev_deinit(struct fp_img_dev *dev) struct aes1610_dev *aesdev; aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/aes1660.c b/libfprint/drivers/aes1660.c index c502a015..f27b9bf9 100644 --- a/libfprint/drivers/aes1660.c +++ b/libfprint/drivers/aes1660.c @@ -40,7 +40,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct aesX660_dev *aesdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -67,7 +67,7 @@ static void dev_deinit(struct fp_img_dev *dev) struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev->buffer); g_free(aesdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index 95a9ccb5..feea5d48 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -122,7 +122,7 @@ static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data) } data = g_malloc(126); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, 126, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 126, read_regs_data_cb, rdata, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -333,7 +333,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, } data = g_malloc(20); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, 20, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 20, finger_det_data_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -558,7 +558,7 @@ static void capture_run_state(fpi_ssm *ssm) } data = g_malloc(1705); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, 1705, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 1705, capture_read_strip_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -842,7 +842,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct aes2501_dev *aesdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -858,7 +858,7 @@ static void dev_deinit(struct fp_img_dev *dev) { struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 227a3ba5..1ce5c802 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -133,7 +133,7 @@ static void finger_det_reqs_cb(struct libusb_transfer *t) /* 2 bytes of result */ data = g_malloc(AES2550_EP_IN_BUF_SIZE); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, AES2550_EP_IN_BUF_SIZE, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, finger_det_data_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -163,7 +163,7 @@ static void start_finger_detection(struct fp_img_dev *dev) fpi_imgdev_session_error(dev, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, finger_det_reqs, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, finger_det_reqs, sizeof(finger_det_reqs), finger_det_reqs_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { @@ -336,7 +336,7 @@ static void capture_run_state(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, capture_reqs, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, capture_reqs, sizeof(capture_reqs), capture_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { @@ -356,7 +356,7 @@ static void capture_run_state(fpi_ssm *ssm) } data = g_malloc(AES2550_EP_IN_BUF_SIZE); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, AES2550_EP_IN_BUF_SIZE, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, capture_read_data_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -374,7 +374,7 @@ static void capture_run_state(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, capture_set_idle_reqs, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, capture_set_idle_reqs, sizeof(capture_set_idle_reqs), capture_set_idle_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { @@ -496,7 +496,7 @@ static void activate_run_state(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, init_reqs, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, init_reqs, sizeof(init_reqs), init_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { @@ -516,7 +516,7 @@ static void activate_run_state(fpi_ssm *ssm) } data = g_malloc(AES2550_EP_IN_BUF_SIZE); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, AES2550_EP_IN_BUF_SIZE, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, init_read_data_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -534,7 +534,7 @@ static void activate_run_state(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, calibrate_reqs, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, calibrate_reqs, sizeof(calibrate_reqs), init_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { @@ -554,7 +554,7 @@ static void activate_run_state(fpi_ssm *ssm) } data = g_malloc(AES2550_EP_IN_BUF_SIZE); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, data, AES2550_EP_IN_BUF_SIZE, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, calibrate_read_data_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -613,7 +613,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct aes2550_dev *aes2550_dev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -630,7 +630,7 @@ static void dev_deinit(struct fp_img_dev *dev) struct aes2550_dev *aesdev; aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/aes2660.c b/libfprint/drivers/aes2660.c index 67844419..de380e7a 100644 --- a/libfprint/drivers/aes2660.c +++ b/libfprint/drivers/aes2660.c @@ -40,7 +40,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct aesX660_dev *aesdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -69,7 +69,7 @@ static void dev_deinit(struct fp_img_dev *dev) aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev->buffer); g_free(aesdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/aes3500.c b/libfprint/drivers/aes3500.c index 43d14867..c083c4ed 100644 --- a/libfprint/drivers/aes3500.c +++ b/libfprint/drivers/aes3500.c @@ -122,7 +122,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct aes3k_dev *aesdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -150,7 +150,7 @@ static void dev_deinit(struct fp_img_dev *dev) { struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/aes3k.c b/libfprint/drivers/aes3k.c index e05fc8fe..6149e3ab 100644 --- a/libfprint/drivers/aes3k.c +++ b/libfprint/drivers/aes3k.c @@ -123,7 +123,7 @@ static void do_capture(struct fp_img_dev *dev) } data = g_malloc(aesdev->data_buflen); - libusb_fill_bulk_transfer(aesdev->img_trf, fpi_imgdev_get_usb_dev(dev), EP_IN, data, + libusb_fill_bulk_transfer(aesdev->img_trf, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, aesdev->data_buflen, img_cb, dev, 0); r = libusb_submit_transfer(aesdev->img_trf); diff --git a/libfprint/drivers/aes4000.c b/libfprint/drivers/aes4000.c index 419d791f..6ea79d15 100644 --- a/libfprint/drivers/aes4000.c +++ b/libfprint/drivers/aes4000.c @@ -119,7 +119,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct aes3k_dev *aesdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -147,7 +147,7 @@ static void dev_deinit(struct fp_img_dev *dev) { struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(aesdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index b36a3b05..cd7b62e7 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -49,7 +49,7 @@ static void aesX660_send_cmd_timeout(fpi_ssm *ssm, const unsigned char *cmd, return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, (unsigned char *)cmd, cmd_len, callback, ssm, timeout); r = libusb_submit_transfer(transfer); @@ -80,7 +80,7 @@ static void aesX660_read_response(fpi_ssm *ssm, size_t buf_len, } data = g_malloc(buf_len); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, buf_len, callback, ssm, BULK_TIMEOUT); diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 5ea64248..42471ebf 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -391,7 +391,7 @@ static void elan_cmd_read(fpi_ssm *ssm) g_free(elandev->last_read); elandev->last_read = g_malloc(response_len); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), elandev->cmd->response_in, elandev->last_read, response_len, elan_cmd_cb, ssm, elandev->cmd_timeout); @@ -426,7 +426,7 @@ static void elan_run_cmd(fpi_ssm *ssm, const struct elan_cmd *cmd, } elandev->cur_transfer = transfer; - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), ELAN_EP_CMD_OUT, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), ELAN_EP_CMD_OUT, (char *) cmd->cmd, ELAN_CMD_LEN, elan_cmd_cb, ssm, elandev->cmd_timeout); transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; @@ -803,7 +803,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) G_DEBUG_HERE(); - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -843,7 +843,7 @@ static void dev_deinit(struct fp_img_dev *dev) elan_dev_reset(elandev); g_free(elandev->background); g_free(elandev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index c958ef1d..b4d50de1 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -656,7 +656,7 @@ static int async_tx(struct fp_img_dev *idev, unsigned int ep, void *cb, } else { return -EIO; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(idev), ep, buffer, length, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(idev)), ep, buffer, length, cb, cb_arg, BULK_TIMEOUT); if (libusb_submit_transfer(transfer)) { @@ -1456,7 +1456,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) dev->ans = g_malloc(FE_SIZE); dev->fp = g_malloc(FE_SIZE * 4); - ret = libusb_claim_interface(fpi_imgdev_get_usb_dev(idev), 0); + ret = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(idev)), 0); if (ret != LIBUSB_SUCCESS) { fp_err("libusb_claim_interface failed on interface 0: %s", libusb_error_name(ret)); return ret; @@ -1475,7 +1475,7 @@ static void dev_close(struct fp_img_dev *idev) g_free(dev->fp); g_free(dev); - libusb_release_interface(fpi_imgdev_get_usb_dev(idev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(idev)), 0); fpi_imgdev_close_complete(idev); } diff --git a/libfprint/drivers/fdu2000.c b/libfprint/drivers/fdu2000.c index 87d78549..44b993dc 100644 --- a/libfprint/drivers/fdu2000.c +++ b/libfprint/drivers/fdu2000.c @@ -169,25 +169,25 @@ capture(struct fp_img_dev *dev, gboolean unconditional, image = g_malloc0(RAW_IMAGE_SIZE); - if ((r = bulk_write_safe(fpi_imgdev_get_usb_dev(dev), LED_ON))) { + if ((r = bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), LED_ON))) { fp_err("Command: LED_ON"); goto out; } - if ((r = bulk_write_safe(fpi_imgdev_get_usb_dev(dev), CAPTURE_READY))) { + if ((r = bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), CAPTURE_READY))) { fp_err("Command: CAPTURE_READY"); goto out; } read: - if ((r = bulk_write_safe(fpi_imgdev_get_usb_dev(dev), CAPTURE_READ))) { + if ((r = bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), CAPTURE_READ))) { fp_err("Command: CAPTURE_READ"); goto out; } /* Now we are ready to read from dev */ - r = libusb_bulk_transfer(fpi_imgdev_get_usb_dev(dev), &msg, &bytes, BULK_TIMEOUT * 10); + r = libusb_bulk_transfer(fpi_dev_get_usb_dev(FP_DEV(dev)), &msg, &bytes, BULK_TIMEOUT * 10); if (r < 0 || bytes < 1) goto read; @@ -228,12 +228,12 @@ read: } } - if ((r = bulk_write_safe(fpi_imgdev_get_usb_dev(dev), CAPTURE_END))) { + if ((r = bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), CAPTURE_END))) { fp_err("Command: CAPTURE_END"); goto out; } - if ((r = bulk_write_safe(fpi_imgdev_get_usb_dev(dev), LED_OFF))) { + if ((r = bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), LED_OFF))) { fp_err("Command: LED_OFF"); goto out; } @@ -254,27 +254,27 @@ static gint dev_init(struct fp_img_dev *dev, unsigned long driver_data) { gint r; - //if ( (r = usb_set_configuration(fpi_imgdev_get_usb_dev(dev), 1)) < 0 ) + //if ( (r = usb_set_configuration(fpi_dev_get_usb_dev(FP_DEV(dev)), 1)) < 0 ) // goto out; - if ( (r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0)) < 0 ) { + if ( (r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0)) < 0 ) { fp_err("could not claim interface 0: %s", libusb_error_name(r)); return r; } - //if ( (r = usb_set_altinterface(fpi_imgdev_get_usb_dev(dev), 1)) < 0 ) + //if ( (r = usb_set_altinterface(fpi_dev_get_usb_dev(FP_DEV(dev)), 1)) < 0 ) // goto out; - //if ( (r = usb_clear_halt(fpi_imgdev_get_usb_dev(dev), EP_CMD)) < 0 ) + //if ( (r = usb_clear_halt(fpi_dev_get_usb_dev(FP_DEV(dev)), EP_CMD)) < 0 ) // goto out; /* Make sure sensor mode is not capture_{ready|read} */ - if ((r = bulk_write_safe(fpi_imgdev_get_usb_dev(dev), CAPTURE_END))) { + if ((r = bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), CAPTURE_END))) { fp_err("Command: CAPTURE_END"); goto out; } - if ((r = bulk_write_safe(fpi_imgdev_get_usb_dev(dev), LED_OFF))) { + if ((r = bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), LED_OFF))) { fp_err("Command: LED_OFF"); goto out; } @@ -289,10 +289,10 @@ out: static void dev_exit(struct fp_img_dev *dev) { - if (bulk_write_safe(fpi_imgdev_get_usb_dev(dev), CAPTURE_END)) + if (bulk_write_safe(fpi_dev_get_usb_dev(FP_DEV(dev)), CAPTURE_END)) fp_err("Command: CAPTURE_END"); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); } static const struct usb_id id_table[] = { diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index ad69b72e..3f294fd0 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -629,7 +629,7 @@ static void sm_write_reg(fpi_ssm *ssm, uint8_t reg, uint8_t value) fp_dbg("set %02x=%02x", reg, value); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); libusb_fill_control_setup(data, 0x40, 0x0c, 0, reg, 1); - libusb_fill_control_transfer(transfer, fpi_imgdev_get_usb_dev(dev), + libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), data, sm_write_reg_cb, ssm, CTRL_TIMEOUT); @@ -677,7 +677,7 @@ static void sm_read_reg(fpi_ssm *ssm, uint8_t reg) fp_dbg("read reg %02x", reg); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 8); libusb_fill_control_setup(data, 0xc0, 0x0c, 0, reg, 8); - libusb_fill_control_transfer(transfer, fpi_imgdev_get_usb_dev(dev), + libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), data, sm_read_reg_cb, ssm, CTRL_TIMEOUT); transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK | @@ -727,7 +727,7 @@ static void sm_await_intr(fpi_ssm *ssm) G_DEBUG_HERE(); data = g_malloc(4); - libusb_fill_interrupt_transfer(transfer, fpi_imgdev_get_usb_dev(dev), + libusb_fill_interrupt_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), 0x83, data, 4, sm_await_intr_cb, ssm, 0); transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK | @@ -1307,7 +1307,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) sdev->img_transfer_data[i].idx = i; sdev->img_transfer_data[i].dev = dev; data = g_malloc(4096); - libusb_fill_bulk_transfer(sdev->img_transfer[i], fpi_imgdev_get_usb_dev(dev), + libusb_fill_bulk_transfer(sdev->img_transfer[i], fpi_dev_get_usb_dev(FP_DEV(dev)), 0x81, data, 4096, img_data_cb, &sdev->img_transfer_data[i], 0); } @@ -1335,7 +1335,7 @@ static void dev_deinit(struct fp_img_dev *dev) void *user_data; user_data = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(user_data); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } @@ -1387,13 +1387,13 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct sonly_dev *sdev; - r = libusb_set_configuration(fpi_imgdev_get_usb_dev(dev), 1); + r = libusb_set_configuration(fpi_dev_get_usb_dev(FP_DEV(dev)), 1); if (r < 0) { fp_err("could not set configuration 1"); return r; } - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index ff669fff..383df419 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -112,7 +112,7 @@ static void activate_run_state(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_out, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out, (unsigned char*)upekdev->setup_commands[upekdev->init_idx].cmd, UPEKTC_CMD_LEN, write_init_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -133,7 +133,7 @@ static void activate_run_state(fpi_ssm *ssm) } data = g_malloc(upekdev->setup_commands[upekdev->init_idx].response_len); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_in, data, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, upekdev->setup_commands[upekdev->init_idx].response_len, read_init_data_cb, ssm, BULK_TIMEOUT); @@ -233,7 +233,7 @@ static void finger_det_cmd_cb(struct libusb_transfer *t) } data = g_malloc(IMAGE_SIZE); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_in, data, IMAGE_SIZE, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, IMAGE_SIZE, finger_det_data_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -263,7 +263,7 @@ static void start_finger_detection(struct fp_img_dev *dev) fpi_imgdev_session_error(dev, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_out, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out, (unsigned char *)scan_cmd, UPEKTC_CMD_LEN, finger_det_cmd_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -335,7 +335,7 @@ static void capture_run_state(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_out, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out, (unsigned char *)scan_cmd, UPEKTC_CMD_LEN, capture_cmd_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -356,7 +356,7 @@ static void capture_run_state(fpi_ssm *ssm) } data = g_malloc(IMAGE_SIZE); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), upekdev->ep_in, data, IMAGE_SIZE, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, IMAGE_SIZE, capture_read_data_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -434,7 +434,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct upektc_dev *upekdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -473,7 +473,7 @@ static void dev_deinit(struct fp_img_dev *dev) void *user_data; user_data = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(user_data); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 4f143449..24ddb43e 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -93,7 +93,7 @@ static void upektc_img_submit_req(fpi_ssm *ssm, upektc_img_cmd_fix_seq(upekdev->cmd, seq); upektc_img_cmd_update_crc(upekdev->cmd, buf_size); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT, 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); @@ -119,7 +119,7 @@ static void upektc_img_read_data(fpi_ssm *ssm, size_t buf_size, size_t buf_offse transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, upekdev->response + buf_offset, buf_size, + 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); @@ -601,7 +601,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; struct upektc_img_dev *upekdev; - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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; @@ -617,7 +617,7 @@ static void dev_deinit(struct fp_img_dev *dev) { struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(upekdev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index fc2218d4..2d3b54fd 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -201,7 +201,7 @@ static int write_regs(struct fp_img_dev *dev, uint16_t first_reg, data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + num_regs); memcpy(data + LIBUSB_CONTROL_SETUP_SIZE, values, num_regs); libusb_fill_control_setup(data, CTRL_OUT, USB_RQ, first_reg, 0, num_regs); - libusb_fill_control_transfer(transfer, fpi_imgdev_get_usb_dev(dev), data, write_regs_cb, + libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), data, write_regs_cb, wrdata, CTRL_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -267,7 +267,7 @@ static int read_regs(struct fp_img_dev *dev, uint16_t first_reg, data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + num_regs); libusb_fill_control_setup(data, CTRL_IN, USB_RQ, first_reg, 0, num_regs); - libusb_fill_control_transfer(transfer, fpi_imgdev_get_usb_dev(dev), data, read_regs_cb, + libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), data, read_regs_cb, rrdata, CTRL_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -435,7 +435,7 @@ static int start_irq_handler(struct fp_img_dev *dev) return -ENOMEM; data = g_malloc(IRQ_LENGTH); - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_INTR, data, IRQ_LENGTH, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_INTR, data, IRQ_LENGTH, irq_handler, dev, 0); urudev->irq_transfer = transfer; @@ -702,7 +702,7 @@ static void imaging_run_state(fpi_ssm *ssm) case IMAGING_CAPTURE: urudev->img_lines_done = 0; urudev->img_block = 0; - libusb_fill_bulk_transfer(urudev->img_transfer, fpi_imgdev_get_usb_dev(dev), EP_DATA, + libusb_fill_bulk_transfer(urudev->img_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_DATA, urudev->img_data, sizeof(struct uru4k_image), image_transfer_cb, ssm, 0); r = libusb_submit_transfer(urudev->img_transfer); if (r < 0) @@ -1257,7 +1257,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) int r; /* Find fingerprint interface */ - r = libusb_get_config_descriptor(libusb_get_device(fpi_imgdev_get_usb_dev(dev)), 0, &config); + r = libusb_get_config_descriptor(libusb_get_device(fpi_dev_get_usb_dev(FP_DEV(dev))), 0, &config); if (r < 0) { fp_err("Failed to get config descriptor"); return r; @@ -1311,7 +1311,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) /* Device looks like a supported reader */ - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), iface_desc->bInterfaceNumber); + r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), iface_desc->bInterfaceNumber); if (r < 0) { fp_err("interface claim failed: %s", libusb_error_name(r)); goto out; @@ -1368,7 +1368,7 @@ static void dev_deinit(struct fp_img_dev *dev) SECITEM_FreeItem(urudev->param, PR_TRUE); if (urudev->slot) PK11_FreeSlot(urudev->slot); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), urudev->interface); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), urudev->interface); g_free(urudev); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index 2176d7a6..bb8b59b1 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -101,7 +101,7 @@ static void sm_write_reg(fpi_ssm *ssm, unsigned char reg, fp_dbg("set %02x=%02x", reg, value); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE); libusb_fill_control_setup(data, CTRL_OUT, reg, value, 0, 0); - libusb_fill_control_transfer(transfer, fpi_imgdev_get_usb_dev(dev), data, sm_write_reg_cb, + libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), data, sm_write_reg_cb, ssm, CTRL_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { @@ -140,7 +140,7 @@ static void sm_exec_cmd(fpi_ssm *ssm, unsigned char cmd, fp_dbg("cmd %02x param %02x", cmd, param); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE); libusb_fill_control_setup(data, CTRL_IN, cmd, param, 0, 0); - libusb_fill_control_transfer(transfer, fpi_imgdev_get_usb_dev(dev), data, sm_exec_cmd_cb, + libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), data, sm_exec_cmd_cb, ssm, CTRL_TIMEOUT); r = libusb_submit_transfer(transfer); if (r < 0) { @@ -231,7 +231,7 @@ static void capture_iterate(fpi_ssm *ssm) return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(dev), EP_IN, + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, vdev->capture_img->data + (RQ_SIZE * iteration), RQ_SIZE, capture_cb, ssm, CTRL_TIMEOUT); transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK; @@ -341,7 +341,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) v5s_dev = g_malloc0(sizeof(struct v5s_dev)); fp_dev_set_instance_data(FP_DEV(dev), v5s_dev); - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + 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)); @@ -356,7 +356,7 @@ static void dev_deinit(struct fp_img_dev *dev) struct v5s_dev *v5s_dev; v5s_dev = FP_INSTANCE_DATA(FP_DEV(dev)); g_free(v5s_dev); - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); fpi_imgdev_close_complete(dev); } diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 0dbc09e1..591fc972 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -54,7 +54,7 @@ static void async_write_callback(struct libusb_transfer *transfer) static void async_write(fpi_ssm *ssm, void *data, int len) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); + struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); vdev->transfer = libusb_alloc_transfer(0); @@ -96,7 +96,7 @@ static void async_read_callback(struct libusb_transfer *transfer) static void async_read(fpi_ssm *ssm, int ep, void *data, int len) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); + struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); ep |= LIBUSB_ENDPOINT_IN; @@ -150,7 +150,7 @@ static void async_abort_callback(struct libusb_transfer *transfer) static void async_abort(fpi_ssm *ssm, int ep) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); + struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); int len = VFS_USB_BUFFER_SIZE; @@ -521,7 +521,7 @@ static void scan_completed(void *data) static void activate_ssm(fpi_ssm *ssm) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct libusb_device_handle *usb_dev = fpi_imgdev_get_usb_dev(idev); + struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -726,7 +726,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) struct vfs_dev_t *vdev; /* Claim usb interface */ - int error = libusb_claim_interface(fpi_imgdev_get_usb_dev(idev), 0); + int error = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(idev)), 0); if (error < 0) { /* Interface not claimed, return error */ fp_err("could not claim interface 0"); @@ -754,7 +754,7 @@ static void dev_close(struct fp_img_dev *idev) g_free(vdev); /* Release usb interface */ - libusb_release_interface(fpi_imgdev_get_usb_dev(idev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(idev)), 0); /* Notify close complete */ fpi_imgdev_close_complete(idev); diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 90dd0fcf..d9e981e4 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -265,7 +265,7 @@ static void async_send(fpi_ssm *ssm) vdev->buffer[1] = byte(1, vdev->seqnum); /* Prepare bulk transfer */ - libusb_fill_bulk_transfer(vdev->transfer, fpi_imgdev_get_usb_dev(dev), EP_OUT(1), vdev->buffer, vdev->length, async_send_cb, ssm, BULK_TIMEOUT); + libusb_fill_bulk_transfer(vdev->transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT(1), vdev->buffer, vdev->length, async_send_cb, ssm, BULK_TIMEOUT); /* Submit transfer */ r = libusb_submit_transfer(vdev->transfer); @@ -347,7 +347,7 @@ static void async_recv(fpi_ssm *ssm) } /* Prepare bulk transfer */ - libusb_fill_bulk_transfer(vdev->transfer, fpi_imgdev_get_usb_dev(dev), EP_IN(1), vdev->buffer, 0x0f, async_recv_cb, ssm, BULK_TIMEOUT); + libusb_fill_bulk_transfer(vdev->transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN(1), vdev->buffer, 0x0f, async_recv_cb, ssm, BULK_TIMEOUT); /* Submit transfer */ r = libusb_submit_transfer(vdev->transfer); @@ -452,7 +452,7 @@ static void async_load(fpi_ssm *ssm) buffer = vdev->buffer + vdev->length; /* Prepare bulk transfer */ - libusb_fill_bulk_transfer(vdev->transfer, fpi_imgdev_get_usb_dev(dev), EP_IN(2), buffer, VFS_BLOCK_SIZE, async_load_cb, ssm, BULK_TIMEOUT); + libusb_fill_bulk_transfer(vdev->transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN(2), buffer, VFS_BLOCK_SIZE, async_load_cb, ssm, BULK_TIMEOUT); /* Submit transfer */ r = libusb_submit_transfer(vdev->transfer); @@ -1494,7 +1494,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) int r; /* Claim usb interface */ - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); if (r < 0) { /* Interface not claimed, return error */ @@ -1523,7 +1523,7 @@ static void dev_close(struct fp_img_dev *dev) g_free(vdev); /* Release usb interface */ - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); /* Notify close complete */ fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 4ebaa5c6..01572044 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -110,7 +110,7 @@ static void m_loop_state(fpi_ssm *ssm) switch (fpi_ssm_get_cur_state(ssm)) { case M_REQUEST_PRINT: - vfs301_proto_request_fingerprint(fpi_imgdev_get_usb_dev(dev), vdev); + vfs301_proto_request_fingerprint(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev); fpi_ssm_next_state(ssm); break; @@ -120,7 +120,7 @@ static void m_loop_state(fpi_ssm *ssm) break; case M_CHECK_PRINT: - if (!vfs301_proto_peek_event(fpi_imgdev_get_usb_dev(dev), vdev)) + if (!vfs301_proto_peek_event(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev)) fpi_ssm_jump_to_state(ssm, M_WAIT_PRINT); else fpi_ssm_next_state(ssm); @@ -128,7 +128,7 @@ static void m_loop_state(fpi_ssm *ssm) case M_READ_PRINT_START: fpi_imgdev_report_finger_status(dev, TRUE); - vfs301_proto_process_event_start(fpi_imgdev_get_usb_dev(dev), vdev); + vfs301_proto_process_event_start(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev); fpi_ssm_next_state(ssm); break; @@ -139,7 +139,7 @@ static void m_loop_state(fpi_ssm *ssm) case M_READ_PRINT_POLL: { - int rv = vfs301_proto_process_event_poll(fpi_imgdev_get_usb_dev(dev), vdev); + int rv = vfs301_proto_process_event_poll(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev); g_assert(rv != VFS301_FAILURE); if (rv == VFS301_ONGOING) fpi_ssm_jump_to_state(ssm, M_READ_PRINT_WAIT); @@ -175,7 +175,7 @@ static void m_init_state(fpi_ssm *ssm) g_assert(fpi_ssm_get_cur_state(ssm) == 0); - vfs301_proto_init(fpi_imgdev_get_usb_dev(dev), vdev); + vfs301_proto_init(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev); fpi_ssm_mark_completed(ssm); } @@ -219,7 +219,7 @@ static void dev_deactivate(struct fp_img_dev *dev) vfs301_dev_t *vdev; vdev = FP_INSTANCE_DATA(FP_DEV(dev)); - vfs301_proto_deinit(fpi_imgdev_get_usb_dev(dev), vdev); + vfs301_proto_deinit(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev); fpi_imgdev_deactivate_complete(dev); } @@ -229,7 +229,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) int r; /* Claim usb interface */ - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); if (r < 0) { /* Interface not claimed, return error */ fp_err("could not claim interface 0: %s", libusb_error_name(r)); @@ -259,7 +259,7 @@ static void dev_close(struct fp_img_dev *dev) g_free(vdev); /* Release usb interface */ - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); /* Notify close complete */ fpi_imgdev_close_complete(dev); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index f8dd36f2..e0f21733 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -196,7 +196,7 @@ static void usbexchange_loop(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(data->device), + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)), action->endpoint, action->data, action->size, async_send_cb, ssm, data->timeout); @@ -212,7 +212,7 @@ static void usbexchange_loop(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, -ENOMEM); return; } - libusb_fill_bulk_transfer(transfer, fpi_imgdev_get_usb_dev(data->device), + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)), action->endpoint, data->receive_buf, action->size, async_recv_cb, ssm, data->timeout); @@ -707,7 +707,7 @@ static void activate_loop(fpi_ssm *ssm) break; case DEV_ACTIVATE_READ_DATA: - r = capture_chunk_async(data, fpi_imgdev_get_usb_dev(dev), CAPTURE_LINES, + r = capture_chunk_async(data, fpi_dev_get_usb_dev(FP_DEV(dev)), CAPTURE_LINES, READ_TIMEOUT, ssm); if (r != 0) { fp_err("Failed to capture data"); @@ -817,13 +817,13 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) (unsigned char *)g_malloc0(CAPTURE_LINES * VFS5011_LINE_SIZE); fp_dev_set_instance_data(FP_DEV(dev), data); - r = libusb_reset_device(fpi_imgdev_get_usb_dev(dev)); + r = libusb_reset_device(fpi_dev_get_usb_dev(FP_DEV(dev))); if (r != 0) { fp_err("Failed to reset the device"); return r; } - r = libusb_claim_interface(fpi_imgdev_get_usb_dev(dev), 0); + r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); if (r != 0) { fp_err("Failed to claim interface: %s", libusb_error_name(r)); return r; @@ -839,7 +839,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) static void dev_close(struct fp_img_dev *dev) { - libusb_release_interface(fpi_imgdev_get_usb_dev(dev), 0); + libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); struct vfs5011_data *data; data = FP_INSTANCE_DATA(FP_DEV(dev)); if (data != NULL) { diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 8fe73697..10816b40 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -67,7 +67,6 @@ enum fp_imgdev_enroll_state { IMG_ACQUIRE_STATE_DEACTIVATING, }; -libusb_device_handle *fpi_imgdev_get_usb_dev(struct fp_img_dev *dev); enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev); enum fp_imgdev_action fpi_imgdev_get_action(struct fp_img_dev *imgdev); int fpi_imgdev_get_action_result(struct fp_img_dev *imgdev); diff --git a/libfprint/img.c b/libfprint/img.c index 22e289be..da5b5b83 100644 --- a/libfprint/img.c +++ b/libfprint/img.c @@ -533,12 +533,6 @@ API_EXPORTED struct fp_minutia **fp_img_get_minutiae(struct fp_img *img, return img->minutiae->list; } -libusb_device_handle * -fpi_imgdev_get_usb_dev(struct fp_img_dev *dev) -{ - return FP_DEV(dev)->udev; -} - enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev) { From cb8732b25586a5329d73496329d3c055224e3373 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Sep 2018 01:16:37 +0200 Subject: [PATCH 060/225] lib: Remove priv struct member in fp_driver It's unused. --- libfprint/drivers_api.h | 2 -- libfprint/fp_internal.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 10816b40..bad5f514 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -93,8 +93,6 @@ struct fp_driver { enum fp_driver_type type; enum fp_scan_type scan_type; - void *priv; - /* Device operations */ int (*discover)(struct libusb_device_descriptor *dsc, uint32_t *devtype); int (*open)(struct fp_dev *dev, unsigned long driver_data); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index aac8f60e..e3fcc10f 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -179,8 +179,6 @@ struct fp_driver { enum fp_driver_type type; enum fp_scan_type scan_type; - void *priv; - /* Device operations */ int (*discover)(struct libusb_device_descriptor *dsc, uint32_t *devtype); int (*open)(struct fp_dev *dev, unsigned long driver_data); From 5d01497b8b4cbc609b0c52b8d76471cfc7c4d75c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Sep 2018 01:20:59 +0200 Subject: [PATCH 061/225] lib: Remove dev_to_img_dev() helper We can access the img_dev struct member directly, and we don't have to double check that the img_dev member is actually an img_dev type, as it always is. --- libfprint/core.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/libfprint/core.c b/libfprint/core.c index 373ed3df..327fc2d7 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -605,13 +605,6 @@ API_EXPORTED enum fp_scan_type fp_driver_get_scan_type(struct fp_driver *drv) return drv->scan_type; } -static struct fp_img_dev *dev_to_img_dev(struct fp_dev *dev) -{ - if (dev->drv->type != DRIVER_IMAGING) - return NULL; - return dev->img_dev; -} - /** * fp_dev_supports_imaging: * @dev: the fingerprint device @@ -659,13 +652,12 @@ API_EXPORTED int fp_dev_supports_identification(struct fp_dev *dev) */ API_EXPORTED int fp_dev_get_img_width(struct fp_dev *dev) { - struct fp_img_dev *imgdev = dev_to_img_dev(dev); - if (!imgdev) { + if (!dev->img_dev) { fp_dbg("get image width for non-imaging device"); return -1; } - return fpi_imgdev_get_img_width(imgdev); + return fpi_imgdev_get_img_width(dev->img_dev); } /** @@ -682,13 +674,12 @@ API_EXPORTED int fp_dev_get_img_width(struct fp_dev *dev) */ API_EXPORTED int fp_dev_get_img_height(struct fp_dev *dev) { - struct fp_img_dev *imgdev = dev_to_img_dev(dev); - if (!imgdev) { + if (!dev->img_dev) { fp_dbg("get image height for non-imaging device"); return -1; } - return fpi_imgdev_get_img_height(imgdev); + return fpi_imgdev_get_img_height(dev->img_dev); } /** From 77defa1d8bb37a1799980e717d4f5519658dd655 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 15 Sep 2018 01:23:02 +0200 Subject: [PATCH 062/225] lib: Remove fpi_dev_get_nr_enroll_stages() It's the same as fp_dev_get_nr_enroll_stages() --- libfprint/core.c | 6 ------ libfprint/drivers/vfs101.c | 2 +- libfprint/drivers_api.h | 1 - 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/libfprint/core.c b/libfprint/core.c index 327fc2d7..0a650c33 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -534,12 +534,6 @@ fpi_dev_get_usb_dev(struct fp_dev *dev) return dev->udev; } -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) diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index d9e981e4..7727b641 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -647,7 +647,7 @@ static int action_completed(struct fp_img_dev *dev) struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); if ((fpi_imgdev_get_action(dev) == IMG_ACTION_ENROLL) && - (vdev->enroll_stage < fpi_dev_get_nr_enroll_stages(FP_DEV(dev)))) + (vdev->enroll_stage < fp_dev_get_nr_enroll_stages(FP_DEV(dev)))) /* Enroll not completed, return false */ return FALSE; diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index bad5f514..034c1746 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -38,7 +38,6 @@ #include "drivers/driver_ids.h" libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); -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); struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev); From d34d7c26def86c5209956316e205793eaebf9e69 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 18 Sep 2018 13:40:43 +0200 Subject: [PATCH 063/225] lib: Remove fpi_ssm_set_user_data() And pass the user_data in fpi_ssm_new() instead. --- doc/libfprint-sections.txt | 1 - libfprint/drivers/aes1610.c | 6 ++---- libfprint/drivers/aes2501.c | 6 ++---- libfprint/drivers/aes2550.c | 6 ++---- libfprint/drivers/aesx660.c | 9 +++------ libfprint/drivers/elan.c | 12 ++++-------- libfprint/drivers/etes603.c | 21 +++++++-------------- libfprint/drivers/upeksonly.c | 29 ++++++++++++----------------- libfprint/drivers/upektc.c | 6 ++---- libfprint/drivers/upektc_img.c | 9 +++------ libfprint/drivers/upekts.c | 17 ++++++++--------- libfprint/drivers/uru4000.c | 12 ++++-------- libfprint/drivers/vcom5s.c | 3 +-- libfprint/drivers/vfs0050.c | 12 ++++-------- libfprint/drivers/vfs101.c | 9 +++------ libfprint/drivers/vfs301.c | 6 ++---- libfprint/drivers/vfs5011.c | 10 ++++------ libfprint/fpi-ssm.c | 31 ++++++++++--------------------- libfprint/fpi-ssm.h | 8 ++++---- 19 files changed, 77 insertions(+), 136 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 2b30ffdc..e0d96b22 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -168,7 +168,6 @@ fpi_ssm_next_state fpi_ssm_jump_to_state fpi_ssm_mark_completed fpi_ssm_mark_failed -fpi_ssm_set_user_data fpi_ssm_get_user_data fpi_ssm_get_error fpi_ssm_get_cur_state diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index cc62dbf5..f90f72e3 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -715,9 +715,8 @@ static void start_capture(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); G_DEBUG_HERE(); - fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); } @@ -768,8 +767,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, - ACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ACTIVATE_NUM_STATES, dev); aesdev->read_regs_retry_count = 0; fpi_ssm_start(ssm, activate_sm_complete); return 0; diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index feea5d48..7aa9e20c 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -599,9 +599,8 @@ static void start_capture(struct fp_img_dev *dev) aesdev->no_finger_cnt = 0; /* Reset gain */ strip_scan_reqs[4].value = AES2501_ADREFHI_MAX_VALUE; - ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); G_DEBUG_HERE(); - fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); } @@ -806,8 +805,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, - ACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ACTIVATE_NUM_STATES, dev); aesdev->read_regs_retry_count = 0; fpi_ssm_start(ssm, activate_sm_complete); return 0; diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 1ce5c802..446694ee 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -412,9 +412,8 @@ static void start_capture(struct fp_img_dev *dev) } aesdev->heartbeat_cnt = 0; - ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); G_DEBUG_HERE(); - fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); } @@ -582,8 +581,7 @@ static void activate_sm_complete(fpi_ssm *ssm) static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, - ACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ACTIVATE_NUM_STATES, dev); fpi_ssm_start(ssm, activate_sm_complete); return 0; } diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index cd7b62e7..0c6255d5 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -247,8 +247,7 @@ static void start_finger_detection(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(FP_DEV(dev), finger_det_run_state, FINGER_DET_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), finger_det_run_state, FINGER_DET_NUM_STATES, dev); fpi_ssm_start(ssm, finger_det_sm_complete); } @@ -427,9 +426,8 @@ static void start_capture(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); G_DEBUG_HERE(); - fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); } @@ -595,8 +593,7 @@ static void activate_sm_complete(fpi_ssm *ssm) int aesX660_dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, - ACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ACTIVATE_NUM_STATES, dev); fpi_ssm_start(ssm, activate_sm_complete); return 0; } diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 42471ebf..f7fb4949 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -487,8 +487,7 @@ static void elan_stop_capture(struct fp_img_dev *dev) fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), stop_capture_run_state, - STOP_CAPTURE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + STOP_CAPTURE_NUM_STATES, dev); fpi_ssm_start(ssm, stop_capture_complete); } @@ -579,8 +578,7 @@ static void elan_capture(struct fp_img_dev *dev) elan_dev_reset(elandev); fpi_ssm *ssm = - fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); fpi_ssm_start(ssm, capture_complete); } @@ -712,8 +710,7 @@ static void elan_calibrate(struct fp_img_dev *dev) elandev->calib_atts_left = ELAN_CALIBRATION_ATTEMPTS; fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), calibrate_run_state, - CALIBRATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + CALIBRATE_NUM_STATES, dev); fpi_ssm_start(ssm, calibrate_complete); } @@ -791,8 +788,7 @@ static void elan_activate(struct fp_img_dev *dev) elan_dev_reset(elandev); fpi_ssm *ssm = - fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + fpi_ssm_new(FP_DEV(dev), activate_run_state, ACTIVATE_NUM_STATES, dev); fpi_ssm_start(ssm, activate_complete); } diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index b4d50de1..3691cf39 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -743,9 +743,8 @@ static void m_exit_complete(fpi_ssm *ssm) static void m_exit_start(struct fp_img_dev *idev) { fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), m_exit_state, - EXIT_NUM_STATES); + EXIT_NUM_STATES, idev); fp_dbg("Switching device to idle mode"); - fpi_ssm_set_user_data(ssm, idev); fpi_ssm_start(ssm, m_exit_complete); } @@ -956,8 +955,7 @@ static void m_finger_complete(fpi_ssm *ssm) if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_cap; ssm_cap = fpi_ssm_new(FP_DEV(idev), m_capture_state, - CAP_NUM_STATES); - fpi_ssm_set_user_data(ssm_cap, idev); + CAP_NUM_STATES, idev); fpi_ssm_start(ssm_cap, m_capture_complete); } else { if (fpi_imgdev_get_action_state(idev) != IMG_ACQUIRE_STATE_DEACTIVATING) { @@ -974,8 +972,7 @@ static void m_finger_complete(fpi_ssm *ssm) static void m_start_fingerdetect(struct fp_img_dev *idev) { fpi_ssm *ssmf; - ssmf = fpi_ssm_new(FP_DEV(idev), m_finger_state, FGR_NUM_STATES); - fpi_ssm_set_user_data(ssmf, idev); + ssmf = fpi_ssm_new(FP_DEV(idev), m_finger_state, FGR_NUM_STATES, idev); fpi_ssm_start(ssmf, m_finger_complete); } @@ -1265,8 +1262,7 @@ static void m_tunedc_complete(fpi_ssm *ssm) if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_tune; ssm_tune = fpi_ssm_new(FP_DEV(idev), m_tunevrb_state, - TUNEVRB_NUM_STATES); - fpi_ssm_set_user_data(ssm_tune, idev); + TUNEVRB_NUM_STATES, idev); fpi_ssm_start(ssm_tune, m_tunevrb_complete); } else { struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -1385,8 +1381,7 @@ static void m_init_complete(fpi_ssm *ssm) if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_tune; ssm_tune = fpi_ssm_new(FP_DEV(idev), m_tunedc_state, - TUNEDC_NUM_STATES); - fpi_ssm_set_user_data(ssm_tune, idev); + TUNEDC_NUM_STATES, idev); fpi_ssm_start(ssm_tune, m_tunedc_complete); } else { struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -1416,16 +1411,14 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) if (dev->dcoffset == 0) { fp_dbg("Tuning device..."); - ssm = fpi_ssm_new(FP_DEV(idev), m_init_state, INIT_NUM_STATES); - fpi_ssm_set_user_data(ssm, idev); + ssm = fpi_ssm_new(FP_DEV(idev), m_init_state, INIT_NUM_STATES, idev); fpi_ssm_start(ssm, m_init_complete); } else { fp_dbg("Using previous tuning (DCOFFSET=0x%02X,VRT=0x%02X," "VRB=0x%02X,GAIN=0x%02X).", dev->dcoffset, dev->vrt, dev->vrb, dev->gain); fpi_imgdev_activate_complete(idev, 0); - ssm = fpi_ssm_new(FP_DEV(idev), m_finger_state, FGR_NUM_STATES); - fpi_ssm_set_user_data(ssm, idev); + ssm = fpi_ssm_new(FP_DEV(idev), m_finger_state, FGR_NUM_STATES, idev); fpi_ssm_start(ssm, m_finger_complete); } return 0; diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 3f294fd0..06cbeedf 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -1143,14 +1143,13 @@ static void loopsm_run_state(fpi_ssm *ssm) switch (sdev->dev_model) { case UPEKSONLY_2016: awfsm = fpi_ssm_new(FP_DEV(dev), awfsm_2016_run_state, - AWFSM_2016_NUM_STATES); + AWFSM_2016_NUM_STATES, dev); break; case UPEKSONLY_1000: awfsm = fpi_ssm_new(FP_DEV(dev), awfsm_1000_run_state, - AWFSM_1000_NUM_STATES); + AWFSM_1000_NUM_STATES, dev); break; } - fpi_ssm_set_user_data(awfsm, dev); fpi_ssm_start_subsm(ssm, awfsm); } break; @@ -1171,18 +1170,17 @@ static void loopsm_run_state(fpi_ssm *ssm) switch (sdev->dev_model) { case UPEKSONLY_2016: capsm = fpi_ssm_new(FP_DEV(dev), capsm_2016_run_state, - CAPSM_2016_NUM_STATES); + CAPSM_2016_NUM_STATES, dev); break; case UPEKSONLY_1000: capsm = fpi_ssm_new(FP_DEV(dev), capsm_1000_run_state, - CAPSM_1000_NUM_STATES); + CAPSM_1000_NUM_STATES, dev); break; case UPEKSONLY_1001: capsm = fpi_ssm_new(FP_DEV(dev), capsm_1001_run_state, - CAPSM_1001_NUM_STATES); + CAPSM_1001_NUM_STATES, dev); break; } - fpi_ssm_set_user_data(capsm, dev); fpi_ssm_start_subsm(ssm, capsm); break; case LOOPSM_CAPTURE: @@ -1192,19 +1190,18 @@ static void loopsm_run_state(fpi_ssm *ssm) switch (sdev->dev_model) { case UPEKSONLY_2016: deinitsm = fpi_ssm_new(FP_DEV(dev), deinitsm_2016_run_state, - DEINITSM_2016_NUM_STATES); + DEINITSM_2016_NUM_STATES, dev); break; case UPEKSONLY_1000: deinitsm = fpi_ssm_new(FP_DEV(dev), deinitsm_1000_run_state, - DEINITSM_1000_NUM_STATES); + DEINITSM_1000_NUM_STATES, dev); break; case UPEKSONLY_1001: deinitsm = fpi_ssm_new(FP_DEV(dev), deinitsm_1001_run_state, - DEINITSM_1001_NUM_STATES); + DEINITSM_1001_NUM_STATES, dev); break; } sdev->capturing = FALSE; - fpi_ssm_set_user_data(deinitsm, dev); fpi_ssm_start_subsm(ssm, deinitsm); break; case LOOPSM_FINAL: @@ -1278,8 +1275,7 @@ static void initsm_complete(fpi_ssm *ssm) if (r != 0) return; - sdev->loopsm = fpi_ssm_new(FP_DEV(dev), loopsm_run_state, LOOPSM_NUM_STATES); - fpi_ssm_set_user_data(sdev->loopsm, dev); + sdev->loopsm = fpi_ssm_new(FP_DEV(dev), loopsm_run_state, LOOPSM_NUM_STATES, dev); fpi_ssm_start(sdev->loopsm, loopsm_complete); } @@ -1314,16 +1310,15 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) switch (sdev->dev_model) { case UPEKSONLY_2016: - ssm = fpi_ssm_new(FP_DEV(dev), initsm_2016_run_state, INITSM_2016_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), initsm_2016_run_state, INITSM_2016_NUM_STATES, dev); break; case UPEKSONLY_1000: - ssm = fpi_ssm_new(FP_DEV(dev), initsm_1000_run_state, INITSM_1000_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), initsm_1000_run_state, INITSM_1000_NUM_STATES, dev); break; case UPEKSONLY_1001: - ssm = fpi_ssm_new(FP_DEV(dev), initsm_1001_run_state, INITSM_1001_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), initsm_1001_run_state, INITSM_1001_NUM_STATES, dev); break; } - fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, initsm_complete); return 0; } diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index 383df419..16a38f67 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -395,9 +395,8 @@ static void start_capture(struct fp_img_dev *dev) return; } - ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); G_DEBUG_HERE(); - fpi_ssm_set_user_data(ssm, dev); fpi_ssm_start(ssm, capture_sm_complete); } @@ -405,8 +404,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, - ACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ACTIVATE_NUM_STATES, dev); upekdev->init_idx = 0; fpi_ssm_start(ssm, activate_sm_complete); return 0; diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 24ddb43e..3348bf35 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -365,8 +365,7 @@ static void start_capture(struct fp_img_dev *dev) upekdev->image_size = 0; - ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); fpi_ssm_start(ssm, capture_sm_complete); } @@ -444,8 +443,7 @@ static void start_deactivation(struct fp_img_dev *dev) upekdev->image_size = 0; - ssm = fpi_ssm_new(FP_DEV(dev), deactivate_run_state, DEACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), deactivate_run_state, DEACTIVATE_NUM_STATES, dev); fpi_ssm_start(ssm, deactivate_sm_complete); } @@ -581,8 +579,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { 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); - fpi_ssm_set_user_data(ssm, dev); + ACTIVATE_NUM_STATES, dev); upekdev->seq = 0; fpi_ssm_start(ssm, activate_sm_complete); return 0; diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index 7d650252..3692f8dd 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -736,9 +736,10 @@ static void initsm_run_state(fpi_ssm *ssm) } } -static fpi_ssm *initsm_new(struct fp_dev *dev) +static fpi_ssm *initsm_new(struct fp_dev *dev, + void *user_data) { - return fpi_ssm_new(dev, initsm_run_state, INITSM_NUM_STATES); + return fpi_ssm_new(dev, initsm_run_state, INITSM_NUM_STATES, user_data); } enum deinitsm_states { @@ -818,7 +819,7 @@ static void deinitsm_state_handler(fpi_ssm *ssm) static fpi_ssm *deinitsm_new(struct fp_dev *dev) { - return fpi_ssm_new(dev, deinitsm_state_handler, DEINITSM_NUM_STATES); + return fpi_ssm_new(dev, deinitsm_state_handler, DEINITSM_NUM_STATES, NULL); } static int dev_init(struct fp_dev *dev, unsigned long driver_data) @@ -923,8 +924,7 @@ static void enroll_start_sm_run_state(fpi_ssm *ssm) switch (fpi_ssm_get_cur_state(ssm)) { case RUN_INITSM: ; - fpi_ssm *initsm = initsm_new(dev); - fpi_ssm_set_user_data(initsm, ssm); + fpi_ssm *initsm = initsm_new(dev, ssm); fpi_ssm_start(initsm, enroll_start_sm_cb_initsm); break; case ENROLL_INIT: ; @@ -1129,7 +1129,7 @@ static int enroll_start(struct fp_dev *dev) /* do_init state machine first */ fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state, - ENROLL_START_NUM_STATES); + ENROLL_START_NUM_STATES, NULL); upekdev->enroll_passed = FALSE; fpi_ssm_start(ssm, enroll_started); @@ -1208,8 +1208,7 @@ static void verify_start_sm_run_state(fpi_ssm *ssm) switch (fpi_ssm_get_cur_state(ssm)) { case VERIFY_RUN_INITSM: ; - fpi_ssm *initsm = initsm_new(dev); - fpi_ssm_set_user_data(initsm, ssm); + fpi_ssm *initsm = initsm_new(dev, ssm); fpi_ssm_start(initsm, verify_start_sm_cb_initsm); break; case VERIFY_INIT: ; @@ -1409,7 +1408,7 @@ static int verify_start(struct fp_dev *dev) { struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state, - VERIFY_NUM_STATES); + VERIFY_NUM_STATES, NULL); upekdev->stop_verify = FALSE; fpi_ssm_start(ssm, verify_started); return 0; diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 2d3b54fd..25961055 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -1076,8 +1076,7 @@ static void init_run_state(fpi_ssm *ssm) break; case INIT_REBOOT_POWER: ; fpi_ssm *rebootsm = fpi_ssm_new(FP_DEV(dev), rebootpwr_run_state, - REBOOTPWR_NUM_STATES); - fpi_ssm_set_user_data(rebootsm, dev); + REBOOTPWR_NUM_STATES, dev); fpi_ssm_start_subsm(ssm, rebootsm); break; case INIT_CHECK_HWSTAT_POWERDOWN: @@ -1095,8 +1094,7 @@ static void init_run_state(fpi_ssm *ssm) urudev->irq_cb = init_scanpwr_irq_cb; fpi_ssm *powerupsm = fpi_ssm_new(FP_DEV(dev), powerup_run_state, - POWERUP_NUM_STATES); - fpi_ssm_set_user_data(powerupsm, dev); + POWERUP_NUM_STATES, dev); fpi_ssm_start_subsm(ssm, powerupsm); break; case INIT_AWAIT_SCAN_POWER: @@ -1169,8 +1167,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) urudev->scanpwr_irq_timeouts = 0; urudev->activate_state = state; - ssm = fpi_ssm_new(FP_DEV(dev), init_run_state, INIT_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), init_run_state, INIT_NUM_STATES, dev); fpi_ssm_start(ssm, activate_initsm_complete); return 0; } @@ -1223,8 +1220,7 @@ static int execute_state_change(struct fp_img_dev *dev) urudev->img_data = g_malloc(sizeof(struct uru4k_image)); urudev->img_enc_seed = rand(); - ssm = fpi_ssm_new(FP_DEV(dev), imaging_run_state, IMAGING_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), imaging_run_state, IMAGING_NUM_STATES, dev); fpi_ssm_start(ssm, imaging_complete); return write_reg(dev, REG_MODE, MODE_CAPTURE, diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index bb8b59b1..ab88d5ef 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -315,8 +315,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), loop_run_state, - LOOP_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + LOOP_NUM_STATES, dev); vdev->deactivating = FALSE; fpi_ssm_start(ssm, loopsm_complete); vdev->loop_running = TRUE; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 591fc972..e39cb61d 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -312,8 +312,7 @@ static void clear_ep2(fpi_ssm *ssm) struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); fpi_ssm *subsm = - fpi_ssm_new(FP_DEV(idev), clear_ep2_ssm, SUBSM1_STATES); - fpi_ssm_set_user_data(subsm, idev); + fpi_ssm_new(FP_DEV(idev), clear_ep2_ssm, SUBSM1_STATES, idev); fpi_ssm_start_subsm(ssm, subsm); } @@ -390,8 +389,7 @@ static void send_control_packet(fpi_ssm *ssm) struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); fpi_ssm *subsm = - fpi_ssm_new(FP_DEV(idev), send_control_packet_ssm, SUBSM2_STATES); - fpi_ssm_set_user_data(subsm, idev); + fpi_ssm_new(FP_DEV(idev), send_control_packet_ssm, SUBSM2_STATES, idev); fpi_ssm_start_subsm(ssm, subsm); } @@ -691,8 +689,7 @@ static int dev_activate(struct fp_img_dev *idev, enum fp_imgdev_state state) vdev->need_report = 1; vdev->ssm_active = 1; - fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), activate_ssm, SSM_STATES); - fpi_ssm_set_user_data(ssm, idev); + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), activate_ssm, SSM_STATES, idev); fpi_ssm_start(ssm, dev_activate_callback); return 0; } @@ -738,8 +735,7 @@ static int dev_open(struct fp_img_dev *idev, unsigned long driver_data) fp_dev_set_instance_data(FP_DEV(idev), vdev); /* Clearing previous device state */ - fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), activate_ssm, SSM_STATES); - fpi_ssm_set_user_data(ssm, idev); + fpi_ssm *ssm = fpi_ssm_new(FP_DEV(idev), activate_ssm, SSM_STATES, idev); fpi_ssm_start(ssm, dev_open_callback); return 0; } diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 7727b641..2cf8d014 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -536,8 +536,7 @@ static void m_swap(fpi_ssm *ssm, unsigned char *data, size_t length) vdev->length = length; /* Start swap ssm */ - subsm = fpi_ssm_new(FP_DEV(dev), m_swap_state, M_SWAP_NUM_STATES); - fpi_ssm_set_user_data(subsm, dev); + subsm = fpi_ssm_new(FP_DEV(dev), m_swap_state, M_SWAP_NUM_STATES, dev); fpi_ssm_start_subsm(ssm, subsm); } @@ -1429,8 +1428,7 @@ static void m_init_complete(fpi_ssm *ssm) fpi_imgdev_activate_complete(dev, 0); /* Start loop ssm */ - ssm_loop = fpi_ssm_new(FP_DEV(dev), m_loop_state, M_LOOP_NUM_STATES); - fpi_ssm_set_user_data(ssm_loop, dev); + ssm_loop = fpi_ssm_new(FP_DEV(dev), m_loop_state, M_LOOP_NUM_STATES, dev); fpi_ssm_start(ssm_loop, m_loop_complete); } @@ -1464,8 +1462,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) vdev->enroll_stage = 0; /* Start init ssm */ - ssm = fpi_ssm_new(FP_DEV(dev), m_init_state, M_INIT_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), m_init_state, M_INIT_NUM_STATES, dev); fpi_ssm_start(ssm, m_init_complete); return 0; diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 01572044..12f9137f 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -191,8 +191,7 @@ static void m_init_complete(fpi_ssm *ssm) fpi_imgdev_activate_complete(dev, 0); /* Start loop ssm */ - ssm_loop = fpi_ssm_new(FP_DEV(dev), m_loop_state, M_LOOP_NUM_STATES); - fpi_ssm_set_user_data(ssm_loop, dev); + ssm_loop = fpi_ssm_new(FP_DEV(dev), m_loop_state, M_LOOP_NUM_STATES, dev); fpi_ssm_start(ssm_loop, m_loop_complete); } @@ -206,8 +205,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) fpi_ssm *ssm; /* Start init ssm */ - ssm = fpi_ssm_new(FP_DEV(dev), m_init_state, 1); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), m_init_state, 1, dev); fpi_ssm_start(ssm, m_init_complete); return 0; diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index e0f21733..4dd3be15 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -238,8 +238,8 @@ static void usb_exchange_async(fpi_ssm *ssm, { fpi_ssm *subsm = fpi_ssm_new(FP_DEV(data->device), usbexchange_loop, - data->stepcount); - fpi_ssm_set_user_data(subsm, data); + data->stepcount, + data); fpi_ssm_start_subsm(ssm, subsm); } @@ -830,8 +830,7 @@ static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) } fpi_ssm *ssm; - ssm = fpi_ssm_new(FP_DEV(dev), open_loop, DEV_OPEN_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), open_loop, DEV_OPEN_NUM_STATES, dev); fpi_ssm_start(ssm, open_loop_complete); return 0; @@ -858,8 +857,7 @@ static void start_scan(struct fp_img_dev *dev) data = FP_INSTANCE_DATA(FP_DEV(dev)); data->loop_running = TRUE; fp_dbg("creating ssm"); - ssm = fpi_ssm_new(FP_DEV(dev), activate_loop, DEV_ACTIVATE_NUM_STATES); - fpi_ssm_set_user_data(ssm, dev); + ssm = fpi_ssm_new(FP_DEV(dev), activate_loop, DEV_ACTIVATE_NUM_STATES, dev); fp_dbg("starting ssm"); fpi_ssm_start(ssm, activate_loop_complete); fp_dbg("ssm done, getting out"); diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index da3a0625..c4b9d39a 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -78,7 +78,7 @@ struct fpi_ssm { struct fp_dev *dev; fpi_ssm *parentsm; - void *priv; + void *user_data; int nr_states; int cur_state; gboolean completed; @@ -92,14 +92,17 @@ struct fpi_ssm { * @dev: a #fp_dev fingerprint device * @handler: the callback function * @nr_states: the number of states + * @user_data: the user data to pass to callbacks * * Allocate a new ssm, with @nr_states states. The @handler callback * will be called after each state transition. * * Returns: a new #fpi_ssm state machine */ -fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, - int nr_states) +fpi_ssm *fpi_ssm_new(struct fp_dev *dev, + ssm_handler_fn handler, + int nr_states, + void *user_data) { fpi_ssm *machine; BUG_ON(nr_states < 1); @@ -109,6 +112,7 @@ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, machine->nr_states = nr_states; machine->dev = dev; machine->completed = TRUE; + machine->user_data = user_data; return machine; } @@ -127,34 +131,19 @@ fpi_ssm_get_dev(fpi_ssm *machine) return machine->dev; } -/** - * fpi_ssm_set_user_data: - * @machine: an #fpi_ssm state machine - * @user_data: a pointer to user data - * - * Set a user data pointer in the #fpi_ssm structure, to be - * retrieved with fpi_ssm_get_user_data() at a later point. - */ -void -fpi_ssm_set_user_data(fpi_ssm *machine, - void *user_data) -{ - machine->priv = user_data; -} - /** * fpi_ssm_get_user_data: * @machine: an #fpi_ssm state machine * - * Retrieve the pointer to user data set with - * fpi_ssm_set_user_data(). + * Retrieve the pointer to user data set when fpi_ssm_new() + * is called. * * Returns: a pointer */ void * fpi_ssm_get_user_data(fpi_ssm *machine) { - return machine->priv; + return machine->user_data; } /** diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 73ee2cab..9c76f315 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -58,8 +58,10 @@ typedef void (*ssm_completed_fn)(fpi_ssm *ssm); typedef void (*ssm_handler_fn)(fpi_ssm *ssm); /* for library and drivers */ -fpi_ssm *fpi_ssm_new(struct fp_dev *dev, ssm_handler_fn handler, - int nr_states); +fpi_ssm *fpi_ssm_new(struct fp_dev *dev, + ssm_handler_fn handler, + int nr_states, + void *user_data); void fpi_ssm_free(fpi_ssm *machine); void fpi_ssm_start(fpi_ssm *ssm, ssm_completed_fn callback); void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child); @@ -70,8 +72,6 @@ void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); void fpi_ssm_mark_completed(fpi_ssm *machine); void fpi_ssm_mark_failed(fpi_ssm *machine, int error); struct fp_dev *fpi_ssm_get_dev(fpi_ssm *machine); -void fpi_ssm_set_user_data(fpi_ssm *machine, - void *user_data); void *fpi_ssm_get_user_data(fpi_ssm *machine); int fpi_ssm_get_error(fpi_ssm *machine); int fpi_ssm_get_cur_state(fpi_ssm *machine); From e397571f83420dc69dcec0c91262652abff9fba6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 18 Sep 2018 13:46:39 +0200 Subject: [PATCH 064/225] lib: Add more args to fpi_ssm callbacks Pass the struct fp_dev and user_data to fpi_ssm callbacks, so that we might be able to get rid of the fpi_ssm_get_user_data(), and fpi_ssm_get_dev() as most drivers just get those from the ssm anyway in their callbacks. --- libfprint/drivers/aes1610.c | 8 ++++---- libfprint/drivers/aes2501.c | 8 ++++---- libfprint/drivers/aes2550.c | 8 ++++---- libfprint/drivers/aesx660.c | 12 ++++++------ libfprint/drivers/elan.c | 16 ++++++++-------- libfprint/drivers/etes603.c | 24 ++++++++++++------------ libfprint/drivers/upeksonly.c | 28 ++++++++++++++-------------- libfprint/drivers/upektc.c | 8 ++++---- libfprint/drivers/upektc_img.c | 12 ++++++------ libfprint/drivers/upekts.c | 20 ++++++++++---------- libfprint/drivers/uru4000.c | 12 ++++++------ libfprint/drivers/vcom5s.c | 4 ++-- libfprint/drivers/vfs0050.c | 10 +++++----- libfprint/drivers/vfs101.c | 10 +++++----- libfprint/drivers/vfs301.c | 8 ++++---- libfprint/drivers/vfs5011.c | 10 +++++----- libfprint/fpi-ssm.c | 6 +++--- libfprint/fpi-ssm.h | 12 ++++++++++-- 18 files changed, 112 insertions(+), 104 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index f90f72e3..f97947a6 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -643,7 +643,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -690,7 +690,7 @@ static void capture_run_state(fpi_ssm *ssm) }; } -static void capture_sm_complete(fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -737,7 +737,7 @@ enum activate_states { ACTIVATE_NUM_STATES, }; -static void activate_run_state(fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -752,7 +752,7 @@ static void activate_run_state(fpi_ssm *ssm) } /* jump to finger detection */ -static void activate_sm_complete(fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index 7aa9e20c..16716f6c 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -520,7 +520,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -571,7 +571,7 @@ static void capture_run_state(fpi_ssm *ssm) }; } -static void capture_sm_complete(fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -736,7 +736,7 @@ static void activate_init3_cb(struct fp_img_dev *dev, int result, fpi_ssm_mark_failed(ssm, result); } -static void activate_run_state(fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -790,7 +790,7 @@ static void activate_run_state(fpi_ssm *ssm) } } -static void activate_sm_complete(fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 446694ee..bc5a0efc 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -323,7 +323,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r; @@ -386,7 +386,7 @@ static void capture_run_state(fpi_ssm *ssm) }; } -static void capture_sm_complete(fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -482,7 +482,7 @@ static void calibrate_read_data_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void activate_run_state(fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r; @@ -567,7 +567,7 @@ static void activate_run_state(fpi_ssm *ssm) } } -static void activate_sm_complete(fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index 0c6255d5..cd8d65bc 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -195,7 +195,7 @@ static void finger_det_set_idle_cmd_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void finger_det_sm_complete(fpi_ssm *ssm) +static void finger_det_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -215,7 +215,7 @@ static void finger_det_sm_complete(fpi_ssm *ssm) } } -static void finger_det_run_state(fpi_ssm *ssm) +static void finger_det_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case FINGER_DET_SEND_LED_CMD: @@ -370,7 +370,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -399,7 +399,7 @@ static void capture_run_state(fpi_ssm *ssm) } } -static void capture_sm_complete(fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -532,7 +532,7 @@ out: libusb_free_transfer(transfer); } -static void activate_run_state(fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -578,7 +578,7 @@ static void activate_run_state(fpi_ssm *ssm) } } -static void activate_sm_complete(fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int err = fpi_ssm_get_error(ssm); diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index f7fb4949..9c5d8bce 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -440,7 +440,7 @@ enum stop_capture_states { STOP_CAPTURE_NUM_STATES, }; -static void stop_capture_run_state(fpi_ssm *ssm) +static void stop_capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { G_DEBUG_HERE(); @@ -451,7 +451,7 @@ static void stop_capture_run_state(fpi_ssm *ssm) } } -static void stop_capture_complete(fpi_ssm *ssm) +static void stop_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -499,7 +499,7 @@ enum capture_states { CAPTURE_NUM_STATES, }; -static void capture_run_state(fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -537,7 +537,7 @@ static void capture_run_state(fpi_ssm *ssm) } } -static void capture_complete(fpi_ssm *ssm) +static void capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -622,7 +622,7 @@ enum calibrate_states { CALIBRATE_NUM_STATES, }; -static void calibrate_run_state(fpi_ssm *ssm) +static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -687,7 +687,7 @@ static void calibrate_run_state(fpi_ssm *ssm) } } -static void calibrate_complete(fpi_ssm *ssm) +static void calibrate_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); @@ -723,7 +723,7 @@ enum activate_states { ACTIVATE_NUM_STATES, }; -static void activate_run_state(fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -767,7 +767,7 @@ static void activate_run_state(fpi_ssm *ssm) } } -static void activate_complete(fpi_ssm *ssm) +static void activate_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index 3691cf39..e5406989 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -699,7 +699,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) } } -static void m_exit_state(fpi_ssm *ssm) +static void m_exit_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -727,7 +727,7 @@ err: fpi_ssm_mark_failed(ssm, -EIO); } -static void m_exit_complete(fpi_ssm *ssm) +static void m_exit_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -748,7 +748,7 @@ static void m_exit_start(struct fp_img_dev *idev) fpi_ssm_start(ssm, m_exit_complete); } -static void m_capture_state(fpi_ssm *ssm) +static void m_capture_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -829,7 +829,7 @@ err: fpi_ssm_mark_failed(ssm, -EIO); } -static void m_capture_complete(fpi_ssm *ssm) +static void m_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -851,7 +851,7 @@ static void m_capture_complete(fpi_ssm *ssm) } } -static void m_finger_state(fpi_ssm *ssm) +static void m_finger_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -947,7 +947,7 @@ err: fpi_ssm_mark_failed(ssm, -EIO); } -static void m_finger_complete(fpi_ssm *ssm) +static void m_finger_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -979,7 +979,7 @@ static void m_start_fingerdetect(struct fp_img_dev *idev) /* * Tune value of VRT and VRB for contrast and brightness. */ -static void m_tunevrb_state(fpi_ssm *ssm) +static void m_tunevrb_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -1131,7 +1131,7 @@ err: fpi_ssm_mark_failed(ssm, -EIO); } -static void m_tunevrb_complete(fpi_ssm *ssm) +static void m_tunevrb_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -1153,7 +1153,7 @@ static void m_tunevrb_complete(fpi_ssm *ssm) * This function tunes the DCoffset value and adjusts the gain value if * required. */ -static void m_tunedc_state(fpi_ssm *ssm) +static void m_tunedc_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -1256,7 +1256,7 @@ err: } -static void m_tunedc_complete(fpi_ssm *ssm) +static void m_tunedc_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); if (!fpi_ssm_get_error(ssm)) { @@ -1274,7 +1274,7 @@ static void m_tunedc_complete(fpi_ssm *ssm) fpi_ssm_free(ssm); } -static void m_init_state(fpi_ssm *ssm) +static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -1375,7 +1375,7 @@ err: } -static void m_init_complete(fpi_ssm *ssm) +static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); if (!fpi_ssm_get_error(ssm)) { diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 06cbeedf..8594622f 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -763,7 +763,7 @@ enum awfsm_1000_states { AWFSM_1000_NUM_STATES, }; -static void awfsm_2016_run_state(fpi_ssm *ssm) +static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -810,7 +810,7 @@ static void awfsm_2016_run_state(fpi_ssm *ssm) } } -static void awfsm_1000_run_state(fpi_ssm *ssm) +static void awfsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case AWFSM_1000_WRITEV_1: @@ -881,7 +881,7 @@ static void capsm_fire_bulk(fpi_ssm *ssm) fpi_ssm_next_state(ssm); } -static void capsm_2016_run_state(fpi_ssm *ssm) +static void capsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -913,7 +913,7 @@ static void capsm_2016_run_state(fpi_ssm *ssm) } } -static void capsm_1000_run_state(fpi_ssm *ssm) +static void capsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -939,7 +939,7 @@ static void capsm_1000_run_state(fpi_ssm *ssm) } } -static void capsm_1001_run_state(fpi_ssm *ssm) +static void capsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -994,7 +994,7 @@ enum deinitsm_1001_states { DEINITSM_1001_NUM_STATES, }; -static void deinitsm_2016_run_state(fpi_ssm *ssm) +static void deinitsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_2016_WRITEV: @@ -1003,7 +1003,7 @@ static void deinitsm_2016_run_state(fpi_ssm *ssm) } } -static void deinitsm_1000_run_state(fpi_ssm *ssm) +static void deinitsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_1000_WRITEV: @@ -1012,7 +1012,7 @@ static void deinitsm_1000_run_state(fpi_ssm *ssm) } } -static void deinitsm_1001_run_state(fpi_ssm *ssm) +static void deinitsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_1001_WRITEV: @@ -1048,7 +1048,7 @@ enum initsm_1001_states { INITSM_1001_NUM_STATES, }; -static void initsm_2016_run_state(fpi_ssm *ssm) +static void initsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -1078,7 +1078,7 @@ static void initsm_2016_run_state(fpi_ssm *ssm) } } -static void initsm_1000_run_state(fpi_ssm *ssm) +static void initsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_1000_WRITEV_1: @@ -1087,7 +1087,7 @@ static void initsm_1000_run_state(fpi_ssm *ssm) } } -static void initsm_1001_run_state(fpi_ssm *ssm) +static void initsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_1001_WRITEV_1: @@ -1120,7 +1120,7 @@ enum loopsm_states { LOOPSM_NUM_STATES, }; -static void loopsm_run_state(fpi_ssm *ssm) +static void loopsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -1245,7 +1245,7 @@ static void dev_deactivate(struct fp_img_dev *dev) cancel_img_transfers(dev); } -static void loopsm_complete(fpi_ssm *ssm) +static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -1264,7 +1264,7 @@ static void loopsm_complete(fpi_ssm *ssm) } } -static void initsm_complete(fpi_ssm *ssm) +static void initsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index 16a38f67..fd59c410 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -98,7 +98,7 @@ static void read_init_data_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void activate_run_state(fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -148,7 +148,7 @@ static void activate_run_state(fpi_ssm *ssm) } } -static void activate_sm_complete(fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fp_dbg("status %d", fpi_ssm_get_error(ssm)); @@ -321,7 +321,7 @@ out: libusb_free_transfer(transfer); } -static void capture_run_state(fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -370,7 +370,7 @@ static void capture_run_state(fpi_ssm *ssm) }; } -static void capture_sm_complete(fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 3348bf35..bfc062ab 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -304,7 +304,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) } } -static void capture_run_state(fpi_ssm *ssm) +static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -341,7 +341,7 @@ static void capture_run_state(fpi_ssm *ssm) }; } -static void capture_sm_complete(fpi_ssm *ssm) +static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -401,7 +401,7 @@ static void deactivate_read_data_cb(struct libusb_transfer *transfer) } } -static void deactivate_run_state(fpi_ssm *ssm) +static void deactivate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -418,7 +418,7 @@ static void deactivate_run_state(fpi_ssm *ssm) }; } -static void deactivate_sm_complete(fpi_ssm *ssm) +static void deactivate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -498,7 +498,7 @@ static void init_read_data_cb(struct libusb_transfer *transfer) } } -static void activate_run_state(fpi_ssm *ssm) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct libusb_transfer *transfer; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -562,7 +562,7 @@ static void activate_run_state(fpi_ssm *ssm) } } -static void activate_sm_complete(fpi_ssm *ssm) +static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int err = fpi_ssm_get_error(ssm); diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index 3692f8dd..149cd7c8 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -649,7 +649,7 @@ static void initsm_send_msg28_handler(fpi_ssm *ssm, } } -static void initsm_run_state(fpi_ssm *ssm) +static void initsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); @@ -785,7 +785,7 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, fpi_ssm_next_state(ssm); } -static void deinitsm_state_handler(fpi_ssm *ssm) +static void deinitsm_state_handler(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; @@ -869,7 +869,7 @@ enum enroll_start_sm_states { }; /* Called when the device initialization state machine completes */ -static void enroll_start_sm_cb_initsm(fpi_ssm *initsm) +static void enroll_start_sm_cb_initsm(fpi_ssm *initsm, struct fp_dev *_dev, void *user_data) { fpi_ssm *enroll_start_ssm = fpi_ssm_get_user_data(initsm); int error = fpi_ssm_get_error(initsm); @@ -917,7 +917,7 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev, } } -static void enroll_start_sm_run_state(fpi_ssm *ssm) +static void enroll_start_sm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; @@ -1112,7 +1112,7 @@ static void enroll_iterate(struct fp_dev *dev) } } -static void enroll_started(fpi_ssm *ssm) +static void enroll_started(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); fpi_drvcb_enroll_started(dev, fpi_ssm_get_error(ssm)); @@ -1136,7 +1136,7 @@ static int enroll_start(struct fp_dev *dev) return 0; } -static void enroll_stop_deinit_cb(fpi_ssm *ssm) +static void enroll_stop_deinit_cb(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* don't really care about errors */ fpi_drvcb_enroll_stopped(fpi_ssm_get_dev(ssm)); @@ -1150,7 +1150,7 @@ static int enroll_stop(struct fp_dev *dev) return 0; } -static void verify_stop_deinit_cb(fpi_ssm *ssm) +static void verify_stop_deinit_cb(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* don't really care about errors */ fpi_drvcb_verify_stopped(fpi_ssm_get_dev(ssm)); @@ -1176,7 +1176,7 @@ enum { }; /* Called when the device initialization state machine completes */ -static void verify_start_sm_cb_initsm(fpi_ssm *initsm) +static void verify_start_sm_cb_initsm(fpi_ssm *initsm, struct fp_dev *_dev, void *user_data) { fpi_ssm *verify_start_ssm = fpi_ssm_get_user_data(initsm); int err; @@ -1201,7 +1201,7 @@ static void verify_init_2803_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void verify_start_sm_run_state(fpi_ssm *ssm) +static void verify_start_sm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; @@ -1390,7 +1390,7 @@ static void verify_iterate(struct fp_dev *dev) } } -static void verify_started(fpi_ssm *ssm) +static void verify_started(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 25961055..d3b577d9 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -687,7 +687,7 @@ static int calc_dev2(struct uru4k_image *img) return res / IMAGE_WIDTH; } -static void imaging_run_state(fpi_ssm *ssm) +static void imaging_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -810,7 +810,7 @@ static void imaging_run_state(fpi_ssm *ssm) } } -static void imaging_complete(fpi_ssm *ssm) +static void imaging_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -874,7 +874,7 @@ static void rebootpwr_pause_cb(void *data) } } -static void rebootpwr_run_state(fpi_ssm *ssm) +static void rebootpwr_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -953,7 +953,7 @@ static void powerup_pause_cb(void *data) } } -static void powerup_run_state(fpi_ssm *ssm) +static void powerup_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -1058,7 +1058,7 @@ static void init_scanpwr_timeout(void *user_data) } } -static void init_run_state(fpi_ssm *ssm) +static void init_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -1136,7 +1136,7 @@ static void init_run_state(fpi_ssm *ssm) } } -static void activate_initsm_complete(fpi_ssm *ssm) +static void activate_initsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r = fpi_ssm_get_error(ssm); diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index ab88d5ef..97ba94dd 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -265,7 +265,7 @@ enum loop_states { LOOP_NUM_STATES, }; -static void loop_run_state(fpi_ssm *ssm) +static void loop_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -293,7 +293,7 @@ static void loop_run_state(fpi_ssm *ssm) } } -static void loopsm_complete(fpi_ssm *ssm) +static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index e39cb61d..fdc50e5f 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -279,7 +279,7 @@ static void submit_image(struct fp_img_dev *idev) /* Proto functions */ /* SSM loop for clear_ep2 */ -static void clear_ep2_ssm(fpi_ssm *ssm) +static void clear_ep2_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); @@ -316,7 +316,7 @@ static void clear_ep2(fpi_ssm *ssm) fpi_ssm_start_subsm(ssm, subsm); } -static void send_control_packet_ssm(fpi_ssm *ssm) +static void send_control_packet_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -516,7 +516,7 @@ static void scan_completed(void *data) } /* Main SSM loop */ -static void activate_ssm(fpi_ssm *ssm) +static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); @@ -669,7 +669,7 @@ static void activate_ssm(fpi_ssm *ssm) /* Driver functions */ /* Callback for dev_activate ssm */ -static void dev_activate_callback(fpi_ssm *ssm) +static void dev_activate_callback(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -710,7 +710,7 @@ static void dev_deactivate(struct fp_img_dev *idev) } /* Callback for dev_open ssm */ -static void dev_open_callback(fpi_ssm *ssm) +static void dev_open_callback(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* Notify open complete */ fpi_imgdev_open_complete(fpi_ssm_get_user_data(ssm), 0); diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 2cf8d014..674855ea 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -507,7 +507,7 @@ enum }; /* Exec swap sequential state machine */ -static void m_swap_state(fpi_ssm *ssm) +static void m_swap_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { @@ -911,7 +911,7 @@ enum }; /* Exec loop sequential state machine */ -static void m_loop_state(fpi_ssm *ssm) +static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -1119,7 +1119,7 @@ static void m_loop_state(fpi_ssm *ssm) } /* Complete loop sequential state machine */ -static void m_loop_complete(fpi_ssm *ssm) +static void m_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* Free sequential state machine */ fpi_ssm_free(ssm); @@ -1175,7 +1175,7 @@ enum }; /* Exec init sequential state machine */ -static void m_init_state(fpi_ssm *ssm) +static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -1416,7 +1416,7 @@ static void m_init_state(fpi_ssm *ssm) } /* Complete init sequential state machine */ -static void m_init_complete(fpi_ssm *ssm) +static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 12f9137f..72f8f53b 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -103,7 +103,7 @@ enum }; /* Exec loop sequential state machine */ -static void m_loop_state(fpi_ssm *ssm) +static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -161,14 +161,14 @@ static void m_loop_state(fpi_ssm *ssm) } /* Complete loop sequential state machine */ -static void m_loop_complete(fpi_ssm *ssm) +static void m_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* Free sequential state machine */ fpi_ssm_free(ssm); } /* Exec init sequential state machine */ -static void m_init_state(fpi_ssm *ssm) +static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -181,7 +181,7 @@ static void m_init_state(fpi_ssm *ssm) } /* Complete init sequential state machine */ -static void m_init_complete(fpi_ssm *ssm) +static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fpi_ssm *ssm_loop; diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 4dd3be15..10a15cc1 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -171,7 +171,7 @@ out: libusb_free_transfer(transfer); } -static void usbexchange_loop(fpi_ssm *ssm) +static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct usbexchange_data *data = fpi_ssm_get_user_data(ssm); if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) { @@ -665,7 +665,7 @@ struct usb_action vfs5011_initiate_capture[] = { /* ====================== lifprint interface ======================= */ -static void activate_loop(fpi_ssm *ssm) +static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { enum {READ_TIMEOUT = 0}; @@ -742,7 +742,7 @@ static void activate_loop(fpi_ssm *ssm) } } -static void activate_loop_complete(fpi_ssm *ssm) +static void activate_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; @@ -772,7 +772,7 @@ static void activate_loop_complete(fpi_ssm *ssm) } -static void open_loop(fpi_ssm *ssm) +static void open_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; @@ -793,7 +793,7 @@ static void open_loop(fpi_ssm *ssm) }; } -static void open_loop_complete(fpi_ssm *ssm) +static void open_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs5011_data *data; diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index c4b9d39a..b00523ad 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -164,7 +164,7 @@ void fpi_ssm_free(fpi_ssm *machine) static void __ssm_call_handler(fpi_ssm *machine) { fp_dbg("%p entering state %d", machine, machine->cur_state); - machine->handler(machine); + machine->handler(machine, machine->dev, machine->user_data); } /** @@ -186,7 +186,7 @@ void fpi_ssm_start(fpi_ssm *ssm, ssm_completed_fn callback) __ssm_call_handler(ssm); } -static void __subsm_complete(fpi_ssm *ssm) +static void __subsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { fpi_ssm *parent = ssm->parentsm; BUG_ON(!parent); @@ -227,7 +227,7 @@ void fpi_ssm_mark_completed(fpi_ssm *machine) machine->completed = TRUE; fp_dbg("%p completed with status %d", machine, machine->error); if (machine->callback) - machine->callback(machine); + machine->callback(machine, machine->dev, machine->user_data); } /** diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 9c76f315..ed38ef37 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -42,20 +42,28 @@ typedef struct fpi_ssm fpi_ssm; /** * ssm_completed_fn: * @ssm: a #fpi_ssm state machine + * @dev: the #fp_dev fingerprint device + * @user_data: the user data passed to fpi_ssm_new() * * The callback called when a state machine completes successfully, * as set when calling fpi_ssm_start(). */ -typedef void (*ssm_completed_fn)(fpi_ssm *ssm); +typedef void (*ssm_completed_fn)(fpi_ssm *ssm, + struct fp_dev *dev, + void *user_data); /** * ssm_handler_fn: * @ssm: a #fpi_ssm state machine + * @dev: the #fp_dev fingerprint device + * @user_data: the user data passed to fpi_ssm_new() * * The callback called when a state machine transitions from one * state to the next, as set when calling fpi_ssm_new(). */ -typedef void (*ssm_handler_fn)(fpi_ssm *ssm); +typedef void (*ssm_handler_fn)(fpi_ssm *ssm, + struct fp_dev *dev, + void *user_data); /* for library and drivers */ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, From 7dfc8f3364e312c266f54872d3ed707cb30805cc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 18 Sep 2018 14:02:23 +0200 Subject: [PATCH 065/225] lib: Remove fpi_ssm_get_dev() Usually by passing the dev it from an fpi_ssm callback, or simply using that callback argument. --- libfprint/drivers/aes1610.c | 6 +- libfprint/drivers/aes2501.c | 9 ++- libfprint/drivers/upeksonly.c | 55 +++++++++--------- libfprint/drivers/upektc_img.c | 3 +- libfprint/drivers/upekts.c | 101 +++++++++++++++++---------------- libfprint/fpi-ssm.c | 15 ----- libfprint/fpi-ssm.h | 1 - 7 files changed, 88 insertions(+), 102 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index f97947a6..1748af73 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -126,11 +126,10 @@ static void generic_write_regv_cb(struct fp_img_dev *dev, int result, /* read the specified number of bytes from the IN endpoint but throw them * away, then increment the SSM */ -static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) +static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; - struct fp_dev *dev; int r; if (!transfer) { @@ -139,7 +138,6 @@ static void generic_read_ignore_data(fpi_ssm *ssm, size_t bytes) } data = g_malloc(bytes); - dev = fpi_ssm_get_dev(ssm); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes, generic_ignore_data_cb, ssm, BULK_TIMEOUT); @@ -657,7 +655,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data break; case CAPTURE_READ_DATA: fp_dbg("read data"); - generic_read_ignore_data(ssm, 665); + generic_read_ignore_data(ssm, _dev, 665); break; case CAPTURE_REQUEST_STRIP: fp_dbg("request strip"); diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index 16716f6c..7d1357c8 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -205,11 +205,10 @@ static void generic_ignore_data_cb(struct libusb_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(fpi_ssm *ssm, size_t bytes) +static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; - struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; if (!transfer) { @@ -532,14 +531,14 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data generic_write_regv_cb, ssm); break; case CAPTURE_READ_DATA_1: - generic_read_ignore_data(ssm, 159); + generic_read_ignore_data(ssm, _dev, 159); break; case CAPTURE_WRITE_REQS_2: aes_write_regv(dev, capture_reqs_2, G_N_ELEMENTS(capture_reqs_2), generic_write_regv_cb, ssm); break; case CAPTURE_READ_DATA_2: - generic_read_ignore_data(ssm, 159); + generic_read_ignore_data(ssm, _dev, 159); break; case CAPTURE_REQUEST_STRIP: if (aesdev->deactivating) @@ -766,7 +765,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case READ_DATA_1: fp_dbg("read data 1"); - generic_read_ignore_data(ssm, 20); + generic_read_ignore_data(ssm, _dev, 20); break; case WRITE_INIT_2: aes_write_regv(dev, init_2, G_N_ELEMENTS(init_2), diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 8594622f..c597e31b 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -574,12 +574,14 @@ static void write_regs_cb(struct libusb_transfer *transfer) write_regs_iterate(wrdata); } -static void sm_write_regs(fpi_ssm *ssm, - const struct sonly_regwrite *regs, size_t num_regs) +static void +sm_write_regs(fpi_ssm *ssm, + struct fp_dev *dev, + const struct sonly_regwrite *regs, + size_t num_regs) { struct write_regs_data *wrdata = g_malloc(sizeof(*wrdata)); unsigned char *data; - struct fp_dev *dev; wrdata->transfer = libusb_alloc_transfer(0); if (!wrdata->transfer) { @@ -590,7 +592,6 @@ static void sm_write_regs(fpi_ssm *ssm, data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); libusb_fill_control_setup(data, 0x40, 0x0c, 0, 0, 1); - dev = fpi_ssm_get_dev(ssm); libusb_fill_control_transfer(wrdata->transfer, fpi_dev_get_usb_dev(dev), data, write_regs_cb, wrdata, CTRL_TIMEOUT); @@ -770,7 +771,7 @@ static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d switch (fpi_ssm_get_cur_state(ssm)) { case AWFSM_2016_WRITEV_1: - sm_write_regs(ssm, awfsm_2016_writev_1, G_N_ELEMENTS(awfsm_2016_writev_1)); + sm_write_regs(ssm, _dev, awfsm_2016_writev_1, G_N_ELEMENTS(awfsm_2016_writev_1)); break; case AWFSM_2016_READ_01: sm_read_reg(ssm, 0x01); @@ -782,7 +783,7 @@ static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d sm_write_reg(ssm, 0x01, 0xc6); break; case AWFSM_2016_WRITEV_2: - sm_write_regs(ssm, awfsm_2016_writev_2, G_N_ELEMENTS(awfsm_2016_writev_2)); + sm_write_regs(ssm, _dev, awfsm_2016_writev_2, G_N_ELEMENTS(awfsm_2016_writev_2)); break; case AWFSM_2016_READ_13: sm_read_reg(ssm, 0x13); @@ -794,7 +795,7 @@ static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d sm_write_reg(ssm, 0x13, 0x45); break; case AWFSM_2016_WRITEV_3: - sm_write_regs(ssm, awfsm_2016_writev_3, G_N_ELEMENTS(awfsm_2016_writev_3)); + sm_write_regs(ssm, _dev, awfsm_2016_writev_3, G_N_ELEMENTS(awfsm_2016_writev_3)); break; case AWFSM_2016_READ_07: sm_read_reg(ssm, 0x07); @@ -805,7 +806,7 @@ static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d sm_write_reg(ssm, 0x07, sdev->read_reg_result); break; case AWFSM_2016_WRITEV_4: - sm_write_regs(ssm, awfsm_2016_writev_4, G_N_ELEMENTS(awfsm_2016_writev_4)); + sm_write_regs(ssm, _dev, awfsm_2016_writev_4, G_N_ELEMENTS(awfsm_2016_writev_4)); break; } } @@ -814,10 +815,10 @@ static void awfsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d { switch (fpi_ssm_get_cur_state(ssm)) { case AWFSM_1000_WRITEV_1: - sm_write_regs(ssm, awfsm_1000_writev_1, G_N_ELEMENTS(awfsm_1000_writev_1)); + sm_write_regs(ssm, _dev, awfsm_1000_writev_1, G_N_ELEMENTS(awfsm_1000_writev_1)); break; case AWFSM_1000_WRITEV_2: - sm_write_regs(ssm, awfsm_1000_writev_2, G_N_ELEMENTS(awfsm_1000_writev_2)); + sm_write_regs(ssm, _dev, awfsm_1000_writev_2, G_N_ELEMENTS(awfsm_1000_writev_2)); break; } } @@ -908,7 +909,7 @@ static void capsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d capsm_fire_bulk (ssm); break; case CAPSM_2016_WRITEV: - sm_write_regs(ssm, capsm_2016_writev, G_N_ELEMENTS(capsm_2016_writev)); + sm_write_regs(ssm, _dev, capsm_2016_writev, G_N_ELEMENTS(capsm_2016_writev)); break; } } @@ -934,7 +935,7 @@ static void capsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d capsm_fire_bulk (ssm); break; case CAPSM_1000_WRITEV: - sm_write_regs(ssm, capsm_1000_writev, G_N_ELEMENTS(capsm_1000_writev)); + sm_write_regs(ssm, _dev, capsm_1000_writev, G_N_ELEMENTS(capsm_1000_writev)); break; } } @@ -960,19 +961,19 @@ static void capsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d capsm_fire_bulk (ssm); break; case CAPSM_1001_WRITEV_1: - sm_write_regs(ssm, capsm_1001_writev_1, G_N_ELEMENTS(capsm_1001_writev_1)); + sm_write_regs(ssm, _dev, capsm_1001_writev_1, G_N_ELEMENTS(capsm_1001_writev_1)); break; case CAPSM_1001_WRITEV_2: - sm_write_regs(ssm, capsm_1001_writev_2, G_N_ELEMENTS(capsm_1001_writev_2)); + sm_write_regs(ssm, _dev, capsm_1001_writev_2, G_N_ELEMENTS(capsm_1001_writev_2)); break; case CAPSM_1001_WRITEV_3: - sm_write_regs(ssm, capsm_1001_writev_3, G_N_ELEMENTS(capsm_1001_writev_3)); + sm_write_regs(ssm, _dev, capsm_1001_writev_3, G_N_ELEMENTS(capsm_1001_writev_3)); break; case CAPSM_1001_WRITEV_4: - sm_write_regs(ssm, capsm_1001_writev_4, G_N_ELEMENTS(capsm_1001_writev_4)); + sm_write_regs(ssm, _dev, capsm_1001_writev_4, G_N_ELEMENTS(capsm_1001_writev_4)); break; case CAPSM_1001_WRITEV_5: - sm_write_regs(ssm, capsm_1001_writev_5, G_N_ELEMENTS(capsm_1001_writev_5)); + sm_write_regs(ssm, _dev, capsm_1001_writev_5, G_N_ELEMENTS(capsm_1001_writev_5)); break; } } @@ -998,7 +999,7 @@ static void deinitsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *use { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_2016_WRITEV: - sm_write_regs(ssm, deinitsm_2016_writev, G_N_ELEMENTS(deinitsm_2016_writev)); + sm_write_regs(ssm, _dev, deinitsm_2016_writev, G_N_ELEMENTS(deinitsm_2016_writev)); break; } } @@ -1007,7 +1008,7 @@ static void deinitsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *use { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_1000_WRITEV: - sm_write_regs(ssm, deinitsm_1000_writev, G_N_ELEMENTS(deinitsm_1000_writev)); + sm_write_regs(ssm, _dev, deinitsm_1000_writev, G_N_ELEMENTS(deinitsm_1000_writev)); break; } } @@ -1016,7 +1017,7 @@ static void deinitsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *use { switch (fpi_ssm_get_cur_state(ssm)) { case DEINITSM_1001_WRITEV: - sm_write_regs(ssm, deinitsm_1001_writev, G_N_ELEMENTS(deinitsm_1001_writev)); + sm_write_regs(ssm, _dev, deinitsm_1001_writev, G_N_ELEMENTS(deinitsm_1001_writev)); break; } } @@ -1055,7 +1056,7 @@ static void initsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_ switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_2016_WRITEV_1: - sm_write_regs(ssm, initsm_2016_writev_1, G_N_ELEMENTS(initsm_2016_writev_1)); + sm_write_regs(ssm, _dev, initsm_2016_writev_1, G_N_ELEMENTS(initsm_2016_writev_1)); break; case INITSM_2016_READ_09: sm_read_reg(ssm, 0x09); @@ -1082,7 +1083,7 @@ static void initsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_ { switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_1000_WRITEV_1: - sm_write_regs(ssm, initsm_1000_writev_1, G_N_ELEMENTS(initsm_1000_writev_1)); + sm_write_regs(ssm, _dev, initsm_1000_writev_1, G_N_ELEMENTS(initsm_1000_writev_1)); break; } } @@ -1091,19 +1092,19 @@ static void initsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_ { switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_1001_WRITEV_1: - sm_write_regs(ssm, initsm_1001_writev_1, G_N_ELEMENTS(initsm_1001_writev_1)); + sm_write_regs(ssm, _dev, initsm_1001_writev_1, G_N_ELEMENTS(initsm_1001_writev_1)); break; case INITSM_1001_WRITEV_2: - sm_write_regs(ssm, initsm_1001_writev_2, G_N_ELEMENTS(initsm_1001_writev_2)); + sm_write_regs(ssm, _dev, initsm_1001_writev_2, G_N_ELEMENTS(initsm_1001_writev_2)); break; case INITSM_1001_WRITEV_3: - sm_write_regs(ssm, initsm_1001_writev_3, G_N_ELEMENTS(initsm_1001_writev_3)); + sm_write_regs(ssm, _dev, initsm_1001_writev_3, G_N_ELEMENTS(initsm_1001_writev_3)); break; case INITSM_1001_WRITEV_4: - sm_write_regs(ssm, initsm_1001_writev_4, G_N_ELEMENTS(initsm_1001_writev_4)); + sm_write_regs(ssm, _dev, initsm_1001_writev_4, G_N_ELEMENTS(initsm_1001_writev_4)); break; case INITSM_1001_WRITEV_5: - sm_write_regs(ssm, initsm_1001_writev_5, G_N_ELEMENTS(initsm_1001_writev_5)); + sm_write_regs(ssm, _dev, initsm_1001_writev_5, G_N_ELEMENTS(initsm_1001_writev_5)); break; } } diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index bfc062ab..750c3a2a 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -498,12 +498,11 @@ static void init_read_data_cb(struct libusb_transfer *transfer) } } -static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { struct libusb_transfer *transfer; struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(idev)); - struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; switch (fpi_ssm_get_cur_state(ssm)) { diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index 149cd7c8..db3e867f 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -484,11 +484,14 @@ enum initsm_states { INITSM_NUM_STATES, }; -static void initsm_read_msg_response_cb(fpi_ssm *ssm, - enum read_msg_status status, uint8_t seq, - unsigned char expect_subcmd, unsigned char subcmd) +static void +initsm_read_msg_response_cb(fpi_ssm *ssm, + struct fp_dev *dev, + enum read_msg_status status, + uint8_t seq, + unsigned char expect_subcmd, + unsigned char subcmd) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (status != READ_MSG_RESPONSE) { @@ -513,7 +516,7 @@ static void read28_0b_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, dev, status, seq, 0x0b, subcmd); } @@ -521,7 +524,7 @@ static void read28_0c_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, dev, status, seq, 0x0c, subcmd); } @@ -529,7 +532,7 @@ static void read28_08_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, dev, status, seq, 0x08, subcmd); } @@ -537,7 +540,7 @@ static void read28_07_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, dev, status, seq, 0x07, subcmd); } @@ -545,14 +548,17 @@ static void read28_06_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_response_cb((fpi_ssm *) user_data, status, seq, + initsm_read_msg_response_cb((fpi_ssm *) user_data, dev, status, seq, 0x06, subcmd); } -static void initsm_read_msg_cmd_cb(fpi_ssm *ssm, - enum read_msg_status status, uint8_t expect_seq, uint8_t seq) +static void +initsm_read_msg_cmd_cb(fpi_ssm *ssm, + struct fp_dev *dev, + enum read_msg_status status, + uint8_t expect_seq, + uint8_t seq) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); if (status == READ_MSG_ERROR) { @@ -579,14 +585,14 @@ static void read_msg05_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_cmd_cb((fpi_ssm *) user_data, status, 5, seq); + initsm_read_msg_cmd_cb((fpi_ssm *) user_data, dev, status, 5, seq); } static void read_msg03_cb(struct fp_dev *dev, enum read_msg_status status, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, void *user_data) { - initsm_read_msg_cmd_cb((fpi_ssm *) user_data, status, 3, seq); + initsm_read_msg_cmd_cb((fpi_ssm *) user_data, dev, status, 3, seq); } static void ctrl400_cb(struct libusb_transfer *transfer) @@ -601,10 +607,12 @@ static void ctrl400_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void initsm_read_msg_handler(fpi_ssm *ssm, - read_msg_cb_fn callback) +static void +initsm_read_msg_handler(fpi_ssm *ssm, + struct fp_dev *dev, + read_msg_cb_fn callback) { - int r = read_msg_async(fpi_ssm_get_dev(ssm), callback, ssm); + int r = read_msg_async(dev, callback, ssm); if (r < 0) { fp_err("async read msg failed in state %d", fpi_ssm_get_cur_state(ssm)); fpi_ssm_mark_failed(ssm, r); @@ -626,10 +634,13 @@ static void initsm_send_msg_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void initsm_send_msg28_handler(fpi_ssm *ssm, - unsigned char subcmd, const unsigned char *data, uint16_t innerlen) +static void +initsm_send_msg28_handler(fpi_ssm *ssm, + struct fp_dev *dev, + unsigned char subcmd, + const unsigned char *data, + uint16_t innerlen) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct libusb_transfer *transfer; int r; @@ -649,9 +660,8 @@ static void initsm_send_msg28_handler(fpi_ssm *ssm, } } -static void initsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void initsm_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); struct libusb_transfer *transfer; int r; @@ -680,7 +690,7 @@ static void initsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) } break; case READ_MSG03: - initsm_read_msg_handler(ssm, read_msg03_cb); + initsm_read_msg_handler(ssm, dev, read_msg03_cb); break; case SEND_RESP03: ; transfer = alloc_send_cmdresponse_transfer(dev, ++upekdev->seq, @@ -698,40 +708,40 @@ static void initsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) } break; case READ_MSG05: - initsm_read_msg_handler(ssm, read_msg05_cb); + initsm_read_msg_handler(ssm, dev, read_msg05_cb); break; case SEND28_06: ; unsigned char dummy28_06 = 0x04; upekdev->seq = 0xf0; - initsm_send_msg28_handler(ssm, 0x06, &dummy28_06, 1); + initsm_send_msg28_handler(ssm, dev, 0x06, &dummy28_06, 1); break; case READ28_06: - initsm_read_msg_handler(ssm, read28_06_cb); + initsm_read_msg_handler(ssm, dev, read28_06_cb); break; case SEND28_07: ; unsigned char dummy28_07 = 0x04; - initsm_send_msg28_handler(ssm, 0x07, &dummy28_07, 1); + initsm_send_msg28_handler(ssm, dev, 0x07, &dummy28_07, 1); break; case READ28_07: - initsm_read_msg_handler(ssm, read28_07_cb); + initsm_read_msg_handler(ssm, dev, read28_07_cb); break; case SEND28_08: - initsm_send_msg28_handler(ssm, 0x08, init28_08, sizeof(init28_08)); + initsm_send_msg28_handler(ssm, dev, 0x08, init28_08, sizeof(init28_08)); break; case READ28_08: - initsm_read_msg_handler(ssm, read28_08_cb); + initsm_read_msg_handler(ssm, dev, read28_08_cb); break; case SEND28_0C: - initsm_send_msg28_handler(ssm, 0x0c, init28_0c, sizeof(init28_0c)); + initsm_send_msg28_handler(ssm, dev, 0x0c, init28_0c, sizeof(init28_0c)); break; case READ28_0C: - initsm_read_msg_handler(ssm, read28_0c_cb); + initsm_read_msg_handler(ssm, dev, read28_0c_cb); break; case SEND28_0B: - initsm_send_msg28_handler(ssm, 0x0b, init28_0b, sizeof(init28_0b)); + initsm_send_msg28_handler(ssm, dev, 0x0b, init28_0b, sizeof(init28_0b)); break; case READ28_0B: - initsm_read_msg_handler(ssm, read28_0b_cb); + initsm_read_msg_handler(ssm, dev, read28_0b_cb); break; } } @@ -785,9 +795,8 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status, fpi_ssm_next_state(ssm); } -static void deinitsm_state_handler(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void deinitsm_state_handler(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -917,9 +926,8 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev, } } -static void enroll_start_sm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void enroll_start_sm_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -1112,9 +1120,8 @@ static void enroll_iterate(struct fp_dev *dev) } } -static void enroll_started(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void enroll_started(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); fpi_drvcb_enroll_started(dev, fpi_ssm_get_error(ssm)); if (!fpi_ssm_get_error(ssm)) @@ -1136,10 +1143,10 @@ static int enroll_start(struct fp_dev *dev) return 0; } -static void enroll_stop_deinit_cb(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void enroll_stop_deinit_cb(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { /* don't really care about errors */ - fpi_drvcb_enroll_stopped(fpi_ssm_get_dev(ssm)); + fpi_drvcb_enroll_stopped(dev); fpi_ssm_free(ssm); } @@ -1150,10 +1157,10 @@ static int enroll_stop(struct fp_dev *dev) return 0; } -static void verify_stop_deinit_cb(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void verify_stop_deinit_cb(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { /* don't really care about errors */ - fpi_drvcb_verify_stopped(fpi_ssm_get_dev(ssm)); + fpi_drvcb_verify_stopped(dev); fpi_ssm_free(ssm); } @@ -1201,9 +1208,8 @@ static void verify_init_2803_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void verify_start_sm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void verify_start_sm_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -1390,9 +1396,8 @@ static void verify_iterate(struct fp_dev *dev) } } -static void verify_started(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void verify_started(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { - struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct upekts_dev *upekdev = FP_INSTANCE_DATA(dev); fpi_drvcb_verify_started(dev, fpi_ssm_get_error(ssm)); diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index b00523ad..2c7df5bf 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -116,21 +116,6 @@ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, return machine; } -/** - * fpi_ssm_get_dev: - * @machine: an #fpi_ssm state machine - * - * Returns the #fp_dev attached to the #fpi_ssm as passed - * in fpi_ssm_new(). - * - * Returns: a struct #fp_dev - */ -struct fp_dev * -fpi_ssm_get_dev(fpi_ssm *machine) -{ - return machine->dev; -} - /** * fpi_ssm_get_user_data: * @machine: an #fpi_ssm state machine diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index ed38ef37..63656a9f 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -79,7 +79,6 @@ void fpi_ssm_next_state(fpi_ssm *machine); void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); void fpi_ssm_mark_completed(fpi_ssm *machine); void fpi_ssm_mark_failed(fpi_ssm *machine, int error); -struct fp_dev *fpi_ssm_get_dev(fpi_ssm *machine); void *fpi_ssm_get_user_data(fpi_ssm *machine); int fpi_ssm_get_error(fpi_ssm *machine); int fpi_ssm_get_cur_state(fpi_ssm *machine); From 9cc859a31890c5a3237b0d52bb5332ed0da600cc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 18 Sep 2018 14:26:00 +0200 Subject: [PATCH 066/225] drivers: Diminish fpi_ssm_get_user_data() usage Can't remove it yet, as libusb transfers and timeouts don't pass the fp_dev or fp_img_dev separately. --- libfprint/drivers/aes1610.c | 8 +- libfprint/drivers/aes2501.c | 8 +- libfprint/drivers/aes2550.c | 13 ++- libfprint/drivers/aesx660.c | 77 ++++++++------ libfprint/drivers/elan.c | 49 ++++----- libfprint/drivers/elan.h | 2 +- libfprint/drivers/etes603.c | 24 ++--- libfprint/drivers/upeksonly.c | 80 ++++++++------- libfprint/drivers/upektc.c | 18 ++-- libfprint/drivers/upektc_img.c | 57 ++++++----- libfprint/drivers/upekts.c | 4 +- libfprint/drivers/uru4000.c | 76 ++++++++------ libfprint/drivers/vcom5s.c | 44 ++++---- libfprint/drivers/vfs0050.c | 67 +++++++------ libfprint/drivers/vfs101.c | 177 +++++++++++++++++++-------------- libfprint/drivers/vfs301.c | 23 +++-- libfprint/drivers/vfs5011.c | 18 ++-- 17 files changed, 418 insertions(+), 327 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index 1748af73..17f9f065 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -643,7 +643,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -690,7 +690,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -737,7 +737,7 @@ enum activate_states { static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; /* activation on aes1610 seems much more straightforward compared to aes2501 */ /* verify theres anything missing here */ @@ -752,7 +752,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat /* jump to finger detection */ static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; fp_dbg("status %d", fpi_ssm_get_error(ssm)); fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index 7d1357c8..f91682bb 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -521,7 +521,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -572,7 +572,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -737,7 +737,7 @@ static void activate_init3_cb(struct fp_img_dev *dev, int result, static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; /* This state machine isn't as linear as it may appear. After doing init1 * and init2 register configuration writes, we have to poll a register @@ -791,7 +791,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; fp_dbg("status %d", fpi_ssm_get_error(ssm)); fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index bc5a0efc..34533b56 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -200,10 +200,9 @@ enum capture_states { }; /* Returns number of processed bytes */ -static int process_strip_data(fpi_ssm *ssm, unsigned char *data) +static int process_strip_data(fpi_ssm *ssm, struct fp_img_dev *dev, unsigned char *data) { unsigned char *stripdata; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct fpi_frame *stripe; int len; @@ -290,7 +289,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) switch (transfer->actual_length) { case AES2550_STRIP_SIZE: - r = process_strip_data(ssm, data); + r = process_strip_data(ssm, dev, data); if (r < 0) { fp_dbg("Processing strip data failed: %d", r); fpi_ssm_mark_failed(ssm, -EPROTO); @@ -325,7 +324,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -388,7 +387,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); fp_dbg("Capture completed"); @@ -484,7 +483,7 @@ static void calibrate_read_data_cb(struct libusb_transfer *transfer) static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -569,7 +568,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; fp_dbg("status %d", fpi_ssm_get_error(ssm)); fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index cd8d65bc..650dc841 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -37,10 +37,15 @@ static void complete_deactivation(struct fp_img_dev *dev); #define min(a, b) (((a) < (b)) ? (a) : (b)) -static void aesX660_send_cmd_timeout(fpi_ssm *ssm, const unsigned char *cmd, - size_t cmd_len, libusb_transfer_cb_fn callback, int timeout) +static void +aesX660_send_cmd_timeout(fpi_ssm *ssm, + struct fp_dev *_dev, + const unsigned char *cmd, + size_t cmd_len, + libusb_transfer_cb_fn callback, + int timeout) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = FP_IMG_DEV(_dev); struct libusb_transfer *transfer = libusb_alloc_transfer(0); int r; @@ -60,16 +65,23 @@ static void aesX660_send_cmd_timeout(fpi_ssm *ssm, const unsigned char *cmd, } } -static void aesX660_send_cmd(fpi_ssm *ssm, const unsigned char *cmd, - size_t cmd_len, libusb_transfer_cb_fn callback) +static void +aesX660_send_cmd(fpi_ssm *ssm, + struct fp_dev *dev, + const unsigned char *cmd, + size_t cmd_len, + libusb_transfer_cb_fn callback) { - return aesX660_send_cmd_timeout(ssm, cmd, cmd_len, callback, BULK_TIMEOUT); + return aesX660_send_cmd_timeout(ssm, dev, cmd, cmd_len, callback, BULK_TIMEOUT); } -static void aesX660_read_response(fpi_ssm *ssm, size_t buf_len, - libusb_transfer_cb_fn callback) +static void +aesX660_read_response(fpi_ssm *ssm, + struct fp_dev *_dev, + size_t buf_len, + libusb_transfer_cb_fn callback) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = FP_IMG_DEV(_dev); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; int r; @@ -197,7 +209,7 @@ static void finger_det_set_idle_cmd_cb(struct libusb_transfer *transfer) static void finger_det_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); @@ -215,23 +227,23 @@ static void finger_det_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user } } -static void finger_det_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void finger_det_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { switch (fpi_ssm_get_cur_state(ssm)) { case FINGER_DET_SEND_LED_CMD: - aesX660_send_cmd(ssm, led_blink_cmd, sizeof(led_blink_cmd), + aesX660_send_cmd(ssm, dev, led_blink_cmd, sizeof(led_blink_cmd), aesX660_send_cmd_cb); break; case FINGER_DET_SEND_FD_CMD: - aesX660_send_cmd_timeout(ssm, wait_for_finger_cmd, sizeof(wait_for_finger_cmd), + aesX660_send_cmd_timeout(ssm, dev, wait_for_finger_cmd, sizeof(wait_for_finger_cmd), aesX660_send_cmd_cb, 0); break; case FINGER_DET_READ_FD_DATA: /* Should return 4 byte of response */ - aesX660_read_response(ssm, 4, finger_det_read_fd_data_cb); + aesX660_read_response(ssm, dev, 4, finger_det_read_fd_data_cb); break; case FINGER_DET_SET_IDLE: - aesX660_send_cmd(ssm, set_idle_cmd, sizeof(set_idle_cmd), + aesX660_send_cmd(ssm, dev, set_idle_cmd, sizeof(set_idle_cmd), finger_det_set_idle_cmd_cb); break; } @@ -262,11 +274,10 @@ enum capture_states { }; /* Returns number of processed bytes */ -static int process_stripe_data(fpi_ssm *ssm, unsigned char *data) +static int process_stripe_data(fpi_ssm *ssm, struct fp_img_dev *dev, unsigned char *data) { struct fpi_frame *stripe; unsigned char *stripdata; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); stripe = g_malloc(aesdev->assembling_ctx->frame_width * FRAME_HEIGHT / 2 + sizeof(struct fpi_frame)); /* 4 bpp */ @@ -351,7 +362,7 @@ static void capture_read_stripe_data_cb(struct libusb_transfer *transfer) aesdev->buffer_max); continue; } else { - finger_missing |= process_stripe_data(ssm, aesdev->buffer); + finger_missing |= process_stripe_data(ssm, dev, aesdev->buffer); aesdev->buffer_max = AESX660_HEADER_SIZE; aesdev->buffer_size = 0; } @@ -372,28 +383,28 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_SEND_LED_CMD: - aesX660_send_cmd(ssm, led_solid_cmd, sizeof(led_solid_cmd), + aesX660_send_cmd(ssm, _dev, led_solid_cmd, sizeof(led_solid_cmd), aesX660_send_cmd_cb); break; case CAPTURE_SEND_CAPTURE_CMD: aesdev->buffer_size = 0; aesdev->buffer_max = AESX660_HEADER_SIZE; - aesX660_send_cmd(ssm, aesdev->start_imaging_cmd, + aesX660_send_cmd(ssm, _dev, aesdev->start_imaging_cmd, aesdev->start_imaging_cmd_len, aesX660_send_cmd_cb); break; case CAPTURE_READ_STRIPE_DATA: - aesX660_read_response(ssm, AESX660_BULK_TRANSFER_SIZE, + aesX660_read_response(ssm, _dev, AESX660_BULK_TRANSFER_SIZE, capture_read_stripe_data_cb); break; case CAPTURE_SET_IDLE: fp_dbg("Got %lu frames\n", aesdev->strips_len); - aesX660_send_cmd(ssm, set_idle_cmd, sizeof(set_idle_cmd), + aesX660_send_cmd(ssm, _dev, set_idle_cmd, sizeof(set_idle_cmd), capture_set_idle_cmd_cb); break; } @@ -401,7 +412,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); @@ -534,30 +545,30 @@ out: static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case ACTIVATE_SET_IDLE: aesdev->init_seq_idx = 0; fp_dbg("Activate: set idle\n"); - aesX660_send_cmd(ssm, set_idle_cmd, sizeof(set_idle_cmd), + aesX660_send_cmd(ssm, _dev, set_idle_cmd, sizeof(set_idle_cmd), aesX660_send_cmd_cb); break; case ACTIVATE_SEND_READ_ID_CMD: fp_dbg("Activate: read ID\n"); - aesX660_send_cmd(ssm, read_id_cmd, sizeof(read_id_cmd), + aesX660_send_cmd(ssm, _dev, read_id_cmd, sizeof(read_id_cmd), aesX660_send_cmd_cb); break; case ACTIVATE_READ_ID: /* Should return 8-byte response */ - aesX660_read_response(ssm, 8, activate_read_id_cb); + aesX660_read_response(ssm, _dev, 8, activate_read_id_cb); break; case ACTIVATE_SEND_INIT_CMD: fp_dbg("Activate: send init seq #%d cmd #%d\n", aesdev->init_seq_idx, aesdev->init_cmd_idx); - aesX660_send_cmd(ssm, + aesX660_send_cmd(ssm, _dev, aesdev->init_seq[aesdev->init_cmd_idx].cmd, aesdev->init_seq[aesdev->init_cmd_idx].len, aesX660_send_cmd_cb); @@ -565,22 +576,22 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat case ACTIVATE_READ_INIT_RESPONSE: fp_dbg("Activate: read init response\n"); /* Should return 4-byte response */ - aesX660_read_response(ssm, 4, activate_read_init_cb); + aesX660_read_response(ssm, _dev, 4, activate_read_init_cb); break; case ACTIVATE_SEND_CALIBRATE_CMD: - aesX660_send_cmd(ssm, calibrate_cmd, sizeof(calibrate_cmd), + aesX660_send_cmd(ssm, _dev, calibrate_cmd, sizeof(calibrate_cmd), aesX660_send_cmd_cb); break; case ACTIVATE_READ_CALIBRATE_DATA: /* Should return 4-byte response */ - aesX660_read_response(ssm, 4, aesX660_read_calibrate_data_cb); + aesX660_read_response(ssm, _dev, 4, aesX660_read_calibrate_data_cb); break; } } static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; int err = fpi_ssm_get_error(ssm); fp_dbg("status %d", err); fpi_imgdev_activate_complete(dev, err); diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 9c5d8bce..330f625f 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -343,7 +343,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) } else { /* just finished sending */ G_DEBUG_HERE(); - elan_cmd_read(ssm); + elan_cmd_read(ssm, dev); } break; case LIBUSB_TRANSFER_CANCELLED: @@ -362,9 +362,8 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) } } -static void elan_cmd_read(fpi_ssm *ssm) +static void elan_cmd_read(fpi_ssm *ssm, struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); int response_len = elandev->cmd->response_len; @@ -401,10 +400,12 @@ static void elan_cmd_read(fpi_ssm *ssm) fpi_ssm_mark_failed(ssm, r); } -static void elan_run_cmd(fpi_ssm *ssm, const struct elan_cmd *cmd, - int cmd_timeout) +static void +elan_run_cmd(fpi_ssm *ssm, + struct fp_img_dev *dev, + const struct elan_cmd *cmd, + int cmd_timeout) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); dbg_buf(cmd->cmd, 2); @@ -440,20 +441,20 @@ enum stop_capture_states { STOP_CAPTURE_NUM_STATES, }; -static void stop_capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void stop_capture_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { G_DEBUG_HERE(); switch (fpi_ssm_get_cur_state(ssm)) { case STOP_CAPTURE: - elan_run_cmd(ssm, &stop_cmd, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, FP_IMG_DEV(dev), &stop_cmd, ELAN_CMD_TIMEOUT); break; } } static void stop_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); int error = fpi_ssm_get_error(ssm); @@ -501,16 +502,16 @@ enum capture_states { static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_LED_ON: - elan_run_cmd(ssm, &led_on_cmd, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, dev, &led_on_cmd, ELAN_CMD_TIMEOUT); break; case CAPTURE_WAIT_FINGER: - elan_run_cmd(ssm, &pre_scan_cmd, -1); + elan_run_cmd(ssm, dev, &pre_scan_cmd, -1); break; case CAPTURE_READ_DATA: /* 0x55 - finger present @@ -518,7 +519,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data if (elandev->last_read && elandev->last_read[0] == 0x55) { if (elandev->dev_state == IMGDEV_STATE_AWAIT_FINGER_ON) fpi_imgdev_report_finger_status(dev, TRUE); - elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, dev, &get_image_cmd, ELAN_CMD_TIMEOUT); } else fpi_ssm_mark_failed(ssm, -EBADMSG); break; @@ -539,7 +540,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -624,14 +625,14 @@ enum calibrate_states { static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); switch (fpi_ssm_get_cur_state(ssm)) { case CALIBRATE_GET_BACKGROUND: - elan_run_cmd(ssm, &get_image_cmd, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, dev, &get_image_cmd, ELAN_CMD_TIMEOUT); break; case CALIBRATE_SAVE_BACKGROUND: elan_save_background(elandev); @@ -642,7 +643,7 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da fpi_ssm_next_state(ssm); break; case CALIBRATE_GET_MEAN: - elan_run_cmd(ssm, &get_calib_mean_cmd, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, dev, &get_calib_mean_cmd, ELAN_CMD_TIMEOUT); break; case CALIBRATE_CHECK_NEEDED: if (elan_need_calibration(elandev)) { @@ -654,7 +655,7 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da case CALIBRATE_GET_STATUS: elandev->calib_atts_left -= 1; if (elandev->calib_atts_left) - elan_run_cmd(ssm, &get_calib_status_cmd, + elan_run_cmd(ssm, dev, &get_calib_status_cmd, ELAN_CMD_TIMEOUT); else { fp_dbg("calibration failed"); @@ -689,7 +690,7 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da static void calibrate_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; G_DEBUG_HERE(); @@ -725,14 +726,14 @@ enum activate_states { static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); switch (fpi_ssm_get_cur_state(ssm)) { case ACTIVATE_GET_FW_VER: - elan_run_cmd(ssm, &get_fw_ver_cmd, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, dev, &get_fw_ver_cmd, ELAN_CMD_TIMEOUT); break; case ACTIVATE_SET_FW_VER: elandev->fw_ver = @@ -741,7 +742,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat fpi_ssm_next_state(ssm); break; case ACTIVATE_GET_SENSOR_DIM: - elan_run_cmd(ssm, &get_sensor_dim_cmd, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, dev, &get_sensor_dim_cmd, ELAN_CMD_TIMEOUT); break; case ACTIVATE_SET_SENSOR_DIM: /* see elan_save_frame for details */ @@ -762,14 +763,14 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case ACTIVATE_CMD_1: /* TODO: find out what this does, if we need it */ - elan_run_cmd(ssm, &activate_cmd_1, ELAN_CMD_TIMEOUT); + elan_run_cmd(ssm, dev, &activate_cmd_1, ELAN_CMD_TIMEOUT); break; } } static void activate_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; G_DEBUG_HERE(); diff --git a/libfprint/drivers/elan.h b/libfprint/drivers/elan.h index fc36bb54..853f31de 100644 --- a/libfprint/drivers/elan.h +++ b/libfprint/drivers/elan.h @@ -211,7 +211,7 @@ static const struct usb_id elan_id_table[] = { }; static void elan_cmd_done(fpi_ssm *ssm); -static void elan_cmd_read(fpi_ssm *ssm); +static void elan_cmd_read(fpi_ssm *ssm, struct fp_img_dev *dev); static void elan_calibrate(struct fp_img_dev *dev); static void elan_capture(struct fp_img_dev *dev); diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index e5406989..06dea505 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -701,7 +701,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) static void m_exit_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -729,7 +729,7 @@ err: static void m_exit_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; if (fpi_ssm_get_error(ssm)) { fp_err("Error switching the device to idle state"); @@ -750,7 +750,7 @@ static void m_exit_start(struct fp_img_dev *idev) static void m_capture_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { @@ -831,7 +831,7 @@ err: static void m_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (fpi_ssm_get_error(ssm)) { @@ -853,7 +853,7 @@ static void m_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat static void m_finger_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { @@ -949,7 +949,7 @@ err: static void m_finger_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (!fpi_ssm_get_error(ssm)) { @@ -981,7 +981,7 @@ static void m_start_fingerdetect(struct fp_img_dev *idev) */ static void m_tunevrb_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); float hist[5]; @@ -1133,7 +1133,7 @@ err: static void m_tunevrb_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; fpi_imgdev_activate_complete(idev, fpi_ssm_get_error(ssm) != 0); if (!fpi_ssm_get_error(ssm)) { @@ -1155,7 +1155,7 @@ static void m_tunevrb_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat */ static void m_tunedc_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { @@ -1258,7 +1258,7 @@ err: static void m_tunedc_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_tune; ssm_tune = fpi_ssm_new(FP_DEV(idev), m_tunevrb_state, @@ -1276,7 +1276,7 @@ static void m_tunedc_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); if (dev->is_active == FALSE) { @@ -1377,7 +1377,7 @@ err: static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_tune; ssm_tune = fpi_ssm_new(FP_DEV(idev), m_tunedc_state, diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index c597e31b..cc5588ca 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -615,9 +615,12 @@ static void sm_write_reg_cb(struct libusb_transfer *transfer) } -static void sm_write_reg(fpi_ssm *ssm, uint8_t reg, uint8_t value) +static void +sm_write_reg(fpi_ssm *ssm, + struct fp_img_dev *dev, + uint8_t reg, + uint8_t value) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; int r; @@ -663,9 +666,11 @@ static void sm_read_reg_cb(struct libusb_transfer *transfer) g_free(transfer->buffer); } -static void sm_read_reg(fpi_ssm *ssm, uint8_t reg) +static void +sm_read_reg(fpi_ssm *ssm, + struct fp_img_dev *dev, + uint8_t reg) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; int r; @@ -714,9 +719,10 @@ static void sm_await_intr_cb(struct libusb_transfer *transfer) fpi_ssm_next_state(ssm); } -static void sm_await_intr(fpi_ssm *ssm) +static void +sm_await_intr(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; int r; @@ -766,7 +772,7 @@ enum awfsm_1000_states { static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -774,36 +780,36 @@ static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d sm_write_regs(ssm, _dev, awfsm_2016_writev_1, G_N_ELEMENTS(awfsm_2016_writev_1)); break; case AWFSM_2016_READ_01: - sm_read_reg(ssm, 0x01); + sm_read_reg(ssm, dev, 0x01); break; case AWFSM_2016_WRITE_01: if (sdev->read_reg_result != 0xc6) - sm_write_reg(ssm, 0x01, 0x46); + sm_write_reg(ssm, dev, 0x01, 0x46); else - sm_write_reg(ssm, 0x01, 0xc6); + sm_write_reg(ssm, dev, 0x01, 0xc6); break; case AWFSM_2016_WRITEV_2: sm_write_regs(ssm, _dev, awfsm_2016_writev_2, G_N_ELEMENTS(awfsm_2016_writev_2)); break; case AWFSM_2016_READ_13: - sm_read_reg(ssm, 0x13); + sm_read_reg(ssm, dev, 0x13); break; case AWFSM_2016_WRITE_13: if (sdev->read_reg_result != 0x45) - sm_write_reg(ssm, 0x13, 0x05); + sm_write_reg(ssm, dev, 0x13, 0x05); else - sm_write_reg(ssm, 0x13, 0x45); + sm_write_reg(ssm, dev, 0x13, 0x45); break; case AWFSM_2016_WRITEV_3: sm_write_regs(ssm, _dev, awfsm_2016_writev_3, G_N_ELEMENTS(awfsm_2016_writev_3)); break; case AWFSM_2016_READ_07: - sm_read_reg(ssm, 0x07); + sm_read_reg(ssm, dev, 0x07); break; case AWFSM_2016_WRITE_07: if (sdev->read_reg_result != 0x10 && sdev->read_reg_result != 0x90) fp_warn("odd reg7 value %x", sdev->read_reg_result); - sm_write_reg(ssm, 0x07, sdev->read_reg_result); + sm_write_reg(ssm, dev, 0x07, sdev->read_reg_result); break; case AWFSM_2016_WRITEV_4: sm_write_regs(ssm, _dev, awfsm_2016_writev_4, G_N_ELEMENTS(awfsm_2016_writev_4)); @@ -852,9 +858,11 @@ enum capsm_1001_states { CAPSM_1001_NUM_STATES, }; -static void capsm_fire_bulk(fpi_ssm *ssm) +static void +capsm_fire_bulk(fpi_ssm *ssm, + struct fp_dev *_dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = FP_IMG_DEV(_dev); struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int i; for (i = 0; i < NUM_BULK_TRANSFERS; i++) { @@ -884,7 +892,7 @@ static void capsm_fire_bulk(fpi_ssm *ssm) static void capsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -900,13 +908,13 @@ static void capsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d fpi_ssm_next_state(ssm); break; case CAPSM_2016_WRITE_15: - sm_write_reg(ssm, 0x15, 0x20); + sm_write_reg(ssm, dev, 0x15, 0x20); break; case CAPSM_2016_WRITE_30: - sm_write_reg(ssm, 0x30, 0xe0); + sm_write_reg(ssm, dev, 0x30, 0xe0); break; case CAPSM_2016_FIRE_BULK: ; - capsm_fire_bulk (ssm); + capsm_fire_bulk (ssm, _dev); break; case CAPSM_2016_WRITEV: sm_write_regs(ssm, _dev, capsm_2016_writev, G_N_ELEMENTS(capsm_2016_writev)); @@ -916,7 +924,7 @@ static void capsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d static void capsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -932,7 +940,7 @@ static void capsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d fpi_ssm_next_state(ssm); break; case CAPSM_1000_FIRE_BULK: ; - capsm_fire_bulk (ssm); + capsm_fire_bulk (ssm, _dev); break; case CAPSM_1000_WRITEV: sm_write_regs(ssm, _dev, capsm_1000_writev, G_N_ELEMENTS(capsm_1000_writev)); @@ -942,7 +950,7 @@ static void capsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d static void capsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -958,7 +966,7 @@ static void capsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d fpi_ssm_next_state(ssm); break; case CAPSM_1001_FIRE_BULK: ; - capsm_fire_bulk (ssm); + capsm_fire_bulk (ssm, _dev); break; case CAPSM_1001_WRITEV_1: sm_write_regs(ssm, _dev, capsm_1001_writev_1, G_N_ELEMENTS(capsm_1001_writev_1)); @@ -1051,7 +1059,7 @@ enum initsm_1001_states { static void initsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -1059,22 +1067,22 @@ static void initsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_ sm_write_regs(ssm, _dev, initsm_2016_writev_1, G_N_ELEMENTS(initsm_2016_writev_1)); break; case INITSM_2016_READ_09: - sm_read_reg(ssm, 0x09); + sm_read_reg(ssm, dev, 0x09); break; case INITSM_2016_WRITE_09: - sm_write_reg(ssm, 0x09, sdev->read_reg_result & ~0x08); + sm_write_reg(ssm, dev, 0x09, sdev->read_reg_result & ~0x08); break; case INITSM_2016_READ_13: - sm_read_reg(ssm, 0x13); + sm_read_reg(ssm, dev, 0x13); break; case INITSM_2016_WRITE_13: - sm_write_reg(ssm, 0x13, sdev->read_reg_result & ~0x10); + sm_write_reg(ssm, dev, 0x13, sdev->read_reg_result & ~0x10); break; case INITSM_2016_WRITE_04: - sm_write_reg(ssm, 0x04, 0x00); + sm_write_reg(ssm, dev, 0x04, 0x00); break; case INITSM_2016_WRITE_05: - sm_write_reg(ssm, 0x05, 0x00); + sm_write_reg(ssm, dev, 0x05, 0x00); break; } } @@ -1123,7 +1131,7 @@ enum loopsm_states { static void loopsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -1162,7 +1170,7 @@ static void loopsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) fpi_ssm_next_state(ssm); break; default: - sm_await_intr(ssm); + sm_await_intr(ssm, dev); break; } break; @@ -1248,7 +1256,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); @@ -1267,7 +1275,7 @@ static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void initsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index fd59c410..43facc20 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -56,9 +56,10 @@ enum activate_states { ACTIVATE_NUM_STATES, }; -static void upektc_next_init_cmd(fpi_ssm *ssm) +static void +upektc_next_init_cmd(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); upekdev->init_idx += 1; @@ -79,7 +80,7 @@ static void write_init_cb(struct libusb_transfer *transfer) if (upekdev->setup_commands[upekdev->init_idx].response_len) fpi_ssm_next_state(ssm); else - upektc_next_init_cmd(ssm); + upektc_next_init_cmd(ssm, dev); } else { fpi_ssm_mark_failed(ssm, -EIO); } @@ -89,9 +90,10 @@ static void write_init_cb(struct libusb_transfer *transfer) static void read_init_data_cb(struct libusb_transfer *transfer) { fpi_ssm *ssm = transfer->user_data; + struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); if (transfer->status == LIBUSB_TRANSFER_COMPLETED) - upektc_next_init_cmd(ssm); + upektc_next_init_cmd(ssm, dev); else fpi_ssm_mark_failed(ssm, -EIO); g_free(transfer->buffer); @@ -100,7 +102,7 @@ static void read_init_data_cb(struct libusb_transfer *transfer) static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -150,7 +152,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; fp_dbg("status %d", fpi_ssm_get_error(ssm)); fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm)); @@ -323,7 +325,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -372,7 +374,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); fp_dbg("Capture completed"); diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 750c3a2a..6fd62dd4 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -71,11 +71,14 @@ static void upektc_img_cmd_update_crc(unsigned char *cmd_buf, size_t size) cmd_buf[size - 1] = (crc & 0xff00) >> 8; } -static void upektc_img_submit_req(fpi_ssm *ssm, - const unsigned char *buf, size_t buf_size, unsigned char seq, - libusb_transfer_cb_fn cb) +static void +upektc_img_submit_req(fpi_ssm *ssm, + struct fp_img_dev *dev, + const unsigned char *buf, + size_t buf_size, + unsigned char seq, + libusb_transfer_cb_fn cb) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct libusb_transfer *transfer = libusb_alloc_transfer(0); int r; @@ -103,10 +106,14 @@ static void upektc_img_submit_req(fpi_ssm *ssm, } } -static void upektc_img_read_data(fpi_ssm *ssm, size_t buf_size, size_t buf_offset, libusb_transfer_cb_fn cb) +static void +upektc_img_read_data(fpi_ssm *ssm, + struct fp_img_dev *dev, + size_t buf_size, + size_t buf_offset, + libusb_transfer_cb_fn cb) { struct libusb_transfer *transfer = libusb_alloc_transfer(0); - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -306,35 +313,35 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_INIT_CAPTURE: - upektc_img_submit_req(ssm, upek2020_init_capture, sizeof(upek2020_init_capture), + upektc_img_submit_req(ssm, dev, upek2020_init_capture, sizeof(upek2020_init_capture), upekdev->seq, capture_reqs_cb); upekdev->seq++; break; case CAPTURE_READ_DATA: case CAPTURE_READ_DATA_TERM: if (!upekdev->response_rest) - upektc_img_read_data(ssm, SHORT_RESPONSE_SIZE, 0, capture_read_data_cb); + upektc_img_read_data(ssm, dev, SHORT_RESPONSE_SIZE, 0, capture_read_data_cb); else - upektc_img_read_data(ssm, MAX_RESPONSE_SIZE - SHORT_RESPONSE_SIZE, + upektc_img_read_data(ssm, dev, MAX_RESPONSE_SIZE - SHORT_RESPONSE_SIZE, SHORT_RESPONSE_SIZE, capture_read_data_cb); break; case CAPTURE_ACK_00_28: case CAPTURE_ACK_00_28_TERM: - upektc_img_submit_req(ssm, upek2020_ack_00_28, sizeof(upek2020_ack_00_28), + upektc_img_submit_req(ssm, dev, upek2020_ack_00_28, sizeof(upek2020_ack_00_28), upekdev->seq, capture_reqs_cb); upekdev->seq++; break; case CAPTURE_ACK_08: - upektc_img_submit_req(ssm, upek2020_ack_08, sizeof(upek2020_ack_08), + upektc_img_submit_req(ssm, dev, upek2020_ack_08, sizeof(upek2020_ack_08), 0, capture_reqs_cb); break; case CAPTURE_ACK_FRAME: - upektc_img_submit_req(ssm, upek2020_ack_frame, sizeof(upek2020_ack_frame), + upektc_img_submit_req(ssm, dev, upek2020_ack_frame, sizeof(upek2020_ack_frame), upekdev->seq, capture_reqs_cb); upekdev->seq++; break; @@ -343,7 +350,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); @@ -403,24 +410,24 @@ static void deactivate_read_data_cb(struct libusb_transfer *transfer) static void deactivate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case DEACTIVATE_DEINIT: - upektc_img_submit_req(ssm, upek2020_deinit, sizeof(upek2020_deinit), + upektc_img_submit_req(ssm, dev, upek2020_deinit, sizeof(upek2020_deinit), upekdev->seq, deactivate_reqs_cb); upekdev->seq++; break; case DEACTIVATE_READ_DEINIT_DATA: - upektc_img_read_data(ssm, SHORT_RESPONSE_SIZE, 0, deactivate_read_data_cb); + upektc_img_read_data(ssm, dev, SHORT_RESPONSE_SIZE, 0, deactivate_read_data_cb); break; }; } static void deactivate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int err = fpi_ssm_get_error(ssm); @@ -501,7 +508,7 @@ static void init_read_data_cb(struct libusb_transfer *transfer) static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) { struct libusb_transfer *transfer; - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(idev)); int r; @@ -533,19 +540,19 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data } break; case ACTIVATE_INIT_1: - upektc_img_submit_req(ssm, upek2020_init_1, sizeof(upek2020_init_1), + upektc_img_submit_req(ssm, idev, upek2020_init_1, sizeof(upek2020_init_1), 0, init_reqs_cb); break; case ACTIVATE_INIT_2: - upektc_img_submit_req(ssm, upek2020_init_2, sizeof(upek2020_init_2), + upektc_img_submit_req(ssm, idev, upek2020_init_2, sizeof(upek2020_init_2), 0, init_reqs_cb); break; case ACTIVATE_INIT_3: - upektc_img_submit_req(ssm, upek2020_init_3, sizeof(upek2020_init_3), + upektc_img_submit_req(ssm, idev, upek2020_init_3, sizeof(upek2020_init_3), 0, init_reqs_cb); break; case ACTIVATE_INIT_4: - upektc_img_submit_req(ssm, upek2020_init_4, sizeof(upek2020_init_4), + upektc_img_submit_req(ssm, idev, upek2020_init_4, sizeof(upek2020_init_4), upekdev->seq, init_reqs_cb); /* Seq should be updated after 4th init */ upekdev->seq++; @@ -556,14 +563,14 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data case ACTIVATE_READ_INIT_2_RESP: case ACTIVATE_READ_INIT_3_RESP: case ACTIVATE_READ_INIT_4_RESP: - upektc_img_read_data(ssm, SHORT_RESPONSE_SIZE, 0, init_read_data_cb); + upektc_img_read_data(ssm, idev, SHORT_RESPONSE_SIZE, 0, init_read_data_cb); break; } } static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; int err = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index db3e867f..98448e1f 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -880,7 +880,7 @@ enum enroll_start_sm_states { /* Called when the device initialization state machine completes */ static void enroll_start_sm_cb_initsm(fpi_ssm *initsm, struct fp_dev *_dev, void *user_data) { - fpi_ssm *enroll_start_ssm = fpi_ssm_get_user_data(initsm); + fpi_ssm *enroll_start_ssm = user_data; int error = fpi_ssm_get_error(initsm); fpi_ssm_free(initsm); @@ -1185,7 +1185,7 @@ enum { /* Called when the device initialization state machine completes */ static void verify_start_sm_cb_initsm(fpi_ssm *initsm, struct fp_dev *_dev, void *user_data) { - fpi_ssm *verify_start_ssm = fpi_ssm_get_user_data(initsm); + fpi_ssm *verify_start_ssm = user_data; int err; err = fpi_ssm_get_error(initsm); diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index d3b577d9..c26235bb 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -354,9 +354,10 @@ static void challenge_cb(struct fp_img_dev *dev, int status, * authentication scheme, where the device challenges the authenticity of the * driver. */ -static void sm_do_challenge_response(fpi_ssm *ssm) +static void +sm_do_challenge_response(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r; G_DEBUG_HERE(); @@ -516,19 +517,25 @@ static void sm_write_reg_cb(struct fp_img_dev *dev, int result, void *user_data) fpi_ssm_next_state(ssm); } -static void sm_write_regs(fpi_ssm *ssm, uint16_t first_reg, uint16_t num_regs, - void *data) +static void +sm_write_regs(fpi_ssm *ssm, + struct fp_img_dev *dev, + uint16_t first_reg, + uint16_t num_regs, + void *data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); int r = write_regs(dev, first_reg, num_regs, data, sm_write_reg_cb, ssm); if (r < 0) fpi_ssm_mark_failed(ssm, r); } -static void sm_write_reg(fpi_ssm *ssm, uint16_t reg, - unsigned char value) +static void +sm_write_reg(fpi_ssm *ssm, + struct fp_img_dev *dev, + uint16_t reg, + unsigned char value) { - sm_write_regs(ssm, reg, 1, &value); + sm_write_regs(ssm, dev, reg, 1, &value); } static void sm_read_reg_cb(struct fp_img_dev *dev, int result, @@ -546,9 +553,12 @@ static void sm_read_reg_cb(struct fp_img_dev *dev, int result, } } -static void sm_read_regs(fpi_ssm *ssm, uint16_t reg, uint16_t num_regs) +static void +sm_read_regs(fpi_ssm *ssm, + struct fp_img_dev *dev, + uint16_t reg, + uint16_t num_regs) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -563,15 +573,21 @@ static void sm_read_regs(fpi_ssm *ssm, uint16_t reg, uint16_t num_regs) fpi_ssm_mark_failed(ssm, r); } -static void sm_read_reg(fpi_ssm *ssm, uint16_t reg) +static void +sm_read_reg(fpi_ssm *ssm, + struct fp_img_dev *dev, + uint16_t reg) { - sm_read_regs(ssm, reg, 1); + sm_read_regs(ssm, dev, reg, 1); } -static void sm_set_hwstat(fpi_ssm *ssm, unsigned char value) +static void +sm_set_hwstat(fpi_ssm *ssm, + struct fp_img_dev *dev, + unsigned char value) { fp_dbg("set %02x", value); - sm_write_reg(ssm, REG_HWSTAT, value); + sm_write_reg(ssm, dev, REG_HWSTAT, value); } /***** IMAGING LOOP *****/ @@ -689,7 +705,7 @@ static int calc_dev2(struct uru4k_image *img) static void imaging_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); struct uru4k_image *img = urudev->img_data; struct fp_img *fpimg; @@ -734,10 +750,10 @@ static void imaging_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data buf[2] = urudev->img_enc_seed >> 8; buf[3] = urudev->img_enc_seed >> 16; buf[4] = urudev->img_enc_seed >> 24; - sm_write_regs(ssm, REG_SCRAMBLE_DATA_INDEX, 5, buf); + sm_write_regs(ssm, dev, REG_SCRAMBLE_DATA_INDEX, 5, buf); break; case IMAGING_READ_KEY: - sm_read_regs(ssm, REG_SCRAMBLE_DATA_KEY, 4); + sm_read_regs(ssm, dev, REG_SCRAMBLE_DATA_KEY, 4); break; case IMAGING_DECODE: key = urudev->last_reg_rd[0]; @@ -812,7 +828,7 @@ static void imaging_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void imaging_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); @@ -876,16 +892,16 @@ static void rebootpwr_pause_cb(void *data) static void rebootpwr_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case REBOOTPWR_SET_HWSTAT: urudev->rebootpwr_ctr = 100; - sm_set_hwstat(ssm, urudev->last_hwstat & 0xf); + sm_set_hwstat(ssm, dev, urudev->last_hwstat & 0xf); break; case REBOOTPWR_GET_HWSTAT: - sm_read_reg(ssm, REG_HWSTAT); + sm_read_reg(ssm, dev, REG_HWSTAT); break; case REBOOTPWR_CHECK_HWSTAT: urudev->last_hwstat = urudev->last_reg_rd[0]; @@ -955,7 +971,7 @@ static void powerup_pause_cb(void *data) static void powerup_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -965,10 +981,10 @@ static void powerup_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data fpi_ssm_next_state(ssm); break; case POWERUP_SET_HWSTAT: - sm_set_hwstat(ssm, urudev->powerup_hwstat); + sm_set_hwstat(ssm, dev, urudev->powerup_hwstat); break; case POWERUP_GET_HWSTAT: - sm_read_reg(ssm, REG_HWSTAT); + sm_read_reg(ssm, dev, REG_HWSTAT); break; case POWERUP_CHECK_HWSTAT: urudev->last_hwstat = urudev->last_reg_rd[0]; @@ -982,7 +998,7 @@ static void powerup_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data fpi_ssm_mark_failed(ssm, -ETIME); break; case POWERUP_CHALLENGE_RESPONSE: - sm_do_challenge_response(ssm); + sm_do_challenge_response(ssm, dev); break; case POWERUP_CHALLENGE_RESPONSE_SUCCESS: fpi_ssm_jump_to_state(ssm, POWERUP_SET_HWSTAT); @@ -1060,12 +1076,12 @@ static void init_scanpwr_timeout(void *user_data) static void init_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case INIT_GET_HWSTAT: - sm_read_reg(ssm, REG_HWSTAT); + sm_read_reg(ssm, dev, REG_HWSTAT); break; case INIT_CHECK_HWSTAT_REBOOT: urudev->last_hwstat = urudev->last_reg_rd[0]; @@ -1081,7 +1097,7 @@ static void init_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) break; case INIT_CHECK_HWSTAT_POWERDOWN: if ((urudev->last_hwstat & 0x80) == 0) - sm_set_hwstat(ssm, urudev->last_hwstat | 0x80); + sm_set_hwstat(ssm, dev, urudev->last_hwstat | 0x80); else fpi_ssm_next_state(ssm); break; @@ -1123,7 +1139,7 @@ static void init_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) fpi_ssm_next_state(ssm); break; case INIT_GET_VERSION: - sm_read_regs(ssm, REG_DEVICE_INFO, 16); + sm_read_regs(ssm, dev, REG_DEVICE_INFO, 16); break; case INIT_REPORT_VERSION: /* Likely hardware revision, and firmware version. @@ -1138,7 +1154,7 @@ static void init_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void activate_initsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index 97ba94dd..0ac931b5 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -85,10 +85,12 @@ static void sm_write_reg_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void sm_write_reg(fpi_ssm *ssm, unsigned char reg, - unsigned char value) +static void +sm_write_reg(fpi_ssm *ssm, + struct fp_img_dev *dev, + unsigned char reg, + unsigned char value) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; int r; @@ -124,10 +126,12 @@ static void sm_exec_cmd_cb(struct libusb_transfer *transfer) libusb_free_transfer(transfer); } -static void sm_exec_cmd(fpi_ssm *ssm, unsigned char cmd, - unsigned char param) +static void +sm_exec_cmd(fpi_ssm *ssm, + struct fp_img_dev *dev, + unsigned char cmd, + unsigned char param) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct libusb_transfer *transfer = libusb_alloc_transfer(0); unsigned char *data; int r; @@ -187,7 +191,7 @@ static gboolean finger_is_present(unsigned char *data) /***** IMAGE ACQUISITION *****/ -static void capture_iterate(fpi_ssm *ssm); +static void capture_iterate(fpi_ssm *ssm, struct fp_img_dev *dev); static void capture_cb(struct libusb_transfer *transfer) { @@ -211,16 +215,17 @@ static void capture_cb(struct libusb_transfer *transfer) fpi_imgdev_image_captured(dev, img); fpi_ssm_next_state(ssm); } else { - capture_iterate(ssm); + capture_iterate(ssm, dev); } out: libusb_free_transfer(transfer); } -static void capture_iterate(fpi_ssm *ssm) +static void +capture_iterate(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int iteration = vdev->capture_iteration; struct libusb_transfer *transfer = libusb_alloc_transfer(0); @@ -243,15 +248,16 @@ static void capture_iterate(fpi_ssm *ssm) } -static void sm_do_capture(fpi_ssm *ssm) +static void +sm_do_capture(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); vdev->capture_img = fpi_img_new_for_imgdev(dev); vdev->capture_iteration = 0; - capture_iterate(ssm); + capture_iterate(ssm, dev); } /***** CAPTURE LOOP *****/ @@ -267,25 +273,25 @@ enum loop_states { static void loop_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { case LOOP_SET_CONTRAST: - sm_write_reg(ssm, REG_CONTRAST, 0x01); + sm_write_reg(ssm, dev, REG_CONTRAST, 0x01); break; case LOOP_SET_GAIN: - sm_write_reg(ssm, REG_GAIN, 0x29); + sm_write_reg(ssm, dev, REG_GAIN, 0x29); break; case LOOP_CMD_SCAN: if (vdev->deactivating) { fp_dbg("deactivating, marking completed"); fpi_ssm_mark_completed(ssm); } else - sm_exec_cmd(ssm, CMD_SCAN, 0x00); + sm_exec_cmd(ssm, dev, CMD_SCAN, 0x00); break; case LOOP_CAPTURE: - sm_do_capture(ssm); + sm_do_capture(ssm, dev); break; case LOOP_CAPTURE_DONE: fpi_ssm_jump_to_state(ssm, LOOP_CMD_SCAN); @@ -295,7 +301,7 @@ static void loop_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r = fpi_ssm_get_error(ssm); diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index fdc50e5f..5a1bc43b 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -51,11 +51,14 @@ static void async_write_callback(struct libusb_transfer *transfer) } /* Send data to EP1, the only out endpoint */ -static void async_write(fpi_ssm *ssm, void *data, int len) +static void +async_write(fpi_ssm *ssm, + struct fp_img_dev *dev, + void *data, + int len) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); - struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(dev)); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); vdev->transfer = libusb_alloc_transfer(0); vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; @@ -93,7 +96,12 @@ static void async_read_callback(struct libusb_transfer *transfer) } /* Receive data from the given ep and compare with expected */ -static void async_read(fpi_ssm *ssm, int ep, void *data, int len) +static void +async_read(fpi_ssm *ssm, + struct fp_img_dev *dev, + int ep, + void *data, + int len) { struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); @@ -279,20 +287,21 @@ static void submit_image(struct fp_img_dev *idev) /* Proto functions */ /* SSM loop for clear_ep2 */ -static void clear_ep2_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) +static void +clear_ep2_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; short result; char command04 = 0x04; switch (fpi_ssm_get_cur_state(ssm)) { case SUBSM1_COMMAND_04: - async_write(ssm, &command04, sizeof(command04)); + async_write(ssm, idev, &command04, sizeof(command04)); break; case SUBSM1_RETURN_CODE: - async_read(ssm, 1, &result, sizeof(result)); + async_read(ssm, idev, 1, &result, sizeof(result)); break; case SUBSM1_ABORT_2: @@ -307,10 +316,10 @@ static void clear_ep2_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) } /* Send command to clear EP2 */ -static void clear_ep2(fpi_ssm *ssm) +static void +clear_ep2(fpi_ssm *ssm, + struct fp_img_dev *idev) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - fpi_ssm *subsm = fpi_ssm_new(FP_DEV(idev), clear_ep2_ssm, SUBSM1_STATES, idev); fpi_ssm_start_subsm(ssm, subsm); @@ -318,7 +327,7 @@ static void clear_ep2(fpi_ssm *ssm) static void send_control_packet_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); short result; @@ -326,11 +335,11 @@ static void send_control_packet_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *use switch (fpi_ssm_get_cur_state(ssm)) { case SUBSM2_SEND_CONTROL: - async_write(ssm, vdev->control_packet, VFS_CONTROL_PACKET_SIZE); + async_write(ssm, idev, vdev->control_packet, VFS_CONTROL_PACKET_SIZE); break; case SUBSM2_RETURN_CODE: - async_read(ssm, 1, &result, sizeof(result)); + async_read(ssm, idev, 1, &result, sizeof(result)); break; case SUBSM2_SEND_COMMIT: @@ -341,19 +350,19 @@ static void send_control_packet_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *use break; } /* commit_out in Windows differs in each commit, but I send the same each time */ - async_write(ssm, commit_out, sizeof(commit_out)); + async_write(ssm, idev, commit_out, sizeof(commit_out)); break; case SUBSM2_COMMIT_RESPONSE: commit_result = g_malloc(VFS_COMMIT_RESPONSE_SIZE); - async_read(ssm, 1, commit_result, VFS_COMMIT_RESPONSE_SIZE); + async_read(ssm, idev, 1, commit_result, VFS_COMMIT_RESPONSE_SIZE); break; case SUBSM2_READ_EMPTY_INTERRUPT: /* I don't know how to check result, it could be different */ g_free(commit_result); - async_read(ssm, 3, vdev->interrupt, VFS_INTERRUPT_SIZE); + async_read(ssm, idev, 3, vdev->interrupt, VFS_INTERRUPT_SIZE); break; case SUBSM2_ABORT_3: @@ -371,7 +380,7 @@ static void send_control_packet_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *use case SUBSM2_CLEAR_EP2: /* After turn_on Windows doesn't clear EP2 */ if (vdev->control_packet != turn_on) - clear_ep2(ssm); + clear_ep2(ssm, idev); else fpi_ssm_next_state(ssm); break; @@ -384,10 +393,10 @@ static void send_control_packet_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *use } /* Send device state control packet */ -static void send_control_packet(fpi_ssm *ssm) +static void +send_control_packet(fpi_ssm *ssm, + struct fp_img_dev *idev) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - fpi_ssm *subsm = fpi_ssm_new(FP_DEV(idev), send_control_packet_ssm, SUBSM2_STATES, idev); fpi_ssm_start_subsm(ssm, subsm); @@ -518,7 +527,7 @@ static void scan_completed(void *data) /* Main SSM loop */ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); @@ -536,14 +545,14 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) break; case SSM_CLEAR_EP2: - clear_ep2(ssm); + clear_ep2(ssm, idev); break; case SSM_TURN_OFF: /* Set control_packet argument */ vdev->control_packet = turn_off; - send_control_packet(ssm); + send_control_packet(ssm, idev); break; case SSM_TURN_ON: @@ -560,7 +569,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Set control_packet argument */ vdev->control_packet = turn_on; - send_control_packet(ssm); + send_control_packet(ssm, idev); break; case SSM_ASK_INTERRUPT: @@ -651,7 +660,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Set control_packet argument */ vdev->control_packet = next_receive_1; - send_control_packet(ssm); + send_control_packet(ssm, idev); break; case SSM_WAIT_ANOTHER_SCAN: @@ -671,7 +680,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Callback for dev_activate ssm */ static void dev_activate_callback(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *idev = user_data; struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); vdev->ssm_active = 0; @@ -713,7 +722,7 @@ static void dev_deactivate(struct fp_img_dev *idev) static void dev_open_callback(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* Notify open complete */ - fpi_imgdev_open_complete(fpi_ssm_get_user_data(ssm), 0); + fpi_imgdev_open_complete(user_data, 0); fpi_ssm_free(ssm); } diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 674855ea..86a2fa1f 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -242,9 +242,10 @@ out: } /* Submit asynchronous send */ -static void async_send(fpi_ssm *ssm) +static void +async_send(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -329,9 +330,10 @@ out: } /* Submit asynchronous recv */ -static void async_recv(fpi_ssm *ssm) +static void +async_recv(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; @@ -362,7 +364,7 @@ static void async_recv(fpi_ssm *ssm) } } -static void async_load(fpi_ssm *ssm); +static void async_load(fpi_ssm *ssm, struct fp_img_dev *dev); /* Callback of asynchronous load */ static void async_load_cb(struct libusb_transfer *transfer) @@ -411,7 +413,7 @@ static void async_load_cb(struct libusb_transfer *transfer) } else /* Image load not completed, submit another asynchronous load */ - async_load(ssm); + async_load(ssm, dev); } else { @@ -430,9 +432,10 @@ out: } /* Submit asynchronous load */ -static void async_load(fpi_ssm *ssm) +static void +async_load(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); unsigned char *buffer; int r; @@ -481,9 +484,11 @@ static void async_sleep_cb(void *data) } /* Submit asynchronous sleep */ -static void async_sleep(unsigned int msec, fpi_ssm *ssm) +static void +async_sleep(unsigned int msec, + fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Add timeout */ @@ -513,20 +518,23 @@ static void m_swap_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { case M_SWAP_SEND: /* Send data */ - async_send(ssm); + async_send(ssm, user_data); break; case M_SWAP_RECV: /* Recv response */ - async_recv(ssm); + async_recv(ssm, user_data); break; } } /* Start swap sequential state machine */ -static void m_swap(fpi_ssm *ssm, unsigned char *data, size_t length) +static void +m_swap(fpi_ssm *ssm, + struct fp_img_dev *dev, + unsigned char *data, + size_t length) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *subsm; @@ -541,7 +549,11 @@ static void m_swap(fpi_ssm *ssm, unsigned char *data, size_t length) } /* Retrieve fingerprint image */ -static void vfs_get_print(fpi_ssm *ssm, unsigned int param, int type) +static void +vfs_get_print(fpi_ssm *ssm, + struct fp_img_dev *dev, + unsigned int param, + int type) { unsigned char data[2][0x0e] = { { 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, @@ -557,11 +569,15 @@ static void vfs_get_print(fpi_ssm *ssm, unsigned int param, int type) data[type][7] = byte(1, param); /* Run swap sequential state machine */ - m_swap(ssm, data[type], 0x0e); + m_swap(ssm, dev, data[type], 0x0e); } /* Set a parameter value on the device */ -static void vfs_set_param(fpi_ssm *ssm, unsigned int param, unsigned int value) +static void +vfs_set_param(fpi_ssm *ssm, + struct fp_img_dev *dev, + unsigned int param, + unsigned int value) { unsigned char data[0x0a] = { 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -574,22 +590,29 @@ static void vfs_set_param(fpi_ssm *ssm, unsigned int param, unsigned int value) data[9] = byte(1, value); /* Run swap sequential state machine */ - m_swap(ssm, data, 0x0a); + m_swap(ssm, dev, data, 0x0a); } /* Abort previous print */ -static void vfs_abort_print(fpi_ssm *ssm) +static void +vfs_abort_print(fpi_ssm *ssm, + struct fp_img_dev *dev) { unsigned char data[0x06] = { 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00 }; G_DEBUG_HERE(); /* Run swap sequential state machine */ - m_swap (ssm, data, 0x06); + m_swap (ssm, dev, data, 0x06); } /* Poke a value on a region */ -static void vfs_poke(fpi_ssm *ssm, unsigned int addr, unsigned int value, unsigned int size) +static void +vfs_poke(fpi_ssm *ssm, + struct fp_img_dev *dev, + unsigned int addr, + unsigned int value, + unsigned int size) { unsigned char data[0x0f] = { 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -607,24 +630,27 @@ static void vfs_poke(fpi_ssm *ssm, unsigned int addr, unsigned int value, unsign data[14] = byte(0, size); /* Run swap sequential state machine */ - m_swap(ssm, data, 0x0f); + m_swap(ssm, dev, data, 0x0f); } /* Get current finger state */ -static void vfs_get_finger_state(fpi_ssm *ssm) +static void +vfs_get_finger_state(fpi_ssm *ssm, + struct fp_img_dev *dev) { unsigned char data[0x06] = { 0x00, 0x00, 0x00, 0x00, 0x16, 0x00 }; G_DEBUG_HERE(); /* Run swap sequential state machine */ - m_swap (ssm, data, 0x06); + m_swap (ssm, dev, data, 0x06); } /* Load raw image from reader */ -static void vfs_img_load(fpi_ssm *ssm) +static void +vfs_img_load(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); G_DEBUG_HERE(); @@ -637,7 +663,7 @@ static void vfs_img_load(fpi_ssm *ssm) vdev->height = -1; /* Asynchronous load */ - async_load(ssm); + async_load(ssm, dev); } /* Check if action is completed */ @@ -753,9 +779,10 @@ static void img_copy(struct vfs101_dev *vdev, struct fp_img *img) } /* Extract fingerpint image from raw data */ -static void img_extract(fpi_ssm *ssm) +static void +img_extract(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); struct fp_img *img; @@ -913,7 +940,7 @@ enum /* Exec loop sequential state machine */ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Check action state */ @@ -928,17 +955,17 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { case M_LOOP_0_GET_PRINT: /* Send get print command to the reader */ - vfs_get_print(ssm, VFS_BUFFER_HEIGHT, 1); + vfs_get_print(ssm, dev, VFS_BUFFER_HEIGHT, 1); break; case M_LOOP_0_SLEEP: /* Wait fingerprint scanning */ - async_sleep(50, ssm); + async_sleep(50, ssm, dev); break; case M_LOOP_0_GET_STATE: /* Get finger state */ - vfs_get_finger_state(ssm); + vfs_get_finger_state(ssm, dev); break; case M_LOOP_0_LOAD_IMAGE: @@ -953,7 +980,7 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case VFS_FINGER_PRESENT: /* Load image from reader */ vdev->ignore_error = TRUE; - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; default: @@ -969,10 +996,10 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Check if image is loaded */ if (vdev->height > 0) /* Fingerprint is loaded, extract image from raw data */ - img_extract(ssm); + img_extract(ssm, dev); /* Wait handling image */ - async_sleep(10, ssm); + async_sleep(10, ssm, dev); break; case M_LOOP_0_CHECK_ACTION: @@ -992,7 +1019,7 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_LOOP_1_GET_STATE: /* Get finger state */ - vfs_get_finger_state(ssm); + vfs_get_finger_state(ssm, dev); break; case M_LOOP_1_CHECK_STATE: @@ -1010,7 +1037,7 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Wait removing finger */ vdev->counter++; - async_sleep(250, ssm); + async_sleep(250, ssm, dev); } else { @@ -1048,13 +1075,13 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_LOOP_1_GET_PRINT: /* Send get print command to the reader */ - vfs_get_print(ssm, VFS_BUFFER_HEIGHT, 1); + vfs_get_print(ssm, dev, VFS_BUFFER_HEIGHT, 1); break; case M_LOOP_1_LOAD_IMAGE: /* Load image */ vdev->ignore_error = TRUE; - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; case M_LOOP_1_LOOP: @@ -1064,29 +1091,29 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_LOOP_1_SLEEP: /* Wait fingerprint scanning */ - async_sleep(10, ssm); + async_sleep(10, ssm, dev); break; case M_LOOP_2_ABORT_PRINT: /* Abort print command */ - vfs_abort_print(ssm); + vfs_abort_print(ssm, dev); break; case M_LOOP_2_LOAD_IMAGE: /* Load abort image */ vdev->ignore_error = TRUE; - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; case M_LOOP_3_GET_PRINT: /* Get empty image */ - vfs_get_print(ssm, 0x000a, 0); + vfs_get_print(ssm, dev, 0x000a, 0); break; case M_LOOP_3_LOAD_IMAGE: /* Load abort image */ vdev->ignore_error = TRUE; - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; case M_LOOP_3_CHECK_IMAGE: @@ -1100,7 +1127,7 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* Wait aborting */ vdev->counter++; - async_sleep(100, ssm); + async_sleep(100, ssm, dev); } else { @@ -1177,7 +1204,7 @@ enum /* Exec init sequential state machine */ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Check action state */ @@ -1193,29 +1220,29 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_INIT_0_RECV_DIRTY: /* Recv eventualy dirty data */ vdev->ignore_error = TRUE; - async_recv(ssm); + async_recv(ssm, dev); break; case M_INIT_0_ABORT_PRINT: /* Abort print command */ - vfs_abort_print(ssm); + vfs_abort_print(ssm, dev); break; case M_INIT_0_LOAD_IMAGE: /* Load abort image */ vdev->ignore_error = TRUE; - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; case M_INIT_1_GET_PRINT: /* Get empty image */ - vfs_get_print(ssm, 0x000a, 0); + vfs_get_print(ssm, dev, 0x000a, 0); break; case M_INIT_1_LOAD_IMAGE: /* Load abort image */ vdev->ignore_error = TRUE; - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; case M_INIT_1_CHECK_IMAGE: @@ -1229,7 +1256,7 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { /* Wait aborting */ vdev->counter++; - async_sleep(100, ssm); + async_sleep(100, ssm, dev); } else { @@ -1247,7 +1274,7 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_INIT_2_GET_STATE: /* Get finger state */ - vfs_get_finger_state(ssm); + vfs_get_finger_state(ssm, dev); break; case M_INIT_2_CHECK_STATE: @@ -1265,7 +1292,7 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Wait removing finger */ vdev->counter++; - async_sleep(250, ssm); + async_sleep(250, ssm, dev); } else { @@ -1292,13 +1319,13 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_INIT_2_GET_PRINT: /* Send get print command to the reader */ - vfs_get_print(ssm, VFS_BUFFER_HEIGHT, 1); + vfs_get_print(ssm, dev, VFS_BUFFER_HEIGHT, 1); break; case M_INIT_2_LOAD_IMAGE: /* Load unexpected image */ vdev->ignore_error = TRUE; - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; case M_INIT_2_LOOP: @@ -1308,68 +1335,68 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_INIT_3_SET_000E: /* Set param 0x000e, required for take image */ - vfs_set_param(ssm, VFS_PAR_000E, VFS_VAL_000E); + vfs_set_param(ssm, dev, VFS_PAR_000E, VFS_VAL_000E); break; case M_INIT_3_SET_0011: /* Set param 0x0011, required for take image */ - vfs_set_param(ssm, VFS_PAR_0011, VFS_VAL_0011); + vfs_set_param(ssm, dev, VFS_PAR_0011, VFS_VAL_0011); break; case M_INIT_3_SET_0076: /* Set param 0x0076, required for use info line */ - vfs_set_param(ssm, VFS_PAR_0076, VFS_VAL_0076); + vfs_set_param(ssm, dev, VFS_PAR_0076, VFS_VAL_0076); break; case M_INIT_3_SET_0078: /* Set param 0x0078, required for use info line */ - vfs_set_param(ssm, VFS_PAR_0078, VFS_VAL_0078); + vfs_set_param(ssm, dev, VFS_PAR_0078, VFS_VAL_0078); break; case M_INIT_3_SET_THRESHOLD: /* Set threshold */ - vfs_set_param(ssm, VFS_PAR_THRESHOLD, VFS_VAL_THRESHOLD); + vfs_set_param(ssm, dev, VFS_PAR_THRESHOLD, VFS_VAL_THRESHOLD); break; case M_INIT_3_SET_STATE3_COUNT: /* Set state 3 count */ - vfs_set_param(ssm, VFS_PAR_STATE_3, VFS_VAL_STATE_3); + vfs_set_param(ssm, dev, VFS_PAR_STATE_3, VFS_VAL_STATE_3); break; case M_INIT_3_SET_STATE5_COUNT: /* Set state 5 count */ - vfs_set_param(ssm, VFS_PAR_STATE_5, VFS_VAL_STATE_5); + vfs_set_param(ssm, dev, VFS_PAR_STATE_5, VFS_VAL_STATE_5); break; case M_INIT_3_SET_INFO_CONTRAST: /* Set info line contrast */ - vfs_set_param(ssm, VFS_PAR_INFO_CONTRAST, 10); + vfs_set_param(ssm, dev, VFS_PAR_INFO_CONTRAST, 10); break; case M_INIT_3_SET_INFO_RATE: /* Set info line rate */ - vfs_set_param(ssm, VFS_PAR_INFO_RATE, 32); + vfs_set_param(ssm, dev, VFS_PAR_INFO_RATE, 32); break; case M_INIT_4_SET_EXPOSURE: /* Set exposure level of reader */ - vfs_poke(ssm, VFS_REG_IMG_EXPOSURE, 0x4000, 0x02); + vfs_poke(ssm, dev, VFS_REG_IMG_EXPOSURE, 0x4000, 0x02); vdev->counter = 1; break; case M_INIT_4_SET_CONTRAST: /* Set contrast level of reader */ - vfs_poke(ssm, VFS_REG_IMG_CONTRAST, vdev->contrast, 0x01); + vfs_poke(ssm, dev, VFS_REG_IMG_CONTRAST, vdev->contrast, 0x01); break; case M_INIT_4_GET_PRINT: /* Get empty image */ - vfs_get_print(ssm, 0x000a, 0); + vfs_get_print(ssm, dev, 0x000a, 0); break; case M_INIT_4_LOAD_IMAGE: /* Load empty image */ - vfs_img_load(ssm); + vfs_img_load(ssm, dev); break; case M_INIT_4_CHECK_CONTRAST: @@ -1395,22 +1422,22 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_INIT_5_SET_EXPOSURE: /* Set exposure level of reader */ - vfs_poke(ssm, VFS_REG_IMG_EXPOSURE, VFS_VAL_IMG_EXPOSURE, 0x02); + vfs_poke(ssm, dev, VFS_REG_IMG_EXPOSURE, VFS_VAL_IMG_EXPOSURE, 0x02); break; case M_INIT_5_SET_CONTRAST: /* Set contrast level of reader */ - vfs_poke(ssm, VFS_REG_IMG_CONTRAST, vdev->contrast, 0x01); + vfs_poke(ssm, dev, VFS_REG_IMG_CONTRAST, vdev->contrast, 0x01); break; case M_INIT_5_SET_INFO_CONTRAST: /* Set info line contrast */ - vfs_set_param(ssm, VFS_PAR_INFO_CONTRAST, vdev->contrast); + vfs_set_param(ssm, dev, VFS_PAR_INFO_CONTRAST, vdev->contrast); break; case M_INIT_5_SET_INFO_RATE: /* Set info line rate */ - vfs_set_param(ssm, VFS_PAR_INFO_RATE, VFS_VAL_INFO_RATE); + vfs_set_param(ssm, dev, VFS_PAR_INFO_RATE, VFS_VAL_INFO_RATE); break; } } @@ -1418,7 +1445,7 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Complete init sequential state machine */ static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm_loop; diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 72f8f53b..a8085b4a 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -35,9 +35,11 @@ static void async_sleep_cb(void *data) } /* Submit asynchronous sleep */ -static void async_sleep(unsigned int msec, fpi_ssm *ssm) +static void +async_sleep(unsigned int msec, + fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); fpi_timeout *timeout; /* Add timeout */ @@ -51,9 +53,10 @@ static void async_sleep(unsigned int msec, fpi_ssm *ssm) } } -static int submit_image(fpi_ssm *ssm) +static int +submit_image(fpi_ssm *ssm, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int height; struct fp_img *img; @@ -105,7 +108,7 @@ enum /* Exec loop sequential state machine */ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); switch (fpi_ssm_get_cur_state(ssm)) { @@ -116,7 +119,7 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_WAIT_PRINT: /* Wait fingerprint scanning */ - async_sleep(200, ssm); + async_sleep(200, ssm, dev); break; case M_CHECK_PRINT: @@ -134,7 +137,7 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case M_READ_PRINT_WAIT: /* Wait fingerprint scanning */ - async_sleep(200, ssm); + async_sleep(200, ssm, dev); break; case M_READ_PRINT_POLL: @@ -149,7 +152,7 @@ static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) break; case M_SUBMIT_PRINT: - if (submit_image(ssm)) { + if (submit_image(ssm, dev)) { fpi_ssm_mark_completed(ssm); /* NOTE: finger off is expected only after submitting image... */ fpi_imgdev_report_finger_status(dev, FALSE); @@ -170,7 +173,7 @@ static void m_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Exec init sequential state machine */ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); g_assert(fpi_ssm_get_cur_state(ssm) == 0); @@ -183,7 +186,7 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Complete init sequential state machine */ static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; fpi_ssm *ssm_loop; if (!fpi_ssm_get_error(ssm)) { diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 10a15cc1..ba57b410 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -173,7 +173,7 @@ out: static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct usbexchange_data *data = fpi_ssm_get_user_data(ssm); + 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); @@ -395,9 +395,11 @@ static int process_chunk(struct vfs5011_data *data, int transferred) return 0; } -void submit_image(fpi_ssm *ssm, struct vfs5011_data *data) +static void +submit_image(fpi_ssm *ssm, + struct vfs5011_data *data, + struct fp_img_dev *dev) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); struct fp_img *img; if (data->lines_recorded == 0) { @@ -669,7 +671,7 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { enum {READ_TIMEOUT = 0}; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct vfs5011_data *data; int r; fpi_timeout *timeout; @@ -744,7 +746,7 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void activate_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct vfs5011_data *data; int r = fpi_ssm_get_error(ssm); @@ -755,7 +757,7 @@ static void activate_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user g_free(data->init_sequence.receive_buf); data->init_sequence.receive_buf = NULL; if (!data->deactivating && !r) { - submit_image(ssm, data); + submit_image(ssm, data, dev); fpi_imgdev_report_finger_status(dev, FALSE); } fpi_ssm_free(ssm); @@ -774,7 +776,7 @@ static void activate_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user static void open_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct vfs5011_data *data; data = FP_INSTANCE_DATA(FP_DEV(dev)); @@ -795,7 +797,7 @@ static void open_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void open_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); + struct fp_img_dev *dev = user_data; struct vfs5011_data *data; data = FP_INSTANCE_DATA(FP_DEV(dev)); From 0c3a22758b8c86d756df2707fbb215c9f8dc78d8 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 18 Sep 2018 17:57:32 +0200 Subject: [PATCH 067/225] drivers: Simplify FP_INSTANCE_DATA(FP_DEV()) calls When fp_dev is already available, don't use the fp_img_dev struct to get to fp_dev with FP_DEV(), use the fp_dev directly. --- libfprint/drivers/aes1610.c | 4 ++-- libfprint/drivers/aes2501.c | 4 ++-- libfprint/drivers/aes2550.c | 2 +- libfprint/drivers/aesx660.c | 7 +++---- libfprint/drivers/elan.c | 10 +++++----- libfprint/drivers/etes603.c | 22 +++++++++++----------- libfprint/drivers/upeksonly.c | 20 +++++++++----------- libfprint/drivers/upektc.c | 6 +++--- libfprint/drivers/upektc_img.c | 10 +++++----- libfprint/drivers/uru4000.c | 10 +++++----- libfprint/drivers/vcom5s.c | 4 ++-- libfprint/drivers/vfs0050.c | 7 +++---- libfprint/drivers/vfs101.c | 6 +++--- libfprint/drivers/vfs301.c | 4 ++-- libfprint/drivers/vfs5011.c | 8 ++++---- 15 files changed, 60 insertions(+), 64 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index 17f9f065..5aa14c36 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -644,7 +644,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(_dev); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -691,7 +691,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aes1610_dev *aesdev = FP_INSTANCE_DATA(_dev); G_DEBUG_HERE(); if (aesdev->deactivating) diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index f91682bb..fa72e236 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -522,7 +522,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -573,7 +573,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev); G_DEBUG_HERE(); if (aesdev->deactivating) diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 34533b56..5a26012b 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -388,7 +388,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aes2550_dev *aesdev = FP_INSTANCE_DATA(_dev); fp_dbg("Capture completed"); if (aesdev->deactivating) diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index 650dc841..d4c26623 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -210,7 +210,7 @@ static void finger_det_set_idle_cmd_cb(struct libusb_transfer *transfer) static void finger_det_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(_dev); int err = fpi_ssm_get_error(ssm); fp_dbg("Finger detection completed"); @@ -383,8 +383,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = user_data; - struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_SEND_LED_CMD: @@ -413,7 +412,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct aesX660_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct aesX660_dev *aesdev = FP_INSTANCE_DATA(_dev); int err = fpi_ssm_get_error(ssm); fp_dbg("Capture completed"); diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 330f625f..2e002593 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -455,7 +455,7 @@ static void stop_capture_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_ static void stop_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct elan_dev *elandev = FP_INSTANCE_DATA(_dev); int error = fpi_ssm_get_error(ssm); G_DEBUG_HERE(); @@ -503,7 +503,7 @@ enum capture_states { static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct elan_dev *elandev = FP_INSTANCE_DATA(_dev); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -541,7 +541,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct elan_dev *elandev = FP_INSTANCE_DATA(_dev); G_DEBUG_HERE(); @@ -626,7 +626,7 @@ enum calibrate_states { static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct elan_dev *elandev = FP_INSTANCE_DATA(_dev); G_DEBUG_HERE(); @@ -727,7 +727,7 @@ enum activate_states { static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct elan_dev *elandev = FP_INSTANCE_DATA(_dev); G_DEBUG_HERE(); diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index 06dea505..2701cb01 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -702,7 +702,7 @@ static void async_tx_cb(struct libusb_transfer *transfer) static void m_exit_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case EXIT_SET_REGS_REQ: @@ -751,7 +751,7 @@ static void m_exit_start(struct fp_img_dev *idev) static void m_capture_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -832,7 +832,7 @@ err: static void m_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); if (fpi_ssm_get_error(ssm)) { if (fpi_imgdev_get_action_state(idev) != IMG_ACQUIRE_STATE_DEACTIVATING) { @@ -854,7 +854,7 @@ static void m_capture_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat static void m_finger_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -950,7 +950,7 @@ err: static void m_finger_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); if (!fpi_ssm_get_error(ssm)) { fpi_ssm *ssm_cap; @@ -982,7 +982,7 @@ static void m_start_fingerdetect(struct fp_img_dev *idev) static void m_tunevrb_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); float hist[5]; if (dev->is_active == FALSE) { @@ -1140,7 +1140,7 @@ static void m_tunevrb_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat fp_dbg("Tuning is done. Starting finger detection."); m_start_fingerdetect(idev); } else { - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); fp_err("Error while tuning VRT"); dev->is_active = FALSE; reset_param(dev); @@ -1156,7 +1156,7 @@ static void m_tunevrb_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat static void m_tunedc_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -1265,7 +1265,7 @@ static void m_tunedc_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data TUNEVRB_NUM_STATES, idev); fpi_ssm_start(ssm_tune, m_tunevrb_complete); } else { - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); fp_err("Error while tuning DCOFFSET"); dev->is_active = FALSE; reset_param(dev); @@ -1277,7 +1277,7 @@ static void m_tunedc_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); if (dev->is_active == FALSE) { fpi_ssm_mark_completed(ssm); @@ -1384,7 +1384,7 @@ static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) TUNEDC_NUM_STATES, idev); fpi_ssm_start(ssm_tune, m_tunedc_complete); } else { - struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct etes603_dev *dev = FP_INSTANCE_DATA(_dev); fp_err("Error initializing the device"); dev->is_active = FALSE; reset_param(dev); diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index cc5588ca..8e9cc2f6 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -773,7 +773,7 @@ enum awfsm_1000_states { static void awfsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case AWFSM_2016_WRITEV_1: @@ -863,7 +863,7 @@ capsm_fire_bulk(fpi_ssm *ssm, struct fp_dev *_dev) { struct fp_img_dev *dev = FP_IMG_DEV(_dev); - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); int i; for (i = 0; i < NUM_BULK_TRANSFERS; i++) { int r = libusb_submit_transfer(sdev->img_transfer[i]); @@ -893,7 +893,7 @@ capsm_fire_bulk(fpi_ssm *ssm, static void capsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case CAPSM_2016_INIT: @@ -924,8 +924,7 @@ static void capsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d static void capsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case CAPSM_1000_INIT: @@ -950,8 +949,7 @@ static void capsm_1000_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d static void capsm_1001_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case CAPSM_1001_INIT: @@ -1060,7 +1058,7 @@ enum initsm_1001_states { static void initsm_2016_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case INITSM_2016_WRITEV_1: @@ -1132,7 +1130,7 @@ enum loopsm_states { static void loopsm_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case LOOPSM_RUN_AWFSM: ; @@ -1257,7 +1255,7 @@ static void dev_deactivate(struct fp_img_dev *dev) static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); @@ -1276,7 +1274,7 @@ static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void initsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct sonly_dev *sdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct sonly_dev *sdev = FP_INSTANCE_DATA(_dev); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index 43facc20..38a17a49 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -103,7 +103,7 @@ static void read_init_data_cb(struct libusb_transfer *transfer) static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(_dev); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -326,7 +326,7 @@ out: static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(_dev); int r; switch (fpi_ssm_get_cur_state(ssm)) { @@ -375,7 +375,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct upektc_dev *upekdev = FP_INSTANCE_DATA(_dev); fp_dbg("Capture completed"); if (upekdev->deactivating) diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 6fd62dd4..9ca25cb4 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -314,7 +314,7 @@ static void capture_read_data_cb(struct libusb_transfer *transfer) static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_INIT_CAPTURE: @@ -351,7 +351,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev); int err = fpi_ssm_get_error(ssm); fp_dbg("Capture completed, %d", err); @@ -411,7 +411,7 @@ static void deactivate_read_data_cb(struct libusb_transfer *transfer) static void deactivate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case DEACTIVATE_DEINIT: @@ -428,7 +428,7 @@ 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) { struct fp_img_dev *dev = user_data; - struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev); int err = fpi_ssm_get_error(ssm); fp_dbg("Deactivate completed"); @@ -509,7 +509,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data { struct libusb_transfer *transfer; struct fp_img_dev *idev = user_data; - struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(dev); int r; switch (fpi_ssm_get_cur_state(ssm)) { diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index c26235bb..b2e80e89 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -706,7 +706,7 @@ static int calc_dev2(struct uru4k_image *img) static void imaging_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(_dev); struct uru4k_image *img = urudev->img_data; struct fp_img *fpimg; uint32_t key; @@ -829,7 +829,7 @@ static void imaging_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data static void imaging_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(_dev); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); @@ -893,7 +893,7 @@ static void rebootpwr_pause_cb(void *data) static void rebootpwr_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case REBOOTPWR_SET_HWSTAT: @@ -972,7 +972,7 @@ static void powerup_pause_cb(void *data) static void powerup_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case POWERUP_INIT: @@ -1077,7 +1077,7 @@ static void init_scanpwr_timeout(void *user_data) static void init_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case INIT_GET_HWSTAT: diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index 0ac931b5..64aa64e8 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -274,7 +274,7 @@ enum loop_states { static void loop_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct v5s_dev *vdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case LOOP_SET_CONTRAST: @@ -302,7 +302,7 @@ static void loop_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct v5s_dev *vdev = FP_INSTANCE_DATA(_dev); int r = fpi_ssm_get_error(ssm); fpi_ssm_free(ssm); diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 5a1bc43b..e805cccd 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -328,7 +328,7 @@ clear_ep2(fpi_ssm *ssm, static void send_control_packet_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; - struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(_dev); short result; unsigned char *commit_result = NULL; @@ -529,7 +529,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *idev = user_data; struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(idev)); - struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case SSM_INITIAL_ABORT_1: @@ -680,8 +680,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) /* Callback for dev_activate ssm */ static void dev_activate_callback(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { - struct fp_img_dev *idev = user_data; - struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(_dev); vdev->ssm_active = 0; diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 86a2fa1f..1d39d339 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -941,7 +941,7 @@ enum static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(_dev); /* Check action state */ if (!vdev->active) @@ -1205,7 +1205,7 @@ enum static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(_dev); /* Check action state */ if (!vdev->active) @@ -1446,7 +1446,7 @@ static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(_dev); fpi_ssm *ssm_loop; if (!fpi_ssm_get_error(ssm) && vdev->active) diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index a8085b4a..5f469c33 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -109,7 +109,7 @@ enum static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + vfs301_dev_t *vdev = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case M_REQUEST_PRINT: @@ -174,7 +174,7 @@ static void m_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { struct fp_img_dev *dev = user_data; - vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + vfs301_dev_t *vdev = FP_INSTANCE_DATA(_dev); g_assert(fpi_ssm_get_cur_state(ssm) == 0); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index ba57b410..ea183a88 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -676,7 +676,7 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) int r; fpi_timeout *timeout; - data = FP_INSTANCE_DATA(FP_DEV(dev)); + data = FP_INSTANCE_DATA(_dev); fp_dbg("main_loop: state %d", fpi_ssm_get_cur_state(ssm)); @@ -750,7 +750,7 @@ static void activate_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user struct vfs5011_data *data; int r = fpi_ssm_get_error(ssm); - data = FP_INSTANCE_DATA(FP_DEV(dev)); + data = FP_INSTANCE_DATA(_dev); fp_dbg("finishing"); if (data->init_sequence.receive_buf != NULL) @@ -779,7 +779,7 @@ static void open_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) struct fp_img_dev *dev = user_data; struct vfs5011_data *data; - data = FP_INSTANCE_DATA(FP_DEV(dev)); + data = FP_INSTANCE_DATA(_dev); switch (fpi_ssm_get_cur_state(ssm)) { case DEV_OPEN_START: @@ -800,7 +800,7 @@ static void open_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat struct fp_img_dev *dev = user_data; struct vfs5011_data *data; - data = FP_INSTANCE_DATA(FP_DEV(dev)); + data = FP_INSTANCE_DATA(_dev); g_free(data->init_sequence.receive_buf); data->init_sequence.receive_buf = NULL; From f68e7fcb9fe493e1ae5a51bdd54d32dd3f113268 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 18 Sep 2018 18:51:14 +0200 Subject: [PATCH 068/225] lib: Add fp_dev argument to timeout callback To cut down on the fpi_ssm_get_user_data() usage again. --- libfprint/drivers/elan.c | 14 +++++++++----- libfprint/drivers/uru4000.c | 28 ++++++++++++++++------------ libfprint/drivers/vfs0050.c | 21 +++++++++++++-------- libfprint/drivers/vfs101.c | 9 +++++---- libfprint/drivers/vfs301.c | 6 ++++-- libfprint/drivers/vfs5011.c | 6 ++++-- libfprint/fpi-poll.c | 15 +++++++++++---- libfprint/fpi-poll.h | 11 ++++++++--- 8 files changed, 70 insertions(+), 40 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 2e002593..699f4cfb 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -583,7 +583,9 @@ static void elan_capture(struct fp_img_dev *dev) fpi_ssm_start(ssm, capture_complete); } -static void fpi_ssm_next_state_async(void *data) +static void +fpi_ssm_next_state_async(struct fp_dev *dev, + void *data) { fpi_ssm_next_state((fpi_ssm *)data); } @@ -678,7 +680,7 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da if (elandev->calib_status == 0x00 && elandev->last_read[0] == 0x01) elandev->calib_status = 0x01; - if (!fpi_timeout_add(50, fpi_ssm_next_state_async, ssm)) + if (!fpi_timeout_add(50, fpi_ssm_next_state_async, _dev, ssm)) fpi_ssm_mark_failed(ssm, -ETIME); } break; @@ -884,9 +886,11 @@ static void elan_change_state(struct fp_img_dev *dev) elandev->dev_state = next_state; } -static void elan_change_state_async(void *data) +static void +elan_change_state_async(struct fp_dev *dev, + void *data) { - elan_change_state((struct fp_img_dev *)data); + elan_change_state(FP_IMG_DEV (dev)); } static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) @@ -902,7 +906,7 @@ static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) /* schedule state change instead of calling it directly to allow all actions * related to the previous state to complete */ elandev->dev_state_next = state; - if (!fpi_timeout_add(10, elan_change_state_async, dev)) { + if (!fpi_timeout_add(10, elan_change_state_async, FP_DEV(dev), NULL)) { fpi_imgdev_session_error(dev, -ETIME); return -ETIME; } diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index b2e80e89..58455c09 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -876,11 +876,12 @@ enum rebootpwr_states { REBOOTPWR_NUM_STATES, }; -static void rebootpwr_pause_cb(void *data) +static void +rebootpwr_pause_cb(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(dev); if (!--urudev->rebootpwr_ctr) { fp_err("could not reboot device power"); @@ -911,7 +912,7 @@ static void rebootpwr_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da fpi_ssm_next_state(ssm); break; case REBOOTPWR_PAUSE: - if (fpi_timeout_add(10, rebootpwr_pause_cb, ssm) == NULL) + if (fpi_timeout_add(10, rebootpwr_pause_cb, _dev, ssm) == NULL) fpi_ssm_mark_failed(ssm, -ETIME); break; } @@ -953,11 +954,12 @@ enum powerup_states { POWERUP_NUM_STATES, }; -static void powerup_pause_cb(void *data) +static void +powerup_pause_cb(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(dev); if (!--urudev->powerup_ctr) { fp_err("could not power device up"); @@ -994,7 +996,7 @@ static void powerup_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data fpi_ssm_next_state(ssm); break; case POWERUP_PAUSE: - if (fpi_timeout_add(10, powerup_pause_cb, ssm) == NULL) + if (fpi_timeout_add(10, powerup_pause_cb, _dev, ssm) == NULL) fpi_ssm_mark_failed(ssm, -ETIME); break; case POWERUP_CHALLENGE_RESPONSE: @@ -1056,11 +1058,12 @@ static void init_scanpwr_irq_cb(struct fp_img_dev *dev, int status, } } -static void init_scanpwr_timeout(void *user_data) +static void +init_scanpwr_timeout(struct fp_dev *dev, + void *user_data) { fpi_ssm *ssm = user_data; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(dev); fp_warn("powerup timed out"); urudev->irq_cb = NULL; @@ -1123,7 +1126,8 @@ static void init_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) * so we include this timeout loop to retry the whole process 3 times * if we don't get an irq any time soon. */ urudev->scanpwr_irq_timeout = fpi_timeout_add(300, - init_scanpwr_timeout, ssm); + init_scanpwr_timeout, + _dev, ssm); if (!urudev->scanpwr_irq_timeout) { fpi_ssm_mark_failed(ssm, -ETIME); break; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index e805cccd..c3e17bc6 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -499,11 +499,12 @@ static void receive_callback(struct libusb_transfer *transfer) } /* Stub to keep SSM alive when waiting an interrupt */ -static void wait_interrupt(void *data) +static void +wait_interrupt(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; - struct fp_img_dev *idev = fpi_ssm_get_user_data(ssm); - struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(idev)); + struct vfs_dev_t *vdev = FP_INSTANCE_DATA(dev); /* Keep sleeping while this flag is on */ if (vdev->wait_interrupt) @@ -511,14 +512,18 @@ static void wait_interrupt(void *data) } /* SSM stub to prepare device to another scan after orange light was on */ -static void another_scan(void *data) +static void +another_scan(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; fpi_ssm_jump_to_state(ssm, SSM_TURN_ON); } /* Another SSM stub to continue after waiting for probable vdev->active changes */ -static void scan_completed(void *data) +static void +scan_completed(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; fpi_ssm_next_state(ssm); @@ -608,7 +613,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) } if (vdev->wait_interrupt) - fpi_timeout_add(VFS_SSM_TIMEOUT, wait_interrupt, ssm); + fpi_timeout_add(VFS_SSM_TIMEOUT, wait_interrupt, _dev, ssm); break; case SSM_RECEIVE_FINGER: @@ -647,7 +652,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) clear_data(vdev); /* Wait for probable vdev->active changing */ - fpi_timeout_add(VFS_SSM_TIMEOUT, scan_completed, ssm); + fpi_timeout_add(VFS_SSM_TIMEOUT, scan_completed, _dev, ssm); break; case SSM_NEXT_RECEIVE: @@ -665,7 +670,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case SSM_WAIT_ANOTHER_SCAN: /* Orange light is on now */ - fpi_timeout_add(VFS_SSM_ORANGE_TIMEOUT, another_scan, ssm); + fpi_timeout_add(VFS_SSM_ORANGE_TIMEOUT, another_scan, _dev, ssm); break; default: diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 1d39d339..6f7d7f0d 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -471,11 +471,12 @@ async_load(fpi_ssm *ssm, } /* Callback of asynchronous sleep */ -static void async_sleep_cb(void *data) +static void +async_sleep_cb(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct vfs101_dev *vdev = FP_INSTANCE_DATA(dev); /* Cleanup timeout */ vdev->timeout = NULL; @@ -492,7 +493,7 @@ async_sleep(unsigned int msec, struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); /* Add timeout */ - vdev->timeout = fpi_timeout_add(msec, async_sleep_cb, ssm); + vdev->timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm); if (vdev->timeout == NULL) { diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 5f469c33..a7854f46 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -27,7 +27,9 @@ /************************** GENERIC STUFF *************************************/ /* Callback of asynchronous sleep */ -static void async_sleep_cb(void *data) +static void +async_sleep_cb(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; @@ -43,7 +45,7 @@ async_sleep(unsigned int msec, fpi_timeout *timeout; /* Add timeout */ - timeout = fpi_timeout_add(msec, async_sleep_cb, ssm); + timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm); if (timeout == NULL) { /* Failed to add timeout */ diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index ea183a88..11766dc6 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -472,7 +472,9 @@ static int capture_chunk_async(struct vfs5011_data *data, return libusb_submit_transfer(data->flying_transfer); } -static void async_sleep_cb(void *data) +static void +async_sleep_cb(struct fp_dev *dev, + void *data) { fpi_ssm *ssm = data; @@ -719,7 +721,7 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) break; case DEV_ACTIVATE_DATA_COMPLETE: - timeout = fpi_timeout_add(1, async_sleep_cb, ssm); + timeout = fpi_timeout_add(1, async_sleep_cb, _dev, ssm); if (timeout == NULL) { /* Failed to add timeout */ diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 5c6fc960..ee7d86d5 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -84,6 +84,7 @@ static fp_pollfd_removed_cb fd_removed_cb = NULL; struct fpi_timeout { struct timeval expiry; fpi_timeout_fn callback; + struct fp_dev *dev; void *data; }; @@ -106,7 +107,8 @@ static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) * fpi_timeout_add: * @msec: the time before calling the function, in milliseconds (1/1000ths of a second) * @callback: function to callback - * @data: data to pass to @callback + * @dev: a struct #fp_dev + * @data: data to pass to @callback, or %NULL * * A timeout is the asynchronous equivalent of sleeping. You create a timeout * saying that you'd like to have a function invoked at a certain time in @@ -118,14 +120,18 @@ static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) * * Returns: an #fpi_timeout structure */ -fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, - void *data) +fpi_timeout *fpi_timeout_add(unsigned int msec, + fpi_timeout_fn callback, + struct fp_dev *dev, + void *data) { struct timespec ts; struct timeval add_msec; fpi_timeout *timeout; int r; + g_return_val_if_fail (dev != NULL, NULL); + fp_dbg("in %dms", msec); r = clock_gettime(CLOCK_MONOTONIC, &ts); @@ -136,6 +142,7 @@ fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, timeout = g_malloc(sizeof(*timeout)); timeout->callback = callback; + timeout->dev = dev; timeout->data = data; TIMESPEC_TO_TIMEVAL(&timeout->expiry, &ts); @@ -207,7 +214,7 @@ static int get_next_timeout_expiry(struct timeval *out, static void handle_timeout(struct fpi_timeout *timeout) { G_DEBUG_HERE(); - timeout->callback(timeout->data); + timeout->callback(timeout->dev, timeout->data); active_timers = g_slist_remove(active_timers, timeout); g_free(timeout); } diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 34c25204..8077eb04 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -18,13 +18,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "fprint.h" + /** * fpi_timeout_fn: + * @dev: the struct #fp_dev passed to fpi_timeout_add() * @data: the data passed to fpi_timeout_add() * * The prototype of the callback function for fpi_timeout_add(). */ -typedef void (*fpi_timeout_fn)(void *data); +typedef void (*fpi_timeout_fn)(struct fp_dev *dev, void *data); /** * fpi_timeout: @@ -33,6 +36,8 @@ typedef void (*fpi_timeout_fn)(void *data); * fpi_timeout_add(). */ typedef struct fpi_timeout fpi_timeout; -fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, - void *data); +fpi_timeout *fpi_timeout_add(unsigned int msec, + fpi_timeout_fn callback, + struct fp_dev *dev, + void *data); void fpi_timeout_cancel(fpi_timeout *timeout); From ac48d662038b06e7831ec72717d5f22d2c388e5e Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 18 Sep 2018 20:02:14 +0200 Subject: [PATCH 069/225] lib: Mention that fpi_timeout gets freed --- libfprint/fpi-poll.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 8077eb04..3eb316cb 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -26,6 +26,8 @@ * @data: the data passed to fpi_timeout_add() * * The prototype of the callback function for fpi_timeout_add(). + * Note that after the callback is called, the #fpi_timeout structure will + * be freed. */ typedef void (*fpi_timeout_fn)(struct fp_dev *dev, void *data); From f2bc826a207e3889550aa12011cf40435a9cc38c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 19 Sep 2018 15:16:40 +0200 Subject: [PATCH 070/225] lib: Move aeslib.[ch] to the drivers directory As it's used by drivers, and isn't a set of generic helpers. --- libfprint/{ => drivers}/aeslib.c | 0 libfprint/{ => drivers}/aeslib.h | 0 libfprint/meson.build | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename libfprint/{ => drivers}/aeslib.c (100%) rename libfprint/{ => drivers}/aeslib.h (100%) diff --git a/libfprint/aeslib.c b/libfprint/drivers/aeslib.c similarity index 100% rename from libfprint/aeslib.c rename to libfprint/drivers/aeslib.c diff --git a/libfprint/aeslib.h b/libfprint/drivers/aeslib.h similarity index 100% rename from libfprint/aeslib.h rename to libfprint/drivers/aeslib.h diff --git a/libfprint/meson.build b/libfprint/meson.build index c593dae9..b0db4548 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -141,7 +141,7 @@ foreach driver: drivers endforeach if aeslib - drivers_sources += [ 'aeslib.c', 'aeslib.h' ] + drivers_sources += [ 'drivers/aeslib.c', 'drivers/aeslib.h' ] endif if aesx660 drivers_sources += ['drivers/aesx660.c', 'drivers/aesx660.h' ] From 50166e88c0ddd6b02f2edb426f8566af80052437 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 19 Sep 2018 15:46:29 +0200 Subject: [PATCH 071/225] lib: Add fpi_ssm_next_state_timeout_cb() helper To be used in 5 drivers. --- doc/libfprint-sections.txt | 1 + libfprint/drivers/elan.c | 9 +-------- libfprint/drivers/vfs0050.c | 11 +---------- libfprint/drivers/vfs101.c | 26 ++------------------------ libfprint/drivers/vfs301.c | 16 +--------------- libfprint/drivers/vfs5011.c | 11 +---------- libfprint/fpi-ssm.c | 22 ++++++++++++++++++++++ libfprint/fpi-ssm.h | 1 + 8 files changed, 30 insertions(+), 67 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index e0d96b22..aeaef131 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -165,6 +165,7 @@ fpi_ssm_start fpi_ssm_start_subsm fpi_ssm_next_state +fpi_ssm_next_state_timeout_cb fpi_ssm_jump_to_state fpi_ssm_mark_completed fpi_ssm_mark_failed diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 699f4cfb..8f48bdab 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -583,13 +583,6 @@ static void elan_capture(struct fp_img_dev *dev) fpi_ssm_start(ssm, capture_complete); } -static void -fpi_ssm_next_state_async(struct fp_dev *dev, - void *data) -{ - fpi_ssm_next_state((fpi_ssm *)data); -} - /* this function needs to have elandev->background and elandev->last_read to be * the calibration mean */ static int elan_need_calibration(struct elan_dev *elandev) @@ -680,7 +673,7 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da if (elandev->calib_status == 0x00 && elandev->last_read[0] == 0x01) elandev->calib_status = 0x01; - if (!fpi_timeout_add(50, fpi_ssm_next_state_async, _dev, ssm)) + if (!fpi_timeout_add(50, fpi_ssm_next_state_timeout_cb, _dev, ssm)) fpi_ssm_mark_failed(ssm, -ETIME); } break; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index c3e17bc6..1d8d7a17 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -520,15 +520,6 @@ another_scan(struct fp_dev *dev, fpi_ssm_jump_to_state(ssm, SSM_TURN_ON); } -/* Another SSM stub to continue after waiting for probable vdev->active changes */ -static void -scan_completed(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - fpi_ssm_next_state(ssm); -} - /* Main SSM loop */ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { @@ -652,7 +643,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) clear_data(vdev); /* Wait for probable vdev->active changing */ - fpi_timeout_add(VFS_SSM_TIMEOUT, scan_completed, _dev, ssm); + fpi_timeout_add(VFS_SSM_TIMEOUT, fpi_ssm_next_state_timeout_cb, _dev, ssm); break; case SSM_NEXT_RECEIVE: diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 6f7d7f0d..e4400f82 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -105,9 +105,6 @@ struct vfs101_dev /* Ignore usb error */ int ignore_error; - /* Timeout */ - fpi_timeout *timeout; - /* Loop counter */ int counter; @@ -470,32 +467,13 @@ async_load(fpi_ssm *ssm, } } -/* Callback of asynchronous sleep */ -static void -async_sleep_cb(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - struct vfs101_dev *vdev = FP_INSTANCE_DATA(dev); - - /* Cleanup timeout */ - vdev->timeout = NULL; - - fpi_ssm_next_state(ssm); -} - /* Submit asynchronous sleep */ static void async_sleep(unsigned int msec, fpi_ssm *ssm, struct fp_img_dev *dev) { - struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); - - /* Add timeout */ - vdev->timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm); - - if (vdev->timeout == NULL) + if (fpi_timeout_add(msec, fpi_ssm_next_state_timeout_cb, FP_DEV(dev), ssm) == NULL) { /* Failed to add timeout */ fp_err("failed to add timeout"); @@ -1505,7 +1483,7 @@ static void dev_deactivate(struct fp_img_dev *dev) vdev->active = FALSE; /* Handle eventualy existing events */ - while (vdev->transfer || vdev->timeout) + while (vdev->transfer) fp_handle_events(); /* Notify deactivate complete */ diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index a7854f46..815c0ab0 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -26,28 +26,14 @@ /************************** GENERIC STUFF *************************************/ -/* Callback of asynchronous sleep */ -static void -async_sleep_cb(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - - fpi_ssm_next_state(ssm); -} - /* Submit asynchronous sleep */ static void async_sleep(unsigned int msec, fpi_ssm *ssm, struct fp_img_dev *dev) { - fpi_timeout *timeout; - /* Add timeout */ - timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm); - - if (timeout == NULL) { + if (fpi_timeout_add(msec, fpi_ssm_next_state_timeout_cb, FP_DEV(dev), ssm) == NULL) { /* Failed to add timeout */ fp_err("failed to add timeout"); fpi_imgdev_session_error(dev, -ETIME); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 11766dc6..24e48689 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -472,15 +472,6 @@ static int capture_chunk_async(struct vfs5011_data *data, return libusb_submit_transfer(data->flying_transfer); } -static void -async_sleep_cb(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - - fpi_ssm_next_state(ssm); -} - /* * Device initialization. Windows driver only does it when the device is * plugged in, but it doesn't harm to do this every time before scanning the @@ -721,7 +712,7 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) break; case DEV_ACTIVATE_DATA_COMPLETE: - timeout = fpi_timeout_add(1, async_sleep_cb, _dev, ssm); + timeout = fpi_timeout_add(1, fpi_ssm_next_state_timeout_cb, _dev, ssm); if (timeout == NULL) { /* Failed to add timeout */ diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 2c7df5bf..a7b2e8b4 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -249,6 +249,28 @@ void fpi_ssm_next_state(fpi_ssm *machine) } } +/** + * fpi_ssm_next_state_timeout_cb: + * @dev: a struct #fp_dev + * @data: a pointer to an #fpi_ssm state machine + * + * Same as fpi_ssm_next_state(), but to be used as a callback + * for an fpi_timeout_add() callback, when the state change needs + * to happen after a timeout. + * + * Make sure to pass the #fpi_ssm as the `user_data` argument + * for that fpi_timeout_add() call. + */ +void +fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, + void *data) +{ + g_return_if_fail (dev != NULL); + g_return_if_fail (data != NULL); + + fpi_ssm_next_state(data); +} + /** * fpi_ssm_jump_to_state: * @machine: an #fpi_ssm state machine diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 63656a9f..709928c0 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -76,6 +76,7 @@ void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child); /* for drivers */ void fpi_ssm_next_state(fpi_ssm *machine); +void fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, void *data); void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); void fpi_ssm_mark_completed(fpi_ssm *machine); void fpi_ssm_mark_failed(fpi_ssm *machine, int error); From bdba9990fb0ff74af06c41c1a2b496b6372442d1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 19 Sep 2018 16:33:03 +0200 Subject: [PATCH 072/225] lib: Add libusb allocation helper --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 6 +++ libfprint/drivers_api.h | 2 +- libfprint/fpi-usb.c | 77 ++++++++++++++++++++++++++++++++++++++ libfprint/fpi-usb.h | 27 +++++++++++++ libfprint/meson.build | 2 + 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 libfprint/fpi-usb.c create mode 100644 libfprint/fpi-usb.h diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index 6d705e53..68543c64 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -42,6 +42,7 @@ + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index aeaef131..6b02bcde 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -193,3 +193,9 @@ FP_IMG_DEV fp_dev_set_instance_data FP_INSTANCE_DATA + +
+fpi-usb.h +fpi-usb +fpi_usb_alloc +
diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 034c1746..a567c3cd 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -27,13 +27,13 @@ #include #include #include -#include #include "fprint.h" #include "fpi-log.h" #include "fpi-ssm.h" #include "fpi-poll.h" #include "fpi-dev.h" +#include "fpi-usb.h" #include "assembling.h" #include "drivers/driver_ids.h" diff --git a/libfprint/fpi-usb.c b/libfprint/fpi-usb.c new file mode 100644 index 00000000..1b8a92e7 --- /dev/null +++ b/libfprint/fpi-usb.c @@ -0,0 +1,77 @@ +/* + * Driver API definitions + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "fpi-usb.h" + +/** + * SECTION:fpi-usb + * @title: Helpers for libusb + * + * A collection of [libusb helpers](http://libusb.sourceforge.net/api-1.0/group__poll.html#details) + * to make driver development easier. Please refer to the libusb API documentation for more + * information about the original API. + */ + +/* Helpers from glib */ +#include +#include +#include +#include +#include + +/* special helpers to avoid gmessage.c dependency */ +static void mem_error (const char *format, ...) G_GNUC_PRINTF (1,2); +#define mem_assert(cond) do { if (G_LIKELY (cond)) ; else mem_error ("assertion failed: %s", #cond); } while (0) + +static void +mem_error (const char *format, + ...) +{ + const char *pname; + va_list args; + /* at least, put out "MEMORY-ERROR", in case we segfault during the rest of the function */ + fputs ("\n***MEMORY-ERROR***: ", stderr); + pname = g_get_prgname(); + g_fprintf (stderr, "%s[%ld]: ", pname ? pname : "", (long)getpid()); + va_start (args, format); + g_vfprintf (stderr, format, args); + va_end (args); + fputs ("\n", stderr); + abort(); + _exit (1); +} + +/** + * fpi_usb_alloc: + * + * Returns a struct libusb_transfer, similar to calling + * `libusb_alloc_transfer(0)`[[1](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#ga13cc69ea40c702181c430c950121c000)]. As libfprint uses GLib internally, + * and [memory allocation failures will make applications fail](https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#glib-Memory-Allocation.description), + * this helper will assert when the libusb call fails. + */ +struct libusb_transfer * +fpi_usb_alloc(void) +{ + struct libusb_transfer *transfer; + + transfer = libusb_alloc_transfer(0); + mem_assert(transfer); + + return transfer; +} diff --git a/libfprint/fpi-usb.h b/libfprint/fpi-usb.h new file mode 100644 index 00000000..c966678e --- /dev/null +++ b/libfprint/fpi-usb.h @@ -0,0 +1,27 @@ +/* + * Driver API definitions + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_USB_H__ +#define __FPI_USB_H__ + +#include + +struct libusb_transfer *fpi_usb_alloc(void) __attribute__((returns_nonnull)); + +#endif diff --git a/libfprint/meson.build b/libfprint/meson.build index b0db4548..c4c32e02 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -11,6 +11,8 @@ libfprint_sources = [ 'fpi-ssm.h', 'fpi-poll.h', 'fpi-poll.c', + 'fpi-usb.h', + 'fpi-usb.c', 'img.c', 'imgdev.c', 'sync.c', From 10ae8ffb558ef3d58a513e22bca5381768519798 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 19 Sep 2018 17:06:17 +0200 Subject: [PATCH 073/225] drivers: Simplify libusb_alloc_transfer(0) calls By using our new, never-failing, USB allocation wrapper. As it can never fail, we can also remove all the error paths for the allocations failing. --- libfprint/drivers/aes1610.c | 21 ++--------- libfprint/drivers/aes2501.c | 28 +++------------ libfprint/drivers/aes2550.c | 62 +++++++------------------------- libfprint/drivers/aes3k.c | 7 +--- libfprint/drivers/aeslib.c | 9 ++--- libfprint/drivers/aesx660.c | 14 ++------ libfprint/drivers/elan.c | 28 +++++---------- libfprint/drivers/etes603.c | 5 +-- libfprint/drivers/upeksonly.c | 35 +++--------------- libfprint/drivers/upektc.c | 41 +++++---------------- libfprint/drivers/upektc_img.c | 20 ++--------- libfprint/drivers/upekts.c | 24 +++---------- libfprint/drivers/uru4000.c | 17 +++------ libfprint/drivers/vcom5s.c | 21 ++--------- libfprint/drivers/vfs0050.c | 10 +++--- libfprint/drivers/vfs101.c | 30 ++-------------- libfprint/drivers/vfs301_proto.c | 9 ++--- libfprint/drivers/vfs5011.c | 18 ++-------- 18 files changed, 74 insertions(+), 325 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index 5aa14c36..5818ad4e 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -128,15 +128,10 @@ static void generic_write_regv_cb(struct fp_img_dev *dev, int result, * away, then increment the SSM */ static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - data = g_malloc(bytes); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes, generic_ignore_data_cb, ssm, BULK_TIMEOUT); @@ -224,12 +219,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, void *user_da return; } - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_imgdev_session_error(dev, -ENOMEM); - return; - } - + transfer = fpi_usb_alloc(); data = g_malloc(19); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 19, finger_det_data_cb, dev, BULK_TIMEOUT); @@ -666,14 +656,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data generic_write_regv_cb, ssm); break; case CAPTURE_READ_STRIP: ; - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - data = g_malloc(665); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 665, capture_read_strip_cb, ssm, BULK_TIMEOUT); diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index fa72e236..dc03493e 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -115,12 +115,7 @@ static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data) if (result != 0) goto err; - transfer = libusb_alloc_transfer(0); - if (!transfer) { - result = -ENOMEM; - goto err; - } - + transfer = fpi_usb_alloc(); data = g_malloc(126); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 126, read_regs_data_cb, rdata, BULK_TIMEOUT); @@ -207,15 +202,10 @@ static void generic_ignore_data_cb(struct libusb_transfer *transfer) * away, then increment the SSM */ static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - data = g_malloc(bytes); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes, generic_ignore_data_cb, ssm, BULK_TIMEOUT); @@ -325,12 +315,7 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, return; } - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_imgdev_session_error(dev, -ENOMEM); - return; - } - + transfer = fpi_usb_alloc(); data = g_malloc(20); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 20, finger_det_data_cb, dev, BULK_TIMEOUT); @@ -548,14 +533,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data generic_write_regv_cb, ssm); break; case CAPTURE_READ_STRIP: ; - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - data = g_malloc(1705); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 1705, capture_read_strip_cb, ssm, BULK_TIMEOUT); diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c index 5a26012b..ce5b6c2b 100644 --- a/libfprint/drivers/aes2550.c +++ b/libfprint/drivers/aes2550.c @@ -125,12 +125,7 @@ static void finger_det_reqs_cb(struct libusb_transfer *t) goto exit_free_transfer; } - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_imgdev_session_error(dev, -ENOMEM); - goto exit_free_transfer; - } - + transfer = fpi_usb_alloc(); /* 2 bytes of result */ data = g_malloc(AES2550_EP_IN_BUF_SIZE); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, @@ -158,11 +153,7 @@ static void start_finger_detection(struct fp_img_dev *dev) return; } - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_imgdev_session_error(dev, -ENOMEM); - return; - } + transfer = fpi_usb_alloc(); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, finger_det_reqs, sizeof(finger_det_reqs), finger_det_reqs_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -330,11 +321,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_WRITE_REQS: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + struct libusb_transfer *transfer = fpi_usb_alloc(); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, capture_reqs, sizeof(capture_reqs), capture_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -346,14 +334,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data break; case CAPTURE_READ_DATA: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - data = g_malloc(AES2550_EP_IN_BUF_SIZE); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, capture_read_data_cb, ssm, BULK_TIMEOUT); @@ -368,11 +351,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data break; case CAPTURE_SET_IDLE: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + struct libusb_transfer *transfer = fpi_usb_alloc(); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, capture_set_idle_reqs, sizeof(capture_set_idle_reqs), capture_set_idle_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -489,11 +469,8 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat switch (fpi_ssm_get_cur_state(ssm)) { case WRITE_INIT: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + struct libusb_transfer *transfer = fpi_usb_alloc(); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, init_reqs, sizeof(init_reqs), init_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -505,14 +482,9 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case READ_DATA: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - data = g_malloc(AES2550_EP_IN_BUF_SIZE); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, init_read_data_cb, ssm, BULK_TIMEOUT); @@ -527,11 +499,8 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case CALIBRATE: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + struct libusb_transfer *transfer = fpi_usb_alloc(); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, calibrate_reqs, sizeof(calibrate_reqs), init_reqs_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -543,14 +512,9 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case READ_CALIB_TABLE: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - data = g_malloc(AES2550_EP_IN_BUF_SIZE); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, AES2550_EP_IN_BUF_SIZE, calibrate_read_data_cb, ssm, BULK_TIMEOUT); diff --git a/libfprint/drivers/aes3k.c b/libfprint/drivers/aes3k.c index 6149e3ab..ee802305 100644 --- a/libfprint/drivers/aes3k.c +++ b/libfprint/drivers/aes3k.c @@ -116,12 +116,7 @@ static void do_capture(struct fp_img_dev *dev) unsigned char *data; int r; - aesdev->img_trf = libusb_alloc_transfer(0); - if (!aesdev->img_trf) { - fpi_imgdev_session_error(dev, -EIO); - return; - } - + aesdev->img_trf = fpi_usb_alloc(); data = g_malloc(aesdev->data_buflen); libusb_fill_bulk_transfer(aesdev->img_trf, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, aesdev->data_buflen, img_cb, dev, 0); diff --git a/libfprint/drivers/aeslib.c b/libfprint/drivers/aeslib.c index 16cc903a..32725406 100644 --- a/libfprint/drivers/aeslib.c +++ b/libfprint/drivers/aeslib.c @@ -24,9 +24,9 @@ #include #include -#include #include +#include "fpi-usb.h" #include "assembling.h" #include "aeslib.h" @@ -73,14 +73,9 @@ 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_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); int r; - if (!transfer) { - g_free(data); - return -ENOMEM; - } - for (i = offset; i < offset + num; i++) { const struct aes_regwrite *regwrite = &wdata->regs[i]; data[data_offset++] = regwrite->reg; diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index d4c26623..b98ddf76 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -46,14 +46,9 @@ aesX660_send_cmd_timeout(fpi_ssm *ssm, int timeout) { struct fp_img_dev *dev = FP_IMG_DEV(_dev); - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, (unsigned char *)cmd, cmd_len, callback, ssm, timeout); @@ -82,15 +77,10 @@ aesX660_read_response(fpi_ssm *ssm, libusb_transfer_cb_fn callback) { struct fp_img_dev *dev = FP_IMG_DEV(_dev); - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - data = g_malloc(buf_len); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, buf_len, diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 8f48bdab..66fd2404 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -380,22 +380,16 @@ static void elan_cmd_read(fpi_ssm *ssm, struct fp_img_dev *dev) response_len = elandev->raw_frame_height * elandev->frame_width * 2; - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - elandev->cur_transfer = transfer; - + elandev->cur_transfer = fpi_usb_alloc(); g_free(elandev->last_read); elandev->last_read = g_malloc(response_len); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), + libusb_fill_bulk_transfer(elandev->cur_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), elandev->cmd->response_in, elandev->last_read, response_len, elan_cmd_cb, ssm, elandev->cmd_timeout); - transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; - int r = libusb_submit_transfer(transfer); + elandev->cur_transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; + int r = libusb_submit_transfer(elandev->cur_transfer); if (r < 0) fpi_ssm_mark_failed(ssm, r); } @@ -420,18 +414,12 @@ elan_run_cmd(fpi_ssm *ssm, return; } - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - elandev->cur_transfer = transfer; - - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), ELAN_EP_CMD_OUT, + elandev->cur_transfer = fpi_usb_alloc(); + libusb_fill_bulk_transfer(elandev->cur_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), ELAN_EP_CMD_OUT, (char *) cmd->cmd, ELAN_CMD_LEN, elan_cmd_cb, ssm, elandev->cmd_timeout); - transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; - int r = libusb_submit_transfer(transfer); + elandev->cur_transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; + int r = libusb_submit_transfer(elandev->cur_transfer); if (r < 0) fpi_ssm_mark_failed(ssm, r); } diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c index 2701cb01..97b6913b 100644 --- a/libfprint/drivers/etes603.c +++ b/libfprint/drivers/etes603.c @@ -640,13 +640,10 @@ static int async_tx(struct fp_img_dev *idev, unsigned int ep, void *cb, void *cb_arg) { struct etes603_dev *dev = FP_INSTANCE_DATA(FP_DEV(idev)); - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *buffer; int length; - if (!transfer) - return -ENOMEM; - if (ep == EP_OUT) { buffer = (unsigned char *)dev->req; length = dev->req_len; diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 8e9cc2f6..c285bdf4 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -583,13 +583,7 @@ sm_write_regs(fpi_ssm *ssm, struct write_regs_data *wrdata = g_malloc(sizeof(*wrdata)); unsigned char *data; - wrdata->transfer = libusb_alloc_transfer(0); - if (!wrdata->transfer) { - g_free(wrdata); - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - + wrdata->transfer = fpi_usb_alloc(); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); libusb_fill_control_setup(data, 0x40, 0x0c, 0, 0, 1); libusb_fill_control_transfer(wrdata->transfer, @@ -621,15 +615,10 @@ sm_write_reg(fpi_ssm *ssm, uint8_t reg, uint8_t value) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - fp_dbg("set %02x=%02x", reg, value); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); libusb_fill_control_setup(data, 0x40, 0x0c, 0, reg, 1); @@ -671,15 +660,10 @@ sm_read_reg(fpi_ssm *ssm, struct fp_img_dev *dev, uint8_t reg) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - fp_dbg("read reg %02x", reg); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 8); libusb_fill_control_setup(data, 0xc0, 0x0c, 0, reg, 8); @@ -723,15 +707,10 @@ static void sm_await_intr(fpi_ssm *ssm, struct fp_img_dev *dev) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - G_DEBUG_HERE(); data = g_malloc(4); libusb_fill_interrupt_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), @@ -1302,11 +1281,7 @@ static int dev_activate(struct fp_img_dev *dev, enum fp_imgdev_state state) sdev->num_flying = 0; for (i = 0; i < NUM_BULK_TRANSFERS; i++) { unsigned char *data; - sdev->img_transfer[i] = libusb_alloc_transfer(0); - if (!sdev->img_transfer[i]) { - free_img_transfers(sdev); - return -ENOMEM; - } + sdev->img_transfer[i] = fpi_usb_alloc(); sdev->img_transfer_data[i].idx = i; sdev->img_transfer_data[i].dev = dev; data = g_malloc(4096); diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c index 38a17a49..0042833e 100644 --- a/libfprint/drivers/upektc.c +++ b/libfprint/drivers/upektc.c @@ -109,11 +109,8 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat switch (fpi_ssm_get_cur_state(ssm)) { case WRITE_INIT: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + struct libusb_transfer *transfer = fpi_usb_alloc(); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out, (unsigned char*)upekdev->setup_commands[upekdev->init_idx].cmd, UPEKTC_CMD_LEN, write_init_cb, ssm, BULK_TIMEOUT); @@ -126,14 +123,9 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case READ_DATA: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - data = g_malloc(upekdev->setup_commands[upekdev->init_idx].response_len); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, upekdev->setup_commands[upekdev->init_idx].response_len, @@ -228,12 +220,7 @@ static void finger_det_cmd_cb(struct libusb_transfer *t) goto exit_free_transfer; } - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_imgdev_session_error(dev, -ENOMEM); - goto exit_free_transfer; - } - + transfer = fpi_usb_alloc(); data = g_malloc(IMAGE_SIZE); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, IMAGE_SIZE, finger_det_data_cb, dev, BULK_TIMEOUT); @@ -260,11 +247,7 @@ static void start_finger_detection(struct fp_img_dev *dev) return; } - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_imgdev_session_error(dev, -ENOMEM); - return; - } + transfer = fpi_usb_alloc(); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out, (unsigned char *)scan_cmd, UPEKTC_CMD_LEN, finger_det_cmd_cb, dev, BULK_TIMEOUT); @@ -332,11 +315,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data switch (fpi_ssm_get_cur_state(ssm)) { case CAPTURE_WRITE_CMD: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + struct libusb_transfer *transfer = fpi_usb_alloc(); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_out, (unsigned char *)scan_cmd, UPEKTC_CMD_LEN, capture_cmd_cb, ssm, BULK_TIMEOUT); @@ -349,14 +329,9 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data break; case CAPTURE_READ_DATA: { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - data = g_malloc(IMAGE_SIZE); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), upekdev->ep_in, data, IMAGE_SIZE, capture_read_data_cb, ssm, BULK_TIMEOUT); diff --git a/libfprint/drivers/upektc_img.c b/libfprint/drivers/upektc_img.c index 9ca25cb4..d749ac51 100644 --- a/libfprint/drivers/upektc_img.c +++ b/libfprint/drivers/upektc_img.c @@ -80,16 +80,11 @@ upektc_img_submit_req(fpi_ssm *ssm, libusb_transfer_cb_fn cb) { struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); int r; BUG_ON(buf_size > MAX_CMD_SIZE); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; memcpy(upekdev->cmd, buf, buf_size); @@ -113,15 +108,10 @@ upektc_img_read_data(fpi_ssm *ssm, size_t buf_offset, libusb_transfer_cb_fn cb) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - BUG_ON(buf_size > MAX_RESPONSE_SIZE); transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; @@ -518,11 +508,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data { unsigned char *data; - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } + transfer = fpi_usb_alloc(); transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER | LIBUSB_TRANSFER_FREE_TRANSFER; diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index 98448e1f..47eb0d2e 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -90,7 +90,7 @@ static struct libusb_transfer *alloc_send_cmd_transfer(struct fp_dev *dev, unsigned char seq_a, unsigned char seq_b, const unsigned char *data, uint16_t len, libusb_transfer_cb_fn callback, void *user_data) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); uint16_t crc; const char *ciao = "Ciao"; @@ -99,9 +99,6 @@ static struct libusb_transfer *alloc_send_cmd_transfer(struct fp_dev *dev, size_t urblen = len + 9; unsigned char *buf; - if (!transfer) - return NULL; - if (!data && len > 0) { fp_err("len>0 but no data?"); return NULL; @@ -367,12 +364,9 @@ static void read_msg_cb(struct libusb_transfer *transfer) * to read the remainder. This is handled below. */ if (len > MAX_DATA_IN_READ_BUF) { int needed = len - MAX_DATA_IN_READ_BUF; - struct libusb_transfer *etransfer = libusb_alloc_transfer(0); + struct libusb_transfer *etransfer = fpi_usb_alloc(); int r; - if (!transfer) - goto err; - fp_dbg("didn't fit in buffer, need to extend by %d bytes", needed); data = g_realloc((gpointer) data, MSG_READ_BUF_SIZE + needed); @@ -407,14 +401,9 @@ out: static int __read_msg_async(struct read_msg_data *udata) { unsigned char *buf = g_malloc(MSG_READ_BUF_SIZE); - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); int r; - if (!transfer) { - g_free(buf); - return -ENOMEM; - } - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(udata->dev), EP_IN, buf, MSG_READ_BUF_SIZE, read_msg_cb, udata, TIMEOUT); r = libusb_submit_transfer(transfer); @@ -670,12 +659,7 @@ static void initsm_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data) case WRITE_CTRL400: ; unsigned char *data; - transfer = libusb_alloc_transfer(0); - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - break; - } - + transfer = fpi_usb_alloc(); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); libusb_fill_control_setup(data, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1); diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 58455c09..0c764260 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -186,13 +186,10 @@ static int write_regs(struct fp_img_dev *dev, uint16_t first_reg, void *user_data) { struct write_regs_data *wrdata; - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) - return -ENOMEM; - wrdata = g_malloc(sizeof(*wrdata)); wrdata->dev = dev; wrdata->callback = callback; @@ -253,13 +250,10 @@ static int read_regs(struct fp_img_dev *dev, uint16_t first_reg, uint16_t num_regs, read_regs_cb_fn callback, void *user_data) { struct read_regs_data *rrdata; - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) - return -ENOMEM; - rrdata = g_malloc(sizeof(*rrdata)); rrdata->dev = dev; rrdata->callback = callback; @@ -428,13 +422,10 @@ out: static int start_irq_handler(struct fp_img_dev *dev) { struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) - return -ENOMEM; - data = g_malloc(IRQ_LENGTH); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_INTR, data, IRQ_LENGTH, irq_handler, dev, 0); @@ -1236,7 +1227,7 @@ static int execute_state_change(struct fp_img_dev *dev) fp_dbg("starting capture"); urudev->irq_cb = NULL; - urudev->img_transfer = libusb_alloc_transfer(0); + urudev->img_transfer = fpi_usb_alloc(); urudev->img_data = g_malloc(sizeof(struct uru4k_image)); urudev->img_enc_seed = rand(); diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c index 64aa64e8..4ed71f69 100644 --- a/libfprint/drivers/vcom5s.c +++ b/libfprint/drivers/vcom5s.c @@ -91,15 +91,10 @@ sm_write_reg(fpi_ssm *ssm, unsigned char reg, unsigned char value) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - fp_dbg("set %02x=%02x", reg, value); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE); libusb_fill_control_setup(data, CTRL_OUT, reg, value, 0, 0); @@ -132,14 +127,9 @@ sm_exec_cmd(fpi_ssm *ssm, unsigned char cmd, unsigned char param) { - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; int r; - - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } fp_dbg("cmd %02x param %02x", cmd, param); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE); @@ -228,14 +218,9 @@ capture_iterate(fpi_ssm *ssm, { struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); int iteration = vdev->capture_iteration; - struct libusb_transfer *transfer = libusb_alloc_transfer(0); + struct libusb_transfer *transfer = fpi_usb_alloc(); int r; - if (!transfer) { - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, vdev->capture_img->data + (RQ_SIZE * iteration), RQ_SIZE, capture_cb, ssm, CTRL_TIMEOUT); diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 1d8d7a17..a437df4f 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -60,7 +60,7 @@ async_write(fpi_ssm *ssm, struct libusb_device_handle *usb_dev = fpi_dev_get_usb_dev(FP_DEV(dev)); struct vfs_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); - vdev->transfer = libusb_alloc_transfer(0); + vdev->transfer = fpi_usb_alloc(); vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; libusb_fill_bulk_transfer(vdev->transfer, usb_dev, 0x01, data, len, async_write_callback, ssm, VFS_USB_TIMEOUT); @@ -109,7 +109,7 @@ async_read(fpi_ssm *ssm, ep |= LIBUSB_ENDPOINT_IN; - vdev->transfer = libusb_alloc_transfer(0); + vdev->transfer = fpi_usb_alloc(); vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; /* 0x83 is the only interrupt endpoint */ @@ -166,7 +166,7 @@ static void async_abort(fpi_ssm *ssm, int ep) ep |= LIBUSB_ENDPOINT_IN; - vdev->transfer = libusb_alloc_transfer(0); + vdev->transfer = fpi_usb_alloc(); vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER | LIBUSB_TRANSFER_FREE_BUFFER; @@ -578,7 +578,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) } /* Asyncronously enquire an interrupt */ - vdev->transfer = libusb_alloc_transfer(0); + vdev->transfer = fpi_usb_alloc(); vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; libusb_fill_interrupt_transfer(vdev->transfer, usb_dev, 0x83, vdev->interrupt, @@ -628,7 +628,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) } /* Receive chunk of data */ - vdev->transfer = libusb_alloc_transfer(0); + vdev->transfer = fpi_usb_alloc(); vdev->transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER; libusb_fill_bulk_transfer(vdev->transfer, usb_dev, 0x82, (void *)vdev->lines_buffer + diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index e4400f82..cf6980f1 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -247,15 +247,7 @@ async_send(fpi_ssm *ssm, int r; /* Allocation of transfer */ - vdev->transfer = libusb_alloc_transfer(0); - if (!vdev->transfer) - { - /* Allocation transfer failed, return no memory error */ - fp_err("allocation of usb transfer failed"); - fpi_imgdev_session_error(dev, -ENOMEM); - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + vdev->transfer = fpi_usb_alloc(); /* Put sequential number into the buffer */ vdev->seqnum++; @@ -335,15 +327,7 @@ async_recv(fpi_ssm *ssm, int r; /* Allocation of transfer */ - vdev->transfer = libusb_alloc_transfer(0); - if (!vdev->transfer) - { - /* Allocation transfer failed, return no memory error */ - fp_err("allocation of usb transfer failed"); - fpi_imgdev_session_error(dev, -ENOMEM); - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + vdev->transfer = fpi_usb_alloc(); /* Prepare bulk transfer */ libusb_fill_bulk_transfer(vdev->transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN(1), vdev->buffer, 0x0f, async_recv_cb, ssm, BULK_TIMEOUT); @@ -438,15 +422,7 @@ async_load(fpi_ssm *ssm, int r; /* Allocation of transfer */ - vdev->transfer = libusb_alloc_transfer(0); - if (!vdev->transfer) - { - /* Allocation transfer failed, return no memory error */ - fp_err("allocation of usb transfer failed"); - fpi_imgdev_session_error(dev, -ENOMEM); - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + vdev->transfer = fpi_usb_alloc(); /* Append new data into the buffer */ buffer = vdev->buffer + vdev->length; diff --git a/libfprint/drivers/vfs301_proto.c b/libfprint/drivers/vfs301_proto.c index f96f411a..7564f56d 100644 --- a/libfprint/drivers/vfs301_proto.c +++ b/libfprint/drivers/vfs301_proto.c @@ -33,8 +33,8 @@ #include #include #include -#include +#include "fpi-usb.h" #include "vfs301_proto.h" #include "vfs301_proto_fragments.h" @@ -499,12 +499,7 @@ void vfs301_proto_process_event_start( USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 64); /* now read the fingerprint data, while there are some */ - transfer = libusb_alloc_transfer(0); - if (!transfer) { - dev->recv_progress = VFS301_FAILURE; - return; - } - + transfer = fpi_usb_alloc(); dev->recv_progress = VFS301_ONGOING; dev->recv_exp_amt = VFS301_FP_RECV_LEN_1; diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 24e48689..2fcb822a 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -189,13 +189,7 @@ static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) switch (action->type) { case ACTION_SEND: fp_dbg("Sending %s", action->name); - transfer = libusb_alloc_transfer(0); - if (transfer == NULL) { - fp_err("Failed to allocate transfer"); - fpi_imgdev_session_error(data->device, -ENOMEM); - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + transfer = fpi_usb_alloc(); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)), action->endpoint, action->data, action->size, async_send_cb, ssm, @@ -205,13 +199,7 @@ static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) case ACTION_RECEIVE: fp_dbg("Receiving %d bytes", action->size); - transfer = libusb_alloc_transfer(0); - if (transfer == NULL) { - fp_err("Failed to allocate transfer"); - fpi_imgdev_session_error(data->device, -ENOMEM); - fpi_ssm_mark_failed(ssm, -ENOMEM); - return; - } + transfer = fpi_usb_alloc(); libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)), action->endpoint, data->receive_buf, action->size, async_recv_cb, ssm, @@ -464,7 +452,7 @@ static int capture_chunk_async(struct vfs5011_data *data, STOP_CHECK_LINES = 50 }; - data->flying_transfer = libusb_alloc_transfer(0); + data->flying_transfer = fpi_usb_alloc(); libusb_fill_bulk_transfer(data->flying_transfer, handle, VFS5011_IN_ENDPOINT_DATA, data->capture_buffer, nline * VFS5011_LINE_SIZE, From 946388d1e9e4a5693a5c5c0f9c5f76bf2628d619 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 15:07:48 +0200 Subject: [PATCH 074/225] lib: Fix incorrect guard in FP_IMG_DEV() The check for the DRIVER_IMAGING type was reversed. --- libfprint/fpi-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index ffaff268..59bffa9a 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -56,7 +56,7 @@ FP_IMG_DEV(struct fp_dev *dev) { g_return_val_if_fail (dev, NULL); g_return_val_if_fail (dev->drv, NULL); - g_return_val_if_fail (dev->drv->type != DRIVER_IMAGING, NULL); + g_return_val_if_fail (dev->drv->type == DRIVER_IMAGING, NULL); return dev->img_dev; } From ccdecdea11863c68bdffb8fb260c14019ab0ff4b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 14:10:48 +0200 Subject: [PATCH 075/225] lib: Document fpi_ssm_jump_to_state() --- libfprint/fpi-ssm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index a7b2e8b4..20a5f2f9 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -276,6 +276,7 @@ fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, * @machine: an #fpi_ssm state machine * @state: the state to jump to * + * Jump to the @state state, bypassing intermediary states. */ void fpi_ssm_jump_to_state(fpi_ssm *machine, int state) { From 29545833735b53ac7a060f8c54d4345494146215 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 11:52:23 +0200 Subject: [PATCH 076/225] lib: Fix memory leak in fpi_poll_exit() The active_timers list was freed, but not the elements themselves. --- libfprint/fpi-poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index ee7d86d5..b51fcb7d 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -413,7 +413,7 @@ void fpi_poll_init(void) void fpi_poll_exit(void) { - g_slist_free(active_timers); + g_slist_free_full(active_timers, g_free); active_timers = NULL; fd_added_cb = NULL; fd_removed_cb = NULL; From d18e10535eb49c6a628ff62a164f2ae05fbee27c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 14:29:18 +0200 Subject: [PATCH 077/225] lib: Add a way to name timeouts To make it easier to print debug information about where timeouts are coming from. --- libfprint/fpi-poll.c | 58 +++++++++++++++++++++++++++++++++++++++++--- libfprint/fpi-poll.h | 2 ++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index b51fcb7d..323774fb 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -86,6 +86,7 @@ struct fpi_timeout { fpi_timeout_fn callback; struct fp_dev *dev; void *data; + char *name; }; static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) @@ -103,6 +104,35 @@ static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) return 0; } +static void +fpi_timeout_free(fpi_timeout *timeout) +{ + if (timeout == NULL) + return; + + g_free(timeout->name); + g_free(timeout); +} + +/** + * fpi_timeout_set_name: + * @timeout: a #fpi_timeout + * @name: the name to give the timeout + * + * Sets a name for a timeout, allowing that name to be printed + * along with any timeout related debug. + */ +void +fpi_timeout_set_name(fpi_timeout *timeout, + const char *name) +{ + g_return_if_fail (timeout != NULL); + g_return_if_fail (name != NULL); + g_return_if_fail (timeout->name == NULL); + + timeout->name = g_strdup(name); +} + /** * fpi_timeout_add: * @msec: the time before calling the function, in milliseconds (1/1000ths of a second) @@ -140,7 +170,7 @@ fpi_timeout *fpi_timeout_add(unsigned int msec, return NULL; } - timeout = g_malloc(sizeof(*timeout)); + timeout = g_new0(fpi_timeout, 1); timeout->callback = callback; timeout->dev = dev; timeout->data = data; @@ -169,7 +199,27 @@ void fpi_timeout_cancel(fpi_timeout *timeout) { G_DEBUG_HERE(); active_timers = g_slist_remove(active_timers, timeout); - g_free(timeout); + fpi_timeout_free(timeout); +} + +void +fpi_timeout_cancel_for_dev(struct fp_dev *dev) +{ + GSList *l; + + g_return_if_fail (dev != NULL); + + l = active_timers; + while (l) { + struct fpi_timeout *timeout = l->data; + GSList *current = l; + + l = l->next; + if (timeout->dev == dev) { + fpi_timeout_free (timeout); + active_timers = g_slist_delete_link (active_timers, current); + } + } } /* get the expiry time and optionally the timeout structure for the next @@ -216,7 +266,7 @@ static void handle_timeout(struct fpi_timeout *timeout) G_DEBUG_HERE(); timeout->callback(timeout->dev, timeout->data); active_timers = g_slist_remove(active_timers, timeout); - g_free(timeout); + fpi_timeout_free(timeout); } static int handle_timeouts(void) @@ -413,7 +463,7 @@ void fpi_poll_init(void) void fpi_poll_exit(void) { - g_slist_free_full(active_timers, g_free); + g_slist_free_full(active_timers, (GDestroyNotify) fpi_timeout_free); active_timers = NULL; fd_added_cb = NULL; fd_removed_cb = NULL; diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 3eb316cb..42214b61 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -42,4 +42,6 @@ fpi_timeout *fpi_timeout_add(unsigned int msec, fpi_timeout_fn callback, struct fp_dev *dev, void *data); +void fpi_timeout_set_name(fpi_timeout *timeout, + const char *name); void fpi_timeout_cancel(fpi_timeout *timeout); From de79609550c63f74d74d66d5c37c584b4e8ef127 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 14:42:43 +0200 Subject: [PATCH 078/225] lib: Use timeout name in debug messages when available --- libfprint/fpi-poll.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 323774fb..6d3dd3f9 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -250,11 +250,18 @@ static int get_next_timeout_expiry(struct timeval *out, *out_timeout = next_timeout; if (timercmp(&tv, &next_timeout->expiry, >=)) { - fp_dbg("first timeout already expired"); + if (next_timeout->name) + fp_dbg("first timeout '%s' already expired", next_timeout->name); + else + fp_dbg("first timeout already expired"); timerclear(out); } else { timersub(&next_timeout->expiry, &tv, out); - fp_dbg("next timeout in %ld.%06lds", out->tv_sec, out->tv_usec); + if (next_timeout->name) + fp_dbg("next timeout '%s' in %ld.%06lds", next_timeout->name, + out->tv_sec, out->tv_usec); + else + fp_dbg("next timeout in %ld.%06lds", out->tv_sec, out->tv_usec); } return 1; From 948a67a51f37fc47eda994be4a46919c2c96d26e Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 12:21:45 +0200 Subject: [PATCH 079/225] lib: Add internal fpi_timeout_cancel_all_for_dev() This will be used to disable all timeouts for a device that's about to be closed, and freed. --- libfprint/fp_internal.h | 2 +- libfprint/fpi-poll.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index e3fcc10f..7044a627 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -327,7 +327,7 @@ int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print, struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); /* polling */ - +void fpi_timeout_cancel_all_for_dev(struct fp_dev *dev); void fpi_poll_init(void); void fpi_poll_exit(void); diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 6d3dd3f9..623b154f 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -477,3 +477,22 @@ void fpi_poll_exit(void) libusb_set_pollfd_notifiers(fpi_usb_ctx, NULL, NULL, NULL); } +void +fpi_timeout_cancel_all_for_dev(struct fp_dev *dev) +{ + GSList *l; + + g_return_if_fail (dev != NULL); + + l = active_timers; + while (l) { + struct fpi_timeout *timeout = l->data; + GSList *current = l; + + l = l->next; + if (timeout->dev == dev) { + g_free (timeout); + active_timers = g_slist_delete_link (active_timers, current); + } + } +} From 44c3f4f772c32b43218b011416c4de1ad6d282e5 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 14:48:07 +0200 Subject: [PATCH 080/225] lib: Cancel pending timeouts on close So that the drivers don't call back into themselves once freed. --- libfprint/async.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/async.c b/libfprint/async.c index aba78b7b..7a9cd0cf 100644 --- a/libfprint/async.c +++ b/libfprint/async.c @@ -93,6 +93,7 @@ void fpi_drvcb_close_complete(struct fp_dev *dev) G_DEBUG_HERE(); BUG_ON(dev->state != DEV_STATE_DEINITIALIZING); dev->state = DEV_STATE_DEINITIALIZED; + fpi_timeout_cancel_all_for_dev(dev); libusb_close(dev->udev); if (dev->close_cb) dev->close_cb(dev, dev->close_cb_data); From d09cb88e9a84a17d74f8a54a67fbc5ff838b3908 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 15:21:01 +0200 Subject: [PATCH 081/225] uru4000: Fix typos in comments --- libfprint/drivers/uru4000.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 0c764260..5064d545 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -295,7 +295,7 @@ static int read_regs(struct fp_img_dev *dev, uint16_t first_reg, * * BIT 1: IRQ PENDING * Just had a brainwave. This bit is set when the device is trying to deliver - * and interrupt to the host. Maybe? + * an interrupt to the host. Maybe? */ static void response_cb(struct fp_img_dev *dev, int status, void *user_data) @@ -847,7 +847,7 @@ static void imaging_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) * confused state and returns hwstat 0x85. On next app run, we don't get the * 56aa interrupt. This is the best way I've found to fix it: mess around * with hwstat until it starts returning more recognisable values. This - * doesn't happen on my other devices: uru4000, uru4000b, ms fp rdr v2 + * doesn't happen on my other devices: uru4000, uru4000b, ms fp rdr v2 * * The windows driver copes with this OK, but then again it uploads firmware * right after reading the 0x85 hwstat, allowing some time to pass before it @@ -909,10 +909,10 @@ static void rebootpwr_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da } } -/* After messing with the device firmware in it's low-power state, we have to +/* After messing with the device firmware in its low-power state, we have to * power it back up and wait for interrupt notification. It's not quite as easy * as that: the combination of both modifying firmware *and* doing C-R auth on - * my ms fp v2 device causes us not to get to get the 56aa interrupt and + * my ms fp v2 device causes us not to get the 56aa interrupt and * for the hwstat write not to take effect. We have to loop a few times, * authenticating each time, until the device wakes up. * From 49ba59369aed3a101aa5758daffe4553dd5ddf6c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 09:11:13 +0200 Subject: [PATCH 082/225] aesx660: Remove home-grown min() implementation And use GLib's. --- libfprint/drivers/aesx660.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index b98ddf76..9af93e3c 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -35,8 +35,6 @@ static void complete_deactivation(struct fp_img_dev *dev); #define BULK_TIMEOUT 4000 #define FRAME_HEIGHT AESX660_FRAME_HEIGHT -#define min(a, b) (((a) < (b)) ? (a) : (b)) - static void aesX660_send_cmd_timeout(fpi_ssm *ssm, struct fp_dev *_dev, @@ -334,7 +332,7 @@ static void capture_read_stripe_data_cb(struct libusb_transfer *transfer) fp_dbg("Got %lu bytes of data", actual_len); do { - copied = min(aesdev->buffer_max - aesdev->buffer_size, actual_len); + copied = MIN(aesdev->buffer_max - aesdev->buffer_size, actual_len); memcpy(aesdev->buffer + aesdev->buffer_size, data, copied); From b817b46494a7a350adb43c4033113b87c0d24ad6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 09:11:45 +0200 Subject: [PATCH 083/225] lib: Remove home-grown min() implementation And use GLib's. --- libfprint/assembling.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libfprint/assembling.c b/libfprint/assembling.c index de8cb342..7ff941c5 100644 --- a/libfprint/assembling.c +++ b/libfprint/assembling.c @@ -350,8 +350,6 @@ static void interpolate_lines(struct fpi_line_asmbl_ctx *ctx, } } -static int min(int a, int b) {return (a < b) ? a : b; } - /* Rescale image to account for variable swiping speed */ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx, GSList *lines, size_t lines_len) @@ -377,7 +375,7 @@ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx, int j, firstrow, lastrow; firstrow = i + 1; - lastrow = min(i + ctx->max_search_offset, lines_len - 1); + lastrow = MIN(i + ctx->max_search_offset, lines_len - 1); row2 = g_slist_next(row1); for (j = firstrow; j <= lastrow; j++) { From b890fa56d806cc0f3c52a9e67c8b20b688b8ecac Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 16:23:41 +0200 Subject: [PATCH 084/225] aes1610: Use constants for buffer sizes --- libfprint/drivers/aes1610.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c index 5818ad4e..1e7b3b9b 100644 --- a/libfprint/drivers/aes1610.c +++ b/libfprint/drivers/aes1610.c @@ -44,6 +44,9 @@ static int adjust_gain(unsigned char *buffer, int status); #define BULK_TIMEOUT 4000 +#define FINGER_DETECTION_LEN 19 +#define STRIP_CAPTURE_LEN 665 + /* * The AES1610 is an imaging device using a swipe-type sensor. It samples * the finger at preprogrammed intervals, sending a 128x8 frame to the @@ -220,8 +223,8 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, void *user_da } transfer = fpi_usb_alloc(); - data = g_malloc(19); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 19, + data = g_malloc(FINGER_DETECTION_LEN); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, FINGER_DETECTION_LEN, finger_det_data_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -645,7 +648,7 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data break; case CAPTURE_READ_DATA: fp_dbg("read data"); - generic_read_ignore_data(ssm, _dev, 665); + generic_read_ignore_data(ssm, _dev, STRIP_CAPTURE_LEN); break; case CAPTURE_REQUEST_STRIP: fp_dbg("request strip"); @@ -659,8 +662,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - data = g_malloc(665); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 665, + data = g_malloc(STRIP_CAPTURE_LEN); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, STRIP_CAPTURE_LEN, capture_read_strip_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); From cb274032da1f6635d3e7d9430f4206b9b9213216 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 16:24:12 +0200 Subject: [PATCH 085/225] aes2501: Use constants for buffer sizes --- libfprint/drivers/aes2501.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index dc03493e..d8a3c58a 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -36,6 +36,11 @@ static void complete_deactivation(struct fp_img_dev *dev); #define BULK_TIMEOUT 4000 +#define FINGER_DETECTION_LEN 20 +#define READ_REGS_LEN 126 +#define READ_REGS_RESP_LEN 159 +#define STRIP_CAPTURE_LEN 1705 + /* * The AES2501 is an imaging device using a swipe-type sensor. It samples * the finger at preprogrammed intervals, sending a 192x16 frame to the @@ -116,8 +121,8 @@ static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data) goto err; transfer = fpi_usb_alloc(); - data = g_malloc(126); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 126, + data = g_malloc(READ_REGS_LEN); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, READ_REGS_LEN, read_regs_data_cb, rdata, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -316,8 +321,8 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, } transfer = fpi_usb_alloc(); - data = g_malloc(20); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 20, + data = g_malloc(FINGER_DETECTION_LEN); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, FINGER_DETECTION_LEN, finger_det_data_cb, dev, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -516,14 +521,14 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data generic_write_regv_cb, ssm); break; case CAPTURE_READ_DATA_1: - generic_read_ignore_data(ssm, _dev, 159); + generic_read_ignore_data(ssm, _dev, READ_REGS_RESP_LEN); break; case CAPTURE_WRITE_REQS_2: aes_write_regv(dev, capture_reqs_2, G_N_ELEMENTS(capture_reqs_2), generic_write_regv_cb, ssm); break; case CAPTURE_READ_DATA_2: - generic_read_ignore_data(ssm, _dev, 159); + generic_read_ignore_data(ssm, _dev, READ_REGS_RESP_LEN); break; case CAPTURE_REQUEST_STRIP: if (aesdev->deactivating) @@ -536,8 +541,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data struct libusb_transfer *transfer = fpi_usb_alloc(); unsigned char *data; - data = g_malloc(1705); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, 1705, + data = g_malloc(STRIP_CAPTURE_LEN); + libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, STRIP_CAPTURE_LEN, capture_read_strip_cb, ssm, BULK_TIMEOUT); r = libusb_submit_transfer(transfer); @@ -745,7 +750,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case READ_DATA_1: fp_dbg("read data 1"); - generic_read_ignore_data(ssm, _dev, 20); + generic_read_ignore_data(ssm, _dev, FINGER_DETECTION_LEN); break; case WRITE_INIT_2: aes_write_regv(dev, init_2, G_N_ELEMENTS(init_2), From 192c4f3cfc97f95d03c130fb9668ab567df1afc9 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 16:24:23 +0200 Subject: [PATCH 086/225] aesx660: Use constants for buffer sizes --- libfprint/drivers/aesx660.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index 9af93e3c..7711eee5 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -35,6 +35,11 @@ static void complete_deactivation(struct fp_img_dev *dev); #define BULK_TIMEOUT 4000 #define FRAME_HEIGHT AESX660_FRAME_HEIGHT +#define ID_LEN 8 +#define INIT_LEN 4 +#define CALIBRATE_DATA_LEN 4 +#define FINGER_DET_DATA_LEN 4 + static void aesX660_send_cmd_timeout(fpi_ssm *ssm, struct fp_dev *_dev, @@ -227,8 +232,7 @@ static void finger_det_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_da aesX660_send_cmd_cb, 0); break; case FINGER_DET_READ_FD_DATA: - /* Should return 4 byte of response */ - aesX660_read_response(ssm, dev, 4, finger_det_read_fd_data_cb); + aesX660_read_response(ssm, dev, FINGER_DET_DATA_LEN, finger_det_read_fd_data_cb); break; case FINGER_DET_SET_IDLE: aesX660_send_cmd(ssm, dev, set_idle_cmd, sizeof(set_idle_cmd), @@ -548,8 +552,7 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat aesX660_send_cmd_cb); break; case ACTIVATE_READ_ID: - /* Should return 8-byte response */ - aesX660_read_response(ssm, _dev, 8, activate_read_id_cb); + aesX660_read_response(ssm, _dev, ID_LEN, activate_read_id_cb); break; case ACTIVATE_SEND_INIT_CMD: fp_dbg("Activate: send init seq #%d cmd #%d\n", @@ -562,16 +565,14 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat break; case ACTIVATE_READ_INIT_RESPONSE: fp_dbg("Activate: read init response\n"); - /* Should return 4-byte response */ - aesX660_read_response(ssm, _dev, 4, activate_read_init_cb); + aesX660_read_response(ssm, _dev, INIT_LEN, activate_read_init_cb); break; case ACTIVATE_SEND_CALIBRATE_CMD: aesX660_send_cmd(ssm, _dev, calibrate_cmd, sizeof(calibrate_cmd), aesX660_send_cmd_cb); break; case ACTIVATE_READ_CALIBRATE_DATA: - /* Should return 4-byte response */ - aesX660_read_response(ssm, _dev, 4, aesX660_read_calibrate_data_cb); + aesX660_read_response(ssm, _dev, CALIBRATE_DATA_LEN, aesX660_read_calibrate_data_cb); break; } } From 96f2e07cddc17ab95235c4b828d4b66ddcf49bbe Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 14:11:09 +0200 Subject: [PATCH 087/225] lib: Add USB transfer helpers Those helpers will provide more arguments in their callbacks, and handle the libusb_transfer lifecycle, making it easier to use for drivers. --- doc/libfprint-sections.txt | 6 ++ libfprint/fpi-usb.c | 158 +++++++++++++++++++++++++++++++++++++ libfprint/fpi-usb.h | 44 +++++++++++ 3 files changed, 208 insertions(+) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 6b02bcde..0a95c2d5 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -197,5 +197,11 @@ FP_INSTANCE_DATA
fpi-usb.h fpi-usb +fpi_usb_transfer + +fpi_usb_transfer_cb_fn fpi_usb_alloc +fpi_usb_fill_bulk_transfer +fpi_usb_submit_transfer +fpi_usb_cancel_transfer
diff --git a/libfprint/fpi-usb.c b/libfprint/fpi-usb.c index 1b8a92e7..8b06ebb4 100644 --- a/libfprint/fpi-usb.c +++ b/libfprint/fpi-usb.c @@ -18,6 +18,7 @@ */ #include "fpi-usb.h" +#include "drivers_api.h" /** * SECTION:fpi-usb @@ -57,6 +58,14 @@ mem_error (const char *format, _exit (1); } +struct fpi_usb_transfer { + struct libusb_transfer *transfer; + fpi_ssm *ssm; + struct fp_dev *dev; + fpi_usb_transfer_cb_fn callback; + void *user_data; +}; + /** * fpi_usb_alloc: * @@ -75,3 +84,152 @@ fpi_usb_alloc(void) return transfer; } + +static fpi_usb_transfer * +fpi_usb_transfer_new(struct fp_dev *dev, + fpi_ssm *ssm, + fpi_usb_transfer_cb_fn callback, + void *user_data) +{ + fpi_usb_transfer *transfer; + + transfer = g_new0(fpi_usb_transfer, 1); + transfer->transfer = fpi_usb_alloc(); + transfer->dev = dev; + transfer->ssm = ssm; + transfer->callback = callback; + transfer->user_data = user_data; + + return transfer; +} + +void +fpi_usb_transfer_free(fpi_usb_transfer *transfer) +{ + if (transfer == NULL) + return; + + g_free(transfer->transfer->buffer); + libusb_free_transfer(transfer->transfer); + g_free(transfer); +} + +static void +fpi_usb_transfer_cb (struct libusb_transfer *transfer) +{ + fpi_usb_transfer *t; + + g_assert(transfer); + g_assert(transfer->user_data); + + t = transfer->user_data; + BUG_ON(transfer->callback == NULL); + (t->callback) (transfer, t->dev, t->ssm, t->user_data); + fpi_usb_transfer_free(t); +} + +/** + * fpi_usb_fill_bulk_transfer: + * @dev: a struct #fp_dev fingerprint device + * @ssm: the current #fpi_ssm state machine + * @endpoint: the USB end point + * @buffer: a buffer allocated with g_malloc() or another GLib function. + * Note that the returned #fpi_usb_transfer will own this buffer, so it + * should not be freed manually. + * @length: the size of @buffer + * @callback: the callback function that will be called once the fpi_usb_submit_transfer() + * call finishes. + * @user_data: a user data pointer to pass to the callback + * @timeout: timeout for the transfer in milliseconds, or 0 for no timeout + * + * This function is similar to calling [`libusb_alloc_transfer(0)`](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#ga13cc69ea40c702181c430c950121c000)] + * followed by calling [`libusb_fill_bulk_transfer()`](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#gad4ddb1a5c6c7fefc979a44d7300b95d7). + * The #fpi_usb_transfer_cb_fn callback will however provide more arguments + * relevant to libfprint drivers, making it a good replacement for the raw libusb + * calls. + * + * Returns: a #fpi_usb_transfer transfer struct, to be passed to + * fpi_usb_submit_transfer(). + */ +fpi_usb_transfer * +fpi_usb_fill_bulk_transfer (struct fp_dev *dev, + fpi_ssm *ssm, + unsigned char endpoint, + unsigned char *buffer, + int length, + fpi_usb_transfer_cb_fn callback, + void *user_data, + unsigned int timeout) +{ + fpi_usb_transfer *transfer; + + g_return_val_if_fail (dev != NULL, NULL); + g_return_val_if_fail (callback != NULL, NULL); + + transfer = fpi_usb_transfer_new(dev, + ssm, + callback, + user_data); + + libusb_fill_bulk_transfer(transfer->transfer, + fpi_dev_get_usb_dev(dev), + endpoint, + buffer, + length, + fpi_usb_transfer_cb, + transfer, + timeout); + + return transfer; +} + +/** + * fpi_usb_submit_transfer: + * @transfer: a #fpi_usb_transfer struct + * + * Start a transfer to the device with the provided #fpi_usb_transfer. + * On error, the #fpi_usb_transfer struct will be freed, otherwise it will + * be freed once the callback provided to fpi_usb_fill_bulk_transfer() has + * been called. + * + * Returns: 0 on success, or the same errors as [libusb_submit_transfer](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#gabb0932601f2c7dad2fee4b27962848ce) + * on failure. + */ +int +fpi_usb_submit_transfer(fpi_usb_transfer *transfer) +{ + int r; + + g_return_val_if_fail (transfer != NULL, LIBUSB_ERROR_INVALID_PARAM); + + r = libusb_submit_transfer(transfer->transfer); + if (r < 0) + fpi_usb_transfer_free(transfer); + + return r; +} + +/** + * fpi_usb_cancel_transfer: + * @transfer: a #fpi_usb_transfer struct + * + * Cancel a transfer to the device with the provided #fpi_usb_transfer. + * Note that this will not complete the cancellation, as your transfer + * callback will be called with the `LIBUSB_TRANSFER_CANCELLED` status, + * as [libusb_cancel_transfer](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#ga685eb7731f9a0593f75beb99727bbe54) + * would. + * + * You should not access anything but the given struct #libusb_transfer + * in the callback before checking whether `LIBUSB_TRANSFER_CANCELLED` has + * been called, as that might cause memory access violations. + * + * Returns: 0 on success, or the same errors as [libusb_cancel_transfer](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#ga685eb7731f9a0593f75beb99727bbe54) + * on failure. + */ +int +fpi_usb_cancel_transfer(fpi_usb_transfer *transfer) +{ + g_return_val_if_fail (transfer != NULL, LIBUSB_ERROR_NOT_FOUND); + + return libusb_cancel_transfer(transfer->transfer); +} diff --git a/libfprint/fpi-usb.h b/libfprint/fpi-usb.h index c966678e..625a7e7b 100644 --- a/libfprint/fpi-usb.h +++ b/libfprint/fpi-usb.h @@ -21,7 +21,51 @@ #define __FPI_USB_H__ #include +#include "fpi-dev.h" +#include "fpi-ssm.h" + +/** + * fpi_usb_transfer: + * + * A structure containing the arguments passed to fpi_usb_fill_bulk_transfer() + * to be used with fpi_usb_submit_transfer(). + */ +typedef struct fpi_usb_transfer fpi_usb_transfer; + +/** + * fpi_usb_transfer_cb_fn: + * @transfer: a struct #libusb_transfer + * @dev: the struct #fp_dev on which the operation was performed + * @ssm: the #fpi_ssm state machine + * @user_data: the user data passed to fpi_usb_fill_bulk_transfer() + * + * This callback will be called in response to a libusb bulk transfer + * triggered via fpi_usb_fill_bulk_transfer() finishing. Note that the + * struct #libusb_transfer does not need to be freed, as it will be + * freed after the callback returns, similarly to + * the [LIBUSB_TRANSFER_FREE_TRANSFER flag](http://libusb.sourceforge.net/api-1.0/group__asyncio.html#gga1fb47dd0f7c209b60a3609ff0c03d56dacf3f064997b283a14097c9f4d6f8ccc1). + * + * Note that the cancelled status of the transfer should be checked + * first thing, as the @dev, @ssm and @user_data pointers might not + * be pointing to valid values anymore. See fpi_usb_cancel_transfer() + * for more information. + */ +typedef void(*fpi_usb_transfer_cb_fn) (struct libusb_transfer *transfer, + struct fp_dev *dev, + fpi_ssm *ssm, + void *user_data); struct libusb_transfer *fpi_usb_alloc(void) __attribute__((returns_nonnull)); +fpi_usb_transfer *fpi_usb_fill_bulk_transfer (struct fp_dev *dev, + fpi_ssm *ssm, + unsigned char endpoint, + unsigned char *buffer, + int length, + fpi_usb_transfer_cb_fn callback, + void *user_data, + unsigned int timeout); +int fpi_usb_submit_transfer (fpi_usb_transfer *transfer); +int fpi_usb_cancel_transfer (fpi_usb_transfer *transfer); + #endif From 27accf42f2019d0364b50b2880fa58d3cdb37828 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 15:52:49 +0200 Subject: [PATCH 088/225] uru4000: Port URU4000 driver to USB helpers Doesn't look very useful. --- libfprint/drivers/uru4000.c | 127 ++++++++++++++++++++---------------- 1 file changed, 71 insertions(+), 56 deletions(-) diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 5064d545..845a1862 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -120,9 +120,10 @@ struct uru4k_dev { unsigned char last_reg_rd[16]; unsigned char last_hwstat; - struct libusb_transfer *irq_transfer; - struct libusb_transfer *img_transfer; + fpi_usb_transfer *irq_transfer; + fpi_usb_transfer *img_transfer; void *img_data; + int img_data_actual_length; uint16_t img_lines_done, img_block; uint32_t img_enc_seed; @@ -366,10 +367,13 @@ sm_do_challenge_response(fpi_ssm *ssm, static int start_irq_handler(struct fp_img_dev *dev); -static void irq_handler(struct libusb_transfer *transfer) +static void irq_handler(struct libusb_transfer *transfer, + struct fp_dev *_dev, + fpi_ssm *ssm, + void *user_data) { - struct fp_img_dev *dev = transfer->user_data; - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct fp_img_dev *dev = FP_IMG_DEV(_dev); + struct uru4k_dev *urudev = FP_INSTANCE_DATA(_dev); unsigned char *data = transfer->buffer; uint16_t type; int r = 0; @@ -391,8 +395,6 @@ static void irq_handler(struct libusb_transfer *transfer) type = GUINT16_FROM_BE(*((uint16_t *) data)); fp_dbg("recv irq type %04x", type); - g_free(data); - libusb_free_transfer(transfer); /* The 0800 interrupt seems to indicate imminent failure (0 bytes transfer) * of the next scan. It still appears on occasion. */ @@ -408,44 +410,43 @@ static void irq_handler(struct libusb_transfer *transfer) if (r == 0) return; - transfer = NULL; - data = NULL; err: if (urudev->irq_cb) urudev->irq_cb(dev, r, 0, urudev->irq_cb_data); out: - g_free(data); - libusb_free_transfer(transfer); urudev->irq_transfer = NULL; } static int start_irq_handler(struct fp_img_dev *dev) { struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); - struct libusb_transfer *transfer = fpi_usb_alloc(); + fpi_usb_transfer *transfer; unsigned char *data; int r; data = g_malloc(IRQ_LENGTH); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_INTR, data, IRQ_LENGTH, - irq_handler, dev, 0); + transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), + NULL, + EP_INTR, + data, + IRQ_LENGTH, + irq_handler, + NULL, + 0); urudev->irq_transfer = transfer; - r = libusb_submit_transfer(transfer); - if (r < 0) { - g_free(data); - libusb_free_transfer(transfer); + r = fpi_usb_submit_transfer(transfer); + if (r < 0) urudev->irq_transfer = NULL; - } return r; } static void stop_irq_handler(struct fp_img_dev *dev, irqs_stopped_cb_fn cb) { struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); - struct libusb_transfer *transfer = urudev->irq_transfer; + fpi_usb_transfer *transfer = urudev->irq_transfer; if (transfer) { - libusb_cancel_transfer(transfer); + fpi_usb_cancel_transfer(transfer); urudev->irqs_stopped_cb = cb; } } @@ -592,28 +593,6 @@ enum imaging_states { IMAGING_NUM_STATES }; -static void image_transfer_cb(struct libusb_transfer *transfer) -{ - fpi_ssm *ssm = transfer->user_data; - - if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { - fp_dbg("cancelled"); - fpi_ssm_mark_failed(ssm, -ECANCELED); - } else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { - fp_dbg("error"); - fpi_ssm_mark_failed(ssm, -EIO); - } else { - fpi_ssm_next_state(ssm); - } -} - -enum { - BLOCKF_CHANGE_KEY = 0x80, - BLOCKF_NO_KEY_UPDATE = 0x04, - BLOCKF_ENCRYPTED = 0x02, - BLOCKF_NOT_PRESENT = 0x01, -}; - struct uru4k_image { uint8_t unknown_00[4]; uint16_t num_lines; @@ -627,6 +606,33 @@ struct uru4k_image { uint8_t data[IMAGE_HEIGHT][IMAGE_WIDTH]; }; +static void image_transfer_cb(struct libusb_transfer *transfer, + struct fp_dev *dev, + fpi_ssm *ssm, + void *user_data) +{ + if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { + fp_dbg("cancelled"); + fpi_ssm_mark_failed(ssm, -ECANCELED); + } else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { + fp_dbg("error"); + fpi_ssm_mark_failed(ssm, -EIO); + } else { + struct uru4k_dev *urudev = FP_INSTANCE_DATA(dev); + + urudev->img_data = g_memdup(transfer->buffer, sizeof(struct uru4k_image)); + urudev->img_data_actual_length = transfer->actual_length; + fpi_ssm_next_state(ssm); + } +} + +enum { + BLOCKF_CHANGE_KEY = 0x80, + BLOCKF_NO_KEY_UPDATE = 0x04, + BLOCKF_ENCRYPTED = 0x02, + BLOCKF_NOT_PRESENT = 0x01, +}; + static uint32_t update_key(uint32_t key) { /* linear feedback shift register @@ -709,20 +715,20 @@ static void imaging_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data case IMAGING_CAPTURE: urudev->img_lines_done = 0; urudev->img_block = 0; - libusb_fill_bulk_transfer(urudev->img_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_DATA, - urudev->img_data, sizeof(struct uru4k_image), image_transfer_cb, ssm, 0); - r = libusb_submit_transfer(urudev->img_transfer); - if (r < 0) + r = fpi_usb_submit_transfer(urudev->img_transfer); + if (r < 0) { + urudev->img_transfer = NULL; fpi_ssm_mark_failed(ssm, -EIO); + } break; case IMAGING_SEND_INDEX: fp_dbg("hw header lines %d", img->num_lines); if (img->num_lines >= IMAGE_HEIGHT || - urudev->img_transfer->actual_length < img->num_lines * IMAGE_WIDTH + 64) { + urudev->img_data_actual_length < img->num_lines * IMAGE_WIDTH + 64) { fp_err("bad captured image (%d lines) or size mismatch %d < %d", img->num_lines, - urudev->img_transfer->actual_length, + urudev->img_data_actual_length, img->num_lines * IMAGE_WIDTH + 64); fpi_ssm_jump_to_state(ssm, IMAGING_CAPTURE); return; @@ -830,11 +836,12 @@ static void imaging_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) if (r) fpi_imgdev_session_error(dev, r); + /* Freed by callback or cancellation */ + urudev->img_transfer = NULL; + g_free(urudev->img_data); urudev->img_data = NULL; - - libusb_free_transfer(urudev->img_transfer); - urudev->img_transfer = NULL; + urudev->img_data_actual_length = 0; r = execute_state_change(dev); if (r) @@ -1205,6 +1212,7 @@ static int execute_state_change(struct fp_img_dev *dev) { struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); fpi_ssm *ssm; + void *img_data; switch (urudev->activate_state) { case IMGDEV_STATE_INACTIVE: @@ -1227,11 +1235,18 @@ static int execute_state_change(struct fp_img_dev *dev) fp_dbg("starting capture"); urudev->irq_cb = NULL; - urudev->img_transfer = fpi_usb_alloc(); - urudev->img_data = g_malloc(sizeof(struct uru4k_image)); - urudev->img_enc_seed = rand(); - ssm = fpi_ssm_new(FP_DEV(dev), imaging_run_state, IMAGING_NUM_STATES, dev); + img_data = g_malloc(sizeof(struct uru4k_image)); + urudev->img_enc_seed = rand(); + urudev->img_transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), + ssm, + EP_DATA, + img_data, + sizeof(struct uru4k_image), + image_transfer_cb, + NULL, + 0); + fpi_ssm_start(ssm, imaging_complete); return write_reg(dev, REG_MODE, MODE_CAPTURE, From bcc1e7ae7379899ef94295d3acbc1a38aa4fbacc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 26 Sep 2018 17:00:05 +0200 Subject: [PATCH 089/225] aes2501: Use USB helpers Nice little cleanups. --- libfprint/drivers/aes2501.c | 131 +++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c index d8a3c58a..2a031732 100644 --- a/libfprint/drivers/aes2501.c +++ b/libfprint/drivers/aes2501.c @@ -88,9 +88,12 @@ struct aes2501_read_regs { void *user_data; }; -static void read_regs_data_cb(struct libusb_transfer *transfer) +static void read_regs_data_cb(struct libusb_transfer *transfer, + struct fp_dev *dev, + fpi_ssm *ssm, + void *user_data) { - struct aes2501_read_regs *rdata = transfer->user_data; + struct aes2501_read_regs *rdata = user_data; unsigned char *retdata = NULL; int r; @@ -105,14 +108,12 @@ static void read_regs_data_cb(struct libusb_transfer *transfer) rdata->callback(rdata->dev, r, retdata, rdata->user_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_transfer *transfer; + fpi_usb_transfer *transfer; unsigned char *data; int r; @@ -120,15 +121,18 @@ static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data) if (result != 0) goto err; - transfer = fpi_usb_alloc(); data = g_malloc(READ_REGS_LEN); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, READ_REGS_LEN, - read_regs_data_cb, rdata, BULK_TIMEOUT); + transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), + NULL, + EP_IN, + data, + READ_REGS_LEN, + read_regs_data_cb, + rdata, + BULK_TIMEOUT); - r = libusb_submit_transfer(transfer); + r = fpi_usb_submit_transfer(transfer); if (r < 0) { - g_free(data); - libusb_free_transfer(transfer); result = -EIO; goto err; } @@ -188,39 +192,40 @@ 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(struct libusb_transfer *transfer) +static void generic_ignore_data_cb(struct libusb_transfer *transfer, + struct fp_dev *dev, + fpi_ssm *ssm, + void *user_data) { - fpi_ssm *ssm = transfer->user_data; - if (transfer->status != LIBUSB_TRANSFER_COMPLETED) fpi_ssm_mark_failed(ssm, -EIO); else if (transfer->length != transfer->actual_length) fpi_ssm_mark_failed(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(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes) { - struct libusb_transfer *transfer = fpi_usb_alloc(); + fpi_usb_transfer *transfer; unsigned char *data; int r; data = g_malloc(bytes); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes, - generic_ignore_data_cb, ssm, BULK_TIMEOUT); + transfer = fpi_usb_fill_bulk_transfer(dev, + ssm, + EP_IN, + data, + bytes, + generic_ignore_data_cb, + NULL, + BULK_TIMEOUT); - r = libusb_submit_transfer(transfer); - if (r < 0) { - g_free(data); - libusb_free_transfer(transfer); + r = fpi_usb_submit_transfer(transfer); + if (r < 0) fpi_ssm_mark_failed(ssm, r); - } } /****** IMAGE PROCESSING ******/ @@ -276,19 +281,22 @@ static const struct aes_regwrite finger_det_reqs[] = { static void start_finger_detection(struct fp_img_dev *dev); -static void finger_det_data_cb(struct libusb_transfer *transfer) +static void finger_det_data_cb(struct libusb_transfer *transfer, + struct fp_dev *_dev, + fpi_ssm *ssm, + void *user_data) { - struct fp_img_dev *dev = transfer->user_data; + struct fp_img_dev *dev = FP_IMG_DEV(_dev); unsigned char *data = transfer->buffer; int i; int sum = 0; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fpi_imgdev_session_error(dev, -EIO); - goto out; + return; } else if (transfer->length != transfer->actual_length) { fpi_imgdev_session_error(dev, -EPROTO); - goto out; + return; } /* examine histogram to determine finger presence */ @@ -302,16 +310,12 @@ static void finger_det_data_cb(struct libusb_transfer *transfer) /* no finger, poll for a new histogram */ start_finger_detection(dev); } - -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_transfer *transfer; + fpi_usb_transfer *transfer; unsigned char *data; int r; @@ -320,17 +324,19 @@ static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, return; } - transfer = fpi_usb_alloc(); data = g_malloc(FINGER_DETECTION_LEN); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, FINGER_DETECTION_LEN, - finger_det_data_cb, dev, BULK_TIMEOUT); + transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), + NULL, + EP_IN, + data, + FINGER_DETECTION_LEN, + finger_det_data_cb, + NULL, + BULK_TIMEOUT); - r = libusb_submit_transfer(transfer); - if (r < 0) { - g_free(data); - libusb_free_transfer(transfer); + r = fpi_usb_submit_transfer(transfer); + if (r < 0) fpi_imgdev_session_error(dev, r); - } } static void start_finger_detection(struct fp_img_dev *dev) @@ -422,35 +428,37 @@ enum capture_states { CAPTURE_NUM_STATES, }; -static void capture_read_strip_cb(struct libusb_transfer *transfer) +static void capture_read_strip_cb(struct libusb_transfer *transfer, + struct fp_dev *_dev, + fpi_ssm *ssm, + void *user_data) { unsigned char *stripdata; - fpi_ssm *ssm = transfer->user_data; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct fp_img_dev *dev = FP_IMG_DEV(_dev); + struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev); unsigned char *data = transfer->buffer; int sum; int threshold; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { fpi_ssm_mark_failed(ssm, -EIO); - goto out; + return; } else if (transfer->length != transfer->actual_length) { fpi_ssm_mark_failed(ssm, -EPROTO); - goto out; + return; } threshold = regval_from_dump(data + 1 + 192*8 + 1 + 16*2 + 1 + 8, AES2501_REG_DATFMT); if (threshold < 0) { fpi_ssm_mark_failed(ssm, threshold); - goto out; + return; } sum = sum_histogram_values(data + 1 + 192*8, threshold & 0x0f); if (sum < 0) { fpi_ssm_mark_failed(ssm, sum); - goto out; + return; } fp_dbg("sum=%d", sum); @@ -503,10 +511,6 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer) fpi_ssm_jump_to_state(ssm, CAPTURE_REQUEST_STRIP); } - -out: - g_free(data); - libusb_free_transfer(transfer); } static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) @@ -538,19 +542,22 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data generic_write_regv_cb, ssm); break; case CAPTURE_READ_STRIP: ; - struct libusb_transfer *transfer = fpi_usb_alloc(); + fpi_usb_transfer *transfer; unsigned char *data; data = g_malloc(STRIP_CAPTURE_LEN); - libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, data, STRIP_CAPTURE_LEN, - capture_read_strip_cb, ssm, BULK_TIMEOUT); + transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), + ssm, + EP_IN, + data, + STRIP_CAPTURE_LEN, + capture_read_strip_cb, + NULL, + BULK_TIMEOUT); - r = libusb_submit_transfer(transfer); - if (r < 0) { - g_free(data); - libusb_free_transfer(transfer); + r = fpi_usb_submit_transfer(transfer); + if (r < 0) fpi_ssm_mark_failed(ssm, r); - } break; }; } From 4b9b34fa4d1db2785c4813fc0beef353053898c0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 15:09:59 +0200 Subject: [PATCH 090/225] elan: Use USB helpers --- libfprint/drivers/elan.c | 51 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 66fd2404..2cb9f2d0 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -73,7 +73,7 @@ struct elan_dev { /* commands */ const struct elan_cmd *cmd; int cmd_timeout; - struct libusb_transfer *cur_transfer; + fpi_usb_transfer *cur_transfer; /* end commands */ /* state */ @@ -319,11 +319,13 @@ static void elan_cmd_done(fpi_ssm *ssm) fpi_ssm_next_state(ssm); } -static void elan_cmd_cb(struct libusb_transfer *transfer) +static void elan_cmd_cb(struct libusb_transfer *transfer, + struct fp_dev *_dev, + fpi_ssm *ssm, + void *user_data) { - fpi_ssm *ssm = transfer->user_data; - struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); - struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); + struct fp_img_dev *dev = FP_IMG_DEV(_dev); + struct elan_dev *elandev = FP_INSTANCE_DATA(_dev); G_DEBUG_HERE(); @@ -338,6 +340,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer) fpi_ssm_mark_failed(ssm, -EPROTO); } else if (transfer->endpoint & LIBUSB_ENDPOINT_IN) { /* just finished receiving */ + elandev->last_read = g_memdup(transfer->buffer, transfer->actual_length); dbg_buf(elandev->last_read, transfer->actual_length); elan_cmd_done(ssm); } else { @@ -366,6 +369,7 @@ static void elan_cmd_read(fpi_ssm *ssm, struct fp_img_dev *dev) { struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); int response_len = elandev->cmd->response_len; + unsigned char *buffer; G_DEBUG_HERE(); @@ -380,16 +384,18 @@ static void elan_cmd_read(fpi_ssm *ssm, struct fp_img_dev *dev) response_len = elandev->raw_frame_height * elandev->frame_width * 2; - elandev->cur_transfer = fpi_usb_alloc(); - g_free(elandev->last_read); - elandev->last_read = g_malloc(response_len); + g_clear_pointer(&elandev->last_read, g_free); + buffer = g_malloc(response_len); - libusb_fill_bulk_transfer(elandev->cur_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), - elandev->cmd->response_in, - elandev->last_read, response_len, elan_cmd_cb, - ssm, elandev->cmd_timeout); - elandev->cur_transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; - int r = libusb_submit_transfer(elandev->cur_transfer); + elandev->cur_transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), + ssm, + elandev->cmd->response_in, + buffer, + response_len, + elan_cmd_cb, + NULL, + elandev->cmd_timeout); + int r = fpi_usb_submit_transfer(elandev->cur_transfer); if (r < 0) fpi_ssm_mark_failed(ssm, r); } @@ -414,12 +420,15 @@ elan_run_cmd(fpi_ssm *ssm, return; } - elandev->cur_transfer = fpi_usb_alloc(); - libusb_fill_bulk_transfer(elandev->cur_transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), ELAN_EP_CMD_OUT, - (char *) cmd->cmd, ELAN_CMD_LEN, elan_cmd_cb, ssm, - elandev->cmd_timeout); - elandev->cur_transfer->flags = LIBUSB_TRANSFER_FREE_TRANSFER; - int r = libusb_submit_transfer(elandev->cur_transfer); + elandev->cur_transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), + ssm, + ELAN_EP_CMD_OUT, + g_memdup((char *) cmd->cmd, ELAN_CMD_LEN), + ELAN_CMD_LEN, + elan_cmd_cb, + NULL, + elandev->cmd_timeout); + int r = fpi_usb_submit_transfer(elandev->cur_transfer); if (r < 0) fpi_ssm_mark_failed(ssm, r); } @@ -849,7 +858,7 @@ static void elan_change_state(struct fp_img_dev *dev) case IMGDEV_STATE_INACTIVE: if (elandev->cur_transfer) /* deactivation will complete in transfer callback */ - libusb_cancel_transfer(elandev->cur_transfer); + fpi_usb_cancel_transfer(elandev->cur_transfer); else elan_deactivate(dev); break; From ebd96f892e2af2666f280b091cd31d4fd79a2dd1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 15:14:05 +0200 Subject: [PATCH 091/225] lib: Make fpi_timeout_add() never fail It will now assert if the monotonic clock isn't available. If that's the case, we'll have bigger problems anyway. --- libfprint/fpi-poll.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 623b154f..4edd4817 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -146,7 +146,9 @@ fpi_timeout_set_name(fpi_timeout *timeout, * * Note that you should hold onto the return value of this function to cancel it * use fpi_timeout_cancel(), otherwise the callback could be called while the driver - * is being torn down. %NULL is returned on failure. + * is being torn down. + * + * This function can be considered to never fail. * * Returns: an #fpi_timeout structure */ @@ -167,6 +169,7 @@ fpi_timeout *fpi_timeout_add(unsigned int msec, r = clock_gettime(CLOCK_MONOTONIC, &ts); if (r < 0) { fp_err("failed to read monotonic clock, errno=%d", errno); + BUG(); return NULL; } From e532524c7e4164b42b97e446ece7e82501e15968 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 15:17:15 +0200 Subject: [PATCH 092/225] elan: Name our timeouts --- libfprint/drivers/elan.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 2cb9f2d0..797c1a53 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -667,11 +667,13 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da elandev->calib_status = 0x03; fpi_ssm_jump_to_state(ssm, CALIBRATE_GET_BACKGROUND); } else { + fpi_timeout *timeout; + if (elandev->calib_status == 0x00 && elandev->last_read[0] == 0x01) elandev->calib_status = 0x01; - if (!fpi_timeout_add(50, fpi_ssm_next_state_timeout_cb, _dev, ssm)) - fpi_ssm_mark_failed(ssm, -ETIME); + timeout = fpi_timeout_add(50, fpi_ssm_next_state_timeout_cb, _dev, ssm); + fpi_timeout_set_name(timeout, "calibrate_run_state"); } break; case CALIBRATE_REPEAT_STATUS: @@ -880,27 +882,34 @@ static void elan_change_state_async(struct fp_dev *dev, void *data) { + g_message ("state change dev: %p", dev); elan_change_state(FP_IMG_DEV (dev)); } static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state) { struct elan_dev *elandev = FP_INSTANCE_DATA(FP_DEV(dev)); + fpi_timeout *timeout; G_DEBUG_HERE(); switch (state) { case IMGDEV_STATE_INACTIVE: case IMGDEV_STATE_AWAIT_FINGER_ON: - case IMGDEV_STATE_AWAIT_FINGER_OFF: + case IMGDEV_STATE_AWAIT_FINGER_OFF: { + char *name; + /* schedule state change instead of calling it directly to allow all actions * related to the previous state to complete */ elandev->dev_state_next = state; - if (!fpi_timeout_add(10, elan_change_state_async, FP_DEV(dev), NULL)) { - fpi_imgdev_session_error(dev, -ETIME); - return -ETIME; - } + timeout = fpi_timeout_add(10, elan_change_state_async, FP_DEV(dev), NULL); + + name = g_strdup_printf ("dev_change_state to %d", state); + fpi_timeout_set_name(timeout, name); + g_free (name); + break; + } case IMGDEV_STATE_CAPTURE: /* TODO MAYBE: split capture ssm into smaller ssms and use this state */ elandev->dev_state = state; From 0ace5f64f89388fddc52b777ff065f24c2d908e2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 15:19:00 +0200 Subject: [PATCH 093/225] elan: Fix use-after-free if USB transfer is cancelled --- libfprint/drivers/elan.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 797c1a53..a2c1105c 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -324,11 +324,18 @@ static void elan_cmd_cb(struct libusb_transfer *transfer, fpi_ssm *ssm, void *user_data) { - struct fp_img_dev *dev = FP_IMG_DEV(_dev); - struct elan_dev *elandev = FP_INSTANCE_DATA(_dev); + struct fp_img_dev *dev; + struct elan_dev *elandev; G_DEBUG_HERE(); + if (transfer->status == LIBUSB_TRANSFER_CANCELLED) { + fp_dbg("transfer cancelled"); + return; + } + + dev = FP_IMG_DEV(_dev); + elandev = FP_INSTANCE_DATA(_dev); elandev->cur_transfer = NULL; switch (transfer->status) { @@ -349,11 +356,6 @@ static void elan_cmd_cb(struct libusb_transfer *transfer, elan_cmd_read(ssm, dev); } break; - case LIBUSB_TRANSFER_CANCELLED: - fp_dbg("transfer cancelled"); - fpi_ssm_mark_failed(ssm, -ECANCELED); - elan_deactivate(dev); - break; case LIBUSB_TRANSFER_TIMED_OUT: fp_dbg("transfer timed out"); fpi_ssm_mark_failed(ssm, -ETIMEDOUT); From 1fd82b5162e510f501e9b6aabfe2879e1d26c956 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 16:07:58 +0200 Subject: [PATCH 094/225] lib: Mark fpi_ssm_get_user_data as deprecated --- libfprint/fpi-ssm.c | 3 +++ libfprint/fpi-ssm.h | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 20a5f2f9..e970c096 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -124,6 +124,9 @@ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, * is called. * * Returns: a pointer + * + * Deprecated: Make sure your asynchronous functions pass that + * @user_data along. */ void * fpi_ssm_get_user_data(fpi_ssm *machine) diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 709928c0..200a2ab3 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -28,6 +28,8 @@ #include #include +#include "fprint.h" + /* async drv <--> lib comms */ /** @@ -80,7 +82,7 @@ void fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, void *data); void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); void fpi_ssm_mark_completed(fpi_ssm *machine); void fpi_ssm_mark_failed(fpi_ssm *machine, int error); -void *fpi_ssm_get_user_data(fpi_ssm *machine); +void *fpi_ssm_get_user_data(fpi_ssm *machine) LIBFPRINT_DEPRECATED; int fpi_ssm_get_error(fpi_ssm *machine); int fpi_ssm_get_cur_state(fpi_ssm *machine); From 7cfe20e07fbe82e54409753f0b786917b4b13ba4 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 16:08:21 +0200 Subject: [PATCH 095/225] lib: Fix gtk-doc warning warning: no link for: "timeval" -> (timeval) --- libfprint/fpi-poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 4edd4817..e416c960 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -360,7 +360,7 @@ API_EXPORTED int fp_handle_events(void) /** * fp_get_next_timeout: - * @tv: a %timeval structure containing the duration to the next timeout. + * @tv: a #timeval structure containing the duration to the next timeout. * * A zero filled @tv timeout means events are to be handled immediately * From 36f527269b556e7fac8c63f4c714cab962e50605 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 14:26:12 +0200 Subject: [PATCH 096/225] Revert "lib: Mark fpi_ssm_get_user_data as deprecated" This reverts commit 1fd82b5162e510f501e9b6aabfe2879e1d26c956. This was causing too many warnings at this stage of porting. We'll add it again when most of the drivers are ported. --- libfprint/fpi-ssm.c | 3 --- libfprint/fpi-ssm.h | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index e970c096..20a5f2f9 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -124,9 +124,6 @@ fpi_ssm *fpi_ssm_new(struct fp_dev *dev, * is called. * * Returns: a pointer - * - * Deprecated: Make sure your asynchronous functions pass that - * @user_data along. */ void * fpi_ssm_get_user_data(fpi_ssm *machine) diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 200a2ab3..709928c0 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -28,8 +28,6 @@ #include #include -#include "fprint.h" - /* async drv <--> lib comms */ /** @@ -82,7 +80,7 @@ void fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, void *data); void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); void fpi_ssm_mark_completed(fpi_ssm *machine); void fpi_ssm_mark_failed(fpi_ssm *machine, int error); -void *fpi_ssm_get_user_data(fpi_ssm *machine) LIBFPRINT_DEPRECATED; +void *fpi_ssm_get_user_data(fpi_ssm *machine); int fpi_ssm_get_error(fpi_ssm *machine); int fpi_ssm_get_cur_state(fpi_ssm *machine); From ca06fae22e71a811a197edc69fab78348a8ff063 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 16:36:09 +0200 Subject: [PATCH 097/225] lib: Split off fpi_print_data helpers And rename data.c to fpi-data.c --- libfprint/drivers_api.h | 24 +----------------- libfprint/fp_internal.h | 33 +----------------------- libfprint/{data.c => fpi-data.c} | 13 ++++++++++ libfprint/fpi-data.h | 43 ++++++++++++++++++++++++++++++++ libfprint/meson.build | 3 ++- 5 files changed, 60 insertions(+), 56 deletions(-) rename libfprint/{data.c => fpi-data.c} (98%) create mode 100644 libfprint/fpi-data.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index a567c3cd..b61aa147 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -34,6 +34,7 @@ #include "fpi-poll.h" #include "fpi-dev.h" #include "fpi-usb.h" +#include "fpi-data.h" #include "assembling.h" #include "drivers/driver_ids.h" @@ -124,29 +125,6 @@ struct fp_img_driver { void (*deactivate)(struct fp_img_dev *dev); }; -enum fp_print_data_type { - PRINT_DATA_RAW = 0, /* memset-imposed default */ - PRINT_DATA_NBIS_MINUTIAE, -}; - -struct fp_print_data_item { - size_t length; - unsigned char data[0]; -}; - -struct fp_print_data { - uint16_t driver_id; - uint32_t devtype; - enum fp_print_data_type type; - GSList *prints; -}; - -struct fp_print_data *fpi_print_data_new(struct fp_dev *dev); -struct fp_print_data_item *fpi_print_data_item_new(size_t length); -gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1, - enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2, - enum fp_print_data_type type2); - struct fp_minutiae; /* bit values for fp_img.flags */ diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 7044a627..ab24df86 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -30,6 +30,7 @@ #include "fprint.h" #include "fpi-log.h" #include "fpi-dev.h" +#include "fpi-data.h" #include "drivers/driver_ids.h" #define container_of(ptr, type, member) ({ \ @@ -237,39 +238,7 @@ struct fp_dscv_print { char *path; }; -enum fp_print_data_type { - PRINT_DATA_RAW = 0, /* memset-imposed default */ - PRINT_DATA_NBIS_MINUTIAE, -}; - -struct fp_print_data_item { - size_t length; - unsigned char data[0]; -}; - -struct fp_print_data { - uint16_t driver_id; - uint32_t devtype; - enum fp_print_data_type type; - GSList *prints; -}; - -struct fpi_print_data_fp2 { - char prefix[3]; - uint16_t driver_id; - uint32_t devtype; - unsigned char data_type; - unsigned char data[0]; -} __attribute__((__packed__)); - -struct fpi_print_data_item_fp2 { - uint32_t length; - unsigned char data[0]; -} __attribute__((__packed__)); - void fpi_data_exit(void); -struct fp_print_data *fpi_print_data_new(struct fp_dev *dev); -struct fp_print_data_item *fpi_print_data_item_new(size_t length); gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1, enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2, enum fp_print_data_type type2); diff --git a/libfprint/data.c b/libfprint/fpi-data.c similarity index 98% rename from libfprint/data.c rename to libfprint/fpi-data.c index 62a5fea5..c2974a18 100644 --- a/libfprint/data.c +++ b/libfprint/fpi-data.c @@ -32,6 +32,19 @@ #define DIR_PERMS 0700 +struct fpi_print_data_fp2 { + char prefix[3]; + uint16_t driver_id; + uint32_t devtype; + unsigned char data_type; + unsigned char data[0]; +} __attribute__((__packed__)); + +struct fpi_print_data_item_fp2 { + uint32_t length; + unsigned char data[0]; +} __attribute__((__packed__)); + /** * SECTION: print_data * @title: Stored prints diff --git a/libfprint/fpi-data.h b/libfprint/fpi-data.h new file mode 100644 index 00000000..3ea27ddb --- /dev/null +++ b/libfprint/fpi-data.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_DATA_H__ +#define __FPI_DATA_H__ + +enum fp_print_data_type { + PRINT_DATA_RAW = 0, /* memset-imposed default */ + PRINT_DATA_NBIS_MINUTIAE +}; + +struct fp_print_data_item { + size_t length; + unsigned char data[0]; +}; + +struct fp_print_data { + uint16_t driver_id; + uint32_t devtype; + enum fp_print_data_type type; + GSList *prints; +}; + +struct fp_print_data *fpi_print_data_new(struct fp_dev *dev); +struct fp_print_data_item *fpi_print_data_item_new(size_t length); + +#endif diff --git a/libfprint/meson.build b/libfprint/meson.build index c4c32e02..1d9079e9 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -3,7 +3,8 @@ libfprint_sources = [ 'drivers_api.h', 'async.c', 'core.c', - 'data.c', + 'fpi-data.c', + 'fpi-data.h', 'fpi-dev.c', 'fpi-dev.h', 'fpi-log.h', From 1d1c34eb604488dd00700ca9de750938a1b36c81 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 16:37:45 +0200 Subject: [PATCH 098/225] lib: Make fpi_print_data_item_free() static --- libfprint/fpi-data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index c2974a18..f38bdf38 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -119,7 +119,7 @@ static struct fp_print_data *print_data_new(uint16_t driver_id, return data; } -void fpi_print_data_item_free(struct fp_print_data_item *item) +static void fpi_print_data_item_free(struct fp_print_data_item *item) { g_free(item); } From 2818d940109d81dcb39593e173ef9f1b02d8b7ea Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 16:49:20 +0200 Subject: [PATCH 099/225] lib: Split off fp_img helpers And rename img.c to fpi-img.c, as well as pixman.c to fpi-img-pixman.c --- libfprint/drivers_api.h | 26 +----------- libfprint/fp_internal.h | 24 +---------- libfprint/{pixman.c => fpi-img-pixman.c} | 0 libfprint/{img.c => fpi-img.c} | 0 libfprint/fpi-img.h | 51 ++++++++++++++++++++++++ libfprint/meson.build | 5 ++- 6 files changed, 56 insertions(+), 50 deletions(-) rename libfprint/{pixman.c => fpi-img-pixman.c} (100%) rename libfprint/{img.c => fpi-img.c} (100%) create mode 100644 libfprint/fpi-img.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index b61aa147..432f1e3f 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -35,6 +35,7 @@ #include "fpi-dev.h" #include "fpi-usb.h" #include "fpi-data.h" +#include "fpi-img.h" #include "assembling.h" #include "drivers/driver_ids.h" @@ -127,31 +128,6 @@ struct fp_img_driver { struct fp_minutiae; -/* bit values for fp_img.flags */ -#define FP_IMG_V_FLIPPED (1<<0) -#define FP_IMG_H_FLIPPED (1<<1) -#define FP_IMG_COLORS_INVERTED (1<<2) -#define FP_IMG_BINARIZED_FORM (1<<3) -#define FP_IMG_PARTIAL (1<<4) - -#define FP_IMG_STANDARDIZATION_FLAGS (FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED \ - | FP_IMG_COLORS_INVERTED) - -struct fp_img { - int width; - int height; - size_t length; - uint16_t flags; - struct fp_minutiae *minutiae; - unsigned char *binarized; - unsigned char data[0]; -}; - -struct fp_img *fpi_img_new(size_t length); -struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); -struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize); -struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); - void fpi_drvcb_open_complete(struct fp_dev *dev, int status); void fpi_drvcb_close_complete(struct fp_dev *dev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index ab24df86..deb520ab 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -31,6 +31,7 @@ #include "fpi-log.h" #include "fpi-dev.h" #include "fpi-data.h" +#include "fpi-img.h" #include "drivers/driver_ids.h" #define container_of(ptr, type, member) ({ \ @@ -264,28 +265,6 @@ struct fp_minutiae { struct fp_minutia **list; }; -/* bit values for fp_img.flags */ -#define FP_IMG_V_FLIPPED (1<<0) -#define FP_IMG_H_FLIPPED (1<<1) -#define FP_IMG_COLORS_INVERTED (1<<2) -#define FP_IMG_BINARIZED_FORM (1<<3) -#define FP_IMG_PARTIAL (1<<4) - -#define FP_IMG_STANDARDIZATION_FLAGS (FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED \ - | FP_IMG_COLORS_INVERTED) - -struct fp_img { - int width; - int height; - size_t length; - uint16_t flags; - struct fp_minutiae *minutiae; - unsigned char *binarized; - unsigned char data[0]; -}; - -struct fp_img *fpi_img_new(size_t length); -struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize); gboolean fpi_img_is_sane(struct fp_img *img); int fpi_img_to_print_data(struct fp_img_dev *imgdev, struct fp_img *img, struct fp_print_data **ret); @@ -293,7 +272,6 @@ int fpi_img_compare_print_data(struct fp_print_data *enrolled_print, struct fp_print_data *new_print); int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print, struct fp_print_data **gallery, int match_threshold, size_t *match_offset); -struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); /* polling */ void fpi_timeout_cancel_all_for_dev(struct fp_dev *dev); diff --git a/libfprint/pixman.c b/libfprint/fpi-img-pixman.c similarity index 100% rename from libfprint/pixman.c rename to libfprint/fpi-img-pixman.c diff --git a/libfprint/img.c b/libfprint/fpi-img.c similarity index 100% rename from libfprint/img.c rename to libfprint/fpi-img.c diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h new file mode 100644 index 00000000..87709ffe --- /dev/null +++ b/libfprint/fpi-img.h @@ -0,0 +1,51 @@ +/* + * Driver API definitions + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_IMG_H__ +#define __FPI_IMG_H__ + +#include + +/* bit values for fp_img.flags */ +#define FP_IMG_V_FLIPPED (1<<0) +#define FP_IMG_H_FLIPPED (1<<1) +#define FP_IMG_COLORS_INVERTED (1<<2) +#define FP_IMG_BINARIZED_FORM (1<<3) +#define FP_IMG_PARTIAL (1<<4) + +#define FP_IMG_STANDARDIZATION_FLAGS (FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED \ + | FP_IMG_COLORS_INVERTED) + +struct fp_img { + int width; + int height; + size_t length; + uint16_t flags; + struct fp_minutiae *minutiae; + unsigned char *binarized; + unsigned char data[0]; +}; + +struct fp_img *fpi_img_new(size_t length); +struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); +struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize); +struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); + +#endif diff --git a/libfprint/meson.build b/libfprint/meson.build index 1d9079e9..f25db93e 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -7,6 +7,8 @@ libfprint_sources = [ 'fpi-data.h', 'fpi-dev.c', 'fpi-dev.h', + 'fpi-img.c', + 'fpi-img.h', 'fpi-log.h', 'fpi-ssm.c', 'fpi-ssm.h', @@ -14,7 +16,6 @@ libfprint_sources = [ 'fpi-poll.c', 'fpi-usb.h', 'fpi-usb.c', - 'img.c', 'imgdev.c', 'sync.c', 'assembling.c', @@ -155,7 +156,7 @@ endif other_sources = [] if imaging_dep.found() - other_sources += [ 'pixman.c' ] + other_sources += [ 'fpi-img-pixman.c' ] endif libfprint_sources += configure_file(input: 'empty_file', From 1035f733aa2f539c3acff93925cef3edd7d2d90a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 27 Sep 2018 17:14:34 +0200 Subject: [PATCH 100/225] lib: Split off async functions And don't add the new fpi-async.h to the driver imports, it will only be used by the upekts driver. --- libfprint/drivers/upekts.c | 1 + libfprint/drivers_api.h | 23 -------------- libfprint/fp_internal.h | 31 ++----------------- libfprint/{async.c => fpi-async.c} | 1 + libfprint/fpi-async.h | 49 ++++++++++++++++++++++++++++++ libfprint/imgdev.c | 1 + libfprint/meson.build | 3 +- 7 files changed, 57 insertions(+), 52 deletions(-) rename libfprint/{async.c => fpi-async.c} (99%) create mode 100644 libfprint/fpi-async.h diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index 47eb0d2e..b930863b 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -28,6 +28,7 @@ #define FP_COMPONENT "upekts" #include "drivers_api.h" +#include "fpi-async.h" #include "upek_proto.h" #define EP_IN (1 | LIBUSB_ENDPOINT_IN) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 432f1e3f..4df20601 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -128,29 +128,6 @@ struct fp_img_driver { struct fp_minutiae; -void fpi_drvcb_open_complete(struct fp_dev *dev, int status); -void fpi_drvcb_close_complete(struct fp_dev *dev); - -void fpi_drvcb_enroll_started(struct fp_dev *dev, int status); -void fpi_drvcb_enroll_stage_completed(struct fp_dev *dev, int result, - struct fp_print_data *data, struct fp_img *img); -void fpi_drvcb_enroll_stopped(struct fp_dev *dev); - -void fpi_drvcb_verify_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_verify_result(struct fp_dev *dev, int result, - struct fp_img *img); -void fpi_drvcb_verify_stopped(struct fp_dev *dev); - -void fpi_drvcb_identify_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, - size_t match_offset, struct fp_img *img); -void fpi_drvcb_identify_stopped(struct fp_dev *dev); - -void fpi_drvcb_capture_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_capture_result(struct fp_dev *dev, int result, - struct fp_img *img); -void fpi_drvcb_capture_stopped(struct fp_dev *dev); - /* for image drivers */ void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status); void fpi_imgdev_close_complete(struct fp_img_dev *imgdev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index deb520ab..8ab87112 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -34,10 +34,6 @@ #include "fpi-img.h" #include "drivers/driver_ids.h" -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - enum fp_dev_state { DEV_STATE_INITIAL = 0, DEV_STATE_ERROR, @@ -222,6 +218,9 @@ extern GSList *opened_devices; void fpi_img_driver_setup(struct fp_img_driver *idriver); +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) #define fpi_driver_to_img_driver(drv) \ container_of((drv), struct fp_img_driver, driver) @@ -278,28 +277,4 @@ void fpi_timeout_cancel_all_for_dev(struct fp_dev *dev); void fpi_poll_init(void); void fpi_poll_exit(void); -void fpi_drvcb_open_complete(struct fp_dev *dev, int status); -void fpi_drvcb_close_complete(struct fp_dev *dev); - -void fpi_drvcb_enroll_started(struct fp_dev *dev, int status); -void fpi_drvcb_enroll_stage_completed(struct fp_dev *dev, int result, - struct fp_print_data *data, struct fp_img *img); -void fpi_drvcb_enroll_stopped(struct fp_dev *dev); - -void fpi_drvcb_verify_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_verify_result(struct fp_dev *dev, int result, - struct fp_img *img); -void fpi_drvcb_verify_stopped(struct fp_dev *dev); - -void fpi_drvcb_identify_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, - size_t match_offset, struct fp_img *img); -void fpi_drvcb_identify_stopped(struct fp_dev *dev); - -void fpi_drvcb_capture_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_capture_result(struct fp_dev *dev, int result, - struct fp_img *img); -void fpi_drvcb_capture_stopped(struct fp_dev *dev); - #endif - diff --git a/libfprint/async.c b/libfprint/fpi-async.c similarity index 99% rename from libfprint/async.c rename to libfprint/fpi-async.c index 7a9cd0cf..cce0dca3 100644 --- a/libfprint/async.c +++ b/libfprint/fpi-async.c @@ -20,6 +20,7 @@ #define FP_COMPONENT "async" #include "fp_internal.h" +#include "fpi-async.h" #include #include diff --git a/libfprint/fpi-async.h b/libfprint/fpi-async.h new file mode 100644 index 00000000..120a7c76 --- /dev/null +++ b/libfprint/fpi-async.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_ASYNC_H__ +#define __FPI_ASYNC_H__ + +#include "fpi-dev.h" +#include "fpi-data.h" + +void fpi_drvcb_open_complete(struct fp_dev *dev, int status); +void fpi_drvcb_close_complete(struct fp_dev *dev); + +void fpi_drvcb_enroll_started(struct fp_dev *dev, int status); +void fpi_drvcb_enroll_stage_completed(struct fp_dev *dev, int result, + struct fp_print_data *data, struct fp_img *img); +void fpi_drvcb_enroll_stopped(struct fp_dev *dev); + +void fpi_drvcb_verify_started(struct fp_dev *dev, int status); +void fpi_drvcb_report_verify_result(struct fp_dev *dev, int result, + struct fp_img *img); +void fpi_drvcb_verify_stopped(struct fp_dev *dev); + +void fpi_drvcb_identify_started(struct fp_dev *dev, int status); +void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, + size_t match_offset, struct fp_img *img); +void fpi_drvcb_identify_stopped(struct fp_dev *dev); + +void fpi_drvcb_capture_started(struct fp_dev *dev, int status); +void fpi_drvcb_report_capture_result(struct fp_dev *dev, int result, + struct fp_img *img); +void fpi_drvcb_capture_stopped(struct fp_dev *dev); + +#endif diff --git a/libfprint/imgdev.c b/libfprint/imgdev.c index 605f6ce5..ac5de83b 100644 --- a/libfprint/imgdev.c +++ b/libfprint/imgdev.c @@ -22,6 +22,7 @@ #include #include "fp_internal.h" +#include "fpi-async.h" #define MIN_ACCEPTABLE_MINUTIAE 10 #define BOZORTH3_DEFAULT_THRESHOLD 40 diff --git a/libfprint/meson.build b/libfprint/meson.build index f25db93e..b5e489e1 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -1,7 +1,8 @@ libfprint_sources = [ 'fp_internal.h', 'drivers_api.h', - 'async.c', + 'fpi-async.c', + 'fpi-async.h', 'core.c', 'fpi-data.c', 'fpi-data.h', From aca2cd41d89199297cdb240bf32a2899a4e10cb0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 11:29:07 +0200 Subject: [PATCH 101/225] lib: Rename sync.c to fpi-sync.c All the functions there are public, so no matching header. --- libfprint/{sync.c => fpi-sync.c} | 0 libfprint/meson.build | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename libfprint/{sync.c => fpi-sync.c} (100%) diff --git a/libfprint/sync.c b/libfprint/fpi-sync.c similarity index 100% rename from libfprint/sync.c rename to libfprint/fpi-sync.c diff --git a/libfprint/meson.build b/libfprint/meson.build index b5e489e1..46ee9178 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -13,12 +13,12 @@ libfprint_sources = [ 'fpi-log.h', 'fpi-ssm.c', 'fpi-ssm.h', + 'fpi-sync.c', 'fpi-poll.h', 'fpi-poll.c', 'fpi-usb.h', 'fpi-usb.c', 'imgdev.c', - 'sync.c', 'assembling.c', 'assembling.h', 'drivers/driver_ids.h', From 1d93b86569744b6026fbc7495054580bb7d6a2bf Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 11:32:09 +0200 Subject: [PATCH 102/225] lib: Rename assembling.[ch] This is already self-contained. --- libfprint/drivers/aeslib.c | 2 +- libfprint/drivers_api.h | 2 +- libfprint/{assembling.c => fpi-assembling.c} | 2 +- libfprint/{assembling.h => fpi-assembling.h} | 6 ++---- libfprint/meson.build | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) rename libfprint/{assembling.c => fpi-assembling.c} (99%) rename libfprint/{assembling.h => fpi-assembling.h} (93%) diff --git a/libfprint/drivers/aeslib.c b/libfprint/drivers/aeslib.c index 32725406..9942f9e0 100644 --- a/libfprint/drivers/aeslib.c +++ b/libfprint/drivers/aeslib.c @@ -27,7 +27,7 @@ #include #include "fpi-usb.h" -#include "assembling.h" +#include "fpi-assembling.h" #include "aeslib.h" #define MAX_REGWRITES_PER_REQUEST 16 diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 4df20601..f65defd5 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -36,7 +36,7 @@ #include "fpi-usb.h" #include "fpi-data.h" #include "fpi-img.h" -#include "assembling.h" +#include "fpi-assembling.h" #include "drivers/driver_ids.h" libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); diff --git a/libfprint/assembling.c b/libfprint/fpi-assembling.c similarity index 99% rename from libfprint/assembling.c rename to libfprint/fpi-assembling.c index 7ff941c5..c192c8fa 100644 --- a/libfprint/assembling.c +++ b/libfprint/fpi-assembling.c @@ -29,7 +29,7 @@ #include #include -#include "assembling.h" +#include "fpi-assembling.h" static unsigned int calc_error(struct fpi_frame_asmbl_ctx *ctx, struct fpi_frame *first_frame, diff --git a/libfprint/assembling.h b/libfprint/fpi-assembling.h similarity index 93% rename from libfprint/assembling.h rename to libfprint/fpi-assembling.h index 5c1c9988..c0e2b09d 100644 --- a/libfprint/assembling.h +++ b/libfprint/fpi-assembling.h @@ -1,6 +1,4 @@ /* - * Image assembling routines - * Shared functions between libfprint Authentec drivers * Copyright (C) 2007 Daniel Drake * Copyright (C) 2015 Vasily Khoruzhick * @@ -19,8 +17,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __ASSEMBLING_H__ -#define __ASSEMBLING_H__ +#ifndef __FPI_ASSEMBLING_H__ +#define __FPI_ASSEMBLING_H__ #include diff --git a/libfprint/meson.build b/libfprint/meson.build index 46ee9178..f00d005b 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -4,6 +4,8 @@ libfprint_sources = [ 'fpi-async.c', 'fpi-async.h', 'core.c', + 'fpi-assembling.c', + 'fpi-assembling.h', 'fpi-data.c', 'fpi-data.h', 'fpi-dev.c', @@ -19,8 +21,6 @@ libfprint_sources = [ 'fpi-usb.h', 'fpi-usb.c', 'imgdev.c', - 'assembling.c', - 'assembling.h', 'drivers/driver_ids.h', ] From 3a9500be6753fcdb13d05f61c2ac282bc4436619 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 11:48:59 +0200 Subject: [PATCH 103/225] lib: Move fpi-img utils to fpi-img's header --- libfprint/drivers_api.h | 4 ---- libfprint/fpi-img.h | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index f65defd5..7edc3978 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -139,9 +139,5 @@ void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img); void fpi_imgdev_abort_scan(struct fp_img_dev *imgdev, int result); void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error); -/* utils */ -int fpi_std_sq_dev(const unsigned char *buf, int size); -int fpi_mean_sq_diff_norm(unsigned char *buf1, unsigned char *buf2, int size); - #endif diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h index 87709ffe..616db3fa 100644 --- a/libfprint/fpi-img.h +++ b/libfprint/fpi-img.h @@ -1,5 +1,4 @@ /* - * Driver API definitions * Copyright (C) 2007-2008 Daniel Drake * Copyright (C) 2018 Bastien Nocera * @@ -48,4 +47,7 @@ struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize); struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); +int fpi_std_sq_dev(const unsigned char *buf, int size); +int fpi_mean_sq_diff_norm(unsigned char *buf1, unsigned char *buf2, int size); + #endif From fcd3c1dd895f45d4d9937c502580ec1dd0351fbc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 12:07:40 +0200 Subject: [PATCH 104/225] lib: Split off core.c drivers API --- libfprint/drivers_api.h | 5 +---- libfprint/{core.c => fpi-core.c} | 0 libfprint/fpi-core.h | 26 ++++++++++++++++++++++++++ libfprint/meson.build | 3 ++- 4 files changed, 29 insertions(+), 5 deletions(-) rename libfprint/{core.c => fpi-core.c} (100%) create mode 100644 libfprint/fpi-core.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 7edc3978..453f34fb 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -30,6 +30,7 @@ #include "fprint.h" #include "fpi-log.h" +#include "fpi-core.h" #include "fpi-ssm.h" #include "fpi-poll.h" #include "fpi-dev.h" @@ -39,10 +40,6 @@ #include "fpi-assembling.h" #include "drivers/driver_ids.h" -libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); -void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, int nr_enroll_stages); -struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev); - enum fp_imgdev_state { IMGDEV_STATE_INACTIVE, IMGDEV_STATE_AWAIT_FINGER_ON, diff --git a/libfprint/core.c b/libfprint/fpi-core.c similarity index 100% rename from libfprint/core.c rename to libfprint/fpi-core.c diff --git a/libfprint/fpi-core.h b/libfprint/fpi-core.h new file mode 100644 index 00000000..1c7b5d7d --- /dev/null +++ b/libfprint/fpi-core.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); +void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, + int nr_enroll_stages); +struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev); diff --git a/libfprint/meson.build b/libfprint/meson.build index f00d005b..260ca6be 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -3,9 +3,10 @@ libfprint_sources = [ 'drivers_api.h', 'fpi-async.c', 'fpi-async.h', - 'core.c', 'fpi-assembling.c', 'fpi-assembling.h', + 'fpi-core.c', + 'fpi-core.h', 'fpi-data.c', 'fpi-data.h', 'fpi-dev.c', From fb5527c58c5c0ea681b8c8be2bdca4a9c315c623 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 13:09:53 +0200 Subject: [PATCH 105/225] lib: Split off imgdev functions They now live in fpi-dev-img.[ch] --- libfprint/drivers_api.h | 42 +--------------- libfprint/fp_internal.h | 31 +----------- libfprint/{imgdev.c => fpi-dev-img.c} | 3 +- libfprint/fpi-dev-img.h | 71 +++++++++++++++++++++++++++ libfprint/meson.build | 3 +- 5 files changed, 77 insertions(+), 73 deletions(-) rename libfprint/{imgdev.c => fpi-dev-img.c} (99%) create mode 100644 libfprint/fpi-dev-img.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 453f34fb..27bd9988 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -30,6 +30,7 @@ #include "fprint.h" #include "fpi-log.h" +#include "fpi-dev-img.h" #include "fpi-core.h" #include "fpi-ssm.h" #include "fpi-poll.h" @@ -40,38 +41,6 @@ #include "fpi-assembling.h" #include "drivers/driver_ids.h" -enum fp_imgdev_state { - IMGDEV_STATE_INACTIVE, - IMGDEV_STATE_AWAIT_FINGER_ON, - IMGDEV_STATE_CAPTURE, - IMGDEV_STATE_AWAIT_FINGER_OFF, -}; - -enum fp_imgdev_action { - IMG_ACTION_NONE = 0, - IMG_ACTION_ENROLL, - IMG_ACTION_VERIFY, - IMG_ACTION_IDENTIFY, - IMG_ACTION_CAPTURE, -}; - -enum fp_imgdev_enroll_state { - IMG_ACQUIRE_STATE_NONE = 0, - IMG_ACQUIRE_STATE_ACTIVATING, - IMG_ACQUIRE_STATE_AWAIT_FINGER_ON, - IMG_ACQUIRE_STATE_AWAIT_IMAGE, - IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF, - IMG_ACQUIRE_STATE_DONE, - IMG_ACQUIRE_STATE_DEACTIVATING, -}; - -enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev); -enum fp_imgdev_action fpi_imgdev_get_action(struct fp_img_dev *imgdev); -int fpi_imgdev_get_action_result(struct fp_img_dev *imgdev); -void fpi_imgdev_set_action_result(struct fp_img_dev *imgdev, int action_result); -int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev); -int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev); - struct usb_id { uint16_t vendor; uint16_t product; @@ -126,15 +95,6 @@ struct fp_img_driver { struct fp_minutiae; /* for image drivers */ -void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status); -void fpi_imgdev_close_complete(struct fp_img_dev *imgdev); -void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status); -void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev); -void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, - gboolean present); -void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img); -void fpi_imgdev_abort_scan(struct fp_img_dev *imgdev, int result); -void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error); #endif diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 8ab87112..dca072fb 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -30,6 +30,7 @@ #include "fprint.h" #include "fpi-log.h" #include "fpi-dev.h" +#include "fpi-dev-img.h" #include "fpi-data.h" #include "fpi-img.h" #include "drivers/driver_ids.h" @@ -109,36 +110,6 @@ struct fp_dev { struct fp_print_data **identify_gallery; }; -enum fp_imgdev_state { - IMGDEV_STATE_INACTIVE, - IMGDEV_STATE_AWAIT_FINGER_ON, - IMGDEV_STATE_CAPTURE, - IMGDEV_STATE_AWAIT_FINGER_OFF, -}; - -enum fp_imgdev_action { - IMG_ACTION_NONE = 0, - IMG_ACTION_ENROLL, - IMG_ACTION_VERIFY, - IMG_ACTION_IDENTIFY, - IMG_ACTION_CAPTURE, -}; - -enum fp_imgdev_enroll_state { - IMG_ACQUIRE_STATE_NONE = 0, - IMG_ACQUIRE_STATE_ACTIVATING, - IMG_ACQUIRE_STATE_AWAIT_FINGER_ON, - IMG_ACQUIRE_STATE_AWAIT_IMAGE, - IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF, - IMG_ACQUIRE_STATE_DONE, - IMG_ACQUIRE_STATE_DEACTIVATING, -}; - -enum fp_imgdev_verify_state { - IMG_VERIFY_STATE_NONE = 0, - IMG_VERIFY_STATE_ACTIVATING -}; - struct fp_img_dev { struct fp_dev *parent; diff --git a/libfprint/imgdev.c b/libfprint/fpi-dev-img.c similarity index 99% rename from libfprint/imgdev.c rename to libfprint/fpi-dev-img.c index ac5de83b..a61e13c4 100644 --- a/libfprint/imgdev.c +++ b/libfprint/fpi-dev-img.c @@ -21,8 +21,9 @@ #include -#include "fp_internal.h" +#include "fpi-dev-img.h" #include "fpi-async.h" +#include "fp_internal.h" #define MIN_ACCEPTABLE_MINUTIAE 10 #define BOZORTH3_DEFAULT_THRESHOLD 40 diff --git a/libfprint/fpi-dev-img.h b/libfprint/fpi-dev-img.h new file mode 100644 index 00000000..15d68e89 --- /dev/null +++ b/libfprint/fpi-dev-img.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_DEV_IMG_H__ +#define __FPI_DEV_IMG_H__ + +#include "fpi-dev.h" +#include "fpi-img.h" + +enum fp_imgdev_action { + IMG_ACTION_NONE = 0, + IMG_ACTION_ENROLL, + IMG_ACTION_VERIFY, + IMG_ACTION_IDENTIFY, + IMG_ACTION_CAPTURE, +}; + +enum fp_imgdev_state { + IMGDEV_STATE_INACTIVE, + IMGDEV_STATE_AWAIT_FINGER_ON, + IMGDEV_STATE_CAPTURE, + IMGDEV_STATE_AWAIT_FINGER_OFF, +}; + +enum fp_imgdev_enroll_state { + IMG_ACQUIRE_STATE_NONE = 0, + IMG_ACQUIRE_STATE_ACTIVATING, + IMG_ACQUIRE_STATE_AWAIT_FINGER_ON, + IMG_ACQUIRE_STATE_AWAIT_IMAGE, + IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF, + IMG_ACQUIRE_STATE_DONE, + IMG_ACQUIRE_STATE_DEACTIVATING, +}; + +enum fp_imgdev_verify_state { + IMG_VERIFY_STATE_NONE = 0, + IMG_VERIFY_STATE_ACTIVATING +}; + +void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status); +void fpi_imgdev_close_complete(struct fp_img_dev *imgdev); +void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status); +void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev); +void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, + gboolean present); +void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img); +void fpi_imgdev_abort_scan(struct fp_img_dev *imgdev, int result); +void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error); + +enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev); +enum fp_imgdev_action fpi_imgdev_get_action(struct fp_img_dev *imgdev); +int fpi_imgdev_get_action_result(struct fp_img_dev *imgdev); +void fpi_imgdev_set_action_result(struct fp_img_dev *imgdev, int action_result); + +#endif diff --git a/libfprint/meson.build b/libfprint/meson.build index 260ca6be..ce761bab 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -11,6 +11,8 @@ libfprint_sources = [ 'fpi-data.h', 'fpi-dev.c', 'fpi-dev.h', + 'fpi-dev-img.c', + 'fpi-dev-img.h', 'fpi-img.c', 'fpi-img.h', 'fpi-log.h', @@ -21,7 +23,6 @@ libfprint_sources = [ 'fpi-poll.c', 'fpi-usb.h', 'fpi-usb.c', - 'imgdev.c', 'drivers/driver_ids.h', ] From a99f920fe0aa6c10e82cbeee9eddec4a1b62ee6b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 13:34:00 +0200 Subject: [PATCH 106/225] lib: Add include guards to fpi-poll.h --- libfprint/fpi-poll.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 42214b61..748641b9 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -18,6 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef __FPI_POLL_H__ +#define __FPI_POLL_H__ + #include "fprint.h" /** @@ -45,3 +48,5 @@ fpi_timeout *fpi_timeout_add(unsigned int msec, void fpi_timeout_set_name(fpi_timeout *timeout, const char *name); void fpi_timeout_cancel(fpi_timeout *timeout); + +#endif From d3aaebb35240089b8f84e79a76c45dd5697e665d Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 13:40:03 +0200 Subject: [PATCH 107/225] lib: Add include guards to fpi-dev.h --- libfprint/fpi-dev.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libfprint/fpi-dev.h b/libfprint/fpi-dev.h index dc0cd60f..b9949ce3 100644 --- a/libfprint/fpi-dev.h +++ b/libfprint/fpi-dev.h @@ -17,6 +17,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef __FPI_DEV_H__ +#define __FPI_DEV_H__ + struct fp_dev; /** @@ -33,3 +36,5 @@ struct fp_img_dev *FP_IMG_DEV (struct fp_dev *dev); void fp_dev_set_instance_data (struct fp_dev *dev, void *instance_data); void *FP_INSTANCE_DATA (struct fp_dev *dev); + +#endif From 5b9f81fb467e2c4ba124fcb1c3764efa9d5344dd Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 13:41:43 +0200 Subject: [PATCH 108/225] lib: Move fp_dev helpers to fpi-dev.h from fpi-core.h --- libfprint/fpi-core.c | 19 ------------------- libfprint/fpi-core.h | 4 ---- libfprint/fpi-dev.c | 19 +++++++++++++++++++ libfprint/fpi-dev.h | 8 ++++++++ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/libfprint/fpi-core.c b/libfprint/fpi-core.c index 0a650c33..8009fe19 100644 --- a/libfprint/fpi-core.c +++ b/libfprint/fpi-core.c @@ -528,25 +528,6 @@ API_EXPORTED int fp_dev_supports_dscv_print(struct fp_dev *dev, 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_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; -} - /** * fp_driver_get_name: * @drv: the driver diff --git a/libfprint/fpi-core.h b/libfprint/fpi-core.h index 1c7b5d7d..f350d46f 100644 --- a/libfprint/fpi-core.h +++ b/libfprint/fpi-core.h @@ -20,7 +20,3 @@ #include #include -libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); -void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, - int nr_enroll_stages); -struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev); diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index 59bffa9a..f97ee61d 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -96,3 +96,22 @@ FP_INSTANCE_DATA (struct fp_dev *dev) return dev->instance_data; } + +libusb_device_handle * +fpi_dev_get_usb_dev(struct fp_dev *dev) +{ + return dev->udev; +} + +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; +} diff --git a/libfprint/fpi-dev.h b/libfprint/fpi-dev.h index b9949ce3..6c50956b 100644 --- a/libfprint/fpi-dev.h +++ b/libfprint/fpi-dev.h @@ -20,6 +20,9 @@ #ifndef __FPI_DEV_H__ #define __FPI_DEV_H__ +#include +#include + struct fp_dev; /** @@ -37,4 +40,9 @@ void fp_dev_set_instance_data (struct fp_dev *dev, void *instance_data); void *FP_INSTANCE_DATA (struct fp_dev *dev); +libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); +void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, + int nr_enroll_stages); +struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev); + #endif From a59a5caaf3350ebfefb63dc515580bd5535f36ff Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 13:43:41 +0200 Subject: [PATCH 109/225] lib: Add missing includes Headers for size_t and ssize_t, as used in the header itself. --- libfprint/fprint.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 26248cc3..ede569b7 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -25,6 +25,8 @@ extern "C" { #endif #include +#include +#include #include #define LIBFPRINT_DEPRECATED __attribute__((__deprecated__)) From e90ec044415a6f027d8c8951b0e0fea3264f0eec Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 13:45:05 +0200 Subject: [PATCH 110/225] lib: Move fp_minutiae to fpi-img.h --- libfprint/drivers_api.h | 4 ---- libfprint/fpi-img.h | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 27bd9988..9dd29fc3 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -92,9 +92,5 @@ struct fp_img_driver { void (*deactivate)(struct fp_img_dev *dev); }; -struct fp_minutiae; - -/* for image drivers */ - #endif diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h index 616db3fa..4a57be28 100644 --- a/libfprint/fpi-img.h +++ b/libfprint/fpi-img.h @@ -22,6 +22,8 @@ #include +struct fp_minutiae; + /* bit values for fp_img.flags */ #define FP_IMG_V_FLIPPED (1<<0) #define FP_IMG_H_FLIPPED (1<<1) From 13bfe7a65c3c4f683d093fdc073320416a42e74d Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 13:46:52 +0200 Subject: [PATCH 111/225] lib: Move driver definitions to fpi-core.h --- libfprint/drivers_api.h | 57 ----------------------------------------- libfprint/fpi-core.h | 56 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 58 deletions(-) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 9dd29fc3..84b7a682 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -22,11 +22,6 @@ #define __DRIVERS_API_H__ #include -#include -#include -#include -#include -#include #include "fprint.h" #include "fpi-log.h" @@ -41,56 +36,4 @@ #include "fpi-assembling.h" #include "drivers/driver_ids.h" -struct usb_id { - uint16_t vendor; - uint16_t product; - unsigned long driver_data; -}; - -enum fp_driver_type { - DRIVER_PRIMITIVE = 0, - DRIVER_IMAGING = 1, -}; - -struct fp_driver { - const uint16_t id; - const char *name; - const char *full_name; - const struct usb_id * const id_table; - enum fp_driver_type type; - enum fp_scan_type scan_type; - - /* Device operations */ - int (*discover)(struct libusb_device_descriptor *dsc, uint32_t *devtype); - int (*open)(struct fp_dev *dev, unsigned long driver_data); - void (*close)(struct fp_dev *dev); - int (*enroll_start)(struct fp_dev *dev); - int (*enroll_stop)(struct fp_dev *dev); - int (*verify_start)(struct fp_dev *dev); - int (*verify_stop)(struct fp_dev *dev, gboolean iterating); - int (*identify_start)(struct fp_dev *dev); - int (*identify_stop)(struct fp_dev *dev, gboolean iterating); - int (*capture_start)(struct fp_dev *dev); - int (*capture_stop)(struct fp_dev *dev); -}; - -/* flags for fp_img_driver.flags */ -#define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0) - -struct fp_img_driver { - struct fp_driver driver; - uint16_t flags; - int img_width; - int img_height; - int bz3_threshold; - - /* Device operations */ - int (*open)(struct fp_img_dev *dev, unsigned long driver_data); - void (*close)(struct fp_img_dev *dev); - int (*activate)(struct fp_img_dev *dev, enum fp_imgdev_state state); - int (*change_state)(struct fp_img_dev *dev, enum fp_imgdev_state state); - void (*deactivate)(struct fp_img_dev *dev); -}; - #endif - diff --git a/libfprint/fpi-core.h b/libfprint/fpi-core.h index f350d46f..cbc2255d 100644 --- a/libfprint/fpi-core.h +++ b/libfprint/fpi-core.h @@ -17,6 +17,60 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#ifndef __FPI_CORE_H__ +#define __FPI_CORE_H__ + #include +struct usb_id { + uint16_t vendor; + uint16_t product; + unsigned long driver_data; +}; + +enum fp_driver_type { + DRIVER_PRIMITIVE = 0, + DRIVER_IMAGING = 1, +}; + +struct fp_driver { + const uint16_t id; + const char *name; + const char *full_name; + const struct usb_id * const id_table; + enum fp_driver_type type; + enum fp_scan_type scan_type; + + /* Device operations */ + int (*discover)(struct libusb_device_descriptor *dsc, uint32_t *devtype); + int (*open)(struct fp_dev *dev, unsigned long driver_data); + void (*close)(struct fp_dev *dev); + int (*enroll_start)(struct fp_dev *dev); + int (*enroll_stop)(struct fp_dev *dev); + int (*verify_start)(struct fp_dev *dev); + int (*verify_stop)(struct fp_dev *dev, gboolean iterating); + int (*identify_start)(struct fp_dev *dev); + int (*identify_stop)(struct fp_dev *dev, gboolean iterating); + int (*capture_start)(struct fp_dev *dev); + int (*capture_stop)(struct fp_dev *dev); +}; + +/* flags for fp_img_driver.flags */ +#define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0) + +struct fp_img_driver { + struct fp_driver driver; + uint16_t flags; + int img_width; + int img_height; + int bz3_threshold; + + /* Device operations */ + int (*open)(struct fp_img_dev *dev, unsigned long driver_data); + void (*close)(struct fp_img_dev *dev); + int (*activate)(struct fp_img_dev *dev, enum fp_imgdev_state state); + int (*change_state)(struct fp_img_dev *dev, enum fp_imgdev_state state); + void (*deactivate)(struct fp_img_dev *dev); +}; + +#endif From 499b5221832cace53dd24c9ca92e0b9013e595da Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 14:24:10 +0200 Subject: [PATCH 112/225] lib: Remove titles from headers The purpose of the headers is (or will be) explained in more details inside each one of the matching C files. --- libfprint/fpi-dev.h | 1 - libfprint/fpi-log.h | 1 - libfprint/fpi-poll.h | 1 - libfprint/fpi-ssm.h | 1 - libfprint/fpi-usb.h | 1 - 5 files changed, 5 deletions(-) diff --git a/libfprint/fpi-dev.h b/libfprint/fpi-dev.h index 6c50956b..98433912 100644 --- a/libfprint/fpi-dev.h +++ b/libfprint/fpi-dev.h @@ -1,5 +1,4 @@ /* - * fp_dev types manipulation * Copyright (C) 2018 Bastien Nocera * * This library is free software; you can redistribute it and/or diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h index d9f354e8..6b494af3 100644 --- a/libfprint/fpi-log.h +++ b/libfprint/fpi-log.h @@ -1,5 +1,4 @@ /* - * Logging * Copyright (C) 2007-2008 Daniel Drake * Copyright (C) 2018 Bastien Nocera * diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 748641b9..2682f277 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -1,5 +1,4 @@ /* - * Polling/timing management * Copyright (C) 2008 Daniel Drake * Copyright (C) 2018 Bastien Nocera * diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 709928c0..a619d42c 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -1,5 +1,4 @@ /* - * Driver API definitions * Copyright (C) 2007-2008 Daniel Drake * Copyright (C) 2018 Bastien Nocera * diff --git a/libfprint/fpi-usb.h b/libfprint/fpi-usb.h index 625a7e7b..822b6124 100644 --- a/libfprint/fpi-usb.h +++ b/libfprint/fpi-usb.h @@ -1,5 +1,4 @@ /* - * Driver API definitions * Copyright (C) 2018 Bastien Nocera * * This library is free software; you can redistribute it and/or From bf8661bf45e672f2ef0bace0f57bd9bcd99b8d87 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 14:25:04 +0200 Subject: [PATCH 113/225] lib: Include "fpi-dev.h" in drivers header --- libfprint/drivers_api.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 84b7a682..647a2084 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -25,6 +25,7 @@ #include "fprint.h" #include "fpi-log.h" +#include "fpi-dev.h" #include "fpi-dev-img.h" #include "fpi-core.h" #include "fpi-ssm.h" From c27390847178e52343f39feeb326ceb40aeb11c2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 14:50:02 +0200 Subject: [PATCH 114/225] lib: Tidy fp_internal.h Group global variables, structure definitions, and functions, and group functions by which C source they're defined in. This also removes the FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE definition that's already available in the drivers API-accessible fpi-core.h --- libfprint/fp_internal.h | 67 ++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index dca072fb..95b212bb 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -35,6 +35,11 @@ #include "fpi-img.h" #include "drivers/driver_ids.h" +/* Global variables */ +extern libusb_context *fpi_usb_ctx; +extern GSList *opened_devices; + +/* fp_dev structure definition */ enum fp_dev_state { DEV_STATE_INITIAL = 0, DEV_STATE_ERROR, @@ -59,8 +64,6 @@ enum fp_dev_state { DEV_STATE_CAPTURE_STOPPING, }; -struct fp_driver **fprint_get_drivers (void); - struct fp_dev { struct fp_driver *drv; uint32_t devtype; @@ -110,6 +113,7 @@ struct fp_dev { struct fp_print_data **identify_gallery; }; +/* fp_img_dev structure definition */ struct fp_img_dev { struct fp_dev *parent; @@ -126,9 +130,7 @@ struct fp_img_dev { size_t identify_match_offset; }; -int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev); -int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev); - +/* fp_driver structure definition */ struct usb_id { uint16_t vendor; uint16_t product; @@ -162,10 +164,12 @@ struct fp_driver { int (*capture_stop)(struct fp_dev *dev); }; -enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv); - -/* flags for fp_img_driver.flags */ -#define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0) +/* fp_img_driver structure definition */ +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +#define fpi_driver_to_img_driver(drv) \ + container_of((drv), struct fp_img_driver, driver) struct fp_img_driver { struct fp_driver driver; @@ -182,19 +186,7 @@ struct fp_img_driver { void (*deactivate)(struct fp_img_dev *dev); }; -#include "drivers_definitions.h" - -extern libusb_context *fpi_usb_ctx; -extern GSList *opened_devices; - -void fpi_img_driver_setup(struct fp_img_driver *idriver); - -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) -#define fpi_driver_to_img_driver(drv) \ - container_of((drv), struct fp_img_driver, driver) - +/* fp_dscv_dev structure definition */ struct fp_dscv_dev { struct libusb_device *udev; struct fp_driver *drv; @@ -202,6 +194,7 @@ struct fp_dscv_dev { uint32_t devtype; }; +/* fp_dscv_print structure definition */ struct fp_dscv_print { uint16_t driver_id; uint32_t devtype; @@ -209,11 +202,7 @@ struct fp_dscv_print { char *path; }; -void fpi_data_exit(void); -gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1, - enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2, - enum fp_print_data_type type2); - +/* fp_minutia structure definition */ struct fp_minutia { int x; int y; @@ -229,12 +218,32 @@ struct fp_minutia { int num_nbrs; }; +/* fp_minutiae structure definition */ struct fp_minutiae { int alloc; int num; struct fp_minutia **list; }; +/* Defined in fpi-dev-img.c */ +void fpi_img_driver_setup(struct fp_img_driver *idriver); +int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev); +int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev); + +/* Exported for use in command-line tools + * Defined in fpi-core.c */ +struct fp_driver **fprint_get_drivers (void); + +/* Defined in fpi-core.c */ +enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv); + +/* Defined in fpi-data.c */ +void fpi_data_exit(void); +gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1, + enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2, + enum fp_print_data_type type2); + +/* Defined in fpi-img.c */ gboolean fpi_img_is_sane(struct fp_img *img); int fpi_img_to_print_data(struct fp_img_dev *imgdev, struct fp_img *img, struct fp_print_data **ret); @@ -243,9 +252,11 @@ int fpi_img_compare_print_data(struct fp_print_data *enrolled_print, int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print, struct fp_print_data **gallery, int match_threshold, size_t *match_offset); -/* polling */ +/* Defined in fpi-poll.c */ void fpi_timeout_cancel_all_for_dev(struct fp_dev *dev); void fpi_poll_init(void); void fpi_poll_exit(void); +#include "drivers_definitions.h" + #endif From 36dba3380888f809ba455f294cffcbb454581380 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 15:55:56 +0200 Subject: [PATCH 115/225] build: Test builds with a single driver with no deps So that we can be sure that the build doesn't break when those drivers are not built. --- .gitlab-ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 05e83068..68bca736 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,7 +14,11 @@ before_script: build: stage: build script: - - meson . _build + # Build with a driver that doesn't need imaging, or nss + - meson -Ddrivers=elan . _build + - ninja -C _build + # And build with everything + - meson -Ddrivers=all . _build - ninja -C _build - ninja -C _build install From 7962d8cdab66cafa39c0fac9e1907889e10077ee Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 15:59:45 +0200 Subject: [PATCH 116/225] build: Fix build with no drivers using imaging_dep Closes: #109 --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index c5c691d4..6109b321 100644 --- a/meson.build +++ b/meson.build @@ -52,8 +52,8 @@ if drivers == [ 'all' ] drivers = all_drivers endif -nss_dep = [] -imaging_dep = [] +nss_dep = dependency('', required: false) +imaging_dep = dependency('', required: false) foreach driver: drivers if driver == 'uru4000' nss_dep = dependency('nss', required: false) From cffe49de5cb59d1e616b21935e32785288817377 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 8 Oct 2018 16:50:30 +0200 Subject: [PATCH 117/225] build: Fix "already configured" meson warning --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 68bca736..ffbdba6e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,6 +17,7 @@ build: # Build with a driver that doesn't need imaging, or nss - meson -Ddrivers=elan . _build - ninja -C _build + - rm -rf _build/ # And build with everything - meson -Ddrivers=all . _build - ninja -C _build From 1006467f33c8f78e2003cb523ac047444673061f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 8 Oct 2018 16:43:28 +0200 Subject: [PATCH 118/225] lib: Add accessor for minutia coordinates Add fp_minutia_get_coords() so that debugging applications can show the detected minutiae along with the captured image. This will also help fix the positively ancient fprint_demo. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=907470 --- doc/libfprint-sections.txt | 1 + libfprint/fpi-img.c | 24 ++++++++++++++++++++++++ libfprint/fprint.h | 1 + 3 files changed, 26 insertions(+) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 0a95c2d5..502c6f44 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -134,6 +134,7 @@ fp_img_save_to_file fp_img_standardize fp_img_binarize fp_img_get_minutiae +fp_minutia_get_coords
diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index da5b5b83..34c9c383 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -533,6 +533,30 @@ API_EXPORTED struct fp_minutia **fp_img_get_minutiae(struct fp_img *img, return img->minutiae->list; } +/** + * fp_minutia_get_coords: + * @minutia: a struct #fp_minutia + * @x: the return variable for the X coordinate of the minutia + * @y: the return variable for the Y coordinate of the minutia + * + * Sets @x and @y to be the coordinates of the detected minutia, so it + * can be presented in a more verbose user interface. This is usually only + * used for debugging purposes. + * + * Returns: 0 on success, -1 on error. + */ +API_EXPORTED int fp_minutia_get_coords(struct fp_minutia *minutia, int *coord_x, int *coord_y) +{ + g_return_val_if_fail (minutia != NULL, -1); + g_return_val_if_fail (coord_x != NULL, -1); + g_return_val_if_fail (coord_y != NULL, -1); + + *coord_x = minutia->x; + *coord_y = minutia->y; + + return 0; +} + enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev) { diff --git a/libfprint/fprint.h b/libfprint/fprint.h index ede569b7..0cf42bb9 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -296,6 +296,7 @@ int fp_img_save_to_file(struct fp_img *img, char *path); void fp_img_standardize(struct fp_img *img); struct fp_img *fp_img_binarize(struct fp_img *img); struct fp_minutia **fp_img_get_minutiae(struct fp_img *img, int *nr_minutiae); +int fp_minutia_get_coords(struct fp_minutia *minutia, int *coord_x, int *coord_y); void fp_img_free(struct fp_img *img); /* Polling and timing */ From 21a779235d009a386062f733f650bf69d4de4077 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 16:08:20 +0200 Subject: [PATCH 119/225] mindtct: Fix powmax_dirs leak on error A copy/paste error meant we were trying to free a variable we only just failed to allocate. Spotted by Seth Arnold Closes: #81 --- libfprint/nbis/mindtct/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/nbis/mindtct/init.c b/libfprint/nbis/mindtct/init.c index a7182790..fd65f9ca 100644 --- a/libfprint/nbis/mindtct/init.c +++ b/libfprint/nbis/mindtct/init.c @@ -725,7 +725,7 @@ int alloc_power_stats(int **owis, double **opowmaxs, int **opowmax_dirs, /* Free memory allocated to this point. */ free(wis); free(powmaxs); - free(pownorms); + free(powmax_dirs); fprintf(stderr, "ERROR : alloc_power_stats : malloc : pownorms\n"); return(-53); } From 5e8b4a81e90f9a724fd312b50c2e2476e10ef240 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 16:11:52 +0200 Subject: [PATCH 120/225] mindtct: Fix leak in pixelize_map() pmap was not freed in error cases. Spotted by Seth Arnold Closes: #83 --- libfprint/nbis/mindtct/maps.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index 5cd031b4..bd2d1fc2 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -736,11 +736,13 @@ int pixelize_map(int **omap, const int iw, const int ih, } if((ret = block_offsets(&blkoffs, &bw, &bh, iw, ih, 0, blocksize))){ + free(pmap); return(ret); } if((bw != mw) || (bh != mh)){ free(blkoffs); + free(pmap); fprintf(stderr, "ERROR : pixelize_map : block dimensions do not match\n"); return(-591); From c35ad20249b2d78339ddc335c847b7407fdd081c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 17:16:03 +0200 Subject: [PATCH 121/225] mindtct: Fix a memory leak in morph_TF_map() cimage is leaked when mimage fails to allocate. Spotted by Seth Arnold Closes: #82 --- libfprint/nbis/mindtct/maps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index bd2d1fc2..419517b1 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -675,6 +675,7 @@ int morph_TF_map(int *tfmap, const int mw, const int mh, mimage = (unsigned char *)malloc(mw*mh); if(mimage == (unsigned char *)NULL){ + free(cimage); fprintf(stderr, "ERROR : morph_TF_map : malloc : mimage\n"); return(-661); } From 94450a1d7404e52322d2f61715e1d7a4669137b5 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 28 Sep 2018 18:02:11 +0200 Subject: [PATCH 122/225] lib: Fix fpi_img_is_sane() The checks weren't: - checking whether the width or height were negative - whether img->width * img->height would overflow, or was bigger than G_MAXINT - whether img->width * img->height was bigger than the total length of the buffer The last one looks like a thinko, it checked for: (img->length * img->height) < img->length which is equivalent to: img->height < 1 which we already check for earlier. Closes: #85 --- libfprint/fpi-img.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 34c9c383..8691bd6d 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -69,12 +69,19 @@ struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev) gboolean fpi_img_is_sane(struct fp_img *img) { + guint len; + /* basic checks */ - if (!img->length || !img->width || !img->height) + if (!img->length || img->width <= 0 || img->height <= 0) return FALSE; - /* buffer is big enough? */ - if ((img->length * img->height) < img->length) + /* Are width and height just too big? */ + if (!g_uint_checked_mul(&len, img->width, img->height) || + len > G_MAXINT) + return FALSE; + + /* buffer big enough? */ + if (len > img->length) return FALSE; return TRUE; From 3a7b03f02235e955af6355dea2288d7732875109 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 12 Oct 2018 12:27:37 +0200 Subject: [PATCH 123/225] lib: Fix crash when too many minutiae were detected struct xyt_struct uses a fixed-sized array to fit MAX_BOZORTH_MINUTIAE (200) minutiae. MAX_FILE_MINUTIAE is 1000. So if we detected more than MAX_BOZORTH_MINUTIAE, we would crash copying the data from the capture to the structure. We might want to use dynamically allocated arrays in the future (or bigger ones) so that we don't lose minutiae. Closes: #116 --- libfprint/fpi-img.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 8691bd6d..da112a47 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -269,9 +269,8 @@ static void minutiae_to_xyt(struct fp_minutiae *minutiae, int bwidth, struct minutiae_struct c[MAX_FILE_MINUTIAE]; struct xyt_struct *xyt = (struct xyt_struct *) buf; - /* FIXME: only considers first 150 minutiae (MAX_FILE_MINUTIAE) */ - /* nist does weird stuff with 150 vs 1000 limits */ - int nmin = min(minutiae->num, MAX_FILE_MINUTIAE); + /* struct xyt_struct uses arrays of MAX_BOZORTH_MINUTIAE (200) */ + int nmin = min(minutiae->num, MAX_BOZORTH_MINUTIAE); for (i = 0; i < nmin; i++){ minutia = minutiae->list[i]; From c88a51cce87e1c48d8ecfdd5be429b87dd0b88e6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 14:28:04 +0200 Subject: [PATCH 124/225] build: Refuse to build without any drivers --- meson.build | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/meson.build b/meson.build index 6109b321..87d7adfa 100644 --- a/meson.build +++ b/meson.build @@ -52,6 +52,10 @@ if drivers == [ 'all' ] drivers = all_drivers endif +if drivers.length() == 0 or drivers[0] == '' + error('Cannot build libfprint without drivers, please specify a valid value for the drivers option') +endif + nss_dep = dependency('', required: false) imaging_dep = dependency('', required: false) foreach driver: drivers From 46ebb39f6511b65f278e82f02fb52608356d9cf7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 14:58:04 +0200 Subject: [PATCH 125/225] lib: Throw an error if fp_init() wasn't called You can't call fp_discover_devs() without calling fp_init() and having it not fail, otherwise there's nothing to discover... --- libfprint/fpi-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libfprint/fpi-core.c b/libfprint/fpi-core.c index 8009fe19..46e664bd 100644 --- a/libfprint/fpi-core.c +++ b/libfprint/fpi-core.c @@ -259,8 +259,7 @@ API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void) int r; int i = 0; - if (registered_drivers == NULL) - return NULL; + g_return_val_if_fail (registered_drivers != NULL, NULL); r = libusb_get_device_list(fpi_usb_ctx, &devs); if (r < 0) { From f42cd6eefdcec6a3ade63b7b509d0054f99ee4af Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 15:00:30 +0200 Subject: [PATCH 126/225] lib: Add fp_driver_supports_imaging() So we don't need to open a device before checking whether it supports imaging. --- doc/libfprint-sections.txt | 1 + libfprint/fpi-core.c | 18 ++++++++++++++++++ libfprint/fprint.h | 1 + 3 files changed, 20 insertions(+) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 502c6f44..9d70895a 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -40,6 +40,7 @@ fp_driver_get_name fp_driver_get_full_name fp_driver_get_driver_id fp_driver_get_scan_type +fp_driver_supports_imaging
diff --git a/libfprint/fpi-core.c b/libfprint/fpi-core.c index 46e664bd..eede91af 100644 --- a/libfprint/fpi-core.c +++ b/libfprint/fpi-core.c @@ -579,6 +579,24 @@ API_EXPORTED enum fp_scan_type fp_driver_get_scan_type(struct fp_driver *drv) return drv->scan_type; } +/** + * fp_driver_supports_imaging: + * @drv: the driver + * + * Determines if a driver has imaging capabilities. If a driver has imaging + * capabilities you are able to perform imaging operations such as retrieving + * scan images using fp_dev_img_capture(). However, not all drivers support + * imaging devices – some do all processing in hardware. This function will + * indicate which class a device in question falls into. + * + * Returns: 1 if the device is an imaging device, 0 if the device does not + * provide images to the host computer + */ +API_EXPORTED int fp_driver_supports_imaging(struct fp_driver *drv) +{ + return drv->capture_start != NULL; +} + /** * fp_dev_supports_imaging: * @dev: the fingerprint device diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 0cf42bb9..6c348398 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -130,6 +130,7 @@ const char *fp_driver_get_name(struct fp_driver *drv); const char *fp_driver_get_full_name(struct fp_driver *drv); uint16_t fp_driver_get_driver_id(struct fp_driver *drv); enum fp_scan_type fp_driver_get_scan_type(struct fp_driver *drv); +int fp_driver_supports_imaging(struct fp_driver *drv); /* Device discovery */ struct fp_dscv_dev **fp_discover_devs(void); From 36b696f4336df01aaf9f66491f3257a72451bbde Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 17:18:11 +0200 Subject: [PATCH 127/225] lib: Fix error messages in async capture functions They mentioned verification instead of capture. --- libfprint/fpi-async.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index cce0dca3..14a8bbd4 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -538,7 +538,7 @@ API_EXPORTED int fp_async_capture_start(struct fp_dev *dev, int unconditional, if (r < 0) { dev->capture_cb = NULL; dev->state = DEV_STATE_ERROR; - fp_err("failed to start verification, error %d", r); + fp_err("failed to start capture, error %d", r); } return r; } @@ -624,7 +624,7 @@ API_EXPORTED int fp_async_capture_stop(struct fp_dev *dev, r = drv->capture_stop(dev); if (r < 0) { - fp_err("failed to stop verification"); + fp_err("failed to stop capture"); dev->capture_stop_cb = NULL; } return r; From a54d020c97c069697bc59c1e566fa5e7bd4db45e Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 17:19:21 +0200 Subject: [PATCH 128/225] lib: Make fp_get_pollfds() fail when fp_init() wasn't called So things can't be called out-of-order. --- libfprint/fpi-poll.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index e416c960..2f2d1f1d 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -418,6 +418,8 @@ API_EXPORTED ssize_t fp_get_pollfds(struct fp_pollfd **pollfds) ssize_t cnt = 0; size_t i = 0; + g_return_val_if_fail (fpi_usb_ctx != NULL, -EIO); + usbfds = libusb_get_pollfds(fpi_usb_ctx); if (!usbfds) { *pollfds = NULL; From 97d0a6dfe6a3ba82adbc548f5708c73af19b5794 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 17:20:38 +0200 Subject: [PATCH 129/225] lib: Add fpi_poll_is_setup() sanity check This checks whether polling was correctly setup for integration with a mainloop. --- libfprint/fpi-poll.c | 6 ++++++ libfprint/fpi-poll.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 2f2d1f1d..ed81a4f0 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -482,6 +482,12 @@ void fpi_poll_exit(void) libusb_set_pollfd_notifiers(fpi_usb_ctx, NULL, NULL, NULL); } +gboolean +fpi_poll_is_setup(void) +{ + return (fd_added_cb != NULL && fd_removed_cb != NULL); +} + void fpi_timeout_cancel_all_for_dev(struct fp_dev *dev) { diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 2682f277..77c5eabe 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -48,4 +48,6 @@ void fpi_timeout_set_name(fpi_timeout *timeout, const char *name); void fpi_timeout_cancel(fpi_timeout *timeout); +gboolean fpi_poll_is_setup(void); + #endif From 700c5791f85166db3e8ea1a3b5f93cdfc3abe778 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 17:21:20 +0200 Subject: [PATCH 130/225] lib: Async functions cannot be started without a mainloop No mainloop, no async. --- libfprint/fpi-async.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index 14a8bbd4..9e89e3e5 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -21,6 +21,7 @@ #include "fp_internal.h" #include "fpi-async.h" +#include "fpi-poll.h" #include #include @@ -162,6 +163,7 @@ API_EXPORTED int fp_async_enroll_start(struct fp_dev *dev, int r; g_return_val_if_fail(dev != NULL, -ENODEV); + g_return_val_if_fail (fpi_poll_is_setup(), -EIO); drv = dev->drv; @@ -270,6 +272,7 @@ API_EXPORTED int fp_async_verify_start(struct fp_dev *dev, int r; g_return_val_if_fail(dev != NULL, -ENODEV); + g_return_val_if_fail (fpi_poll_is_setup(), -EIO); drv = dev->drv; @@ -396,6 +399,7 @@ API_EXPORTED int fp_async_identify_start(struct fp_dev *dev, int r; g_return_val_if_fail(dev != NULL, -ENODEV); + g_return_val_if_fail (fpi_poll_is_setup(), -EIO); drv = dev->drv; @@ -522,6 +526,7 @@ API_EXPORTED int fp_async_capture_start(struct fp_dev *dev, int unconditional, int r; g_return_val_if_fail(dev != NULL, -ENODEV); + g_return_val_if_fail (fpi_poll_is_setup(), -EIO); drv = dev->drv; From b1afa9da5d8a796c37dea73d310a85728b0e775b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 17:21:52 +0200 Subject: [PATCH 131/225] lib: No mainloop, no timeouts either --- libfprint/fpi-poll.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index ed81a4f0..18689ec0 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -163,6 +163,7 @@ fpi_timeout *fpi_timeout_add(unsigned int msec, int r; g_return_val_if_fail (dev != NULL, NULL); + g_return_val_if_fail (fpi_poll_is_setup(), NULL); fp_dbg("in %dms", msec); From e113754312fd8f17be9b58d3319b934a587b33eb Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 19 Oct 2018 16:42:47 +0200 Subject: [PATCH 132/225] docs: Add "struct #fp_dev" to the API docs --- libfprint/fpi-sync.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libfprint/fpi-sync.c b/libfprint/fpi-sync.c index 8f71b6ea..682f913f 100644 --- a/libfprint/fpi-sync.c +++ b/libfprint/fpi-sync.c @@ -82,7 +82,7 @@ static void sync_close_cb(struct fp_dev *dev, void *user_data) /** * fp_dev_close: - * @dev: the device to close. If %NULL, function simply returns. + * @dev: the struct #fp_dev device to close. If %NULL, function simply returns. * * Close a device. You must call this function when you are finished using * a fingerprint device. @@ -128,7 +128,7 @@ static void enroll_stop_cb(struct fp_dev *dev, void *user_data) /** * fp_enroll_finger_img: - * @dev: the device + * @dev: the struct #fp_dev device * @print_data: a location to return the resultant enrollment data from * the final stage. Must be freed with fp_print_data_free() after use. * @img: location to store the scan image. accepts %NULL for no image @@ -290,7 +290,7 @@ err: /** * fp_enroll_finger: - * @dev: the device + * @dev: the struct #fp_dev device * @print_data: a location to return the resultant enrollment data from * the final stage. Must be freed with fp_print_data_free() after use. * @@ -331,7 +331,7 @@ static void verify_stop_cb(struct fp_dev *dev, void *user_data) /** * fp_verify_finger_img: - * @dev: the device to perform the scan. + * @dev: the struct #fp_dev device to perform the scan on * @enrolled_print: the print to verify against. Must have been previously * enrolled with a device compatible to the device selected to perform the scan. * @img: location to store the scan image. accepts %NULL for no image @@ -423,7 +423,7 @@ err: /** * fp_verify_finger: - * @dev: the device to perform the scan. + * @dev: the struct #fp_dev device to perform the scan on * @enrolled_print: the print to verify against. Must have been previously * enrolled with a device compatible to the device selected to perform the scan. * @@ -467,7 +467,7 @@ static void identify_stop_cb(struct fp_dev *dev, void *user_data) /** * fp_identify_finger_img: - * @dev: the device to perform the scan. + * @dev: the struct #fp_dev device to perform the scan on * @print_gallery: NULL-terminated array of pointers to the prints to * identify against. Each one must have been previously enrolled with a device * compatible to the device selected to perform the scan. @@ -565,7 +565,7 @@ err: /** * fp_identify_finger: - * @dev: the device to perform the scan. + * @dev: the struct #fp_dev device to perform the scan on * @print_gallery: %NULL-terminated array of pointers to the prints to * identify against. Each one must have been previously enrolled with a device * compatible to the device selected to perform the scan. @@ -611,7 +611,7 @@ static void capture_stop_cb(struct fp_dev *dev, void *user_data) } /** * fp_dev_img_capture: - * @dev: the device + * @dev: the struct #fp_dev device * @unconditional: whether to unconditionally capture an image, or to only capture when a finger is detected * @img: a location to return the captured image. Must be freed with * fp_img_free() after use. From d113ed9d8305ddab149cdd5a973afd08bdbccddf Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 19 Oct 2018 16:45:02 +0200 Subject: [PATCH 133/225] docs: Update API docs style No period at the end of parameter docs. --- libfprint/fpi-sync.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libfprint/fpi-sync.c b/libfprint/fpi-sync.c index 682f913f..5b553675 100644 --- a/libfprint/fpi-sync.c +++ b/libfprint/fpi-sync.c @@ -82,7 +82,7 @@ static void sync_close_cb(struct fp_dev *dev, void *user_data) /** * fp_dev_close: - * @dev: the struct #fp_dev device to close. If %NULL, function simply returns. + * @dev: the struct #fp_dev device to close. If %NULL, function simply returns * * Close a device. You must call this function when you are finished using * a fingerprint device. @@ -130,10 +130,10 @@ static void enroll_stop_cb(struct fp_dev *dev, void *user_data) * fp_enroll_finger_img: * @dev: the struct #fp_dev device * @print_data: a location to return the resultant enrollment data from - * the final stage. Must be freed with fp_print_data_free() after use. + * the final stage. Must be freed with fp_print_data_free() after use * @img: location to store the scan image. accepts %NULL for no image * storage. If an image is returned, it must be freed with fp_img_free() after - * use. + * use * * Performs an enroll stage. See [Enrolling](libfprint-Devices-operations.html#enrolling) * for an explanation of enroll stages. @@ -292,7 +292,7 @@ err: * fp_enroll_finger: * @dev: the struct #fp_dev device * @print_data: a location to return the resultant enrollment data from - * the final stage. Must be freed with fp_print_data_free() after use. + * the final stage. Must be freed with fp_print_data_free() after use * * Performs an enroll stage. See [Enrolling](libfprint-Devices-operations.html#enrolling) * for an explanation of enroll stages. This function is just a shortcut to @@ -333,10 +333,10 @@ static void verify_stop_cb(struct fp_dev *dev, void *user_data) * fp_verify_finger_img: * @dev: the struct #fp_dev device to perform the scan on * @enrolled_print: the print to verify against. Must have been previously - * enrolled with a device compatible to the device selected to perform the scan. + * enrolled with a device compatible to the device selected to perform the scan * @img: location to store the scan image. accepts %NULL for no image * storage. If an image is returned, it must be freed with fp_img_free() after - * use. + * use * Performs a new scan and verify it against a previously enrolled print. * If the device is an imaging device, it can also return the image from @@ -425,7 +425,7 @@ err: * fp_verify_finger: * @dev: the struct #fp_dev device to perform the scan on * @enrolled_print: the print to verify against. Must have been previously - * enrolled with a device compatible to the device selected to perform the scan. + * enrolled with a device compatible to the device selected to perform the scan * * Performs a new scan and verify it against a previously enrolled print. This * function is just a shortcut to calling fp_verify_finger_img() with a NULL @@ -470,13 +470,13 @@ static void identify_stop_cb(struct fp_dev *dev, void *user_data) * @dev: the struct #fp_dev device to perform the scan on * @print_gallery: NULL-terminated array of pointers to the prints to * identify against. Each one must have been previously enrolled with a device - * compatible to the device selected to perform the scan. + * compatible to the device selected to perform the scan * @match_offset: output location to store the array index of the matched * gallery print (if any was found). Only valid if %FP_VERIFY_MATCH was - * returned. + * returned * @img: location to store the scan image. accepts %NULL for no image * storage. If an image is returned, it must be freed with fp_img_free() after - * use. + * use * Performs a new scan and attempts to identify the scanned finger against * a collection of previously enrolled fingerprints. @@ -568,10 +568,10 @@ err: * @dev: the struct #fp_dev device to perform the scan on * @print_gallery: %NULL-terminated array of pointers to the prints to * identify against. Each one must have been previously enrolled with a device - * compatible to the device selected to perform the scan. + * compatible to the device selected to perform the scan * @match_offset: output location to store the array index of the matched * gallery print (if any was found). Only valid if %FP_VERIFY_MATCH was - * returned. + * returned * Performs a new scan and attempts to identify the scanned finger against a * collection of previously enrolled fingerprints. This function is just a @@ -614,7 +614,7 @@ static void capture_stop_cb(struct fp_dev *dev, void *user_data) * @dev: the struct #fp_dev device * @unconditional: whether to unconditionally capture an image, or to only capture when a finger is detected * @img: a location to return the captured image. Must be freed with - * fp_img_free() after use. + * fp_img_free() after use * * Captures a #fp_img from a device. The returned image is the raw * image provided by the device, you may wish to [standardize](libfprint-Image-operations.html#img_std) it. @@ -628,7 +628,7 @@ static void capture_stop_cb(struct fp_dev *dev, void *user_data) * * Returns: 0 on success, non-zero on error. -ENOTSUP indicates that either the * @unconditional flag was set but the device does not support this, or that the - * device does not support imaging. + * device does not support imaging */ API_EXPORTED int fp_dev_img_capture(struct fp_dev *dev, int unconditional, struct fp_img **img) From d91eae26e59046c65ecd329aadf04aea38e8a1f0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 10:10:03 +0200 Subject: [PATCH 134/225] lib: Add API docs for the async functions --- libfprint/fpi-async.c | 121 +++++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 42 deletions(-) diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index 9e89e3e5..9180b87e 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -40,11 +40,18 @@ void fpi_drvcb_open_complete(struct fp_dev *dev, int status) /** * fp_async_dev_open: - * @ddev: - * @callback: - * @user_data: + * @ddev: the struct #fp_dscv_dev discovered device to open + * @callback: the callback to call when the device has been opened + * @user_data: user data to pass to the callback * - * Returns: + * Opens and initialises a device. This is the function you call in order + * to convert a #fp_dscv_dev discovered device into an actual device handle + * that you can perform operations with. + * + * The error status of the opening will be provided as an argument to the + * #fp_dev_open_cb callback. + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_dev_open(struct fp_dscv_dev *ddev, fp_dev_open_cb callback, void *user_data) @@ -104,9 +111,12 @@ void fpi_drvcb_close_complete(struct fp_dev *dev) /** * fp_async_dev_close: - * @dev: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @callback: the callback to call when the device has been closed + * @user_data: user data to pass to the callback + * + * Closes a device. You must call this function when you have finished using + * a fingerprint device. */ API_EXPORTED void fp_async_dev_close(struct fp_dev *dev, fp_operation_stop_cb callback, void *user_data) @@ -150,11 +160,15 @@ void fpi_drvcb_enroll_started(struct fp_dev *dev, int status) /** * fp_async_enroll_start: - * @dev: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @callback: the callback to call for each stage of the enrollment + * @user_data: user data to pass to the callback * - * Returns: + * Starts an enrollment and calls @callback for each enrollment stage. + * See [Enrolling](libfprint-Devices-operations.html#enrolling) + * for an explanation of enroll stages. + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_enroll_start(struct fp_dev *dev, fp_enroll_stage_cb callback, void *user_data) @@ -217,11 +231,13 @@ void fpi_drvcb_enroll_stopped(struct fp_dev *dev) /** * fp_async_enroll_stop: - * @dev: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @callback: the callback to call when the enrollment has been cancelled + * @user_data: user data to pass to the callback * - * Returns: + * Stops an ongoing enrollment started with fp_async_enroll_start(). + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_enroll_stop(struct fp_dev *dev, fp_operation_stop_cb callback, void *user_data) @@ -258,12 +274,17 @@ API_EXPORTED int fp_async_enroll_stop(struct fp_dev *dev, /** * fp_async_verify_start: - * @dev: - * @data: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @data: the print to verify against. Must have been previously + * enrolled with a device compatible to the device selected to perform the scan + * @callback: the callback to call when the verification has finished + * @user_data: user data to pass to the callback * - * Returns: + * Starts a verification and calls @callback when the verification has + * finished. See fp_verify_finger_img() for the synchronous API. When the + * @callback has been called, you must call fp_async_verify_stop(). + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_verify_start(struct fp_dev *dev, struct fp_print_data *data, fp_img_operation_cb callback, void *user_data) @@ -340,11 +361,13 @@ void fpi_drvcb_verify_stopped(struct fp_dev *dev) /** * fp_async_verify_stop: - * @dev: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @callback: the callback to call to finish a verification + * @user_data: user data to pass to the callback * - * Returns: + * Finishes an ongoing verification started with fp_async_verify_start(). + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_verify_stop(struct fp_dev *dev, fp_operation_stop_cb callback, void *user_data) @@ -385,12 +408,17 @@ API_EXPORTED int fp_async_verify_stop(struct fp_dev *dev, /** * fp_async_identify_start: - * @dev: - * @gallery: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @gallery: NULL-terminated array of pointers to the prints to + * identify against. Each one must have been previously enrolled with a device + * compatible to the device selected to perform the scan + * @callback: the callback to call when the identification has finished + * @user_data: user data to pass to the callback * - * Returns: + * Performs a new scan and verifies it against a previously enrolled print. + * See also: fp_verify_finger_img() + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_identify_start(struct fp_dev *dev, struct fp_print_data **gallery, fp_identify_cb callback, void *user_data) @@ -457,11 +485,13 @@ void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, /** * fp_async_identify_stop: - * @dev: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @callback: the callback to call when the identification has stopped + * @user_data: user data to pass to the callback * - * Returns: + * Stops an ongoing identification started with fp_async_identify_start(). + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_identify_stop(struct fp_dev *dev, fp_operation_stop_cb callback, void *user_data) @@ -512,12 +542,17 @@ void fpi_drvcb_identify_stopped(struct fp_dev *dev) /** * fp_async_capture_start: - * @dev: - * @unconditional: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @unconditional: whether to unconditionally capture an image, or to only capture when a finger is detected + * @callback: the callback to call when the capture has finished + * @user_data: user data to pass to the callback * - * Returns: + * Start the capture of an #fp_img from a device. When the @callback has been called, + * you must call fp_async_capture_stop(). + * + * Returns: 0 on success, non-zero on error. -ENOTSUP indicates that either the + * @unconditional flag was set but the device does not support this, or that the• + * device does not support imaging */ API_EXPORTED int fp_async_capture_start(struct fp_dev *dev, int unconditional, fp_img_operation_cb callback, void *user_data) @@ -593,11 +628,13 @@ void fpi_drvcb_capture_stopped(struct fp_dev *dev) /** * fp_async_capture_stop: - * @dev: - * @callback: - * @user_data: + * @dev: the struct #fp_dev device + * @callback: the callback to call when the capture has been stopped + * @user_data: user data to pass to the callback * - * Returns: + * Stops an ongoing verification started with fp_async_capture_start(). + * + * Returns: 0 on success, non-zero on error */ API_EXPORTED int fp_async_capture_stop(struct fp_dev *dev, fp_operation_stop_cb callback, void *user_data) From 9bcacd97df072cfc82be70a1b22dc100859c07f4 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 10:10:57 +0200 Subject: [PATCH 135/225] lib: Require a callback for a number of async calls Otherwise the caller won't be able to call the appropriate _finish() calls when done. See https://gitlab.freedesktop.org/libfprint/libfprint/issues/119 for the long-term plan --- libfprint/fpi-async.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index 9180b87e..aadbc41a 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -62,6 +62,7 @@ API_EXPORTED int fp_async_dev_open(struct fp_dscv_dev *ddev, fp_dev_open_cb call int r; g_return_val_if_fail(ddev != NULL, -ENODEV); + g_return_val_if_fail (callback != NULL, -EINVAL); drv = ddev->drv; @@ -178,6 +179,7 @@ API_EXPORTED int fp_async_enroll_start(struct fp_dev *dev, g_return_val_if_fail(dev != NULL, -ENODEV); g_return_val_if_fail (fpi_poll_is_setup(), -EIO); + g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; @@ -294,6 +296,7 @@ API_EXPORTED int fp_async_verify_start(struct fp_dev *dev, g_return_val_if_fail(dev != NULL, -ENODEV); g_return_val_if_fail (fpi_poll_is_setup(), -EIO); + g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; @@ -428,6 +431,7 @@ API_EXPORTED int fp_async_identify_start(struct fp_dev *dev, g_return_val_if_fail(dev != NULL, -ENODEV); g_return_val_if_fail (fpi_poll_is_setup(), -EIO); + g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; @@ -562,6 +566,7 @@ API_EXPORTED int fp_async_capture_start(struct fp_dev *dev, int unconditional, g_return_val_if_fail(dev != NULL, -ENODEV); g_return_val_if_fail (fpi_poll_is_setup(), -EIO); + g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; From 18495d122d4cdf3632448408ca15f821f32922cb Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 10:18:41 +0200 Subject: [PATCH 136/225] lib: Fix up @dev argument docs --- libfprint/fpi-core.c | 18 +++++++++--------- libfprint/fpi-sync.c | 2 +- libfprint/fprint.h | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libfprint/fpi-core.c b/libfprint/fpi-core.c index eede91af..fc197570 100644 --- a/libfprint/fpi-core.c +++ b/libfprint/fpi-core.c @@ -453,7 +453,7 @@ API_EXPORTED struct fp_dscv_dev *fp_dscv_dev_for_dscv_print(struct fp_dscv_dev * /** * fp_dev_get_driver: - * @dev: the device + * @dev: the struct #fp_dev device * * Get the #fp_driver for a fingerprint device. * @@ -466,7 +466,7 @@ API_EXPORTED struct fp_driver *fp_dev_get_driver(struct fp_dev *dev) /** * fp_dev_get_nr_enroll_stages: - * @dev: the device + * @dev: the struct #fp_dev device * * Gets the number of [enroll stages](intro.html#enrollment) required to enroll a * fingerprint with the device. @@ -480,7 +480,7 @@ API_EXPORTED int fp_dev_get_nr_enroll_stages(struct fp_dev *dev) /** * fp_dev_get_devtype: - * @dev: the device + * @dev: the struct #fp_dev device * * Gets the [devtype](advanced-topics.html#device-types) for a device. * @@ -493,7 +493,7 @@ API_EXPORTED uint32_t fp_dev_get_devtype(struct fp_dev *dev) /** * fp_dev_supports_print_data: - * @dev: the device + * @dev: the struct #fp_dev device * @data: the stored print * * Determines if a stored print is compatible with a certain device. @@ -510,7 +510,7 @@ API_EXPORTED int fp_dev_supports_print_data(struct fp_dev *dev, /** * fp_dev_supports_dscv_print: - * @dev: the device + * @dev: the struct #fp_dev device * @print: the discovered print * * Determines if a #fp_dscv_print discovered print appears to be compatible @@ -599,7 +599,7 @@ API_EXPORTED int fp_driver_supports_imaging(struct fp_driver *drv) /** * fp_dev_supports_imaging: - * @dev: the fingerprint device + * @dev: the struct #fp_dev device * * Determines if a device has imaging capabilities. If a device has imaging * capabilities you are able to perform imaging operations such as retrieving @@ -617,7 +617,7 @@ API_EXPORTED int fp_dev_supports_imaging(struct fp_dev *dev) /** * fp_dev_supports_identification: - * @dev: the fingerprint device + * @dev: the struct #fp_dev device * * Determines if a device is capable of [identification](intro.html#identification) * through fp_identify_finger() and similar. Not all devices support this @@ -632,7 +632,7 @@ API_EXPORTED int fp_dev_supports_identification(struct fp_dev *dev) /** * fp_dev_get_img_width: - * @dev: the fingerprint device + * @dev: the struct #fp_dev device * * Gets the expected width of images that will be captured from the device. * This function will return -1 for devices that are not @@ -654,7 +654,7 @@ API_EXPORTED int fp_dev_get_img_width(struct fp_dev *dev) /** * fp_dev_get_img_height: - * @dev: the fingerprint device + * @dev: the struct #fp_dev device * * Gets the expected height of images that will be captured from the device. * This function will return -1 for devices that are not diff --git a/libfprint/fpi-sync.c b/libfprint/fpi-sync.c index 5b553675..54e76882 100644 --- a/libfprint/fpi-sync.c +++ b/libfprint/fpi-sync.c @@ -40,7 +40,7 @@ static void sync_open_cb(struct fp_dev *dev, int status, void *user_data) /** * fp_dev_open: - * @ddev: the discovered device to open + * @ddev: the struct #fp_dscv_dev discovered device to open * * Opens and initialises a device. This is the function you call in order * to convert a #fp_dscv_dev discovered device into an actual device handle diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 6c348398..8c249704 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -351,7 +351,7 @@ void fp_set_debug(int level) LIBFPRINT_DEPRECATED; /** * fp_operation_stop_cb: - * @dev: the #fp_dev device + * @dev: the struct #fp_dev device * @user_data: user data passed to the callback * * Type definition for a function that will be called when fp_async_dev_close(), @@ -362,7 +362,7 @@ typedef void (*fp_operation_stop_cb)(struct fp_dev *dev, void *user_data); /** * fp_img_operation_cb: - * @dev: the #fp_dev device + * @dev: the struct #fp_dev device * @result: an #fp_verify_result for fp_async_verify_start(), or an #fp_capture_result * for fp_async_capture_start(), or a negative value on error * @img: the captured #fp_img if capture or verification was successful @@ -376,7 +376,7 @@ typedef void (*fp_img_operation_cb)(struct fp_dev *dev, int result, /** * fp_dev_open_cb: - * @dev: the #fp_dev device + * @dev: the struct #fp_dev device * @status: 0 on success, or a negative value on error * @user_data: user data passed to the callback * @@ -393,7 +393,7 @@ void fp_async_dev_close(struct fp_dev *dev, fp_operation_stop_cb callback, /** * fp_enroll_stage_cb: - * @dev: the #fp_dev device + * @dev: the struct #fp_dev device * @result: a #fp_enroll_result on success, or a negative value on failure * @print: the enrollment data from the final stage * @img: an #fp_img to free with fp_img_free() @@ -419,7 +419,7 @@ int fp_async_verify_stop(struct fp_dev *dev, fp_operation_stop_cb callback, /** * fp_identify_cb: - * @dev: the #fp_dev device + * @dev: the struct #fp_dev device * @result: a #fp_verify_result on success, or a negative value on error. * @match_offset: the array index of the matched gallery print (if any was found). * Only valid if %FP_VERIFY_MATCH was returned. From 531d9048b3232377cd506ece25f46e59fbde431d Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 10:19:17 +0200 Subject: [PATCH 137/225] lib: Fix up third-person usage in API docs --- libfprint/fpi-sync.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/fpi-sync.c b/libfprint/fpi-sync.c index 54e76882..e5a64f81 100644 --- a/libfprint/fpi-sync.c +++ b/libfprint/fpi-sync.c @@ -84,7 +84,7 @@ static void sync_close_cb(struct fp_dev *dev, void *user_data) * fp_dev_close: * @dev: the struct #fp_dev device to close. If %NULL, function simply returns * - * Close a device. You must call this function when you are finished using + * Closes a device. You must call this function when you have finished using * a fingerprint device. */ API_EXPORTED void fp_dev_close(struct fp_dev *dev) @@ -338,7 +338,7 @@ static void verify_stop_cb(struct fp_dev *dev, void *user_data) * storage. If an image is returned, it must be freed with fp_img_free() after * use - * Performs a new scan and verify it against a previously enrolled print. + * Performs a new scan and verifies it against a previously enrolled print. * If the device is an imaging device, it can also return the image from * the scan, even when the verify fails with a RETRY code. It is legal to * call this function even on non-imaging devices, just don't expect them to From e0d2f3ae53dac59b16c9656feb4e123d71891a3e Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 10:20:23 +0200 Subject: [PATCH 138/225] lib: Link to fp_enroll_finger_img() in fp_enroll_stage_cb() doc --- libfprint/fprint.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 8c249704..49f19c13 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -400,7 +400,8 @@ void fp_async_dev_close(struct fp_dev *dev, fp_operation_stop_cb callback, * @user_data: user data passed to the callback * * Type definition for a function that will be called when - * fp_async_enroll_start() finishes. + * fp_async_enroll_start() finishes. See fp_enroll_finger_img() for + * the expected behaviour of your program based on the @result. */ typedef void (*fp_enroll_stage_cb)(struct fp_dev *dev, int result, struct fp_print_data *print, struct fp_img *img, void *user_data); From 422f81b60c9c2c56db12fe82757a23a86d9f49dc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 12:20:40 +0100 Subject: [PATCH 139/225] Revert "lib: Async functions cannot be started without a mainloop" This reverts commit 700c5791f85166db3e8ea1a3b5f93cdfc3abe778. We don't need a poll setup to be able to call sync functions, which then use async functions for implementation internally. Closes: #124 Conflicts: libfprint/fpi-async.c --- libfprint/fpi-async.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index aadbc41a..957874a5 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -21,7 +21,6 @@ #include "fp_internal.h" #include "fpi-async.h" -#include "fpi-poll.h" #include #include @@ -178,7 +177,6 @@ API_EXPORTED int fp_async_enroll_start(struct fp_dev *dev, int r; g_return_val_if_fail(dev != NULL, -ENODEV); - g_return_val_if_fail (fpi_poll_is_setup(), -EIO); g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; @@ -295,7 +293,6 @@ API_EXPORTED int fp_async_verify_start(struct fp_dev *dev, int r; g_return_val_if_fail(dev != NULL, -ENODEV); - g_return_val_if_fail (fpi_poll_is_setup(), -EIO); g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; @@ -430,7 +427,6 @@ API_EXPORTED int fp_async_identify_start(struct fp_dev *dev, int r; g_return_val_if_fail(dev != NULL, -ENODEV); - g_return_val_if_fail (fpi_poll_is_setup(), -EIO); g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; @@ -565,7 +561,6 @@ API_EXPORTED int fp_async_capture_start(struct fp_dev *dev, int unconditional, int r; g_return_val_if_fail(dev != NULL, -ENODEV); - g_return_val_if_fail (fpi_poll_is_setup(), -EIO); g_return_val_if_fail (callback != NULL, -EINVAL); drv = dev->drv; From 0fcb4533b56743d3efb3040ef05b7506b058d06a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 13:28:59 +0100 Subject: [PATCH 140/225] doc: Add more headers to ignore list Those are not public headers, so don't need to be documented. This removes 18 symbols from the undocumented symbols list. --- doc/meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/meson.build b/doc/meson.build index c2c1b772..591cb8ab 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -16,6 +16,7 @@ private_headers = [ 'aesx660.h', 'driver_ids.h', 'elan.h', + 'upek_proto.h', 'upeksonly.h', 'upektc.h', 'upektc_img.h', @@ -32,6 +33,7 @@ private_headers = [ 'log.h', 'bz_array.h', 'lfs.h', + 'mytime.h', ] html_images = [ From 5d4a5981d0916dadcd0eac07f535ddc0b4dd615f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 13:33:02 +0100 Subject: [PATCH 141/225] lib: Make fpi_poll_is_setup() private As it's not used in other parts of the library after the changes in commit 422f81b. --- libfprint/fpi-poll.c | 4 +++- libfprint/fpi-poll.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 18689ec0..8fe79812 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -89,6 +89,8 @@ struct fpi_timeout { char *name; }; +static gboolean fpi_poll_is_setup(void); + static int timeout_sort_fn(gconstpointer _a, gconstpointer _b) { fpi_timeout *a = (fpi_timeout *) _a; @@ -483,7 +485,7 @@ void fpi_poll_exit(void) libusb_set_pollfd_notifiers(fpi_usb_ctx, NULL, NULL, NULL); } -gboolean +static gboolean fpi_poll_is_setup(void) { return (fd_added_cb != NULL && fd_removed_cb != NULL); diff --git a/libfprint/fpi-poll.h b/libfprint/fpi-poll.h index 77c5eabe..2682f277 100644 --- a/libfprint/fpi-poll.h +++ b/libfprint/fpi-poll.h @@ -48,6 +48,4 @@ void fpi_timeout_set_name(fpi_timeout *timeout, const char *name); void fpi_timeout_cancel(fpi_timeout *timeout); -gboolean fpi_poll_is_setup(void); - #endif From 4885b38be5f5b0d56d345447a71a179d51eec5c7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 13:35:40 +0100 Subject: [PATCH 142/225] lib: Rename fpi_img_resize() to fpi_img_realloc() To better match what it does. It does not resize an image, but reallocate its internal data structure's size. --- libfprint/drivers/vfs301.c | 2 +- libfprint/fpi-img.c | 2 +- libfprint/fpi-img.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 815c0ab0..4116e71e 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -71,7 +71,7 @@ submit_image(fpi_ssm *ssm, img->width = VFS301_FP_OUTPUT_WIDTH; img->height = height; - img = fpi_img_resize(img, img->height * img->width); + img = fpi_img_realloc(img, img->height * img->width); fpi_imgdev_image_captured(dev, img); return 1; diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index da112a47..5c24370f 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -87,7 +87,7 @@ gboolean fpi_img_is_sane(struct fp_img *img) return TRUE; } -struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize) +struct fp_img *fpi_img_realloc(struct fp_img *img, size_t newsize) { return g_realloc(img, sizeof(*img) + newsize); } diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h index 4a57be28..7867b4a8 100644 --- a/libfprint/fpi-img.h +++ b/libfprint/fpi-img.h @@ -46,7 +46,7 @@ struct fp_img { struct fp_img *fpi_img_new(size_t length); struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); -struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize); +struct fp_img *fpi_img_realloc(struct fp_img *img, size_t newsize); struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); int fpi_std_sq_dev(const unsigned char *buf, int size); From fe17dfe01d9c616d636287d94ded2d923f7500ec Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 13:36:52 +0100 Subject: [PATCH 143/225] lib: Rename fpi_im_resize() to fpi_img_resize() Now that this name is free. This makes all the image manipulation functions have the same "fpi_img_" prefix. --- libfprint/drivers/aes3k.c | 2 +- libfprint/fpi-img-pixman.c | 2 +- libfprint/fpi-img.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libfprint/drivers/aes3k.c b/libfprint/drivers/aes3k.c index ee802305..59c91bcc 100644 --- a/libfprint/drivers/aes3k.c +++ b/libfprint/drivers/aes3k.c @@ -94,7 +94,7 @@ static void img_cb(struct libusb_transfer *transfer) /* FIXME: this is an ugly hack to make the image big enough for NBIS * to process reliably */ - img = fpi_im_resize(tmp, aesdev->enlarge_factor, aesdev->enlarge_factor); + img = fpi_img_resize(tmp, aesdev->enlarge_factor, aesdev->enlarge_factor); fp_img_free(tmp); fpi_imgdev_image_captured(dev, img); diff --git a/libfprint/fpi-img-pixman.c b/libfprint/fpi-img-pixman.c index 1b4ca06f..47044619 100644 --- a/libfprint/fpi-img-pixman.c +++ b/libfprint/fpi-img-pixman.c @@ -23,7 +23,7 @@ #include "fp_internal.h" -struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor) +struct fp_img *fpi_img_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor) { int new_width = img->width * w_factor; int new_height = img->height * h_factor; diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h index 7867b4a8..666083c4 100644 --- a/libfprint/fpi-img.h +++ b/libfprint/fpi-img.h @@ -47,7 +47,7 @@ struct fp_img { struct fp_img *fpi_img_new(size_t length); struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); struct fp_img *fpi_img_realloc(struct fp_img *img, size_t newsize); -struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); +struct fp_img *fpi_img_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); int fpi_std_sq_dev(const unsigned char *buf, int size); int fpi_mean_sq_diff_norm(unsigned char *buf1, unsigned char *buf2, int size); From 74024010570994018208d04fd8540993fa17f20f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 13:52:26 +0100 Subject: [PATCH 144/225] doc: Add fpi-img section to the docs --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 21 +++++++++++++++++++++ libfprint/fpi-img.c | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index 68543c64..cb0a7f68 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -42,6 +42,7 @@ + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 9d70895a..0c1bdf80 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -196,6 +196,27 @@ fp_dev_set_instance_data FP_INSTANCE_DATA
+
+fpi-img.h +fpi-img +fp_minutiae + +FP_IMG_V_FLIPPED +FP_IMG_H_FLIPPED +FP_IMG_COLORS_INVERTED +FP_IMG_BINARIZED_FORM +FP_IMG_PARTIAL +FP_IMG_STANDARDIZATION_FLAGS + +fpi_img_new +fpi_img_new_for_imgdev +fpi_img_realloc +fpi_img_resize + +fpi_std_sq_dev +fpi_mean_sq_diff_norm +
+
fpi-usb.h fpi-usb diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 5c24370f..341f811e 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -48,6 +48,15 @@ * natural upright orientation. */ +/** + * SECTION:fpi-img + * @title: Driver Image operations + * + * Those are the driver-specific helpers for #fp_img manipulation. See #fp_img's + * documentation for more information about data formats, and their uses in + * front-end applications. + */ + struct fp_img *fpi_img_new(size_t length) { struct fp_img *img = g_malloc0(sizeof(*img) + length); From 6e230f0a072b93eddd6e5d15515bc3ba75ebb5af Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 13:53:03 +0100 Subject: [PATCH 145/225] doc: Add missing fpi_timeout_set_name() to the docs --- doc/libfprint-sections.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 0c1bdf80..a2977278 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -182,6 +182,7 @@ fpi_ssm_get_cur_state fpi_timeout fpi_timeout_fn fpi_timeout_add +fpi_timeout_set_name fpi_timeout_cancel
From 857a399bfa992866ebe7f46211c8b18961b404ef Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 13:56:42 +0100 Subject: [PATCH 146/225] doc: Fix parameter names in fp_minutia_get_coords() docs The API docs for fp_minutia_get_coords() as added in commit 1006467 had the parameters in the docs not match the actual names used. --- libfprint/fpi-img.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 341f811e..08b751d5 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -551,10 +551,10 @@ API_EXPORTED struct fp_minutia **fp_img_get_minutiae(struct fp_img *img, /** * fp_minutia_get_coords: * @minutia: a struct #fp_minutia - * @x: the return variable for the X coordinate of the minutia - * @y: the return variable for the Y coordinate of the minutia + * @coord_x: the return variable for the X coordinate of the minutia + * @coord_y: the return variable for the Y coordinate of the minutia * - * Sets @x and @y to be the coordinates of the detected minutia, so it + * Sets @coord_x and @coord_y to be the coordinates of the detected minutia, so it * can be presented in a more verbose user interface. This is usually only * used for debugging purposes. * From 6c6daaa619d27be5deda2d2b2df89d90d139faa0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 14:08:04 +0100 Subject: [PATCH 147/225] doc: Add fpi-assembling section to the docs --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 12 ++++++++++++ libfprint/fpi-assembling.c | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index cb0a7f68..832be0c6 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -43,6 +43,7 @@ + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index a2977278..53ccce0b 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -218,6 +218,18 @@ fpi_std_sq_dev fpi_mean_sq_diff_norm +
+fpi-assembling.h +fpi-assembling +fpi_frame +fpi_frame_asmbl_ctx +fpi_line_asmbl_ctx + +fpi_do_movement_estimation +fpi_assemble_frames +fpi_assemble_lines +
+
fpi-usb.h fpi-usb diff --git a/libfprint/fpi-assembling.c b/libfprint/fpi-assembling.c index c192c8fa..b4d74c06 100644 --- a/libfprint/fpi-assembling.c +++ b/libfprint/fpi-assembling.c @@ -31,6 +31,16 @@ #include "fpi-assembling.h" +/** + * SECTION:fpi-assembling + * @title: Image frame assembly + * + * Those are the helpers to manipulate capture data from fingerprint readers + * into a uniform image that can be further processed. This is usually used + * by drivers for devices which have a small sensor and thus need to capture + * data in small stripes. + */ + static unsigned int calc_error(struct fpi_frame_asmbl_ctx *ctx, struct fpi_frame *first_frame, struct fpi_frame *second_frame, From 2365c608f9c0eb00bc8a940874f361514335d281 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 14:20:19 +0100 Subject: [PATCH 148/225] lib: Change "unsigned" to "unsigned int" To appease gtk-doc's struct parser, which chokes on the short name for the data type. See https://gitlab.gnome.org/GNOME/gtk-doc/issues/63 --- libfprint/fpi-assembling.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libfprint/fpi-assembling.h b/libfprint/fpi-assembling.h index c0e2b09d..fdd9518b 100644 --- a/libfprint/fpi-assembling.h +++ b/libfprint/fpi-assembling.h @@ -29,13 +29,13 @@ struct fpi_frame { }; struct fpi_frame_asmbl_ctx { - unsigned frame_width; - unsigned frame_height; - unsigned image_width; + unsigned int frame_width; + unsigned int frame_height; + unsigned int image_width; unsigned char (*get_pixel)(struct fpi_frame_asmbl_ctx *ctx, struct fpi_frame *frame, - unsigned x, - unsigned y); + unsigned int x, + unsigned int y); }; void fpi_do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx, @@ -45,16 +45,16 @@ struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx, GSList *stripes, size_t stripes_len); struct fpi_line_asmbl_ctx { - unsigned line_width; - unsigned max_height; - unsigned resolution; - unsigned median_filter_size; - unsigned max_search_offset; + unsigned int line_width; + unsigned int max_height; + unsigned int resolution; + unsigned int median_filter_size; + unsigned int max_search_offset; int (*get_deviation)(struct fpi_line_asmbl_ctx *ctx, GSList *line1, GSList *line2); unsigned char (*get_pixel)(struct fpi_line_asmbl_ctx *ctx, GSList *line, - unsigned x); + unsigned int x); }; struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx, From f45c18116aeb654cbfdc7f8a783c1197f3ddceef Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 14:21:10 +0100 Subject: [PATCH 149/225] doc: Add fpi-data section to the docs --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 10 ++++++++++ libfprint/fpi-data.c | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index 832be0c6..ac42ceb0 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -44,6 +44,7 @@ + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 53ccce0b..b09840ee 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -230,6 +230,16 @@ fpi_assemble_frames fpi_assemble_lines
+
+fpi-data.h +fpi-data +fp_print_data_type +fp_print_data_item + +fpi_print_data_new +fpi_print_data_item_new +
+
fpi-usb.h fpi-usb diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index f38bdf38..173be86f 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -63,6 +63,15 @@ struct fpi_print_data_item_fp2 { * in any fashion that suits you. */ +/** + * SECTION: fpi-data + * @title: Stored prints creation + * + * Stored print can be loaded and created by certain drivers which do their own + * print matching in hardware. Most drivers will not be using those functions. + * See #fp_print_data for the public API counterpart. + */ + static char *base_store = NULL; static void storage_setup(void) From f2e3a840db7b9c57816fb355a82631dbba2ba596 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 14:43:58 +0100 Subject: [PATCH 150/225] doc: Add fpi-core and fpi-core-img sections to the docs --- doc/libfprint-docs.xml | 2 ++ doc/libfprint-sections.txt | 14 ++++++++++++++ libfprint/fpi-core.c | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index ac42ceb0..21fd5905 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -40,6 +40,8 @@ Writing Drivers + + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index b09840ee..ea6ee945 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -197,6 +197,20 @@ fp_dev_set_instance_data FP_INSTANCE_DATA
+
+fpi-core.h +fpi-core +usb_id +fp_driver_type +
+ +
+fpi-core.h +fpi-core-img +FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE +fp_img_driver +
+
fpi-img.h fpi-img diff --git a/libfprint/fpi-core.c b/libfprint/fpi-core.c index fc197570..75b2838d 100644 --- a/libfprint/fpi-core.c +++ b/libfprint/fpi-core.c @@ -111,6 +111,25 @@ GSList *opened_devices = NULL; * verification) on some devices which do not provide images. */ +/** + * SECTION:fpi-core + * @title: Driver structures + * + * Driver structures need to be defined inside each driver in + * order for the core library to know what function to call, and the capabilities + * of the driver and the devices it supports. + */ + +/** + * SECTION:fpi-core-img + * @title: Image driver structures + * + * Image driver structures need to be defined inside each image driver in + * order for the core library to know what function to call, and the capabilities + * of the driver and the devices it supports. Its structure is based off the + * #fp_driver struct. + */ + static GSList *registered_drivers = NULL; static void register_driver(struct fp_driver *drv) From 4f7e5077166d71ec91e1d44948775b895d5f171c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 14:52:11 +0100 Subject: [PATCH 151/225] doc: Add fpi-dev-img section to the docs --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 22 ++++++++++++++++++++++ libfprint/fpi-dev-img.c | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index 21fd5905..ce174d1e 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -40,6 +40,7 @@ Writing Drivers + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index ea6ee945..6dc4ee2e 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -197,6 +197,28 @@ fp_dev_set_instance_data FP_INSTANCE_DATA
+
+fpi-dev-img.h +fpi-dev-img +fp_imgdev_action +fp_imgdev_state +fp_imgdev_enroll_state +fp_imgdev_verify_state + +fpi_imgdev_abort_scan +fpi_imgdev_activate_complete +fpi_imgdev_close_complete +fpi_imgdev_deactivate_complete +fpi_imgdev_get_action +fpi_imgdev_get_action_result +fpi_imgdev_get_action_state +fpi_imgdev_image_captured +fpi_imgdev_open_complete +fpi_imgdev_report_finger_status +fpi_imgdev_session_error +fpi_imgdev_set_action_result +
+
fpi-core.h fpi-core diff --git a/libfprint/fpi-dev-img.c b/libfprint/fpi-dev-img.c index a61e13c4..bdf4fec5 100644 --- a/libfprint/fpi-dev-img.c +++ b/libfprint/fpi-dev-img.c @@ -25,6 +25,15 @@ #include "fpi-async.h" #include "fp_internal.h" +/** + * SECTION:fpi-dev-img + * @title: Image device operations + * + * As drivers work through different operations, they need to report back + * to the core as to their internal state, so errors and successes can be + * reported back to front-ends. + */ + #define MIN_ACCEPTABLE_MINUTIAE 10 #define BOZORTH3_DEFAULT_THRESHOLD 40 #define IMG_ENROLL_STAGES 5 From 53d2fb3ad218335ba609bb8afc0f26c1c0fb1aa5 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 14:53:58 +0100 Subject: [PATCH 152/225] doc: Add more functions to fpi-dev section And rename section to match that of fpi-dev-img --- doc/libfprint-sections.txt | 4 ++++ libfprint/fpi-dev.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 6dc4ee2e..9a7b1576 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -195,6 +195,10 @@ FP_DEV FP_IMG_DEV fp_dev_set_instance_data FP_INSTANCE_DATA + +fpi_dev_get_usb_dev +fpi_dev_get_verify_data +fpi_dev_set_nr_enroll_stages
diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index f97ee61d..8ad7dd5d 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -22,7 +22,7 @@ /** * SECTION:fpi-dev - * @title: Device structures + * @title: Device operations * * Those macros and functions will help get access to and from struct #fp_dev, * and struct #fp_img_dev types, as well as get and set the instance struct From a97ae3bc35609e426e15746d0418217ebc19f9a4 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 15:00:10 +0100 Subject: [PATCH 153/225] doc: Add fpi-async section to the docs --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 19 +++++++++++++++++++ libfprint/fpi-async.c | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index ce174d1e..a9705bc6 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -43,6 +43,7 @@ + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 9a7b1576..7c6c983f 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -237,6 +237,25 @@ FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE fp_img_driver
+
+fpi-async.h +fpi-async +fpi_drvcb_capture_started +fpi_drvcb_capture_stopped +fpi_drvcb_close_complete +fpi_drvcb_enroll_stage_completed +fpi_drvcb_enroll_started +fpi_drvcb_enroll_stopped +fpi_drvcb_identify_started +fpi_drvcb_identify_stopped +fpi_drvcb_open_complete +fpi_drvcb_report_capture_result +fpi_drvcb_report_identify_result +fpi_drvcb_report_verify_result +fpi_drvcb_verify_started +fpi_drvcb_verify_stopped +
+
fpi-img.h fpi-img diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index 957874a5..cc1e6ed5 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -26,6 +26,14 @@ #include #include +/** + * SECTION:fpi-async + * @title: Asynchronous operations reporting + * + * Those functions are used by primitive drivers to report back their + * current status. Most drivers, imaging ones, do not need to use them. + */ + /* Drivers call this when device initialisation has completed */ void fpi_drvcb_open_complete(struct fp_dev *dev, int status) { From 3dc5c4a6deabcc4c217fc2e8b5005db2ccd23d98 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 15:06:54 +0100 Subject: [PATCH 154/225] doc: Add LIBFPRINT_DEPRECATED to the docs --- doc/libfprint-sections.txt | 1 + libfprint/fprint.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 7c6c983f..103d0103 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -3,6 +3,7 @@ fprint.h events Initialisation and events handling +LIBFPRINT_DEPRECATED fp_set_debug fp_init fp_exit diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 49f19c13..c6efecc2 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -29,6 +29,13 @@ extern "C" { #include #include +/** + * LIBFPRINT_DEPRECATED: + * + * Expands to the GNU C deprecated attribute if the compiler is `gcc`. When + * called with the `-Wdeprecated-declarations` option, `gcc` will generate warnings + * when deprecated interfaces are used. + */ #define LIBFPRINT_DEPRECATED __attribute__((__deprecated__)) /** From 23f7c4aaf74251de90b7b24d1728f838021017bb Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 15:07:20 +0100 Subject: [PATCH 155/225] doc: Hide G_LOG_DOMAIN from gtk-doc It's only used internally, and doesn't need to be documented here, as FP_COMPONENT which uses it already is. --- libfprint/fpi-log.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h index 6b494af3..0d13400b 100644 --- a/libfprint/fpi-log.h +++ b/libfprint/fpi-log.h @@ -35,8 +35,10 @@ #ifdef FP_COMPONENT #undef G_LOG_DOMAIN +#ifndef __GTK_DOC_IGNORE__ #define G_LOG_DOMAIN "libfprint-"FP_COMPONENT #endif +#endif #include From 2951daaa01a7aa8585f99259db5d3513a3a93489 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Nov 2018 15:32:17 +0100 Subject: [PATCH 156/225] doc: Split driver docs into chapters --- doc/libfprint-docs.xml | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index a9705bc6..11ad54aa 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -38,17 +38,32 @@ Writing Drivers - - - - - - - - - - - + + Logging, and async machinery + + + + + + + Device and driver structures + + + + + + + + Image manipulation + + + + + + Hardware print matchine + + + From 5edfd55e00ba76b461d1f125e976d87aa7d03a0b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 12:10:11 +0100 Subject: [PATCH 157/225] doc: Fix typo in chapter title --- doc/libfprint-docs.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index 11ad54aa..a330bebf 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -60,7 +60,7 @@ - Hardware print matchine + Hardware print matching From 7a72d8fd5875153c0c486edc119902b3e34438f6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 12:47:05 +0200 Subject: [PATCH 158/225] lib: Fix uninitialised variable in fpi_imgdev_image_captured() libfprint/fpi-dev-img.c:255:6: warning: variable 'print' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (imgdev->action != IMG_ACTION_CAPTURE) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/fpi-dev-img.c:271:25: note: uninitialized use occurs here imgdev->acquire_data = print; ^~~~~ libfprint/fpi-dev-img.c:255:2: note: remove the 'if' if its condition is always true if (imgdev->action != IMG_ACTION_CAPTURE) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/fpi-dev-img.c:232:29: note: initialize the variable 'print' to silence this warning struct fp_print_data *print; ^ = NULL --- libfprint/fpi-dev-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-dev-img.c b/libfprint/fpi-dev-img.c index bdf4fec5..b094da23 100644 --- a/libfprint/fpi-dev-img.c +++ b/libfprint/fpi-dev-img.c @@ -238,7 +238,7 @@ void fpi_imgdev_abort_scan(struct fp_img_dev *imgdev, int result) void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img) { - struct fp_print_data *print; + struct fp_print_data *print = NULL; int r; G_DEBUG_HERE(); From 4dcbc6a3aaa72a1e4a18a0b03b05557904bc29b7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 12:49:52 +0200 Subject: [PATCH 159/225] vfs101: Fix typo in "VFS_IMG_BEST_CONRAST" constant It's contrast, says so above the definition. --- libfprint/drivers/vfs101.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index cf6980f1..1ea40307 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -56,7 +56,7 @@ #define VFS_IMG_MIN_IMAGE_LEVEL 144 /* Best image contrast */ -#define VFS_IMG_BEST_CONRAST 128 +#define VFS_IMG_BEST_CONTRAST 128 /* Device parameters address */ #define VFS_PAR_000E 0x000e @@ -851,7 +851,7 @@ static void vfs_check_contrast(struct vfs101_dev *vdev) fp_dbg("contrast = %d, level = %ld", vdev->contrast, count); - if (abs(count - VFS_IMG_BEST_CONRAST) < abs(vdev->best_clevel - VFS_IMG_BEST_CONRAST)) + if (abs(count - VFS_IMG_BEST_CONTRAST) < abs(vdev->best_clevel - VFS_IMG_BEST_CONTRAST)) { /* Better contrast found, use it */ vdev->best_contrast = vdev->contrast; From e5f4021a4f63648592abea9a5fd513dd9c24d956 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 12:51:47 +0200 Subject: [PATCH 160/225] vfs101: Fix warning about value truncation libfprint/drivers/vfs101.c:854:6: warning: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value] if (abs(count - VFS_IMG_BEST_CONTRAST) < abs(vdev->best_clevel - VFS_IMG_BEST_CONTRAST)) ^ libfprint/drivers/vfs101.c:854:6: note: use function 'labs' instead if (abs(count - VFS_IMG_BEST_CONTRAST) < abs(vdev->best_clevel - VFS_IMG_BEST_CONTRAST)) ^~~ labs --- libfprint/drivers/vfs101.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 1ea40307..32c67394 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -851,7 +851,7 @@ static void vfs_check_contrast(struct vfs101_dev *vdev) fp_dbg("contrast = %d, level = %ld", vdev->contrast, count); - if (abs(count - VFS_IMG_BEST_CONTRAST) < abs(vdev->best_clevel - VFS_IMG_BEST_CONTRAST)) + if (labs(count - VFS_IMG_BEST_CONTRAST) < abs(vdev->best_clevel - VFS_IMG_BEST_CONTRAST)) { /* Better contrast found, use it */ vdev->best_contrast = vdev->contrast; From 9da69dfc3699bd71c5153ed6315d573a2cc891f4 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 12:53:29 +0200 Subject: [PATCH 161/225] elan: Fix format mismatch warnings in debug output libfprint/drivers/elan.c:351:12: warning: format specifies type 'unsigned short' but the argument has type 'unsigned char' [-Wformat] dbg_buf(elandev->last_read, transfer->actual_length); ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/drivers/elan.c:46:21: note: expanded from macro 'dbg_buf' fp_dbg("%02hx", buf[0]); \ ~~~~~~~~~~~~~~~~^~~~~~~ include/glib-2.0/glib/gmessages.h:345:32: note: expanded from macro 'g_debug' __VA_ARGS__) ^~~~~~~~~~~ libfprint/drivers/elan.c:351:12: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] dbg_buf(elandev->last_read, transfer->actual_length); ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/drivers/elan.c:48:21: note: expanded from macro 'dbg_buf' fp_dbg("%04hx", buf[0] << 8 | buf[1]); \ ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ include/glib-2.0/glib/gmessages.h:345:32: note: expanded from macro 'g_debug' __VA_ARGS__) ^~~~~~~~~~~ libfprint/drivers/elan.c:351:12: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] dbg_buf(elandev->last_read, transfer->actual_length); ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/drivers/elan.c:50:35: note: expanded from macro 'dbg_buf' fp_dbg("%04hx... (%d bytes)", buf[0] << 8 | buf[1], len) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ include/glib-2.0/glib/gmessages.h:345:32: note: expanded from macro 'g_debug' __VA_ARGS__) ^~~~~~~~~~~ libfprint/drivers/elan.c:413:10: warning: format specifies type 'unsigned short' but the argument has type 'unsigned char' [-Wformat] dbg_buf(cmd->cmd, 2); ~~~~~~~~^~~~~~~~~~~~ libfprint/drivers/elan.c:46:21: note: expanded from macro 'dbg_buf' fp_dbg("%02hx", buf[0]); \ ~~~~~~~~~~~~~~~~^~~~~~~ include/glib-2.0/glib/gmessages.h:345:32: note: expanded from macro 'g_debug' __VA_ARGS__) ^~~~~~~~~~~ libfprint/drivers/elan.c:413:10: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] dbg_buf(cmd->cmd, 2); ~~~~~~~~^~~~~~~~~~~~ libfprint/drivers/elan.c:48:21: note: expanded from macro 'dbg_buf' fp_dbg("%04hx", buf[0] << 8 | buf[1]); \ ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ include/glib-2.0/glib/gmessages.h:345:32: note: expanded from macro 'g_debug' __VA_ARGS__) ^~~~~~~~~~~ libfprint/drivers/elan.c:413:10: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] dbg_buf(cmd->cmd, 2); ~~~~~~~~^~~~~~~~~~~~ libfprint/drivers/elan.c:50:35: note: expanded from macro 'dbg_buf' fp_dbg("%04hx... (%d bytes)", buf[0] << 8 | buf[1], len) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ include/glib-2.0/glib/gmessages.h:345:32: note: expanded from macro 'g_debug' __VA_ARGS__) ^~~~~~~~~~~ --- libfprint/drivers/elan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index a2c1105c..32d75349 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -43,11 +43,11 @@ #define dbg_buf(buf, len) \ if (len == 1) \ - fp_dbg("%02hx", buf[0]); \ + fp_dbg("%02x", buf[0]); \ else if (len == 2) \ - fp_dbg("%04hx", buf[0] << 8 | buf[1]); \ + fp_dbg("%04x", buf[0] << 8 | buf[1]); \ else if (len > 2) \ - fp_dbg("%04hx... (%d bytes)", buf[0] << 8 | buf[1], len) + fp_dbg("%04x... (%d bytes)", buf[0] << 8 | buf[1], len) unsigned char elan_get_pixel(struct fpi_frame_asmbl_ctx *ctx, struct fpi_frame *frame, unsigned int x, From 11b11a9d71cbaee63cdbc0f02abf8c371a63b26c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 23 Oct 2018 16:24:14 +0200 Subject: [PATCH 162/225] lib: Fix get_next_timeout_expiry If get_next_timeout_expiry() fails, and libusb_get_next_timeout() has no timeouts or failed, fprint_timeout will not be set, and we cannot compare it to libusb_timeout. Exit early if both failed or have empty queues. --- libfprint/fpi-poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 8fe79812..f3303e03 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -381,7 +381,7 @@ API_EXPORTED int fp_get_next_timeout(struct timeval *tv) /* if we have no pending timeouts and the same is true for libusb, * indicate that we have no pending timouts */ - if (r_fprint == 0 && r_libusb == 0) + if (r_fprint <= 0 && r_libusb <= 0) return 0; /* if fprint have no pending timeouts return libusb timeout */ From f7173e66456c8eb14a13aa35694fa0f792329fe7 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 11 Oct 2018 18:03:50 +0200 Subject: [PATCH 163/225] ci: Add GTK+ to the CI --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ffbdba6e..0854eac1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: DEPENDENCIES: libusb1-devel glib2-devel nss-devel pixman-devel systemd meson gtk-doc - gcc gcc-c++ glibc-devel libX11-devel libXv-devel + gcc gcc-c++ glibc-devel libX11-devel libXv-devel gtk3-devel before_script: From 29461fa910e86f9a1d6c10ecdca85200bcf217de Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 8 Oct 2018 16:33:04 +0200 Subject: [PATCH 164/225] demo: Add GTK+ test application --- demo/gtk-libfprint-test.c | 514 ++++++++++++++++++++++++++ demo/gtk-libfprint-test.gresource.xml | 6 + demo/gtk-libfprint-test.ui | 351 ++++++++++++++++++ demo/loop.c | 196 ++++++++++ demo/loop.h | 27 ++ demo/meson.build | 17 + meson.build | 12 + meson_options.txt | 4 + 8 files changed, 1127 insertions(+) create mode 100644 demo/gtk-libfprint-test.c create mode 100644 demo/gtk-libfprint-test.gresource.xml create mode 100644 demo/gtk-libfprint-test.ui create mode 100644 demo/loop.c create mode 100644 demo/loop.h create mode 100644 demo/meson.build diff --git a/demo/gtk-libfprint-test.c b/demo/gtk-libfprint-test.c new file mode 100644 index 00000000..b23e38dd --- /dev/null +++ b/demo/gtk-libfprint-test.c @@ -0,0 +1,514 @@ +/* + * Example libfprint GTK+ image capture program + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include +#include + +#include "loop.h" + +typedef GtkApplication LibfprintDemo; +typedef GtkApplicationClass LibfprintDemoClass; + +G_DEFINE_TYPE (LibfprintDemo, libfprint_demo, GTK_TYPE_APPLICATION) + +typedef enum { + IMAGE_DISPLAY_NONE = 0, + IMAGE_DISPLAY_MINUTIAE = 1 << 0, + IMAGE_DISPLAY_BINARY = 1 << 1 +} ImageDisplayFlags; + +typedef struct { + GtkApplicationWindow parent_instance; + + GtkWidget *header_bar; + GtkWidget *mode_stack; + GtkWidget *capture_button; + GtkWidget *capture_image; + GtkWidget *spinner; + GtkWidget *instructions; + + struct fp_dscv_dev *ddev; + struct fp_dev *dev; + + struct fp_img *img; + ImageDisplayFlags img_flags; +} LibfprintDemoWindow; + +typedef GtkApplicationWindowClass LibfprintDemoWindowClass; + +G_DEFINE_TYPE (LibfprintDemoWindow, libfprint_demo_window, GTK_TYPE_APPLICATION_WINDOW) + +typedef enum { + EMPTY_MODE, + NOIMAGING_MODE, + CAPTURE_MODE, + SPINNER_MODE, + ERROR_MODE +} LibfprintDemoMode; + +static void libfprint_demo_set_mode (LibfprintDemoWindow *win, + LibfprintDemoMode mode); + +static void +pixbuf_destroy (guchar *pixels, gpointer data) +{ + if (pixels == NULL) + return; + g_free (pixels); +} + +static unsigned char * +img_to_rgbdata (struct fp_img *img, + int width, + int height) +{ + int size = width * height; + unsigned char *imgdata = fp_img_get_data (img); + unsigned char *rgbdata = g_malloc (size * 3); + size_t i; + size_t rgb_offset = 0; + + for (i = 0; i < size; i++) { + unsigned char pixel = imgdata[i]; + + rgbdata[rgb_offset++] = pixel; + rgbdata[rgb_offset++] = pixel; + rgbdata[rgb_offset++] = pixel; + } + + return rgbdata; +} + +static void +plot_minutiae (unsigned char *rgbdata, + int width, + int height, + struct fp_minutia **minlist, + int nr_minutiae) +{ + int i; +#define write_pixel(num) do { \ + rgbdata[((num) * 3)] = 0xff; \ + rgbdata[((num) * 3) + 1] = 0; \ + rgbdata[((num) * 3) + 2] = 0; \ + } while(0) + + for (i = 0; i < nr_minutiae; i++) { + struct fp_minutia *min = minlist[i]; + int x, y; + size_t pixel_offset; + + fp_minutia_get_coords(min, &x, &y); + pixel_offset = (y * width) + x; + write_pixel(pixel_offset - 2); + write_pixel(pixel_offset - 1); + write_pixel(pixel_offset); + write_pixel(pixel_offset + 1); + write_pixel(pixel_offset + 2); + + write_pixel(pixel_offset - (width * 2)); + write_pixel(pixel_offset - (width * 1) - 1); + write_pixel(pixel_offset - (width * 1)); + write_pixel(pixel_offset - (width * 1) + 1); + write_pixel(pixel_offset + (width * 1) - 1); + write_pixel(pixel_offset + (width * 1)); + write_pixel(pixel_offset + (width * 1) + 1); + write_pixel(pixel_offset + (width * 2)); + } +} + +static GdkPixbuf * +img_to_pixbuf (struct fp_img *img, + ImageDisplayFlags flags) +{ + int width; + int height; + unsigned char *rgbdata; + + width = fp_img_get_width (img); + height = fp_img_get_height (img); + + if (flags & IMAGE_DISPLAY_BINARY) { + struct fp_img *binary; + binary = fp_img_binarize (img); + rgbdata = img_to_rgbdata (binary, width, height); + fp_img_free (binary); + } else { + rgbdata = img_to_rgbdata (img, width, height); + } + + if (flags & IMAGE_DISPLAY_MINUTIAE) { + struct fp_minutia **minlist; + int nr_minutiae; + + minlist = fp_img_get_minutiae (img, &nr_minutiae); + plot_minutiae (rgbdata, width, height, minlist, nr_minutiae); + } + + return gdk_pixbuf_new_from_data (rgbdata, GDK_COLORSPACE_RGB, + FALSE, 8, width, height, + width * 3, pixbuf_destroy, + NULL); +} + +static void +update_image (LibfprintDemoWindow *win) +{ + GdkPixbuf *pixbuf; + + if (win->img == NULL) { + gtk_image_clear (GTK_IMAGE (win->capture_image)); + return; + } + + g_debug ("Updating image, minutiae %s, binary mode %s", + win->img_flags & IMAGE_DISPLAY_MINUTIAE ? "shown" : "hidden", + win->img_flags & IMAGE_DISPLAY_BINARY ? "on" : "off"); + pixbuf = img_to_pixbuf (win->img, win->img_flags); + gtk_image_set_from_pixbuf (GTK_IMAGE (win->capture_image), pixbuf); + g_object_unref (pixbuf); +} + +static void +libfprint_demo_set_spinner_label (LibfprintDemoWindow *win, + const char *message) +{ + char *label; + + label = g_strdup_printf ("%s", message); + gtk_label_set_markup (GTK_LABEL (win->instructions), label); + g_free (label); +} + +static void +libfprint_demo_set_capture_label (LibfprintDemoWindow *win) +{ + struct fp_driver *drv; + enum fp_scan_type scan_type; + const char *message; + + drv = fp_dscv_dev_get_driver (win->ddev); + scan_type = fp_driver_get_scan_type(drv); + + switch (scan_type) { + case FP_SCAN_TYPE_PRESS: + message = "Place your finger on the fingerprint reader"; + break; + case FP_SCAN_TYPE_SWIPE: + message = "Swipe your finger across the fingerprint reader"; + break; + default: + g_assert_not_reached (); + } + + libfprint_demo_set_spinner_label (win, message); +} + +static void +dev_capture_start_cb (struct fp_dev *dev, + int result, + struct fp_img *img, + void *user_data) +{ + LibfprintDemoWindow *win = user_data; + + if (result < 0) { + libfprint_demo_set_mode (win, ERROR_MODE); + return; + } + + fp_async_capture_stop (dev, NULL, NULL); + + win->img = img; + update_image (win); + + libfprint_demo_set_mode (win, CAPTURE_MODE); +} + +static void +dev_open_cb (struct fp_dev *dev, int status, void *user_data) +{ + LibfprintDemoWindow *win = user_data; + int r; + + if (status < 0) { + libfprint_demo_set_mode (win, ERROR_MODE); + return; + } + + libfprint_demo_set_capture_label (win); + + win->dev = dev; + r = fp_async_capture_start (win->dev, FALSE, dev_capture_start_cb, user_data); + if (r < 0) { + g_warning ("fp_async_capture_start failed: %d", r); + libfprint_demo_set_mode (win, ERROR_MODE); + return; + } +} + +static void +activate_capture (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + LibfprintDemoWindow *win = user_data; + int r; + + libfprint_demo_set_mode (win, SPINNER_MODE); + g_clear_pointer (&win->img, fp_img_free); + + if (win->dev != NULL) { + dev_open_cb (win->dev, 0, user_data); + return; + } + + libfprint_demo_set_spinner_label (win, "Opening fingerprint reader"); + + r = fp_async_dev_open (win->ddev, dev_open_cb, user_data); + if (r < 0) { + g_warning ("fp_async_dev_open failed: %d", r); + libfprint_demo_set_mode (win, ERROR_MODE); + return; + } +} + +static void +activate_quit (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GtkApplication *app = user_data; + GtkWidget *win; + GList *list, *next; + + list = gtk_application_get_windows (app); + while (list) + { + win = list->data; + next = list->next; + + gtk_widget_destroy (GTK_WIDGET (win)); + + list = next; + } +} + +static void +activate_show_minutiae (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + LibfprintDemoWindow *win = user_data; + GVariant *state; + gboolean new_state; + + state = g_action_get_state (G_ACTION (action)); + new_state = !g_variant_get_boolean (state); + g_action_change_state (G_ACTION (action), g_variant_new_boolean (new_state)); + g_variant_unref (state); + + if (new_state) + win->img_flags |= IMAGE_DISPLAY_MINUTIAE; + else + win->img_flags &= ~IMAGE_DISPLAY_MINUTIAE; + + update_image (win); +} + +static void +activate_show_binary (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + LibfprintDemoWindow *win = user_data; + GVariant *state; + gboolean new_state; + + state = g_action_get_state (G_ACTION (action)); + new_state = !g_variant_get_boolean (state); + g_action_change_state (G_ACTION (action), g_variant_new_boolean (new_state)); + g_variant_unref (state); + + if (new_state) + win->img_flags |= IMAGE_DISPLAY_BINARY; + else + win->img_flags &= ~IMAGE_DISPLAY_BINARY; + + update_image (win); +} + +static void +change_show_minutiae_state (GSimpleAction *action, + GVariant *state, + gpointer user_data) +{ + g_simple_action_set_state (action, state); +} + +static void +change_show_binary_state (GSimpleAction *action, + GVariant *state, + gpointer user_data) +{ + g_simple_action_set_state (action, state); +} + +static GActionEntry app_entries[] = { + { "quit", activate_quit, NULL, NULL, NULL }, +}; + +static GActionEntry win_entries[] = { + { "show-minutiae", activate_show_minutiae, NULL, "false", change_show_minutiae_state }, + { "show-binary", activate_show_binary, NULL, "false", change_show_binary_state }, + { "capture", activate_capture, NULL, NULL, NULL } +}; + +static void +activate (GApplication *app) +{ + LibfprintDemoWindow *window; + + window = g_object_new (libfprint_demo_window_get_type (), + "application", app, + NULL); + gtk_widget_show (GTK_WIDGET (window)); +} + +static void +libfprint_demo_set_mode (LibfprintDemoWindow *win, + LibfprintDemoMode mode) +{ + struct fp_driver *drv; + char *title; + + switch (mode) { + case EMPTY_MODE: + gtk_stack_set_visible_child_name (GTK_STACK (win->mode_stack), "empty-mode"); + gtk_widget_set_sensitive (win->capture_button, FALSE); + gtk_spinner_stop (GTK_SPINNER (win->spinner)); + break; + case NOIMAGING_MODE: + gtk_stack_set_visible_child_name (GTK_STACK (win->mode_stack), "noimaging-mode"); + gtk_widget_set_sensitive (win->capture_button, FALSE); + gtk_spinner_stop (GTK_SPINNER (win->spinner)); + break; + case CAPTURE_MODE: + gtk_stack_set_visible_child_name (GTK_STACK (win->mode_stack), "capture-mode"); + gtk_widget_set_sensitive (win->capture_button, TRUE); + + drv = fp_dscv_dev_get_driver (win->ddev); + title = g_strdup_printf ("%s Test", fp_driver_get_full_name (drv)); + gtk_header_bar_set_title (GTK_HEADER_BAR (win->header_bar), title); + g_free (title); + + gtk_spinner_stop (GTK_SPINNER (win->spinner)); + break; + case SPINNER_MODE: + gtk_stack_set_visible_child_name (GTK_STACK (win->mode_stack), "spinner-mode"); + gtk_widget_set_sensitive (win->capture_button, FALSE); + gtk_spinner_start (GTK_SPINNER (win->spinner)); + break; + case ERROR_MODE: + gtk_stack_set_visible_child_name (GTK_STACK (win->mode_stack), "error-mode"); + gtk_widget_set_sensitive (win->capture_button, FALSE); + gtk_spinner_stop (GTK_SPINNER (win->spinner)); + break; + default: + g_assert_not_reached (); + } +} + +static void +libfprint_demo_init (LibfprintDemo *app) +{ + g_action_map_add_action_entries (G_ACTION_MAP (app), + app_entries, G_N_ELEMENTS (app_entries), + app); +} + +static void +libfprint_demo_class_init (LibfprintDemoClass *class) +{ + GApplicationClass *app_class = G_APPLICATION_CLASS (class); + + app_class->activate = activate; +} + +static void +libfprint_demo_window_init (LibfprintDemoWindow *window) +{ + struct fp_dscv_dev **discovered_devs; + + gtk_widget_init_template (GTK_WIDGET (window)); + gtk_window_set_default_size (GTK_WINDOW (window), 700, 500); + + g_action_map_add_action_entries (G_ACTION_MAP (window), + win_entries, G_N_ELEMENTS (win_entries), + window); + + if (fp_init () < 0) { + libfprint_demo_set_mode (window, ERROR_MODE); + return; + } + + setup_pollfds (); + + discovered_devs = fp_discover_devs(); + if (!discovered_devs) + return; + + if (!fp_driver_supports_imaging(fp_dscv_dev_get_driver(discovered_devs[0]))) { + libfprint_demo_set_mode (window, NOIMAGING_MODE); + return; + } + + window->ddev = discovered_devs[0]; + libfprint_demo_set_mode (window, CAPTURE_MODE); +} + +static void +libfprint_demo_window_class_init (LibfprintDemoWindowClass *class) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + gtk_widget_class_set_template_from_resource (widget_class, "/libfprint_demo/gtk-libfprint-test.ui"); + gtk_widget_class_bind_template_child (widget_class, LibfprintDemoWindow, header_bar); + gtk_widget_class_bind_template_child (widget_class, LibfprintDemoWindow, mode_stack); + gtk_widget_class_bind_template_child (widget_class, LibfprintDemoWindow, capture_button); + gtk_widget_class_bind_template_child (widget_class, LibfprintDemoWindow, capture_image); + gtk_widget_class_bind_template_child (widget_class, LibfprintDemoWindow, spinner); + gtk_widget_class_bind_template_child (widget_class, LibfprintDemoWindow, instructions); + + //FIXME setup dispose +} + +int main (int argc, char **argv) +{ + GtkApplication *app; + + app = GTK_APPLICATION (g_object_new (libfprint_demo_get_type (), + "application-id", "org.freedesktop.libfprint.Demo", + "flags", G_APPLICATION_FLAGS_NONE, + NULL)); + + return g_application_run (G_APPLICATION (app), 0, NULL); +} diff --git a/demo/gtk-libfprint-test.gresource.xml b/demo/gtk-libfprint-test.gresource.xml new file mode 100644 index 00000000..15408374 --- /dev/null +++ b/demo/gtk-libfprint-test.gresource.xml @@ -0,0 +1,6 @@ + + + + gtk-libfprint-test.ui + + diff --git a/demo/gtk-libfprint-test.ui b/demo/gtk-libfprint-test.ui new file mode 100644 index 00000000..0691620d --- /dev/null +++ b/demo/gtk-libfprint-test.ui @@ -0,0 +1,351 @@ + + + + + + + +
+ + Show Minutiae + win.show-minutiae + + + Show Binary + win.show-binary + +
+
+
diff --git a/demo/loop.c b/demo/loop.c new file mode 100644 index 00000000..81dd62ef --- /dev/null +++ b/demo/loop.c @@ -0,0 +1,196 @@ +/* + * fprint D-Bus daemon + * Copyright (C) 2008 Daniel Drake + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include +#include + +#include +#include + +#include "loop.h" + +struct fdsource { + GSource source; + GSList *pollfds; +}; + +static gboolean source_prepare(GSource *source, gint *timeout) +{ + int r; + struct timeval tv; + + r = fp_get_next_timeout(&tv); + if (r == 0) { + *timeout = -1; + return FALSE; + } + + if (!timerisset(&tv)) + return TRUE; + + *timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); + return FALSE; +} + +static gboolean source_check(GSource *source) +{ + struct fdsource *_fdsource = (struct fdsource *) source; + GSList *l; + struct timeval tv; + int r; + + if (!_fdsource->pollfds) + return FALSE; + + for (l = _fdsource->pollfds; l != NULL; l = l->next) { + GPollFD *pollfd = l->data; + + if (pollfd->revents) + return TRUE; + } + + r = fp_get_next_timeout(&tv); + if (r == 1 && !timerisset(&tv)) + return TRUE; + + return FALSE; +} + +static gboolean source_dispatch(GSource *source, GSourceFunc callback, + gpointer data) +{ + struct timeval zerotimeout = { + .tv_sec = 0, + .tv_usec = 0, + }; + + /* FIXME error handling */ + fp_handle_events_timeout(&zerotimeout); + + /* FIXME whats the return value used for? */ + return TRUE; +} + +static void source_finalize(GSource *source) +{ + struct fdsource *_fdsource = (struct fdsource *) source; + GSList *l; + + if (!_fdsource->pollfds) + return; + + for (l = _fdsource->pollfds; l != NULL; l = l->next) { + GPollFD *pollfd = l->data; + + g_source_remove_poll((GSource *) _fdsource, pollfd); + g_slice_free(GPollFD, pollfd); + _fdsource->pollfds = g_slist_delete_link(_fdsource->pollfds, l); + } + + g_slist_free(_fdsource->pollfds); +} + +static GSourceFuncs sourcefuncs = { + .prepare = source_prepare, + .check = source_check, + .dispatch = source_dispatch, + .finalize = source_finalize, +}; + +static struct fdsource *fdsource = NULL; + +static void pollfd_add(int fd, short events) +{ + GPollFD *pollfd; + + pollfd = g_slice_new(GPollFD); + pollfd->fd = fd; + pollfd->events = 0; + pollfd->revents = 0; + if (events & POLLIN) + pollfd->events |= G_IO_IN; + if (events & POLLOUT) + pollfd->events |= G_IO_OUT; + + fdsource->pollfds = g_slist_prepend(fdsource->pollfds, pollfd); + g_source_add_poll((GSource *) fdsource, pollfd); +} + +static void pollfd_added_cb(int fd, short events) +{ + g_debug("now monitoring fd %d", fd); + pollfd_add(fd, events); +} + +static void pollfd_removed_cb(int fd) +{ + GSList *l; + + g_debug("no longer monitoring fd %d", fd); + + if (!fdsource->pollfds) { + g_debug("cannot remove from list as list is empty?"); + return; + } + + for (l = fdsource->pollfds; l != NULL; l = l->next) { + GPollFD *pollfd = l->data; + + if (pollfd->fd != fd) + continue; + + g_source_remove_poll((GSource *) fdsource, pollfd); + g_slice_free(GPollFD, pollfd); + fdsource->pollfds = g_slist_delete_link(fdsource->pollfds, l); + return; + } + + g_error("couldn't find fd %d in list\n", fd); +} + +int setup_pollfds(void) +{ + ssize_t numfds; + size_t i; + struct fp_pollfd *fpfds; + GSource *gsource; + + gsource = g_source_new(&sourcefuncs, sizeof(struct fdsource)); + fdsource = (struct fdsource *) gsource; + fdsource->pollfds = NULL; + + numfds = fp_get_pollfds(&fpfds); + if (numfds < 0) { + if (fpfds) + free(fpfds); + return (int) numfds; + } else if (numfds > 0) { + for (i = 0; i < numfds; i++) { + struct fp_pollfd *fpfd = &fpfds[i]; + pollfd_add(fpfd->fd, fpfd->events); + } + } + + free(fpfds); + fp_set_pollfd_notifiers(pollfd_added_cb, pollfd_removed_cb); + g_source_attach(gsource, NULL); + return 0; +} diff --git a/demo/loop.h b/demo/loop.h new file mode 100644 index 00000000..0266bfbd --- /dev/null +++ b/demo/loop.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2008 Daniel Drake + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef POLL_H + +#define POLL_H + +int setup_pollfds(void); + +#endif + diff --git a/demo/meson.build b/demo/meson.build new file mode 100644 index 00000000..4b6278a7 --- /dev/null +++ b/demo/meson.build @@ -0,0 +1,17 @@ +gtk_test_resources = gnome.compile_resources('gtk-test-resources', 'gtk-libfprint-test.gresource.xml', + source_dir : '.', + c_name : 'gtk_test') + +prefix = get_option('prefix') +bindir = join_paths(prefix, get_option('bindir')) + +executable('gtk-libfprint-test', + [ 'gtk-libfprint-test.c', 'loop.c', 'loop.h', gtk_test_resources ], + dependencies: [ libfprint_dep, gtk_dep ], + include_directories: [ + root_inc, + ], + c_args: [ common_cflags, + '-DPACKAGE_VERSION="' + meson.project_version() + '"' ], + install: true, + install_dir: bindir) diff --git a/meson.build b/meson.build index 87d7adfa..56291198 100644 --- a/meson.build +++ b/meson.build @@ -111,6 +111,15 @@ if get_option('x11-examples') endif endif +if get_option('gtk-examples') + gnome = import('gnome') + + gtk_dep = dependency('gtk+-3.0', required: false) + if not gtk_dep.found() + error('GTK+ 3.x is required for GTK+ examples') + endif +endif + libfprint_conf.set('API_EXPORTED', '__attribute__((visibility("default")))') configure_file(output: 'config.h', configuration: libfprint_conf) @@ -120,6 +129,9 @@ if get_option('doc') gnome = import('gnome') subdir('doc') endif +if get_option('gtk-examples') + subdir('demo') +endif pkgconfig = import('pkgconfig') pkgconfig.generate( diff --git a/meson_options.txt b/meson_options.txt index f847bff0..3e63304b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -14,6 +14,10 @@ option('x11-examples', description: 'Whether to build X11 example applications', type: 'boolean', value: true) +option('gtk-examples', + description: 'Whether to build GTK+ example applications', + type: 'boolean', + value: true) option('doc', description: 'Whether to build the API documentation', type: 'boolean', From 702932c69b93ff5a75356482cc260fdf8c5cc893 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 19 Nov 2018 13:36:22 +0100 Subject: [PATCH 165/225] demo: Add Flatpak manifest for the demo application --- demo/meson.build | 13 +++++ ...org.freedesktop.libfprint.Demo.appdata.xml | 28 ++++++++++ demo/org.freedesktop.libfprint.Demo.desktop | 10 ++++ demo/org.freedesktop.libfprint.Demo.json | 51 ++++++++++++++++++ demo/org.freedesktop.libfprint.Demo.png | Bin 0 -> 25039 bytes 5 files changed, 102 insertions(+) create mode 100644 demo/org.freedesktop.libfprint.Demo.appdata.xml create mode 100644 demo/org.freedesktop.libfprint.Demo.desktop create mode 100644 demo/org.freedesktop.libfprint.Demo.json create mode 100644 demo/org.freedesktop.libfprint.Demo.png diff --git a/demo/meson.build b/demo/meson.build index 4b6278a7..1f0b537d 100644 --- a/demo/meson.build +++ b/demo/meson.build @@ -4,6 +4,7 @@ gtk_test_resources = gnome.compile_resources('gtk-test-resources', 'gtk-libfprin prefix = get_option('prefix') bindir = join_paths(prefix, get_option('bindir')) +datadir = join_paths(prefix, get_option('datadir')) executable('gtk-libfprint-test', [ 'gtk-libfprint-test.c', 'loop.c', 'loop.h', gtk_test_resources ], @@ -15,3 +16,15 @@ executable('gtk-libfprint-test', '-DPACKAGE_VERSION="' + meson.project_version() + '"' ], install: true, install_dir: bindir) + +appdata = 'org.freedesktop.libfprint.Demo.appdata.xml' +install_data(appdata, + install_dir: join_paths(datadir, 'metainfo')) + +desktop = 'org.freedesktop.libfprint.Demo.desktop' +install_data(desktop, + install_dir: join_paths(datadir, 'applications')) + +icon = 'org.freedesktop.libfprint.Demo.png' +install_data(icon, + install_dir: join_paths(datadir, 'icons')) diff --git a/demo/org.freedesktop.libfprint.Demo.appdata.xml b/demo/org.freedesktop.libfprint.Demo.appdata.xml new file mode 100644 index 00000000..4cf57678 --- /dev/null +++ b/demo/org.freedesktop.libfprint.Demo.appdata.xml @@ -0,0 +1,28 @@ + + + org.freedesktop.libfprint.Demo.desktop + Fingerprint Reader Demo + Test fingerprint readers + CC0-1.0 + LGPL-2.1+ + +

+ Fingerprint Reader Demo is a test application for the libfprint + fingerprint reader library. Its purpose is to test drivers, new and old, + in a sandbox, to make sure that the drivers and associated functions + work correctly. +

+

+ Fingerprint Reader Demo does not modify the system, or replace integration + in desktop environments. +

+
+ https://fprint.freedesktop.org + + https://git.gnome.org/browse/totem/plain/data/appdata/ss-main.png + https://git.gnome.org/browse/totem/plain/data/appdata/ss-music-playlist.png + + hadess@hadess.net + + libfprint +
diff --git a/demo/org.freedesktop.libfprint.Demo.desktop b/demo/org.freedesktop.libfprint.Demo.desktop new file mode 100644 index 00000000..3368b6e3 --- /dev/null +++ b/demo/org.freedesktop.libfprint.Demo.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Fingerprint Reader Demo +Comment=Test fingerprint readers +Keywords=finger;print;fingerprint;fprint;demo;driver;reader; +Exec=gtk-libfprint-test +Icon=org.freedesktop.libfprint.Demo +Terminal=false +Type=Application +Categories=GTK;GNOME;Development;System; +StartupNotify=true diff --git a/demo/org.freedesktop.libfprint.Demo.json b/demo/org.freedesktop.libfprint.Demo.json new file mode 100644 index 00000000..cbb4046f --- /dev/null +++ b/demo/org.freedesktop.libfprint.Demo.json @@ -0,0 +1,51 @@ +{ + "app-id": "org.freedesktop.libfprint.Demo", + "runtime": "org.gnome.Platform", + "runtime-version": "master", + "sdk": "org.gnome.Sdk", + "command": "gtk-libfprint-test", + "finish-args": [ + /* X11 + XShm access */ + "--share=ipc", "--socket=x11", + /* Wayland access */ + "--socket=wayland", + /* OpenGL access */ + "--device=dri", + /* USB access */ + "--device=all" + ], + "cleanup": [ "/include", "/lib/pkgconfig/" ], + "modules": [ + { + "name": "libusb", + "config-opts": [ "--disable-static", "--disable-udev" ], + "cleanup": [ + "/lib/*.la", + "/lib/pkgconfig", + "/include" + ], + "sources": [ + { + "type": "archive", + "url": "https://github.com/libusb/libusb/archive/v1.0.22.tar.gz", + "sha256": "3500f7b182750cd9ccf9be8b1df998f83df56a39ab264976bdb3307773e16f48" + } + ], + "post-install": [ + "install -Dm644 COPYING /app/share/licenses/libusb/COPYING" + ] + }, + { + "name": "libfprint", + "buildsystem": "meson", + "config-opts": [ "-Dudev_rules=false", "-Dx11-examples=false", "-Dgtk-examples=true" ], + "sources": [ + { + "type": "git", + "url": "https://gitlab.freedesktop.org/libfprint/libfprint.git", + "branch": "wip/hadess/gtk-example" + } + ] + } + ] +} diff --git a/demo/org.freedesktop.libfprint.Demo.png b/demo/org.freedesktop.libfprint.Demo.png new file mode 100644 index 0000000000000000000000000000000000000000..b27672a9580abb48bad25e435c70737430a44922 GIT binary patch literal 25039 zcmcF~Raab1*KOmCH_*5>uEE_QKyU~WAUFhfcWB%m+}$O(ySo!0xP;&YcZZMn;{1ej zQG4&Puc}7Pwbq<-RYj;MeL+VdLID5(=&~}Bsvqyc{|zAG$FsL2#u@+syLhQ;w+>GI#Mp4@ zc9Y>WEq_&2q^r7_dwp5AY#7Y2KYN+y(Elw4j;tL?#t3Uew_vpps z(~Ra%;O0PRqL((}$JyrO$O zwdddW*SLNGnGaFJcmfu=9GEN)Qttx6I!}Z;d-DhV&&-RUo{X%gM-c$c_WH1~n7d+K zvGLF1W#==7uOs6AcuX_JW~Fdr%(-B)E{5XStaw*Dk@@+9u9d5$c@@;?+Bt%Re8+t4 zCZdNUS7^TJkQG~l*+!_MPF3S-Wz%9NpVjT0b<3vLdErdAG@UY{-gD zLm2;lmbK&DP(FUHey7Q&8U4<7&+D^+(i(Ihw~gktGw+kOrLj_y;rGV*0YdW}*LeiF z7X6OXJHfNg#n@_J_uC~s`JSV7(ev+5XBh(DM9+^!-J?sr-;Y4D zF2?@|Nhi2xFRL*Chm|=)@m5p+vb^xj&FGoun|@eL%l;!Et>iWJKKgR*ceXBisv{=% zmfXE3daSE*{KhMQ|GWKs`nB8M|5sCkNTjL=`W(2tq)sS2ns>eKN^7pD=auuN1L;B3 zC9m6?(HpKrH9(xd*QNTpvy(3xU;4W(Y=LL&y|FNh){8AhMiA zv;91VTtX&R>Fq^)fV42#R+_J9wk~_CN7b_q*39Sxkp?3PG>IaEQt3`m`-Bf zU%^e!`;ZjmOa^F@9H(#LL2&Y5rn)%gbIhKn(%l-=Mm|S+dBGJB=$|HqrNd6U(p8tO z<7@lqo!_`fxOrRW%$tea-nlDZ_uHR!t!3a#emA&f@xH8@EUNjzd2mNIKWMG)z%FVe z9GYi~bOZWzJo2x@kFG(JcZ*y-uFndOS3~RBP9vD-cVamW@e!JE@6*`1)|0!xAL*zC z{);&7&Pmm`KbO@Tnz{;Sd>u(@FD^_Ko;oR0n#Hrj-rLhnJxv2eYmYciwQE@DS70A9t+6LCs6))5K#X2vM8s9JVAg^t^3uqw%ycOpyV{ zVl-omJue=G!}aK9@-Sw`dNPXqTlWF;Vdat^jDkLoy6n@MQh-#zrvj3hA>mUpJJ?T` z|Lrdq^r_-%&>>6Y6v)ACe(j)yPS?6mX^gtVD8Db~M%w&NmalZMXK6?<>H%cdP&0??r@tv~=lT5cF?AXYo^ zgG|G|qIWu+`8sTN8(rJiUc1;nCTm{)r_rJ3-TG%e0ToeZJ6Iqs^Vf!X81h}0xH?DS zT@R%*OvKOJlq0$=dx#o*5wgiwO@27DBg1-PuFn{UyMnm zP01K|wE?hf-@{YBf$%diMOv2NSAKgSlRbB>T0GZc7>=0)CSardR0Cai)8qYd8Q)F5=$(Mc@?pe_n4e>g6Rz~p>alnR1EsJP8h zJVd}bmebi$n8kPGHib;gsp2&|>2`1mW68kiJl+ z`Bf-v#>11sY?-_01edLY_6a59H2DzTR?LS$^gV)A!u*D0sFQ<9HVQ%KF16KewMF>f z`3faW$jHSt$W%2$$4y1xO&|+H$l4EEq(5AE*VnOwNcmg0+=~znP+kf1qJugpeEQM| z6B_6Gh})I2cfqTxu}25U;g$VZD&ea!I9KKhr%=tq6uMvv3B`1k=&yJah5=deVL18t zBh8gi1?AX<4T_(Y9wUNehFBv4ORy9WW_@mmbh;ysa}i94l@zbyS9^Q$(RAH8>07py zaHzP{E!Che6Zgs(36dPbQirKS+*c#3O*TK&xPYWiIJ>Il>EEWY-vxe(_76{@g^kLv z-vx-(%|X#;BXnm%3|H~@#9EefSw#wH4PLI7{IOLLc`CkYu#hZ62f+0=Hshc3`n4EK zFz^G^x2mr8vvy;`Bn)3_6N`+162|> zcI?OkeL6;QYEO!Kk%2`8m$>Jrum8~KD>*5S_rC<{-raFQnu!9@!x&X(R#1OcEX9tq5HT0WbYR_fx`l_hAh zSOxhqi~$LCJPk9>k5hdN3MZB_9+nTX2oyj0e5{r498BGA__fl4oVIBC_rl_1lWzzy zJ#xR2IV1ItqFpHwhjbxI)ZgL*Fw~PCjv5V76CPcGE<&Uerid0N)c)J#c&c5soKXbU znrd-rGP*l4VcN)ijIeHr-%Y5n0{Q7h3bkq1GjK(9w<(l0!ZQ-h8;hlYe=05Kluoj1 z@>rm6|I&>LO&+)*zkXtU>UOlTAn>Q0GAUPrqm?1+JOpvDy2X#SG8p>AxpvOYeh03MX(w2T#`jJ z!Qx_g+XwJ)O2m9Ax>@0b5ifr<#w4bq)hu)gX3P&FbhD#G7zS{LQ#|NKV68^({Vg{< zZQJv7iB4b`#~G$n$@+{yXlV{Ir+6E!tcWG?O=KM-U8Y{y^^D6^;EkW^|H3~{sg@pc zNe|*`q`{xVTP8%3r(ws6xRJJ_*Mez8%c*e9mu#{&5dW&+w=vqr6v}h5kFuN3ME9++ z{4|cqJ+$~gf_AT0AR5CMJv-)8-u{AeF$006)L5QHaMjl8FG*>l%s%>Zv)5N@xLz&; zm)fZ4f6(PG2Z43I1El=JvZkkxoUUokm4SC!w8i;T=|wROnuLyO@T#NX4iko0ImrJm zuoI{-ysqjW;lbd6D9w_xTIFDbLLQj<*r!#4KN7$m-~J|CR~5E@G{O(`q)-Z-?Up?3 z1fFKx)q#zJ7r9_r$V#4!wA(|831TjMEpM?u-@u-t0o|;_=ZdSL5%)J%7(_D!TM*Ku zqePJYx!j!dNJji~-Ha!@lj&c&mIu zJI7Qti9GyzqPlAytJs1mJ}-)Q>K)9!Ss4tCU9~dW*Jb`0w~A2W_$0QwXx$FO!ptQ%^ECFwzgC<;zR<#Sg>TM_L-;NUgt)J!M z3AxJeDL69QvBW`kas!>&Hgbx1KVuXKRg6;bQ$a5&J`Ca+;X*kr!038jv0F9a4;n7x5Qt0)T7y?@;W&6gt-)v-ATKVVf( z|CZ5^L}^uYeK$Go$Es&&7yI!GLzDnzMcC7h`Hce2uUU%<7F}6cXIXJ_aHG{P4KoPN z&62FOXnb|t)+7&?Ko*Uu3BV0SnCCF>#oD5JK&#KXAkDt$P@_O*&mdN8h*)BoGWpiO zgL1vM44Al+wmk^H#vYf5AP^oAii>7kL1HM_xv{(bT;7?i9Z?M0YrV1A^(dL^RKe;e zwg|u^CSz5pL8TJ5z2x^(=52R~h`!L6T}sNY=K@6VM6tbO#cbQQOPm!EBi&N7Z{`V$ z2}9&FdHW2-dWgsg8_3%H_2c@t5(+>sf zI;b|!`F13822X^3kCHR1Wl{^riiJ1^%BpuuU8es{{YYLVsh8^QR}}%riYScPQ<&nw z#wmt5uv_UShtE?R{~8})39>pVwtMOGxs$<8<+1esPo_YprQOn1x>tu+9m89N<&peF zqS)cPcv@K&4%xN2hYd|hgtSD$r{XE77_{to%Yrn(1%C4vz6a(F+v3%p!iZ!(m1SI9 zXVNr?fy%%t)zxVXE}{R=ldZ7RVEQ{PA;a?yd+PysDj}#~`U=Yf=L^_2 zGJz(XC{a8IlX&5J;1MzRvTTsRjdEO}3@#haqtZ*SvF6%n^^%@O31Nv%=1iC3l1SRw zmY;%p^*VKFB##&sk}_oMNR5`v!#XB``Lhdw3;Q=~0&oLEH=GvAm}g2;06Ta)dXedt zhcO|wc9)k1q_^;=jbXRN<|8bKOHM940=|L4(DMNWmhG=hYp^>F zg)>Q8XReqS4SF$Wcl_$IqdfudFIo|1iGgB z%@WP1og_8N(55anE)wo!i(PWe?F!+$4OU#i`)aq@1D$>E3UdJ^)xW4CZ)zeTdYsFP zk`&DpOITJD{tj^=t79$!&2c8*BWV3i82|*XN+2e0QJSr(PEpSh&8w$3Qh~3t$i^+qqCs1j_2dYtzaxUU8s0wDq8ZY)w{R$ z@NiN-Y;)aeRM}%At{e_%G`$(k`%3i5z4r1yMfUQ|=;nfu?j~HPPAjS4^~jpmmWO1X>-$SPp5bFkm1&Zhy;b&J(pP!#Y69pXwwGDFlgO6X@zQ zMK+NWhbC(O>*0NwduXkd2U+p%gsGx=v+ePfxz?Ojvlfk#Gonav9;y{gCJwFq;x;nA z$ZxM|Yee6^PkNz{#f;eMM*|0E4G9660%(i~FtbeIo&--I8-0OkZdn`uM=4Uq(w0AhzUyuk6@0Fqt8xq+; zM%x(xK*jmrfB|G=5q$haa*PeTUE{^+~=vx*w zwHRe;MjliGJVaGC6lB4~_)`<}SG91Soo&b5nO%p@iJzNg%f{-W-OA~=)uxT+W!qDV zrc@e@ie_;v%nJbbB_I|)j_EH-9LQ;M@;o*j`7@e@ZAZr+gKIA#iP6d3jLw|%gX2f9 zuFZ28SiD*&0<$3us#fp+w@*ZX+IK0C5MYZ5aO3~5h`i+sAPmT*FnqU_H_48FBX3Iw z2q78TY?UG}`_GXXX2-sfcXyEkqUs4-f9 z~-TKA%W8%h~(nH5_ZebYn z_RV5qY$K=}O}-~sGE z!qt7czKau3H%FLkH>I`c9)~BbQ6M7*Q|{A(IC?=SEAJ~K>r)O2F`*MEzjHM6tE3RT zW3dZI4yk9l8nh)rAZ&Pezs-5YSqC++OalCo6P#U3DmNuD>v+WHKR?#~u~_Q*#vH#+ zD+4@)w>DwK9#*+{Bs1Q+0w5TOl1s3#m>^251_SC~8G5leF(?QI<{tmNT*x&wsXtCd zrwRU80&cQc>&H$Q+ZGBBuMRx07p&3ntOUF@D8CX6&*(`t9QMYy!% zt^P@X&;%8V1jj-KfG0;QCTMQ~0wAQgns&d@9pH~26>0VD<2hctI%I7DUr4T1&1 z4gdi`%wR}31VRA}MnwQ(0U@}cIFQ)<*$j4u%j#seTa+C8=PvHsu~fNWc=oL?4)a{P zT+wz3(iLIBE2rWu^9c1V__gB%;PkQy+MWk0s~eJ6mawF=jc4Qm;CD<|VD2z7fk^)=&w|Jx_sGUF z2|?`gomK22>c=;pH{Yo+LJqB`nHxtpCRFI{$=xwZB8YOqWcLt-p6;04IzD0+1vVFC z3F?A?V9jI4FW>&~22h#`C9S~!9YCiTFS;6yU^H2(Q*D~k$`()D)xaPoA^RDdBc$g( zFN~>4k4?LZ01pEL<8Tk3hW1Gcjw~ZItl)2vj7zJmu2cKh1Bd?2ji6tl6LS|`I=Pl2 zHOk!>DwDw0mvaQ$=-l()ZUn0TyTdsr)|!WyZ2B-Ygbrms&7XrnTSC*CC)w(RHz zA3?}|a(n{!W=@V1==TbuHnvl2QvI8n$-P_LK{~w{^XfobemLCj(xzXFuza^HfGAKN;NSeB2zxj08)=u)))<7M{ zf7+%>W2~wvTHz#~{Ru!lU;OoY@qs2QzUh7>FJSKzBoVJdmol4#4?I%YW#k@Y3C#x^ zGC=S+r&(?sy_A@7PDBD*1-gisVSum_0RYu}fN>zyccS9w87CcA4o1}KpXUkbp`#yE zh0ze;4cFq&6I-(;R<@F&KVNHaB6`$;TKS(KfIx`YJlFi7BpkKkfb3TX4|*>Cjn+e# zz8}uL8=IlC-Xh~123^*>2q~EtGcu6hklmQfcLp@><5Lh5gMbT| zWd56GPehB4v1_RKsidg(+pyFGMzHKR{Q7&(49L=^bLRFB$;AMHk93*oieXeN1kF76 z9lm-t6pNBHv~0zan0RE0UL1&oNRcS9NAkMd4ZqxBdT5h8V5Z>_!sS!1008m#qdi)n z_7~dZ%ljE&|k1lZ-u_W?scOS-95qhTQ^#vZPt~%|$ zq!dCe3U5cBfL`Q(+@IMc*A<;zHA`6O#U69ixt1zsH{wwu|IIuA;dz2(qQjGj zA+hX~>SiNz%y2jo$R2;ebhXH0l!!$Csb=xzfmghXT%5BL&TQ0Fn^|b+DiMq$`1u5y zg^YC*j8v8ML)7V^po>Lv0c%z(8FDNZ5Q=T&Aj7H-xwjk>AmGY2Q*EQmZROvKd!xQE zj2Jzr)>506Mt+V<7mSW1o4;{1%pZnh-hO&$Z5z~iNIs)ge)|ua^Y8~2KK1qIUh%8X zKw%%Wmwm!oM9d=^VdSZAlS={1yMHkmB?AdoHXN&P_#c~JIoZ!B#aE1(BLpQw z9KSbn7;z9}c@YguT#OMc1`zWYqCcIp)ofGXW;B-%$}r9r@o4Q7vU=IQV(9UxHTL+} zB5H`kMRMtU=Isclp2*)MG5W@6Wj&SFt91V)AcDf7RP9p$CeR~2Pl6Cp%hbzV`^31|;myZhydJU^IAU}`?}I7>-u2(m?v_3DX{}yeOSO=8 zMS~{8zgn^T>hseUYa#MI0>o-#+fEWRwVsiJgCP(+&?d@<;h-IcoK}$OI%AG}TFRKv z!K!J^M@m7ATT0AHr^xGkYmW{a*gF>cUfizU%saq)Oq~FqX>Pi%6Zdw3vuR8&4v;A5 zDVPfRN-Y&sly;K1@i~9$NTRq46TeEB!1JGq#C>Y!wReYrX~3_e|3T;E)$*oAcd7oq z<}%9zRdC$>(Nlz+Yv{!BM9J4)}DddN`3D z**HKO@)$YCRE-Q1$F~4z9%oicGsH+wHj4+s18ITwI%H z8W)%Bc(8GVHoIkp+Z|l&v2;wPMU7y+vfoXizo|R-0_HEme5|ied$GcLY_4xrDR2Fx znJKs+{S*iT(Fa9JEHH9TwD{+o-@h+rqC;nV?~^p^W2iX|@-l{j{j?*B3~3E*SGZyA z*O)llY0(n;tM+BfrQhpj=10YCVg%6y?2p4Ujk>{bh6WVJ3DVGj5MFXc0N}Z~Ld9P^ zgab1b`z@i37|>bhxoq;g}FwitY!4JD$=+rQlTPoX&J zXZo256FgJzt~uYTvn+T?8RB!9H_PjEg)+r28Q1F)OKkO?pTeYkQnvnq0b*bO%lROb zB-9~x_z@ErbTPL#1r=?CR3el9ZKrdOedQ}n0Bl%?2S=E`5Ox4)Yyu+OM?7V{@~(`D zMdoOqI%gG*@y3b~*T=`jQN|s-VOto;MQo=p#sZ^*9wr-Gw zh*XE{gJ*(T9$12O`TJOYXiLffo<6|CarP&9VQC>94KT2S6UE&&gU>Lm*yx_YA|t=) z!(SMJ^dCgF)>CQU7eU_dHdveF4Z*r!7ck;0A=Sf+eyJgcZ|DBBYYmCcymBBx&71qIZe{3vXzv z(SMpUC%j1U91$2cF+nw=%#!P~lo44LjO@lv44eIOXizTy>~41J>PqWuxh(aOWn+kV zXE*KI>0j@rddwPi50Qp1(%9Rd->$6w9$w121>&d7ZvKjx#o4gK-WS1-SthY)Y&67sjQA)KbIk9pzpg_gBTpa_A<*wr`coIxxc zJh__#`QVF@39OvIRCC!O8{;jIIzpp(MEc=FcDF#RmUXi$6f2g_?RLF3Kiaxcrb;P* zL@=zqmZV0?*cj(XvhOev?uwlfEfT}H>|P<$FsuGoq1)+a1zp;s-H~_I>^~jCBc?43 z2p=U-_g`TDf1*9Alz?Am?U0SyGzlmyx%VromX4a9AGZ?G}RE-GDxFT>Oj1eukTSW?Q4& zkp-sBgMfT+kOCYoiWE@J;L*_Fgb$UP0@|b(xuN51XgmKfBM>n~z^NZ~$tb+f!j3-5 z<_Xga2b=nDmrJHL&DjP3Rp=eOfrqN(11NOmk;I|xPO_^n3t>NFm{Jp;zh|oX3K|3r zP~Be1&by$#pPSN7F@g;5ony_p2$g<(rDjN!F&%Ex<|j6<(Y3_}iDg~}-W>Z2Wt#Hn zkHSO$)|t2}`_(q|8Za)(eywejb!lJco7;ibHIbUQ`^Rat*dG`&e?>Et`T(V!Wo6-2 zU$48dzv0%oKe`ypQ^hg?JescfwEc!Sm}bc{rG`aJhW_Fe>AWCdgF3q2;npDxdx$ zU%F|+w1EXj((Es1?%OTw?xg~Ou;1pTj#~Wv8N((7q7~9qeAW_K!O>(hjgd)#<;)~5h1vsqQ*$)7D4 z|JLgGGn)&6rXVt);mZA9DEqZm2rbma2-D*?>>e=WVU|z^fJVO%!($Ch_2HBdePQle z1Aho&9I zq83iwx1S_<{z=CF;eHcYn&!N_gyZB-_N9NWPlpjSC67>yPnJm74zrR46T{`cpsoph zHrM|9n$z|#LrZJ_zqSC-Qo6?Wwoer%!ArLK^q6wpeW`YpBg$*T4k8?!=pYdR%UJ)- zkJ{hR=KYER=UDf|2Fd(9gJkXtr*!(A!rN?YTAtl8^@|Z^W+%2EzGK$G?2) z8KE{RO@W1m12{Lpy_cHrS({GvLYbKVZC%K`{@1Yxo*td#ab47pJDZ-FsH?Z3P)<{M zsb~?|m<$MHTE(iw%eTlF6R1Onc9EfM*zsC<>CxLCOAbEDwO#KlZJsx|A`RZg0>jZ3 zW$`hvuh0+?SsJ%d?OELRYO)8B25$Op;D70h`0y^6>791}J0SsXJfpe@4(ziqE*%D3`3Vi16* z8Y4N4a1b)XBwHqesCba9KAjS%H4At79nc*k@}r8bxn}#7g>JFl8k=S}9}^MMU!*~; zSsJdgHdBpSf7w{zAQ8v=Ek(&}*TISdkh;J1Ik;Frg1;nx6rq?9CdQBGc`g4HX@YOZ zje$YZXIz6vv25E-NVm2*gQGh#@%yYqfP0S)fe9n(cdT}6r-jp8A{C`Z|F{OqmPFM2B%H{l?%NeJ7T*c{C29b^Y~LA$(REyz8=qt6 zLS)>k)lZM(;hD-RGk^0Uu;~0-2{~-ILvH*UZ`cRL>o(j9(_D8(G{O3_gXC;MTEB#Q zqgjH`D-}f2KI1%VEl-xDC{1UPuU{Et6%#_*?#m(XV|F3i13P)r1|d(`TA*o-lL3e^ zg7OZues)^V9AtDq$rFv!4Pr;qm<^%bF19Imt5X^_e1nJnBVEHrGw@9t&}bM^O?RC3 zO|@H4mrvg?HVyir}(u zg0)4jTInsqT3wV_?1K2jhatt;_|KiONTI{bnAkgWJAz2vG53L-iHi?~oxfOA9z=}V zEX!?;Slgm{imVZl-S6MG$)0Q@xRSWO6Q*|_m|Og03tpyK6Ak?)vtx}s>{SS<*@q^J z8O4(R?*oNN>BDi_mMM@F8VRjoAS`GSmQg`0&uC4sJjO{cbVB*b^`%||VgCF*nj#z_ zBo1{^@6J94-~$F-f0MsNSojeo`>PJT221_5;RFArQ}niF8>F!d z-mk_E4+_YG^m^#WB(Ua$G$sMokI96piQg-g~9ZSiqvLpgJML z7AC_s74Bkd(aGm?rp~uL7X3p|gnDQGlgbVZ(xqAD9lRU?bpO}ykI^!Pul`r4_YonO zUatC@d4dH>4G)rs)|37$s~+zvhtQ#Ln5-vNX{D=eqkG=rSE%R}i-$>Z?zW&|XJV0= zidm!)A}6AuF+EH-AsPzQ1a^H1AgjQ}cwUg7k{p{D8jsi;IMda`;^CQPxlzky(>%FH z{V%+3C+a}t&1UujzJy&x2DBW1U%@ONO+gHxl#ZQ!t-q)U#F$4oI`Fi<=C2dB-us7+ zO7_$hU~Im~&p^~w8B=!Ry6x0~Tgzp%Ea<<&Ei;hYV`BsW1p$xL{3IKDxERe}_JvrA zM?y53PMTRn4Lt(y-^C0_6SWR={7dl?K!)#kE(9}G9dcBXu?xnx?UbxkNq7|w?LHO( zq|`hnlklI+J~57PHJOT;SwdU)Es^bH<)P{NUWQ>P_-G#ne9;rj4_YGja^u}{16xua z?*N+M1r%``3k1M^JYZ`%cm&RgSY)76bx|KrVqny|C?UhhiV#B zO~0&8MZJaxbbBz;{Tbs3x02nDlJ|R0Md4k$IDiNrUaIgNJN(rR!#%Y5GU!dL->lD0 zgA{xl4Y$pI!^-QqiV61s8$vEog``%yGvjd`tV zMWJ32W~Kp?V8+HUk5i0H|ITAB1NmU*X^zfVcz;X?R9d#O-Y41liT*=renMDpUfr6K zgn?39Kml~{u)ny_w+jQ+vnqc7BCUdJlu&W0WHJ6K?YMr`p(qikji%i{0b208YW^p8 z#H(F>rgUyj#>1$TdKZ?8@`YNV78MBV`hi`fKR!p=sT(D`VlV&$k>tb~Zs6w2*75ueQui)$=m5qabLTgM5Yr5Us?i_1=wV%kqW8(LIgSr@BFAySu0`G-2n8c&?A6JiA z{21KY7CyhW)1M8#k_id(<6gYrIvkYCs4q>MjmIMh+7=w9m}9_(dDPkmyU*{Vtgsm8 zO1)!2L|SWzHO8pHJi$^#A7+W+S%TA~w#AWXL-4&mBN$rFoG94Rld70bjKr7AC-4p5 z`+l`*;DEUi9!G%{Y~BY8JEA{6Wg)1OJhVXlp?N)}7YkXHx~@fV!~u(|@^cBAIparm z?FCr!ro+js`1@EwD&fT(JFCia%`afGkkyp%wPQZ(D`M;();_ zqs+3OK@jDnvFGNGg=QdGAy{rFRb66M&tt?YHzGYk`@gx%dY#z&Pr6=ks1}w?vFN^} zE;Yf6i%~;rUn8EE+zhmQJ#KWV}h4f;}BMzI+_J)?}ijg6Q>uu=KYMui-+CyZ12$;9|Cd(4vh4 ztNsEp_zPj$ngiURF)AXn7eagAQ+(W z_9@3yB#Kd4B^pG=2*4#J#e*=)<60zKrfho~X#5 z#Z?YY4|KqLoiBF8`na@m7IUvr{e^LDCk^p9{arJCyinzKTrvZs&7Ye zvcPXgojK&l18aYgSoj&fR8pH&OPc5pE7{&Qy^&>Q;o@_Xf@$*hJ%I;wN$JL)T{ zr38S0aktgsJFzt7Vk6*05rZxGYB65feD!A&5=JB^rQ~^ zvyH`JrdtOPvv8?o=Xd{%JOY*o6muT(YkT`svoEkBp{G(d*?KeNzlW}zW=ID(@!$J- zvwHP<+%G+Hbmn1g1 z*k@$E#tBh^e#(hDW^XvIp0cfxdwr%yRfHXWgggIYagB78WF+-6W>Y(SrLkFyg!~zd zQInH!GLw0RWMu8Y*{kRutXd zu=A~c8cSNk^=!Mze3Wpk_1g{pxftw8q-MTh+OYR>bRuu+4Q>&->_3}cmCrs+oiT6M z^+i1Tou1-`iCi&{-kJq+bMLq1%itgVUJDcYK(?<;?vPQiNLMkq1ovXA8xY$QZ4$3a zmRH@}dig#E%GoRbHW- z1$S+sim3m07T~B-a|`>!k(j*l=4m9EHC3@|;S!A0f1}K@0d@ZUs@?6NeZksWa4orEb56u{_9(P?1Y_9? zAWs$Q8`o1YvWjIGPTmVL>8os=ioW=s`;{gFVF)E>=b&M$4gZzN_uQzZYAZx;ZP`{{ z8=yA@P5=p~{IDf+_&TV}+Xc}4(+V?!9z{Rm8!H-e#GBcP(c$YX(7n=*fq%PF>rNMN zBk5OTuQYGmnuX%hL|0fX9rWSisCYs!6q|aJw9x@D3fc3}%+yp0zXH5$JbW*2FhrJ6 zMm6+F-ZE#7l+mlT9}*eS;%yPi01Sk>yg3Dpo^sp}&Xfk04CPrm-tRg8EX3dVI0Rs8 z|5E+1l462XRDY>vB|%lNKHFet2}Hs8dD7{@65+y+`{5~GOZ8DCQ_+@Jnj92o{x4S$ zGhvGEI|-mSu1BCBKTyXorP<-$+Rk;XFUZ3l)hys%nNVWYQ3&gGd z8%S}XZQ`KbvjTOCKi)7^(JlH2ut#jd1-pCUB-#goWFufWO04J#1Ue%%3u>rVjt9^zOt2S160;&`;cC3Bz1|nn3eW z2`??uDq_Dh?J`%Qp10Gaw)np8+LsqUL`N2$#-_34xG(8;{rCKLk&HSiw^6z4gJiOX zh;UQoWi3mHvADR51S1tr>Gz%elFZ86)TyT84yP|AlWU){^BC=yulJm+-cB{_@IVx# zpH$uV0yKge?cpU#j(=k`eFiV!85*wS8pJDIAXhvDX5t*a*gn68Dtw^jTcs~bf??j@ zdXnev)!l4rFy%azuPF?zQi~Ym$5XP1|8Y8uUJYyjIu;cpC{-&)kc^;=;RV^!nW`bd zK&=XUk%#7FW88YWmYDy0*r27r%Qn^kRPIjm{HMyB9$qVr^&oZwpKt@@0pA*3_W>Tz z&y-rM$a=7Utuy>(QfZBVUEH+uWlZPsgXc+4E3NTSxqpt(63Z(+OSrjs8o3fa*)}hK z_Rr)!YxY(ELto$Td%u4%?{K=)SuLFgcNPDe(lT*yzXf0j8c&m}ar}G`B9UGsBNnmKWvCL zO_7;iqQJz}8C8SDjI39wClTy$BP*mK62@r*O-T+5}vb+XW(FLf zKS=#9WkT*<5n#8jTU3pN+`0L73tb-;=0iRT^+5~`5cXz`wP~@;JR^hwrptN0r5)c> zN0ZO0=eB&+krJj3VfyHou1v^tT%=ABZyh3dd9(Q}A!(n|#lnB*wNp_S9p8Msabc8jH_BLoSgly{B5+hU7~X!%Z?d8{fH{}lqyGx`02GAZ#B z1YS%h3hXU9h9oQPiQut#o^ulzU=oaJFxKCf?Jr?ovC330Wz0z#s%hxq!rxzjM!>5P z<*4Rnasp2({U2i(eHl!($O<6;)MYULCl7i%YrUgSF7{KT7JOJ*orNj-{-=tMg3)1g z-W|9}#-OW&a3U;6ve|)Vt{l#89|6NP#RWJ0-7wH91_NChzw%U8J zpVlAOW~c6kDWUnj6V6|W_VqW4S$2-eXENgE6{N_C%noWS?&t0Fs|HQhvX7d_II1^gQYWpLfPZ(HU$&bL@is>o51JLs!L~?=fXM$P8EVVS7tY zM!S=$Sbsm(!nHus6Gt#g0YZBN@IGdLo2!fnO&mxm!0B~Y@#vcqhbdNSNG{DW*(#&z zB`YfX4{z`!zxKVO+&=;b&rBq0GR)m%m!3A5omb}avFF?0-X(vD*P*>uA2)uvrWN}4 zZ_(xT)M@3#XT)M)h$|Ht-bE%mOGE zV|46l#KId%qKCC^?x_FjE;waX!0vxKLQ?WbB97u<3eK*QZtqKy_)fIYW!jOvU38Qz zDVZebv025PgP6E7uU_iLv+xsPwhpP_n^4&)e>>~Y{6_k^*REiQdP6;>$M8C$&K?EB z!ivDW=aDYR_qv`j{PPB%FEw6@wBc_8d547n*J*u0M3`V6KzRNs*Hdcij5)czNp_ZU zjjsF%4<1)mAzhu}-+CE)IE%j_>L2%nfdguAu z-%&DdmRwva+HM&6v#S12Ey+e#3ZK6J(>pv;^~#+=lHQep1J}6?(rMRONFi6+N^21% z{@N^%USYvaDA9y4&!OKvVcu}L203JS@%mm}NVZq_mh2pMgXO^LpU8Muhy={@$L0;W zyfgkSbRCrMqwcZq{bgFTIQ?>89G88{(53mGSzjd=PEw*()|c+g*y-kU0>Z+9a0@}O zqjVBpO#+j2rtMSV1kz7&@QyiO>60`;pz{g05R$=wNf?q=GoWK*Qs8Ng*+giZW4Q1z z7ss&|Q}Fj==b{E)L0d&H6?O*&81US!@Fi^T+xhg6`+<=MS0OQTwCc%&VIn>nPKoWH zZ_ji81j&MilaKBNTE;O)7pxYx@gT|69}us87<+`kFRnyAN?GWQ%wIQ#UzW0c=_cuX zH~Yi|@!i8`Ghi=lX!2)JNL7RJ^`x~@f@zp1BOa^c{AVO~_0= zl(5$?KmPP=mR?%NGlfI)T}d(5{F3iPT34i^ub5MA-N_p{@bmvQa@Ai^eP4Tq?gnXx zbfmkx973d|8HVl#1*923x+SDrIuwu`T41E58v*Gq3BU7s|AP0fv+lY-+;!Hu=kEQS zefIP0voevvX_IhVavZtXQ+v|MDBC9t?dAoE4XySjJop{{c}#obBe)nP+)DEP(bm1PRq+!U1wEATMdkVM3%uAWZ-#YvtQV)lH-tR5w5Z$=(sKZ?+HJb{j_4p8x>g@U7c+j{{Wb4 z<-yo~x0IY|8p@gRn=kL+A8>c=Oq3we7Hvy$twQTP(-MAUT$Eae@WN8x{@(A|D}3}^ADEQi&|4?Leqb`?(6|;i+KqbVk>`98W38EPCMVGGv5|Mgn!I+reAmykbMrrxp3Vg%Bx(s-R)Vq0 z6Cm2bd#*pMe6%#1i~g2S=hir8)@2ss3N#-b4)@HyTM5hGi_q=j1tk;(kD+vPhTbS< zbY-?a;R7CG&6lQp&-r7?cJ3(*isi_KpP&OcsZTWD8fXlZD)5UhgLr7=uV@(2?uK9T zWfgzkaf4gNQDTIs+x-?Zzr$heQK>e(7llN92cr3&Y{##Db*j)vT+-jQIFrU^!uJX< z%kqK6u8l@K{a|VJRQ38*bB^GkU#;o+qNw)O6qPp?0toR53=&B z*W^`1&EtKynp`g{r#&sov*p|&YzYDPphIcGOtF=)GhG5PXyxGd5enouxF@rpHfLV; z`LinyqzN?aj~GiO5m$KU3mpwVicW?akMM`FH>W|n08s7pY}1Ql;aQ`bQ;gH44$?@k zr#VBBAFxmaamH-D!{VIpms!1L#xo}>lAykF(1gy^WEJ4`FbEYC{O%&|V4CbPqxF7Y zg2ENM2x&n*J2axirHRxIm0 zunty~S@ceu5dB}3aQyNTY6dqr7c%}#mmAXVB|4Uygc7)6l(P`MP|N69oDErs)o9(m z7Wit)UyRbIXHyl|i4v6)mBKdT1mMc8K-x@!c3@1aK#p`?WHB49QbILctUo?j=8Ax< z{4ESMb!V#j8k#TrGCl|6hw)jC(BotDI{q1buJo#k)NAUsJ>TL43<)1~K+G%7=nn=4`hVGFjS*&oYfD`zd70Y)Lw5kVdQ%MFzXV=B4=h2!gffYZ{n$&}B(P58@tCzsf6Hjln)Lu42Oi-paZn}7n6mG z2_o?*6Hd&-8^}lawmu02T+fEPxBvX8{#AkYco4ovIe#WEvYASdDX|n*DS+u%m0=}c zMy0!(snx6)KC8l};I0g!Ft2m|74qboYb5+B%ws6(RUI3`Nv+X-lYt6T%xcj!y_HCzU zey=A@)qS^hnM~okoJ;^FDhGKO)A(0g62!W*a81SEy-zDVm!lsu;CZ!}+up!cMPT01 zgy(AaVo|lU7u-tuJ;@z*M=Q(sM^% z6$$94B`|%<2KabT@B4|g^{uex*?eKxGra94&`aB^K11mC-CW0^4*QAUP2&c+?A6V6 z!N7N5&bQ6iSOm`Z?@gNUhxcho(By8EIgkdKs!A81IzMV#)gV37FzT;_%lsL{b)wcf z>VYg)hhq9EA#c`vNmm#gwMqzPn<;YYkV*>)&L=gcGK3b%{#@fvbjGzmIuP!XlocE% zSRU?dn`!!Ss$VTP2^a_{9}|MF;aJ~(xgxv!LU5-?3V2V}49qBF@ypZfTlhAfU1V{( z2LzK5oj@a^1xMcBj>uTIyoKE}U z5DEL=m<#+~|7BXX(|En`6liwjNRTM9dB{%)z3={pd|wcHxU5iCd+taCA@jW*H$HsO zLXSZM;~Boo2kvmH2~n3)GnyrILD`5-R1rTW-@y|rLi#>Ai~F%|(JC8Y06ey6Ex~f9 zH(rGP(}9c^Ex-Osjo*kPNCICg$dNA3vf6PBQ=k)M`%q+KIh!FVl~#Dfk%T%tEs1T} z8g9+eMIrmCo-;YdyETq4G^Q*zVx)M%mT4xW#mh0^?_=#Xebqf>vM=!xI zp83npe%wrtH6kZQ3d&(_e1qjef$ zIk=dxP#tKe6OfxmG&(bM-5FwLKaRbxp4?0g-hn;nl|_132D3xRAe!7*0E4=~dIeMN zpvX>jS$0sX_R_xK=Gj)=rV~Q-e^t4u)-I^S`gcML03-}{L*agYBslj*<#h(pKY4e; zi%`^sr~>FKstN>r=gDwz0G(&w3&jPY6>S}&w&$lm^(n!4 zTK)5dA1x4sfZ1j}-{p_gly=Y5!|Kw7l>j8N%g_sp@HVD-#QV!P7eJi{l4>3Qn&)E+ z3!msqWK&{PQpr{rXz4jEa!LZ~M#{r_>Q&SOgB^t-&UT6%pHB)49AGw@xa^v1I58;} zYu5oeb!m#EPDALyT)jo@=N$#UCv`>zV9=F5Iivr+2Sg#xAk=b(T9RrlP#FC5s3Swh zZp7!dfOXP5zBbZZmp6>Qmuz_vduK1C+VC5SUNl5e{Cm`=04&$p55J}o&yLecVs)P@ zW~->3k|VRkP#&(o=$o0Cj`B1clOgCKdXBMv+6QdFL~l2JbBE)WAdkRvymgMf0Zw_Z zKJnyRsrmi2(JJPl@tm}<1;C^}17oZ^v+bIuIOViMN(+NE;eE9LWgrc4x^FHuz`t5; zLQfXVye*-XM$j%3M76`I13=_>lT+1L%T2!8&*VX%|~eRibQLZbJL0=h!4Z;aa>I7QLV`BH4llB9FKery=u$ zaKhWOae8%x`yE0ABj%^nz?+#5Emw;v^3#abH(8U?o+V>d;t3~Kwimz5bwZg#Z5DV1 zm{OF(&7PMM0hHrBIqAxz4pxZj3t$V%H-0k4`!p88|0KA3i$<_*Yiq5GZaeiJ&W8y} zaGc`?eVOoSi1p=24dQBvgqt6v(YtSba1|8d!FK|56u4Z*g?)u)G$3gtvvsoPiVu-9 z@Sao{qn4>c9h+wFuJ>UElvU}V2q>bM%ZB0sI;92r6YTU)Y$uq}l?4hi%S7a#?{Z?p0jels&`TU8*8mQC z#ZFjEt{>uxt0XilQdkdtC-=Nu;I}M!FrGu2B<64AMEzq0brIY1VOZUwMUF$x*6h6T z(Mmwlav#(7EPbwCPA;-ug>7E{!h{ZWTTh^7Wh_#Jqd%V4@&N4%Dz+_z>HxRCJ7?0B z7@oP~Mk;>_FS7m*`En#{`<;RVXm&M!@NZFJam5chqipDT($lsa%DT>0&6_%mt>kxN z(T(C#Hd0@IZ`}&TgDdl&=$_k%*wbbP52;`wBxfxw%7Cc+np$j=ynhJIg^yS(=ZDKP zx4CyvDbX3>%K$rZtix9rN=Jk;ZeW1vsAhw)HAEgVqrV$zv`1_^WkW%jWqMo^RrF8f!MlpH zt515%ZIu&rMSERZ7T3(F&-9e*>|lp*OYde!_hUG{6&bfei>`x=QL;GPb-i|*wEiC& zNRx2mkW_YET6~4yx+-+kBIAnTP9)ecr!m;r)~j>TWRm^m`X|Y+sQfhwawKISuO9kq zPFpE&{naIOp1D~!Nz+uwyo~aXrZPMF0{&IWXOWF*MMgt4nPF#f_lW#=-#vmNxQ#`u z)dy=6b>y`Xnt7{+-m_BTK{CRGKs>UCYVEziP}(E8Z^N<(e?Hn<=M#b&y!aai zKNT`63v1mkUqI3!L+DzJAT`%l6r6Ggj*Sh6L6K~ZRZXOlV_~GlG4k31X;ix)ZJSWb zII0)dvgqpJ6jedR5v=_mp(X-j1|0m*x2PpV-aI)%t2ut_@QgmQ4nj)iIAk)u-RPh# zc|86TeLH#cfZGTv-4kK5gGETjPT9Mq1ADKH6?7NH{4osq=SX$1>xd(c-saUMHFqC0 z-v-vI5LNr`_0Z(w0sVEJQ*H_-takTVeLfCJdC)pPeo)AkmmKG{>OGV&#+7p^U2VAD z?Slk_c=}i_1p&9lB4KPnTMI}_u=W8;xnf?sj3ZJ$#DYlXC#>EUJD1~Sw`WfJ-`ld& zZ%%!UjN!7DF%3iI7*GjZ7E5@~efEbI8<>0pb6d z2;@5vV+NXKG+|-irG4$FoO&n4$goN0iK2f<1m{;SUjb(8J_>+418n`E4gd~fmh*1l zA`NC>((ES``1y@G(jki#)z;5|Fji2MW~Ty69(zG_TT5RX7OnNHlBJ4&Dj(` z6)i92d!K{Q!&=Xj|1?w<2J$krEW0A=KYCs+rf5H$ct7lCp(!QI^jPSE^vdj-lorIy zUk>$BMxX|TxbF4VVyy?EnyOI*9$j7q!Ok|!K1cq_)9u;9GUb7_76o5*{Ec0JWLnE>D3F>4 zss%jRQcWF$VGC^JYeCsDdlz_e+5+^P!#%#~n4~P;|M~N=V3`f8kr~beGChu(M1UYA zcl6`#)_tD*m8!Ts?L;+)oVpp-n87g0g#){-g!;}NY2EC-*PRG$d4xb>dWkY0Jm*C7 zJ0@Km^dE4#S7`aF+M-aW0&E#Q8}Dg<5c~VZ=})LHL7>@p-~4)xUTi(mwHs`o1%Hap zq3hjIq9Y{XUXv=nmo_FVlRvL|z&COH(Z;VhpY|s`+2~gEUs8Bz&LN_OpIK*Ju#-lQs%w$USB&`@_jDbn9!dXoM!gV<6v8`x{B4AK<`1gG^w^5k zI#;fJ5B(3mP}~nFpp}8;mD8l&XZ~58D!lX&YXF~8(`tMfLOuAn;I;wZ>&@*X`dLtK z{$4m-W0r}U#gas&;-cy2$i0+eDO^5v)BU;@kh5hIzn@A&&FB&(^=bHl{#F8;0u#lt$Q8v5>j7c9?c$jpvA9<3 z6uk@O{l`UINvuhC^;ANH^tZ;CEwNea7=U&eHR8`@JkQW#BI{(wPFz~R!OX$83*nnX zs5*a=zw05-cWbXEF`n3o(*H`ytVcOi%OHE*81jRpnQ~B&=#x`}q>pR%b4XTXmk< zkf!;_VAoT@uZ;TZ6;er|4dj`m-Bo7cpE&XQ6FA{D>hamBp37G_q{SGDxyKJv%$nFoPMUI!+xAvA4P_lKe(|E7op?TM(`d*D(s3R7 z17|)tpiS68Y+<=}#fx7DyyeN>FUjQliD9Jl-Ts5c@oBiZ>{ge(;j1CA!gGm*)!X#(5#Y_=qE}ks9mBtLgLy9MkQi0g7%vtv(&jP z+~_xm7K!G-{inM%Ha+lP=b=+cPg6vRbCjnKf&>McEx7QG05IxX|X0%RQ6;QJ0@APLf)|M^8#Kv zP}&OtuaC1Tx~b_FRwT4xCpwanODPPwE*}4YD%8lLg^P}O>0OivD^!2?h4c9@N}nL= zkYJ?YZN7(r1jLXMSf+R_T`&!3{^58F8c+Bf-rvjDwjf z?N~b=wnPXYiEFh_>e~a@I%Otze|w4k?9%g69Po;_!>qAd1y}O?wZ1O|rx@4&!%VJl zBogX0bn}xw{jc?1kVaX>0HSs)9|fGZzfpXT5B3ZN(YVYQj@CT*1brk&6G0QhN^y__5OcuPV7OeNZ1otQ_@1p8p}Bo0s|_(& z^K}P)Rur39YFX1tY2r+-xAv&s3HkhAi>dr>tBQFxHI%t*Hj8+U|_G){gAb zY1Q#D?#&Fa2-4n{@NihY`2ESSeZwy2dfWW{+@ScMWR5=dv{=x{_Ql0u1Rr;ug~JKX zDw(Kr5?DmzHSwhGNg^YN7TTvv{dQVh+SE=&p~T)d;WwMasU_x$oqCOLLgPjLuuub#zq3{9 zUL0#ot}h{yMU7=44+3~po7avfL7yUezvRWW!tHd!NCvl; z>mOEheq8DlRoIN|S`|TEiVRy>h_&dxt5{L{zusjnM6$BiiV3^_qrwp2nRDBF0&+;o zrlhri{#ZKPe0`9XgG7xxV$|{Vy$9#d1I;$sv~!{(H~%H5Rk1}7VX|e=6H&6(Mjy{j zT}`SZDMr|UKS#v{qb-Z>Ep7*K9|>0Rq+f%^(-s-x-?5!}C!Lh+k_l{(k@Ni7W{nZl zN}Bwn@-RO9PACX&PwlVBL<4mbIj5m8!^1RgeS>}jiTq`UF-M0RD6}Xd4;D+7b8^gx z+QM#qhe3QgBhaeUV8J}_mt~ujUIepG9fQSzM}Xhe<-wPd#wDa1nNl`a9GnzPKoO35t}% zS_#Eb+25q7e`+Pn5C+P$=o&g z7N+T!M$c%-9WoSy5;ycvvFGc9A)7(bYZ zW&3)XI?jrlW;W@JEKey+VN*n7;zD^u+_3)J=o=XV73Sj&M$E5Fe#8`3uNV*MEe^oi z&a!cpai_hNa)goY)wn@Y-$MJoO|*NqkL3P)r0l|oJmdoJcNf}?&@I=+{P zw~5~i%QGsPCw+{`u-C8Dnf05m66M@@d!UIu%V%*tQ~V}PZ!j(cvTaKrJxFgIug+dg zHjp4^b)!-ZwXW1LWLDmCB^>7$`+$V;!Sxi|!#-sG8ifKnl|XeOeRl13)HO?A!2ac( z`D1E!)Q3u)eEOw1$umSG8P5fVCGfb!KGYKqP!>$hObE}b6CC?C?-NAV6z6ORwpkEn^il-t3-OjwE&buOnv9*il?XpBf z@kOXR|AqF_Il=Ffh8Yxg@;XF1JjyT9{mGou9jektArzZN8hWk_`f=GGJg;$TEK2s4 zL&=V+GcZn zFEyw|2Mr+)SjM%EP5sUD5|3N86Y!neZ4jAgtougRu0!>8SfkoE%163Rj7Vn}6~y62 zbIf(nBES92*eO}71<;_(z2GNas;{Du6P~Jaw673{E@Q`decvvJ_92dtrX5^H?1&}W zQmB_tXn8PKbBFE^{qoMBZYh4)F+FWbud?+Pk*v`QMwdoTLM++Bjz+?=DFcivDYsxWa$6 Date: Tue, 23 Oct 2018 10:37:44 +0200 Subject: [PATCH 166/225] ci: Generate Flatpak and export it --- .gitlab-ci.yml | 55 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0854eac1..838c33c3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,25 +1,64 @@ image: fedora:rawhide stages: - build + - test variables: DEPENDENCIES: libusb1-devel glib2-devel nss-devel pixman-devel systemd meson gtk-doc - gcc gcc-c++ glibc-devel libX11-devel libXv-devel gtk3-devel + gcc gcc-c++ glibc-devel libX11-devel libXv-devel gtk3-devel flatpak-builder + BUNDLE: "org.freedesktop.libfprint.Demo.flatpak" - -before_script: - - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES - - -build: - stage: build +.build_one_driver_template: &build_one_driver script: + - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES # Build with a driver that doesn't need imaging, or nss - meson -Ddrivers=elan . _build - ninja -C _build - rm -rf _build/ + +.build_template: &build + script: + - dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES # And build with everything - meson -Ddrivers=all . _build - ninja -C _build - ninja -C _build install +build: + stage: build + <<: *build_one_driver + <<: *build + +.flatpak_script_template: &flatpak_script + script: + - flatpak-builder --stop-at=${FLATPAK_MODULE} app ${MANIFEST_PATH} + # Make sure to keep this in sync with the Flatpak manifest, all arguments + # are passed except the config-args because we build it ourselves + - flatpak build app meson --prefix=/app --libdir=lib ${MESON_ARGS} _build + - flatpak build app ninja -C _build install + - flatpak build app rm -rf /app/include/ /app/lib/pkgconfig/ + - flatpak-builder --finish-only --repo=repo app ${MANIFEST_PATH} + # Generate a Flatpak bundle + - flatpak build-bundle repo ${BUNDLE} --runtime-repo=${RUNTIME_REPO} ${DBUS_ID} + +.flatpak_artifacts_template: &flatpak_artifacts + artifacts: + paths: + - ${BUNDLE} + when: always + expire_in: 30 days + +.flatpak_template: &flatpak + <<: *flatpak_script + <<: *flatpak_artifacts + +flatpak master: + image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master + stage: test + variables: + MANIFEST_PATH: "demo/org.freedesktop.libfprint.Demo.json" + # From demo/org.freedesktop.libfprint.Demo.json + MESON_ARGS: "-Dudev_rules=false -Dx11-examples=false -Dgtk-examples=true" + FLATPAK_MODULE: "libfprint" + DBUS_ID: "org.freedesktop.libfprint.Demo" + <<: *flatpak From 9e5ae25abfe031fe154e3bf1603eb6abf4271c48 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 13:29:00 +0100 Subject: [PATCH 167/225] lib: Transform fp_img flags into a FpiImgFlags enum And document it. --- doc/libfprint-sections.txt | 8 +------- libfprint/fpi-img.c | 3 +++ libfprint/fpi-img.h | 33 +++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 103d0103..525c4c0a 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -261,13 +261,7 @@ fpi_drvcb_verify_stopped fpi-img.h fpi-img fp_minutiae - -FP_IMG_V_FLIPPED -FP_IMG_H_FLIPPED -FP_IMG_COLORS_INVERTED -FP_IMG_BINARIZED_FORM -FP_IMG_PARTIAL -FP_IMG_STANDARDIZATION_FLAGS +FpiImgFlags fpi_img_new fpi_img_new_for_imgdev diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 08b751d5..889e368c 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -303,6 +303,9 @@ static void minutiae_to_xyt(struct fp_minutiae *minutiae, int bwidth, xyt->nrows = nmin; } +#define FP_IMG_STANDARDIZATION_FLAGS (FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED \ + | FP_IMG_COLORS_INVERTED) + static int fpi_img_detect_minutiae(struct fp_img *img) { struct fp_minutiae *minutiae; diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h index 666083c4..580c41ae 100644 --- a/libfprint/fpi-img.h +++ b/libfprint/fpi-img.h @@ -24,21 +24,34 @@ struct fp_minutiae; -/* bit values for fp_img.flags */ -#define FP_IMG_V_FLIPPED (1<<0) -#define FP_IMG_H_FLIPPED (1<<1) -#define FP_IMG_COLORS_INVERTED (1<<2) -#define FP_IMG_BINARIZED_FORM (1<<3) -#define FP_IMG_PARTIAL (1<<4) - -#define FP_IMG_STANDARDIZATION_FLAGS (FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED \ - | FP_IMG_COLORS_INVERTED) +/** + * FpiImgFlags: + * @FP_IMG_V_FLIPPED: the image is vertically flipped + * @FP_IMG_H_FLIPPED: the image is horizontally flipped + * @FP_IMG_COLORS_INVERTED: the colours are inverted + * @FP_IMG_BINARIZED_FORM: binarised image, see fp_img_binarize() + * @FP_IMG_PARTIAL: the image is partial, useful for driver to keep track + * of incomplete captures + * + * Flags used in the #fp_img structure to describe the image contained + * into the structure. Note that a number of functions will refuse to + * handle images which haven't been standardised through fp_img_standardize() + * (meaning the @FP_IMG_V_FLIPPED, @FP_IMG_H_FLIPPED and @FP_IMG_COLORS_INVERTED + * should all be unset when the image needs to be analysed). + */ +typedef enum { + FP_IMG_V_FLIPPED = 1 << 0, + FP_IMG_H_FLIPPED = 1 << 1, + FP_IMG_COLORS_INVERTED = 1 << 2, + FP_IMG_BINARIZED_FORM = 1 << 3, + FP_IMG_PARTIAL = 1 << 4 +} FpiImgFlags; struct fp_img { int width; int height; size_t length; - uint16_t flags; + FpiImgFlags flags; struct fp_minutiae *minutiae; unsigned char *binarized; unsigned char data[0]; From 882fc8ab543fc9e5e66b21da6c33b670d6de0339 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 13:31:28 +0100 Subject: [PATCH 168/225] lib: Fix sloppy grammar in error output --- libfprint/fpi-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 889e368c..d053246d 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -318,7 +318,7 @@ static int fpi_img_detect_minutiae(struct fp_img *img) GTimer *timer; if (img->flags & FP_IMG_STANDARDIZATION_FLAGS) { - fp_err("cant detect minutiae for non-standardized image"); + fp_err("Cannot detect minutiae for non-standardized images"); return -EINVAL; } From 8ca34303f29d8d27e2d9e101d2be144a5b4d291a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 13:59:26 +0100 Subject: [PATCH 169/225] lib: Transform fp_img_driver flags into a FpiImgDriverFlags enum And document it. --- doc/libfprint-sections.txt | 2 +- libfprint/fpi-core.h | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 525c4c0a..94899a20 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -234,7 +234,7 @@ fp_driver_type
fpi-core.h fpi-core-img -FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE +FpiImgDriverFlags fp_img_driver
diff --git a/libfprint/fpi-core.h b/libfprint/fpi-core.h index cbc2255d..7cf0e57f 100644 --- a/libfprint/fpi-core.h +++ b/libfprint/fpi-core.h @@ -55,12 +55,20 @@ struct fp_driver { int (*capture_stop)(struct fp_dev *dev); }; -/* flags for fp_img_driver.flags */ -#define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0) +/** + * FpiImgDriverFlags: + * @FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE: Whether the driver supports + * unconditional image capture. No driver currently does. + * + * Flags used in the #fp_img_driver to advertise the capabilities of drivers. + */ +typedef enum { + FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE = 1 << 0 +} FpiImgDriverFlags; struct fp_img_driver { struct fp_driver driver; - uint16_t flags; + FpiImgDriverFlags flags; int img_width; int img_height; int bz3_threshold; From 6f18fc4bf43093685ab70f0656a2d49820a358a2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 14:08:07 +0100 Subject: [PATCH 170/225] lib: Document all the internal symbols in fpi-dev.c --- libfprint/fpi-dev.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index 8ad7dd5d..9ded0b3d 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -97,12 +97,27 @@ FP_INSTANCE_DATA (struct fp_dev *dev) return dev->instance_data; } +/** + * fpi_dev_get_usb_dev: + * @dev: a struct #fp_dev + * + * Return the #libusb_device_handle for this device. + */ libusb_device_handle * fpi_dev_get_usb_dev(struct fp_dev *dev) { return dev->udev; } +/** + * fpi_dev_set_nr_enroll_stages: + * @dev: a struct #fp_dev + * @nr_enroll_stages: the number of enroll stages + * + * Sets the number of enroll stages that this device uses. This is + * usually only necessary for primitive devices which have a hard-coded + * number of enroll stages baked into their protocol. + */ void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, int nr_enroll_stages) @@ -110,6 +125,14 @@ fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, dev->nr_enroll_stages = nr_enroll_stages; } +/** + * fpi_dev_get_verify_data: + * @dev: a struct #fp_dev + * + * Returns the verify data associated with this instance of the device. + * This is usually only necessary for primitive devices which need to + * have access to the raw verify data as it might have been stored on disk. + */ struct fp_print_data * fpi_dev_get_verify_data(struct fp_dev *dev) { From 511e164f170152f7e10d626b46a43aab14e3d1eb Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 14:20:28 +0100 Subject: [PATCH 171/225] lib: Add @short_description for all the sections So gtk-doc doesn't warn about them any more. --- libfprint/fpi-assembling.c | 1 + libfprint/fpi-async.c | 1 + libfprint/fpi-core.c | 5 +++++ libfprint/fpi-data.c | 3 +++ libfprint/fpi-dev-img.c | 1 + libfprint/fpi-dev.c | 1 + libfprint/fpi-img.c | 2 ++ libfprint/fpi-log.h | 1 + libfprint/fpi-poll.c | 2 ++ libfprint/fpi-ssm.c | 1 + libfprint/fpi-usb.c | 1 + 11 files changed, 19 insertions(+) diff --git a/libfprint/fpi-assembling.c b/libfprint/fpi-assembling.c index b4d74c06..046d4f5f 100644 --- a/libfprint/fpi-assembling.c +++ b/libfprint/fpi-assembling.c @@ -34,6 +34,7 @@ /** * SECTION:fpi-assembling * @title: Image frame assembly + * @short_description: Image frame assembly helpers * * Those are the helpers to manipulate capture data from fingerprint readers * into a uniform image that can be further processed. This is usually used diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index cc1e6ed5..c367b4b9 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -29,6 +29,7 @@ /** * SECTION:fpi-async * @title: Asynchronous operations reporting + * @short_description: Asynchronous operations reporting functions * * Those functions are used by primitive drivers to report back their * current status. Most drivers, imaging ones, do not need to use them. diff --git a/libfprint/fpi-core.c b/libfprint/fpi-core.c index 75b2838d..e57b050a 100644 --- a/libfprint/fpi-core.c +++ b/libfprint/fpi-core.c @@ -33,6 +33,7 @@ GSList *opened_devices = NULL; /** * SECTION:discovery * @title: Device discovery + * @short_description: Device discovery functions * * These functions allow you to scan the system for supported fingerprint * scanning hardware. This is your starting point when integrating libfprint @@ -47,6 +48,7 @@ GSList *opened_devices = NULL; /** * SECTION:drv * @title: Driver operations + * @short_description: Driver operation functions * * Internally, libfprint is abstracted into various drivers to communicate * with the different types of supported fingerprint readers. libfprint works @@ -61,6 +63,7 @@ GSList *opened_devices = NULL; /** * SECTION:dev * @title: Devices operations + * @short_description: Device operation functions * * In order to interact with fingerprint scanners, your software will * interface primarily with libfprint's representation of devices, detailed @@ -114,6 +117,7 @@ GSList *opened_devices = NULL; /** * SECTION:fpi-core * @title: Driver structures + * @short_description: Driver structures * * Driver structures need to be defined inside each driver in * order for the core library to know what function to call, and the capabilities @@ -123,6 +127,7 @@ GSList *opened_devices = NULL; /** * SECTION:fpi-core-img * @title: Image driver structures + * @short_description: Image driver structures * * Image driver structures need to be defined inside each image driver in * order for the core library to know what function to call, and the capabilities diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index 173be86f..7f5f2d78 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -48,6 +48,7 @@ struct fpi_print_data_item_fp2 { /** * SECTION: print_data * @title: Stored prints + * @short_description: Stored prints functions * * Stored prints are represented by a structure named #fp_print_data. * Stored prints are originally obtained from an enrollment function such as @@ -66,6 +67,7 @@ struct fpi_print_data_item_fp2 { /** * SECTION: fpi-data * @title: Stored prints creation + * @short_description: Stored prints creation functions * * Stored print can be loaded and created by certain drivers which do their own * print matching in hardware. Most drivers will not be using those functions. @@ -582,6 +584,7 @@ API_EXPORTED uint32_t fp_print_data_get_devtype(struct fp_print_data *data) /** * SECTION:dscv_print * @title: Print discovery (deprecated) + * @short_description: Print discovery functions * * The [stored print](libfprint-Stored-prints.html) documentation detailed a simple API * for storing per-device prints for a single user, namely diff --git a/libfprint/fpi-dev-img.c b/libfprint/fpi-dev-img.c index b094da23..2a640751 100644 --- a/libfprint/fpi-dev-img.c +++ b/libfprint/fpi-dev-img.c @@ -28,6 +28,7 @@ /** * SECTION:fpi-dev-img * @title: Image device operations + * @short_description: Image device operation functions * * As drivers work through different operations, they need to report back * to the core as to their internal state, so errors and successes can be diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index 9ded0b3d..c32f002a 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -23,6 +23,7 @@ /** * SECTION:fpi-dev * @title: Device operations + * @short_description: Device operation functions * * Those macros and functions will help get access to and from struct #fp_dev, * and struct #fp_img_dev types, as well as get and set the instance struct diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index d053246d..378dfd7f 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -31,6 +31,7 @@ /** * SECTION:img * @title: Image operations + * @short_description: Image operation functions * * libfprint offers several ways of retrieving images from imaging devices, * one example being the fp_dev_img_capture() function. The functions @@ -51,6 +52,7 @@ /** * SECTION:fpi-img * @title: Driver Image operations + * @short_description: Driver image operation functions * * Those are the driver-specific helpers for #fp_img manipulation. See #fp_img's * documentation for more information about data formats, and their uses in diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h index 0d13400b..177e0f7e 100644 --- a/libfprint/fpi-log.h +++ b/libfprint/fpi-log.h @@ -23,6 +23,7 @@ /** * SECTION:fpi-log * @title: Logging + * @short_description: Logging functions * * Logging in libfprint is handled through GLib's logging system, and behave the same * way as in the GLib [Message Output and Debugging Functions](https://developer.gnome.org/glib/stable/glib-Message-Logging.html) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index f3303e03..1a4b443d 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -33,6 +33,7 @@ /** * SECTION:events * @title: Initialisation and events handling + * @short_description: Initialisation and events handling functions * * These functions are only applicable to users of libfprint's asynchronous * API. @@ -67,6 +68,7 @@ /** * SECTION:fpi-poll * @title: Timeouts + * @short_description: Timeout handling helpers * * Helper functions to schedule a function call to be made after a timeout. This * is useful to avoid making blocking calls while waiting for hardware to answer diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 20a5f2f9..2d679b2f 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -28,6 +28,7 @@ /** * SECTION:fpi-ssm * @title: Sequential state machine + * @short_description: State machine helpers * * Asynchronous driver design encourages some kind of state machine behind it. * In most cases, the state machine is entirely linear - you only go to the diff --git a/libfprint/fpi-usb.c b/libfprint/fpi-usb.c index 8b06ebb4..b140d7ef 100644 --- a/libfprint/fpi-usb.c +++ b/libfprint/fpi-usb.c @@ -23,6 +23,7 @@ /** * SECTION:fpi-usb * @title: Helpers for libusb + * @short_description: libusb-related helpers * * A collection of [libusb helpers](http://libusb.sourceforge.net/api-1.0/group__poll.html#details) * to make driver development easier. Please refer to the libusb API documentation for more From 46ad86fab2141ed31666e3989bb5f3d7ae2b99e6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 14:21:56 +0100 Subject: [PATCH 172/225] doc: Remove empty "poll" section In commit 231b8f9, when porting from doxygen to gtk-doc, we created a section for "poll" functions, but we renamed that section to "events" during the porting process. We ended up with an empty "poll" section, and a correctly migrated "events" section. --- doc/libfprint-sections.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 94899a20..bbfc16ac 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -139,11 +139,6 @@ fp_img_get_minutiae fp_minutia_get_coords
-
-fprint.h -poll -
-
fpi-log.h fpi-log From e57f037a106d2a451dda520255dccbf08f452fbf Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 14:55:17 +0100 Subject: [PATCH 173/225] lib: Document FP_IMG_DEV ...and add "Returns" docs to fpi-dev.c We might need to do this more, documenting what the function does in prose, as well as a short explanation of the returned data. --- libfprint/fpi-dev.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libfprint/fpi-dev.c b/libfprint/fpi-dev.c index c32f002a..219a2a1a 100644 --- a/libfprint/fpi-dev.c +++ b/libfprint/fpi-dev.c @@ -35,6 +35,8 @@ * @dev: a struct #fp_img_dev * * Returns the struct #fp_dev associated with @dev, or %NULL on failure. + * + * Returns: a struct #fp_dev or %NULL */ struct fp_dev * FP_DEV(struct fp_img_dev *dev) @@ -50,7 +52,9 @@ FP_DEV(struct fp_img_dev *dev) * FP_IMG_DEV: * @dev: a struct #fp_dev representing an imaging device. * - * Returns: a struct #fp_img_dev or %NULL on failure. + * Returns a struct #fp_img_dev associated with @dev, or %NULL on failure. + * + * Returns: a struct #fp_img_dev or %NULL */ struct fp_img_dev * FP_IMG_DEV(struct fp_dev *dev) @@ -102,7 +106,10 @@ FP_INSTANCE_DATA (struct fp_dev *dev) * fpi_dev_get_usb_dev: * @dev: a struct #fp_dev * - * Return the #libusb_device_handle for this device. + * Returns the #libusb_device_handle associated with @dev or %NULL + * if none are associated. + * + * Returns: a #libusb_device_handle pointer or %NULL */ libusb_device_handle * fpi_dev_get_usb_dev(struct fp_dev *dev) @@ -130,9 +137,11 @@ fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, * fpi_dev_get_verify_data: * @dev: a struct #fp_dev * - * Returns the verify data associated with this instance of the device. + * Returns the verify data associated with @dev. * This is usually only necessary for primitive devices which need to * have access to the raw verify data as it might have been stored on disk. + * + * Returns: a struct #fp_print_data pointer or %NULL */ struct fp_print_data * fpi_dev_get_verify_data(struct fp_dev *dev) From ca148cbcf1926a4b0627a599fa80ed812aa97c40 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 15:59:43 +0100 Subject: [PATCH 174/225] lib: Add documentation for usb_id --- libfprint/fp_internal.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 95b212bb..63019823 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -131,6 +131,33 @@ struct fp_img_dev { }; /* fp_driver structure definition */ + +/** + * usb_id: + * @vendor: the USB vendor ID + * @product: the USB product ID + * @driver_data: data to differentiate devices of different + * vendor and product IDs. + * + * The struct #usb_id is used to declare devices supported by a + * particular driver. The @driver_data information is used to + * differentiate different models of devices which only need + * small changes compared to the default driver behaviour to function. + * + * For example, a device might have a different initialisation from + * the stock device, so the driver could do: + * + * |[ + * if (driver_data == MY_DIFFERENT_DEVICE_QUIRK) { + * ... + * } else { + * ... + * } + * ]| + * + * The default value is zero, so the @driver_data needs to be a + * non-zero to be useful. + */ struct usb_id { uint16_t vendor; uint16_t product; From 92e31683095309719d8bc0e34921a05eeacda9cd Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 12 Nov 2018 16:00:04 +0100 Subject: [PATCH 175/225] lib: Add documentation for fp_driver_type --- libfprint/fp_internal.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 63019823..f3bd9ed5 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -164,6 +164,13 @@ struct usb_id { unsigned long driver_data; }; +/** + * fp_driver_type: + * @DRIVER_PRIMITIVE: primitive, non-imaging, driver + * @DRIVER_IMAGING: imaging driver + * + * The type of device the driver supports. + */ enum fp_driver_type { DRIVER_PRIMITIVE = 0, DRIVER_IMAGING = 1, From 7615aaef7ab55f6f93278d023b2c2dd04de38963 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 12:23:32 +0100 Subject: [PATCH 176/225] lib: Document fp_img functions And fix fpi_img_new_for_imgdev()'s argument names to match between the header and the C file. --- libfprint/fpi-img-pixman.c | 12 ++++++++++++ libfprint/fpi-img.c | 38 ++++++++++++++++++++++++++++++++++++++ libfprint/fpi-img.h | 17 ++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/libfprint/fpi-img-pixman.c b/libfprint/fpi-img-pixman.c index 47044619..1c1bedb9 100644 --- a/libfprint/fpi-img-pixman.c +++ b/libfprint/fpi-img-pixman.c @@ -23,6 +23,18 @@ #include "fp_internal.h" +/** + * fpi_img_resize: + * @img: an #fp_img image + * @w_factor: horizontal factor to resize the image by + * @h_factor: vertical factor to resize the image by + * + * Resizes the #fp_img image by scaling it by @w_factor times horizontally + * and @h_factor times vertically. + * + * Returns: a newly allocated #fp_img, the original @img will not be modified + * and will also need to be freed + */ struct fp_img *fpi_img_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor) { int new_width = img->width * w_factor; diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 378dfd7f..7b9354e4 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -59,6 +59,15 @@ * front-end applications. */ +/** + * fpi_img_new: + * @length: the length of data to allocate + * + * Creates a new #fp_img structure with @length bytes of data allocated + * to hold the image. + * + * Returns: a new #fp_img to free with fp_img_free() + */ struct fp_img *fpi_img_new(size_t length) { struct fp_img *img = g_malloc0(sizeof(*img) + length); @@ -67,6 +76,16 @@ struct fp_img *fpi_img_new(size_t length) return img; } +/** + * fpi_img_new_for_imgdev: + * @imgdev: a #fp_img_dev imaging fingerprint device + * + * Creates a new #fp_img structure, like fpi_img_new(), but uses the + * driver's advertised height and width to calculate the size of the + * length of data to allocate. + * + * Returns: a new #fp_img to free with fp_img_free() + */ struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev) { struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(FP_DEV(imgdev)->drv); @@ -78,6 +97,16 @@ struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev) return img; } +/** + * fpi_img_is_sane: + * @img: a #fp_img image + * + * Checks whether an #fp_img structure passes some basic checks, such + * as length, width and height being non-zero, and the buffer being + * big enough to hold the image of said size. + * + * Returns: %TRUE if the image is sane, %FALSE otherwise + */ gboolean fpi_img_is_sane(struct fp_img *img) { guint len; @@ -98,6 +127,15 @@ gboolean fpi_img_is_sane(struct fp_img *img) return TRUE; } +/** + * fpi_img_realloc: + * @img: an #fp_img image + * @newsize: the new length of the image + * + * Changes the size of the data part of the #fp_img. + * + * Returns: the modified #fp_img, the same as the first argument to this function + */ struct fp_img *fpi_img_realloc(struct fp_img *img, size_t newsize) { return g_realloc(img, sizeof(*img) + newsize); diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h index 580c41ae..ab4bfe80 100644 --- a/libfprint/fpi-img.h +++ b/libfprint/fpi-img.h @@ -47,6 +47,21 @@ typedef enum { FP_IMG_PARTIAL = 1 << 4 } FpiImgFlags; +/** + * fp_img: + * @width: the width of the image + * @height: the height of the image + * @length: the length of the data associated with the image + * @flags: @FpiImgFlags flags describing the image contained in the structure + * @minutiae: an opaque structure representing the detected minutiae + * @binarized: the binarized image data + * @data: the start of the image data, which will be of @length size. + * + * A structure representing a captured, or processed image. The @flags member + * will show its current state, including whether whether the binarized form + * if present, whether it is complete, and whether it needs particular changes + * before being processed. + */ struct fp_img { int width; int height; @@ -58,7 +73,7 @@ struct fp_img { }; struct fp_img *fpi_img_new(size_t length); -struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev); +struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *imgdev); struct fp_img *fpi_img_realloc(struct fp_img *img, size_t newsize); struct fp_img *fpi_img_resize(struct fp_img *img, unsigned int w_factor, unsigned int h_factor); From d2e3ad4dbcfa35570621260290f6d35a4f07a4b0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 12:59:49 +0100 Subject: [PATCH 177/225] lib: Add API docs for 3 enums --- libfprint/fpi-dev-img.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libfprint/fpi-dev-img.h b/libfprint/fpi-dev-img.h index 15d68e89..3fbf5b51 100644 --- a/libfprint/fpi-dev-img.h +++ b/libfprint/fpi-dev-img.h @@ -23,6 +23,17 @@ #include "fpi-dev.h" #include "fpi-img.h" +/** + * fp_imgdev_action: + * @IMG_ACTION_NONE: no action + * @IMG_ACTION_ENROLL: device action is enrolling + * @IMG_ACTION_VERIFY: device action is verifying + * @IMG_ACTION_IDENTIFY: device action is identifying + * @IMG_ACTION_CAPTURE: device action is capturing + * + * The current action being performed by an imaging device. The current + * action can be gathered inside the driver using fpi_imgdev_get_action(). + */ enum fp_imgdev_action { IMG_ACTION_NONE = 0, IMG_ACTION_ENROLL, @@ -31,6 +42,16 @@ enum fp_imgdev_action { IMG_ACTION_CAPTURE, }; +/** + * fp_imgdev_state: + * @IMGDEV_STATE_INACTIVE: inactive + * @IMGDEV_STATE_AWAIT_FINGER_ON: waiting for the finger to be pressed or swiped + * @IMGDEV_STATE_CAPTURE: capturing an image + * @IMGDEV_STATE_AWAIT_FINGER_OFF: waiting for the finger to be removed + * + * The state of an imaging device while doing a capture. The state is + * passed through to the driver using the ::activate() or ::change_state() vfuncs. + */ enum fp_imgdev_state { IMGDEV_STATE_INACTIVE, IMGDEV_STATE_AWAIT_FINGER_ON, @@ -38,6 +59,20 @@ enum fp_imgdev_state { IMGDEV_STATE_AWAIT_FINGER_OFF, }; +/** + * fp_imgdev_enroll_state: + * @IMG_ACQUIRE_STATE_NONE: doing nothing + * @IMG_ACQUIRE_STATE_ACTIVATING: activating the device + * @IMG_ACQUIRE_STATE_AWAIT_FINGER_ON: waiting for the finger to be pressed or swiped + * @IMG_ACQUIRE_STATE_AWAIT_IMAGE: waiting for the image to be captured + * @IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF: waiting for the finger to be removed + * @IMG_ACQUIRE_STATE_DONE: enrollment has all the images it needs + * @IMG_ACQUIRE_STATE_DEACTIVATING: deactivating the device + * + * The state of an imaging device while enrolling a fingerprint. Given that enrollment + * requires multiple captures, a number of those states will be repeated before + * the state is @IMG_ACQUIRE_STATE_DONE. + */ enum fp_imgdev_enroll_state { IMG_ACQUIRE_STATE_NONE = 0, IMG_ACQUIRE_STATE_ACTIVATING, From 1781ad140ebcb1585a7ff55f1dc02cc5d38a9d9a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 13:01:34 +0100 Subject: [PATCH 178/225] lib: Remove unused fp_imgdev_verify_state enum --- doc/libfprint-sections.txt | 1 - libfprint/fpi-dev-img.h | 5 ----- 2 files changed, 6 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index bbfc16ac..fccea60c 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -203,7 +203,6 @@ fpi_dev_set_nr_enroll_stages fp_imgdev_action fp_imgdev_state fp_imgdev_enroll_state -fp_imgdev_verify_state fpi_imgdev_abort_scan fpi_imgdev_activate_complete diff --git a/libfprint/fpi-dev-img.h b/libfprint/fpi-dev-img.h index 3fbf5b51..0b0d48bc 100644 --- a/libfprint/fpi-dev-img.h +++ b/libfprint/fpi-dev-img.h @@ -83,11 +83,6 @@ enum fp_imgdev_enroll_state { IMG_ACQUIRE_STATE_DEACTIVATING, }; -enum fp_imgdev_verify_state { - IMG_VERIFY_STATE_NONE = 0, - IMG_VERIFY_STATE_ACTIVATING -}; - void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status); void fpi_imgdev_close_complete(struct fp_img_dev *imgdev); void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status); From 2b21430abe88b7b1c5921f1a97cbe1aa4d106b04 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 13:11:39 +0100 Subject: [PATCH 179/225] lib: Fix lack of description for fp_dscv_dev_get_driver_id() We documented the return value, but without writing out the function description. --- libfprint/fpi-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libfprint/fpi-core.c b/libfprint/fpi-core.c index e57b050a..2b5d3c6f 100644 --- a/libfprint/fpi-core.c +++ b/libfprint/fpi-core.c @@ -351,7 +351,10 @@ API_EXPORTED struct fp_driver *fp_dscv_dev_get_driver(struct fp_dscv_dev *dev) * fp_dscv_dev_get_driver_id: * @dev: a discovered fingerprint device * - * Returns: the ID for the underlying driver for that device + * Returns a unique driver identifier for the underlying driver + * for that device. + * + * Returns: the ID for #dev */ API_EXPORTED uint16_t fp_dscv_dev_get_driver_id(struct fp_dscv_dev *dev) { From 61483a4c472a27d3c5f8035463166517b6cd2911 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 14:05:25 +0100 Subject: [PATCH 180/225] lib: Make the fp_print_data structure private And add a couple of helpers for the upekts driver to use. --- doc/libfprint-sections.txt | 1 - libfprint/drivers/upekts.c | 4 ++-- libfprint/fp_internal.h | 13 +++++++++++++ libfprint/fpi-data.c | 13 +++++++++++++ libfprint/fpi-data.h | 15 +++------------ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index fccea60c..715ea5ae 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -281,7 +281,6 @@ fpi_assemble_lines
fpi-data.h fpi-data -fp_print_data_type fp_print_data_item fpi_print_data_new diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c index b930863b..476ef34c 100644 --- a/libfprint/drivers/upekts.c +++ b/libfprint/drivers/upekts.c @@ -1042,7 +1042,7 @@ static void e_handle_resp02(struct fp_dev *dev, unsigned char *data, item = fpi_print_data_item_new(data_len - sizeof(scan_comp)); memcpy(item->data, data + sizeof(scan_comp), data_len - sizeof(scan_comp)); - fdata->prints = g_slist_prepend(fdata->prints, item); + fpi_print_data_add_item(fdata, item); result = FP_ENROLL_COMPLETE; } @@ -1204,7 +1204,7 @@ static void verify_start_sm_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *us break; case VERIFY_INIT: ; 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 = fpi_print_data_get_item(print); size_t data_len = sizeof(verify_hdr) + item->length; unsigned char *data = g_malloc(data_len); struct libusb_transfer *transfer; diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index f3bd9ed5..5a69e51e 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -39,6 +39,19 @@ extern libusb_context *fpi_usb_ctx; extern GSList *opened_devices; +/* fp_print_data structure definition */ +enum fp_print_data_type { + PRINT_DATA_RAW = 0, /* memset-imposed default */ + PRINT_DATA_NBIS_MINUTIAE +}; + +struct fp_print_data { + uint16_t driver_id; + uint32_t devtype; + enum fp_print_data_type type; + GSList *prints; +}; + /* fp_dev structure definition */ enum fp_dev_state { DEV_STATE_INITIAL = 0, diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index 7f5f2d78..0465b725 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -149,6 +149,19 @@ struct fp_print_data *fpi_print_data_new(struct fp_dev *dev) fpi_driver_get_data_type(dev->drv)); } +struct fp_print_data_item * +fpi_print_data_get_item(struct fp_print_data *data) +{ + return data->prints->data; +} + +void +fpi_print_data_add_item(struct fp_print_data *data, + struct fp_print_data_item *item) +{ + data->prints = g_slist_prepend(data->prints, item); +} + /** * fp_print_data_get_data: * @data: the stored print diff --git a/libfprint/fpi-data.h b/libfprint/fpi-data.h index 3ea27ddb..37a7911a 100644 --- a/libfprint/fpi-data.h +++ b/libfprint/fpi-data.h @@ -20,24 +20,15 @@ #ifndef __FPI_DATA_H__ #define __FPI_DATA_H__ -enum fp_print_data_type { - PRINT_DATA_RAW = 0, /* memset-imposed default */ - PRINT_DATA_NBIS_MINUTIAE -}; - +struct fp_print_data; struct fp_print_data_item { size_t length; unsigned char data[0]; }; -struct fp_print_data { - uint16_t driver_id; - uint32_t devtype; - enum fp_print_data_type type; - GSList *prints; -}; - struct fp_print_data *fpi_print_data_new(struct fp_dev *dev); struct fp_print_data_item *fpi_print_data_item_new(size_t length); +struct fp_print_data_item *fpi_print_data_get_item(struct fp_print_data *data); +void fpi_print_data_add_item(struct fp_print_data *data, struct fp_print_data_item *item); #endif From 1d00c2d4b47bfc1ee67d7455899d992695d96a26 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 14:38:24 +0100 Subject: [PATCH 181/225] lib: Make 6 async reporting funcs private As those aren't used in any driver. --- doc/libfprint-sections.txt | 6 ------ libfprint/fp_internal.h | 11 +++++++++++ libfprint/fpi-async.h | 10 ---------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 715ea5ae..36b6573f 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -235,17 +235,11 @@ fp_img_driver
fpi-async.h fpi-async -fpi_drvcb_capture_started -fpi_drvcb_capture_stopped fpi_drvcb_close_complete fpi_drvcb_enroll_stage_completed fpi_drvcb_enroll_started fpi_drvcb_enroll_stopped -fpi_drvcb_identify_started -fpi_drvcb_identify_stopped fpi_drvcb_open_complete -fpi_drvcb_report_capture_result -fpi_drvcb_report_identify_result fpi_drvcb_report_verify_result fpi_drvcb_verify_started fpi_drvcb_verify_stopped diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 5a69e51e..cb0a982d 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -304,6 +304,17 @@ void fpi_timeout_cancel_all_for_dev(struct fp_dev *dev); void fpi_poll_init(void); void fpi_poll_exit(void); +/* Defined in fpi-async.c */ +void fpi_drvcb_capture_started(struct fp_dev *dev, int status); +void fpi_drvcb_report_capture_result(struct fp_dev *dev, int result, + struct fp_img *img); +void fpi_drvcb_capture_stopped(struct fp_dev *dev); + +void fpi_drvcb_identify_started(struct fp_dev *dev, int status); +void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, + size_t match_offset, struct fp_img *img); +void fpi_drvcb_identify_stopped(struct fp_dev *dev); + #include "drivers_definitions.h" #endif diff --git a/libfprint/fpi-async.h b/libfprint/fpi-async.h index 120a7c76..cf6fa32e 100644 --- a/libfprint/fpi-async.h +++ b/libfprint/fpi-async.h @@ -36,14 +36,4 @@ void fpi_drvcb_report_verify_result(struct fp_dev *dev, int result, struct fp_img *img); void fpi_drvcb_verify_stopped(struct fp_dev *dev); -void fpi_drvcb_identify_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_identify_result(struct fp_dev *dev, int result, - size_t match_offset, struct fp_img *img); -void fpi_drvcb_identify_stopped(struct fp_dev *dev); - -void fpi_drvcb_capture_started(struct fp_dev *dev, int status); -void fpi_drvcb_report_capture_result(struct fp_dev *dev, int result, - struct fp_img *img); -void fpi_drvcb_capture_stopped(struct fp_dev *dev); - #endif From aff7efd8910445d80b3f668d95c9a308712a8e93 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 15:22:37 +0100 Subject: [PATCH 182/225] lib: Remove upekts used headers from the docs They're only used by this super quirky driver that stores data internally. See #127 --- doc/libfprint-docs.xml | 5 ----- doc/libfprint-sections.txt | 22 ---------------------- doc/meson.build | 2 ++ libfprint/drivers_api.h | 1 - libfprint/fpi-async.c | 2 +- libfprint/fpi-data.c | 2 +- 6 files changed, 4 insertions(+), 30 deletions(-) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index a330bebf..3ef995b7 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -59,11 +59,6 @@ - - Hardware print matching - - - diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 36b6573f..b0c74fa9 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -232,19 +232,6 @@ FpiImgDriverFlags fp_img_driver
-
-fpi-async.h -fpi-async -fpi_drvcb_close_complete -fpi_drvcb_enroll_stage_completed -fpi_drvcb_enroll_started -fpi_drvcb_enroll_stopped -fpi_drvcb_open_complete -fpi_drvcb_report_verify_result -fpi_drvcb_verify_started -fpi_drvcb_verify_stopped -
-
fpi-img.h fpi-img @@ -272,15 +259,6 @@ fpi_assemble_frames fpi_assemble_lines
-
-fpi-data.h -fpi-data -fp_print_data_item - -fpi_print_data_new -fpi_print_data_item_new -
-
fpi-usb.h fpi-usb diff --git a/doc/meson.build b/doc/meson.build index 591cb8ab..83247085 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -6,6 +6,8 @@ private_headers = [ 'aeslib.h', 'assembling.h', 'fp_internal.h', + 'fpi-async.h', + 'fpi-data.h', # Drivers 'aes1660.h', diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index 647a2084..7867e346 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -32,7 +32,6 @@ #include "fpi-poll.h" #include "fpi-dev.h" #include "fpi-usb.h" -#include "fpi-data.h" #include "fpi-img.h" #include "fpi-assembling.h" #include "drivers/driver_ids.h" diff --git a/libfprint/fpi-async.c b/libfprint/fpi-async.c index c367b4b9..ddf5230b 100644 --- a/libfprint/fpi-async.c +++ b/libfprint/fpi-async.c @@ -26,7 +26,7 @@ #include #include -/** +/* * SECTION:fpi-async * @title: Asynchronous operations reporting * @short_description: Asynchronous operations reporting functions diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index 0465b725..b2609ef3 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -64,7 +64,7 @@ struct fpi_print_data_item_fp2 { * in any fashion that suits you. */ -/** +/* * SECTION: fpi-data * @title: Stored prints creation * @short_description: Stored prints creation functions From b5f175b78e41b4a3c0dbf0bd099a60c3b2e0a644 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 15:28:38 +0100 Subject: [PATCH 183/225] lib: Move action state functions to correct C file --- libfprint/fpi-dev-img.c | 25 +++++++++++++++++++++++++ libfprint/fpi-img.c | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/libfprint/fpi-dev-img.c b/libfprint/fpi-dev-img.c index 2a640751..2a57686f 100644 --- a/libfprint/fpi-dev-img.c +++ b/libfprint/fpi-dev-img.c @@ -39,6 +39,31 @@ #define BOZORTH3_DEFAULT_THRESHOLD 40 #define IMG_ENROLL_STAGES 5 +enum fp_imgdev_enroll_state +fpi_imgdev_get_action_state(struct fp_img_dev *imgdev) +{ + return imgdev->action_state; +} + +enum fp_imgdev_action +fpi_imgdev_get_action(struct fp_img_dev *imgdev) +{ + return imgdev->action; +} + +int +fpi_imgdev_get_action_result(struct fp_img_dev *imgdev) +{ + return imgdev->action_result; +} + +void +fpi_imgdev_set_action_result(struct fp_img_dev *imgdev, + int action_result) +{ + imgdev->action_result = action_result; +} + static int img_dev_open(struct fp_dev *dev, unsigned long driver_data) { struct fp_img_dev *imgdev = g_malloc0(sizeof(*imgdev)); diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index 7b9354e4..b4677db7 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -615,31 +615,6 @@ API_EXPORTED int fp_minutia_get_coords(struct fp_minutia *minutia, int *coord_x, return 0; } -enum fp_imgdev_enroll_state -fpi_imgdev_get_action_state(struct fp_img_dev *imgdev) -{ - return imgdev->action_state; -} - -enum fp_imgdev_action -fpi_imgdev_get_action(struct fp_img_dev *imgdev) -{ - return imgdev->action; -} - -int -fpi_imgdev_get_action_result(struct fp_img_dev *imgdev) -{ - return imgdev->action_result; -} - -void -fpi_imgdev_set_action_result(struct fp_img_dev *imgdev, - int action_result) -{ - imgdev->action_result = action_result; -} - /* Calculate squared standand deviation */ int fpi_std_sq_dev(const unsigned char *buf, int size) { From 6ba101602442a1d18bcb050c25974ddb3b1f99c0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 17:15:10 +0100 Subject: [PATCH 184/225] lib: Hide struct fp_minutiae from the docs It's only used internally. --- doc/libfprint-sections.txt | 1 - libfprint/fpi-img.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index b0c74fa9..556ea723 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -235,7 +235,6 @@ fp_img_driver
fpi-img.h fpi-img -fp_minutiae FpiImgFlags fpi_img_new diff --git a/libfprint/fpi-img.h b/libfprint/fpi-img.h index ab4bfe80..4ebc3f39 100644 --- a/libfprint/fpi-img.h +++ b/libfprint/fpi-img.h @@ -67,7 +67,9 @@ struct fp_img { int height; size_t length; FpiImgFlags flags; + /*< private >*/ struct fp_minutiae *minutiae; + /*< public >*/ unsigned char *binarized; unsigned char data[0]; }; From ce1a675dd5b4978739e9fafe14dac45b56db6e86 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 17:15:39 +0100 Subject: [PATCH 185/225] lib: Reword "use the functions below" docs Those usually appear in struct definitions which will be at the bottom of the docs, so there's nothing but the bottom of the page below. --- libfprint/fprint.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libfprint/fprint.h b/libfprint/fprint.h index c6efecc2..b9b09092 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -42,7 +42,7 @@ extern "C" { * fp_dscv_dev: * * #fp_dscv_dev is an opaque structure type. You must access it using the - * functions below. + * functions in this section. */ struct fp_dscv_dev; @@ -50,7 +50,7 @@ struct fp_dscv_dev; * fp_dscv_print: * * #fp_dscv_print is an opaque structure type. You must access it using the - * functions below. + * functions in this section. */ struct fp_dscv_print; @@ -58,7 +58,7 @@ struct fp_dscv_print; * fp_dev: * * #fp_dev is an opaque structure type. You must access it using the - * functions below. + * functions in this section. */ struct fp_dev; @@ -66,7 +66,7 @@ struct fp_dev; * fp_driver: * * #fp_driver is an opaque structure type. You must access it using the - * functions below. + * functions in this section. */ struct fp_driver; @@ -74,7 +74,7 @@ struct fp_driver; * fp_print_data: * * #fp_print_data is an opaque structure type. You must access it using the - * functions below. + * functions in this section. */ struct fp_print_data; @@ -82,7 +82,7 @@ struct fp_print_data; * fp_img: * * #fp_img is an opaque structure type. You must access it using the - * functions below. + * functions in this section. */ struct fp_img; @@ -293,7 +293,7 @@ uint32_t fp_print_data_get_devtype(struct fp_print_data *data); * fp_minutia: * * #fp_minutia is an opaque structure type. You must access it using the - * functions below. + * functions in this section. */ struct fp_minutia; From eae5721f8e8103ce0d46d28b17e0e7f354690f7c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 17:18:16 +0100 Subject: [PATCH 186/225] vfs101: Add FIXME about fpi_imgdev_set_action_result usage We shouldn't need to use fpi_imgdev_set_action_result(), because as fpi_imgdev_image_captured() is already there. --- libfprint/drivers/vfs101.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 32c67394..8faaa230 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -767,6 +767,11 @@ img_extract(fpi_ssm *ssm, /* Notify image captured */ fpi_imgdev_image_captured(dev, img); + /* FIXME + * What is this for? The action result, and the enroll stages should + * already be handled in fpi_imgdev_image_captured() + */ + /* Check captured result */ if (fpi_imgdev_get_action_result(dev) >= 0 && fpi_imgdev_get_action_result(dev) != FP_ENROLL_RETRY && From dabcae7b4da4506acec17121cff85941a0d4c43b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 29 Nov 2018 17:20:33 +0100 Subject: [PATCH 187/225] lib: Document fpi_imgdev_*() functions --- libfprint/fpi-dev-img.c | 90 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/libfprint/fpi-dev-img.c b/libfprint/fpi-dev-img.c index 2a57686f..93f1f47e 100644 --- a/libfprint/fpi-dev-img.c +++ b/libfprint/fpi-dev-img.c @@ -39,24 +39,56 @@ #define BOZORTH3_DEFAULT_THRESHOLD 40 #define IMG_ENROLL_STAGES 5 +/** + * fpi_imgdev_get_action_state: + * @imgdev: a #fp_img_dev imaging fingerprint device + * + * Returns the state of an imaging device while enrolling a fingerprint. + * + * Returns: a enum #fp_imgdev_enroll_state + */ enum fp_imgdev_enroll_state fpi_imgdev_get_action_state(struct fp_img_dev *imgdev) { return imgdev->action_state; } +/** + * fpi_imgdev_get_action: + * @imgdev: a #fp_img_dev imaging fingerprint device + * + * Returns the current action being performed by an imaging device. + * + * Returns: a enum #fp_imgdev_action + */ enum fp_imgdev_action fpi_imgdev_get_action(struct fp_img_dev *imgdev) { return imgdev->action; } +/** + * fpi_imgdev_get_action_result: + * @imgdev: a #fp_img_dev imaging fingerprint device + * + * Returns an integer representing the result of an action. Which enum + * the result code is taken from depends on the current action being performed. + * See #fp_capture_result, #fp_enroll_result and #fp_verify_result. + */ int fpi_imgdev_get_action_result(struct fp_img_dev *imgdev) { return imgdev->action_result; } +/** + * fpi_imgdev_set_action_result: + * @imgdev: a #fp_img_dev imaging fingerprint device + * @action_result: an action result + * + * Drivers should use fpi_imgdev_image_captured() instead. This function + * should not be used, and will be removed soon. + */ void fpi_imgdev_set_action_result(struct fp_img_dev *imgdev, int action_result) @@ -91,6 +123,14 @@ err: return r; } +/** + * fpi_imgdev_open_complete: + * @imgdev: a #fp_img_dev imaging fingerprint device + * @status: an error code + * + * Function to call when the device has been opened, whether + * successfully of not. + */ void fpi_imgdev_open_complete(struct fp_img_dev *imgdev, int status) { fpi_drvcb_open_complete(FP_DEV(imgdev), status); @@ -106,6 +146,12 @@ static void img_dev_close(struct fp_dev *dev) fpi_drvcb_close_complete(dev); } +/** + * fpi_imgdev_close_complete: + * @imgdev: a #fp_img_dev imaging fingerprint device + * + * Function to call when the device has been closed. + */ void fpi_imgdev_close_complete(struct fp_img_dev *imgdev) { fpi_drvcb_close_complete(FP_DEV(imgdev)); @@ -153,6 +199,14 @@ static int sanitize_image(struct fp_img_dev *imgdev, struct fp_img **_img) return 0; } +/** + * fpi_imgdev_report_finger_status: + * @imgdev: a #fp_img_dev imaging fingerprint device + * @present: whether the finger is present on the sensor + * + * Reports from the driver whether the user's finger is on + * the sensor. + */ void fpi_imgdev_report_finger_status(struct fp_img_dev *imgdev, gboolean present) { @@ -255,6 +309,14 @@ static void identify_process_img(struct fp_img_dev *imgdev) imgdev->identify_match_offset = match_offset; } +/** + * fpi_imgdev_abort_scan: + * @imgdev: a #fp_img_dev imaging fingerprint device + * @result: the scan result + * + * Aborts a scan after an error, and set the action result. See + * fpi_imgdev_get_action_result() for possible values. + */ void fpi_imgdev_abort_scan(struct fp_img_dev *imgdev, int result) { imgdev->action_result = result; @@ -262,6 +324,13 @@ void fpi_imgdev_abort_scan(struct fp_img_dev *imgdev, int result) dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_OFF); } +/** + * fpi_imgdev_image_captured: + * @imgdev: a #fp_img_dev imaging fingerprint device + * @img: an #fp_img image + * + * Report to the core that the driver captured this image from the sensor. + */ void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img) { struct fp_print_data *print = NULL; @@ -342,6 +411,13 @@ next_state: dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_OFF); } +/** + * fpi_imgdev_session_error: + * @imgdev: a #fp_img_dev imaging fingerprint device + * @error: an error code + * + * Report an error that occurred in the driver. + */ void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error) { fp_dbg("error %d", error); @@ -365,6 +441,14 @@ void fpi_imgdev_session_error(struct fp_img_dev *imgdev, int error) } } +/** + * fpi_imgdev_activate_complete: + * @imgdev: a #fp_img_dev imaging fingerprint device + * @status: the activation result + * + * Marks an activation as complete, whether successful or not. + * See fpi_imgdev_get_action_result() for possible values. + */ void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status) { fp_dbg("status %d", status); @@ -393,6 +477,12 @@ void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status) } } +/** + * fpi_imgdev_deactivate_complete: + * @imgdev: a #fp_img_dev imaging fingerprint device + * + * Marks a deactivation as complete. + */ void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev) { G_DEBUG_HERE(); From 451a4c0969d34f2ea16ee983ad8dd123b0ef4e08 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 30 Nov 2018 16:05:23 +0100 Subject: [PATCH 188/225] lib: Remove duplicated structs from fp_internal.h They are already declared in fpi-core.h. Also move their API docs to fpi-core.h. --- libfprint/fp_internal.h | 84 +---------------------------------------- libfprint/fpi-core.h | 34 +++++++++++++++++ 2 files changed, 36 insertions(+), 82 deletions(-) diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index cb0a982d..d9857387 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -28,8 +28,9 @@ #include #include "fprint.h" -#include "fpi-log.h" #include "fpi-dev.h" +#include "fpi-core.h" +#include "fpi-log.h" #include "fpi-dev-img.h" #include "fpi-data.h" #include "fpi-img.h" @@ -145,72 +146,6 @@ struct fp_img_dev { /* fp_driver structure definition */ -/** - * usb_id: - * @vendor: the USB vendor ID - * @product: the USB product ID - * @driver_data: data to differentiate devices of different - * vendor and product IDs. - * - * The struct #usb_id is used to declare devices supported by a - * particular driver. The @driver_data information is used to - * differentiate different models of devices which only need - * small changes compared to the default driver behaviour to function. - * - * For example, a device might have a different initialisation from - * the stock device, so the driver could do: - * - * |[ - * if (driver_data == MY_DIFFERENT_DEVICE_QUIRK) { - * ... - * } else { - * ... - * } - * ]| - * - * The default value is zero, so the @driver_data needs to be a - * non-zero to be useful. - */ -struct usb_id { - uint16_t vendor; - uint16_t product; - unsigned long driver_data; -}; - -/** - * fp_driver_type: - * @DRIVER_PRIMITIVE: primitive, non-imaging, driver - * @DRIVER_IMAGING: imaging driver - * - * The type of device the driver supports. - */ -enum fp_driver_type { - DRIVER_PRIMITIVE = 0, - DRIVER_IMAGING = 1, -}; - -struct fp_driver { - const uint16_t id; - const char *name; - const char *full_name; - const struct usb_id * const id_table; - enum fp_driver_type type; - enum fp_scan_type scan_type; - - /* Device operations */ - int (*discover)(struct libusb_device_descriptor *dsc, uint32_t *devtype); - int (*open)(struct fp_dev *dev, unsigned long driver_data); - void (*close)(struct fp_dev *dev); - int (*enroll_start)(struct fp_dev *dev); - int (*enroll_stop)(struct fp_dev *dev); - int (*verify_start)(struct fp_dev *dev); - int (*verify_stop)(struct fp_dev *dev, gboolean iterating); - int (*identify_start)(struct fp_dev *dev); - int (*identify_stop)(struct fp_dev *dev, gboolean iterating); - int (*capture_start)(struct fp_dev *dev); - int (*capture_stop)(struct fp_dev *dev); -}; - /* fp_img_driver structure definition */ #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ @@ -218,21 +153,6 @@ struct fp_driver { #define fpi_driver_to_img_driver(drv) \ container_of((drv), struct fp_img_driver, driver) -struct fp_img_driver { - struct fp_driver driver; - uint16_t flags; - int img_width; - int img_height; - int bz3_threshold; - - /* Device operations */ - int (*open)(struct fp_img_dev *dev, unsigned long driver_data); - void (*close)(struct fp_img_dev *dev); - int (*activate)(struct fp_img_dev *dev, enum fp_imgdev_state state); - int (*change_state)(struct fp_img_dev *dev, enum fp_imgdev_state state); - void (*deactivate)(struct fp_img_dev *dev); -}; - /* fp_dscv_dev structure definition */ struct fp_dscv_dev { struct libusb_device *udev; diff --git a/libfprint/fpi-core.h b/libfprint/fpi-core.h index 7cf0e57f..a5a0a44d 100644 --- a/libfprint/fpi-core.h +++ b/libfprint/fpi-core.h @@ -21,13 +21,47 @@ #define __FPI_CORE_H__ #include +#include "fpi-dev-img.h" +/** + * usb_id: + * @vendor: the USB vendor ID + * @product: the USB product ID + * @driver_data: data to differentiate devices of different + * vendor and product IDs. + * + * The struct #usb_id is used to declare devices supported by a + * particular driver. The @driver_data information is used to + * differentiate different models of devices which only need + * small changes compared to the default driver behaviour to function. + * + * For example, a device might have a different initialisation from + * the stock device, so the driver could do: + * + * |[ + * if (driver_data == MY_DIFFERENT_DEVICE_QUIRK) { + * ... + * } else { + * ... + * } + * ]| + * + * The default value is zero, so the @driver_data needs to be a + * non-zero to be useful. + */ struct usb_id { uint16_t vendor; uint16_t product; unsigned long driver_data; }; +/** + * fp_driver_type: + * @DRIVER_PRIMITIVE: primitive, non-imaging, driver + * @DRIVER_IMAGING: imaging driver + * + * The type of device the driver supports. + */ enum fp_driver_type { DRIVER_PRIMITIVE = 0, DRIVER_IMAGING = 1, From dd24cf57c695fefdd96df4be531d377c0c1efb54 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 30 Nov 2018 17:57:40 +0100 Subject: [PATCH 189/225] README: Add links to historical resources --- README | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README b/README index c54fb2c9..fbf76705 100644 --- a/README +++ b/README @@ -39,3 +39,13 @@ We include bozorth3 from the US export controlled distribution. We have determined that it is fine to ship bozorth3 in an open source project, see https://fprint.freedesktop.org/us-export-control.html +## Historical links + +Older versions of libfprint are available at: +https://sourceforge.net/projects/fprint/files/ + +Historical mailing-list archives: +http://www.reactivated.net/fprint_list_archives/ + +Historical website: +http://web.archive.org/web/*/https://www.freedesktop.org/wiki/Software/fprint/ From c9733d27dfee17c7dea4ab6b765a3f9a8afd556b Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Mon, 3 Dec 2018 14:08:24 +0100 Subject: [PATCH 190/225] lib: Add API docs for fpi_img comparison functions --- libfprint/fpi-img.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/libfprint/fpi-img.c b/libfprint/fpi-img.c index b4677db7..f5ebea7f 100644 --- a/libfprint/fpi-img.c +++ b/libfprint/fpi-img.c @@ -615,7 +615,22 @@ API_EXPORTED int fp_minutia_get_coords(struct fp_minutia *minutia, int *coord_x, return 0; } -/* Calculate squared standand deviation */ +/** + * fpi_std_sq_dev: + * @buf: buffer (usually bitmap, one byte per pixel) + * @size: size of @buffer + * + * Calculates the squared standard deviation of the individual + * pixels in the buffer, as per the following formula: + * |[ + * mean = sum (buf[0..size]) / size + * sq_dev = sum ((buf[0.size] - mean) ^ 2) + * ]| + * This function is usually used to determine whether image + * is empty. + * + * Returns: the squared standard deviation for @buffer + */ int fpi_std_sq_dev(const unsigned char *buf, int size) { int res = 0, mean = 0, i; @@ -638,7 +653,23 @@ int fpi_std_sq_dev(const unsigned char *buf, int size) return res / size; } -/* Calculate normalized mean square difference of two lines */ +/** + * fpi_mean_sq_diff_norm: + * @buf1: buffer (usually bitmap, one byte per pixel) + * @buf2: buffer (usually bitmap, one byte per pixel) + * @size: buffer size of smallest buffer + * + * This function calculates the normalized mean square difference of + * two buffers, usually two lines, as per the following formula: + * |[ + * sq_diff = sum ((buf1[0..size] - buf2[0..size]) ^ 2) / size + * ]| + * + * This functions is usually used to get numerical difference + * between two images. + * + * Returns: the normalized mean squared difference between @buf1 and @buf2 + */ int fpi_mean_sq_diff_norm(unsigned char *buf1, unsigned char *buf2, int size) { int res = 0, i; From 2088a6177f9b42694cee2f4512cd0b7483330cf6 Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Sun, 2 Dec 2018 11:02:12 -0800 Subject: [PATCH 191/225] lib: Document assembling functions --- libfprint/fpi-assembling.c | 70 +++++++++++++++++++++++++++++++------- libfprint/fpi-assembling.h | 58 +++++++++++++++++++++++++++++-- 2 files changed, 112 insertions(+), 16 deletions(-) diff --git a/libfprint/fpi-assembling.c b/libfprint/fpi-assembling.c index 046d4f5f..3eabb4d0 100644 --- a/libfprint/fpi-assembling.c +++ b/libfprint/fpi-assembling.c @@ -163,6 +163,22 @@ static unsigned int do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx, return total_error / num_stripes; } +/** + * fpi_do_movement_estimation: + * @ctx: #fpi_frame_asmbl_ctx - frame assembling context + * @stripes: a singly-linked list of #fpi_frame + * @num_stripes: number of items in @stripes to process + * + * fpi_do_movement_estimation() estimates the movement between adjacent + * frames, populating @delta_x and @delta_y values for each #fpi_frame. + * + * This function is used for devices that don't do movement estimation + * in hardware. If hardware movement estimation is supported, the driver + * should populate @delta_x and @delta_y instead. + * + * Note that @num_stripes might be shorter than the length of the list, + * if some stripes should be skipped. + */ void fpi_do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx, GSList *stripes, size_t num_stripes) { @@ -236,8 +252,22 @@ static inline void aes_blit_stripe(struct fpi_frame_asmbl_ctx *ctx, } } +/** + * fpi_assemble_frames: + * @ctx: #fpi_frame_asmbl_ctx - frame assembling context + * @stripes: linked list of #fpi_frame + * @num_stripes: number of items in @stripes to process + * + * fpi_assemble_frames() assembles individual frames into a single image. + * It expects @delta_x and @delta_y of #fpi_frame to be populated. + * + * Note that @num_stripes might be shorter than the length of the list, + * if some stripes should be skipped. + * + * Returns: a newly allocated #fp_img. + */ struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx, - GSList *stripes, size_t stripes_len) + GSList *stripes, size_t num_stripes) { GSList *stripe; struct fp_img *img; @@ -246,7 +276,8 @@ struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx, gboolean reverse = FALSE; struct fpi_frame *fpi_frame; - BUG_ON(stripes_len == 0); + //FIXME g_return_if_fail + BUG_ON(num_stripes == 0); BUG_ON(ctx->image_width < ctx->frame_width); /* Calculate height */ @@ -263,7 +294,7 @@ struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx, height += fpi_frame->delta_y; i++; stripe = g_slist_next(stripe); - } while (i < stripes_len); + } while (i < num_stripes); fp_dbg("height is %d", height); @@ -305,7 +336,7 @@ struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx, stripe = g_slist_next(stripe); i++; - } while (i < stripes_len); + } while (i < num_stripes); return img; } @@ -361,32 +392,45 @@ static void interpolate_lines(struct fpi_line_asmbl_ctx *ctx, } } -/* Rescale image to account for variable swiping speed */ +/** + * fpi_assemble_lines: + * @ctx: #fpi_frame_asmbl_ctx - frame assembling context + * @lines: linked list of lines + * @num_lines: number of items in @lines to process + * + * #fpi_assemble_lines assembles individual lines into a single image. + * It also rescales image to account variable swiping speed. + * + * Note that @num_lines might be shorter than the length of the list, + * if some lines should be skipped. + * + * Returns: a newly allocated #fp_img. + */ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx, - GSList *lines, size_t lines_len) + GSList *lines, size_t num_lines) { /* Number of output lines per distance between two scanners */ int i; GSList *row1, *row2; float y = 0.0; int line_ind = 0; - int *offsets = (int *)g_malloc0((lines_len / 2) * sizeof(int)); + int *offsets = (int *)g_malloc0((num_lines / 2) * sizeof(int)); unsigned char *output = g_malloc0(ctx->line_width * ctx->max_height); struct fp_img *img; g_return_val_if_fail (lines != NULL, NULL); - g_return_val_if_fail (lines_len > 0, NULL); + g_return_val_if_fail (num_lines > 0, NULL); fp_dbg("%"G_GINT64_FORMAT, g_get_real_time()); row1 = lines; - for (i = 0; (i < lines_len - 1) && row1; i += 2) { + for (i = 0; (i < num_lines - 1) && row1; i += 2) { int bestmatch = i; int bestdiff = 0; int j, firstrow, lastrow; firstrow = i + 1; - lastrow = MIN(i + ctx->max_search_offset, lines_len - 1); + lastrow = MIN(i + ctx->max_search_offset, num_lines - 1); row2 = g_slist_next(row1); for (j = firstrow; j <= lastrow; j++) { @@ -406,13 +450,13 @@ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx, row1 = g_slist_next(row1); } - median_filter(offsets, (lines_len / 2) - 1, ctx->median_filter_size); + median_filter(offsets, (num_lines / 2) - 1, ctx->median_filter_size); fp_dbg("offsets_filtered: %"G_GINT64_FORMAT, g_get_real_time()); - for (i = 0; i <= (lines_len / 2) - 1; i++) + for (i = 0; i <= (num_lines / 2) - 1; i++) fp_dbg("%d", offsets[i]); row1 = lines; - for (i = 0; i < lines_len - 1; i++, row1 = g_slist_next(row1)) { + for (i = 0; i < num_lines - 1; i++, row1 = g_slist_next(row1)) { int offset = offsets[i/2]; if (offset > 0) { float ynext = y + (float)ctx->resolution / offset; diff --git a/libfprint/fpi-assembling.h b/libfprint/fpi-assembling.h index fdd9518b..d2a66515 100644 --- a/libfprint/fpi-assembling.h +++ b/libfprint/fpi-assembling.h @@ -22,12 +22,36 @@ #include +/** + * fpi_frame: + * @delta_x: X offset of the frame + * @delta_y: Y offset of the frame + * @data: bitmap + * + * #fpi_frame is used to store frames for swipe sensors. Drivers should + * populate delta_x and delta_y if the device supports hardware movement + * estimation. + */ struct fpi_frame { int delta_x; int delta_y; unsigned char data[0]; }; +/** + * fpi_frame_asmbl_ctx: + * @frame_width: width of the frame + * @frame_height: height of the frame + * @image_width: resulting image width + * @get_pixel: pixel accessor, returns pixel brightness at x,y of frame + * + * #fpi_frame_asmbl_ctx is a structure holding the context for frame + * assembling routines. + * + * Drivers should define their own #fpi_frame_asmbl_ctx depending on + * hardware parameters of scanner. @image_width is usually 25% wider than + * @frame_width to take horizontal movement into account. + */ struct fpi_frame_asmbl_ctx { unsigned int frame_width; unsigned int frame_height; @@ -39,11 +63,39 @@ struct fpi_frame_asmbl_ctx { }; void fpi_do_movement_estimation(struct fpi_frame_asmbl_ctx *ctx, - GSList *stripes, size_t stripes_len); + GSList *stripes, size_t num_stripes); struct fp_img *fpi_assemble_frames(struct fpi_frame_asmbl_ctx *ctx, - GSList *stripes, size_t stripes_len); + GSList *stripes, size_t num_stripes); +/** + * fpi_line_asmbl_ctx: + * @line_width: width of line + * @max_height: maximal height of assembled image + * @resolution: scale factor used for line assembling routines. + * @median_filter_size: size of median filter for movement estimation + * @max_search_offset: the number of lines to search for the next line + * @get_deviation: pointer to a function that returns the numerical difference + * between two lines + * @get_pixel: pixel accessor, returns pixel brightness at x of line + * + * #fpi_line_asmbl_ctx is a structure holding the context for line assembling + * routines. + * + * Drivers should define their own #fpi_line_asmbl_ctx depending on + * the hardware parameters of the scanner. Swipe scanners of this type usually + * return two lines, the second line is often narrower than first and is used + * for movement estimation. + * + * The @max_search_offset value indicates how many lines forward the assembling + * routines should look while searching for next line. This value depends on + * how fast the hardware sends frames. + * + * The function pointed to by @get_deviation should return the numerical difference + * between two lines. Higher values means lines are more different. If the reader + * returns two lines at a time, this function should be used to estimate the + * difference between pairs of lines. + */ struct fpi_line_asmbl_ctx { unsigned int line_width; unsigned int max_height; @@ -58,6 +110,6 @@ struct fpi_line_asmbl_ctx { }; struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx, - GSList *lines, size_t lines_len); + GSList *lines, size_t num_lines); #endif From bcfe0ad12ce87a95bd836f1b88815d9928b6a382 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Dec 2018 16:41:48 +0100 Subject: [PATCH 192/225] ci: Disable Flatpak generation for now It's currently broken on our CI runners, we'll need to reactivate it again in the future. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 838c33c3..13a8ec36 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,7 +52,7 @@ build: <<: *flatpak_script <<: *flatpak_artifacts -flatpak master: +.flatpak master: image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master stage: test variables: From 95b1e75f1b0453fa8455aa19e2909de68bde3ec2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 4 Dec 2018 17:43:19 +0100 Subject: [PATCH 193/225] Revert "ci: Disable Flatpak generation for now" This reverts commit bcfe0ad12ce87a95bd836f1b88815d9928b6a382. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 13a8ec36..838c33c3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,7 +52,7 @@ build: <<: *flatpak_script <<: *flatpak_artifacts -.flatpak master: +flatpak master: image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master stage: test variables: From 3cbc908a6ed8a4168a8c59476bbf93cf272d5c6e Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 6 Dec 2018 10:58:35 +0100 Subject: [PATCH 194/225] lib: Add better guard against huge malloc See dda6857feef60694dac1493b3860a64e4fa5f8f3 and https://bugzilla.redhat.com/show_bug.cgi?id=1656518 When the number of lines to assemble is 1, the median_filter() function would be passed -1 as its size as it was calculated with: (num_lines / 2) - 1 so (1 / 2) - 1 = 0 - 1 = -1 Add a guard to stop drivers trying to assemble single lines. This doesn't however fix the vfs5011 driver that tried to do that. --- libfprint/fpi-assembling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-assembling.c b/libfprint/fpi-assembling.c index 3eabb4d0..e33dafe5 100644 --- a/libfprint/fpi-assembling.c +++ b/libfprint/fpi-assembling.c @@ -419,7 +419,7 @@ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx, struct fp_img *img; g_return_val_if_fail (lines != NULL, NULL); - g_return_val_if_fail (num_lines > 0, NULL); + g_return_val_if_fail (num_lines >= 2, NULL); fp_dbg("%"G_GINT64_FORMAT, g_get_real_time()); From 6d47c443355d0693103edfeb8f2da0038549008a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 15:32:03 +0100 Subject: [PATCH 195/225] lib: Fix possible dereference in fpi_ssm_next_state() libfprint/fpi-ssm.c:244:9: warning: Access to field 'completed' results in a dereference of a null pointer (loaded from variable 'machine') BUG_ON(machine->completed); ^~~~~~~~~~~~~~~~~~ libfprint/fpi-log.h:84:6: note: expanded from macro 'BUG_ON' if (condition) { \ ^~~~~~~~~ --- libfprint/fpi-ssm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 2d679b2f..64430c16 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -241,6 +241,8 @@ void fpi_ssm_mark_failed(fpi_ssm *machine, int error) */ void fpi_ssm_next_state(fpi_ssm *machine) { + g_return_if_fail (machine != NULL); + BUG_ON(machine->completed); machine->cur_state++; if (machine->cur_state == machine->nr_states) { From 0ddd11f81b95c95d6529be79f896f01550c11529 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 15:34:43 +0100 Subject: [PATCH 196/225] lib: Fix unintialised variable warning in fp_get_next_timeout() libfprint/fpi-poll.c:398:11: warning: The left operand of '==' is a garbage value else if (timercmp(&fprint_timeout, &libusb_timeout, <)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/time.h:162:17: note: expanded from macro 'timercmp' (((a)->tv_sec == (b)->tv_sec) ? \ ~~~~~~~~~~~ ^ --- libfprint/fpi-poll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/fpi-poll.c b/libfprint/fpi-poll.c index 1a4b443d..af0c4bee 100644 --- a/libfprint/fpi-poll.c +++ b/libfprint/fpi-poll.c @@ -373,8 +373,8 @@ API_EXPORTED int fp_handle_events(void) */ API_EXPORTED int fp_get_next_timeout(struct timeval *tv) { - struct timeval fprint_timeout; - struct timeval libusb_timeout; + struct timeval fprint_timeout = { 0, 0 }; + struct timeval libusb_timeout = { 0, 0 }; int r_fprint; int r_libusb; From 21bac4301515b95a5496f8d934817d7fa7a1a2e9 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 15:37:27 +0100 Subject: [PATCH 197/225] lib: Fix memory leak on error in fp_print_data_save() libfprint/fpi-data.c:393:3: warning: Potential leak of memory pointed to by 'buf' fp_err("couldn't create storage directory"); ^~~~~~ libfprint/fpi-log.h:75:16: note: expanded from macro 'fp_err' #define fp_err g_warning ^~~~~~~~~ --- libfprint/fpi-data.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index b2609ef3..e57b8a4a 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -391,6 +391,7 @@ API_EXPORTED int fp_print_data_save(struct fp_print_data *data, r = g_mkdir_with_parents(dirpath, DIR_PERMS); if (r < 0) { fp_err("couldn't create storage directory"); + free(buf); g_free(path); g_free(dirpath); return r; From 6725b22fd474ad4efb9a05bcdd00e7289f11a60f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 15:38:47 +0100 Subject: [PATCH 198/225] lib: Fix uninitialised value in fp_print_data_load() libfprint/fpi-data.c:497:7: warning: 2nd function call argument is an uninitialized value if (!fp_dev_supports_print_data(dev, fdata)) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- libfprint/fpi-data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index e57b8a4a..e57f096b 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -483,7 +483,7 @@ API_EXPORTED int fp_print_data_load(struct fp_dev *dev, enum fp_finger finger, struct fp_print_data **data) { gchar *path; - struct fp_print_data *fdata; + struct fp_print_data *fdata = NULL; int r; if (!base_store) From 52208a66063eee81cab6ac45f55c35813b426785 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 15:43:38 +0100 Subject: [PATCH 199/225] lib: Fix baroque code in fp_discover_prints() Use GPtrArray to simplify the implementation. libfprint/fpi-data.c:777:13: warning: Access to field 'data' results in a dereference of a null pointer (loaded from variable 'elem') list[i] = elem->data; ^~~~~~~~~~ --- libfprint/fpi-data.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libfprint/fpi-data.c b/libfprint/fpi-data.c index e57f096b..0ac0f987 100644 --- a/libfprint/fpi-data.c +++ b/libfprint/fpi-data.c @@ -734,9 +734,7 @@ API_EXPORTED struct fp_dscv_print **fp_discover_prints(void) GError *err = NULL; GSList *tmplist = NULL; GSList *elem; - unsigned int tmplist_len; - struct fp_dscv_print **list; - unsigned int i; + GPtrArray *array; if (!base_store) storage_setup(); @@ -771,15 +769,17 @@ API_EXPORTED struct fp_dscv_print **fp_discover_prints(void) } g_dir_close(dir); - tmplist_len = g_slist_length(tmplist); - list = g_malloc(sizeof(*list) * (tmplist_len + 1)); - elem = tmplist; - for (i = 0; i < tmplist_len; i++, elem = g_slist_next(elem)) - list[i] = elem->data; - list[tmplist_len] = NULL; /* NULL-terminate */ + + if (tmplist == NULL) + return NULL; + + array = g_ptr_array_new(); + for (elem = tmplist; elem != NULL; elem = elem->next) + g_ptr_array_add(array, elem->data); + g_ptr_array_add(array, NULL); g_slist_free(tmplist); - return list; + return (struct fp_dscv_print **) g_ptr_array_free(array, FALSE); } /** From 25d0fa42e256ccc69212c9a828718ab1e4e1dbfc Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:03:35 +0100 Subject: [PATCH 200/225] uru4000: Fix unused value in sm_read_regs() We don't need to assign urudev if we only want the size of one of its members. libfprint/drivers/uru4000.c:554:20: warning: Value stored to 'urudev' during its initialization is never read struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- libfprint/drivers/uru4000.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 845a1862..94973858 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -545,16 +545,17 @@ static void sm_read_reg_cb(struct fp_img_dev *dev, int result, } } +#define member_size(type, member) sizeof(((type *)0)->member) + static void sm_read_regs(fpi_ssm *ssm, struct fp_img_dev *dev, uint16_t reg, uint16_t num_regs) { - struct uru4k_dev *urudev = FP_INSTANCE_DATA(FP_DEV(dev)); int r; - if (num_regs > sizeof(urudev->last_reg_rd)) { + if (num_regs > member_size(struct uru4k_dev, last_reg_rd)) { fpi_ssm_mark_failed(ssm, -EIO); return; } From 6845e400cdb37fffb715e0e1e59c72743c33a2e5 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:06:03 +0100 Subject: [PATCH 201/225] uru4000: Fix memory leak on error in dev_init() libfprint/drivers/uru4000.c:1357:3: warning: Potential leak of memory pointed to by 'urudev' fp_err("could not get encryption slot"); ^~~~~~ --- libfprint/drivers/uru4000.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index 94973858..7830c562 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -1348,6 +1348,8 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } urudev = g_malloc0(sizeof(*urudev)); + fp_dev_set_instance_data(FP_DEV(dev), urudev); + urudev->profile = &uru4k_dev_info[driver_data]; urudev->interface = iface_desc->bInterfaceNumber; @@ -1374,7 +1376,6 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) } urudev->param = PK11_ParamFromIV(urudev->cipher, NULL); - fp_dev_set_instance_data(FP_DEV(dev), urudev); fpi_imgdev_open_complete(dev, 0); out: From 9a025bde8b2c75cb057fe0f572083b94b3b00d19 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:10:10 +0100 Subject: [PATCH 202/225] upeksonly: Fix possible division by zero in upeksonly_get_deviation2() By asserting if we have a zero line width. libfprint/drivers/upeksonly.c:118:7: warning: Division by zero mean /= (ctx->line_width / 2); ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ --- libfprint/drivers/upeksonly.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index c285bdf4..7b92a427 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -112,6 +112,9 @@ static int upeksonly_get_deviation2(struct fpi_line_asmbl_ctx *ctx, { unsigned char *buf1 = line1->data, *buf2 = line2->data; int res = 0, mean = 0, i; + + g_assert (ctx->line_width > 0); + for (i = 0; i < ctx->line_width; i+= 2) mean += (int)buf1[i + 1] + (int)buf2[i]; From e7bc8e03fc0f2513da2e664c6c94e33953d13359 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:13:29 +0100 Subject: [PATCH 203/225] upeksonly: Fix typos in upeksonly_get_deviation2() comment --- libfprint/drivers/upeksonly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c index 7b92a427..99c5ffae 100644 --- a/libfprint/drivers/upeksonly.c +++ b/libfprint/drivers/upeksonly.c @@ -106,7 +106,7 @@ struct sonly_dev { }; -/* Calculade squared standand deviation of sum of two lines */ +/* Calculate squared standard deviation of sum of two lines */ static int upeksonly_get_deviation2(struct fpi_line_asmbl_ctx *ctx, GSList *line1, GSList *line2) { From cec307ce7fa1cb441b341cbae6b7527052989592 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:17:32 +0100 Subject: [PATCH 204/225] aeslib: Fix memory leak in aes_write_regv() libfprint/drivers/aeslib.c:156:1: warning: Potential leak of memory pointed to by 'wdata' } ^ --- libfprint/drivers/aeslib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libfprint/drivers/aeslib.c b/libfprint/drivers/aeslib.c index 9942f9e0..1ff3986d 100644 --- a/libfprint/drivers/aeslib.c +++ b/libfprint/drivers/aeslib.c @@ -144,8 +144,10 @@ static void continue_write_regv(struct write_regv_data *wdata) void aes_write_regv(struct fp_img_dev *dev, const struct aes_regwrite *regs, unsigned int num_regs, aes_write_regv_cb callback, void *user_data) { - struct write_regv_data *wdata = g_malloc(sizeof(*wdata)); + struct write_regv_data *wdata; + fp_dbg("write %d regs", num_regs); + wdata = g_malloc(sizeof(*wdata)); wdata->imgdev = dev; wdata->num_regs = num_regs; wdata->regs = regs; @@ -153,6 +155,8 @@ void aes_write_regv(struct fp_img_dev *dev, const struct aes_regwrite *regs, wdata->callback = callback; wdata->user_data = user_data; continue_write_regv(wdata); + + g_free(wdata); } unsigned char aes_get_pixel(struct fpi_frame_asmbl_ctx *ctx, From 551616c3ab96099f59ded50cac90461415332e4a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:19:20 +0100 Subject: [PATCH 205/225] aesx660: Fix memory leak in process_stripe_data() libfprint/drivers/aesx660.c:292:10: warning: Potential leak of memory pointed to by 'stripe' return 0; ^ --- libfprint/drivers/aesx660.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfprint/drivers/aesx660.c b/libfprint/drivers/aesx660.c index 7711eee5..852c7509 100644 --- a/libfprint/drivers/aesx660.c +++ b/libfprint/drivers/aesx660.c @@ -288,10 +288,10 @@ static int process_stripe_data(fpi_ssm *ssm, struct fp_img_dev *dev, unsigned ch aesdev->strips = g_slist_prepend(aesdev->strips, stripe); aesdev->strips_len++; return (data[AESX660_LAST_FRAME_OFFSET] & AESX660_LAST_FRAME_BIT); - } else { - return 0; } + g_free(stripe); + return 0; } static void capture_set_idle_cmd_cb(struct libusb_transfer *transfer) From b54514df6ee4aaa7f821c447cea62354c6dec28c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:24:05 +0100 Subject: [PATCH 206/225] elan: Assert on a possible division by zero in elan_process_frame_linear() libfprint/drivers/elan.c:249:26: warning: Division by zero px = (px - min) * 0xff / (max - min); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ --- libfprint/drivers/elan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 32d75349..ea84e7ca 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -243,6 +243,8 @@ static void elan_process_frame_linear(unsigned short *raw_frame, max = raw_frame[i]; } + g_assert(max != min); + unsigned short px; for (int i = 0; i < frame_size; i++) { px = raw_frame[i]; From ce856efa257587359a5c4d6b9c990dd134724a70 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:30:26 +0100 Subject: [PATCH 207/225] elan: Assert on a possible division by zero in elan_need_calibration() libfprint/drivers/elan.c:598:10: warning: Division by zero bg_mean /= frame_size; ~~~~~~~~^~~~~~~~~~~~~ --- libfprint/drivers/elan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index ea84e7ca..3020f053 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -595,6 +595,8 @@ static int elan_need_calibration(struct elan_dev *elandev) unsigned int bg_mean = 0, delta; unsigned int frame_size = elandev->frame_width * elandev->frame_height; + g_assert(frame_size != 0); + for (int i = 0; i < frame_size; i++) bg_mean += elandev->background[i]; bg_mean /= frame_size; From 69fe7a1b8c62076d276e07a3db173f273143099f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 16:56:33 +0100 Subject: [PATCH 208/225] elan: Fix "garbage value" errors in elan_cmd_cb() libfprint/drivers/elan.c:351:4: warning: 2nd function call argument is an uninitialized value dbg_buf(elandev->last_read, transfer->actual_length); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/drivers/elan.c:46:5: note: expanded from macro 'dbg_buf' fp_dbg("%02x", buf[0]); \ ^~~~~~~~~~~~~~~~~~~~~~ ../../../../../../Projects/jhbuild/libfprint/libfprint/fpi-log.h:52:16: note: expanded from macro 'fp_dbg' #define fp_dbg g_debug ^ libfprint/drivers/elan.c:351:4: warning: The left operand of '<<' is a garbage value dbg_buf(elandev->last_read, transfer->actual_length); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/drivers/elan.c:48:27: note: expanded from macro 'dbg_buf' fp_dbg("%04x", buf[0] << 8 | buf[1]); \ ~~~~~~ ^ libfprint/drivers/elan.c:351:4: warning: The left operand of '<<' is a garbage value dbg_buf(elandev->last_read, transfer->actual_length); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libfprint/drivers/elan.c:50:41: note: expanded from macro 'dbg_buf' fp_dbg("%04x... (%d bytes)", buf[0] << 8 | buf[1], len) ~~~~~~ ^ --- libfprint/drivers/elan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 3020f053..ed474b05 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -350,7 +350,7 @@ static void elan_cmd_cb(struct libusb_transfer *transfer, } else if (transfer->endpoint & LIBUSB_ENDPOINT_IN) { /* just finished receiving */ elandev->last_read = g_memdup(transfer->buffer, transfer->actual_length); - dbg_buf(elandev->last_read, transfer->actual_length); + dbg_buf(transfer->buffer, transfer->actual_length); elan_cmd_done(ssm); } else { /* just finished sending */ From 74bb899ce2a3f8965a4a005a4201c2977dc0fd56 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 17:06:36 +0100 Subject: [PATCH 209/225] mindtct: Fix "garbage value" error in dft_dir_powers() libfprint/nbis/mindtct/dft.c:212:30: warning: The left operand of '*' is a garbage value cospart += (rowsums[i] * wave->cos[i]); ~~~~~~~~~~ ^ --- libfprint/nbis/mindtct/dft.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/nbis/mindtct/dft.c b/libfprint/nbis/mindtct/dft.c index 0cc490a3..be485864 100644 --- a/libfprint/nbis/mindtct/dft.c +++ b/libfprint/nbis/mindtct/dft.c @@ -118,6 +118,7 @@ int dft_dir_powers(double **powers, unsigned char *pdata, fprintf(stderr, "ERROR : dft_dir_powers : malloc : rowsums\n"); return(-91); } + memset(rowsums, 0, dftgrids->grid_w * sizeof(int)); /* Foreach direction ... */ for(dir = 0; dir < dftgrids->ngrids; dir++){ From eaa4aa964c5e27fd4d91cef00ef6ac2e12d8a836 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 17:14:21 +0100 Subject: [PATCH 210/225] mindtct: Fix memory leaks in get_centered_contour() The first contour wasn't freed if we failed on the second contour. libfprint/nbis/mindtct/contour.c:521:14: warning: Potential leak of memory pointed to by 'half1_ex' return(ret); ^~~ libfprint/nbis/mindtct/contour.c:521:14: warning: Potential leak of memory pointed to by 'half1_ey' return(ret); ^~~ libfprint/nbis/mindtct/contour.c:521:14: warning: Potential leak of memory pointed to by 'half1_x' return(ret); ^~~ libfprint/nbis/mindtct/contour.c:521:14: warning: Potential leak of memory pointed to by 'half1_y' return(ret); ^~~ --- libfprint/nbis/mindtct/contour.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/nbis/mindtct/contour.c b/libfprint/nbis/mindtct/contour.c index 689ffafb..33610476 100644 --- a/libfprint/nbis/mindtct/contour.c +++ b/libfprint/nbis/mindtct/contour.c @@ -517,6 +517,8 @@ int get_centered_contour(int **ocontour_x, int **ocontour_y, /* If system error occurred on 2nd trace ... */ if(ret < 0){ + /* Deallocate loop's contour. */ + free_contour(half1_x, half1_y, half1_ex, half1_ey); /* Return error code. */ return(ret); } From 0add0ca9b1a9b98baad5d8eacd7d4baf82036fac Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 17:17:35 +0100 Subject: [PATCH 211/225] bozorth3: Remove unused assignments in bz_match_score() libfprint/nbis/bozorth3/bozorth3.c:704:1: warning: Value stored to 'kx' is never read kx = 0; ^ ~ libfprint/nbis/bozorth3/bozorth3.c:820:4: warning: Value stored to 'l' is never read l = 1; ^ ~ --- libfprint/nbis/bozorth3/bozorth3.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libfprint/nbis/bozorth3/bozorth3.c b/libfprint/nbis/bozorth3/bozorth3.c index 7724aea6..0a8b0ff7 100644 --- a/libfprint/nbis/bozorth3/bozorth3.c +++ b/libfprint/nbis/bozorth3/bozorth3.c @@ -701,7 +701,6 @@ tp = 0; p1 = 0; tot = 0; ftt = 0; -kx = 0; match_score = 0; for ( k = 0; k < np - 1; k++ ) { @@ -817,7 +816,6 @@ for ( k = 0; k < np - 1; k++ ) { - l = 1; t = np + 1; b = kq; From a218437cf4f7a573a4ac7050a0d2a9c98c014528 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 12 Dec 2018 17:24:45 +0100 Subject: [PATCH 212/225] mindtct: Fix uninitialised value usage in count_minutia_ridges() libfprint/nbis/mindtct/ridges.c:153:7: warning: 1st function call argument is an uninitialized value free(nbr_list); ^~~~~~~~~~~~~~ --- libfprint/nbis/mindtct/ridges.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libfprint/nbis/mindtct/ridges.c b/libfprint/nbis/mindtct/ridges.c index b5b7f2c4..f411bc5b 100644 --- a/libfprint/nbis/mindtct/ridges.c +++ b/libfprint/nbis/mindtct/ridges.c @@ -148,9 +148,11 @@ int count_minutia_ridges(const int first, MINUTIAE *minutiae, int i, ret, *nbr_list, *nbr_nridges, nnbrs; /* Find up to the maximum number of qualifying neighbors. */ + nbr_list = NULL; if((ret = find_neighbors(&nbr_list, &nnbrs, lfsparms->max_nbrs, first, minutiae))){ - free(nbr_list); + if (nbr_list != NULL) + free(nbr_list); return(ret); } From c3e996b96ccf2eeec35ec0913ed15d528e58bb06 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 11:27:00 +0100 Subject: [PATCH 213/225] mindtct: Fix memory leak in error path in shape_from_contour() libfprint/nbis/mindtct/shape.c:263:13: warning: Potential leak of memory pointed to by 'shape' fprintf(stderr, ^~~~~~~ --- libfprint/nbis/mindtct/shape.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/nbis/mindtct/shape.c b/libfprint/nbis/mindtct/shape.c index f189a998..5f9e7bcb 100644 --- a/libfprint/nbis/mindtct/shape.c +++ b/libfprint/nbis/mindtct/shape.c @@ -260,6 +260,7 @@ int shape_from_contour(SHAPE **oshape, const int *contour_x, if(row->npts >= row->alloc){ /* This should never happen becuase we have allocated */ /* based on shape bounding limits. */ + free(shape); fprintf(stderr, "ERROR : shape_from_contour : row overflow\n"); return(-260); From a53f07a8f64664e1f3337ed3abd6e4b1d202bbbe Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 11:30:06 +0100 Subject: [PATCH 214/225] mindtct: Fix memory leak in error path in gen_image_maps() Free the maps if we're not returning them. libfprint/nbis/mindtct/maps.c:176:14: warning: Potential leak of memory pointed to by 'direction_map' return(ret); ^~~ libfprint/nbis/mindtct/maps.c:195:14: warning: Potential leak of memory pointed to by 'low_contrast_map' return(ret); ^~~ libfprint/nbis/mindtct/maps.c:195:14: warning: Potential leak of memory pointed to by 'low_flow_map' return(ret); ^~~ --- libfprint/nbis/mindtct/maps.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index 419517b1..532eefa7 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -159,6 +159,9 @@ int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap, } if((ret = morph_TF_map(low_flow_map, mw, mh, lfsparms))){ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); return(ret); } @@ -173,6 +176,9 @@ int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap, /* 5. Interpolate INVALID direction blocks with their valid neighbors. */ if((ret = interpolate_direction_map(direction_map, low_contrast_map, mw, mh, lfsparms))){ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); return(ret); } @@ -192,6 +198,9 @@ int gen_image_maps(int **odmap, int **olcmap, int **olfmap, int **ohcmap, /* 9. Generate High Curvature Map from interpolated Direction Map. */ if((ret = gen_high_curve_map(&high_curve_map, direction_map, mw, mh, lfsparms))){ + free(direction_map); + free(low_contrast_map); + free(low_flow_map); return(ret); } From db607c4a6f510d6984daac2cb71fb0f248ea60f2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 11:59:24 +0100 Subject: [PATCH 215/225] mindtct: Fix memory leak in error path in find_neighbors() libfprint/nbis/mindtct/ridges.c:284:13: warning: Potential leak of memory pointed to by 'nbr_list' free(nbr_sqr_dists); ^~~~ --- libfprint/nbis/mindtct/ridges.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/nbis/mindtct/ridges.c b/libfprint/nbis/mindtct/ridges.c index f411bc5b..8f69fb24 100644 --- a/libfprint/nbis/mindtct/ridges.c +++ b/libfprint/nbis/mindtct/ridges.c @@ -281,6 +281,7 @@ int find_neighbors(int **onbr_list, int *onnbrs, const int max_nbrs, if((ret = update_nbr_dists(nbr_list, nbr_sqr_dists, &nnbrs, max_nbrs, first, second, minutiae))){ free(nbr_sqr_dists); + free(nbr_list); return(ret); } } From 8a3a974ea3d21543173b33f25d8a12040482efec Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:13:06 +0100 Subject: [PATCH 216/225] lib: Add helper for NBIS copy-paste library This will allow us to segragate helper functions that we want to use within NBIS. The first helper will be a macro checking for overflow in multiplications. --- doc/meson.build | 1 + libfprint/fp_internal.h | 1 + libfprint/meson.build | 1 + libfprint/nbis-helpers.h | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 libfprint/nbis-helpers.h diff --git a/doc/meson.build b/doc/meson.build index 83247085..37d515d8 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -6,6 +6,7 @@ private_headers = [ 'aeslib.h', 'assembling.h', 'fp_internal.h', + 'nbis-helpers.h', 'fpi-async.h', 'fpi-data.h', diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index d9857387..5c89e184 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -27,6 +27,7 @@ #include #include +#include "nbis-helpers.h" #include "fprint.h" #include "fpi-dev.h" #include "fpi-core.h" diff --git a/libfprint/meson.build b/libfprint/meson.build index ce761bab..abd00054 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -1,5 +1,6 @@ libfprint_sources = [ 'fp_internal.h', + 'nbis-helpers.h', 'drivers_api.h', 'fpi-async.c', 'fpi-async.h', diff --git a/libfprint/nbis-helpers.h b/libfprint/nbis-helpers.h new file mode 100644 index 00000000..eab861e1 --- /dev/null +++ b/libfprint/nbis-helpers.h @@ -0,0 +1,33 @@ +/* + * Helpers to use within the NBIS copy/paste library + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#define ASSERT_SIZE_MUL(a,b) \ + { \ + gsize dest; \ + g_assert(g_size_checked_mul(&dest, a, b)); \ + } + +#define ASSERT_INT_MUL(a, b) \ + { \ + gsize dest; \ + g_assert(g_size_checked_mul(&dest, a, b)); \ + g_assert(dest < G_MAXINT); \ + } From 239034714f28e775fa7c4d1c26e2f876e6fed4a2 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:19:26 +0100 Subject: [PATCH 217/225] mindtct: Check for multiplication overflow in gen_quality_map() Assert if any of the multiplications, which are then used to allocate memory, would overflow. Closes: #103 --- libfprint/nbis/mindtct/quality.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libfprint/nbis/mindtct/quality.c b/libfprint/nbis/mindtct/quality.c index db2bc5c2..94e9b63a 100644 --- a/libfprint/nbis/mindtct/quality.c +++ b/libfprint/nbis/mindtct/quality.c @@ -115,6 +115,9 @@ int gen_quality_map(int **oqmap, int *direction_map, int *low_contrast_map, int arrayPos, arrayPos2; int QualOffset; + ASSERT_SIZE_MUL(map_w, map_h); + ASSERT_SIZE_MUL(map_w * map_h, sizeof(int)); + QualMap = (int *)malloc(map_w * map_h * sizeof(int)); if(QualMap == (int *)NULL){ fprintf(stderr, "ERROR : gen_quality_map : malloc : QualMap\n"); From 4fa8c5ec478c92b1a64a114b915cc32e670ab456 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:23:48 +0100 Subject: [PATCH 218/225] mindtct: Check for multiplication overflow in gen_high_curve_map() Assert if any of the multiplications, which are then used to allocate memory, would overflow. Closes: #101 --- libfprint/nbis/mindtct/maps.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index 532eefa7..494a4de3 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -898,9 +898,11 @@ int gen_high_curve_map(int **ohcmap, int *direction_map, int bx, by; int nvalid, cmeasure, vmeasure; + ASSERT_INT_MUL(mw, mh); mapsize = mw*mh; /* Allocate High Curvature Map. */ + ASSERT_SIZE_MUL(mapsize, sizeof(int)); high_curve_map = (int *)malloc(mapsize * sizeof(int)); if(high_curve_map == (int *)NULL){ fprintf(stderr, From 5459823667cc9de14e29959ee95226006a4e0039 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:25:37 +0100 Subject: [PATCH 219/225] mindtct: Check for multiplication overflow in interpolate_direction_map() Assert if any of the multiplications, which are then used to allocate memory, would overflow. Closes: #100 --- libfprint/nbis/mindtct/maps.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index 494a4de3..d3a0b44d 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -502,6 +502,8 @@ int interpolate_direction_map(int *direction_map, int *low_contrast_map, print2log("INTERPOLATE DIRECTION MAP\n"); /* Allocate output (interpolated) Direction Map. */ + ASSERT_SIZE_MUL(mw, mh); + ASSERT_SIZE_MUL(mw * mh, sizeof(int)); omap = (int *)malloc(mw*mh*sizeof(int)); if(omap == (int *)NULL){ fprintf(stderr, From 9abc6791c7a93359eaef5f6570d7d4b12e5c9ab6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:27:12 +0100 Subject: [PATCH 220/225] mindtct: Check for multiplication overflow in gen_initial_maps() Assert if any of the multiplications, which are then used to allocate memory, would overflow. Closes: #99 --- libfprint/nbis/mindtct/maps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index d3a0b44d..12c716f8 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -272,6 +272,7 @@ int gen_initial_maps(int **odmap, int **olcmap, int **olfmap, print2log("INITIAL MAP\n"); /* Compute total number of blocks in map */ + ASSERT_INT_MUL(mw, mh); bsize = mw * mh; /* Allocate Direction Map memory */ From 34b316d7d5ff4ec6abf8ae61e27fd82d08fd21cf Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:29:20 +0100 Subject: [PATCH 221/225] mindtct: Check for multiplication overflow in allocate_contour() Assert if any of the multiplications, which are then used to allocate memory, would overflow. Closes: #97 --- libfprint/nbis/mindtct/contour.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libfprint/nbis/mindtct/contour.c b/libfprint/nbis/mindtct/contour.c index 33610476..5d802c28 100644 --- a/libfprint/nbis/mindtct/contour.c +++ b/libfprint/nbis/mindtct/contour.c @@ -107,6 +107,8 @@ int allocate_contour(int **ocontour_x, int **ocontour_y, { int *contour_x, *contour_y, *contour_ex, *contour_ey; + ASSERT_SIZE_MUL(ncontour, sizeof(int)); + /* Allocate contour's x-coord list. */ contour_x = (int *)malloc(ncontour*sizeof(int)); /* If allocation error... */ From 49e1e98914d9ebf83e85154f25718095bd21226b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:30:58 +0100 Subject: [PATCH 222/225] mindtct: Check for multiplication overflow in pixelize_map() Assert if any of the multiplications, which are then used to allocate memory, would overflow. Closes: #96 --- libfprint/nbis/mindtct/maps.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index 12c716f8..239005f0 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -742,6 +742,9 @@ int pixelize_map(int **omap, const int iw, const int ih, int *blkoffs, bw, bh, bi; int *spptr, *pptr; + ASSERT_SIZE_MUL(iw, ih); + ASSERT_SIZE_MUL(iw * ih, sizeof(int)); + pmap = (int *)malloc(iw*ih*sizeof(int)); if(pmap == (int *)NULL){ fprintf(stderr, "ERROR : pixelize_map : malloc : pmap\n"); From a1e69a0e9db59ec8b25010066ec279f1723c87e8 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:38:46 +0100 Subject: [PATCH 223/225] mindtct: Check for multiplication overflow in morph_TF_map() Assert if any of the multiplications, which are then used to allocate memory and run a loop, would overflow. Closes: #92 --- libfprint/nbis/mindtct/maps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libfprint/nbis/mindtct/maps.c b/libfprint/nbis/mindtct/maps.c index 239005f0..ac3b82da 100644 --- a/libfprint/nbis/mindtct/maps.c +++ b/libfprint/nbis/mindtct/maps.c @@ -677,6 +677,7 @@ int morph_TF_map(int *tfmap, const int mw, const int mh, int *mptr; int i; + ASSERT_INT_MUL(mw, mh); /* Convert TRUE/FALSE map into a binary byte image. */ cimage = (unsigned char *)malloc(mw*mh); From 0372ae8ba59e397565ac19520b075d15d561a2c1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 13 Dec 2018 15:40:24 +0100 Subject: [PATCH 224/225] mindtct: Check for multiplication overflow in alloc_power_stats() Assert if any of the multiplications, which are then used to allocate memory, would overflow. Closes: #91 --- libfprint/nbis/mindtct/init.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libfprint/nbis/mindtct/init.c b/libfprint/nbis/mindtct/init.c index fd65f9ca..90152283 100644 --- a/libfprint/nbis/mindtct/init.c +++ b/libfprint/nbis/mindtct/init.c @@ -693,6 +693,9 @@ int alloc_power_stats(int **owis, double **opowmaxs, int **opowmax_dirs, int *wis, *powmax_dirs; double *powmaxs, *pownorms; + ASSERT_SIZE_MUL(nstats, sizeof(int)); + ASSERT_SIZE_MUL(nstats, sizeof(double)); + /* Allocate DFT wave index vector */ wis = (int *)malloc(nstats * sizeof(int)); if(wis == (int *)NULL){ From 1abe213844b28fd8afc28eb072fd569f0f72d7f1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 14 Dec 2018 13:17:49 +0100 Subject: [PATCH 225/225] 0.99.0 --- NEWS | 20 ++++++++++++++++++++ meson.build | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 91351eea..34d6cc2e 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,26 @@ This file lists notable changes in each release. For the full history of all changes, see ChangeLog. +2018-12-14: v0.99.0 release +* Library: + - All the internal API for device driver writers is now covered by the + documentation and has been enhanced to make it easier to write drivers + - Update internal NBIS fingerprint data processing library to one that's + nearly 10 years newer + - Re-add accessor for minutia coordinates which was used in the very + old fprint_demo program, but also by our new GTK+ test program (see below) + - Fix a crash when too many minutiae were detected in a capture + +* Drivers: + - Support more devices in the Elan driver, stability improvements + +* Tools: + - Add a test GTK+ application that will eventually be used for testing + drivers without modifying the OS installed version. Note that this + application currently requires manually changing permissions of USB + devices, this will be fixed when the infrastructure exists to access + those devices without additional permissions, as a normal user. + 2018-07-15: v0.8.2 release * Drivers: - Add USB ID for TNP Nano USB Fingerprint Reader diff --git a/meson.build b/meson.build index 56291198..db5008f1 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('libfprint', [ 'c', 'cpp' ], - version: '0.8.2', + version: '0.99.0', license: 'LGPLv2.1+', default_options: [ 'buildtype=debugoptimized',