Compare commits
1 Commits
benzea/ci-
...
benzea/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
400cacf867 |
113
.ci/check-abi
@@ -1,113 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def format_title(title):
|
||||
box = {
|
||||
'tl': '╔', 'tr': '╗', 'bl': '╚', 'br': '╝', 'h': '═', 'v': '║',
|
||||
}
|
||||
hline = box['h'] * (len(title) + 2)
|
||||
|
||||
return '\n'.join([
|
||||
f"{box['tl']}{hline}{box['tr']}",
|
||||
f"{box['v']} {title} {box['v']}",
|
||||
f"{box['bl']}{hline}{box['br']}",
|
||||
])
|
||||
|
||||
|
||||
def rm_rf(path):
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def sanitize_path(name):
|
||||
return name.replace('/', '-')
|
||||
|
||||
|
||||
def get_current_revision():
|
||||
revision = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||
encoding='utf-8').strip()
|
||||
|
||||
if revision == 'HEAD':
|
||||
# This is a detached HEAD, get the commit hash
|
||||
revision = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip().decode('utf-8')
|
||||
|
||||
return revision
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def checkout_git_revision(revision):
|
||||
current_revision = get_current_revision()
|
||||
subprocess.check_call(['git', 'checkout', '-q', revision])
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
subprocess.check_call(['git', 'checkout', '-q', current_revision])
|
||||
|
||||
|
||||
def build_install(revision):
|
||||
build_dir = '_build'
|
||||
dest_dir = os.path.abspath(sanitize_path(revision))
|
||||
print(format_title(f'# Building and installing {revision} in {dest_dir}'),
|
||||
end='\n\n', flush=True)
|
||||
|
||||
with checkout_git_revision(revision):
|
||||
rm_rf(build_dir)
|
||||
rm_rf(revision)
|
||||
|
||||
subprocess.check_call(['meson', build_dir,
|
||||
'--prefix=/usr', '--libdir=lib',
|
||||
'-Dx11-examples=false', '-Ddoc=false', '-Dgtk-examples=false'])
|
||||
subprocess.check_call(['ninja', '-v', '-C', build_dir])
|
||||
subprocess.check_call(['ninja', '-v', '-C', build_dir, 'install'],
|
||||
env={'DESTDIR': dest_dir})
|
||||
|
||||
return dest_dir
|
||||
|
||||
|
||||
def compare(old_tree, new_tree):
|
||||
print(format_title(f'# Comparing the two ABIs'), end='\n\n', flush=True)
|
||||
|
||||
old_headers = os.path.join(old_tree, 'usr', 'include')
|
||||
old_lib = os.path.join(old_tree, 'usr', 'lib', 'libfprint.so')
|
||||
|
||||
new_headers = os.path.join(new_tree, 'usr', 'include')
|
||||
new_lib = os.path.join(new_tree, 'usr', 'lib', 'libfprint.so')
|
||||
|
||||
subprocess.check_call([
|
||||
'abidiff', '--headers-dir1', old_headers, '--headers-dir2', new_headers,
|
||||
'--drop-private-types', '--fail-no-debug-info', '--no-added-syms', old_lib, new_lib])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('old', help='the previous revision, considered the reference')
|
||||
parser.add_argument('new', help='the new revision, to compare to the reference')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.old == args.new:
|
||||
print("Let's not waste time comparing something to itself")
|
||||
sys.exit(0)
|
||||
|
||||
old_tree = build_install(args.old)
|
||||
new_tree = build_install(args.new)
|
||||
|
||||
try:
|
||||
compare(old_tree, new_tree)
|
||||
|
||||
except Exception:
|
||||
sys.exit(1)
|
||||
|
||||
print(f'Hurray! {args.old} and {args.new} are ABI-compatible!')
|
||||
23
.gitignore
vendored
@@ -1,3 +1,24 @@
|
||||
ltmain.sh
|
||||
missing
|
||||
stamp-h1
|
||||
libtool
|
||||
*.la
|
||||
*.lo
|
||||
*.o
|
||||
*.swp
|
||||
_build
|
||||
Makefile
|
||||
Makefile.in
|
||||
config.h*
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
config.guess
|
||||
config.log
|
||||
config.status
|
||||
config.sub
|
||||
configure
|
||||
depcomp
|
||||
install-sh
|
||||
.deps
|
||||
.libs
|
||||
compile
|
||||
ChangeLog
|
||||
|
||||
106
.gitlab-ci.yml
@@ -1,87 +1,33 @@
|
||||
include:
|
||||
- local: '.gitlab-ci/libfprint-templates.yaml'
|
||||
- project: 'wayland/ci-templates'
|
||||
ref: master
|
||||
file: '/templates/fedora.yml'
|
||||
|
||||
variables:
|
||||
extends: .libfprint_common_variables
|
||||
FDO_DISTRIBUTION_TAG: latest
|
||||
FDO_DISTRIBUTION_VERSION: rawhide
|
||||
FEDORA_IMAGE: "$CI_REGISTRY/libfprint/$CI_PROJECT_NAME/fedora/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG"
|
||||
BUNDLE: "org.freedesktop.libfprint.Demo.flatpak"
|
||||
LAST_ABI_BREAK: "056ea541ddc97f5806cffbd99a12dc87e4da3546"
|
||||
|
||||
image: fedora:rawhide
|
||||
stages:
|
||||
- check-source
|
||||
- build
|
||||
- test
|
||||
- flatpak
|
||||
|
||||
image: "$FEDORA_IMAGE"
|
||||
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 flatpak-builder
|
||||
BUNDLE: "org.freedesktop.libfprint.Demo.flatpak"
|
||||
|
||||
.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 --werror -Ddrivers=$driver . _build
|
||||
- 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 --werror -Ddrivers=all . _build
|
||||
- meson -Ddrivers=all . _build
|
||||
- ninja -C _build
|
||||
- ninja -C _build install
|
||||
|
||||
.build_template: &check_abi
|
||||
script:
|
||||
- ./.ci/check-abi ${LAST_ABI_BREAK} $(git rev-parse HEAD)
|
||||
|
||||
build:
|
||||
stage: build
|
||||
except:
|
||||
variables:
|
||||
- $CI_PIPELINE_SOURCE == "schedule"
|
||||
variables:
|
||||
driver: virtual_image
|
||||
<<: *build_one_driver
|
||||
<<: *build
|
||||
# <<: *check_abi
|
||||
|
||||
test:
|
||||
stage: test
|
||||
except:
|
||||
variables:
|
||||
- $CI_PIPELINE_SOURCE == "schedule"
|
||||
script:
|
||||
- meson --werror -Ddrivers=all -Db_coverage=true . _build
|
||||
- ninja -C _build
|
||||
- meson test -C _build --verbose --no-stdsplit
|
||||
- ninja -C _build coverage
|
||||
- cat _build/meson-logs/coverage.txt
|
||||
artifacts:
|
||||
paths:
|
||||
- _build/meson-logs
|
||||
expire_in: 1 week
|
||||
|
||||
test_valgrind:
|
||||
stage: test
|
||||
except:
|
||||
variables:
|
||||
- $CI_PIPELINE_SOURCE == "schedule"
|
||||
script:
|
||||
- meson -Ddrivers=all . _build
|
||||
- ninja -C _build
|
||||
- meson test -C _build --verbose --no-stdsplit --setup=valgrind
|
||||
|
||||
test_indent:
|
||||
stage: check-source
|
||||
except:
|
||||
variables:
|
||||
- $CI_PIPELINE_SOURCE == "schedule"
|
||||
script:
|
||||
- scripts/uncrustify.sh --check
|
||||
|
||||
.flatpak_script_template: &flatpak_script
|
||||
script:
|
||||
@@ -106,9 +52,9 @@ test_indent:
|
||||
<<: *flatpak_script
|
||||
<<: *flatpak_artifacts
|
||||
|
||||
.flatpak_master_template: &flatpak_master
|
||||
image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:3.32
|
||||
stage: flatpak
|
||||
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
|
||||
@@ -116,31 +62,3 @@ test_indent:
|
||||
FLATPAK_MODULE: "libfprint"
|
||||
DBUS_ID: "org.freedesktop.libfprint.Demo"
|
||||
<<: *flatpak
|
||||
|
||||
flatpak-auto master:
|
||||
<<: *flatpak_master
|
||||
when: always
|
||||
only:
|
||||
- tags
|
||||
- master
|
||||
|
||||
flatpak-manual master:
|
||||
<<: *flatpak_master
|
||||
when: manual
|
||||
except:
|
||||
refs:
|
||||
- tags
|
||||
- master
|
||||
variables:
|
||||
- $CI_PIPELINE_SOURCE == "schedule"
|
||||
|
||||
# CONTAINERS creation stage
|
||||
container_fedora_build:
|
||||
extends: .fdo.container-build@fedora
|
||||
only:
|
||||
variables:
|
||||
- $CI_PIPELINE_SOURCE == "schedule" && $CRON_TASK == "BUILD_CI_IMAGES"
|
||||
variables:
|
||||
GIT_STRATEGY: none # no need to pull the whole tree for rebuilding the image
|
||||
# a list of packages to install
|
||||
FDO_DISTRIBUTION_PACKAGES: $LIBFPRINT_DEPENDENCIES
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
.libfprint_common_variables:
|
||||
LIBFPRINT_DEPENDENCIES:
|
||||
doxygen
|
||||
flatpak-builder
|
||||
gcc
|
||||
gcc-c++
|
||||
gcovr
|
||||
git
|
||||
glib2-devel
|
||||
glibc-devel
|
||||
gobject-introspection-devel
|
||||
gtk-doc
|
||||
gtk3-devel
|
||||
libabigail
|
||||
libgusb-devel
|
||||
libX11-devel
|
||||
libXv-devel
|
||||
meson
|
||||
nss-devel
|
||||
pixman-devel
|
||||
python3-cairo
|
||||
python3-gobject
|
||||
systemd
|
||||
umockdev
|
||||
uncrustify
|
||||
valgrind
|
||||
25
HACKING.md
@@ -3,29 +3,8 @@
|
||||
## GLib
|
||||
|
||||
Although the library uses GLib internally, libfprint is designed to provide
|
||||
a completely neutral interface to its application users. So, the public
|
||||
APIs should never return GLib data types.
|
||||
|
||||
## License clarification
|
||||
|
||||
Although this library's license could allow for shims that hook up into
|
||||
proprietary blobs to add driver support for some unsupported devices, the
|
||||
intent of the original authors, and of current maintainers of the library,
|
||||
was for this license to allow _integration into_ proprietary stacks, not
|
||||
_integration of_ proprietary code in the library.
|
||||
|
||||
As such, no code to integrate proprietary drivers will be accepted in libfprint
|
||||
upstream. Proprietary drivers would make it impossible to debug problems in
|
||||
libfprint, as we wouldn't know what the proprietary driver does behind the
|
||||
library's back. The closed source nature of drivers is usually used to hide
|
||||
parts of the hardware setup, such as encryption keys, or protocols, in order
|
||||
to protect the hardware's integrity. Unfortunately, this is only [security through
|
||||
obscurity](https://en.wikipedia.org/wiki/Security_through_obscurity).
|
||||
|
||||
We however encourage potential contributors to take advantage of libfprint's
|
||||
source availability to create such shims to make it easier to reverse-engineer
|
||||
proprietary drivers in order to create new free software drivers, to the extent
|
||||
permitted by local laws.
|
||||
a completely neutral interface to it's application users. So, the public
|
||||
APIs should never return GLib data types or anything like that.
|
||||
|
||||
## Two-faced-ness
|
||||
|
||||
|
||||
83
NEWS
@@ -1,89 +1,6 @@
|
||||
This file lists notable changes in each release. For the full history of all
|
||||
changes, see ChangeLog.
|
||||
|
||||
2019-11-20: v1.90.1 release
|
||||
|
||||
This release fixes a lot of the regressions introduced in 1.90.0. Please note
|
||||
that both the driver and external APIs have changed, as both the verify and
|
||||
the identify functions now have early reporting mechanisms.
|
||||
The soname for the library, as well as a number of file locations have also
|
||||
changed. While this allows installation in parallel with the 1.0 version of
|
||||
libfprint, we recommend installing only one, and migrating from version 1.0 to
|
||||
version 2.0 alongside its main consumer (fprintd).
|
||||
|
||||
Only major changes are listed below. A lot of other cleanup work and small
|
||||
fixes have also been merged.
|
||||
|
||||
* Library:
|
||||
- Add support to run tests in gdb/valgrind
|
||||
- Allow testing on all architectures
|
||||
- Avoid image device AWAIT_FINGER_ON to deactivate state transitions
|
||||
- Fix verify/identify error propagation to library user
|
||||
- Correctly read image device information from class data
|
||||
- Continue enroll after an image driver reported a retry error
|
||||
- Change external API to allow reporting match results early
|
||||
- A lot of new unit tests and integration tests have been added
|
||||
|
||||
* Drivers API
|
||||
- Support variadic arguments in error functions
|
||||
- Various re-definitions of ownership handling
|
||||
- Add convenience API to change state after a timeout
|
||||
- Add unit tests for all the drivers API
|
||||
|
||||
* Drivers:
|
||||
- elan: Ensure correct deactivation of device
|
||||
- uru4000: Fix IRQ handler registration and internal state handling
|
||||
- uru4000: Fix control transfer request type
|
||||
- synaptics: Ensure errors are only reported after finger removal
|
||||
|
||||
2019-11-20: v1.90.0 release
|
||||
|
||||
This release updates the core of the library to use GLib routines and Gio
|
||||
style APIs. While the API both for library users remain similar in most
|
||||
ways, there are some changes and all users will need to be ported.
|
||||
|
||||
A large motivation for the in-depth changes was the requirement to add
|
||||
new API to support sensors that store the prints on the sensor. This
|
||||
support is already used by the new synaptics driver, which will support
|
||||
the current generation of the Prometheus MIS (match-in-sensor) chipset
|
||||
by Synaptics (USB ID 06cb:00bd).
|
||||
|
||||
The current codebase is considered stable at this point. However, due to
|
||||
the lack of wider testing it is only released as a 1.90.0 release which
|
||||
can be considered a beta-release for 2.0.
|
||||
|
||||
With the rewrite, it is now also possible to support devices that are not
|
||||
connected through USB (e.g. I2C). Another major improvement is that the
|
||||
library has now a test suite, testing both the library core and allowing
|
||||
tests of the drivers using umockdev.
|
||||
|
||||
2019-08-08: v1.0 release
|
||||
* Library:
|
||||
- Add guards to the public API and require GLib 2.50
|
||||
- Deprecate print storage API
|
||||
- Better documentation for fp_discover_devs()
|
||||
- Remove unused internal fpi_timeout_cancel_for_dev()
|
||||
- Remove state from fp_img_driver activate handler
|
||||
- Bug fixes related to restarting a failed verification immediately
|
||||
|
||||
* Drivers:
|
||||
- The Elan driver received a lot of bug fixes including a fix for a
|
||||
hang when verifying prints with fprintd, quirks for some devices,
|
||||
a memory leak fix and support for 04f3:0c42
|
||||
- Fix a probable crash in all the AES drivers
|
||||
- Add support for Lenovo Preferred Pro Keyboard (KUF1256) to vfs5011
|
||||
- Prevent hang during enroll process in etes603 driver
|
||||
- Fix possible integer overflow in uru4000
|
||||
- Work-around SELinux AVC warnings when uru4000 driver starts
|
||||
- Remove long-unmaintained and broken fdu2000 driver
|
||||
|
||||
* Tools/Examples:
|
||||
- Fix examples not working due to an overly strict check
|
||||
- Fix crash in GTK demo when there's no supported devices
|
||||
- Disable GTK demo until we have a USB Flatpak portal
|
||||
- Remove sleep() in enroll example which caused a crash in some drivers
|
||||
- Add a simple storage implementation example
|
||||
|
||||
2018-12-14: v0.99.0 release
|
||||
* Library:
|
||||
- All the internal API for device driver writers is now covered by the
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
This project and its community follow the [Freedesktop.org code of conduct]
|
||||
|
||||
[Freedesktop.org code of conduct]: https://www.freedesktop.org/wiki/CodeOfConduct/
|
||||
@@ -22,11 +22,11 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
struct _LibfprintDemo
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (LibfprintDemo, libfprint_demo, FP, DEMO, GtkApplication)
|
||||
#include "loop.h"
|
||||
|
||||
typedef GtkApplication LibfprintDemo;
|
||||
typedef GtkApplicationClass LibfprintDemoClass;
|
||||
|
||||
G_DEFINE_TYPE (LibfprintDemo, libfprint_demo, GTK_TYPE_APPLICATION)
|
||||
|
||||
typedef enum {
|
||||
@@ -35,28 +35,25 @@ typedef enum {
|
||||
IMAGE_DISPLAY_BINARY = 1 << 1
|
||||
} ImageDisplayFlags;
|
||||
|
||||
struct _LibfprintDemoWindow
|
||||
{
|
||||
typedef struct {
|
||||
GtkApplicationWindow parent_instance;
|
||||
|
||||
GtkWidget *header_bar;
|
||||
GtkWidget *mode_stack;
|
||||
GtkWidget *capture_button;
|
||||
GtkWidget *cancel_button;
|
||||
GtkWidget *capture_image;
|
||||
GtkWidget *spinner;
|
||||
GtkWidget *instructions;
|
||||
|
||||
GCancellable *cancellable;
|
||||
struct fp_dscv_dev *ddev;
|
||||
struct fp_dev *dev;
|
||||
|
||||
gboolean opened;
|
||||
FpDevice *dev;
|
||||
|
||||
FpImage *img;
|
||||
struct fp_img *img;
|
||||
ImageDisplayFlags img_flags;
|
||||
};
|
||||
} LibfprintDemoWindow;
|
||||
|
||||
typedef GtkApplicationWindowClass LibfprintDemoWindowClass;
|
||||
|
||||
G_DECLARE_FINAL_TYPE (LibfprintDemoWindow, libfprint_demo_window, FP, DEMO_WINDOW, GtkApplicationWindow)
|
||||
G_DEFINE_TYPE (LibfprintDemoWindow, libfprint_demo_window, GTK_TYPE_APPLICATION_WINDOW)
|
||||
|
||||
typedef enum {
|
||||
@@ -64,26 +61,33 @@ typedef enum {
|
||||
NOIMAGING_MODE,
|
||||
CAPTURE_MODE,
|
||||
SPINNER_MODE,
|
||||
ERROR_MODE,
|
||||
RETRY_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 (const guint8 *imgdata,
|
||||
img_to_rgbdata (struct fp_img *img,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
int size = width * height;
|
||||
guint8 *rgbdata = g_malloc (size * 3);
|
||||
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++)
|
||||
{
|
||||
guint8 pixel = imgdata[i];
|
||||
for (i = 0; i < size; i++) {
|
||||
unsigned char pixel = imgdata[i];
|
||||
|
||||
rgbdata[rgb_offset++] = pixel;
|
||||
rgbdata[rgb_offset++] = pixel;
|
||||
@@ -97,19 +101,18 @@ static void
|
||||
plot_minutiae (unsigned char *rgbdata,
|
||||
int width,
|
||||
int height,
|
||||
GPtrArray *minutiae)
|
||||
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 < minutiae->len; i++)
|
||||
{
|
||||
struct fp_minutia *min = g_ptr_array_index (minutiae, i);
|
||||
for (i = 0; i < nr_minutiae; i++) {
|
||||
struct fp_minutia *min = minlist[i];
|
||||
int x, y;
|
||||
size_t pixel_offset;
|
||||
|
||||
@@ -133,38 +136,36 @@ plot_minutiae (unsigned char *rgbdata,
|
||||
}
|
||||
|
||||
static GdkPixbuf *
|
||||
img_to_pixbuf (FpImage *img,
|
||||
img_to_pixbuf (struct fp_img *img,
|
||||
ImageDisplayFlags flags)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
const guint8 *data;
|
||||
unsigned char *rgbdata;
|
||||
|
||||
width = fp_image_get_width (img);
|
||||
height = fp_image_get_height (img);
|
||||
width = fp_img_get_width (img);
|
||||
height = fp_img_get_height (img);
|
||||
|
||||
if (flags & IMAGE_DISPLAY_BINARY)
|
||||
data = fp_image_get_binarized (img, NULL);
|
||||
else
|
||||
data = fp_image_get_data (img, NULL);
|
||||
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 (!data)
|
||||
return NULL;
|
||||
if (flags & IMAGE_DISPLAY_MINUTIAE) {
|
||||
struct fp_minutia **minlist;
|
||||
int nr_minutiae;
|
||||
|
||||
rgbdata = img_to_rgbdata (data, width, height);
|
||||
|
||||
if (flags & IMAGE_DISPLAY_MINUTIAE)
|
||||
{
|
||||
GPtrArray *minutiae;
|
||||
|
||||
minutiae = fp_image_get_minutiae (img);
|
||||
plot_minutiae (rgbdata, width, height, 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, (GdkPixbufDestroyNotify) g_free,
|
||||
width * 3, pixbuf_destroy,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@@ -173,8 +174,7 @@ update_image (LibfprintDemoWindow *win)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
|
||||
if (win->img == NULL)
|
||||
{
|
||||
if (win->img == NULL) {
|
||||
gtk_image_clear (GTK_IMAGE (win->capture_image));
|
||||
return;
|
||||
}
|
||||
@@ -201,21 +201,20 @@ libfprint_demo_set_spinner_label (LibfprintDemoWindow *win,
|
||||
static void
|
||||
libfprint_demo_set_capture_label (LibfprintDemoWindow *win)
|
||||
{
|
||||
FpScanType scan_type;
|
||||
struct fp_driver *drv;
|
||||
enum fp_scan_type scan_type;
|
||||
const char *message;
|
||||
|
||||
scan_type = fp_device_get_scan_type (win->dev);
|
||||
drv = fp_dscv_dev_get_driver (win->ddev);
|
||||
scan_type = fp_driver_get_scan_type(drv);
|
||||
|
||||
switch (scan_type)
|
||||
{
|
||||
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 ();
|
||||
}
|
||||
@@ -224,58 +223,46 @@ libfprint_demo_set_capture_label (LibfprintDemoWindow *win)
|
||||
}
|
||||
|
||||
static void
|
||||
dev_capture_start_cb (FpDevice *dev,
|
||||
GAsyncResult *res,
|
||||
dev_capture_start_cb (struct fp_dev *dev,
|
||||
int result,
|
||||
struct fp_img *img,
|
||||
void *user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
LibfprintDemoWindow *win = user_data;
|
||||
FpImage *image = NULL;
|
||||
|
||||
g_clear_object (&win->cancellable);
|
||||
|
||||
image = fp_device_capture_finish (dev, res, &error);
|
||||
if (!image)
|
||||
{
|
||||
g_warning ("Error capturing data: %s", error->message);
|
||||
if (error->domain == FP_DEVICE_RETRY ||
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
libfprint_demo_set_mode (win, RETRY_MODE);
|
||||
else
|
||||
if (result < 0) {
|
||||
libfprint_demo_set_mode (win, ERROR_MODE);
|
||||
return;
|
||||
}
|
||||
|
||||
g_clear_object (&win->img);
|
||||
win->img = image;
|
||||
fp_async_capture_stop (dev, NULL, NULL);
|
||||
|
||||
win->img = img;
|
||||
update_image (win);
|
||||
|
||||
libfprint_demo_set_mode (win, CAPTURE_MODE);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_start_capture (LibfprintDemoWindow *win)
|
||||
{
|
||||
libfprint_demo_set_capture_label (win);
|
||||
|
||||
fp_device_capture (win->dev, TRUE, win->cancellable, (GAsyncReadyCallback) dev_capture_start_cb, win);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_open_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||
dev_open_cb (struct fp_dev *dev, int status, void *user_data)
|
||||
{
|
||||
LibfprintDemoWindow *win = user_data;
|
||||
int r;
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!fp_device_open_finish (dev, res, &error))
|
||||
{
|
||||
g_warning ("Failed to open device: %s", error->message);
|
||||
if (status < 0) {
|
||||
libfprint_demo_set_mode (win, ERROR_MODE);
|
||||
return;
|
||||
}
|
||||
|
||||
dev_start_capture (win);
|
||||
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
|
||||
@@ -284,36 +271,24 @@ activate_capture (GSimpleAction *action,
|
||||
gpointer user_data)
|
||||
{
|
||||
LibfprintDemoWindow *win = user_data;
|
||||
int r;
|
||||
|
||||
libfprint_demo_set_mode (win, SPINNER_MODE);
|
||||
g_clear_pointer (&win->img, g_object_unref);
|
||||
g_clear_pointer (&win->img, fp_img_free);
|
||||
|
||||
g_clear_object (&win->cancellable);
|
||||
win->cancellable = g_cancellable_new ();
|
||||
|
||||
if (win->opened)
|
||||
{
|
||||
dev_start_capture (win);
|
||||
if (win->dev != NULL) {
|
||||
dev_open_cb (win->dev, 0, user_data);
|
||||
return;
|
||||
}
|
||||
|
||||
libfprint_demo_set_spinner_label (win, "Opening fingerprint reader");
|
||||
|
||||
win->opened = TRUE;
|
||||
fp_device_open (win->dev, win->cancellable, (GAsyncReadyCallback) dev_open_cb, user_data);
|
||||
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
|
||||
cancel_capture (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
LibfprintDemoWindow *win = user_data;
|
||||
|
||||
g_debug ("cancelling %p", win->cancellable);
|
||||
|
||||
if (win->cancellable)
|
||||
g_cancellable_cancel (win->cancellable);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -404,8 +379,7 @@ static GActionEntry app_entries[] = {
|
||||
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 },
|
||||
{ "cancel", cancel_capture, NULL, NULL, NULL }
|
||||
{ "capture", activate_capture, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -423,57 +397,41 @@ static void
|
||||
libfprint_demo_set_mode (LibfprintDemoWindow *win,
|
||||
LibfprintDemoMode mode)
|
||||
{
|
||||
struct fp_driver *drv;
|
||||
char *title;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
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_widget_set_sensitive (win->cancel_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_widget_set_sensitive (win->cancel_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);
|
||||
gtk_widget_set_sensitive (win->cancel_button, FALSE);
|
||||
|
||||
title = g_strdup_printf ("%s Test", fp_device_get_name (win->dev));
|
||||
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_widget_set_sensitive (win->cancel_button, TRUE);
|
||||
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_widget_set_sensitive (win->cancel_button, FALSE);
|
||||
gtk_spinner_stop (GTK_SPINNER (win->spinner));
|
||||
break;
|
||||
|
||||
case RETRY_MODE:
|
||||
gtk_stack_set_visible_child_name (GTK_STACK (win->mode_stack), "retry-mode");
|
||||
gtk_widget_set_sensitive (win->capture_button, TRUE);
|
||||
gtk_widget_set_sensitive (win->cancel_button, FALSE);
|
||||
gtk_spinner_stop (GTK_SPINNER (win->spinner));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
@@ -498,8 +456,7 @@ libfprint_demo_class_init (LibfprintDemoClass *class)
|
||||
static void
|
||||
libfprint_demo_window_init (LibfprintDemoWindow *window)
|
||||
{
|
||||
FpContext *ctx;
|
||||
GPtrArray *devices;
|
||||
struct fp_dscv_dev **discovered_devs;
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (window));
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
|
||||
@@ -508,29 +465,32 @@ libfprint_demo_window_init (LibfprintDemoWindow *window)
|
||||
win_entries, G_N_ELEMENTS (win_entries),
|
||||
window);
|
||||
|
||||
ctx = fp_context_new ();
|
||||
if (fp_init () < 0) {
|
||||
libfprint_demo_set_mode (window, ERROR_MODE);
|
||||
return;
|
||||
}
|
||||
|
||||
devices = fp_context_get_devices (ctx);
|
||||
if (!devices)
|
||||
{
|
||||
setup_pollfds ();
|
||||
|
||||
discovered_devs = fp_discover_devs();
|
||||
if (!discovered_devs) {
|
||||
libfprint_demo_set_mode (window, ERROR_MODE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Empty list? */
|
||||
if (devices->len == 0)
|
||||
{
|
||||
if (discovered_devs[0] == NULL) {
|
||||
fp_dscv_devs_free (discovered_devs);
|
||||
libfprint_demo_set_mode (window, EMPTY_MODE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fp_device_supports_capture (g_ptr_array_index (devices, 0)))
|
||||
{
|
||||
if (!fp_driver_supports_imaging(fp_dscv_dev_get_driver(discovered_devs[0]))) {
|
||||
libfprint_demo_set_mode (window, NOIMAGING_MODE);
|
||||
return;
|
||||
}
|
||||
|
||||
window->dev = g_object_ref (g_ptr_array_index (devices, 0));
|
||||
window->ddev = discovered_devs[0];
|
||||
libfprint_demo_set_mode (window, CAPTURE_MODE);
|
||||
}
|
||||
|
||||
@@ -543,7 +503,6 @@ libfprint_demo_window_class_init (LibfprintDemoWindowClass *class)
|
||||
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, cancel_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);
|
||||
@@ -551,8 +510,7 @@ libfprint_demo_window_class_init (LibfprintDemoWindowClass *class)
|
||||
//FIXME setup dispose
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
GtkApplication *app;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.0 -->
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<template class="LibfprintDemoWindow" parent="GtkApplicationWindow">
|
||||
@@ -7,6 +7,59 @@
|
||||
<property name="default_width">500</property>
|
||||
<property name="default_height">400</property>
|
||||
<property name="show_menubar">False</property>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar" id="header_bar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title">Fingerprint Reader Test</property>
|
||||
<property name="subtitle">Capture test</property>
|
||||
<property name="show_close_button">True</property>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="option-menu-button">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="menu-model">options-menu</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">open-menu-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">end</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="capture_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="action_name">win.capture</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="capture_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_Capture</property>
|
||||
<property name="use_underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="text-button"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">end</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStack" id="mode_stack">
|
||||
<property name="visible">True</property>
|
||||
@@ -51,6 +104,9 @@
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
@@ -60,6 +116,70 @@
|
||||
<property name="title">spinner-mode</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="empty-mode">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="row_spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_bottom">9</property>
|
||||
<property name="pixel_size">192</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">9</property>
|
||||
<property name="label" translatable="yes"><b><span size="large">No fingerprint readers found</span></b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Please connect a supported fingerprint reader and start the application again</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">empty-mode</property>
|
||||
<property name="title">empty-mode</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAspectFrame" id="capture-mode">
|
||||
<property name="visible">True</property>
|
||||
@@ -81,7 +201,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="retry-mode">
|
||||
<object class="GtkGrid" id="error-mode">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
@@ -108,7 +228,7 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">9</property>
|
||||
<property name="label" translatable="yes"><b><span size="large">Device reported a recoverable error. Please retry!</span></b></property>
|
||||
<property name="label" translatable="yes"><b><span size="large">An error occurred trying to access the fingerprint reader</span></b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
@@ -116,6 +236,20 @@
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Please consult the debugging output before restarting the application</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
@@ -127,8 +261,8 @@
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">retry-mode</property>
|
||||
<property name="title">retry-mode</property>
|
||||
<property name="name">error-mode</property>
|
||||
<property name="title">error-mode</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
@@ -198,216 +332,6 @@
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="error-mode">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="row_spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_bottom">9</property>
|
||||
<property name="pixel_size">192</property>
|
||||
<property name="icon_name">dialog-warning-symbolic</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">9</property>
|
||||
<property name="label" translatable="yes"><b><span size="large">An error occurred trying to access the fingerprint reader</span></b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Please consult the debugging output before restarting the application</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">error-mode</property>
|
||||
<property name="title">error-mode</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="empty-mode">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="row_spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_bottom">9</property>
|
||||
<property name="pixel_size">192</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">9</property>
|
||||
<property name="label" translatable="yes"><b><span size="large">No fingerprint readers found</span></b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Please connect a supported fingerprint reader and start the application again</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">empty-mode</property>
|
||||
<property name="title">empty-mode</property>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar" id="header_bar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title">Fingerprint Reader Test</property>
|
||||
<property name="subtitle">Capture test</property>
|
||||
<property name="show_close_button">True</property>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="option-menu-button">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="menu-model">options-menu</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">open-menu-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">end</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="cancel_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="action_name">win.cancel</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="cancel_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="use_underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="text-button"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="capture_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="action_name">win.capture</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="capture_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_Capture</property>
|
||||
<property name="use_underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="text-button"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
|
||||
196
demo/loop.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* fprint D-Bus daemon
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* 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 <glib.h>
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
#include <poll.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
27
demo/loop.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
gtk_test_resources = gnome.compile_resources('gtk-test-resources',
|
||||
'gtk-libfprint-test.gresource.xml',
|
||||
gtk_test_resources = gnome.compile_resources('gtk-test-resources', 'gtk-libfprint-test.gresource.xml',
|
||||
source_dir : '.',
|
||||
c_name : 'gtk_test')
|
||||
|
||||
@@ -8,12 +7,13 @@ bindir = join_paths(prefix, get_option('bindir'))
|
||||
datadir = join_paths(prefix, get_option('datadir'))
|
||||
|
||||
executable('gtk-libfprint-test',
|
||||
[ 'gtk-libfprint-test.c', gtk_test_resources ],
|
||||
dependencies: [
|
||||
gtk_dep,
|
||||
libfprint_dep,
|
||||
[ 'gtk-libfprint-test.c', 'loop.c', 'loop.h', gtk_test_resources ],
|
||||
dependencies: [ libfprint_dep, gtk_dep ],
|
||||
include_directories: [
|
||||
root_inc,
|
||||
],
|
||||
c_args: '-DPACKAGE_VERSION="' + meson.project_version() + '"',
|
||||
c_args: [ common_cflags,
|
||||
'-DPACKAGE_VERSION="' + meson.project_version() + '"' ],
|
||||
install: true,
|
||||
install_dir: bindir)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"app-id": "org.freedesktop.libfprint.Demo",
|
||||
"runtime": "org.gnome.Platform",
|
||||
"runtime-version": "3.32",
|
||||
"runtime-version": "master",
|
||||
"sdk": "org.gnome.Sdk",
|
||||
"command": "gtk-libfprint-test",
|
||||
"finish-args": [
|
||||
@@ -32,30 +32,18 @@
|
||||
}
|
||||
],
|
||||
"post-install": [
|
||||
"install -Dm644 COPYING /app/share/licenses/libgusb/COPYING"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "libgusb",
|
||||
"buildsystem": "meson",
|
||||
"config-opts": [ "-Dtests=false", "-Dvapi=false", "-Ddocs=false", "-Dintrospection=false" ],
|
||||
"sources": [
|
||||
{
|
||||
"type": "archive",
|
||||
"url": "https://github.com/hughsie/libgusb/archive/0.3.0.tar.gz",
|
||||
"sha256": "b36310f8405d5fd68f6caf4a829f7ab4c627b38fd3d02a139d411fce0f3a49f1"
|
||||
}
|
||||
"install -Dm644 COPYING /app/share/licenses/libusb/COPYING"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "libfprint",
|
||||
"buildsystem": "meson",
|
||||
"config-opts": [ "-Dudev_rules=false", "-Dx11-examples=false", "-Dgtk-examples=true", "-Ddrivers=all" ],
|
||||
"config-opts": [ "-Dudev_rules=false", "-Dx11-examples=false", "-Dgtk-examples=true" ],
|
||||
"sources": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://gitlab.freedesktop.org/libfprint/libfprint.git",
|
||||
"branch": "wip/benzea/v2"
|
||||
"branch": "wip/hadess/gtk-example"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -60,18 +60,21 @@
|
||||
<para>
|
||||
In summary, libfprint represents fingerprints in several internal structures
|
||||
and each representation will offer you a way of determining the
|
||||
<ulink url="#driver">driver</ulink> and <ulink url="#device-id">device ID</ulink> of the print in
|
||||
<ulink url="#driver_id">driver ID</ulink> and <ulink url="#device-types">devtype</ulink> of the print in
|
||||
question. Prints are only compatible if the driver ID <emphasis role="strong">and</emphasis> devtypes
|
||||
match. libfprint does offer you some "is this print compatible?" helper
|
||||
functions, so you don't have to worry about these details too much.
|
||||
</para>
|
||||
</refsect2>
|
||||
|
||||
<refsect2 id="driver">
|
||||
<title>Driver</title>
|
||||
<refsect2 id="driver_id">
|
||||
<title>Driver IDs</title>
|
||||
|
||||
<para>
|
||||
Each driver is assigned a unique string identifier by the project maintainer.
|
||||
Each driver is assigned a unique ID by the project maintainer. These
|
||||
assignments are
|
||||
<ulink url="https://gitlab.freedesktop.org/libfprint/libfprint/blob/master/libfprint/drivers/driver_ids.h">
|
||||
documented in the sources</ulink> and will never change.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -86,23 +89,22 @@
|
||||
</para>
|
||||
</refsect2>
|
||||
|
||||
<refsect2 id="device-id">
|
||||
<title>Device ID</title>
|
||||
<refsect2 id="device-types">
|
||||
<title>Device types</title>
|
||||
|
||||
<para>
|
||||
Internally, the behind a device assigns a string identifier to the device
|
||||
This cannot be used as a unique ID for a specific device as many devices
|
||||
under the same range may share the same devtype. The device ID may even
|
||||
be the same string in all cases. It is guaranteed to have a non-zero length
|
||||
and be a valid file name. It defaults to "0".
|
||||
Internally, the <ulink url="libfprint-Driver-operations.html#libfprint-Driver-operations.description">driver</ulink> behind a device assigns a 32-bit
|
||||
<emphasis>devtype</emphasis> identifier to the device. This cannot be used as a unique
|
||||
ID for a specific device as many devices under the same range may share
|
||||
the same devtype. The devtype may even be 0 in all cases.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The only reason you may be interested in retrieving the device ID for a
|
||||
The only reason you may be interested in retrieving the devtype for a
|
||||
device is for the purpose of checking if some print data is compatible
|
||||
with a device. libfprint uses the device ID as one way of checking that the
|
||||
with a device. libfprint uses the devtype as one way of checking that the
|
||||
print you are verifying is compatible with the device in question - the
|
||||
device ID must be equal. This effectively allows drivers to support more
|
||||
devtypes must be equal. This effectively allows drivers to support more
|
||||
than one type of device where the data from each one is not compatible with
|
||||
the other. Note that libfprint does provide you with helper functions to
|
||||
determine whether a print is compatible with a device, so under most
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
<para>
|
||||
Usually the first thing you want to do is determine which fingerprint
|
||||
devices are present. This is done using the <ulink url="fp-context.html">FpContext</ulink> object.
|
||||
devices are present. This is done through <ulink url="libfprint-Device-discovery.html">device discovery</ulink>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Once you have found a device you would like to operate, you should open it.
|
||||
Refer to <ulink url="fp-context.html">device operations</ulink>. This section also details enrollment,
|
||||
Refer to <ulink url="libfprint-Devices-operations.html">device operations</ulink>. This section also details enrollment,
|
||||
image capture, and verification.
|
||||
</para>
|
||||
|
||||
|
||||
@@ -25,43 +25,41 @@
|
||||
|
||||
<part>
|
||||
<title>Library API Documentation</title>
|
||||
<xi:include href="xml/fp-context.xml"/>
|
||||
<xi:include href="xml/fp-device.xml"/>
|
||||
<xi:include href="xml/fp-image-device.xml"/>
|
||||
<xi:include href="xml/fp-print.xml"/>
|
||||
<xi:include href="xml/fp-image.xml"/>
|
||||
<xi:include href="xml/events.xml"/>
|
||||
<xi:include href="xml/discovery.xml"/>
|
||||
|
||||
<xi:include href="xml/drv.xml"/>
|
||||
<xi:include href="xml/dev.xml"/>
|
||||
<xi:include href="xml/print_data.xml"/>
|
||||
<!-- FIXME https://bugs.freedesktop.org/show_bug.cgi?id=106550 -->
|
||||
<xi:include href="xml/dscv_print.xml"/>
|
||||
<xi:include href="xml/img.xml"/>
|
||||
</part>
|
||||
|
||||
<part>
|
||||
<title>Writing Drivers</title>
|
||||
<chapter id="driver-dev">
|
||||
<title>Device methods for drivers</title>
|
||||
<xi:include href="xml/fpi-device.xml"/>
|
||||
<xi:include href="xml/fpi-image-device.xml"/>
|
||||
<chapter id="driver-helpers">
|
||||
<title>Logging, and async machinery</title>
|
||||
<xi:include href="xml/fpi-log.xml"/>
|
||||
<xi:include href="xml/fpi-ssm.xml"/>
|
||||
<xi:include href="xml/fpi-poll.xml"/>
|
||||
</chapter>
|
||||
|
||||
<chapter id="driver-helpers">
|
||||
<title>USB and State Machine helpers</title>
|
||||
<xi:include href="xml/fpi-usb-transfer.xml"/>
|
||||
<xi:include href="xml/fpi-ssm.xml"/>
|
||||
<xi:include href="xml/fpi-log.xml"/>
|
||||
<chapter id="driver-dev">
|
||||
<title>Device and driver structures</title>
|
||||
<xi:include href="xml/fpi-dev.xml"/>
|
||||
<xi:include href="xml/fpi-dev-img.xml"/>
|
||||
<xi:include href="xml/fpi-core.xml"/>
|
||||
<xi:include href="xml/fpi-core-img.xml"/>
|
||||
</chapter>
|
||||
|
||||
<chapter id="driver-img">
|
||||
<title>Image manipulation</title>
|
||||
<xi:include href="xml/fpi-image.xml"/>
|
||||
<xi:include href="xml/fpi-img.xml"/>
|
||||
<xi:include href="xml/fpi-assembling.xml"/>
|
||||
</chapter>
|
||||
|
||||
<chapter id="driver-print">
|
||||
<title>Print handling</title>
|
||||
<xi:include href="xml/fpi-print.xml"/>
|
||||
</chapter>
|
||||
|
||||
<chapter id="driver-misc">
|
||||
<title>Listing drivers</title>
|
||||
<xi:include href="xml/fpi-context.xml"/>
|
||||
</chapter>
|
||||
<xi:include href="xml/fpi-usb.xml"/>
|
||||
</part>
|
||||
|
||||
<index id="api-index">
|
||||
|
||||
@@ -1,194 +1,146 @@
|
||||
<SECTION>
|
||||
<FILE>drivers_api</FILE>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>events</FILE>
|
||||
<TITLE>Initialisation and events handling</TITLE>
|
||||
LIBFPRINT_DEPRECATED
|
||||
fp_set_debug
|
||||
fp_init
|
||||
fp_exit
|
||||
fp_pollfd
|
||||
fp_handle_events_timeout
|
||||
fp_handle_events
|
||||
fp_get_next_timeout
|
||||
fp_get_pollfds
|
||||
fp_pollfd_added_cb
|
||||
fp_pollfd_removed_cb
|
||||
fp_set_pollfd_notifiers
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fp-context</FILE>
|
||||
<TITLE>FpContext</TITLE>
|
||||
FP_TYPE_CONTEXT
|
||||
FpContextClass
|
||||
fp_context_new
|
||||
fp_context_enumerate
|
||||
fp_context_get_devices
|
||||
FpContext
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>discovery</FILE>
|
||||
<TITLE>Device discovery</TITLE>
|
||||
fp_dscv_dev
|
||||
fp_discover_devs
|
||||
fp_dscv_devs_free
|
||||
fp_dscv_dev_get_driver
|
||||
fp_dscv_dev_get_devtype
|
||||
fp_dscv_dev_get_driver_id
|
||||
fp_dscv_dev_supports_print_data
|
||||
fp_dscv_dev_supports_dscv_print
|
||||
fp_dscv_dev_for_print_data
|
||||
fp_dscv_dev_for_dscv_print
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fp-device</FILE>
|
||||
FP_TYPE_DEVICE
|
||||
FP_DEVICE_RETRY
|
||||
FP_DEVICE_ERROR
|
||||
FpDeviceType
|
||||
FpScanType
|
||||
FpDeviceRetry
|
||||
FpDeviceError
|
||||
fp_device_retry_quark
|
||||
fp_device_error_quark
|
||||
FpEnrollProgress
|
||||
FpMatchCb
|
||||
fp_device_get_driver
|
||||
fp_device_get_device_id
|
||||
fp_device_get_name
|
||||
fp_device_get_scan_type
|
||||
fp_device_get_nr_enroll_stages
|
||||
fp_device_has_storage
|
||||
fp_device_supports_identify
|
||||
fp_device_supports_capture
|
||||
fp_device_open
|
||||
fp_device_close
|
||||
fp_device_enroll
|
||||
fp_device_verify
|
||||
fp_device_identify
|
||||
fp_device_capture
|
||||
fp_device_delete_print
|
||||
fp_device_list_prints
|
||||
fp_device_open_finish
|
||||
fp_device_close_finish
|
||||
fp_device_enroll_finish
|
||||
fp_device_verify_finish
|
||||
fp_device_identify_finish
|
||||
fp_device_capture_finish
|
||||
fp_device_delete_print_finish
|
||||
fp_device_list_prints_finish
|
||||
fp_device_open_sync
|
||||
fp_device_close_sync
|
||||
fp_device_enroll_sync
|
||||
fp_device_verify_sync
|
||||
fp_device_identify_sync
|
||||
fp_device_capture_sync
|
||||
fp_device_delete_print_sync
|
||||
fp_device_list_prints_sync
|
||||
FpDevice
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>drv</FILE>
|
||||
fp_driver
|
||||
fp_driver_get_name
|
||||
fp_driver_get_full_name
|
||||
fp_driver_get_driver_id
|
||||
fp_driver_get_scan_type
|
||||
fp_driver_supports_imaging
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fp-image</FILE>
|
||||
FP_TYPE_IMAGE
|
||||
FpMinutia
|
||||
fp_image_new
|
||||
fp_image_get_width
|
||||
fp_image_get_height
|
||||
fp_image_get_ppmm
|
||||
fp_image_get_minutiae
|
||||
fp_image_detect_minutiae
|
||||
fp_image_detect_minutiae_finish
|
||||
fp_image_get_data
|
||||
fp_image_get_binarized
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>dev</FILE>
|
||||
fp_dev
|
||||
fp_scan_type
|
||||
fp_capture_result
|
||||
fp_enroll_result
|
||||
fp_verify_result
|
||||
|
||||
fp_dev_get_driver
|
||||
fp_dev_get_nr_enroll_stages
|
||||
fp_dev_get_devtype
|
||||
fp_dev_supports_print_data
|
||||
fp_dev_supports_imaging
|
||||
fp_dev_supports_identification
|
||||
fp_dev_supports_dscv_print
|
||||
fp_dev_get_img_width
|
||||
fp_dev_get_img_height
|
||||
|
||||
fp_operation_stop_cb
|
||||
fp_img_operation_cb
|
||||
fp_dev_open_cb
|
||||
fp_enroll_stage_cb
|
||||
fp_identify_cb
|
||||
|
||||
fp_dev_open
|
||||
fp_async_dev_open
|
||||
|
||||
fp_dev_close
|
||||
fp_async_dev_close
|
||||
|
||||
fp_enroll_finger
|
||||
fp_enroll_finger_img
|
||||
fp_async_enroll_start
|
||||
fp_async_enroll_stop
|
||||
|
||||
fp_verify_finger
|
||||
fp_verify_finger_img
|
||||
fp_async_verify_start
|
||||
fp_async_verify_stop
|
||||
|
||||
fp_identify_finger
|
||||
fp_identify_finger_img
|
||||
fp_async_identify_start
|
||||
fp_async_identify_stop
|
||||
|
||||
fp_dev_img_capture
|
||||
fp_async_capture_start
|
||||
fp_async_capture_stop
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>print_data</FILE>
|
||||
fp_finger
|
||||
fp_print_data
|
||||
fp_print_data_get_data
|
||||
fp_print_data_from_data
|
||||
fp_print_data_save
|
||||
fp_print_data_load
|
||||
fp_print_data_delete
|
||||
fp_print_data_from_dscv_print
|
||||
fp_print_data_free
|
||||
fp_print_data_get_driver_id
|
||||
fp_print_data_get_devtype
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>dscv_print</FILE>
|
||||
fp_dscv_print
|
||||
fp_discover_prints
|
||||
fp_dscv_prints_free
|
||||
fp_dscv_print_get_driver_id
|
||||
fp_dscv_print_get_devtype
|
||||
fp_dscv_print_get_finger
|
||||
fp_dscv_print_delete
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>img</FILE>
|
||||
fp_img
|
||||
fp_minutia
|
||||
fp_img_free
|
||||
fp_img_get_height
|
||||
fp_img_get_width
|
||||
fp_img_get_data
|
||||
fp_img_save_to_file
|
||||
fp_img_standardize
|
||||
fp_img_binarize
|
||||
fp_img_get_minutiae
|
||||
fp_minutia_get_coords
|
||||
FpImage
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fp-image-device</FILE>
|
||||
FP_TYPE_IMAGE_DEVICE
|
||||
FpImageDevice
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fp-print</FILE>
|
||||
FP_TYPE_PRINT
|
||||
FpFinger
|
||||
FpPrint
|
||||
fp_print_new
|
||||
fp_print_new_from_data
|
||||
fp_print_to_data
|
||||
fp_print_get_driver
|
||||
fp_print_get_device_id
|
||||
fp_print_get_device_stored
|
||||
fp_print_get_image
|
||||
fp_print_get_finger
|
||||
fp_print_get_username
|
||||
fp_print_get_description
|
||||
fp_print_get_enroll_date
|
||||
fp_print_set_finger
|
||||
fp_print_set_username
|
||||
fp_print_set_description
|
||||
fp_print_set_enroll_date
|
||||
fp_print_compatible
|
||||
fp_print_equal
|
||||
fp_print_serialize
|
||||
fp_print_deserialize
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fpi-assembling</FILE>
|
||||
fpi_frame
|
||||
fpi_frame_asmbl_ctx
|
||||
fpi_do_movement_estimation
|
||||
fpi_assemble_frames
|
||||
fpi_line_asmbl_ctx
|
||||
fpi_assemble_lines
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fpi-context</FILE>
|
||||
fpi_get_driver_types
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fpi-device</FILE>
|
||||
FpDeviceClass
|
||||
FpTimeoutFunc
|
||||
FpiDeviceAction
|
||||
FpIdEntry
|
||||
fpi_device_get_usb_device
|
||||
fpi_device_get_virtual_env
|
||||
fpi_device_get_current_action
|
||||
fpi_device_retry_new
|
||||
fpi_device_error_new
|
||||
fpi_device_retry_new_msg
|
||||
fpi_device_error_new_msg
|
||||
fpi_device_get_driver_data
|
||||
fpi_device_get_enroll_data
|
||||
fpi_device_get_capture_data
|
||||
fpi_device_get_verify_data
|
||||
fpi_device_get_identify_data
|
||||
fpi_device_get_delete_data
|
||||
fpi_device_get_cancellable
|
||||
fpi_device_action_is_cancelled
|
||||
fpi_device_add_timeout
|
||||
fpi_device_set_nr_enroll_stages
|
||||
fpi_device_set_scan_type
|
||||
fpi_device_action_error
|
||||
fpi_device_probe_complete
|
||||
fpi_device_open_complete
|
||||
fpi_device_close_complete
|
||||
fpi_device_enroll_complete
|
||||
fpi_device_verify_complete
|
||||
fpi_device_identify_complete
|
||||
fpi_device_capture_complete
|
||||
fpi_device_delete_complete
|
||||
fpi_device_enroll_progress
|
||||
fpi_device_verify_report
|
||||
fpi_device_identify_report
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fpi-image</FILE>
|
||||
FpiImageFlags
|
||||
FpImage
|
||||
fpi_std_sq_dev
|
||||
fpi_mean_sq_diff_norm
|
||||
fpi_image_resize
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fpi-image-device</FILE>
|
||||
<TITLE>FpImageDevice</TITLE>
|
||||
FpiImageDeviceState
|
||||
FpImageDeviceClass
|
||||
fpi_image_device_session_error
|
||||
fpi_image_device_open_complete
|
||||
fpi_image_device_close_complete
|
||||
fpi_image_device_activate_complete
|
||||
fpi_image_device_deactivate_complete
|
||||
fpi_image_device_report_finger_status
|
||||
fpi_image_device_image_captured
|
||||
fpi_image_device_retry_scan
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-log.h</INCLUDE>
|
||||
<FILE>fpi-log</FILE>
|
||||
fp_dbg
|
||||
fp_info
|
||||
@@ -199,62 +151,121 @@ BUG
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fpi-print</FILE>
|
||||
FpiPrintType
|
||||
FpiMatchResult
|
||||
fpi_print_add_print
|
||||
fpi_print_set_type
|
||||
fpi_print_set_device_stored
|
||||
fpi_print_add_from_image
|
||||
fpi_print_bz3_match
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-ssm.h</INCLUDE>
|
||||
<FILE>fpi-ssm</FILE>
|
||||
FpiSsmCompletedCallback
|
||||
FpiSsmHandlerCallback
|
||||
fpi_ssm
|
||||
ssm_completed_fn
|
||||
ssm_handler_fn
|
||||
|
||||
fpi_ssm_new
|
||||
fpi_ssm_new_full
|
||||
fpi_ssm_free
|
||||
fpi_ssm_start
|
||||
fpi_ssm_start_subsm
|
||||
|
||||
fpi_ssm_next_state
|
||||
fpi_ssm_next_state_delayed
|
||||
fpi_ssm_next_state_timeout_cb
|
||||
fpi_ssm_jump_to_state
|
||||
fpi_ssm_jump_to_state_delayed
|
||||
fpi_ssm_cancel_delayed_state_change
|
||||
fpi_ssm_mark_completed
|
||||
fpi_ssm_mark_failed
|
||||
fpi_ssm_set_data
|
||||
fpi_ssm_get_data
|
||||
fpi_ssm_get_user_data
|
||||
fpi_ssm_get_error
|
||||
fpi_ssm_dup_error
|
||||
fpi_ssm_get_cur_state
|
||||
fpi_ssm_next_state_timeout_cb
|
||||
fpi_ssm_usb_transfer_cb
|
||||
FpiSsm
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>fpi-usb-transfer</FILE>
|
||||
FPI_USB_ENDPOINT_IN
|
||||
FPI_USB_ENDPOINT_OUT
|
||||
FpiUsbTransferCallback
|
||||
FpiTransferType
|
||||
FpiUsbTransfer
|
||||
fpi_usb_transfer_new
|
||||
fpi_usb_transfer_ref
|
||||
fpi_usb_transfer_unref
|
||||
fpi_usb_transfer_set_short_error
|
||||
fpi_usb_transfer_fill_bulk
|
||||
fpi_usb_transfer_fill_bulk_full
|
||||
fpi_usb_transfer_fill_control
|
||||
fpi_usb_transfer_fill_interrupt
|
||||
fpi_usb_transfer_fill_interrupt_full
|
||||
fpi_usb_transfer_submit
|
||||
fpi_usb_transfer_submit_sync
|
||||
<SUBSECTION Standard>
|
||||
FPI_TYPE_USB_TRANSFER
|
||||
fpi_usb_transfer_get_type
|
||||
<INCLUDE>fpi-poll.h</INCLUDE>
|
||||
<FILE>fpi-poll</FILE>
|
||||
fpi_timeout
|
||||
fpi_timeout_fn
|
||||
fpi_timeout_add
|
||||
fpi_timeout_set_name
|
||||
fpi_timeout_cancel
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-dev.h</INCLUDE>
|
||||
<FILE>fpi-dev</FILE>
|
||||
fp_img_dev
|
||||
|
||||
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
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-dev-img.h</INCLUDE>
|
||||
<FILE>fpi-dev-img</FILE>
|
||||
fp_imgdev_action
|
||||
fp_imgdev_state
|
||||
fp_imgdev_enroll_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
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-core.h</INCLUDE>
|
||||
<FILE>fpi-core</FILE>
|
||||
usb_id
|
||||
fp_driver_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-core.h</INCLUDE>
|
||||
<FILE>fpi-core-img</FILE>
|
||||
FpiImgDriverFlags
|
||||
fp_img_driver
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-img.h</INCLUDE>
|
||||
<FILE>fpi-img</FILE>
|
||||
FpiImgFlags
|
||||
|
||||
fpi_img_new
|
||||
fpi_img_new_for_imgdev
|
||||
fpi_img_realloc
|
||||
fpi_img_resize
|
||||
|
||||
fpi_std_sq_dev
|
||||
fpi_mean_sq_diff_norm
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-assembling.h</INCLUDE>
|
||||
<FILE>fpi-assembling</FILE>
|
||||
fpi_frame
|
||||
fpi_frame_asmbl_ctx
|
||||
fpi_line_asmbl_ctx
|
||||
|
||||
fpi_do_movement_estimation
|
||||
fpi_assemble_frames
|
||||
fpi_assemble_lines
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fpi-usb.h</INCLUDE>
|
||||
<FILE>fpi-usb</FILE>
|
||||
fpi_usb_transfer
|
||||
|
||||
fpi_usb_transfer_cb_fn
|
||||
fpi_usb_alloc
|
||||
fpi_usb_fill_bulk_transfer
|
||||
fpi_usb_submit_transfer
|
||||
fpi_usb_cancel_transfer
|
||||
</SECTION>
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>context</FILE>
|
||||
<TITLE>Device discovery and hotplugging</TITLE>
|
||||
FP_TYPE_CONTEXT
|
||||
FpContext
|
||||
fp_context_new
|
||||
fp_context_enumerate
|
||||
fp_context_get_devices
|
||||
</SECTION>
|
||||
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>device</FILE>
|
||||
<TITLE>Device</TITLE>
|
||||
FP_TYPE_DEVICE
|
||||
FpDevice
|
||||
FpDeviceType
|
||||
FpScanType
|
||||
FpDeviceRetry
|
||||
FpDeviceError
|
||||
FP_DEVICE_ERROR
|
||||
FP_DEVICE_RETRY
|
||||
fp_device_get_driver
|
||||
fp_device_get_device_id
|
||||
fp_device_get_name
|
||||
fp_device_get_scan_type
|
||||
|
||||
fp_device_open
|
||||
fp_device_open_finish
|
||||
fp_device_open_sync
|
||||
|
||||
fp_device_close
|
||||
fp_device_close_finish
|
||||
fp_device_close_sync
|
||||
|
||||
fp_device_enroll
|
||||
fp_device_enroll_finish
|
||||
fp_device_enroll_sync
|
||||
|
||||
fp_device_identify
|
||||
fp_device_identify_finish
|
||||
fp_device_identify_sync
|
||||
|
||||
fp_device_capture
|
||||
fp_device_capture_finish
|
||||
fp_device_capture_sync
|
||||
|
||||
fp_device_verify
|
||||
fp_device_verify_finish
|
||||
fp_device_verify_sync
|
||||
|
||||
_fp_device_get_cancellable
|
||||
</SECTION>
|
||||
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>print</FILE>
|
||||
<TITLE>Fingerprint handling</TITLE>
|
||||
FpPrint
|
||||
fp_print_new
|
||||
</SECTION>
|
||||
|
||||
|
||||
<SECTION>
|
||||
<INCLUDE>fprint.h</INCLUDE>
|
||||
<FILE>image</FILE>
|
||||
<TITLE>Image handling</TITLE>
|
||||
FP_TYPE_IMAGE
|
||||
FpImage
|
||||
fp_image_new
|
||||
fp_image_detect_minutiae
|
||||
fp_image_detect_minutiae_finish
|
||||
fp_image_device_new
|
||||
fp_image_get_binarized
|
||||
fp_image_get_data
|
||||
fp_image_get_height
|
||||
fp_image_get_minutiae
|
||||
fp_image_get_ppmm
|
||||
fp_image_get_width
|
||||
</SECTION>
|
||||
|
||||
|
||||
<SECTION>
|
||||
<FILE>internal-image-device</FILE>
|
||||
<INCLUDE>drivers_api.h</INCLUDE>
|
||||
<TITLE>Base class for image devices</TITLE>
|
||||
FpImageDevice
|
||||
FpImageDeviceClass
|
||||
FpiImageDeviceState
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>internal-usb-transfers</FILE>
|
||||
<INCLUDE>drivers_api.h</INCLUDE>
|
||||
<TITLE>USB Transfers</TITLE>
|
||||
FpUsbTransfer
|
||||
fp_usb_transfer_fill_bulk
|
||||
fp_usb_transfer_fill_bulk_full
|
||||
fp_usb_transfer_fill_control
|
||||
fp_usb_transfer_fill_interrupt
|
||||
fp_usb_transfer_fill_interrupt_full
|
||||
fp_usb_transfer_get_type
|
||||
fp_usb_transfer_new
|
||||
fp_usb_transfer_ref
|
||||
fp_usb_transfer_set_short_error
|
||||
fp_usb_transfer_submit
|
||||
fp_usb_transfer_submit_sync
|
||||
fp_usb_transfer_unref
|
||||
FpUsbTransferCallback
|
||||
FP_USB_ENDPOINT_IN
|
||||
FP_USB_ENDPOINT_OUT
|
||||
</SECTION>
|
||||
@@ -2,12 +2,41 @@ subdir('xml')
|
||||
|
||||
private_headers = [
|
||||
'config.h',
|
||||
'nbis-helpers.h',
|
||||
'fprint.h',
|
||||
|
||||
# Subdirectories to ignore
|
||||
'drivers',
|
||||
'nbis',
|
||||
'aeslib.h',
|
||||
'assembling.h',
|
||||
'fp_internal.h',
|
||||
'nbis-helpers.h',
|
||||
'fpi-async.h',
|
||||
'fpi-data.h',
|
||||
|
||||
# Drivers
|
||||
'aes1660.h',
|
||||
'aes2501.h',
|
||||
'aes2550.h',
|
||||
'aes2660.h',
|
||||
'aes3k.h',
|
||||
'aesx660.h',
|
||||
'driver_ids.h',
|
||||
'elan.h',
|
||||
'upek_proto.h',
|
||||
'upeksonly.h',
|
||||
'upektc.h',
|
||||
'upektc_img.h',
|
||||
'vfs0050.h',
|
||||
'vfs301_proto_fragments.h',
|
||||
'vfs301_proto.h',
|
||||
'vfs5011_proto.h',
|
||||
|
||||
# NBIS
|
||||
'morph.h',
|
||||
'sunrast.h',
|
||||
'bozorth.h',
|
||||
'defs.h',
|
||||
'log.h',
|
||||
'bz_array.h',
|
||||
'lfs.h',
|
||||
'mytime.h',
|
||||
]
|
||||
|
||||
html_images = [
|
||||
@@ -23,13 +52,16 @@ glib_prefix = dependency('glib-2.0').get_pkgconfig_variable('prefix')
|
||||
glib_docpath = join_paths(glib_prefix, 'share', 'gtk-doc', 'html')
|
||||
docpath = join_paths(get_option('datadir'), 'gtk-doc', 'html')
|
||||
|
||||
gnome.gtkdoc(versioned_libname,
|
||||
gnome.gtkdoc('libfprint',
|
||||
main_xml: 'libfprint-docs.xml',
|
||||
src_dir: join_paths(meson.source_root(), 'libfprint'),
|
||||
dependencies: libfprint_dep,
|
||||
content_files: content_files,
|
||||
expand_content_files: expand_content_files,
|
||||
ignore_headers: private_headers,
|
||||
scan_args: [
|
||||
'--ignore-decorators=API_EXPORTED',
|
||||
'--ignore-headers=' + ' '.join(private_headers),
|
||||
],
|
||||
fixxref_args: [
|
||||
'--html-dir=@0@'.format(docpath),
|
||||
'--extra-dir=@0@'.format(join_paths(glib_docpath, 'glib')),
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
ent_conf = configuration_data()
|
||||
ent_conf.set('PACKAGE', versioned_libname)
|
||||
ent_conf.set('PACKAGE', 'libfprint')
|
||||
ent_conf.set('PACKAGE_BUGREPORT', 'https://gitlab.freedesktop.org/libfprint/libfprint/issues')
|
||||
ent_conf.set('PACKAGE_NAME', versioned_libname)
|
||||
ent_conf.set('PACKAGE_STRING', versioned_libname)
|
||||
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://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)
|
||||
configure_file(input: 'gtkdocentities.ent.in', output: 'gtkdocentities.ent', configuration: ent_conf)
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
FpContext *ctx;
|
||||
|
||||
ctx = fp_context_new ();
|
||||
g_object_unref (ctx);
|
||||
|
||||
fp_init ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* Example fingerprint enrollment program
|
||||
* Enrolls your choosen finger and saves the print to disk
|
||||
* Enrolls your right index finger and saves the print to disk
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -19,180 +18,142 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "example-enroll"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
#include "storage.h"
|
||||
#include "utilities.h"
|
||||
|
||||
typedef struct _EnrollData
|
||||
struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
|
||||
{
|
||||
GMainLoop *loop;
|
||||
FpFinger finger;
|
||||
int ret_value;
|
||||
} EnrollData;
|
||||
struct fp_dscv_dev *ddev = discovered_devs[0];
|
||||
struct fp_driver *drv;
|
||||
if (!ddev)
|
||||
return NULL;
|
||||
|
||||
static void
|
||||
enroll_data_free (EnrollData *enroll_data)
|
||||
{
|
||||
g_main_loop_unref (enroll_data->loop);
|
||||
g_free (enroll_data);
|
||||
}
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EnrollData, enroll_data_free)
|
||||
|
||||
static void
|
||||
on_device_closed (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||
{
|
||||
EnrollData *enroll_data = user_data;
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
fp_device_close_finish (dev, res, &error);
|
||||
|
||||
if (error)
|
||||
g_warning ("Failed closing device %s\n", error->message);
|
||||
|
||||
g_main_loop_quit (enroll_data->loop);
|
||||
drv = fp_dscv_dev_get_driver(ddev);
|
||||
printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
|
||||
return ddev;
|
||||
}
|
||||
|
||||
static void
|
||||
on_enroll_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||
{
|
||||
EnrollData *enroll_data = user_data;
|
||||
struct fp_print_data *enroll(struct fp_dev *dev) {
|
||||
struct fp_print_data *enrolled_print = NULL;
|
||||
int r;
|
||||
|
||||
g_autoptr(FpPrint) print = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
printf("You will need to successfully scan your finger %d times to "
|
||||
"complete the process.\n", fp_dev_get_nr_enroll_stages(dev));
|
||||
|
||||
print = fp_device_enroll_finish (dev, res, &error);
|
||||
do {
|
||||
struct fp_img *img = NULL;
|
||||
|
||||
if (!error)
|
||||
{
|
||||
enroll_data->ret_value = EXIT_SUCCESS;
|
||||
printf("\nScan your finger now.\n");
|
||||
|
||||
if (!fp_device_has_storage (dev))
|
||||
{
|
||||
g_debug ("Device has not storage, saving locally");
|
||||
int r = print_data_save (print, enroll_data->finger);
|
||||
if (r < 0)
|
||||
{
|
||||
g_warning ("Data save failed, code %d", r);
|
||||
enroll_data->ret_value = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("Enroll failed with error %s\n", error->message);
|
||||
}
|
||||
|
||||
fp_device_close (dev, NULL, (GAsyncReadyCallback) on_device_closed,
|
||||
enroll_data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_enroll_progress (FpDevice *device,
|
||||
gint completed_stages,
|
||||
FpPrint *print,
|
||||
gpointer user_data,
|
||||
GError *error)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Enroll stage %d of %d failed with error %s",
|
||||
completed_stages,
|
||||
fp_device_get_nr_enroll_stages (device),
|
||||
error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fp_device_supports_capture (device) &&
|
||||
print_image_save (print, "enrolled.pgm"))
|
||||
r = fp_enroll_finger_img(dev, &enrolled_print, &img);
|
||||
if (img) {
|
||||
fp_img_save_to_file(img, "enrolled.pgm");
|
||||
printf("Wrote scanned image to enrolled.pgm\n");
|
||||
|
||||
printf ("Enroll stage %d of %d passed. Yay!\n", completed_stages,
|
||||
fp_device_get_nr_enroll_stages (device));
|
||||
fp_img_free(img);
|
||||
}
|
||||
if (r < 0) {
|
||||
printf("Enroll failed with error %d\n", r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
on_device_opened (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||
{
|
||||
EnrollData *enroll_data = user_data;
|
||||
FpPrint *print_template;
|
||||
switch (r) {
|
||||
case FP_ENROLL_COMPLETE:
|
||||
printf("Enroll complete!\n");
|
||||
break;
|
||||
case FP_ENROLL_FAIL:
|
||||
printf("Enroll failed, something wen't wrong :(\n");
|
||||
return NULL;
|
||||
case FP_ENROLL_PASS:
|
||||
printf("Enroll stage passed. Yay!\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY:
|
||||
printf("Didn't quite catch that. Please try again.\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY_TOO_SHORT:
|
||||
printf("Your swipe was too short, please try again.\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY_CENTER_FINGER:
|
||||
printf("Didn't catch that, please center your finger on the "
|
||||
"sensor and try again.\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY_REMOVE_FINGER:
|
||||
printf("Scan failed, please remove your finger and then try "
|
||||
"again.\n");
|
||||
break;
|
||||
}
|
||||
} while (r != FP_ENROLL_COMPLETE);
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!fp_device_open_finish (dev, res, &error))
|
||||
{
|
||||
g_warning ("Failed to open device: %s", error->message);
|
||||
g_main_loop_quit (enroll_data->loop);
|
||||
return;
|
||||
if (!enrolled_print) {
|
||||
fprintf(stderr, "Enroll complete but no print?\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf ("Opened device. It's now time to enroll your finger.\n\n");
|
||||
printf ("You will need to successfully scan your %s finger %d times to "
|
||||
"complete the process.\n\n", finger_to_string (enroll_data->finger),
|
||||
fp_device_get_nr_enroll_stages (dev));
|
||||
printf ("Scan your finger now.\n");
|
||||
|
||||
print_template = print_create_template (dev, enroll_data->finger);
|
||||
fp_device_enroll (dev, print_template, NULL, on_enroll_progress, NULL,
|
||||
NULL, (GAsyncReadyCallback) on_enroll_completed,
|
||||
enroll_data);
|
||||
printf("Enrollment completed!\n\n");
|
||||
return enrolled_print;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
int main(void)
|
||||
{
|
||||
g_autoptr(FpContext) ctx = NULL;
|
||||
g_autoptr(EnrollData) enroll_data = NULL;
|
||||
GPtrArray *devices;
|
||||
FpDevice *dev;
|
||||
FpFinger finger;
|
||||
int r = 1;
|
||||
struct fp_dscv_dev *ddev;
|
||||
struct fp_dscv_dev **discovered_devs;
|
||||
struct fp_dev *dev;
|
||||
struct fp_print_data *data;
|
||||
|
||||
g_print ("This program will enroll the selected finger, unconditionally "
|
||||
"overwriting any print for the same finger that was enrolled "
|
||||
printf("This program will enroll your right index finger, "
|
||||
"unconditionally overwriting any right-index print that was enrolled "
|
||||
"previously. If you want to continue, press enter, otherwise hit "
|
||||
"Ctrl+C\n");
|
||||
getchar();
|
||||
|
||||
g_print ("Choose the finger to enroll:\n");
|
||||
finger = finger_chooser ();
|
||||
|
||||
if (finger == FP_FINGER_UNKNOWN)
|
||||
{
|
||||
g_warning ("Unknown finger selected");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
||||
setenv ("LIBUSB_DEBUG", "3", 0);
|
||||
|
||||
ctx = fp_context_new ();
|
||||
|
||||
devices = fp_context_get_devices (ctx);
|
||||
if (!devices)
|
||||
{
|
||||
g_warning ("Impossible to get devices");
|
||||
return EXIT_FAILURE;
|
||||
r = fp_init();
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Failed to initialize libfprint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dev = discover_device (devices);
|
||||
if (!dev)
|
||||
{
|
||||
g_warning ("No devices detected.");
|
||||
return EXIT_FAILURE;
|
||||
discovered_devs = fp_discover_devs();
|
||||
if (!discovered_devs) {
|
||||
fprintf(stderr, "Could not discover devices\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
enroll_data = g_new0 (EnrollData, 1);
|
||||
enroll_data->finger = finger;
|
||||
enroll_data->ret_value = EXIT_FAILURE;
|
||||
enroll_data->loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
fp_device_open (dev, NULL, (GAsyncReadyCallback) on_device_opened,
|
||||
enroll_data);
|
||||
|
||||
g_main_loop_run (enroll_data->loop);
|
||||
|
||||
return enroll_data->ret_value;
|
||||
ddev = discover_device(discovered_devs);
|
||||
if (!ddev) {
|
||||
fprintf(stderr, "No devices detected.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev = fp_dev_open(ddev);
|
||||
fp_dscv_devs_free(discovered_devs);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "Could not open device.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Opened device. It's now time to enroll your finger.\n\n");
|
||||
data = enroll(dev);
|
||||
if (!data)
|
||||
goto out_close;
|
||||
|
||||
r = print_data_save(data, RIGHT_INDEX);
|
||||
if (r < 0)
|
||||
fprintf(stderr, "Data save failed, code %d\n", r);
|
||||
|
||||
fp_print_data_free(data);
|
||||
out_close:
|
||||
fp_dev_close(dev);
|
||||
out:
|
||||
fp_exit();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
108
examples/img_capture.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Example libfprint image capture program
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
|
||||
{
|
||||
struct fp_dscv_dev *ddev = discovered_devs[0];
|
||||
struct fp_driver *drv;
|
||||
if (!ddev)
|
||||
return NULL;
|
||||
|
||||
drv = fp_dscv_dev_get_driver(ddev);
|
||||
printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
|
||||
return ddev;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int r = 1;
|
||||
struct fp_dscv_dev *ddev;
|
||||
struct fp_dscv_dev **discovered_devs;
|
||||
struct fp_dev *dev;
|
||||
struct fp_img *img = NULL;
|
||||
|
||||
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
||||
setenv ("LIBUSB_DEBUG", "3", 0);
|
||||
|
||||
r = fp_init();
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Failed to initialize libfprint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
discovered_devs = fp_discover_devs();
|
||||
if (!discovered_devs) {
|
||||
fprintf(stderr, "Could not discover devices\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ddev = discover_device(discovered_devs);
|
||||
if (!ddev) {
|
||||
fp_dscv_devs_free(discovered_devs);
|
||||
fprintf(stderr, "No devices detected.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev = fp_dev_open(ddev);
|
||||
fp_dscv_devs_free(discovered_devs);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "Could not open device.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!fp_dev_supports_imaging(dev)) {
|
||||
fprintf(stderr, "this device does not have imaging capabilities.\n");
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
printf("Opened device. It's now time to scan your finger.\n\n");
|
||||
|
||||
r = fp_dev_img_capture(dev, 0, &img);
|
||||
if (r) {
|
||||
fprintf(stderr, "image capture failed, code %d\n", r);
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
r = fp_img_save_to_file(img, "finger.pgm");
|
||||
if (r) {
|
||||
fprintf(stderr, "img save failed, code %d\n", r);
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
fp_img_standardize(img);
|
||||
r = fp_img_save_to_file(img, "finger_standardized.pgm");
|
||||
fp_img_free(img);
|
||||
if (r) {
|
||||
fprintf(stderr, "standardized img save failed, code %d\n", r);
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
r = 0;
|
||||
out_close:
|
||||
fp_dev_close(dev);
|
||||
out:
|
||||
fp_exit();
|
||||
return r;
|
||||
}
|
||||
|
||||
261
examples/img_capture_continuous.c
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Example libfprint continuous image capture program
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/extensions/Xvlib.h>
|
||||
|
||||
#define FORMAT 0x32595559
|
||||
|
||||
static int adaptor = -1;
|
||||
static char *framebuffer = NULL;
|
||||
|
||||
static Display *display = NULL;
|
||||
static Window window=(Window)NULL;
|
||||
static XvImage *xv_image = NULL;
|
||||
static XvAdaptorInfo *info;
|
||||
static GC gc;
|
||||
static int connection = -1;
|
||||
|
||||
/* based on macro by Bart Nabbe */
|
||||
#define GREY2YUV(grey, y, u, v)\
|
||||
y = (9798*grey + 19235*grey + 3736*grey) / 32768;\
|
||||
u = (-4784*grey - 9437*grey + 14221*grey) / 32768 + 128;\
|
||||
v = (20218*grey - 16941*grey - 3277*grey) / 32768 + 128;\
|
||||
y = y < 0 ? 0 : y;\
|
||||
u = u < 0 ? 0 : u;\
|
||||
v = v < 0 ? 0 : v;\
|
||||
y = y > 255 ? 255 : y;\
|
||||
u = u > 255 ? 255 : u;\
|
||||
v = v > 255 ? 255 : v
|
||||
|
||||
static void grey2yuy2 (unsigned char *grey, char *YUV, int num) {
|
||||
int i, j;
|
||||
int y0, y1, u0, u1, v0, v1;
|
||||
uint64_t gval;
|
||||
|
||||
for (i = 0, j = 0; i < num; i += 2, j += 4)
|
||||
{
|
||||
gval = grey[i];
|
||||
GREY2YUV (gval, y0, u0 , v0);
|
||||
gval = grey[i + 1];
|
||||
GREY2YUV (gval, y1, u1 , v1);
|
||||
YUV[j + 0] = y0;
|
||||
YUV[j + 1] = (u0+u1)/2;
|
||||
YUV[j + 2] = y1;
|
||||
YUV[j + 3] = (v0+v1)/2;
|
||||
}
|
||||
}
|
||||
|
||||
static void display_frame(struct fp_img *img)
|
||||
{
|
||||
int width = fp_img_get_width(img);
|
||||
int height = fp_img_get_height(img);
|
||||
unsigned char *data = fp_img_get_data(img);
|
||||
|
||||
if (adaptor < 0)
|
||||
return;
|
||||
|
||||
grey2yuy2(data, framebuffer, width * height);
|
||||
xv_image = XvCreateImage(display, info[adaptor].base_id, FORMAT,
|
||||
framebuffer, width, height);
|
||||
XvPutImage(display, info[adaptor].base_id, window, gc, xv_image,
|
||||
0, 0, width, height, 0, 0, width, height);
|
||||
}
|
||||
|
||||
static void QueryXv(void)
|
||||
{
|
||||
unsigned int num_adaptors;
|
||||
int num_formats;
|
||||
XvImageFormatValues *formats = NULL;
|
||||
int i,j;
|
||||
char xv_name[5];
|
||||
|
||||
XvQueryAdaptors(display, DefaultRootWindow(display), &num_adaptors,
|
||||
&info);
|
||||
|
||||
for(i = 0; i < num_adaptors; i++) {
|
||||
formats = XvListImageFormats(display, info[i].base_id,
|
||||
&num_formats);
|
||||
for(j = 0; j < num_formats; j++) {
|
||||
xv_name[4] = 0;
|
||||
memcpy(xv_name, &formats[j].id, 4);
|
||||
if(formats[j].id == FORMAT) {
|
||||
printf("using Xv format 0x%x %s %s\n",
|
||||
formats[j].id, xv_name,
|
||||
(formats[j].format==XvPacked)
|
||||
? "packed" : "planar");
|
||||
if (adaptor < 0)
|
||||
adaptor = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
XFree(formats);
|
||||
if (adaptor < 0)
|
||||
printf("No suitable Xv adaptor found\n");
|
||||
}
|
||||
|
||||
struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
|
||||
{
|
||||
struct fp_dscv_dev *ddev = discovered_devs[0];
|
||||
struct fp_driver *drv;
|
||||
if (!ddev)
|
||||
return NULL;
|
||||
|
||||
drv = fp_dscv_dev_get_driver(ddev);
|
||||
printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
|
||||
return ddev;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int r = 1;
|
||||
XEvent xev;
|
||||
XGCValues xgcv;
|
||||
long background=0x010203;
|
||||
struct fp_dscv_dev *ddev;
|
||||
struct fp_dscv_dev **discovered_devs;
|
||||
struct fp_dev *dev;
|
||||
int img_width;
|
||||
int img_height;
|
||||
int standardize = 0;
|
||||
|
||||
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
||||
setenv ("LIBUSB_DEBUG", "3", 0);
|
||||
|
||||
r = fp_init();
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Failed to initialize libfprint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
discovered_devs = fp_discover_devs();
|
||||
if (!discovered_devs) {
|
||||
fprintf(stderr, "Could not discover devices\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ddev = discover_device(discovered_devs);
|
||||
if (!ddev) {
|
||||
fprintf(stderr, "No devices detected.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev = fp_dev_open(ddev);
|
||||
fp_dscv_devs_free(discovered_devs);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "Could not open device.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!fp_dev_supports_imaging(dev)) {
|
||||
fprintf(stderr, "this device does not have imaging capabilities.\n");
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
img_width = fp_dev_get_img_width(dev);
|
||||
img_height = fp_dev_get_img_height(dev);
|
||||
if (img_width <= 0 || img_height <= 0) {
|
||||
fprintf(stderr, "this device returns images with variable dimensions,"
|
||||
" this example does not support that.\n");
|
||||
goto out_close;
|
||||
}
|
||||
framebuffer = malloc(img_width * img_height * 2);
|
||||
if (!framebuffer)
|
||||
goto out_close;
|
||||
|
||||
/* make the window */
|
||||
display = XOpenDisplay(getenv("DISPLAY"));
|
||||
if(display == NULL) {
|
||||
fprintf(stderr,"Could not open display \"%s\"\n",
|
||||
getenv("DISPLAY"));
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
QueryXv();
|
||||
|
||||
if (adaptor < 0)
|
||||
goto out_close;
|
||||
|
||||
window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0,
|
||||
img_width, img_height, 0,
|
||||
WhitePixel(display, DefaultScreen(display)), background);
|
||||
|
||||
XSelectInput(display, window, StructureNotifyMask | KeyPressMask);
|
||||
XMapWindow(display, window);
|
||||
connection = ConnectionNumber(display);
|
||||
|
||||
gc = XCreateGC(display, window, 0, &xgcv);
|
||||
|
||||
printf("Press S to toggle standardized mode, Q to quit\n");
|
||||
|
||||
while (1) { /* event loop */
|
||||
struct fp_img *img;
|
||||
|
||||
r = fp_dev_img_capture(dev, 1, &img);
|
||||
if (r) {
|
||||
fprintf(stderr, "image capture failed, code %d\n", r);
|
||||
goto out_close;
|
||||
}
|
||||
if (standardize)
|
||||
fp_img_standardize(img);
|
||||
|
||||
display_frame(img);
|
||||
fp_img_free(img);
|
||||
XFlush(display);
|
||||
|
||||
while (XPending(display) > 0) {
|
||||
XNextEvent(display, &xev);
|
||||
if (xev.type != KeyPress)
|
||||
continue;
|
||||
|
||||
switch (XKeycodeToKeysym(display, xev.xkey.keycode, 0)) {
|
||||
case XK_q:
|
||||
case XK_Q:
|
||||
r = 0;
|
||||
goto out_close;
|
||||
break;
|
||||
case XK_s:
|
||||
case XK_S:
|
||||
standardize = !standardize;
|
||||
break;
|
||||
}
|
||||
} /* XPending */
|
||||
}
|
||||
|
||||
r = 0;
|
||||
out_close:
|
||||
if (framebuffer)
|
||||
free(framebuffer);
|
||||
fp_dev_close(dev);
|
||||
if ((void *) window != NULL)
|
||||
XUnmapWindow(display, window);
|
||||
if (display != NULL)
|
||||
XFlush(display);
|
||||
out:
|
||||
fp_exit();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
* Example fingerprint device prints listing and deletion
|
||||
* Enrolls your right index finger and saves the print to disk
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "example-mange-prints"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
#include "utilities.h"
|
||||
|
||||
typedef struct _ListData
|
||||
{
|
||||
GMainLoop *loop;
|
||||
int ret_value;
|
||||
GList *to_delete;
|
||||
gboolean any_failed;
|
||||
} ListData;
|
||||
|
||||
static void
|
||||
list_data_free (ListData *list_data)
|
||||
{
|
||||
g_list_free_full (list_data->to_delete, g_object_unref);
|
||||
g_main_loop_unref (list_data->loop);
|
||||
g_free (list_data);
|
||||
}
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ListData, list_data_free)
|
||||
|
||||
static void
|
||||
on_device_closed (FpDevice *dev,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
ListData *list_data = user_data;
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
fp_device_close_finish (dev, res, &error);
|
||||
|
||||
if (error)
|
||||
g_warning ("Failed closing device %s\n", error->message);
|
||||
|
||||
g_main_loop_quit (list_data->loop);
|
||||
}
|
||||
|
||||
typedef struct _DeleteData
|
||||
{
|
||||
ListData *list_data;
|
||||
FpPrint *print;
|
||||
} DeleteData;
|
||||
|
||||
static void
|
||||
delete_data_free (DeleteData *delete_data)
|
||||
{
|
||||
g_object_unref (delete_data->print);
|
||||
g_free (delete_data);
|
||||
}
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DeleteData, delete_data_free);
|
||||
|
||||
static void on_print_deleted (FpDevice *dev,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data);
|
||||
|
||||
static void
|
||||
delete_next_print (FpDevice *dev,
|
||||
ListData *list_data)
|
||||
{
|
||||
FpPrint *print;
|
||||
|
||||
g_assert_nonnull (list_data->to_delete);
|
||||
print = list_data->to_delete->data;
|
||||
|
||||
g_debug ("Deleting print %s\n", fp_print_get_description (print));
|
||||
fp_device_delete_print (dev, print, NULL,
|
||||
(GAsyncReadyCallback) on_print_deleted, list_data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_print_deleted (FpDevice *dev,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
ListData *list_data = user_data;
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(FpPrint) print = NULL;
|
||||
GList *deleted_link;
|
||||
|
||||
fp_device_delete_print_finish (dev, res, &error);
|
||||
|
||||
deleted_link = list_data->to_delete;
|
||||
print = g_steal_pointer (&deleted_link->data);
|
||||
list_data->to_delete = g_list_delete_link (list_data->to_delete, deleted_link);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Failed to remove print %s: %s",
|
||||
fp_print_get_description (print), error->message);
|
||||
list_data->any_failed = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_debug ("Deleted print %s from device", fp_print_get_description (print));
|
||||
}
|
||||
|
||||
if (list_data->to_delete != NULL)
|
||||
{
|
||||
delete_next_print (dev, list_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!list_data->any_failed)
|
||||
list_data->ret_value = EXIT_SUCCESS;
|
||||
|
||||
fp_device_close (dev, NULL, (GAsyncReadyCallback) on_device_closed,
|
||||
list_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_list_completed (FpDevice *dev,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
ListData *list_data = user_data;
|
||||
|
||||
g_autoptr(GPtrArray) prints = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
prints = fp_device_list_prints_finish (dev, res, &error);
|
||||
|
||||
if (!error)
|
||||
{
|
||||
guint i;
|
||||
char buf[128];
|
||||
|
||||
g_print ("Device contains %u prints\n", prints->len);
|
||||
|
||||
for (i = 0; i < prints->len; ++i)
|
||||
{
|
||||
FpPrint * print = prints->pdata[i];
|
||||
const GDate *date = fp_print_get_enroll_date (print);
|
||||
|
||||
g_print ("[%d] Print of %s finger for username %s", i + 1,
|
||||
finger_to_string (fp_print_get_finger (print)),
|
||||
fp_print_get_username (print));
|
||||
|
||||
if (date)
|
||||
{
|
||||
g_date_strftime (buf, G_N_ELEMENTS (buf), "%Y-%m-%d\0", date);
|
||||
g_print (", enrolled on %s", buf);
|
||||
}
|
||||
|
||||
g_print (". Description: %s\n", fp_print_get_description (print));
|
||||
}
|
||||
|
||||
if (prints->len)
|
||||
{
|
||||
gint64 idx = 0;
|
||||
|
||||
g_print ("Want to delete saved print? [<number>/A/n]\n> ");
|
||||
if (fgets (buf, 3, stdin))
|
||||
idx = g_ascii_strtoll (buf, NULL, 10);
|
||||
|
||||
if (idx > 0 && idx <= prints->len)
|
||||
{
|
||||
FpPrint *print = prints->pdata[idx - 1];
|
||||
list_data->to_delete = g_list_prepend (list_data->to_delete,
|
||||
g_object_ref (print));
|
||||
}
|
||||
else if (buf[0] == 'A')
|
||||
{
|
||||
for (i = 0; i < prints->len; ++i)
|
||||
{
|
||||
FpPrint *print = prints->pdata[i];
|
||||
list_data->to_delete = g_list_prepend (list_data->to_delete,
|
||||
g_object_ref (print));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buf[0] == 'n' || buf[0] == 'N')
|
||||
list_data->ret_value = EXIT_SUCCESS;
|
||||
else
|
||||
g_warning ("Invalid finger selected");
|
||||
}
|
||||
}
|
||||
|
||||
if (list_data->to_delete)
|
||||
delete_next_print (dev, list_data);
|
||||
else
|
||||
fp_device_close (dev, NULL, (GAsyncReadyCallback) on_device_closed,
|
||||
list_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("Getting prints failed with error %s", error->message);
|
||||
g_main_loop_quit (list_data->loop);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_device_opened (FpDevice *dev,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
ListData *list_data = user_data;
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!fp_device_open_finish (dev, res, &error))
|
||||
{
|
||||
g_warning ("Failed to open device: %s", error->message);
|
||||
g_main_loop_quit (list_data->loop);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fp_device_has_storage (dev))
|
||||
{
|
||||
g_warning ("Device %s doesn't support storage", fp_device_get_name (dev));
|
||||
g_main_loop_quit (list_data->loop);
|
||||
return;
|
||||
}
|
||||
|
||||
fp_device_list_prints (dev, NULL,
|
||||
(GAsyncReadyCallback) on_list_completed, list_data);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
g_autoptr(FpContext) ctx = NULL;
|
||||
g_autoptr(ListData) list_data = NULL;
|
||||
GPtrArray *devices;
|
||||
FpDevice *dev;
|
||||
|
||||
g_print ("This program will report the prints saved in device\n");
|
||||
|
||||
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
||||
|
||||
ctx = fp_context_new ();
|
||||
|
||||
devices = fp_context_get_devices (ctx);
|
||||
if (!devices)
|
||||
{
|
||||
g_warning ("Impossible to get devices");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
dev = discover_device (devices);
|
||||
if (!dev)
|
||||
{
|
||||
g_warning ("No devices detected.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
list_data = g_new0 (ListData, 1);
|
||||
list_data->ret_value = EXIT_FAILURE;
|
||||
list_data->loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
fp_device_open (dev, NULL, (GAsyncReadyCallback) on_device_opened, list_data);
|
||||
|
||||
g_main_loop_run (list_data->loop);
|
||||
|
||||
return list_data->ret_value;
|
||||
}
|
||||
@@ -1,16 +1,29 @@
|
||||
|
||||
examples = [ 'enroll', 'verify', 'manage-prints' ]
|
||||
examples = [ 'verify_live', 'enroll', 'verify', 'img_capture' ]
|
||||
foreach example: examples
|
||||
executable(example,
|
||||
[ example + '.c', 'storage.c', 'utilities.c' ],
|
||||
dependencies: [
|
||||
libfprint_dep,
|
||||
glib_dep,
|
||||
[example + '.c', 'storage.c'],
|
||||
dependencies: [libfprint_dep, glib_dep],
|
||||
include_directories: [
|
||||
root_inc,
|
||||
],
|
||||
)
|
||||
c_args: common_cflags)
|
||||
endforeach
|
||||
|
||||
executable('cpp-test',
|
||||
'cpp-test.cpp',
|
||||
dependencies: libfprint_dep,
|
||||
)
|
||||
include_directories: [
|
||||
root_inc,
|
||||
],
|
||||
c_args: common_cflags)
|
||||
|
||||
if get_option('x11-examples')
|
||||
executable('img_capture_continuous',
|
||||
'img_capture_continuous.c',
|
||||
dependencies: [ libfprint_dep, xv_dep, x11_dep ],
|
||||
include_directories: [
|
||||
root_inc,
|
||||
],
|
||||
c_args: common_cflags)
|
||||
endif
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
These are example images from NIST and are in the public domain.
|
||||
|
||||
The PNG files have been generated by using the greyscale data as a mask.
|
||||
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 102 KiB |
@@ -1,111 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# This script can be used together with the virtual_imgdev to simulate an
|
||||
# image based fingerprint reader.
|
||||
#
|
||||
# To use, set the FP_VIRTUAL_IMAGE environment variable for both the
|
||||
# libfprint using program (e.g. fprintd) and this script.
|
||||
#
|
||||
# Usually this would work by adding it into the systemd unit file. The
|
||||
# best way of doing so is to create
|
||||
# /etc/systemd/system/fprintd.service.d/fprintd-test.conf
|
||||
#
|
||||
# [Service]
|
||||
# RuntimeDirectory=fprint
|
||||
# Environment=FP_VIRTUAL_IMAGE=/run/fprint/virtimg_sock
|
||||
# Environment=G_MESSAGES_DEBUG=all
|
||||
# ReadWritePaths=$RUNTIME_DIR
|
||||
#
|
||||
# After that run:
|
||||
#
|
||||
# systemctl daemon-reload
|
||||
# systemctl restart fprintd.service
|
||||
#
|
||||
# You may also need to disable selinux.
|
||||
#
|
||||
# Then run this script with e.g.
|
||||
# FP_VIRTUAL_IMAGE=/run/fprint/virtimg_sock ./sendvirtimg.py prints/whorl.png
|
||||
|
||||
|
||||
|
||||
import cairo
|
||||
import sys
|
||||
import os
|
||||
import socket
|
||||
import struct
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
sys.stderr.write('You need to pass a PNG with an alpha channel!\n')
|
||||
sys.exit(1)
|
||||
|
||||
# Just copied from the C file, we could also use the introspection data for
|
||||
# this. Also, most of them do *not* make any sense.
|
||||
commands = {
|
||||
'retry' : struct.pack('ii', -1, 0),
|
||||
'retry-too-short' : struct.pack('ii', -1, 1),
|
||||
'retry-center-finger' : struct.pack('ii', -1, 2),
|
||||
'retry-remove-finger' : struct.pack('ii', -1, 3),
|
||||
|
||||
'error' : struct.pack('ii', -2, 0),
|
||||
'error-not-supported' : struct.pack('ii', -2, 1),
|
||||
'error-not-open' : struct.pack('ii', -2, 2),
|
||||
'error-already-open' : struct.pack('ii', -2, 3),
|
||||
'error-busy' : struct.pack('ii', -2, 4),
|
||||
'error-proto' : struct.pack('ii', -2, 5),
|
||||
'error-data-invalid' : struct.pack('ii', -2, 6),
|
||||
'error-data-not-found' : struct.pack('ii', -2, 7),
|
||||
'error-data-full' : struct.pack('ii', -2, 8),
|
||||
}
|
||||
|
||||
|
||||
if sys.argv[1] in commands:
|
||||
command = commands[sys.argv[1]]
|
||||
else:
|
||||
png = cairo.ImageSurface.create_from_png(sys.argv[1])
|
||||
|
||||
# Cairo wants 4 byte aligned rows, so just add a few pixel if necessary
|
||||
w = png.get_width()
|
||||
h = png.get_height()
|
||||
w = (w + 3) // 4 * 4
|
||||
h = (h + 3) // 4 * 4
|
||||
img = cairo.ImageSurface(cairo.Format.A8, w, h)
|
||||
cr = cairo.Context(img)
|
||||
|
||||
cr.set_source_rgba(1, 1, 1, 1)
|
||||
cr.paint()
|
||||
|
||||
cr.set_source_rgba(0, 0, 0, 0)
|
||||
cr.set_operator(cairo.OPERATOR_SOURCE)
|
||||
|
||||
cr.set_source_surface(png)
|
||||
cr.paint()
|
||||
|
||||
mem = img.get_data()
|
||||
mem = mem.tobytes()
|
||||
assert len(mem) == img.get_width() * img.get_height()
|
||||
|
||||
command = struct.pack('ii', img.get_width(), img.get_height())
|
||||
command += mem
|
||||
|
||||
|
||||
|
||||
def write_dbg_img():
|
||||
dbg_img_rgb = cairo.ImageSurface(cairo.Format.RGB24, img.get_width(), img.get_height())
|
||||
dbg_cr = cairo.Context(dbg_img_rgb)
|
||||
dbg_cr.set_source_rgb(0, 0, 0)
|
||||
dbg_cr.paint()
|
||||
dbg_cr.set_source_rgb(1, 1, 1)
|
||||
dbg_cr.mask_surface(img, 0, 0)
|
||||
|
||||
dbg_img_rgb.write_to_png('/tmp/test.png')
|
||||
|
||||
#write_dbg_img()
|
||||
|
||||
# Send image through socket
|
||||
sockaddr = os.environ['FP_VIRTUAL_IMAGE']
|
||||
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(sockaddr)
|
||||
|
||||
sock.sendall(command)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* Trivial storage driver for example programs
|
||||
*
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -19,39 +18,32 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "example-storage"
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
#include <libfprint/fpi-compat.h>
|
||||
#include "storage.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
#define STORAGE_FILE "test-storage.variant"
|
||||
|
||||
static char *
|
||||
get_print_data_descriptor (FpPrint *print, FpDevice *dev, FpFinger finger)
|
||||
get_print_data_descriptor (struct fp_print_data *data, struct fp_dev *dev, enum fp_finger finger)
|
||||
{
|
||||
const char *driver;
|
||||
const char *dev_id;
|
||||
gint drv_id;
|
||||
gint devtype;
|
||||
|
||||
if (print)
|
||||
{
|
||||
driver = fp_print_get_driver (print);
|
||||
dev_id = fp_print_get_device_id (print);
|
||||
}
|
||||
else
|
||||
{
|
||||
driver = fp_device_get_driver (dev);
|
||||
dev_id = fp_device_get_device_id (dev);
|
||||
if (data) {
|
||||
drv_id = fp_print_data_get_driver_id (data);
|
||||
devtype = fp_print_data_get_devtype (data);
|
||||
} else {
|
||||
drv_id = fp_driver_get_driver_id(fp_dev_get_driver (dev));
|
||||
devtype = fp_dev_get_devtype (dev);
|
||||
}
|
||||
|
||||
return g_strdup_printf ("%s/%s/%x",
|
||||
driver,
|
||||
dev_id,
|
||||
return g_strdup_printf("%x/%08x/%x",
|
||||
drv_id,
|
||||
devtype,
|
||||
finger);
|
||||
}
|
||||
|
||||
@@ -61,20 +53,14 @@ load_data (void)
|
||||
GVariantDict *res;
|
||||
GVariant *var;
|
||||
gchar *contents = NULL;
|
||||
gsize length = 0;
|
||||
gssize length = 0;
|
||||
|
||||
if (!g_file_get_contents (STORAGE_FILE, &contents, &length, NULL))
|
||||
{
|
||||
if (!g_file_get_contents (STORAGE_FILE, &contents, &length, NULL)) {
|
||||
g_warning ("Error loading storage, assuming it is empty");
|
||||
return g_variant_dict_new(NULL);
|
||||
}
|
||||
|
||||
var = g_variant_new_from_data (G_VARIANT_TYPE_VARDICT,
|
||||
contents,
|
||||
length,
|
||||
FALSE,
|
||||
g_free,
|
||||
contents);
|
||||
var = g_variant_new_from_data (G_VARIANT_TYPE_VARDICT, contents, length, FALSE, NULL, NULL);
|
||||
|
||||
res = g_variant_dict_new(var);
|
||||
g_variant_unref(var);
|
||||
@@ -90,8 +76,7 @@ save_data (GVariant *data)
|
||||
length = g_variant_get_size(data);
|
||||
contents = (gchar*) g_variant_get_data (data);
|
||||
|
||||
if (!g_file_set_contents (STORAGE_FILE, contents, length, NULL))
|
||||
{
|
||||
if (!g_file_set_contents (STORAGE_FILE, contents, length, NULL)) {
|
||||
g_warning ("Error saving storage,!");
|
||||
return -1;
|
||||
}
|
||||
@@ -103,132 +88,49 @@ save_data (GVariant *data)
|
||||
}
|
||||
|
||||
int
|
||||
print_data_save (FpPrint *print, FpFinger finger)
|
||||
print_data_save(struct fp_print_data *fp_data, enum fp_finger finger)
|
||||
{
|
||||
g_autofree gchar *descr = get_print_data_descriptor (print, NULL, finger);
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariantDict) dict = NULL;
|
||||
g_autofree guchar *data = NULL;
|
||||
gchar *descr = get_print_data_descriptor (fp_data, NULL, finger);
|
||||
GVariantDict *dict;
|
||||
GVariant *val;
|
||||
guchar *data;
|
||||
gsize size;
|
||||
int res;
|
||||
|
||||
dict = load_data();
|
||||
|
||||
fp_print_serialize (print, &data, &size, &error);
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Error serializing data: %s", error->message);
|
||||
return -1;
|
||||
}
|
||||
size = fp_print_data_get_data(fp_data, &data);
|
||||
val = g_variant_new_fixed_array (G_VARIANT_TYPE("y"), data, size, 1);
|
||||
g_variant_dict_insert_value (dict, descr, val);
|
||||
|
||||
res = save_data(g_variant_dict_end(dict));
|
||||
g_variant_dict_unref(dict);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
FpPrint *
|
||||
print_data_load (FpDevice *dev, FpFinger finger)
|
||||
struct fp_print_data*
|
||||
print_data_load(struct fp_dev *dev, enum fp_finger finger)
|
||||
{
|
||||
g_autofree gchar *descr = get_print_data_descriptor (NULL, dev, finger);
|
||||
|
||||
g_autoptr(GVariant) val = NULL;
|
||||
g_autoptr(GVariantDict) dict = NULL;
|
||||
const guchar *stored_data = NULL;
|
||||
gchar *descr = get_print_data_descriptor (NULL, dev, finger);
|
||||
GVariantDict *dict;
|
||||
guchar *stored_data;
|
||||
gsize stored_len;
|
||||
GVariant *val;
|
||||
struct fp_print_data *res = NULL;
|
||||
|
||||
dict = load_data();
|
||||
val = g_variant_dict_lookup_value (dict, descr, G_VARIANT_TYPE ("ay"));
|
||||
|
||||
if (val)
|
||||
{
|
||||
FpPrint *print;
|
||||
g_autoptr(GError) error = NULL;
|
||||
if (val) {
|
||||
stored_data = (guchar*) g_variant_get_fixed_array (val, &stored_len, 1);
|
||||
res = fp_print_data_from_data(stored_data, stored_len);
|
||||
|
||||
stored_data = (const guchar *) g_variant_get_fixed_array (val, &stored_len, 1);
|
||||
print = fp_print_deserialize (stored_data, stored_len, &error);
|
||||
|
||||
if (error)
|
||||
g_warning ("Error deserializing data: %s", error->message);
|
||||
|
||||
return print;
|
||||
g_variant_unref(val);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FpPrint *
|
||||
print_create_template (FpDevice *dev, FpFinger finger)
|
||||
{
|
||||
g_autoptr(GDateTime) datetime = NULL;
|
||||
g_autoptr(GDate) date = NULL;
|
||||
FpPrint *template = NULL;
|
||||
gint year, month, day;
|
||||
|
||||
template = fp_print_new (dev);
|
||||
fp_print_set_finger (template, finger);
|
||||
fp_print_set_username (template, g_get_user_name ());
|
||||
datetime = g_date_time_new_now_local ();
|
||||
g_date_time_get_ymd (datetime, &year, &month, &day);
|
||||
date = g_date_new_dmy (day, month, year);
|
||||
fp_print_set_enroll_date (template, date);
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
save_image_to_pgm (FpImage *img, const char *path)
|
||||
{
|
||||
FILE *fd = fopen (path, "w");
|
||||
size_t write_size;
|
||||
const guchar *data = fp_image_get_data (img, &write_size);
|
||||
int r;
|
||||
|
||||
if (!fd)
|
||||
{
|
||||
g_warning ("could not open '%s' for writing: %d", path, errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r = fprintf (fd, "P5 %d %d 255\n",
|
||||
fp_image_get_width (img), fp_image_get_height (img));
|
||||
if (r < 0)
|
||||
{
|
||||
fclose (fd);
|
||||
g_critical ("pgm header write failed, error %d", r);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r = fwrite (data, 1, write_size, fd);
|
||||
if (r < write_size)
|
||||
{
|
||||
fclose (fd);
|
||||
g_critical ("short write (%d)", r);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fclose (fd);
|
||||
g_debug ("written to '%s'", path);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
print_image_save (FpPrint *print, const char *path)
|
||||
{
|
||||
FpImage *img = NULL;
|
||||
|
||||
g_return_val_if_fail (FP_IS_PRINT (print), FALSE);
|
||||
g_return_val_if_fail (path != NULL, FALSE);
|
||||
|
||||
img = fp_print_get_image (print);
|
||||
|
||||
if (img)
|
||||
return save_image_to_pgm (img, path);
|
||||
|
||||
return FALSE;
|
||||
g_variant_dict_unref(dict);
|
||||
g_free(descr);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __STORAGE_H
|
||||
#define __STORAGE_H
|
||||
|
||||
int print_data_save (FpPrint *print,
|
||||
FpFinger finger);
|
||||
FpPrint * print_data_load (FpDevice *dev,
|
||||
FpFinger finger);
|
||||
FpPrint * print_create_template (FpDevice *dev,
|
||||
FpFinger finger);
|
||||
gboolean print_image_save (FpPrint *print,
|
||||
const char *path);
|
||||
int print_data_save(struct fp_print_data *fp_data, enum fp_finger finger);
|
||||
struct fp_print_data* print_data_load(struct fp_dev *dev, enum fp_finger finger);
|
||||
|
||||
#endif /* __STORAGE_H */
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Utilities for example programs
|
||||
*
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "example-utilities"
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
FpDevice *
|
||||
discover_device (GPtrArray * devices)
|
||||
{
|
||||
FpDevice *dev;
|
||||
int i;
|
||||
|
||||
if (!devices->len)
|
||||
return NULL;
|
||||
|
||||
if (devices->len == 1)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print ("Multiple devices found, choose one\n");
|
||||
|
||||
for (i = 0; i < devices->len; ++i)
|
||||
{
|
||||
dev = g_ptr_array_index (devices, i);
|
||||
g_print ("[%d] %s (%s) - driver %s\n", i,
|
||||
fp_device_get_device_id (dev), fp_device_get_name (dev),
|
||||
fp_device_get_driver (dev));
|
||||
}
|
||||
|
||||
g_print ("> ");
|
||||
if (!scanf ("%d%*c", &i))
|
||||
return NULL;
|
||||
|
||||
if (i < 0 || i >= devices->len)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev = g_ptr_array_index (devices, i);
|
||||
g_print ("Selected device %s (%s) claimed by %s driver\n",
|
||||
fp_device_get_device_id (dev), fp_device_get_name (dev),
|
||||
fp_device_get_driver (dev));
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
const char *
|
||||
finger_to_string (FpFinger finger)
|
||||
{
|
||||
switch (finger)
|
||||
{
|
||||
case FP_FINGER_LEFT_THUMB:
|
||||
return "left thumb";
|
||||
|
||||
case FP_FINGER_LEFT_INDEX:
|
||||
return "left index";
|
||||
|
||||
case FP_FINGER_LEFT_MIDDLE:
|
||||
return "left middle";
|
||||
|
||||
case FP_FINGER_LEFT_RING:
|
||||
return "left ring";
|
||||
|
||||
case FP_FINGER_LEFT_LITTLE:
|
||||
return "left little";
|
||||
|
||||
case FP_FINGER_RIGHT_THUMB:
|
||||
return "right thumb";
|
||||
|
||||
case FP_FINGER_RIGHT_INDEX:
|
||||
return "right index";
|
||||
|
||||
case FP_FINGER_RIGHT_MIDDLE:
|
||||
return "right middle";
|
||||
|
||||
case FP_FINGER_RIGHT_RING:
|
||||
return "right ring";
|
||||
|
||||
case FP_FINGER_RIGHT_LITTLE:
|
||||
return "right little";
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
FpFinger
|
||||
finger_chooser (void)
|
||||
{
|
||||
int i = FP_FINGER_UNKNOWN;
|
||||
|
||||
for (i = FP_FINGER_FIRST; i <= FP_FINGER_LAST; ++i)
|
||||
g_print (" [%d] %s\n", (i - FP_FINGER_FIRST), finger_to_string (i));
|
||||
|
||||
g_print ("> ");
|
||||
if (!scanf ("%d%*c", &i))
|
||||
return FP_FINGER_UNKNOWN;
|
||||
|
||||
i += FP_FINGER_FIRST;
|
||||
|
||||
if (i < FP_FINGER_FIRST || i > FP_FINGER_LAST)
|
||||
return FP_FINGER_UNKNOWN;
|
||||
|
||||
return i;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Trivial storage driver for example programs
|
||||
*
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
FpDevice * discover_device (GPtrArray *devices);
|
||||
FpFinger finger_chooser (void);
|
||||
const char * finger_to_string (FpFinger finger);
|
||||
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* Example fingerprint verification program, which verifies the
|
||||
* Example fingerprint verification program, which verifies the right index
|
||||
* finger which has been previously enrolled to disk.
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -19,298 +18,132 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "example-verify"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
#include "storage.h"
|
||||
#include "utilities.h"
|
||||
|
||||
typedef struct _VerifyData
|
||||
struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
|
||||
{
|
||||
GMainLoop *loop;
|
||||
FpFinger finger;
|
||||
int ret_value;
|
||||
} VerifyData;
|
||||
struct fp_dscv_dev *ddev = discovered_devs[0];
|
||||
struct fp_driver *drv;
|
||||
if (!ddev)
|
||||
return NULL;
|
||||
|
||||
static void
|
||||
verify_data_free (VerifyData *verify_data)
|
||||
{
|
||||
g_main_loop_unref (verify_data->loop);
|
||||
g_free (verify_data);
|
||||
}
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (VerifyData, verify_data_free)
|
||||
|
||||
static void
|
||||
on_device_closed (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||
{
|
||||
VerifyData *verify_data = user_data;
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
fp_device_close_finish (dev, res, &error);
|
||||
|
||||
if (error)
|
||||
g_warning ("Failed closing device %s\n", error->message);
|
||||
|
||||
g_main_loop_quit (verify_data->loop);
|
||||
drv = fp_dscv_dev_get_driver(ddev);
|
||||
printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
|
||||
return ddev;
|
||||
}
|
||||
|
||||
static void
|
||||
verify_quit (FpDevice *dev,
|
||||
VerifyData *verify_data)
|
||||
int verify(struct fp_dev *dev, struct fp_print_data *data)
|
||||
{
|
||||
if (!fp_device_is_open (dev))
|
||||
{
|
||||
g_main_loop_quit (verify_data->loop);
|
||||
return;
|
||||
int r;
|
||||
|
||||
do {
|
||||
struct fp_img *img = NULL;
|
||||
|
||||
sleep(1);
|
||||
printf("\nScan your finger now.\n");
|
||||
r = fp_verify_finger_img(dev, data, &img);
|
||||
if (img) {
|
||||
fp_img_save_to_file(img, "verify.pgm");
|
||||
printf("Wrote scanned image to verify.pgm\n");
|
||||
fp_img_free(img);
|
||||
}
|
||||
if (r < 0) {
|
||||
printf("verification failed with error %d :(\n", r);
|
||||
return r;
|
||||
}
|
||||
switch (r) {
|
||||
case FP_VERIFY_NO_MATCH:
|
||||
printf("NO MATCH!\n");
|
||||
return 0;
|
||||
case FP_VERIFY_MATCH:
|
||||
printf("MATCH!\n");
|
||||
return 0;
|
||||
case FP_VERIFY_RETRY:
|
||||
printf("Scan didn't quite work. Please try again.\n");
|
||||
break;
|
||||
case FP_VERIFY_RETRY_TOO_SHORT:
|
||||
printf("Swipe was too short, please try again.\n");
|
||||
break;
|
||||
case FP_VERIFY_RETRY_CENTER_FINGER:
|
||||
printf("Please center your finger on the sensor and try again.\n");
|
||||
break;
|
||||
case FP_VERIFY_RETRY_REMOVE_FINGER:
|
||||
printf("Please remove finger from the sensor and try again.\n");
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
fp_device_close (dev, NULL, (GAsyncReadyCallback) on_device_closed, verify_data);
|
||||
}
|
||||
|
||||
static void start_verification (FpDevice *dev,
|
||||
VerifyData *verify_data);
|
||||
|
||||
static void
|
||||
on_verify_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||
int main(void)
|
||||
{
|
||||
VerifyData *verify_data = user_data;
|
||||
|
||||
g_autoptr(FpPrint) print = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
char buffer[20];
|
||||
gboolean match;
|
||||
|
||||
if (!fp_device_verify_finish (dev, res, &match, &print, &error))
|
||||
{
|
||||
g_warning ("Failed to verify print: %s", error->message);
|
||||
verify_data->ret_value = EXIT_FAILURE;
|
||||
|
||||
if (error->domain != FP_DEVICE_RETRY)
|
||||
{
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
g_print ("Verify again? [Y/n]? ");
|
||||
if (fgets (buffer, sizeof (buffer), stdin) &&
|
||||
(buffer[0] == 'Y' || buffer[0] == 'y' || buffer[0] == '\n'))
|
||||
{
|
||||
start_verification (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
||||
verify_quit (dev, verify_data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_match_cb (FpDevice *dev, FpPrint *match, FpPrint *print,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
VerifyData *verify_data = user_data;
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Match report: Finger not matched, retry error reported: %s",
|
||||
error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (print && fp_device_supports_capture (dev) &&
|
||||
print_image_save (print, "verify.pgm"))
|
||||
g_print ("Print image saved as verify.pgm\n");
|
||||
|
||||
if (match)
|
||||
{
|
||||
char date_str[128];
|
||||
|
||||
verify_data->ret_value = EXIT_SUCCESS;
|
||||
|
||||
g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0",
|
||||
fp_print_get_enroll_date (match));
|
||||
g_debug ("Match report: device %s matched finger %s successifully "
|
||||
"with print %s, enrolled on date %s by user %s",
|
||||
fp_device_get_name (dev),
|
||||
finger_to_string (fp_print_get_finger (match)),
|
||||
fp_print_get_description (match), date_str,
|
||||
fp_print_get_username (match));
|
||||
|
||||
g_print ("MATCH!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
g_debug ("Match report: Finger not matched");
|
||||
g_print ("NO MATCH!\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
VerifyData *verify_data = user_data;
|
||||
|
||||
g_autoptr(GPtrArray) prints = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
prints = fp_device_list_prints_finish (dev, res, &error);
|
||||
|
||||
if (!error)
|
||||
{
|
||||
FpPrint *verify_print = NULL;
|
||||
guint i;
|
||||
|
||||
if (!prints->len)
|
||||
g_warning ("No prints saved on device");
|
||||
|
||||
for (i = 0; i < prints->len; ++i)
|
||||
{
|
||||
FpPrint *print = prints->pdata[i];
|
||||
|
||||
if (fp_print_get_finger (print) == verify_data->finger &&
|
||||
g_strcmp0 (fp_print_get_username (print), g_get_user_name ()) == 0)
|
||||
{
|
||||
const GDate *verify_print_date = NULL;
|
||||
const GDate *print_date = fp_print_get_enroll_date (print);
|
||||
|
||||
if (verify_print)
|
||||
verify_print_date = fp_print_get_enroll_date (verify_print);
|
||||
|
||||
if (!verify_print || !print_date || !verify_print_date ||
|
||||
g_date_compare (print_date, verify_print_date) >= 0)
|
||||
verify_print = print;
|
||||
}
|
||||
}
|
||||
|
||||
if (!verify_print)
|
||||
{
|
||||
g_warning ("Did you remember to enroll your %s finger first?",
|
||||
finger_to_string (verify_data->finger));
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
||||
g_debug ("Comparing print with %s",
|
||||
fp_print_get_description (verify_print));
|
||||
|
||||
g_print ("Print loaded. Time to verify!\n");
|
||||
fp_device_verify (dev, verify_print, NULL,
|
||||
on_match_cb, verify_data, NULL,
|
||||
(GAsyncReadyCallback) on_verify_completed,
|
||||
verify_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("Loading prints failed with error %s", error->message);
|
||||
verify_quit (dev, verify_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
start_verification (FpDevice *dev, VerifyData *verify_data)
|
||||
{
|
||||
if (verify_data->finger == FP_FINGER_UNKNOWN)
|
||||
{
|
||||
g_print ("Choose the finger to verify:\n");
|
||||
verify_data->finger = finger_chooser ();
|
||||
}
|
||||
|
||||
if (verify_data->finger == FP_FINGER_UNKNOWN)
|
||||
{
|
||||
g_warning ("Unknown finger selected");
|
||||
verify_data->ret_value = EXIT_FAILURE;
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fp_device_has_storage (dev))
|
||||
{
|
||||
g_print ("Creating finger template, using device storage...\n");
|
||||
fp_device_list_prints (dev, NULL,
|
||||
(GAsyncReadyCallback) on_list_completed,
|
||||
verify_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_print ("Loading previously enrolled %s finger data...\n",
|
||||
finger_to_string (verify_data->finger));
|
||||
g_autoptr(FpPrint) verify_print = NULL;
|
||||
|
||||
verify_print = print_data_load (dev, verify_data->finger);
|
||||
|
||||
if (!verify_print)
|
||||
{
|
||||
g_warning ("Failed to load fingerprint data");
|
||||
g_warning ("Did you remember to enroll your %s finger first?",
|
||||
finger_to_string (verify_data->finger));
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
||||
g_print ("Print loaded. Time to verify!\n");
|
||||
fp_device_verify (dev, verify_print, NULL,
|
||||
NULL, NULL, NULL,
|
||||
(GAsyncReadyCallback) on_verify_completed,
|
||||
verify_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_device_opened (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||
{
|
||||
VerifyData *verify_data = user_data;
|
||||
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!fp_device_open_finish (dev, res, &error))
|
||||
{
|
||||
g_warning ("Failed to open device: %s", error->message);
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
||||
g_print ("Opened device. ");
|
||||
|
||||
start_verification (dev, verify_data);
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
g_autoptr(FpContext) ctx = NULL;
|
||||
g_autoptr(VerifyData) verify_data = NULL;
|
||||
GPtrArray *devices;
|
||||
FpDevice *dev;
|
||||
int r = 1;
|
||||
struct fp_dscv_dev *ddev;
|
||||
struct fp_dscv_dev **discovered_devs;
|
||||
struct fp_dev *dev;
|
||||
struct fp_print_data *data;
|
||||
|
||||
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
||||
setenv ("LIBUSB_DEBUG", "3", 0);
|
||||
|
||||
ctx = fp_context_new ();
|
||||
|
||||
devices = fp_context_get_devices (ctx);
|
||||
if (!devices)
|
||||
{
|
||||
g_warning ("Impossible to get devices");
|
||||
return EXIT_FAILURE;
|
||||
r = fp_init();
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Failed to initialize libfprint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dev = discover_device (devices);
|
||||
if (!dev)
|
||||
{
|
||||
g_warning ("No devices detected.");
|
||||
return EXIT_FAILURE;
|
||||
discovered_devs = fp_discover_devs();
|
||||
if (!discovered_devs) {
|
||||
fprintf(stderr, "Could not discover devices\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
verify_data = g_new0 (VerifyData, 1);
|
||||
verify_data->ret_value = EXIT_FAILURE;
|
||||
verify_data->loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
fp_device_open (dev, NULL, (GAsyncReadyCallback) on_device_opened,
|
||||
verify_data);
|
||||
|
||||
g_main_loop_run (verify_data->loop);
|
||||
|
||||
return verify_data->ret_value;
|
||||
ddev = discover_device(discovered_devs);
|
||||
if (!ddev) {
|
||||
fprintf(stderr, "No devices detected.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev = fp_dev_open(ddev);
|
||||
fp_dscv_devs_free(discovered_devs);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "Could not open device.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Opened device. Loading previously enrolled right index finger "
|
||||
"data...\n");
|
||||
|
||||
data = print_data_load(dev, RIGHT_INDEX);
|
||||
if (!data) {
|
||||
fprintf(stderr, "Failed to load fingerprint, error %d\n", r);
|
||||
fprintf(stderr, "Did you remember to enroll your right index finger "
|
||||
"first?\n");
|
||||
goto out_close;
|
||||
}
|
||||
|
||||
printf("Print loaded. Time to verify!\n");
|
||||
do {
|
||||
char buffer[20];
|
||||
|
||||
verify(dev, data);
|
||||
printf("Verify again? [Y/n]? ");
|
||||
fgets(buffer, sizeof(buffer), stdin);
|
||||
if (buffer[0] != '\n' && buffer[0] != 'y' && buffer[0] != 'Y')
|
||||
break;
|
||||
} while (1);
|
||||
|
||||
fp_print_data_free(data);
|
||||
out_close:
|
||||
fp_dev_close(dev);
|
||||
out:
|
||||
fp_exit();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
188
examples/verify_live.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Example fingerprint verification program
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
|
||||
struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
|
||||
{
|
||||
struct fp_dscv_dev *ddev = discovered_devs[0];
|
||||
struct fp_driver *drv;
|
||||
if (!ddev)
|
||||
return NULL;
|
||||
|
||||
drv = fp_dscv_dev_get_driver(ddev);
|
||||
printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
|
||||
return ddev;
|
||||
}
|
||||
|
||||
struct fp_print_data *enroll(struct fp_dev *dev) {
|
||||
struct fp_print_data *enrolled_print = NULL;
|
||||
int r;
|
||||
|
||||
printf("You will need to successfully scan your finger %d times to "
|
||||
"complete the process.\n", fp_dev_get_nr_enroll_stages(dev));
|
||||
|
||||
do {
|
||||
printf("\nScan your finger now.\n");
|
||||
r = fp_enroll_finger(dev, &enrolled_print);
|
||||
if (r < 0) {
|
||||
printf("Enroll failed with error %d\n", r);
|
||||
return NULL;
|
||||
}
|
||||
switch (r) {
|
||||
case FP_ENROLL_COMPLETE:
|
||||
printf("Enroll complete!\n");
|
||||
break;
|
||||
case FP_ENROLL_FAIL:
|
||||
printf("Enroll failed, something wen't wrong :(\n");
|
||||
return NULL;
|
||||
case FP_ENROLL_PASS:
|
||||
printf("Enroll stage passed. Yay!\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY:
|
||||
printf("Didn't quite catch that. Please try again.\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY_TOO_SHORT:
|
||||
printf("Your swipe was too short, please try again.\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY_CENTER_FINGER:
|
||||
printf("Didn't catch that, please center your finger on the "
|
||||
"sensor and try again.\n");
|
||||
break;
|
||||
case FP_ENROLL_RETRY_REMOVE_FINGER:
|
||||
printf("Scan failed, please remove your finger and then try "
|
||||
"again.\n");
|
||||
break;
|
||||
}
|
||||
} while (r != FP_ENROLL_COMPLETE);
|
||||
|
||||
if (!enrolled_print) {
|
||||
fprintf(stderr, "Enroll complete but no print?\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf("Enrollment completed!\n\n");
|
||||
return enrolled_print;
|
||||
}
|
||||
|
||||
int verify(struct fp_dev *dev, struct fp_print_data *data)
|
||||
{
|
||||
int r;
|
||||
|
||||
do {
|
||||
sleep(1);
|
||||
printf("\nScan your finger now.\n");
|
||||
r = fp_verify_finger(dev, data);
|
||||
if (r < 0) {
|
||||
printf("verification failed with error %d :(\n", r);
|
||||
return r;
|
||||
}
|
||||
switch (r) {
|
||||
case FP_VERIFY_NO_MATCH:
|
||||
printf("NO MATCH!\n");
|
||||
return 0;
|
||||
case FP_VERIFY_MATCH:
|
||||
printf("MATCH!\n");
|
||||
return 0;
|
||||
case FP_VERIFY_RETRY:
|
||||
printf("Scan didn't quite work. Please try again.\n");
|
||||
break;
|
||||
case FP_VERIFY_RETRY_TOO_SHORT:
|
||||
printf("Swipe was too short, please try again.\n");
|
||||
break;
|
||||
case FP_VERIFY_RETRY_CENTER_FINGER:
|
||||
printf("Please center your finger on the sensor and try again.\n");
|
||||
break;
|
||||
case FP_VERIFY_RETRY_REMOVE_FINGER:
|
||||
printf("Please remove finger from the sensor and try again.\n");
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int r = 1;
|
||||
struct fp_dscv_dev *ddev;
|
||||
struct fp_dscv_dev **discovered_devs;
|
||||
struct fp_dev *dev;
|
||||
struct fp_print_data *data;
|
||||
|
||||
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
||||
setenv ("LIBUSB_DEBUG", "3", 0);
|
||||
|
||||
r = fp_init();
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Failed to initialize libfprint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
discovered_devs = fp_discover_devs();
|
||||
if (!discovered_devs) {
|
||||
fprintf(stderr, "Could not discover devices\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ddev = discover_device(discovered_devs);
|
||||
if (!ddev) {
|
||||
fprintf(stderr, "No devices detected.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev = fp_dev_open(ddev);
|
||||
fp_dscv_devs_free(discovered_devs);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "Could not open device.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Opened device. It's now time to enroll your finger.\n\n");
|
||||
data = enroll(dev);
|
||||
if (!data)
|
||||
goto out_close;
|
||||
|
||||
|
||||
printf("Normally we'd save that print to disk, and recall it at some "
|
||||
"point later when we want to authenticate the user who just "
|
||||
"enrolled. In the interests of demonstration, we'll authenticate "
|
||||
"that user immediately.\n");
|
||||
|
||||
do {
|
||||
char buffer[20];
|
||||
|
||||
verify(dev, data);
|
||||
printf("Verify again? [Y/n]? ");
|
||||
fgets(buffer, sizeof(buffer), stdin);
|
||||
if (buffer[0] != '\n' && buffer[0] != 'y' && buffer[0] != 'Y')
|
||||
break;
|
||||
} while (1);
|
||||
|
||||
fp_print_data_free(data);
|
||||
out_close:
|
||||
fp_dev_close(dev);
|
||||
out:
|
||||
fp_exit();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,9 @@
|
||||
#include "drivers_api.h"
|
||||
#include "aeslib.h"
|
||||
|
||||
static void start_capture (FpImageDevice *dev);
|
||||
static void complete_deactivation (FpImageDevice *dev);
|
||||
static int adjust_gain (unsigned char *buffer,
|
||||
int status);
|
||||
static void start_capture(struct fp_img_dev *dev);
|
||||
static void complete_deactivation(struct fp_img_dev *dev);
|
||||
static int adjust_gain(unsigned char *buffer, int status);
|
||||
|
||||
#define FIRST_AES1610_REG 0x1B
|
||||
#define LAST_AES1610_REG 0xFF
|
||||
@@ -40,8 +39,8 @@ static int adjust_gain (unsigned char *buffer,
|
||||
#define GAIN_STATUS_NORMAL 2
|
||||
|
||||
/* FIXME these need checking */
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
|
||||
#define BULK_TIMEOUT 4000
|
||||
|
||||
@@ -70,19 +69,13 @@ static int adjust_gain (unsigned char *buffer,
|
||||
|
||||
/****** GENERAL FUNCTIONS ******/
|
||||
|
||||
struct _FpiDeviceAes1610
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
guint8 read_regs_retry_count;
|
||||
struct aes1610_dev {
|
||||
uint8_t read_regs_retry_count;
|
||||
GSList *strips;
|
||||
gsize strips_len;
|
||||
size_t strips_len;
|
||||
gboolean deactivating;
|
||||
guint8 blanks_count;
|
||||
uint8_t blanks_count;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceAes1610, fpi_device_aes1610, FPI, DEVICE_AES1610,
|
||||
FpImageDevice);
|
||||
G_DEFINE_TYPE (FpiDeviceAes1610, fpi_device_aes1610, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.frame_width = FRAME_WIDTH,
|
||||
@@ -91,58 +84,67 @@ static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.get_pixel = aes_get_pixel,
|
||||
};
|
||||
|
||||
typedef void (*aes1610_read_regs_cb)(FpImageDevice *dev,
|
||||
int status,
|
||||
unsigned char *regs,
|
||||
void *user_data);
|
||||
typedef void (*aes1610_read_regs_cb)(struct fp_img_dev *dev, int status,
|
||||
unsigned char *regs, void *user_data);
|
||||
|
||||
struct aes1610_read_regs
|
||||
{
|
||||
FpImageDevice *dev;
|
||||
struct aes1610_read_regs {
|
||||
struct fp_img_dev *dev;
|
||||
aes1610_read_regs_cb callback;
|
||||
struct aes_regwrite *regwrite;
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
/* FIXME: what to do here? */
|
||||
static void
|
||||
stub_capture_stop_cb (FpImageDevice *dev, GError *error,
|
||||
void *user_data)
|
||||
static void stub_capture_stop_cb(struct fp_img_dev *dev, int result, void *user_data)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
fp_warn ("Error stopping capture: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
generic_write_regv_cb (FpImageDevice *dev, GError *error,
|
||||
|
||||
/* check that read succeeded but ignore all data */
|
||||
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_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);
|
||||
}
|
||||
|
||||
static void generic_write_regv_cb(struct fp_img_dev *dev, int result,
|
||||
void *user_data)
|
||||
{
|
||||
FpiSsm *ssm = user_data;
|
||||
|
||||
if (!error)
|
||||
fpi_ssm *ssm = user_data;
|
||||
if (result == 0)
|
||||
fpi_ssm_next_state(ssm);
|
||||
else
|
||||
fpi_ssm_mark_failed (ssm, error);
|
||||
fpi_ssm_mark_failed(ssm, 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 (FpiSsm *ssm, FpDevice *dev,
|
||||
size_t bytes)
|
||||
static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes)
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
data = g_malloc(bytes);
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_IN, data, bytes, g_free);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes,
|
||||
generic_ignore_data_cb, ssm, BULK_TIMEOUT);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
|
||||
/****** FINGER PRESENCE DETECTION ******/
|
||||
@@ -173,67 +175,72 @@ static const struct aes_regwrite finger_det_reqs[] = {
|
||||
{ 0x81, 0x04 }
|
||||
};
|
||||
|
||||
static void start_finger_detection (FpImageDevice *dev);
|
||||
static void start_finger_detection(struct fp_img_dev *dev);
|
||||
|
||||
static void
|
||||
finger_det_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void finger_det_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
struct fp_img_dev *dev = transfer->user_data;
|
||||
unsigned char *data = transfer->buffer;
|
||||
int i;
|
||||
int sum = 0;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
return;
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_imgdev_session_error(dev, -EIO);
|
||||
goto out;
|
||||
} else if (transfer->length != transfer->actual_length) {
|
||||
fpi_imgdev_session_error(dev, -EPROTO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* examine histogram to determine finger presence */
|
||||
for (i = 3; i < 17; i++)
|
||||
sum += (data[i] & 0xf) + (data[i] >> 4);
|
||||
if (sum > 20)
|
||||
{
|
||||
if (sum > 20) {
|
||||
/* reset default gain */
|
||||
adjust_gain(data,GAIN_STATUS_FIRST);
|
||||
/* finger present, start capturing */
|
||||
fpi_image_device_report_finger_status (dev, TRUE);
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
start_capture(dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* 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 (FpImageDevice *dev, GError *error,
|
||||
void *user_data)
|
||||
static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, void *user_data)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
struct libusb_transfer *transfer;
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
if (result) {
|
||||
fpi_imgdev_session_error(dev, result);
|
||||
return;
|
||||
}
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, FINGER_DETECTION_LEN);
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
finger_det_data_cb, NULL);
|
||||
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);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
}
|
||||
|
||||
static void
|
||||
start_finger_detection (FpImageDevice *dev)
|
||||
{
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (dev);
|
||||
}
|
||||
|
||||
if (self->deactivating)
|
||||
static void start_finger_detection(struct fp_img_dev *dev)
|
||||
{
|
||||
struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
if (aesdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
@@ -397,42 +404,36 @@ static unsigned char list_BD_values[10] = {
|
||||
/*
|
||||
* Adjust the gain according to the histogram data
|
||||
* 0xbd, 0xbe, 0x29 and 0x2A registers are affected
|
||||
* Returns 0 if no problem occurred
|
||||
* Returns 0 if no problem occured
|
||||
* TODO: This is a basic support for gain. It needs testing/tweaking. */
|
||||
static int
|
||||
adjust_gain (unsigned char *buffer, int status)
|
||||
static int adjust_gain(unsigned char *buffer, int status)
|
||||
{
|
||||
// The position in the array of possible values for 0xBE and 0xBD registers
|
||||
static int pos_list_BE = 0;
|
||||
static int pos_list_BD = 0;
|
||||
|
||||
// This is the first adjustment (we begin acquisition)
|
||||
// This is the first adjustement (we begin acquisition)
|
||||
// We adjust strip_scan_reqs for future strips and capture_reqs that is sent just after this step
|
||||
if (status == GAIN_STATUS_FIRST)
|
||||
{
|
||||
if (buffer[1] > 0x78) // maximum gain needed
|
||||
{
|
||||
if (status == GAIN_STATUS_FIRST) {
|
||||
if (buffer[1] > 0x78) { // maximum gain needed
|
||||
strip_scan_reqs[0].value = 0x6B;
|
||||
strip_scan_reqs[1].value = 0x06;
|
||||
strip_scan_reqs[2].value = 0x35;
|
||||
strip_scan_reqs[3].value = 0x4B;
|
||||
}
|
||||
else if (buffer[1] > 0x55)
|
||||
{
|
||||
else if (buffer[1] > 0x55) {
|
||||
strip_scan_reqs[0].value = 0x63;
|
||||
strip_scan_reqs[1].value = 0x15;
|
||||
strip_scan_reqs[2].value = 0x35;
|
||||
strip_scan_reqs[3].value = 0x3b;
|
||||
}
|
||||
else if (buffer[1] > 0x40 || buffer[16] > 0x19)
|
||||
{
|
||||
else if (buffer[1] > 0x40 || buffer[16] > 0x19) {
|
||||
strip_scan_reqs[0].value = 0x43;
|
||||
strip_scan_reqs[1].value = 0x13;
|
||||
strip_scan_reqs[2].value = 0x35;
|
||||
strip_scan_reqs[3].value = 0x30;
|
||||
}
|
||||
else // minimum gain needed
|
||||
{
|
||||
else { // minimum gain needed
|
||||
strip_scan_reqs[0].value = 0x23;
|
||||
strip_scan_reqs[1].value = 0x07;
|
||||
strip_scan_reqs[2].value = 0x35;
|
||||
@@ -447,13 +448,12 @@ adjust_gain (unsigned char *buffer, int status)
|
||||
|
||||
fp_dbg("first gain: %x %x %x %x %x %x %x %x", strip_scan_reqs[0].reg, strip_scan_reqs[0].value, strip_scan_reqs[1].reg, strip_scan_reqs[1].value, strip_scan_reqs[2].reg, strip_scan_reqs[2].value, strip_scan_reqs[3].reg, strip_scan_reqs[3].value);
|
||||
}
|
||||
|
||||
// Every 2/3 strips
|
||||
// We try to soften big changes of the gain (at least for 0xBE and 0xBD
|
||||
// FIXME: This softenning will need testing and tweaking too
|
||||
else if (status == GAIN_STATUS_NORMAL)
|
||||
{
|
||||
if (buffer[514] > 0x78) // maximum gain needed
|
||||
{
|
||||
else if (status == GAIN_STATUS_NORMAL) {
|
||||
if (buffer[514] > 0x78) { // maximum gain needed
|
||||
if (pos_list_BE < 7)
|
||||
pos_list_BE++;
|
||||
|
||||
@@ -463,8 +463,7 @@ adjust_gain (unsigned char *buffer, int status)
|
||||
strip_scan_reqs[1].value = 0x04;
|
||||
strip_scan_reqs[2].value = 0x35;
|
||||
}
|
||||
else if (buffer[514] > 0x55)
|
||||
{
|
||||
else if (buffer[514] > 0x55) {
|
||||
if (pos_list_BE < 2)
|
||||
pos_list_BE++;
|
||||
else if (pos_list_BE > 2)
|
||||
@@ -478,8 +477,7 @@ adjust_gain (unsigned char *buffer, int status)
|
||||
strip_scan_reqs[1].value = 0x15;
|
||||
strip_scan_reqs[2].value = 0x35;
|
||||
}
|
||||
else if (buffer[514] > 0x40 || buffer[529] > 0x19)
|
||||
{
|
||||
else if (buffer[514] > 0x40 || buffer[529] > 0x19) {
|
||||
if (pos_list_BE < 1)
|
||||
pos_list_BE++;
|
||||
else if (pos_list_BE > 1)
|
||||
@@ -493,8 +491,7 @@ adjust_gain (unsigned char *buffer, int status)
|
||||
strip_scan_reqs[1].value = 0x13;
|
||||
strip_scan_reqs[2].value = 0x35;
|
||||
}
|
||||
else // minimum gain needed
|
||||
{
|
||||
else { // minimum gain needed
|
||||
if (pos_list_BE > 0)
|
||||
pos_list_BE--;
|
||||
|
||||
@@ -511,8 +508,7 @@ adjust_gain (unsigned char *buffer, int status)
|
||||
fp_dbg("gain: %x %x %x %x %x %x %x %x", strip_scan_reqs[0].reg, strip_scan_reqs[0].value, strip_scan_reqs[1].reg, strip_scan_reqs[1].value, strip_scan_reqs[2].reg, strip_scan_reqs[2].value, strip_scan_reqs[3].reg, strip_scan_reqs[3].value);
|
||||
}
|
||||
// Unknown status
|
||||
else
|
||||
{
|
||||
else {
|
||||
fp_err("Unexpected gain status.");
|
||||
return 1;
|
||||
}
|
||||
@@ -522,8 +518,7 @@ adjust_gain (unsigned char *buffer, int status)
|
||||
|
||||
/*
|
||||
* Restore the default gain values */
|
||||
static void
|
||||
restore_gain (void)
|
||||
static void restore_gain(void)
|
||||
{
|
||||
strip_scan_reqs[0].value = list_BE_values[0];
|
||||
strip_scan_reqs[1].value = 0x04;
|
||||
@@ -539,7 +534,7 @@ restore_gain (void)
|
||||
|
||||
/* capture SM movement:
|
||||
* request and read strip,
|
||||
* jump back to request UNLESS there's no finger, in which case exit SM,
|
||||
* jump back to request UNLESS theres no finger, in which case exit SM,
|
||||
* report lack of finger presence, and move to finger detection */
|
||||
|
||||
enum capture_states {
|
||||
@@ -550,167 +545,163 @@ enum capture_states {
|
||||
CAPTURE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
capture_read_strip_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void capture_read_strip_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
unsigned char *stripdata;
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (dev);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
unsigned char *data = transfer->buffer;
|
||||
gint sum, i;
|
||||
int sum, i;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
return;
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
} else if (transfer->length != transfer->actual_length) {
|
||||
fpi_ssm_mark_failed(ssm, -EPROTO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* FIXME: would preallocating strip buffers be a decent optimization? */
|
||||
|
||||
sum = 0;
|
||||
for (i = 516; i < 530; i++)
|
||||
{
|
||||
/* histogram[i] = number of pixels of value i
|
||||
Only the pixel values from 10 to 15 are used to detect finger. */
|
||||
sum += data[i];
|
||||
}
|
||||
|
||||
fp_dbg ("sum=%d", sum);
|
||||
if (sum > 0)
|
||||
{
|
||||
if (sum > 0) {
|
||||
/* FIXME: would preallocating strip buffers be a decent optimization? */
|
||||
struct fpi_frame *stripe = g_malloc(FRAME_WIDTH * (FRAME_HEIGHT / 2) + sizeof(struct fpi_frame));
|
||||
stripe->delta_x = 0;
|
||||
stripe->delta_y = 0;
|
||||
stripdata = stripe->data;
|
||||
memcpy(stripdata, data + 1, FRAME_WIDTH * (FRAME_HEIGHT / 2));
|
||||
self->strips = g_slist_prepend (self->strips, stripe);
|
||||
self->strips_len++;
|
||||
self->blanks_count = 0;
|
||||
aesdev->strips = g_slist_prepend(aesdev->strips, stripe);
|
||||
aesdev->strips_len++;
|
||||
aesdev->blanks_count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (sum < 0) {
|
||||
fpi_ssm_mark_failed(ssm, sum);
|
||||
goto out;
|
||||
}
|
||||
fp_dbg("sum=%d", sum);
|
||||
|
||||
/* FIXME: 0 might be too low as a threshold */
|
||||
/* FIXME: sometimes we get 0 in the middle of a scan, should we wait for
|
||||
* a few consecutive zeroes? */
|
||||
|
||||
/* sum cannot be negative, so is 0 */
|
||||
self->blanks_count++;
|
||||
/* If sum is 0 for a reasonable # of frames, finger has been removed */
|
||||
if (sum == 0) {
|
||||
aesdev->blanks_count++;
|
||||
fp_dbg("got blank frame");
|
||||
}
|
||||
|
||||
|
||||
/* use histogram data above for gain calibration (0xbd, 0xbe, 0x29 and 0x2A ) */
|
||||
adjust_gain(data, GAIN_STATUS_NORMAL);
|
||||
|
||||
/* stop capturing if MAX_FRAMES is reached */
|
||||
if (self->blanks_count > 10 || g_slist_length (self->strips) >= MAX_FRAMES)
|
||||
{
|
||||
FpImage *img;
|
||||
if (aesdev->blanks_count > 10 || g_slist_length(aesdev->strips) >= MAX_FRAMES) {
|
||||
struct fp_img *img;
|
||||
|
||||
fp_dbg ("sending stop capture.... blanks=%d frames=%d",
|
||||
self->blanks_count, g_slist_length (self->strips));
|
||||
fp_dbg("sending stop capture.... blanks=%d frames=%d", aesdev->blanks_count, g_slist_length(aesdev->strips));
|
||||
/* send stop capture bits */
|
||||
aes_write_regv(dev, capture_stop, G_N_ELEMENTS(capture_stop), stub_capture_stop_cb, NULL);
|
||||
self->strips = g_slist_reverse (self->strips);
|
||||
fpi_do_movement_estimation (&assembling_ctx, self->strips);
|
||||
img = fpi_assemble_frames (&assembling_ctx, self->strips);
|
||||
|
||||
g_slist_free_full (self->strips, g_free);
|
||||
self->strips = NULL;
|
||||
self->strips_len = 0;
|
||||
self->blanks_count = 0;
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
fpi_image_device_report_finger_status (dev, FALSE);
|
||||
aesdev->strips = g_slist_reverse(aesdev->strips);
|
||||
fpi_do_movement_estimation(&assembling_ctx, aesdev->strips, aesdev->strips_len);
|
||||
img = fpi_assemble_frames(&assembling_ctx, aesdev->strips, aesdev->strips_len);
|
||||
img->flags |= FP_IMG_PARTIAL;
|
||||
g_slist_free_full(aesdev->strips, g_free);
|
||||
aesdev->strips = NULL;
|
||||
aesdev->strips_len = 0;
|
||||
aesdev->blanks_count = 0;
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
/* marking machine complete will re-trigger finger detection loop */
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
/* Acquisition finished: restore default gain values */
|
||||
restore_gain();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* obtain next strip */
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_REQUEST_STRIP);
|
||||
}
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_REQUEST_STRIP);
|
||||
}
|
||||
|
||||
static void
|
||||
capture_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (_dev);
|
||||
out:
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
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(_dev);
|
||||
int r;
|
||||
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case CAPTURE_WRITE_REQS:
|
||||
fp_dbg("write reqs");
|
||||
aes_write_regv(dev, capture_reqs, G_N_ELEMENTS(capture_reqs),
|
||||
generic_write_regv_cb, ssm);
|
||||
break;
|
||||
|
||||
case CAPTURE_READ_DATA:
|
||||
fp_dbg("read data");
|
||||
generic_read_ignore_data(ssm, _dev, STRIP_CAPTURE_LEN);
|
||||
break;
|
||||
|
||||
case CAPTURE_REQUEST_STRIP:
|
||||
fp_dbg("request strip");
|
||||
if (self->deactivating)
|
||||
if (aesdev->deactivating)
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
else
|
||||
aes_write_regv(dev, strip_scan_reqs, G_N_ELEMENTS(strip_scan_reqs),
|
||||
generic_write_regv_cb, ssm);
|
||||
break;
|
||||
|
||||
case CAPTURE_READ_STRIP: ;
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (_dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, STRIP_CAPTURE_LEN);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
capture_read_strip_cb, NULL);
|
||||
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);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
break;
|
||||
}
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct aes1610_dev *aesdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
G_DEBUG_HERE();
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating)
|
||||
complete_deactivation(dev);
|
||||
if (error)
|
||||
g_error_free (error);
|
||||
}
|
||||
else if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
}
|
||||
else if (fpi_ssm_get_error(ssm))
|
||||
fpi_imgdev_session_error(dev, fpi_ssm_get_error(ssm));
|
||||
else
|
||||
{
|
||||
start_finger_detection(dev);
|
||||
}
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
start_capture (FpImageDevice *dev)
|
||||
static void start_capture(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (dev);
|
||||
FpiSsm *ssm;
|
||||
struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
|
||||
ssm = fpi_ssm_new (FP_DEVICE (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_start(ssm, capture_sm_complete);
|
||||
}
|
||||
@@ -732,15 +723,13 @@ enum activate_states {
|
||||
ACTIVATE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
activate_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
|
||||
/* activation on aes1610 seems much more straightforward compared to aes2501 */
|
||||
/* verify there's anything missing here */
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
/* verify theres anything missing here */
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case WRITE_INIT:
|
||||
fp_dbg("write init");
|
||||
aes_write_regv(dev, init, G_N_ELEMENTS(init), generic_write_regv_cb, ssm);
|
||||
@@ -749,110 +738,100 @@ activate_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
}
|
||||
|
||||
/* jump to finger detection */
|
||||
static void
|
||||
activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
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));
|
||||
|
||||
fpi_image_device_activate_complete (dev, error);
|
||||
|
||||
if (!error)
|
||||
if (!fpi_ssm_get_error(ssm))
|
||||
start_finger_detection(dev);
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (dev);
|
||||
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES);
|
||||
|
||||
self->read_regs_retry_count = 0;
|
||||
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, dev);
|
||||
aesdev->read_regs_retry_count = 0;
|
||||
fpi_ssm_start(ssm, activate_sm_complete);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (dev);
|
||||
|
||||
struct aes1610_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
/* FIXME: audit cancellation points, probably need more, specifically
|
||||
* in error handling paths? */
|
||||
self->deactivating = TRUE;
|
||||
aesdev->deactivating = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
complete_deactivation (FpImageDevice *dev)
|
||||
static void complete_deactivation(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes1610 *self = FPI_DEVICE_AES1610 (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.
|
||||
* maybe we can do this with a master reset, unconditionally? */
|
||||
|
||||
self->deactivating = FALSE;
|
||||
g_slist_free (self->strips);
|
||||
self->strips = NULL;
|
||||
self->strips_len = 0;
|
||||
self->blanks_count = 0;
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
aesdev->deactivating = FALSE;
|
||||
g_slist_free(aesdev->strips);
|
||||
aesdev->strips = NULL;
|
||||
aesdev->strips_len = 0;
|
||||
aesdev->blanks_count = 0;
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_init (FpImageDevice *dev)
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
/* FIXME check endpoints */
|
||||
int r;
|
||||
struct aes1610_dev *aesdev;
|
||||
|
||||
if (!g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error))
|
||||
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;
|
||||
}
|
||||
|
||||
aesdev = g_malloc0(sizeof(struct aes1610_dev));
|
||||
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)
|
||||
{
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
return;
|
||||
struct aes1610_dev *aesdev;
|
||||
aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(aesdev);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
fpi_image_device_open_complete (dev, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deinit (FpImageDevice *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
}
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x08ff, .pid = 0x1600, },/* AES1600 */
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x08ff, .product = 0x1600 }, /* AES1600 */
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_aes1610_init (FpiDeviceAes1610 *self)
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_aes1610_class_init (FpiDeviceAes1610Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
struct fp_img_driver aes1610_driver = {
|
||||
.driver = {
|
||||
.id = AES1610_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "AuthenTec AES1610",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = -1,
|
||||
.img_width = IMAGE_WIDTH,
|
||||
|
||||
dev_class->id = "aes1610";
|
||||
dev_class->full_name = "AuthenTec AES1610";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
.bz3_threshold = 20,
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
img_class->bz3_threshold = 20;
|
||||
|
||||
img_class->img_width = IMAGE_WIDTH;
|
||||
img_class->img_height = -1;
|
||||
}
|
||||
|
||||
@@ -27,14 +27,6 @@
|
||||
#define FRAME_WIDTH 128
|
||||
#define IMAGE_WIDTH (FRAME_WIDTH + (FRAME_WIDTH / 2))
|
||||
|
||||
struct _FpiDeviceAes1660
|
||||
{
|
||||
FpiDeviceAesX660 parent;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceAes1660, fpi_device_aes1660, FPI,
|
||||
DEVICE_AES1660, FpiDeviceAesX660);
|
||||
G_DEFINE_TYPE (FpiDeviceAes1660, fpi_device_aes1660, FPI_TYPE_DEVICE_AES_X660);
|
||||
|
||||
static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.frame_width = FRAME_WIDTH,
|
||||
.frame_height = AESX660_FRAME_HEIGHT,
|
||||
@@ -42,54 +34,79 @@ static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.get_pixel = aes_get_pixel,
|
||||
};
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x08ff, .pid = 0x1660, },
|
||||
{ .vid = 0x08ff, .pid = 0x1680, },
|
||||
{ .vid = 0x08ff, .pid = 0x1681, },
|
||||
{ .vid = 0x08ff, .pid = 0x1682, },
|
||||
{ .vid = 0x08ff, .pid = 0x1683, },
|
||||
{ .vid = 0x08ff, .pid = 0x1684, },
|
||||
{ .vid = 0x08ff, .pid = 0x1685, },
|
||||
{ .vid = 0x08ff, .pid = 0x1686, },
|
||||
{ .vid = 0x08ff, .pid = 0x1687, },
|
||||
{ .vid = 0x08ff, .pid = 0x1688, },
|
||||
{ .vid = 0x08ff, .pid = 0x1689, },
|
||||
{ .vid = 0x08ff, .pid = 0x168a, },
|
||||
{ .vid = 0x08ff, .pid = 0x168b, },
|
||||
{ .vid = 0x08ff, .pid = 0x168c, },
|
||||
{ .vid = 0x08ff, .pid = 0x168d, },
|
||||
{ .vid = 0x08ff, .pid = 0x168e, },
|
||||
{ .vid = 0x08ff, .pid = 0x168f, },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
/* TODO check that device has endpoints we're using */
|
||||
int r;
|
||||
struct aesX660_dev *aesdev;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
aesdev = g_malloc0(sizeof(struct aesX660_dev));
|
||||
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);
|
||||
aesdev->init_seqs[1] = aes1660_init_2;
|
||||
aesdev->init_seqs_len[1] = G_N_ELEMENTS(aes1660_init_2);
|
||||
aesdev->start_imaging_cmd = (unsigned char *)aes1660_start_imaging_cmd;
|
||||
aesdev->start_imaging_cmd_len = sizeof(aes1660_start_imaging_cmd);
|
||||
aesdev->assembling_ctx = &assembling_ctx;
|
||||
aesdev->extra_img_flags = FP_IMG_PARTIAL;
|
||||
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x08ff, .product = 0x1660 },
|
||||
{ .vendor = 0x08ff, .product = 0x1680 },
|
||||
{ .vendor = 0x08ff, .product = 0x1681 },
|
||||
{ .vendor = 0x08ff, .product = 0x1682 },
|
||||
{ .vendor = 0x08ff, .product = 0x1683 },
|
||||
{ .vendor = 0x08ff, .product = 0x1684 },
|
||||
{ .vendor = 0x08ff, .product = 0x1685 },
|
||||
{ .vendor = 0x08ff, .product = 0x1686 },
|
||||
{ .vendor = 0x08ff, .product = 0x1687 },
|
||||
{ .vendor = 0x08ff, .product = 0x1688 },
|
||||
{ .vendor = 0x08ff, .product = 0x1689 },
|
||||
{ .vendor = 0x08ff, .product = 0x168a },
|
||||
{ .vendor = 0x08ff, .product = 0x168b },
|
||||
{ .vendor = 0x08ff, .product = 0x168c },
|
||||
{ .vendor = 0x08ff, .product = 0x168d },
|
||||
{ .vendor = 0x08ff, .product = 0x168e },
|
||||
{ .vendor = 0x08ff, .product = 0x168f },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_aes1660_init (FpiDeviceAes1660 *self)
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_aes1660_class_init (FpiDeviceAes1660Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
FpiDeviceAesX660Class *aes_class = FPI_DEVICE_AES_X660_CLASS (klass);
|
||||
struct fp_img_driver aes1660_driver = {
|
||||
.driver = {
|
||||
.id = AES1660_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "AuthenTec AES1660",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = -1,
|
||||
.img_width = FRAME_WIDTH + FRAME_WIDTH / 2,
|
||||
.bz3_threshold = 20,
|
||||
|
||||
dev_class->id = "aes1660";
|
||||
dev_class->full_name = "AuthenTec AES1660";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
|
||||
img_class->bz3_threshold = 20;
|
||||
|
||||
img_class->img_width = FRAME_WIDTH + FRAME_WIDTH / 2;
|
||||
img_class->img_height = -1;
|
||||
|
||||
aes_class->init_seqs[0] = aes1660_init_1;
|
||||
aes_class->init_seqs_len[0] = G_N_ELEMENTS (aes1660_init_1);
|
||||
aes_class->init_seqs[1] = aes1660_init_2;
|
||||
aes_class->init_seqs_len[1] = G_N_ELEMENTS (aes1660_init_2);
|
||||
aes_class->start_imaging_cmd = (unsigned char *) aes1660_start_imaging_cmd;
|
||||
aes_class->start_imaging_cmd_len = sizeof (aes1660_start_imaging_cmd);
|
||||
aes_class->assembling_ctx = &assembling_ctx;
|
||||
}
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = aesX660_dev_activate,
|
||||
.deactivate = aesX660_dev_deactivate,
|
||||
};
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __AES1660_H
|
||||
#define __AES1660_H
|
||||
|
||||
#define AES1660_FRAME_SIZE 0x244
|
||||
|
||||
@@ -1985,3 +1986,5 @@ static const unsigned char aes1660_start_imaging_cmd[] = {
|
||||
0x55, 0x07, 0x00, 0x80, 0x42, 0x00, 0x7f, 0x00, 0x00, 0x14,
|
||||
0x49, 0x03, 0x00, 0x20, 0x00, 0xc8
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
#include "aeslib.h"
|
||||
#include "aes2501.h"
|
||||
|
||||
static void start_capture (FpImageDevice *dev);
|
||||
static void complete_deactivation (FpImageDevice *dev);
|
||||
static void start_capture(struct fp_img_dev *dev);
|
||||
static void complete_deactivation(struct fp_img_dev *dev);
|
||||
|
||||
/* FIXME these need checking */
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
|
||||
#define BULK_TIMEOUT 4000
|
||||
|
||||
@@ -63,19 +63,13 @@ static void complete_deactivation (FpImageDevice *dev);
|
||||
|
||||
/****** GENERAL FUNCTIONS ******/
|
||||
|
||||
struct _FpiDeviceAes2501
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
guint8 read_regs_retry_count;
|
||||
struct aes2501_dev {
|
||||
uint8_t read_regs_retry_count;
|
||||
GSList *strips;
|
||||
size_t strips_len;
|
||||
gboolean deactivating;
|
||||
int no_finger_cnt;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceAes2501, fpi_device_aes2501, FPI, DEVICE_AES2501,
|
||||
FpImageDevice);
|
||||
G_DEFINE_TYPE (FpiDeviceAes2501, fpi_device_aes2501, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.frame_width = FRAME_WIDTH,
|
||||
@@ -84,52 +78,72 @@ static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.get_pixel = aes_get_pixel,
|
||||
};
|
||||
|
||||
typedef void (*aes2501_read_regs_cb)(FpImageDevice *dev,
|
||||
GError *error,
|
||||
unsigned char *regs,
|
||||
void *user_data);
|
||||
typedef void (*aes2501_read_regs_cb)(struct fp_img_dev *dev, int status,
|
||||
unsigned char *regs, void *user_data);
|
||||
|
||||
struct aes2501_read_regs
|
||||
{
|
||||
FpImageDevice *dev;
|
||||
struct aes2501_read_regs {
|
||||
struct fp_img_dev *dev;
|
||||
aes2501_read_regs_cb callback;
|
||||
struct aes_regwrite *regwrite;
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
static void
|
||||
read_regs_data_cb (FpiUsbTransfer *transfer, FpDevice *dev,
|
||||
gpointer user_data, GError *error)
|
||||
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 = user_data;
|
||||
unsigned char *retdata = NULL;
|
||||
int r;
|
||||
|
||||
rdata->callback (rdata->dev, error, transfer->buffer, rdata->user_data);
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
r = -EIO;
|
||||
} else if (transfer->length != transfer->actual_length) {
|
||||
r = -EPROTO;
|
||||
} else {
|
||||
r = 0;
|
||||
retdata = transfer->buffer;
|
||||
}
|
||||
|
||||
rdata->callback(rdata->dev, r, retdata, rdata->user_data);
|
||||
g_free(rdata);
|
||||
}
|
||||
|
||||
static void
|
||||
read_regs_rq_cb (FpImageDevice *dev, GError *error, void *user_data)
|
||||
static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data)
|
||||
{
|
||||
struct aes2501_read_regs *rdata = user_data;
|
||||
FpiUsbTransfer *transfer;
|
||||
fpi_usb_transfer *transfer;
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
g_free(rdata->regwrite);
|
||||
if (error)
|
||||
{
|
||||
rdata->callback (dev, error, NULL, rdata->user_data);
|
||||
g_free (rdata);
|
||||
if (result != 0)
|
||||
goto err;
|
||||
|
||||
data = g_malloc(READ_REGS_LEN);
|
||||
transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev),
|
||||
NULL,
|
||||
EP_IN,
|
||||
data,
|
||||
READ_REGS_LEN,
|
||||
read_regs_data_cb,
|
||||
rdata,
|
||||
BULK_TIMEOUT);
|
||||
|
||||
r = fpi_usb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
result = -EIO;
|
||||
goto err;
|
||||
}
|
||||
|
||||
return;
|
||||
err:
|
||||
rdata->callback(dev, result, NULL, rdata->user_data);
|
||||
g_free(rdata);
|
||||
}
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, READ_REGS_LEN);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
read_regs_data_cb, rdata);
|
||||
}
|
||||
|
||||
static void
|
||||
read_regs (FpImageDevice *dev, aes2501_read_regs_cb callback,
|
||||
static void read_regs(struct fp_img_dev *dev, aes2501_read_regs_cb callback,
|
||||
void *user_data)
|
||||
{
|
||||
/* FIXME: regwrite is dynamic because of asynchronity. is this really
|
||||
@@ -150,19 +164,16 @@ read_regs (FpImageDevice *dev, aes2501_read_regs_cb callback,
|
||||
}
|
||||
|
||||
/* Read the value of a specific register from a register dump */
|
||||
static int
|
||||
regval_from_dump (unsigned char *data, guint8 target)
|
||||
{
|
||||
if (*data != FIRST_AES2501_REG)
|
||||
static int regval_from_dump(unsigned char *data, uint8_t target)
|
||||
{
|
||||
if (*data != FIRST_AES2501_REG) {
|
||||
fp_err("not a register dump");
|
||||
return -1;
|
||||
return -EILSEQ;
|
||||
}
|
||||
|
||||
if (!(FIRST_AES2501_REG <= target && target <= LAST_AES2501_REG))
|
||||
{
|
||||
if (!(FIRST_AES2501_REG <= target && target <= LAST_AES2501_REG)) {
|
||||
fp_err("out of range");
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
target -= FIRST_AES2501_REG;
|
||||
@@ -170,48 +181,66 @@ regval_from_dump (unsigned char *data, guint8 target)
|
||||
return data[target + 1];
|
||||
}
|
||||
|
||||
static void
|
||||
generic_write_regv_cb (FpImageDevice *dev, GError *error,
|
||||
static void generic_write_regv_cb(struct fp_img_dev *dev, int result,
|
||||
void *user_data)
|
||||
{
|
||||
FpiSsm *ssm = user_data;
|
||||
|
||||
if (!error)
|
||||
fpi_ssm *ssm = user_data;
|
||||
if (result == 0)
|
||||
fpi_ssm_next_state(ssm);
|
||||
else
|
||||
fpi_ssm_mark_failed (ssm, error);
|
||||
fpi_ssm_mark_failed(ssm, result);
|
||||
}
|
||||
|
||||
/* check that read succeeded but ignore all data */
|
||||
static void generic_ignore_data_cb(struct libusb_transfer *transfer,
|
||||
struct fp_dev *dev,
|
||||
fpi_ssm *ssm,
|
||||
void *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);
|
||||
}
|
||||
|
||||
/* read the specified number of bytes from the IN endpoint but throw them
|
||||
* away, then increment the SSM */
|
||||
static void
|
||||
generic_read_ignore_data (FpiSsm *ssm, FpDevice *dev,
|
||||
size_t bytes)
|
||||
static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
fpi_usb_transfer *transfer;
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
transfer = fpi_usb_transfer_new (dev);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, bytes);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
data = g_malloc(bytes);
|
||||
transfer = fpi_usb_fill_bulk_transfer(dev,
|
||||
ssm,
|
||||
EP_IN,
|
||||
data,
|
||||
bytes,
|
||||
generic_ignore_data_cb,
|
||||
NULL,
|
||||
BULK_TIMEOUT);
|
||||
|
||||
r = fpi_usb_submit_transfer(transfer);
|
||||
if (r < 0)
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
|
||||
/****** IMAGE PROCESSING ******/
|
||||
|
||||
static int
|
||||
sum_histogram_values (unsigned char *data, guint8 threshold)
|
||||
static int sum_histogram_values(unsigned char *data, uint8_t threshold)
|
||||
{
|
||||
int r = 0;
|
||||
int i;
|
||||
guint16 *histogram = (guint16 *) (data + 1);
|
||||
uint16_t *histogram = (uint16_t *)(data + 1);
|
||||
|
||||
if (*data != 0xde)
|
||||
return -1;
|
||||
return -EILSEQ;
|
||||
|
||||
if (threshold > 0x0f)
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
|
||||
/* FIXME endianness */
|
||||
for (i = threshold; i < 16; i++)
|
||||
@@ -250,67 +279,72 @@ static const struct aes_regwrite finger_det_reqs[] = {
|
||||
{ AES2501_REG_LPONT, AES2501_LPONT_MIN_VALUE },
|
||||
};
|
||||
|
||||
static void start_finger_detection (FpImageDevice *dev);
|
||||
static void start_finger_detection(struct fp_img_dev *dev);
|
||||
|
||||
static void
|
||||
finger_det_data_cb (FpiUsbTransfer *transfer, FpDevice *_dev,
|
||||
gpointer user_data, GError *error)
|
||||
static void finger_det_data_cb(struct libusb_transfer *transfer,
|
||||
struct fp_dev *_dev,
|
||||
fpi_ssm *ssm,
|
||||
void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
struct fp_img_dev *dev = FP_IMG_DEV(_dev);
|
||||
unsigned char *data = transfer->buffer;
|
||||
int i;
|
||||
int sum = 0;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_imgdev_session_error(dev, -EIO);
|
||||
return;
|
||||
} else if (transfer->length != transfer->actual_length) {
|
||||
fpi_imgdev_session_error(dev, -EPROTO);
|
||||
return;
|
||||
}
|
||||
|
||||
/* examine histogram to determine finger presence */
|
||||
for (i = 1; i < 9; i++)
|
||||
sum += (data[i] & 0xf) + (data[i] >> 4);
|
||||
if (sum > 20)
|
||||
{
|
||||
if (sum > 20) {
|
||||
/* finger present, start capturing */
|
||||
fpi_image_device_report_finger_status (dev, TRUE);
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
start_capture(dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* no finger, poll for a new histogram */
|
||||
start_finger_detection(dev);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finger_det_reqs_cb (FpImageDevice *dev, GError *error,
|
||||
static void finger_det_reqs_cb(struct fp_img_dev *dev, int result,
|
||||
void *user_data)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
fpi_usb_transfer *transfer;
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
if (result) {
|
||||
fpi_imgdev_session_error(dev, result);
|
||||
return;
|
||||
}
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, FINGER_DETECTION_LEN);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
finger_det_data_cb, NULL);
|
||||
data = g_malloc(FINGER_DETECTION_LEN);
|
||||
transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev),
|
||||
NULL,
|
||||
EP_IN,
|
||||
data,
|
||||
FINGER_DETECTION_LEN,
|
||||
finger_det_data_cb,
|
||||
NULL,
|
||||
BULK_TIMEOUT);
|
||||
|
||||
r = fpi_usb_submit_transfer(transfer);
|
||||
if (r < 0)
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
}
|
||||
|
||||
static void
|
||||
start_finger_detection (FpImageDevice *dev)
|
||||
static void start_finger_detection(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (dev);
|
||||
|
||||
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
G_DEBUG_HERE();
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
@@ -381,7 +415,7 @@ static struct aes_regwrite strip_scan_reqs[] = {
|
||||
/* capture SM movement:
|
||||
* write reqs and read data 1 + 2,
|
||||
* request and read strip,
|
||||
* jump back to request UNLESS there's no finger, in which case exit SM,
|
||||
* jump back to request UNLESS theres no finger, in which case exit SM,
|
||||
* report lack of finger presence, and move to finger detection */
|
||||
|
||||
enum capture_states {
|
||||
@@ -394,50 +428,45 @@ enum capture_states {
|
||||
CAPTURE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
capture_read_strip_cb (FpiUsbTransfer *transfer, FpDevice *_dev,
|
||||
gpointer user_data, GError *error)
|
||||
static void capture_read_strip_cb(struct libusb_transfer *transfer,
|
||||
struct fp_dev *_dev,
|
||||
fpi_ssm *ssm,
|
||||
void *user_data)
|
||||
{
|
||||
FpiSsm *ssm = transfer->ssm;
|
||||
unsigned char *stripdata;
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (_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 (error)
|
||||
{
|
||||
fpi_ssm_mark_failed (ssm, error);
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
return;
|
||||
} else if (transfer->length != transfer->actual_length) {
|
||||
fpi_ssm_mark_failed(ssm, -EPROTO);
|
||||
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,
|
||||
fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
|
||||
if (threshold < 0) {
|
||||
fpi_ssm_mark_failed(ssm, threshold);
|
||||
return;
|
||||
}
|
||||
|
||||
sum = sum_histogram_values(data + 1 + 192*8, threshold & 0x0f);
|
||||
if (sum < 0)
|
||||
{
|
||||
fpi_ssm_mark_failed (ssm,
|
||||
fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
|
||||
if (sum < 0) {
|
||||
fpi_ssm_mark_failed(ssm, sum);
|
||||
return;
|
||||
}
|
||||
fp_dbg("sum=%d", sum);
|
||||
|
||||
if (sum < AES2501_SUM_LOW_THRESH)
|
||||
{
|
||||
if (sum < AES2501_SUM_LOW_THRESH) {
|
||||
strip_scan_reqs[4].value -= 0x8;
|
||||
if (strip_scan_reqs[4].value < AES2501_ADREFHI_MIN_VALUE)
|
||||
strip_scan_reqs[4].value = AES2501_ADREFHI_MIN_VALUE;
|
||||
}
|
||||
else if (sum > AES2501_SUM_HIGH_THRESH)
|
||||
{
|
||||
} else if (sum > AES2501_SUM_HIGH_THRESH) {
|
||||
strip_scan_reqs[4].value += 0x8;
|
||||
if (strip_scan_reqs[4].value > AES2501_ADREFHI_MAX_VALUE)
|
||||
strip_scan_reqs[4].value = AES2501_ADREFHI_MAX_VALUE;
|
||||
@@ -447,32 +476,28 @@ capture_read_strip_cb (FpiUsbTransfer *transfer, FpDevice *_dev,
|
||||
/* Sum is 0, maybe finger was removed? Wait for 3 empty frames
|
||||
* to ensure
|
||||
*/
|
||||
if (sum == 0)
|
||||
{
|
||||
self->no_finger_cnt++;
|
||||
if (self->no_finger_cnt == 3)
|
||||
{
|
||||
FpImage *img;
|
||||
if (sum == 0) {
|
||||
aesdev->no_finger_cnt++;
|
||||
if (aesdev->no_finger_cnt == 3) {
|
||||
struct fp_img *img;
|
||||
|
||||
self->strips = g_slist_reverse (self->strips);
|
||||
fpi_do_movement_estimation (&assembling_ctx, self->strips);
|
||||
aesdev->strips = g_slist_reverse(aesdev->strips);
|
||||
fpi_do_movement_estimation(&assembling_ctx,
|
||||
aesdev->strips, aesdev->strips_len);
|
||||
img = fpi_assemble_frames(&assembling_ctx,
|
||||
self->strips);
|
||||
g_slist_free_full (self->strips, g_free);
|
||||
self->strips = NULL;
|
||||
self->strips_len = 0;
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
fpi_image_device_report_finger_status (dev, FALSE);
|
||||
aesdev->strips, aesdev->strips_len);
|
||||
img->flags |= FP_IMG_PARTIAL;
|
||||
g_slist_free_full(aesdev->strips, g_free);
|
||||
aesdev->strips = NULL;
|
||||
aesdev->strips_len = 0;
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
/* marking machine complete will re-trigger finger detection loop */
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_REQUEST_STRIP);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* obtain next strip */
|
||||
/* FIXME: would preallocating strip buffers be a decent optimization? */
|
||||
struct fpi_frame *stripe = g_malloc(FRAME_WIDTH * FRAME_HEIGHT / 2 + sizeof(struct fpi_frame));
|
||||
@@ -480,103 +505,92 @@ capture_read_strip_cb (FpiUsbTransfer *transfer, FpDevice *_dev,
|
||||
stripe->delta_y = 0;
|
||||
stripdata = stripe->data;
|
||||
memcpy(stripdata, data + 1, 192*8);
|
||||
self->no_finger_cnt = 0;
|
||||
self->strips = g_slist_prepend (self->strips, stripe);
|
||||
self->strips_len++;
|
||||
aesdev->no_finger_cnt = 0;
|
||||
aesdev->strips = g_slist_prepend(aesdev->strips, stripe);
|
||||
aesdev->strips_len++;
|
||||
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_REQUEST_STRIP);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
capture_run_state (FpiSsm *ssm, FpDevice *device)
|
||||
static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (device);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev);
|
||||
int r;
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case CAPTURE_WRITE_REQS_1:
|
||||
aes_write_regv(dev, capture_reqs_1, G_N_ELEMENTS(capture_reqs_1),
|
||||
generic_write_regv_cb, ssm);
|
||||
break;
|
||||
|
||||
case CAPTURE_READ_DATA_1:
|
||||
generic_read_ignore_data (ssm, device, READ_REGS_RESP_LEN);
|
||||
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, device, READ_REGS_RESP_LEN);
|
||||
generic_read_ignore_data(ssm, _dev, READ_REGS_RESP_LEN);
|
||||
break;
|
||||
|
||||
case CAPTURE_REQUEST_STRIP:
|
||||
if (self->deactivating)
|
||||
if (aesdev->deactivating)
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
else
|
||||
aes_write_regv(dev, strip_scan_reqs, G_N_ELEMENTS(strip_scan_reqs),
|
||||
generic_write_regv_cb, ssm);
|
||||
break;
|
||||
case CAPTURE_READ_STRIP: ;
|
||||
fpi_usb_transfer *transfer;
|
||||
unsigned char *data;
|
||||
|
||||
case CAPTURE_READ_STRIP: {
|
||||
FpiUsbTransfer *transfer;
|
||||
data = g_malloc(STRIP_CAPTURE_LEN);
|
||||
transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev),
|
||||
ssm,
|
||||
EP_IN,
|
||||
data,
|
||||
STRIP_CAPTURE_LEN,
|
||||
capture_read_strip_cb,
|
||||
NULL,
|
||||
BULK_TIMEOUT);
|
||||
|
||||
transfer = fpi_usb_transfer_new (device);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, STRIP_CAPTURE_LEN);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
capture_read_strip_cb, NULL);
|
||||
r = fpi_usb_submit_transfer(transfer);
|
||||
if (r < 0)
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
G_DEBUG_HERE();
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating)
|
||||
complete_deactivation(dev);
|
||||
g_clear_pointer (&error, g_error_free);
|
||||
}
|
||||
else if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
}
|
||||
else if (fpi_ssm_get_error(ssm))
|
||||
fpi_imgdev_session_error(dev, fpi_ssm_get_error(ssm));
|
||||
else
|
||||
{
|
||||
start_finger_detection(dev);
|
||||
}
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
start_capture (FpImageDevice *dev)
|
||||
static void start_capture(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (dev);
|
||||
FpiSsm *ssm;
|
||||
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
|
||||
self->no_finger_cnt = 0;
|
||||
aesdev->no_finger_cnt = 0;
|
||||
/* Reset gain */
|
||||
strip_scan_reqs[4].value = AES2501_ADREFHI_MAX_VALUE;
|
||||
ssm = fpi_ssm_new (FP_DEVICE (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_start(ssm, capture_sm_complete);
|
||||
}
|
||||
@@ -686,43 +700,36 @@ enum activate_states {
|
||||
ACTIVATE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
activate_read_regs_cb (FpImageDevice *dev, GError *error,
|
||||
void activate_read_regs_cb(struct fp_img_dev *dev, int status,
|
||||
unsigned char *regs, void *user_data)
|
||||
{
|
||||
FpiSsm *ssm = user_data;
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (dev);
|
||||
fpi_ssm *ssm = user_data;
|
||||
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_ssm_mark_failed (ssm, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (status != 0) {
|
||||
fpi_ssm_mark_failed(ssm, status);
|
||||
} else {
|
||||
fp_dbg("reg 0xaf = %x", regs[0x5f]);
|
||||
if (regs[0x5f] != 0x6b || ++self->read_regs_retry_count == 13)
|
||||
if (regs[0x5f] != 0x6b || ++aesdev->read_regs_retry_count == 13)
|
||||
fpi_ssm_jump_to_state(ssm, WRITE_INIT_4);
|
||||
else
|
||||
fpi_ssm_next_state(ssm);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activate_init3_cb (FpImageDevice *dev, GError *error,
|
||||
static void activate_init3_cb(struct fp_img_dev *dev, int result,
|
||||
void *user_data)
|
||||
{
|
||||
FpiSsm *ssm = user_data;
|
||||
|
||||
if (!error)
|
||||
fpi_ssm *ssm = user_data;
|
||||
if (result == 0)
|
||||
fpi_ssm_jump_to_state(ssm, READ_REGS);
|
||||
else
|
||||
fpi_ssm_mark_failed (ssm, error);
|
||||
fpi_ssm_mark_failed(ssm, result);
|
||||
}
|
||||
|
||||
static void
|
||||
activate_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
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
|
||||
@@ -743,37 +750,30 @@ activate_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
aes_write_regv(init_4);
|
||||
*/
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case WRITE_INIT_1:
|
||||
aes_write_regv(dev, init_1, G_N_ELEMENTS(init_1),
|
||||
generic_write_regv_cb, ssm);
|
||||
break;
|
||||
|
||||
case READ_DATA_1:
|
||||
fp_dbg("read data 1");
|
||||
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),
|
||||
generic_write_regv_cb, ssm);
|
||||
break;
|
||||
|
||||
case READ_REGS:
|
||||
read_regs(dev, activate_read_regs_cb, ssm);
|
||||
break;
|
||||
|
||||
case WRITE_INIT_3:
|
||||
aes_write_regv(dev, init_3, G_N_ELEMENTS(init_3),
|
||||
activate_init3_cb, ssm);
|
||||
break;
|
||||
|
||||
case WRITE_INIT_4:
|
||||
aes_write_regv(dev, init_4, G_N_ELEMENTS(init_4),
|
||||
generic_write_regv_cb, ssm);
|
||||
break;
|
||||
|
||||
case WRITE_INIT_5:
|
||||
aes_write_regv(dev, init_5, G_N_ELEMENTS(init_5),
|
||||
generic_write_regv_cb, ssm);
|
||||
@@ -781,101 +781,97 @@ activate_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activate_sm_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
|
||||
static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
fpi_image_device_activate_complete (FP_IMAGE_DEVICE (dev), error);
|
||||
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));
|
||||
|
||||
if (!error)
|
||||
start_finger_detection (FP_IMAGE_DEVICE (dev));
|
||||
if (!fpi_ssm_get_error(ssm))
|
||||
start_finger_detection(dev);
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (dev);
|
||||
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES);
|
||||
|
||||
self->read_regs_retry_count = 0;
|
||||
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, dev);
|
||||
aesdev->read_regs_retry_count = 0;
|
||||
fpi_ssm_start(ssm, activate_sm_complete);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (dev);
|
||||
|
||||
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
/* FIXME: audit cancellation points, probably need more, specifically
|
||||
* in error handling paths? */
|
||||
self->deactivating = TRUE;
|
||||
aesdev->deactivating = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
complete_deactivation (FpImageDevice *dev)
|
||||
static void complete_deactivation(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2501 *self = FPI_DEVICE_AES2501 (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.
|
||||
* maybe we can do this with a master reset, unconditionally? */
|
||||
|
||||
self->deactivating = FALSE;
|
||||
g_slist_free (self->strips);
|
||||
self->strips = NULL;
|
||||
self->strips_len = 0;
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
aesdev->deactivating = FALSE;
|
||||
g_slist_free(aesdev->strips);
|
||||
aesdev->strips = NULL;
|
||||
aesdev->strips_len = 0;
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_init (FpImageDevice *dev)
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
/* FIXME check endpoints */
|
||||
int r;
|
||||
struct aes2501_dev *aesdev;
|
||||
|
||||
g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error);
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deinit (FpImageDevice *dev)
|
||||
aesdev = g_malloc0(sizeof(struct aes2501_dev));
|
||||
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)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(aesdev);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x08ff, .pid = 0x2500, },/* AES2500 */
|
||||
{ .vid = 0x08ff, .pid = 0x2580, },/* AES2501 */
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x08ff, .product = 0x2500 }, /* AES2500 */
|
||||
{ .vendor = 0x08ff, .product = 0x2580 }, /* AES2501 */
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_aes2501_init (FpiDeviceAes2501 *self)
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_aes2501_class_init (FpiDeviceAes2501Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
struct fp_img_driver aes2501_driver = {
|
||||
.driver = {
|
||||
.id = AES2501_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "AuthenTec AES2501",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = -1,
|
||||
.img_width = IMAGE_WIDTH,
|
||||
|
||||
dev_class->id = "aes2501";
|
||||
dev_class->full_name = "AuthenTec AES2501";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
|
||||
img_class->img_width = IMAGE_WIDTH;
|
||||
img_class->img_height = -1;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __AES2501_H
|
||||
#define __AES2501_H
|
||||
|
||||
enum aes2501_regs {
|
||||
AES2501_REG_CTRL1 = 0x80,
|
||||
@@ -108,7 +109,7 @@ enum aes2501_mesure_drive {
|
||||
|
||||
/* Select (1=square | 0=sine) wave drive during measure */
|
||||
#define AES2501_MEASDRV_SQUARE 0x20
|
||||
/* 0 = use measure drive setting, 1 = when sine wave is selected */
|
||||
/* 0 = use mesure drive setting, 1 = when sine wave is selected */
|
||||
#define AES2501_MEASDRV_MEASURE_SQUARE 0x10
|
||||
|
||||
enum aes2501_measure_freq {
|
||||
@@ -171,3 +172,5 @@ enum aes2501_sensor_gain2 {
|
||||
|
||||
#define AES2501_SUM_HIGH_THRESH 1000
|
||||
#define AES2501_SUM_LOW_THRESH 700
|
||||
|
||||
#endif /* __AES2501_H */
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
#include "aes2550.h"
|
||||
#include "aeslib.h"
|
||||
|
||||
static void start_capture (FpImageDevice *dev);
|
||||
static void complete_deactivation (FpImageDevice *dev);
|
||||
static void start_capture(struct fp_img_dev *dev);
|
||||
static void complete_deactivation(struct fp_img_dev *dev);
|
||||
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
#define BULK_TIMEOUT 4000
|
||||
|
||||
/*
|
||||
@@ -51,18 +51,12 @@ static void complete_deactivation (FpImageDevice *dev);
|
||||
#define FRAME_SIZE (FRAME_WIDTH * FRAME_HEIGHT)
|
||||
#define IMAGE_WIDTH (FRAME_WIDTH + (FRAME_WIDTH / 2))
|
||||
|
||||
struct _FpiDeviceAes2550
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
struct aes2550_dev {
|
||||
GSList *strips;
|
||||
size_t strips_len;
|
||||
gboolean deactivating;
|
||||
int heartbeat_cnt;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceAes2550, fpi_device_aes2550, FPI, DEVICE_AES2550,
|
||||
FpImageDevice);
|
||||
G_DEFINE_TYPE (FpiDeviceAes2550, fpi_device_aes2550, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.frame_width = FRAME_WIDTH,
|
||||
@@ -84,78 +78,89 @@ static unsigned char finger_det_reqs[] = {
|
||||
AES2550_CMD_RUN_FD,
|
||||
};
|
||||
|
||||
static void start_finger_detection (FpImageDevice *dev);
|
||||
static void start_finger_detection(struct fp_img_dev *dev);
|
||||
|
||||
static void
|
||||
finger_det_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void finger_det_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
struct fp_img_dev *dev = transfer->user_data;
|
||||
unsigned char *data = transfer->buffer;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_image_device_session_error (FP_IMAGE_DEVICE (device), error);
|
||||
return;
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("data transfer status %d\n", transfer->status);
|
||||
fpi_imgdev_session_error(dev, -EIO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fp_dbg("transfer completed, len: %.4x, data: %.2x %.2x",
|
||||
(gint) transfer->actual_length, (int) data[0], (int) data[1]);
|
||||
transfer->actual_length, (int)data[0], (int)data[1]);
|
||||
|
||||
/* Check if we got 2 bytes, reg address 0x83 and its value */
|
||||
if ((transfer->actual_length >= 2) && (data[0] == 0x83) && (data[1] & AES2550_REG83_FINGER_PRESENT))
|
||||
{
|
||||
if ((transfer->actual_length >= 2) && (data[0] == 0x83) && (data[1] & AES2550_REG83_FINGER_PRESENT)) {
|
||||
/* finger present, start capturing */
|
||||
fpi_image_device_report_finger_status (dev, TRUE);
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
start_capture(dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* 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 (FpiUsbTransfer *t, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void finger_det_reqs_cb(struct libusb_transfer *t)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
struct libusb_transfer *transfer;
|
||||
unsigned char *data;
|
||||
int r;
|
||||
struct fp_img_dev *dev = t->user_data;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
return;
|
||||
if (t->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("req transfer status %d\n", t->status);
|
||||
fpi_imgdev_session_error(dev, -EIO);
|
||||
goto exit_free_transfer;
|
||||
} else if (t->length != t->actual_length) {
|
||||
fp_dbg("expected %d, got %d bytes", t->length, t->actual_length);
|
||||
fpi_imgdev_session_error(dev, -EPROTO);
|
||||
goto exit_free_transfer;
|
||||
}
|
||||
|
||||
transfer = fpi_usb_transfer_new (device);
|
||||
transfer = fpi_usb_alloc();
|
||||
/* 2 bytes of result */
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, AES2550_EP_IN_BUF_SIZE);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
finger_det_data_cb, NULL);
|
||||
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,
|
||||
finger_det_data_cb, dev, BULK_TIMEOUT);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
}
|
||||
exit_free_transfer:
|
||||
libusb_free_transfer(t);
|
||||
}
|
||||
|
||||
static void
|
||||
start_finger_detection (FpImageDevice *dev)
|
||||
static void start_finger_detection(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (dev);
|
||||
FpiUsbTransfer *transfer;
|
||||
|
||||
int r;
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
struct libusb_transfer *transfer;
|
||||
G_DEBUG_HERE();
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_OUT, finger_det_reqs,
|
||||
sizeof (finger_det_reqs), NULL);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
finger_det_reqs_cb, NULL);
|
||||
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);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
}
|
||||
}
|
||||
|
||||
/****** CAPTURE ******/
|
||||
@@ -186,212 +191,207 @@ enum capture_states {
|
||||
};
|
||||
|
||||
/* Returns number of processed bytes */
|
||||
static gboolean
|
||||
process_strip_data (FpiSsm *ssm, FpImageDevice *dev,
|
||||
unsigned char *data)
|
||||
static int process_strip_data(fpi_ssm *ssm, struct fp_img_dev *dev, unsigned char *data)
|
||||
{
|
||||
unsigned char *stripdata;
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (dev);
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
struct fpi_frame *stripe;
|
||||
int len;
|
||||
|
||||
if (data[0] != AES2550_EDATA_MAGIC)
|
||||
{
|
||||
if (data[0] != AES2550_EDATA_MAGIC) {
|
||||
fp_dbg("Bogus magic: %.2x\n", (int)(data[0]));
|
||||
return FALSE;
|
||||
return -EPROTO;
|
||||
}
|
||||
len = data[1] * 256 + data[2];
|
||||
if (len != (AES2550_STRIP_SIZE - 3))
|
||||
if (len != (AES2550_STRIP_SIZE - 3)) {
|
||||
fp_dbg("Bogus frame len: %.4x\n", len);
|
||||
stripe = g_malloc0 (FRAME_WIDTH * FRAME_HEIGHT / 2 + sizeof (struct fpi_frame)); /* 4 bits per pixel */
|
||||
}
|
||||
stripe = g_malloc(FRAME_WIDTH * FRAME_HEIGHT / 2 + sizeof(struct fpi_frame)); /* 4 bits per pixel */
|
||||
stripe->delta_x = (int8_t)data[6];
|
||||
stripe->delta_y = -(int8_t)data[7];
|
||||
stripdata = stripe->data;
|
||||
memcpy(stripdata, data + 33, FRAME_WIDTH * FRAME_HEIGHT / 2);
|
||||
self->strips = g_slist_prepend (self->strips, stripe);
|
||||
self->strips_len++;
|
||||
aesdev->strips = g_slist_prepend(aesdev->strips, stripe);
|
||||
aesdev->strips_len++;
|
||||
|
||||
fp_dbg("deltas: %dx%d", stripe->delta_x, stripe->delta_y);
|
||||
|
||||
return TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
capture_set_idle_reqs_cb (FpiUsbTransfer *transfer,
|
||||
FpDevice *device, gpointer user_data,
|
||||
GError *error)
|
||||
static void capture_reqs_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (dev);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (!error && self->strips_len)
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void capture_set_idle_reqs_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImage *img;
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
self->strips = g_slist_reverse (self->strips);
|
||||
img = fpi_assemble_frames (&assembling_ctx, self->strips);
|
||||
g_slist_free_full (self->strips, g_free);
|
||||
self->strips = NULL;
|
||||
self->strips_len = 0;
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
fpi_image_device_report_finger_status (dev, FALSE);
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length) &&
|
||||
aesdev->strips_len) {
|
||||
struct fp_img *img;
|
||||
|
||||
aesdev->strips = g_slist_reverse(aesdev->strips);
|
||||
img = fpi_assemble_frames(&assembling_ctx,
|
||||
aesdev->strips, aesdev->strips_len);
|
||||
img->flags |= FP_IMG_PARTIAL;
|
||||
g_slist_free_full(aesdev->strips, g_free);
|
||||
aesdev->strips = NULL;
|
||||
aesdev->strips_len = 0;
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
/* marking machine complete will re-trigger finger detection loop */
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error)
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
else
|
||||
fpi_ssm_mark_failed (transfer->ssm,
|
||||
fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
capture_read_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void capture_read_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (dev);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
unsigned char *data = transfer->buffer;
|
||||
int r;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
return;
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("request is not completed, %d", transfer->status);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fp_dbg ("request completed, len: %.4x", (gint) transfer->actual_length);
|
||||
fp_dbg("request completed, len: %.4x", transfer->actual_length);
|
||||
if (transfer->actual_length >= 2)
|
||||
fp_dbg("data: %.2x %.2x", (int)data[0], (int)data[1]);
|
||||
|
||||
switch (transfer->actual_length)
|
||||
{
|
||||
switch (transfer->actual_length) {
|
||||
case AES2550_STRIP_SIZE:
|
||||
if (!process_strip_data (transfer->ssm, dev, data))
|
||||
{
|
||||
fp_dbg ("Processing strip data failed");
|
||||
fpi_ssm_mark_failed (transfer->ssm,
|
||||
fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
|
||||
return;
|
||||
r = process_strip_data(ssm, dev, data);
|
||||
if (r < 0) {
|
||||
fp_dbg("Processing strip data failed: %d", r);
|
||||
fpi_ssm_mark_failed(ssm, -EPROTO);
|
||||
goto out;
|
||||
}
|
||||
self->heartbeat_cnt = 0;
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_READ_DATA);
|
||||
aesdev->heartbeat_cnt = 0;
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
break;
|
||||
|
||||
case AES2550_HEARTBEAT_SIZE:
|
||||
if (data[0] == AES2550_HEARTBEAT_MAGIC)
|
||||
{
|
||||
if (data[0] == AES2550_HEARTBEAT_MAGIC) {
|
||||
/* No data for a long time => finger was removed or there's no movement */
|
||||
self->heartbeat_cnt++;
|
||||
if (self->heartbeat_cnt == 3)
|
||||
{
|
||||
aesdev->heartbeat_cnt++;
|
||||
if (aesdev->heartbeat_cnt == 3) {
|
||||
/* Got 3 heartbeat message, that's enough to consider that finger was removed,
|
||||
* assemble image and submit it to the library */
|
||||
fp_dbg("Got 3 heartbeats => finger removed");
|
||||
fpi_ssm_next_state (transfer->ssm);
|
||||
}
|
||||
else
|
||||
{
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
CAPTURE_READ_DATA);
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fp_dbg ("Short frame %d, skip",
|
||||
(gint) transfer->actual_length);
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_READ_DATA);
|
||||
fp_dbg("Short frame %d, skip", transfer->actual_length);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
break;
|
||||
}
|
||||
out:
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
capture_run_state (FpiSsm *ssm, FpDevice *dev)
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
struct fp_img_dev *dev = user_data;
|
||||
int r;
|
||||
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case CAPTURE_WRITE_REQS:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_OUT, capture_reqs,
|
||||
sizeof (capture_reqs), NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
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) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, -ENOMEM);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CAPTURE_READ_DATA:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, AES2550_EP_IN_BUF_SIZE);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
capture_read_data_cb, NULL);
|
||||
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);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CAPTURE_SET_IDLE:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_OUT,
|
||||
capture_set_idle_reqs,
|
||||
sizeof (capture_set_idle_reqs),
|
||||
NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
capture_set_idle_reqs_cb, NULL);
|
||||
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) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, -ENOMEM);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (_dev);
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (self);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
fp_dbg("Capture completed");
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating)
|
||||
complete_deactivation(dev);
|
||||
g_clear_pointer (&error, g_error_free);
|
||||
}
|
||||
else if (error)
|
||||
{
|
||||
fpi_image_device_session_error (dev, error);
|
||||
}
|
||||
else if (fpi_ssm_get_error(ssm))
|
||||
fpi_imgdev_session_error(dev, fpi_ssm_get_error(ssm));
|
||||
else
|
||||
{
|
||||
start_finger_detection(dev);
|
||||
}
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
start_capture (FpImageDevice *dev)
|
||||
static void start_capture(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (dev);
|
||||
FpiSsm *ssm;
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (aesdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
|
||||
self->heartbeat_cnt = 0;
|
||||
ssm = fpi_ssm_new (FP_DEVICE (dev), capture_run_state, CAPTURE_NUM_STATES);
|
||||
aesdev->heartbeat_cnt = 0;
|
||||
ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev);
|
||||
G_DEBUG_HERE();
|
||||
fpi_ssm_start(ssm, capture_sm_complete);
|
||||
}
|
||||
@@ -420,162 +420,201 @@ enum activate_states {
|
||||
ACTIVATE_NUM_STATES,
|
||||
};
|
||||
|
||||
/* TODO: use calibration table, datasheet is rather terse on that
|
||||
* need more info for implementation */
|
||||
static void
|
||||
calibrate_read_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void init_reqs_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
fpi_ssm_usb_transfer_cb (transfer, device, user_data, error);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
activate_run_state (FpiSsm *ssm, FpDevice *dev)
|
||||
static void init_read_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
/* TODO: use calibration table, datasheet is rather terse on that
|
||||
* need more info for implementaion */
|
||||
static void calibrate_read_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
struct fp_img_dev *dev = user_data;
|
||||
int r;
|
||||
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case WRITE_INIT:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_OUT, init_reqs,
|
||||
sizeof (init_reqs), NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
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) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, -ENOMEM);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case READ_DATA:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, AES2550_EP_IN_BUF_SIZE);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
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);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CALIBRATE:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_OUT,
|
||||
calibrate_reqs,
|
||||
sizeof (calibrate_reqs), NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
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) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, -ENOMEM);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case READ_CALIB_TABLE:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_IN, AES2550_EP_IN_BUF_SIZE);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
calibrate_read_data_cb, NULL);
|
||||
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);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
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));
|
||||
|
||||
fpi_image_device_activate_complete (dev, error);
|
||||
|
||||
if (!error)
|
||||
if (!fpi_ssm_get_error(ssm))
|
||||
start_finger_detection(dev);
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES);
|
||||
|
||||
fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES, dev);
|
||||
fpi_ssm_start(ssm, activate_sm_complete);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (dev);
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
self->deactivating = TRUE;
|
||||
aesdev->deactivating = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
complete_deactivation (FpImageDevice *dev)
|
||||
static void complete_deactivation(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes2550 *self = FPI_DEVICE_AES2550 (dev);
|
||||
|
||||
struct aes2550_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
G_DEBUG_HERE();
|
||||
|
||||
self->deactivating = FALSE;
|
||||
g_slist_free (self->strips);
|
||||
self->strips = NULL;
|
||||
self->strips_len = 0;
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
aesdev->deactivating = FALSE;
|
||||
g_slist_free(aesdev->strips);
|
||||
aesdev->strips = NULL;
|
||||
aesdev->strips_len = 0;
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_init (FpImageDevice *dev)
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
/* TODO check that device has endpoints we're using */
|
||||
int r;
|
||||
struct aes2550_dev *aes2550_dev;
|
||||
|
||||
g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error);
|
||||
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deinit (FpImageDevice *dev)
|
||||
aes2550_dev = g_malloc0(sizeof(struct aes2550_dev));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), aes2550_dev);
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dev_deinit(struct fp_img_dev *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
struct aes2550_dev *aesdev;
|
||||
aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(aesdev);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x08ff, .pid = 0x2550, },/* AES2550 */
|
||||
{ .vid = 0x08ff, .pid = 0x2810, },/* AES2810 */
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x08ff, .product = 0x2550 }, /* AES2550 */
|
||||
{ .vendor = 0x08ff, .product = 0x2810 }, /* AES2810 */
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_aes2550_init (FpiDeviceAes2550 *self)
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_aes2550_class_init (FpiDeviceAes2550Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
struct fp_img_driver aes2550_driver = {
|
||||
.driver = {
|
||||
.id = AES2550_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "AuthenTec AES2550/AES2810",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = -1,
|
||||
.img_width = FRAME_WIDTH + FRAME_WIDTH / 2,
|
||||
|
||||
dev_class->id = "aes2550";
|
||||
dev_class->full_name = "AuthenTec AES2550/AES2810";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
|
||||
img_class->img_width = FRAME_WIDTH + FRAME_WIDTH / 2;
|
||||
img_class->img_height = -1;
|
||||
}
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __AES2550_H
|
||||
#define __AES2550_H
|
||||
|
||||
/* Registers bits */
|
||||
|
||||
@@ -109,3 +110,5 @@ enum aes2550_cmds {
|
||||
#define AES2550_HEARTBEAT_MAGIC 0xdb
|
||||
|
||||
#define AES2550_EP_IN_BUF_SIZE 8192
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,14 +27,6 @@
|
||||
#define FRAME_WIDTH 192
|
||||
#define IMAGE_WIDTH (FRAME_WIDTH + (FRAME_WIDTH / 2))
|
||||
|
||||
struct _FpiDeviceAes2660
|
||||
{
|
||||
FpiDeviceAesX660 parent;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceAes2660, fpi_device_aes2660, FPI,
|
||||
DEVICE_AES2660, FpiDeviceAesX660);
|
||||
G_DEFINE_TYPE (FpiDeviceAes2660, fpi_device_aes2660, FPI_TYPE_DEVICE_AES_X660);
|
||||
|
||||
static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.frame_width = FRAME_WIDTH,
|
||||
.frame_height = AESX660_FRAME_HEIGHT,
|
||||
@@ -42,56 +34,81 @@ static struct fpi_frame_asmbl_ctx assembling_ctx = {
|
||||
.get_pixel = aes_get_pixel,
|
||||
};
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x08ff, .pid = 0x2660, },
|
||||
{ .vid = 0x08ff, .pid = 0x2680, },
|
||||
{ .vid = 0x08ff, .pid = 0x2681, },
|
||||
{ .vid = 0x08ff, .pid = 0x2682, },
|
||||
{ .vid = 0x08ff, .pid = 0x2683, },
|
||||
{ .vid = 0x08ff, .pid = 0x2684, },
|
||||
{ .vid = 0x08ff, .pid = 0x2685, },
|
||||
{ .vid = 0x08ff, .pid = 0x2686, },
|
||||
{ .vid = 0x08ff, .pid = 0x2687, },
|
||||
{ .vid = 0x08ff, .pid = 0x2688, },
|
||||
{ .vid = 0x08ff, .pid = 0x2689, },
|
||||
{ .vid = 0x08ff, .pid = 0x268a, },
|
||||
{ .vid = 0x08ff, .pid = 0x268b, },
|
||||
{ .vid = 0x08ff, .pid = 0x268c, },
|
||||
{ .vid = 0x08ff, .pid = 0x268d, },
|
||||
{ .vid = 0x08ff, .pid = 0x268e, },
|
||||
{ .vid = 0x08ff, .pid = 0x268f, },
|
||||
{ .vid = 0x08ff, .pid = 0x2691, },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
/* TODO check that device has endpoints we're using */
|
||||
int r;
|
||||
struct aesX660_dev *aesdev;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
aesdev = g_malloc0(sizeof(struct aesX660_dev));
|
||||
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;
|
||||
aesdev->init_seqs_len[0] = G_N_ELEMENTS(aes2660_init_1);
|
||||
aesdev->init_seqs[1] = aes2660_init_2;
|
||||
aesdev->init_seqs_len[1] = G_N_ELEMENTS(aes2660_init_2);
|
||||
aesdev->start_imaging_cmd = (unsigned char *)aes2660_start_imaging_cmd;
|
||||
aesdev->start_imaging_cmd_len = sizeof(aes2660_start_imaging_cmd);
|
||||
aesdev->assembling_ctx = &assembling_ctx;
|
||||
aesdev->extra_img_flags = FP_IMG_PARTIAL;
|
||||
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dev_deinit(struct fp_img_dev *dev)
|
||||
{
|
||||
struct aesX660_dev *aesdev;
|
||||
aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(aesdev->buffer);
|
||||
g_free(aesdev);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x08ff, .product = 0x2660 },
|
||||
{ .vendor = 0x08ff, .product = 0x2680 },
|
||||
{ .vendor = 0x08ff, .product = 0x2681 },
|
||||
{ .vendor = 0x08ff, .product = 0x2682 },
|
||||
{ .vendor = 0x08ff, .product = 0x2683 },
|
||||
{ .vendor = 0x08ff, .product = 0x2684 },
|
||||
{ .vendor = 0x08ff, .product = 0x2685 },
|
||||
{ .vendor = 0x08ff, .product = 0x2686 },
|
||||
{ .vendor = 0x08ff, .product = 0x2687 },
|
||||
{ .vendor = 0x08ff, .product = 0x2688 },
|
||||
{ .vendor = 0x08ff, .product = 0x2689 },
|
||||
{ .vendor = 0x08ff, .product = 0x268a },
|
||||
{ .vendor = 0x08ff, .product = 0x268b },
|
||||
{ .vendor = 0x08ff, .product = 0x268c },
|
||||
{ .vendor = 0x08ff, .product = 0x268d },
|
||||
{ .vendor = 0x08ff, .product = 0x268e },
|
||||
{ .vendor = 0x08ff, .product = 0x268f },
|
||||
{ .vendor = 0x08ff, .product = 0x2691 },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_aes2660_init (FpiDeviceAes2660 *self)
|
||||
{
|
||||
}
|
||||
struct fp_img_driver aes2660_driver = {
|
||||
.driver = {
|
||||
.id = AES2660_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "AuthenTec AES2660",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = -1,
|
||||
.img_width = FRAME_WIDTH + FRAME_WIDTH / 2,
|
||||
|
||||
static void
|
||||
fpi_device_aes2660_class_init (FpiDeviceAes2660Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
FpiDeviceAesX660Class *aes_class = FPI_DEVICE_AES_X660_CLASS (klass);
|
||||
|
||||
dev_class->id = "aes2660";
|
||||
dev_class->full_name = "AuthenTec AES2660";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
|
||||
img_class->bz3_threshold = 20;
|
||||
|
||||
img_class->img_width = FRAME_WIDTH + FRAME_WIDTH / 2;
|
||||
img_class->img_height = -1;
|
||||
|
||||
aes_class->init_seqs[0] = aes2660_init_1;
|
||||
aes_class->init_seqs_len[0] = G_N_ELEMENTS (aes2660_init_1);
|
||||
aes_class->init_seqs[1] = aes2660_init_2;
|
||||
aes_class->init_seqs_len[1] = G_N_ELEMENTS (aes2660_init_2);
|
||||
aes_class->start_imaging_cmd = (unsigned char *) aes2660_start_imaging_cmd;
|
||||
aes_class->start_imaging_cmd_len = sizeof (aes2660_start_imaging_cmd);
|
||||
aes_class->assembling_ctx = &assembling_ctx;
|
||||
}
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = aesX660_dev_activate,
|
||||
.deactivate = aesX660_dev_deactivate,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __AES2660_H
|
||||
#define __AES2660_H
|
||||
|
||||
#define AES2660_FRAME_SIZE 0x354
|
||||
|
||||
@@ -1959,3 +1960,5 @@ static const unsigned char aes2660_start_imaging_cmd[] = {
|
||||
0x55, 0x07, 0x00, 0x80, 0x42, 0x00, 0xbf, 0x00, 0x00, 0x18,
|
||||
0x49, 0x03, 0x00, 0x20, 0x08, 0xc8
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
#define FP_COMPONENT "aes3500"
|
||||
|
||||
#include "drivers_api.h"
|
||||
#include "aeslib.h"
|
||||
#include "aes3k.h"
|
||||
|
||||
#define DATA_BUFLEN 0x2089
|
||||
@@ -115,44 +117,67 @@ static struct aes_regwrite init_reqs[] = {
|
||||
{ 0x81, 0x00 },
|
||||
};
|
||||
|
||||
struct _FpiDeviceAes3500
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
FpiDeviceAes3k parent;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceAes3500, fpi_device_aes3500, FPI,
|
||||
DEVICE_AES3500, FpiDeviceAes3k);
|
||||
G_DEFINE_TYPE (FpiDeviceAes3500, fpi_device_aes3500, FPI_TYPE_DEVICE_AES3K);
|
||||
int r;
|
||||
struct aes3k_dev *aesdev;
|
||||
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x08ff, .pid = 0x5731 },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_aes3500_init (FpiDeviceAes3500 *self)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
fpi_device_aes3500_class_init (FpiDeviceAes3500Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
FpiDeviceAes3kClass *aes_class = FPI_DEVICE_AES3K_CLASS (klass);
|
||||
aesdev = g_malloc0(sizeof(struct aes3k_dev));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), aesdev);
|
||||
|
||||
dev_class->id = "aes3500";
|
||||
dev_class->full_name = "AuthenTec AES3500";
|
||||
dev_class->id_table = id_table;
|
||||
if (!aesdev)
|
||||
return -ENOMEM;
|
||||
|
||||
img_class->img_height = FRAME_WIDTH * ENLARGE_FACTOR;
|
||||
img_class->img_width = FRAME_WIDTH * ENLARGE_FACTOR;
|
||||
aesdev->data_buflen = DATA_BUFLEN;
|
||||
aesdev->frame_width = FRAME_WIDTH;
|
||||
aesdev->frame_size = FRAME_SIZE;
|
||||
aesdev->frame_number = FRAME_NUMBER;
|
||||
aesdev->enlarge_factor = ENLARGE_FACTOR;
|
||||
aesdev->init_reqs = init_reqs;
|
||||
aesdev->init_reqs_len = G_N_ELEMENTS(init_reqs);
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
|
||||
aes_class->data_buflen = DATA_BUFLEN;
|
||||
aes_class->frame_width = FRAME_WIDTH;
|
||||
aes_class->frame_size = FRAME_SIZE;
|
||||
aes_class->frame_number = FRAME_NUMBER;
|
||||
aes_class->enlarge_factor = ENLARGE_FACTOR;
|
||||
aes_class->init_reqs = init_reqs;
|
||||
aes_class->init_reqs_len = G_N_ELEMENTS (init_reqs);
|
||||
return r;
|
||||
}
|
||||
|
||||
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_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x08ff, .product = 0x5731 },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
struct fp_img_driver aes3500_driver = {
|
||||
.driver = {
|
||||
.id = AES3500_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "AuthenTec AES3500",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_PRESS,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = FRAME_WIDTH * ENLARGE_FACTOR,
|
||||
.img_width = FRAME_WIDTH * ENLARGE_FACTOR,
|
||||
|
||||
/* temporarily lowered until image quality improves */
|
||||
.bz3_threshold = 9,
|
||||
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = aes3k_dev_activate,
|
||||
.deactivate = aes3k_dev_deactivate,
|
||||
};
|
||||
|
||||
|
||||
@@ -40,30 +40,19 @@
|
||||
#include "aeslib.h"
|
||||
#include "aes3k.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FpiUsbTransfer *img_trf;
|
||||
gboolean deactivating;
|
||||
} FpiDeviceAes3kPrivate;
|
||||
|
||||
#define CTRL_TIMEOUT 1000
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
|
||||
static void do_capture (FpImageDevice *dev);
|
||||
static void do_capture(struct fp_img_dev *dev);
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (FpiDeviceAes3k, fpi_device_aes3k, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
static void
|
||||
aes3k_assemble_image (unsigned char *input, size_t width, size_t height,
|
||||
static void aes3k_assemble_image(unsigned char *input, size_t width, size_t height,
|
||||
unsigned char *output)
|
||||
{
|
||||
size_t row, column;
|
||||
|
||||
for (column = 0; column < width; column++)
|
||||
{
|
||||
for (row = 0; row < height; row += 2)
|
||||
{
|
||||
for (column = 0; column < width; column++) {
|
||||
for (row = 0; row < height; row += 2) {
|
||||
output[width * row + column] = (*input & 0x0f) * 17;
|
||||
output[width * (row + 1) + column] = ((*input & 0xf0) >> 4) * 17;
|
||||
input++;
|
||||
@@ -71,156 +60,99 @@ aes3k_assemble_image (unsigned char *input, size_t width, size_t height,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
img_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void img_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceAes3k *self = FPI_DEVICE_AES3K (device);
|
||||
FpiDeviceAes3kPrivate *priv = fpi_device_aes3k_get_instance_private (self);
|
||||
FpiDeviceAes3kClass *cls = FPI_DEVICE_AES3K_GET_CLASS (self);
|
||||
struct fp_img_dev *dev = transfer->user_data;
|
||||
struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
unsigned char *ptr = transfer->buffer;
|
||||
FpImage *tmp;
|
||||
FpImage *img;
|
||||
struct fp_img *tmp;
|
||||
struct fp_img *img;
|
||||
int i;
|
||||
|
||||
priv->img_trf = NULL;
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (g_error_matches (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_CANCELLED))
|
||||
{
|
||||
/* Deactivation was completed. */
|
||||
g_error_free (error);
|
||||
if (priv->deactivating)
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
return;
|
||||
if (transfer->status == LIBUSB_TRANSFER_CANCELLED) {
|
||||
goto err;
|
||||
} else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_imgdev_session_error(dev, -EIO);
|
||||
goto err;
|
||||
} else if (transfer->length != transfer->actual_length) {
|
||||
fpi_imgdev_session_error(dev, -EPROTO);
|
||||
goto err;
|
||||
}
|
||||
|
||||
fpi_image_device_session_error (dev, error);
|
||||
}
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
|
||||
fpi_image_device_report_finger_status (dev, TRUE);
|
||||
|
||||
tmp = fp_image_new (cls->frame_width, cls->frame_width);
|
||||
tmp->width = cls->frame_width;
|
||||
tmp->height = cls->frame_width;
|
||||
tmp->flags = FPI_IMAGE_COLORS_INVERTED | FPI_IMAGE_V_FLIPPED | FPI_IMAGE_H_FLIPPED;
|
||||
for (i = 0; i < cls->frame_number; i++)
|
||||
{
|
||||
tmp = fpi_img_new(aesdev->frame_width * aesdev->frame_width);
|
||||
tmp->width = aesdev->frame_width;
|
||||
tmp->height = aesdev->frame_width;
|
||||
tmp->flags = FP_IMG_COLORS_INVERTED | FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED;
|
||||
for (i = 0; i < aesdev->frame_number; i++) {
|
||||
fp_dbg("frame header byte %02x", *ptr);
|
||||
ptr++;
|
||||
aes3k_assemble_image (ptr, cls->frame_width, AES3K_FRAME_HEIGHT, tmp->data + (i * cls->frame_width * AES3K_FRAME_HEIGHT));
|
||||
ptr += cls->frame_size;
|
||||
aes3k_assemble_image(ptr, aesdev->frame_width, AES3K_FRAME_HEIGHT, tmp->data + (i * aesdev->frame_width * AES3K_FRAME_HEIGHT));
|
||||
ptr += aesdev->frame_size;
|
||||
}
|
||||
|
||||
/* FIXME: this is an ugly hack to make the image big enough for NBIS
|
||||
* to process reliably */
|
||||
img = fpi_image_resize (tmp, cls->enlarge_factor, cls->enlarge_factor);
|
||||
g_object_unref (tmp);
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
img = fpi_img_resize(tmp, aesdev->enlarge_factor, aesdev->enlarge_factor);
|
||||
fp_img_free(tmp);
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
|
||||
/* FIXME: rather than assuming finger has gone, we should poll regs until
|
||||
* it really has, then restart the capture */
|
||||
fpi_image_device_report_finger_status (dev, FALSE);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
|
||||
do_capture(dev);
|
||||
|
||||
err:
|
||||
g_free(transfer->buffer);
|
||||
aesdev->img_trf = NULL;
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void do_capture(struct fp_img_dev *dev)
|
||||
{
|
||||
struct aes3k_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
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);
|
||||
|
||||
r = libusb_submit_transfer(aesdev->img_trf);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(aesdev->img_trf);
|
||||
aesdev->img_trf = NULL;
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_reqs_cb(struct fp_img_dev *dev, int result, void *user_data)
|
||||
{
|
||||
fpi_imgdev_activate_complete(dev, result);
|
||||
if (result == 0)
|
||||
do_capture(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
do_capture (FpImageDevice *dev)
|
||||
int aes3k_dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceAes3k *self = FPI_DEVICE_AES3K (dev);
|
||||
FpiDeviceAes3kPrivate *priv = fpi_device_aes3k_get_instance_private (self);
|
||||
FpiDeviceAes3kClass *cls = FPI_DEVICE_AES3K_GET_CLASS (self);
|
||||
|
||||
priv->img_trf = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
fpi_usb_transfer_fill_bulk (priv->img_trf, EP_IN, cls->data_buflen);
|
||||
priv->img_trf->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (priv->img_trf, 0,
|
||||
fpi_device_get_cancellable (FP_DEVICE (dev)),
|
||||
img_cb, NULL);
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
init_reqs_cb (FpImageDevice *dev, GError *result, void *user_data)
|
||||
void aes3k_dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
fpi_image_device_activate_complete (dev, result);
|
||||
if (!result)
|
||||
do_capture (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
|
||||
* cleaned up */
|
||||
if (aesdev->img_trf)
|
||||
libusb_cancel_transfer(aesdev->img_trf);
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
aes3k_dev_activate (FpImageDevice *dev)
|
||||
{
|
||||
FpiDeviceAes3k *self = FPI_DEVICE_AES3K (dev);
|
||||
FpiDeviceAes3kPrivate *priv = fpi_device_aes3k_get_instance_private (self);
|
||||
FpiDeviceAes3kClass *cls = FPI_DEVICE_AES3K_GET_CLASS (self);
|
||||
|
||||
priv->deactivating = FALSE;
|
||||
aes_write_regv (dev, cls->init_reqs, cls->init_reqs_len, init_reqs_cb, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
aes3k_dev_deactivate (FpImageDevice *dev)
|
||||
{
|
||||
FpiDeviceAes3k *self = FPI_DEVICE_AES3K (dev);
|
||||
FpiDeviceAes3kPrivate *priv = fpi_device_aes3k_get_instance_private (self);
|
||||
|
||||
priv->deactivating = TRUE;
|
||||
if (priv->img_trf)
|
||||
return;
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
fpi_device_aes3k_init (FpiDeviceAes3k *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
aes3k_dev_init (FpImageDevice *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error))
|
||||
{
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_image_device_open_complete (dev, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
aes3k_dev_deinit (FpImageDevice *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fpi_device_aes3k_class_init (FpiDeviceAes3kClass *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_PRESS;
|
||||
|
||||
img_class->img_open = aes3k_dev_init;
|
||||
img_class->img_close = aes3k_dev_deinit;
|
||||
img_class->activate = aes3k_dev_activate;
|
||||
img_class->deactivate = aes3k_dev_deactivate;
|
||||
|
||||
/* Extremely low due to low image quality. */
|
||||
img_class->bz3_threshold = 9;
|
||||
|
||||
/* Everything else is set by the subclasses. */
|
||||
}
|
||||
|
||||
@@ -34,27 +34,25 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "fpi-image-device.h"
|
||||
#include "aeslib.h"
|
||||
#ifndef __AES3K_H
|
||||
#define __AES3K_H
|
||||
|
||||
#define AES3K_FRAME_HEIGHT 16
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (FpiDeviceAes3k, fpi_device_aes3k, FPI,
|
||||
DEVICE_AES3K, FpImageDevice)
|
||||
struct aes3k_dev {
|
||||
struct libusb_transfer *img_trf;
|
||||
size_t frame_width; /* image size = frame_width x frame_width */
|
||||
size_t frame_size; /* 4 bits/pixel: frame_width x AES3K_FRAME_HEIGHT / 2 */
|
||||
size_t frame_number; /* number of frames */
|
||||
size_t enlarge_factor;
|
||||
|
||||
#define FPI_TYPE_DEVICE_AES3K (fpi_device_aes3k_get_type ())
|
||||
|
||||
struct _FpiDeviceAes3kClass
|
||||
{
|
||||
FpImageDeviceClass parent;
|
||||
|
||||
gsize frame_width; /* image size = frame_width x frame_width */
|
||||
gsize frame_size; /* 4 bits/pixel: frame_width x AES3K_FRAME_HEIGHT / 2 */
|
||||
gsize frame_number; /* number of frames */
|
||||
gsize enlarge_factor;
|
||||
|
||||
gsize data_buflen; /* buffer length of usb bulk transfer */
|
||||
size_t data_buflen; /* buffer length of usb bulk transfer */
|
||||
struct aes_regwrite *init_reqs; /* initial values sent to device */
|
||||
gsize init_reqs_len;
|
||||
size_t init_reqs_len;
|
||||
};
|
||||
|
||||
|
||||
int aes3k_dev_activate(struct fp_img_dev *dev);
|
||||
void aes3k_dev_deactivate(struct fp_img_dev *dev);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
#define FP_COMPONENT "aes4000"
|
||||
|
||||
#include "drivers_api.h"
|
||||
#include "aeslib.h"
|
||||
#include "aes3k.h"
|
||||
|
||||
#define DATA_BUFLEN 0x1259
|
||||
@@ -112,44 +114,67 @@ static struct aes_regwrite init_reqs[] = {
|
||||
{ 0x81, 0x00 },
|
||||
};
|
||||
|
||||
struct _FpiDeviceAes4000
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
FpiDeviceAes3k parent;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceAes4000, fpi_device_aes4000, FPI,
|
||||
DEVICE_AES4000, FpiDeviceAes3k);
|
||||
G_DEFINE_TYPE (FpiDeviceAes4000, fpi_device_aes4000, FPI_TYPE_DEVICE_AES3K);
|
||||
int r;
|
||||
struct aes3k_dev *aesdev;
|
||||
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .pid = 0x08ff, .vid = 0x5501 },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_aes4000_init (FpiDeviceAes4000 *self)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
fpi_device_aes4000_class_init (FpiDeviceAes4000Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
FpiDeviceAes3kClass *aes_class = FPI_DEVICE_AES3K_CLASS (klass);
|
||||
aesdev = g_malloc0(sizeof(struct aes3k_dev));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), aesdev);
|
||||
|
||||
dev_class->id = "aes4000";
|
||||
dev_class->full_name = "AuthenTec AES4000";
|
||||
dev_class->id_table = id_table;
|
||||
if (!aesdev)
|
||||
return -ENOMEM;
|
||||
|
||||
img_class->img_height = FRAME_WIDTH * ENLARGE_FACTOR;
|
||||
img_class->img_width = FRAME_WIDTH * ENLARGE_FACTOR;
|
||||
aesdev->data_buflen = DATA_BUFLEN;
|
||||
aesdev->frame_width = FRAME_WIDTH;
|
||||
aesdev->frame_size = FRAME_SIZE;
|
||||
aesdev->frame_number = FRAME_NUMBER;
|
||||
aesdev->enlarge_factor = ENLARGE_FACTOR;
|
||||
aesdev->init_reqs = init_reqs;
|
||||
aesdev->init_reqs_len = G_N_ELEMENTS(init_reqs);
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
|
||||
aes_class->data_buflen = DATA_BUFLEN;
|
||||
aes_class->frame_width = FRAME_WIDTH;
|
||||
aes_class->frame_size = FRAME_SIZE;
|
||||
aes_class->frame_number = FRAME_NUMBER;
|
||||
aes_class->enlarge_factor = ENLARGE_FACTOR;
|
||||
aes_class->init_reqs = init_reqs;
|
||||
aes_class->init_reqs_len = G_N_ELEMENTS (init_reqs);
|
||||
return r;
|
||||
}
|
||||
|
||||
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_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x08ff, .product = 0x5501 },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
struct fp_img_driver aes4000_driver = {
|
||||
.driver = {
|
||||
.id = AES4000_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "AuthenTec AES4000",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_PRESS,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = FRAME_WIDTH * ENLARGE_FACTOR,
|
||||
.img_width = FRAME_WIDTH * ENLARGE_FACTOR,
|
||||
|
||||
/* temporarily lowered until image quality improves */
|
||||
.bz3_threshold = 9,
|
||||
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = aes3k_dev_activate,
|
||||
.deactivate = aes3k_dev_deactivate,
|
||||
};
|
||||
|
||||
|
||||
@@ -19,21 +19,25 @@
|
||||
|
||||
#define FP_COMPONENT "aeslib"
|
||||
|
||||
#include "drivers_api.h"
|
||||
#include "fp_internal.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "fpi-usb.h"
|
||||
#include "fpi-assembling.h"
|
||||
#include "aeslib.h"
|
||||
|
||||
#define MAX_REGWRITES_PER_REQUEST 16
|
||||
|
||||
#define BULK_TIMEOUT 4000
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
|
||||
struct write_regv_data
|
||||
{
|
||||
struct write_regv_data {
|
||||
struct fp_img_dev *imgdev;
|
||||
unsigned int num_regs;
|
||||
const struct aes_regwrite *regs;
|
||||
unsigned int offset;
|
||||
@@ -41,72 +45,70 @@ struct write_regv_data
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
static void continue_write_regv (FpImageDevice *dev,
|
||||
struct write_regv_data *wdata);
|
||||
static void continue_write_regv(struct write_regv_data *wdata);
|
||||
|
||||
/* libusb bulk callback for regv write completion transfer. continues the
|
||||
* transaction */
|
||||
static void
|
||||
write_regv_trf_complete (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void write_regv_trf_complete(struct libusb_transfer *transfer)
|
||||
{
|
||||
struct write_regv_data *wdata = user_data;
|
||||
struct write_regv_data *wdata = transfer->user_data;
|
||||
|
||||
if (error)
|
||||
{
|
||||
wdata->callback (FP_IMAGE_DEVICE (device), error, wdata->user_data);
|
||||
g_free (wdata);
|
||||
}
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED)
|
||||
wdata->callback(wdata->imgdev, -EIO, wdata->user_data);
|
||||
else if (transfer->length != transfer->actual_length)
|
||||
wdata->callback(wdata->imgdev, -EPROTO, wdata->user_data);
|
||||
else
|
||||
{
|
||||
continue_write_regv (FP_IMAGE_DEVICE (device), wdata);
|
||||
}
|
||||
continue_write_regv(wdata);
|
||||
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
/* write from wdata->offset to upper_bound (inclusive) of wdata->regs */
|
||||
static void
|
||||
do_write_regv (FpImageDevice *dev, struct write_regv_data *wdata, int upper_bound)
|
||||
static int do_write_regv(struct write_regv_data *wdata, int upper_bound)
|
||||
{
|
||||
unsigned int offset = wdata->offset;
|
||||
unsigned int num = upper_bound - offset + 1;
|
||||
size_t alloc_size = num * 2;
|
||||
unsigned char *data = g_malloc(alloc_size);
|
||||
unsigned int i;
|
||||
size_t data_offset = 0;
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
int r;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer, EP_OUT, alloc_size);
|
||||
|
||||
for (i = offset; i < offset + num; i++)
|
||||
{
|
||||
for (i = offset; i < offset + num; i++) {
|
||||
const struct aes_regwrite *regwrite = &wdata->regs[i];
|
||||
transfer->buffer[data_offset++] = regwrite->reg;
|
||||
transfer->buffer[data_offset++] = regwrite->value;
|
||||
data[data_offset++] = regwrite->reg;
|
||||
data[data_offset++] = regwrite->value;
|
||||
}
|
||||
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
write_regv_trf_complete, wdata);
|
||||
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) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* write the next batch of registers to be written, or if there are no more,
|
||||
* indicate completion to the caller */
|
||||
static void
|
||||
continue_write_regv (FpImageDevice *dev, struct write_regv_data *wdata)
|
||||
static void continue_write_regv(struct write_regv_data *wdata)
|
||||
{
|
||||
unsigned int offset = wdata->offset;
|
||||
unsigned int regs_remaining;
|
||||
unsigned int limit;
|
||||
unsigned int upper_bound;
|
||||
int i;
|
||||
int r;
|
||||
|
||||
/* skip all zeros and ensure there is still work to do */
|
||||
while (TRUE)
|
||||
{
|
||||
if (offset >= wdata->num_regs)
|
||||
{
|
||||
while (TRUE) {
|
||||
if (offset >= wdata->num_regs) {
|
||||
fp_dbg("all registers written");
|
||||
wdata->callback (dev, 0, wdata->user_data);
|
||||
g_free (wdata);
|
||||
wdata->callback(wdata->imgdev, 0, wdata->user_data);
|
||||
return;
|
||||
}
|
||||
if (wdata->regs[offset].reg)
|
||||
@@ -122,13 +124,16 @@ continue_write_regv (FpImageDevice *dev, struct write_regv_data *wdata)
|
||||
/* determine if we can write the entire of the regs at once, or if there
|
||||
* is a zero dividing things up */
|
||||
for (i = offset; i <= upper_bound; i++)
|
||||
if (!wdata->regs[i].reg)
|
||||
{
|
||||
if (!wdata->regs[i].reg) {
|
||||
upper_bound = i - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
do_write_regv (dev, wdata, upper_bound);
|
||||
r = do_write_regv(wdata, upper_bound);
|
||||
if (r < 0) {
|
||||
wdata->callback(wdata->imgdev, r, wdata->user_data);
|
||||
return;
|
||||
}
|
||||
|
||||
wdata->offset = upper_bound + 1;
|
||||
}
|
||||
@@ -136,25 +141,25 @@ continue_write_regv (FpImageDevice *dev, struct write_regv_data *wdata)
|
||||
/* write a load of registers to the device, combining multiple writes in a
|
||||
* single URB up to a limit. insert writes to non-existent register 0 to force
|
||||
* specific groups of writes to be separated by different URBs. */
|
||||
void
|
||||
aes_write_regv (FpImageDevice *dev, const struct aes_regwrite *regs,
|
||||
unsigned int num_regs, aes_write_regv_cb callback,
|
||||
void *user_data)
|
||||
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;
|
||||
|
||||
fp_dbg("write %d regs", num_regs);
|
||||
wdata = g_malloc(sizeof(*wdata));
|
||||
wdata->imgdev = dev;
|
||||
wdata->num_regs = num_regs;
|
||||
wdata->regs = regs;
|
||||
wdata->offset = 0;
|
||||
wdata->callback = callback;
|
||||
wdata->user_data = user_data;
|
||||
continue_write_regv (dev, wdata);
|
||||
continue_write_regv(wdata);
|
||||
|
||||
g_free(wdata);
|
||||
}
|
||||
|
||||
unsigned char
|
||||
aes_get_pixel (struct fpi_frame_asmbl_ctx *ctx,
|
||||
unsigned char aes_get_pixel(struct fpi_frame_asmbl_ctx *ctx,
|
||||
struct fpi_frame *frame,
|
||||
unsigned int x,
|
||||
unsigned int y)
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __AESLIB_H__
|
||||
#define __AESLIB_H__
|
||||
|
||||
#include <fprint.h>
|
||||
|
||||
struct aes_regwrite
|
||||
{
|
||||
struct aes_regwrite {
|
||||
unsigned char reg;
|
||||
unsigned char value;
|
||||
};
|
||||
@@ -30,17 +30,16 @@ struct aes_regwrite
|
||||
struct fpi_frame;
|
||||
struct fpi_frame_asmbl_ctx;
|
||||
|
||||
typedef void (*aes_write_regv_cb)(FpImageDevice *dev,
|
||||
GError *error,
|
||||
typedef void (*aes_write_regv_cb)(struct fp_img_dev *dev, int result,
|
||||
void *user_data);
|
||||
|
||||
void aes_write_regv (FpImageDevice *dev,
|
||||
const struct aes_regwrite *regs,
|
||||
unsigned int num_regs,
|
||||
aes_write_regv_cb callback,
|
||||
void *user_data);
|
||||
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);
|
||||
|
||||
unsigned char aes_get_pixel(struct fpi_frame_asmbl_ctx *ctx,
|
||||
struct fpi_frame *frame,
|
||||
unsigned int x,
|
||||
unsigned int y);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __AESX660_H
|
||||
#define __AESX660_H
|
||||
|
||||
#define AESX660_HEADER_SIZE 3
|
||||
#define AESX660_RESPONSE_TYPE_OFFSET 0x00
|
||||
@@ -42,32 +43,37 @@
|
||||
|
||||
#define AESX660_FRAME_HEIGHT 8
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (FpiDeviceAesX660, fpi_device_aes_x660, FPI,
|
||||
DEVICE_AES_X660, FpImageDevice)
|
||||
|
||||
#define FPI_TYPE_DEVICE_AES_X660 (fpi_device_aes_x660_get_type ())
|
||||
|
||||
struct _FpiDeviceAesX660Class
|
||||
{
|
||||
FpImageDeviceClass parent;
|
||||
struct aesX660_dev {
|
||||
GSList *strips;
|
||||
size_t strips_len;
|
||||
gboolean deactivating;
|
||||
struct aesX660_cmd *init_seq;
|
||||
size_t init_seq_len;
|
||||
unsigned int init_cmd_idx;
|
||||
unsigned int init_seq_idx;
|
||||
struct libusb_transfer *fd_data_transfer;
|
||||
unsigned char *buffer;
|
||||
size_t buffer_size;
|
||||
size_t buffer_max;
|
||||
|
||||
/* Device-specific stuff */
|
||||
struct aesX660_cmd *init_seqs[2];
|
||||
gsize init_seqs_len[2];
|
||||
guint8 *start_imaging_cmd;
|
||||
gsize start_imaging_cmd_len;
|
||||
size_t init_seqs_len[2];
|
||||
unsigned char *start_imaging_cmd;
|
||||
size_t start_imaging_cmd_len;
|
||||
struct fpi_frame_asmbl_ctx *assembling_ctx;
|
||||
uint16_t extra_img_flags;
|
||||
};
|
||||
|
||||
struct aesX660_cmd
|
||||
{
|
||||
const guint8 *cmd;
|
||||
gsize len;
|
||||
struct aesX660_cmd {
|
||||
const unsigned char *cmd;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
/* 0x77 cmd seems to control LED, this sequence
|
||||
* makes LED blink
|
||||
*/
|
||||
static const guint8 led_blink_cmd[] = {
|
||||
static const unsigned char led_blink_cmd[] = {
|
||||
0x77, 0x18, 0x00,
|
||||
0x00, 0x3f, 0x00, 0xff, 0x00,
|
||||
0x01, 0x01, 0x00, 0x00, 0x00, 0xf3, 0x01, 0x00,
|
||||
@@ -77,35 +83,40 @@ static const guint8 led_blink_cmd[] = {
|
||||
|
||||
/* This sequence makes LED light solid
|
||||
*/
|
||||
static const guint8 led_solid_cmd[] = {
|
||||
static const unsigned char led_solid_cmd[] = {
|
||||
0x77, 0x18, 0x00, 0x00, 0x3f, 0x00, 0xff, 0x00,
|
||||
0x01, 0x01, 0x00, 0x00, 0x00, 0xe7, 0x03, 0x00,
|
||||
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x7f
|
||||
};
|
||||
|
||||
static const guint8 wait_for_finger_cmd[] = {
|
||||
static const unsigned char wait_for_finger_cmd[] = {
|
||||
0x20,
|
||||
0x40, 0x04, 0x00, 0x02, 0x1e, 0x00, 0x32
|
||||
};
|
||||
|
||||
/* 0x40 cmd response
|
||||
*
|
||||
static const guint8 pkt1371[] = {
|
||||
static const unsigned char pkt1371[] = {
|
||||
0x40, 0x01, 0x00, 0x01
|
||||
};
|
||||
*/
|
||||
|
||||
static const guint8 set_idle_cmd[] = {
|
||||
static const unsigned char set_idle_cmd[] = {
|
||||
0x0d, /* Reset or "set idle"? */
|
||||
};
|
||||
|
||||
static const guint8 read_id_cmd[] = {
|
||||
static const unsigned char read_id_cmd[] = {
|
||||
0x44, 0x02, 0x00, 0x08, 0x00, /* Max transfer size is 8 */
|
||||
0x07, /* Read ID? */
|
||||
};
|
||||
|
||||
static const guint8 calibrate_cmd[] = {
|
||||
static const unsigned char calibrate_cmd[] = {
|
||||
0x44, 0x02, 0x00, 0x04, 0x00,
|
||||
0x06,
|
||||
};
|
||||
|
||||
int aesX660_dev_activate(struct fp_img_dev *dev);
|
||||
void aesX660_dev_deactivate(struct fp_img_dev *dev);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Example fingerprint device prints listing and deletion
|
||||
* Enrolls your right index finger and saves the print to disk
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
* Driver IDs
|
||||
* Copyright (C) 2012 Vasily Khoruzhick <anarsoul@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -18,18 +17,31 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __DRIVER_IDS
|
||||
#define __DRIVER_IDS
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wredundant-decls"
|
||||
enum {
|
||||
UPEKTS_ID = 1,
|
||||
URU4000_ID = 2,
|
||||
AES4000_ID = 3,
|
||||
AES2501_ID = 4,
|
||||
UPEKTC_ID = 5,
|
||||
AES1610_ID = 6,
|
||||
/* FDU2000_ID = 7, */
|
||||
VCOM5S_ID = 8,
|
||||
UPEKSONLY_ID = 9,
|
||||
VFS101_ID = 10,
|
||||
VFS301_ID = 11,
|
||||
AES2550_ID = 12,
|
||||
/* UPEKE2_ID = 13 */
|
||||
AES1660_ID = 14,
|
||||
AES2660_ID = 15,
|
||||
AES3500_ID = 16,
|
||||
UPEKTC_IMG_ID = 17,
|
||||
ETES603_ID = 18,
|
||||
VFS5011_ID = 19,
|
||||
VFS0050_ID = 20,
|
||||
ELAN_ID = 21,
|
||||
};
|
||||
|
||||
#include <bozorth.h>
|
||||
#include <bz_array.h>
|
||||
#include <defs.h>
|
||||
#include <lfs.h>
|
||||
#include <log.h>
|
||||
#include <morph.h>
|
||||
#include <mytime.h>
|
||||
#include <sunrast.h>
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
@@ -18,9 +18,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __ELAN_H
|
||||
#define __ELAN_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <libusb.h>
|
||||
|
||||
#define ELAN_VEND_ID 0x04f3
|
||||
|
||||
@@ -58,9 +59,9 @@
|
||||
#define ELAN_SKIP_LAST_FRAMES 2
|
||||
|
||||
#define ELAN_CMD_LEN 0x2
|
||||
#define ELAN_EP_CMD_OUT (0x1 | FPI_USB_ENDPOINT_OUT)
|
||||
#define ELAN_EP_CMD_IN (0x3 | FPI_USB_ENDPOINT_IN)
|
||||
#define ELAN_EP_IMG_IN (0x2 | FPI_USB_ENDPOINT_IN)
|
||||
#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
|
||||
@@ -70,13 +71,11 @@
|
||||
#define ELAN_CMD_TIMEOUT 10000
|
||||
#define ELAN_FINGER_TIMEOUT 200
|
||||
|
||||
struct elan_cmd
|
||||
{
|
||||
struct elan_cmd {
|
||||
unsigned char cmd[ELAN_CMD_LEN];
|
||||
int response_len;
|
||||
int response_in;
|
||||
unsigned short devices;
|
||||
gboolean never_cancel;
|
||||
};
|
||||
|
||||
static const struct elan_cmd get_sensor_dim_cmd = {
|
||||
@@ -153,73 +152,73 @@ static const struct elan_cmd stop_cmd = {
|
||||
.response_len = ELAN_CMD_SKIP_READ,
|
||||
.response_in = ELAN_EP_CMD_IN,
|
||||
.devices = ELAN_ALL_DEV,
|
||||
.never_cancel = TRUE,
|
||||
};
|
||||
|
||||
static const FpIdEntry elan_id_table[] = {
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0903, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0907, .driver_data = ELAN_0907},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c01, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c02, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c03, .driver_data = ELAN_0C03},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c04, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c05, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c06, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c07, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c08, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c09, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c0a, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c0b, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c0c, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c0d, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c0e, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c0f, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c10, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c11, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c12, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c13, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c14, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c15, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c16, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c17, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c18, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c19, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c1a, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c1b, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c1c, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c1d, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c1e, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c1f, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c20, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c21, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c22, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c23, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c24, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c25, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c26, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c27, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c28, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c29, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c2a, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c2b, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c2c, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c2d, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c2e, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c2f, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c30, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c31, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c32, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c33, .driver_data = ELAN_ALL_DEV},
|
||||
{.vid = ELAN_VEND_ID, .pid = 0x0c42, .driver_data = ELAN_0C42},
|
||||
{.vid = 0, .pid = 0, .driver_data = 0},
|
||||
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_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},
|
||||
{.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},
|
||||
{.vendor = ELAN_VEND_ID,.product = 0x0c42,.driver_data = ELAN_0C42},
|
||||
{0, 0, 0,},
|
||||
};
|
||||
|
||||
static void elan_cmd_done (FpiSsm *ssm);
|
||||
static void elan_cmd_read (FpiSsm *ssm,
|
||||
FpDevice *dev);
|
||||
static void elan_cmd_done(fpi_ssm *ssm);
|
||||
static void elan_cmd_read(fpi_ssm *ssm, struct fp_img_dev *dev);
|
||||
|
||||
static void elan_calibrate (FpDevice *dev);
|
||||
static void elan_capture (FpDevice *dev);
|
||||
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 void dev_change_state (FpImageDevice *dev,
|
||||
FpiImageDeviceState state);
|
||||
static int dev_change_state(struct fp_img_dev *dev, enum fp_imgdev_state state);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
/*
|
||||
* Synaptics MiS Fingerprint Sensor Interface
|
||||
* Copyright (C) 2019 Synaptics Inc
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**< User ID maximum length allowed */
|
||||
#define BMKT_MAX_USER_ID_LEN 100
|
||||
/**< Software Part Number length */
|
||||
#define BMKT_PART_NUM_LEN 10
|
||||
/**< Software supplier identification length */
|
||||
#define BMKT_SUPPLIER_ID_LEN 2
|
||||
|
||||
/**< Maximum namber of templates for storing in internal flash of the fingerprint sensor */
|
||||
#define BMKT_MAX_NUM_TEMPLATES_INTERNAL_FLASH 15
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bmkt_response.h"
|
||||
|
||||
/*!
|
||||
*******************************************************************************
|
||||
** Type definition for result
|
||||
*/
|
||||
/** No error; Operation successfully completed. */
|
||||
#define BMKT_SUCCESS 0
|
||||
/** Fingerprint system not initialized */
|
||||
#define BMKT_FP_SYSTEM_NOT_INITIALIZED 101
|
||||
/** Fingerprint system busy performing another operation */
|
||||
#define BMKT_FP_SYSTEM_BUSY 102
|
||||
/** Operation not allowed */
|
||||
#define BMKT_OPERATION_DENIED 103
|
||||
/** System ran out of memory while performing operation */
|
||||
#define BMKT_OUT_OF_MEMORY 104
|
||||
/** Corrupt message, CRC check fail or truncated message */
|
||||
#define BMKT_CORRUPT_MESSAGE 110
|
||||
/** One of the command parameters is outside the range of valid values */
|
||||
#define BMKT_INVALID_PARAM 111
|
||||
/** Unrecognized message or message with invalid message ID */
|
||||
#define BMKT_UNRECOGNIZED_MESSAGE 112
|
||||
/** Operation time out */
|
||||
#define BMKT_OP_TIME_OUT 113
|
||||
/** General error – cause of error cannot be determined */
|
||||
#define BMKT_GENERAL_ERROR 114
|
||||
|
||||
#define BMKT_SET_SECURITY_LEVEL_FAIL 120
|
||||
#define BMKT_GET_SECURITY_LEVEL_FAIL 121
|
||||
|
||||
/** Fingerprint sensor reset while operation was being performed */
|
||||
#define BMKT_SENSOR_RESET 201
|
||||
/** Fingerprint sensor malfunctioned */
|
||||
#define BMKT_SENSOR_MALFUNCTION 202
|
||||
/** Fingerprint sensor cannot be accessed despite repeated attempts */
|
||||
#define BMKT_SENSOR_TAMPERED 203
|
||||
/**
|
||||
* BMKT_SENSOR_NOT_INIT:
|
||||
* Fingerprint sensor module not initialized yet – not ready for use
|
||||
* (different from error code 101 which indicates that the entire system
|
||||
* has not been initialized)
|
||||
*/
|
||||
#define BMKT_SENSOR_NOT_INIT 204
|
||||
/** Number of re-pairing operations exceeded limit or re-pairing has been disabled */
|
||||
#define BMKT_OWNERSHIP_RESET_MAX_EXCEEDED 205
|
||||
/**
|
||||
* BMKT_SENSOR_STIMULUS_ERROR:
|
||||
* There is a finger or debris on the sensor that needs to be removed
|
||||
* before issuing this command
|
||||
*/
|
||||
#define BMKT_SENSOR_STIMULUS_ERROR 213
|
||||
/**
|
||||
* BMKT_CORRUPT_TEMPLATE_DATA:
|
||||
* One of the fingerprint templates stored on flash is corrupt.
|
||||
* This error code is returned in case of failure in finding a fingerprint match
|
||||
* during identify or verify operations while also detecting that one or more
|
||||
* fingerprint templates stored on the flash has become corrupted
|
||||
*/
|
||||
#define BMKT_CORRUPT_TEMPLATE_DATA 300
|
||||
/** Failed to extract features from fingerprint image acquired by sensor */
|
||||
#define BMKT_FEATURE_EXTRACT_FAIL 301
|
||||
/** Failed to generate fingerprint template */
|
||||
#define BMKT_ENROLL_FAIL 302
|
||||
/** Specified finger already enrolled for this user */
|
||||
#define BMKT_ENROLLMENT_EXISTS 303
|
||||
/** Invalid fingerprint image */
|
||||
#define BMKT_INVALID_FP_IMAGE 304
|
||||
/** No matching user fingerprint template found in database */
|
||||
#define BMKT_FP_NO_MATCH 404
|
||||
/** Fingerprint database is full */
|
||||
#define BMKT_FP_DATABASE_FULL 501
|
||||
/** Fingerprint database is empty */
|
||||
#define BMKT_FP_DATABASE_EMPTY 502
|
||||
/** Cannot access fingerprint database */
|
||||
#define BMKT_FP_DATABASE_ACCESS_FAIL 503
|
||||
/** Fingerprint template record does not exist */
|
||||
#define BMKT_FP_DATABASE_NO_RECORD_EXISTS 504
|
||||
/** Failed to read/write system parameters stored on flash */
|
||||
#define BMKT_FP_PARAM_ACCESS_FAIL 505
|
||||
/** Fingerprint is a spoof */
|
||||
#define BMKT_FP_SPOOF_ALERT 801
|
||||
/** Anti-spoof module failure */
|
||||
#define BMKT_ANTI_SPOOF_MODULE_FAIL 802
|
||||
|
||||
#define BMKT_CORRUPT_UPDATE_IMAGE 901
|
||||
#define BMKT_SYSTEM_UPDATE_FAIL 902
|
||||
|
||||
#define BMKT_EVENT_NOT_SET 1000
|
||||
#define BMKT_SENSOR_NOT_READY 1001
|
||||
#define BMKT_TIMEOUT 1002
|
||||
#define BMKT_SENSOR_RESPONSE_PENDING 1003
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* bmkt_mode:
|
||||
* Fingerprint system operational mode values level 1
|
||||
*/
|
||||
typedef enum bmkt_mode {
|
||||
BMKT_STATE_UNINIT = 0xFF,
|
||||
BMKT_STATE_IDLE = 0x00,
|
||||
BMKT_STATE_ENROLL = 0x10,
|
||||
BMKT_STATE_IDENTIFY = 0x20,
|
||||
BMKT_STATE_VERIFY = 0x30,
|
||||
BMKT_STATE_DB_OPS = 0x40,
|
||||
BMKT_STATE_SYS_TEST = 0x50,
|
||||
BMKT_STATE_SYS_OPS = 0x60,
|
||||
} bmkt_mode_t;
|
||||
|
||||
/**
|
||||
* bmkt_mode_level2:
|
||||
* Fingerprint system operational mode values level 2
|
||||
*/
|
||||
typedef enum bmkt_mode_level2 {
|
||||
BMKT_STATE_L2_IDLE = 0x00,
|
||||
BMKT_STATE_L2_STARTING = 0x11,
|
||||
BMKT_STATE_L2_WAITING_FOR_FINGER = 0x12,
|
||||
BMKT_STATE_L2_CAPTURE_IMAGE = 0x13,
|
||||
BMKT_STATE_L2_CAPTURE_COMPLETE = 0x14,
|
||||
BMKT_STATE_L2_EXTRACT_FEATURE = 0x15,
|
||||
BMKT_STATE_L2_CREATE_TEMPLATE = 0x16,
|
||||
BMKT_STATE_L2_READING_FROM_FLASH = 0x17,
|
||||
BMKT_STATE_L2_WRITING_TO_FLASH = 0x18,
|
||||
BMKT_STATE_L2_FINISHING = 0x19,
|
||||
BMKT_STATE_L2_CANCELING_OP = 0x20,
|
||||
BMKT_STATE_L2_MATCHING = 0x21,
|
||||
BMKT_STATE_L2_TRANSMITTING_RESPONSE = 0x22,
|
||||
BMKT_STATE_L2_READY_POWER_DOWN = 0xF0,
|
||||
} bmkt_mode_level2_t;
|
||||
|
||||
/**
|
||||
* bmkt_transport_type:
|
||||
* Fingerprint system transport types
|
||||
*/
|
||||
typedef enum bmkt_transport_type {
|
||||
BMKT_TRANSPORT_TYPE_USB = 0,
|
||||
} bmkt_transport_type_t;
|
||||
|
||||
/**
|
||||
* bmkt_usb_config:
|
||||
* Structure represcontainingenting USB configuration details
|
||||
*/
|
||||
typedef struct bmkt_usb_config
|
||||
{
|
||||
int product_id; /**< USB device product ID */
|
||||
} bmkt_usb_config_t;
|
||||
|
||||
/**
|
||||
* bmkt_transport_config_t:
|
||||
* Union containing transport configuration details
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
bmkt_usb_config_t usb_config;
|
||||
} bmkt_transport_config_t;
|
||||
|
||||
/**
|
||||
* bmkt_sensor_desc_t:
|
||||
* Structure containing fingerprint system description
|
||||
*/
|
||||
typedef struct bmkt_sensor_desc
|
||||
{
|
||||
int product_id;
|
||||
int flags;
|
||||
} bmkt_sensor_desc_t;
|
||||
|
||||
/**
|
||||
* bmkt_finger_state_t:
|
||||
* Finger state representation values.
|
||||
*/
|
||||
typedef enum {
|
||||
BMKT_FINGER_STATE_UNKNOWN = 0,
|
||||
BMKT_FINGER_STATE_ON_SENSOR,
|
||||
BMKT_FINGER_STATE_NOT_ON_SENSOR,
|
||||
} bmkt_finger_state_t;
|
||||
|
||||
/**
|
||||
* bmkt_finger_event_t:
|
||||
* Structure containing finger state
|
||||
*/
|
||||
typedef struct bmkt_finger_event
|
||||
{
|
||||
bmkt_finger_state_t finger_state;
|
||||
} bmkt_finger_event_t;
|
||||
|
||||
typedef struct bmkt_user_id
|
||||
{
|
||||
uint8_t user_id_len;
|
||||
uint8_t user_id[BMKT_MAX_USER_ID_LEN];
|
||||
} bmkt_user_id_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,400 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Synaptics Inc
|
||||
*
|
||||
* 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 <glib.h>
|
||||
#include "bmkt_response.h"
|
||||
#include "bmkt_message.h"
|
||||
|
||||
static uint8_t
|
||||
extract8 (const uint8_t *buf, int *offset)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
int off = 0;
|
||||
|
||||
if (offset)
|
||||
off = *offset;
|
||||
|
||||
ret = *(buf + off);
|
||||
|
||||
if (offset)
|
||||
*offset += 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
parse_error_response (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
if (msg_resp->payload_len != 2)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
resp->result = (msg_resp->payload[0] << 8) | msg_resp->payload[1];
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_init_ok (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_init_resp_t *init_resp = &resp->response.init_resp;
|
||||
|
||||
if (msg_resp->payload_len != 1)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
init_resp->finger_presence = extract8 (msg_resp->payload, NULL);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
parse_fps_mode_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
int offset = 0;
|
||||
bmkt_fps_mode_resp_t *fps_mode_resp = &resp->response.fps_mode_resp;
|
||||
|
||||
if (msg_resp->payload_len != sizeof (bmkt_fps_mode_resp_t))
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
fps_mode_resp->mode = extract8 (msg_resp->payload, &offset);
|
||||
fps_mode_resp->level2_mode = extract8 (msg_resp->payload, &offset);
|
||||
fps_mode_resp->cmd_id = extract8 (msg_resp->payload, &offset);
|
||||
fps_mode_resp->finger_presence = extract8 (msg_resp->payload, &offset);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_enroll_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_enroll_resp_t *enroll_resp = &resp->response.enroll_resp;
|
||||
|
||||
if (msg_resp->payload_len != 1)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
enroll_resp->progress = extract8 (msg_resp->payload, NULL);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_enroll_ok (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_enroll_resp_t *enroll_resp = &resp->response.enroll_resp;
|
||||
|
||||
if (msg_resp->payload_len < 1 || msg_resp->payload_len > (BMKT_MAX_USER_ID_LEN + 1))
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
enroll_resp->finger_id = msg_resp->payload[0];
|
||||
memcpy (enroll_resp->user_id, &msg_resp->payload[1], msg_resp->payload_len - 1);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_auth_ok (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_identify_resp_t *id_resp = &resp->response.id_resp;
|
||||
|
||||
if (msg_resp->payload_len < 3 || msg_resp->payload_len > (BMKT_MAX_USER_ID_LEN + 3))
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
id_resp->match_result = (double) msg_resp->payload[0] + 0.01 * (double) msg_resp->payload[1];
|
||||
id_resp->finger_id = msg_resp->payload[2];
|
||||
memcpy (id_resp->user_id, &msg_resp->payload[3], msg_resp->payload_len - 3);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_security_level_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_set_sec_level_resp_t *sec_level_resp = &resp->response.sec_level_resp;
|
||||
|
||||
if (msg_resp->payload_len != 1)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
sec_level_resp->sec_level = extract8 (msg_resp->payload, NULL);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_del_all_users_progress_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_del_all_users_resp_t *del_all_users_resp = &resp->response.del_all_users_resp;
|
||||
|
||||
if (msg_resp->payload_len != 1)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
del_all_users_resp->progress = extract8 (msg_resp->payload, NULL);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_db_cap_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_get_db_capacity_resp_t *db_cap_resp = &resp->response.db_cap_resp;
|
||||
int offset = 0;
|
||||
|
||||
if (msg_resp->payload_len < 2 || msg_resp->payload_len > 4)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
db_cap_resp->total = extract8 (msg_resp->payload, &offset);
|
||||
db_cap_resp->empty = extract8 (msg_resp->payload, &offset);
|
||||
|
||||
if (msg_resp->payload_len == 4)
|
||||
{
|
||||
db_cap_resp->bad_slots = extract8 (msg_resp->payload, &offset);
|
||||
db_cap_resp->corrupt_templates = extract8 (msg_resp->payload, &offset);
|
||||
}
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_get_enrolled_fingers_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
int offset = 0;
|
||||
int i = 0;
|
||||
|
||||
if (msg_resp->payload_len < 2)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
/* 2 bytes per finger so calculate the total number of fingers to process*/
|
||||
int num_fingers = (msg_resp->payload_len) / 2;
|
||||
|
||||
bmkt_enrolled_fingers_resp_t *get_enrolled_fingers_resp = &resp->response.enrolled_fingers_resp;
|
||||
|
||||
for (i = 0; i < num_fingers; i++)
|
||||
{
|
||||
get_enrolled_fingers_resp->fingers[i].finger_id = extract8 (msg_resp->payload, &offset);
|
||||
get_enrolled_fingers_resp->fingers[i].template_status = extract8 (msg_resp->payload, &offset);
|
||||
|
||||
}
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
static int
|
||||
parse_get_enrolled_users_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
int offset = 0;
|
||||
int i = 0;
|
||||
|
||||
/* the payload is 2 bytes + template data */
|
||||
if (msg_resp->payload_len < 2)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
bmkt_enroll_templates_resp_t *get_enroll_templates_resp = &resp->response.enroll_templates_resp;
|
||||
|
||||
get_enroll_templates_resp->total_query_messages = extract8 (msg_resp->payload, &offset);
|
||||
get_enroll_templates_resp->query_sequence = extract8 (msg_resp->payload, &offset);
|
||||
|
||||
int n = 0;
|
||||
for (n = 0; n < BMKT_MAX_NUM_TEMPLATES_INTERNAL_FLASH; n++)
|
||||
{
|
||||
if (offset >= msg_resp->payload_len)
|
||||
break;
|
||||
get_enroll_templates_resp->templates[n].user_id_len = extract8 (msg_resp->payload, &offset) - 2;
|
||||
if(get_enroll_templates_resp->templates[n].user_id_len > BMKT_MAX_USER_ID_LEN)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
get_enroll_templates_resp->templates[n].template_status = extract8 (msg_resp->payload, &offset);
|
||||
get_enroll_templates_resp->templates[n].finger_id = extract8 (msg_resp->payload, &offset);
|
||||
for (i = 0; i < get_enroll_templates_resp->templates[n].user_id_len; i++)
|
||||
get_enroll_templates_resp->templates[n].user_id[i] = extract8 (msg_resp->payload, &offset);
|
||||
get_enroll_templates_resp->templates[n].user_id[i] = '\0';
|
||||
}
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_get_version_report (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
bmkt_get_version_resp_t *get_version_resp = &resp->response.get_version_resp;
|
||||
int offset = 0;
|
||||
|
||||
if (msg_resp->payload_len != 15)
|
||||
return BMKT_UNRECOGNIZED_MESSAGE;
|
||||
|
||||
memcpy (get_version_resp->part, msg_resp->payload, BMKT_PART_NUM_LEN);
|
||||
offset += BMKT_PART_NUM_LEN;
|
||||
get_version_resp->year = extract8 (msg_resp->payload, &offset);
|
||||
get_version_resp->week = extract8 (msg_resp->payload, &offset);
|
||||
get_version_resp->patch = extract8 (msg_resp->payload, &offset);
|
||||
memcpy (get_version_resp->supplier_id, msg_resp->payload + offset, BMKT_SUPPLIER_ID_LEN);
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
bmkt_compose_message (uint8_t *cmd, int *cmd_len, uint8_t msg_id, uint8_t seq_num,
|
||||
uint8_t payload_size, const uint8_t *payload)
|
||||
{
|
||||
int message_len = BMKT_MESSAGE_HEADER_LEN + payload_size;
|
||||
|
||||
if (*cmd_len < message_len)
|
||||
return BMKT_OUT_OF_MEMORY;
|
||||
|
||||
cmd[BMKT_MESSAGE_HEADER_ID_FIELD] = BMKT_MESSAGE_HEADER_ID;
|
||||
cmd[BMKT_MESSAGE_SEQ_NUM_FIELD] = seq_num;
|
||||
cmd[BMKT_MESSAGE_ID_FIELD] = msg_id;
|
||||
cmd[BMKT_MESSAGE_PAYLOAD_LEN_FIELD] = payload_size;
|
||||
memcpy (&cmd[BMKT_MESSAGE_PAYLOAD_FIELD], payload, payload_size);
|
||||
|
||||
*cmd_len = message_len;
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
bmkt_parse_message_header (uint8_t *resp_buf, int resp_len, bmkt_msg_resp_t *msg_resp)
|
||||
{
|
||||
if (resp_buf[BMKT_MESSAGE_HEADER_ID_FIELD] != BMKT_MESSAGE_HEADER_ID)
|
||||
return BMKT_CORRUPT_MESSAGE;
|
||||
|
||||
msg_resp->seq_num = resp_buf[BMKT_MESSAGE_SEQ_NUM_FIELD];
|
||||
msg_resp->msg_id = resp_buf[BMKT_MESSAGE_ID_FIELD];
|
||||
msg_resp->payload_len = resp_buf[BMKT_MESSAGE_PAYLOAD_LEN_FIELD];
|
||||
if (msg_resp->payload_len > 0)
|
||||
msg_resp->payload = &resp_buf[BMKT_MESSAGE_PAYLOAD_FIELD];
|
||||
else
|
||||
msg_resp->payload = NULL;
|
||||
|
||||
return BMKT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
bmkt_parse_message_payload (bmkt_msg_resp_t *msg_resp, bmkt_response_t *resp)
|
||||
{
|
||||
int ret = BMKT_SUCCESS;
|
||||
|
||||
memset (resp, 0, sizeof (bmkt_response_t));
|
||||
|
||||
resp->response_id = msg_resp->msg_id;
|
||||
|
||||
switch(msg_resp->msg_id)
|
||||
{
|
||||
case BMKT_RSP_CONTINUOUS_IMAGE_CAPTURE_FAIL:
|
||||
case BMKT_RSP_SENSOR_MODULE_TEST_FAIL:
|
||||
case BMKT_RSP_FPS_INIT_FAIL:
|
||||
case BMKT_RSP_FPS_MODE_FAIL:
|
||||
case BMKT_RSP_SET_SECURITY_LEVEL_FAIL:
|
||||
case BMKT_RSP_GET_SECURITY_LEVEL_FAIL:
|
||||
case BMKT_RSP_CANCEL_OP_FAIL:
|
||||
case BMKT_RSP_ENROLL_FAIL:
|
||||
case BMKT_RSP_ID_FAIL:
|
||||
case BMKT_RSP_VERIFY_FAIL:
|
||||
case BMKT_RSP_QUERY_FAIL:
|
||||
case BMKT_RSP_DEL_USER_FP_FAIL:
|
||||
case BMKT_RSP_DEL_FULL_DB_FAIL:
|
||||
case BMKT_RSP_REPEAT_LAST_BMKT_RSP_FAIL:
|
||||
case BMKT_RSP_POWER_DOWN_FAIL:
|
||||
case BMKT_RSP_GET_VERSION_FAIL:
|
||||
case BMKT_RSP_DISABLE_PAIRING_FAIL:
|
||||
case BMKT_RSP_QUERY_PAIRING_FAIL:
|
||||
case BMKT_RSP_SENSOR_STATUS_FAIL:
|
||||
case BMKT_RSP_RETRIEVE_FINAL_RESULT_FAIL:
|
||||
ret = parse_error_response (msg_resp, resp);
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_FPS_INIT_OK:
|
||||
ret = parse_init_ok (msg_resp, resp);
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_CANCEL_OP_OK:
|
||||
case BMKT_RSP_DEL_FULL_DB_OK:
|
||||
case BMKT_RSP_DEL_USER_FP_OK:
|
||||
/* responses with a payload of 0
|
||||
so the response indicates success */
|
||||
resp->result = BMKT_SUCCESS;
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_FPS_MODE_REPORT:
|
||||
// parse_fps_mode
|
||||
ret = parse_fps_mode_report (msg_resp, resp);
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_GET_SECURITY_LEVEL_REPORT:
|
||||
case BMKT_RSP_SET_SECURITY_LEVEL_REPORT:
|
||||
/* parse security level result */
|
||||
ret = parse_security_level_report (msg_resp, resp);
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_DELETE_PROGRESS:
|
||||
ret = parse_del_all_users_progress_report (msg_resp, resp);
|
||||
break;
|
||||
|
||||
case BMKT_RSP_CAPTURE_COMPLETE:
|
||||
resp->result = BMKT_SUCCESS;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_ENROLL_READY:
|
||||
resp->result = BMKT_SUCCESS;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_ENROLL_REPORT:
|
||||
ret = parse_enroll_report (msg_resp, resp);
|
||||
break;
|
||||
|
||||
case BMKT_RSP_ENROLL_OK:
|
||||
resp->complete = 1;
|
||||
ret = parse_enroll_ok (msg_resp, resp);
|
||||
break;
|
||||
|
||||
case BMKT_RSP_ID_OK:
|
||||
case BMKT_RSP_VERIFY_OK:
|
||||
ret = parse_auth_ok (msg_resp, resp);
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_GET_ENROLLED_FINGERS_REPORT:
|
||||
ret = parse_get_enrolled_fingers_report (msg_resp, resp);
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_DATABASE_CAPACITY_REPORT:
|
||||
resp->complete = 1;
|
||||
ret = parse_db_cap_report (msg_resp, resp);
|
||||
break;
|
||||
|
||||
case BMKT_RSP_TEMPLATE_RECORDS_REPORT:
|
||||
ret = parse_get_enrolled_users_report (msg_resp, resp);
|
||||
break;
|
||||
|
||||
case BMKT_RSP_QUERY_RESPONSE_COMPLETE:
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_VERSION_INFO:
|
||||
ret = parse_get_version_report (msg_resp, resp);
|
||||
resp->complete = 1;
|
||||
break;
|
||||
|
||||
case BMKT_RSP_POWER_DOWN_READY:
|
||||
resp->complete = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Synaptics Inc
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define BMKT_MESSAGE_HEADER_ID 0xFE
|
||||
#define BMKT_MESSAGE_HEADER_LEN (4)
|
||||
#define BMKT_MESSAGE_CRC32_LEN (4)
|
||||
#define BMKT_MESSAGE_HEADER_ID_FIELD 0
|
||||
#define BMKT_MESSAGE_SEQ_NUM_FIELD 1
|
||||
#define BMKT_MESSAGE_ID_FIELD 2
|
||||
#define BMKT_MESSAGE_PAYLOAD_LEN_FIELD 3
|
||||
#define BMKT_MESSAGE_PAYLOAD_FIELD 4
|
||||
|
||||
// Command messages
|
||||
#define BMKT_CMD_CONTINUOUS_IMAGE_CAPTURE 0x01
|
||||
#define BMKT_CMD_CONTINUOUS_IMAGE_CAPTURE_STOP 0x04
|
||||
#define BMKT_CMD_SENSOR_MODULE_TEST 0x06
|
||||
#define BMKT_CMD_SENSOR_MODULE_TEST_START 0x08
|
||||
#define BMKT_CMD_NEXT_TEST_REPORT_CHUNK 0x0B
|
||||
#define BMKT_CMD_FPS_INIT 0x11
|
||||
#define BMKT_CMD_GET_FPS_MODE 0x21
|
||||
#define BMKT_CMD_SET_SECURITY_LEVEL 0x31
|
||||
#define BMKT_CMD_GET_SECURITY_LEVEL 0x34
|
||||
#define BMKT_CMD_CANCEL_OP 0x41
|
||||
#define BMKT_CMD_ENROLL_USER 0x51
|
||||
#define BMKT_CMD_ENROLL_PAUSE 0x52
|
||||
#define BMKT_CMD_ENROLL_RESUME 0x53
|
||||
#define BMKT_CMD_ID_USER 0x61
|
||||
#define BMKT_CMD_VERIFY_USER 0x65
|
||||
#define BMKT_CMD_GET_TEMPLATE_RECORDS 0x71
|
||||
#define BMKT_CMD_GET_NEXT_QUERY_RESPONSE 0x72
|
||||
#define BMKT_CMD_GET_ENROLLED_FINGERS 0x73
|
||||
#define BMKT_CMD_GET_DATABASE_CAPACITY 0x74
|
||||
#define BMKT_CMD_DEL_USER_FP 0x81
|
||||
#define BMKT_CMD_DEL_FULL_DB 0x84
|
||||
#define BMKT_CMD_REPEAT_LAST_RSP 0x92
|
||||
#define BMKT_CMD_POWER_DOWN_NOTIFY 0xA1
|
||||
#define BMKT_CMD_GET_VERSION 0xB1
|
||||
#define BMKT_CMD_DISABLE_PAIRING 0xC2
|
||||
#define BMKT_CMD_QUERY_PAIRING 0xC5
|
||||
#define BMKT_CMD_SENSOR_STATUS 0xD1
|
||||
#define BMKT_CMD_ID_USER_IN_ORDER 0xE1
|
||||
#define BMKT_CMD_ID_NEXT_USER 0xE3
|
||||
#define BMKT_CMD_VERIFY_USER_IN_ORDER 0xF1
|
||||
#define BMKT_CMD_VERIFY_FINGERS_IN_ORDER 0xF2
|
||||
#define BMKT_CMD_GET_FINAL_RESULT 0xE4
|
||||
|
||||
#define BMKT_EVT_FINGER_REPORT 0x91
|
||||
|
||||
#define BMKT_EVT_FINGER_STATE_NOT_ON_SENSOR 0x00
|
||||
#define BMKT_EVT_FINGER_STATE_ON_SENSOR 0x01
|
||||
|
||||
typedef struct bmkt_msg_resp
|
||||
{
|
||||
uint8_t msg_id;
|
||||
uint8_t seq_num;
|
||||
uint8_t payload_len;
|
||||
uint8_t *payload;
|
||||
int result;
|
||||
} bmkt_msg_resp_t;
|
||||
|
||||
int bmkt_compose_message (uint8_t *cmd,
|
||||
int *cmd_len,
|
||||
uint8_t msg_id,
|
||||
uint8_t seq_num,
|
||||
uint8_t payload_size,
|
||||
const uint8_t *payload);
|
||||
|
||||
int bmkt_parse_message_header (uint8_t *resp_buf,
|
||||
int resp_len,
|
||||
bmkt_msg_resp_t *msg_resp);
|
||||
int bmkt_parse_message_payload (bmkt_msg_resp_t *msg_resp,
|
||||
bmkt_response_t *resp);
|
||||
@@ -1,485 +0,0 @@
|
||||
/*
|
||||
* Synaptics MiS Fingerprint Sensor Response Data Interface
|
||||
* Copyright (C) 2019 Synaptics Inc
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bmkt.h"
|
||||
|
||||
/** List of response message IDs */
|
||||
#define BMKT_RSP_CONTINUOUS_IMAGE_CAPTURE_FAIL 0x02
|
||||
#define BMKT_RSP_CONTINUOUS_IMAGE_CAPTURE_READY 0x03
|
||||
#define BMKT_RSP_CONTINUOUS_IMAGE_CAPTURE_STOPPED 0x05
|
||||
#define BMKT_RSP_SENSOR_MODULE_TEST_READY 0x07
|
||||
#define BMKT_RSP_SENSOR_MODULE_TEST_FAIL 0x09
|
||||
#define BMKT_RSP_SENSOR_MODULE_TEST_REPORT 0x0A
|
||||
#define BMKT_RSP_NEXT_TEST_REPORT_CHUNK 0x0C
|
||||
|
||||
/*! \addtogroup init
|
||||
* Response IDs returned by fingerprint initialization operation
|
||||
* @{
|
||||
*/
|
||||
/** Failed to initialize fingerprint sensor module */
|
||||
#define BMKT_RSP_FPS_INIT_FAIL 0x12
|
||||
/** Successfully initialized fingerprint sensor module */
|
||||
#define BMKT_RSP_FPS_INIT_OK 0x13
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup mode
|
||||
* Response IDs returned by get fingerprint mode operation
|
||||
* @{
|
||||
*/
|
||||
/** Failed to get fingerprint sensor module’s current operational mode */
|
||||
#define BMKT_RSP_FPS_MODE_FAIL 0x22
|
||||
/**
|
||||
* BMKT_RSP_FPS_MODE_REPORT:
|
||||
* Response containing the current operational mode of the fingerprint sensor module
|
||||
* <br>Payload data represented in \ref bmkt_fps_mode_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_FPS_MODE_REPORT 0x23
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup setseclevel
|
||||
* Response IDs returned by set security level operation
|
||||
* @{
|
||||
*/
|
||||
/** Failed to set fingerprint sensor module security level */
|
||||
#define BMKT_RSP_SET_SECURITY_LEVEL_FAIL 0x32
|
||||
/**
|
||||
* BMKT_RSP_SET_SECURITY_LEVEL_REPORT:
|
||||
* Security level of the fingerprint sensor module was set successfully
|
||||
* <br>Contains payload data represented in \ref bmkt_set_sec_level_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_SET_SECURITY_LEVEL_REPORT 0x33
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup getseclevel
|
||||
* Response IDs returned by get security level operation
|
||||
* @{
|
||||
*/
|
||||
/** Failed to get fingerprint sensor module security level */
|
||||
#define BMKT_RSP_GET_SECURITY_LEVEL_FAIL 0x35
|
||||
/**
|
||||
* BMKT_RSP_GET_SECURITY_LEVEL_REPORT:
|
||||
* Returns the current security level of the fingerprint sensor module
|
||||
* <br>Contains payload data represented in \ref bmkt_set_sec_level_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_GET_SECURITY_LEVEL_REPORT 0x36
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup cancelop
|
||||
* Response IDs returned by cancel_operation operation
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* BMKT_RSP_CANCEL_OP_OK:
|
||||
* Successfully canceled the current operation and returned
|
||||
* fingerprint sensor module to idle mode
|
||||
*/
|
||||
#define BMKT_RSP_CANCEL_OP_OK 0x42
|
||||
/** Failed to cancel the current operation */
|
||||
#define BMKT_RSP_CANCEL_OP_FAIL 0x43
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup enrollment
|
||||
* Response IDs returned by enrollment operation
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* BMKT_RSP_ENROLL_READY:
|
||||
* Fingerprint enrollment session has begun and the user can place
|
||||
* their finger on the sensor
|
||||
*/
|
||||
#define BMKT_RSP_ENROLL_READY 0x54
|
||||
/** Progress of the currently on-going fingerprint enrollment session */
|
||||
#define BMKT_RSP_ENROLL_REPORT 0x55
|
||||
/** Enrollment has been paused */
|
||||
#define BMKT_RSP_ENROLL_PAUSED 0x56
|
||||
/** Enrollment has been resume */
|
||||
#define BMKT_RSP_ENROLL_RESUMED 0x57
|
||||
/** The current enrollment session has encountered an error */
|
||||
#define BMKT_RSP_ENROLL_FAIL 0x58
|
||||
/**
|
||||
* BMKT_RSP_ENROLL_OK:
|
||||
* User has been successfully enrolled into the fingerprint sensor module
|
||||
* <br>Contains payload data represented in \ref bmkt_enroll_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_ENROLL_OK 0x59
|
||||
|
||||
/**
|
||||
* BMKT_RSP_CAPTURE_COMPLETE:
|
||||
* Fingerprint image capture is complete and it is safe for the user
|
||||
* to lift their finger off the sensor
|
||||
*/
|
||||
#define BMKT_RSP_CAPTURE_COMPLETE 0x60
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup identify
|
||||
* Response IDs returned by identify operation.
|
||||
* @{
|
||||
*/
|
||||
/* Fingerprint identification session has begun */
|
||||
#define BMKT_RSP_ID_READY 0x62
|
||||
/* Identification has failed */
|
||||
#define BMKT_RSP_ID_FAIL 0x63
|
||||
/**
|
||||
* BMKT_RSP_ID_OK:
|
||||
* User has been successfully identified
|
||||
* <br>Contains payload data represented in \ref bmkt_auth_resp struct
|
||||
*/
|
||||
#define BMKT_RSP_ID_OK 0x64
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup verify
|
||||
* Response IDs returned by identify operation.
|
||||
* @{
|
||||
*/
|
||||
/** Fingerprint verification session has begun */
|
||||
#define BMKT_RSP_VERIFY_READY 0x66
|
||||
/** Verification has failed */
|
||||
#define BMKT_RSP_VERIFY_FAIL 0x67
|
||||
/**
|
||||
* BMKT_RSP_VERIFY_OK:
|
||||
* User’s identity has been successfully verified
|
||||
* <br>Contains payload data represented in \ref bmkt_auth_resp struct
|
||||
*/
|
||||
#define BMKT_RSP_VERIFY_OK 0x68
|
||||
/*! @} */
|
||||
|
||||
/**
|
||||
* BMKT_RSP_TEMPLATE_RECORDS_REPORT:
|
||||
* Response ID returned by get enrolled users templates record operation
|
||||
* <br>Returns list of template records containing user IDs and corresponding finger IDs
|
||||
* <br>Payload data represented in \ref bmkt_enroll_templates_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_TEMPLATE_RECORDS_REPORT 0x75
|
||||
|
||||
/**
|
||||
* BMKT_RSP_QUERY_RESPONSE_COMPLETE:
|
||||
* Response ID returned by get next query response operation
|
||||
* <br>Complete sequence of messages containing the template records query response has been sent
|
||||
*/
|
||||
#define BMKT_RSP_QUERY_RESPONSE_COMPLETE 0x76
|
||||
|
||||
/**
|
||||
* BMKT_RSP_GET_ENROLLED_FINGERS_REPORT:
|
||||
* Response ID returned by get enrolled fingers operation
|
||||
* <br> Returns list of IDs of enrolled fingers for a specific user,
|
||||
* along with template record status corresponding to each enrolled finger
|
||||
* <br>Contains payload data represented in \ref bmkt_enrolled_fingers_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_GET_ENROLLED_FINGERS_REPORT 0x77
|
||||
|
||||
/*! \addtogroup dbcapacity
|
||||
* Response IDs returned by get database capacity operation
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* BMKT_RSP_DATABASE_CAPACITY_REPORT:
|
||||
* Response specifying total capacity of fingerprint template database and
|
||||
* how much free capacity is remaining along with how many templates are corrupted and
|
||||
* how many bad (permanently unusable) storage slots are there.
|
||||
* <br>Payload data represented in \ref bmkt_get_db_capacity_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_DATABASE_CAPACITY_REPORT 0x78
|
||||
/** Failed to execute database query */
|
||||
#define BMKT_RSP_QUERY_FAIL 0x79
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup deluser
|
||||
* Response IDs returned by delete fingerprint of specific user operation
|
||||
* @{
|
||||
*/
|
||||
/** Failed to delete a user’s fingerprint template from the database */
|
||||
#define BMKT_RSP_DEL_USER_FP_FAIL 0x82
|
||||
/**
|
||||
* BMKT_RSP_DEL_USER_FP_OK:
|
||||
* Fingerprint template successfully deleted from the database.
|
||||
* Returns the user ID and finger ID deleted. If value of finger ID is set equal to 0,
|
||||
* then all fingerprint templates for that user have been deleted from the database
|
||||
* <br>Payload data represented in \ref bmkt_del_user_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_DEL_USER_FP_OK 0x83
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup delfulldb
|
||||
* Response IDs returned by delete entire fingerprint template DB operation
|
||||
* @{
|
||||
*/
|
||||
/** Failed to erase entire fingerprint template database */
|
||||
#define BMKT_RSP_DEL_FULL_DB_FAIL 0x85
|
||||
/** Successfully erased entire fingerprint template database */
|
||||
#define BMKT_RSP_DEL_FULL_DB_OK 0x86
|
||||
/**
|
||||
* BMKT_RSP_DELETE_PROGRESS:
|
||||
* Notify progress made during the on-going deletion of the full template database
|
||||
* <br>Payload data represented in \ref bmkt_del_all_users_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_DELETE_PROGRESS 0x87
|
||||
/*! @} */
|
||||
|
||||
/**
|
||||
* BMKT_RSP_REPEAT_LAST_BMKT_RSP_FAIL:
|
||||
* Response ID returned by repeate last response operation
|
||||
* <br>Failed to retrieve and re-send last response
|
||||
*/
|
||||
#define BMKT_RSP_REPEAT_LAST_BMKT_RSP_FAIL 0x93
|
||||
|
||||
/*! \addtogroup pwrdwn
|
||||
* Response IDs returned by power down notify operation
|
||||
* @{
|
||||
*/
|
||||
/** Fingerprint sensor module is ready to be powered down */
|
||||
#define BMKT_RSP_POWER_DOWN_READY 0xA2
|
||||
/** Failed to go into power down mode */
|
||||
#define BMKT_RSP_POWER_DOWN_FAIL 0xA3
|
||||
/*! @} */
|
||||
|
||||
/*! \addtogroup versioninfo
|
||||
* Response IDs returned by get version operation
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* BMKT_RSP_VERSION_INFO:
|
||||
* System version information of the fingerprint sensor module
|
||||
* <br>Payload data represented in \ref bmkt_get_version_resp_t struct
|
||||
*/
|
||||
#define BMKT_RSP_VERSION_INFO 0xB2
|
||||
/* Failed to retrieve and send last response */
|
||||
#define BMKT_RSP_GET_VERSION_FAIL 0xB3
|
||||
/*! @} */
|
||||
|
||||
/**
|
||||
* BMKT_RSP_GENERAL_ERROR:
|
||||
* Not tied to a specific command-response session.
|
||||
* <br>Could be caused by corrupt or truncated command message
|
||||
*/
|
||||
#define BMKT_RSP_GENERAL_ERROR 0xC1
|
||||
#define BMKT_RSP_DISABLE_PAIRING_FAIL 0xC3
|
||||
#define BMKT_RSP_DISABLE_PAIRING_OK 0xC4
|
||||
#define BMKT_RSP_QUERY_PAIRING_FAIL 0xC6
|
||||
#define BMKT_RSP_SENSOR_PAIRING_REPORT 0xC7
|
||||
|
||||
/*! \addtogroup versioninfo
|
||||
* Response IDs returned by get sensor module status operation
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* BMKT_RSP_SENSOR_STATUS_REPORT:
|
||||
* Response returning the current status of the sensor module
|
||||
* <br>Payload data represented in bmkt_XXX struct
|
||||
*/
|
||||
#define BMKT_RSP_SENSOR_STATUS_REPORT 0xD2
|
||||
/** Failed to retrieve sensor status */
|
||||
#define BMKT_RSP_SENSOR_STATUS_FAIL 0xD3
|
||||
/*! @} */
|
||||
|
||||
/**
|
||||
* BMKT_RSP_SEND_NEXT_USER_ID:
|
||||
* Response ID returned by identify user in order operation
|
||||
* <br>Notify to send the next batch of user IDs in the priority list
|
||||
*/
|
||||
#define BMKT_RSP_SEND_NEXT_USER_ID 0xE2
|
||||
/**
|
||||
* BMKT_RSP_RETRIEVE_FINAL_RESULT_FAIL:
|
||||
* Response IDs returned by retrieve final result operation
|
||||
* <br>Failed to retrieve and re-send cached final result
|
||||
*/
|
||||
#define BMKT_RSP_RETRIEVE_FINAL_RESULT_FAIL 0xE5
|
||||
|
||||
/**
|
||||
* Response payload data structure returned by sensor initialization operation.
|
||||
*/
|
||||
typedef struct bmkt_init_resp
|
||||
{
|
||||
uint8_t finger_presence; /**< Indicates finger existence on the sensor during startup */
|
||||
} bmkt_init_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_enroll_resp:
|
||||
* Response payload data structure returned by enrollment operation.
|
||||
*/
|
||||
typedef struct bmkt_enroll_resp
|
||||
{
|
||||
int progress; /**< Shows current progress stutus [0-100] */
|
||||
uint8_t finger_id; /**< User's finger id [1-10] */
|
||||
uint8_t user_id[BMKT_MAX_USER_ID_LEN]; /**< User name to be enrolled */
|
||||
} bmkt_enroll_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_auth_resp:
|
||||
* Response payload data structure returned by identify and verify operations.
|
||||
*/
|
||||
struct bmkt_auth_resp
|
||||
{
|
||||
double match_result; /**< match result returned by matcher */
|
||||
uint8_t finger_id; /**< Matched templates's finger id */
|
||||
uint8_t user_id[BMKT_MAX_USER_ID_LEN]; /**< Matched template's user id */
|
||||
};
|
||||
|
||||
typedef struct bmkt_auth_resp bmkt_verify_resp_t; /**< Returned by verify */
|
||||
typedef struct bmkt_auth_resp bmkt_identify_resp_t; /**< Returned by identify */
|
||||
|
||||
/**
|
||||
* bmkt_fps_mode_resp:
|
||||
* Response payload data structure returned by get fingerprint mode operation.
|
||||
*/
|
||||
typedef struct bmkt_fps_mode_resp
|
||||
{
|
||||
uint8_t mode; /**< One of the Level I bmkt_mode_t values */
|
||||
uint8_t level2_mode; /**< One of the Level II bmkt_mode_level2_t values */
|
||||
uint8_t cmd_id; /**< Message ID of command being executed when bmkt_get_fps_mode was called */
|
||||
uint8_t finger_presence; /**< Finger presence status value finger on sensor 1 / finger not on sensor 0 */
|
||||
} bmkt_fps_mode_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_get_version_resp:
|
||||
* Response payload data structure returned by get version operation.
|
||||
*/
|
||||
typedef struct bmkt_get_version_resp
|
||||
{
|
||||
uint8_t part[BMKT_PART_NUM_LEN]; /**< Software Part Number */
|
||||
uint8_t year; /**< Software Version Year */
|
||||
uint8_t week; /**< Software Version Week */
|
||||
uint8_t patch; /**< Software Version Patch Level */
|
||||
uint8_t supplier_id[BMKT_SUPPLIER_ID_LEN]; /**< Software Supplier Identification */
|
||||
} bmkt_get_version_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_get_db_capacity_resp:
|
||||
* Response payload data structure returned by get DB capacity operation.
|
||||
*/
|
||||
typedef struct bmkt_get_db_capacity_resp
|
||||
{
|
||||
uint8_t total; /**< Total Available Capacity: Total number of template records that can be stored */
|
||||
uint8_t empty; /**< Free Capacity: Number of template records that can still be stored */
|
||||
uint8_t bad_slots; /**< Number of bad template storage slots */
|
||||
uint8_t corrupt_templates; /**< Number of corrupt templates */
|
||||
} bmkt_get_db_capacity_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_sec_level:
|
||||
* Security level values.
|
||||
*/
|
||||
typedef enum bmkt_sec_level {
|
||||
BMKT_SECURITY_LEVEL_LOW = 0x10,
|
||||
BMKT_SECURITY_LEVEL_MEDIUM = 0x40,
|
||||
BMKT_SECURITY_LEVEL_HIGH = 0x60,
|
||||
} bmkt_sec_level_t;
|
||||
|
||||
/**
|
||||
* bmkt_set_sec_level_resp:
|
||||
* Response payload data structure returned by get/set security level operations.
|
||||
*/
|
||||
typedef struct bmkt_set_sec_level_resp
|
||||
{
|
||||
bmkt_sec_level_t sec_level; /**< One of the bmkt_sec_level_t values */
|
||||
} bmkt_set_sec_level_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_del_all_users_resp:
|
||||
* Response payload data structure returned by delete all enrolled users operation.
|
||||
*/
|
||||
typedef struct bmkt_del_all_users_resp
|
||||
{
|
||||
int progress; /**< Progress indicator as a percentage */
|
||||
} bmkt_del_all_users_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_del_user_resp:
|
||||
* Response payload data structure returned by delete enrolled user operation.
|
||||
*/
|
||||
typedef struct bmkt_del_user_resp
|
||||
{
|
||||
int progress; /**< Progress indicator as a percentage */
|
||||
} bmkt_del_user_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_enroll_template:
|
||||
* Structure of enrolled users template record data.
|
||||
*/
|
||||
typedef struct bmkt_enroll_template
|
||||
{
|
||||
uint8_t user_id_len; /**< Length of user_id string */
|
||||
uint8_t template_status; /**< Template record status */
|
||||
uint8_t finger_id; /**< ID of enrolled finger */
|
||||
uint8_t user_id[BMKT_MAX_USER_ID_LEN + 1]; /**< Name of the enrolled user */
|
||||
} bmkt_enroll_template_t;
|
||||
|
||||
/**
|
||||
* bmkt_enroll_templates_resp:
|
||||
* Response payload data structure returned by get enrolled user list operation.
|
||||
*/
|
||||
typedef struct bmkt_enroll_templates_resp
|
||||
{
|
||||
uint8_t total_query_messages; /**< Total query response messages */
|
||||
uint8_t query_sequence; /**< Query response sequence number */
|
||||
bmkt_enroll_template_t templates[BMKT_MAX_NUM_TEMPLATES_INTERNAL_FLASH]; /**< Enrolled user template records list */
|
||||
} bmkt_enroll_templates_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_enrolled_fingers:
|
||||
* Structure of template record status corresponding to each enrolled finger.
|
||||
*/
|
||||
typedef struct bmkt_enrolled_fingers
|
||||
{
|
||||
uint8_t finger_id; /**< ID of enrolled finger */
|
||||
uint8_t template_status; /**< Template record status of finger_id */
|
||||
} bmkt_enrolled_fingers_t;
|
||||
|
||||
/**
|
||||
* bmkt_enrolled_fingers_resp:
|
||||
* Response payload data structure returned by get enrolled fingers operation.
|
||||
*/
|
||||
typedef struct bmkt_enrolled_fingers_resp
|
||||
{
|
||||
bmkt_enrolled_fingers_t fingers[10]; /**< List of enroled fingers, max number of supported fingers per user is 10 */
|
||||
} bmkt_enrolled_fingers_resp_t;
|
||||
|
||||
/**
|
||||
* bmkt_response_data_t:
|
||||
* Union combining all response payload data types.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
bmkt_init_resp_t init_resp;
|
||||
bmkt_enroll_resp_t enroll_resp;
|
||||
bmkt_verify_resp_t verify_resp;
|
||||
bmkt_identify_resp_t id_resp;
|
||||
bmkt_fps_mode_resp_t fps_mode_resp;
|
||||
bmkt_get_version_resp_t get_version_resp;
|
||||
bmkt_get_db_capacity_resp_t db_cap_resp;
|
||||
bmkt_set_sec_level_resp_t sec_level_resp;
|
||||
bmkt_del_all_users_resp_t del_all_users_resp;
|
||||
bmkt_enroll_templates_resp_t enroll_templates_resp;
|
||||
bmkt_del_user_resp_t del_user_resp;
|
||||
bmkt_enrolled_fingers_resp_t enrolled_fingers_resp;
|
||||
} bmkt_response_data_t;
|
||||
|
||||
/**
|
||||
* bmkt_response:
|
||||
* Structure to abstract different response structure types in one API
|
||||
* to be used in bmkt_resp_cb_t callback function.
|
||||
*/
|
||||
typedef struct bmkt_response
|
||||
{
|
||||
int response_id; /**< Response message ID, one of th BMKT_RSP_XXX */
|
||||
int result; /**< Operation execution result code */
|
||||
int complete; /**< Operation completion status 1: complete / 0: not completed */
|
||||
bmkt_response_data_t response; /**< Operation specific response union */
|
||||
} bmkt_response_t;
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Synaptics Inc
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "usb_transport.h"
|
||||
#define BMKT_MAX_PENDING_SESSIONS 2
|
||||
|
||||
typedef enum bmkt_sensor_state {
|
||||
BMKT_SENSOR_STATE_UNINIT = 0,
|
||||
BMKT_SENSOR_STATE_IDLE,
|
||||
BMKT_SENSOR_STATE_INIT,
|
||||
BMKT_SENSOR_STATE_EXIT,
|
||||
} bmkt_sensor_state_t;
|
||||
|
||||
typedef struct bmkt_sensor_drv bmkt_sensor_drv_t;
|
||||
|
||||
typedef struct bmkt_sensor_version
|
||||
{
|
||||
uint32_t build_time;
|
||||
uint32_t build_num;
|
||||
uint8_t version_major;
|
||||
uint8_t version_minor;
|
||||
uint8_t target;
|
||||
uint8_t product;
|
||||
uint8_t silicon_rev;
|
||||
uint8_t formal_release;
|
||||
uint8_t platform;
|
||||
uint8_t patch;
|
||||
uint8_t serial_number[6];
|
||||
uint16_t security;
|
||||
uint8_t iface;
|
||||
uint8_t device_type;
|
||||
} bmkt_sensor_version_t;
|
||||
|
||||
typedef struct bmkt_sensor
|
||||
{
|
||||
bmkt_usb_transport_t usb_xport;
|
||||
bmkt_sensor_version_t version;
|
||||
bmkt_session_ctx_t pending_sessions[BMKT_MAX_PENDING_SESSIONS];
|
||||
int empty_session_idx;
|
||||
int flags;
|
||||
int seq_num;
|
||||
bmkt_sensor_state_t sensor_state;
|
||||
bmkt_event_cb_t finger_event_cb;
|
||||
void *finger_cb_ctx;
|
||||
bmkt_general_error_cb_t gen_err_cb;
|
||||
void *gen_err_cb_ctx;
|
||||
bmkt_op_state_t op_state;
|
||||
} bmkt_sensor_t;
|
||||
|
||||
int bmkt_sensor_open (bmkt_sensor_t *sensor,
|
||||
bmkt_general_error_cb_t err_cb,
|
||||
void *err_cb_ctx);
|
||||
int bmkt_sensor_close (bmkt_sensor_t *sensor);
|
||||
|
||||
int bmkt_sensor_init_fps (bmkt_sensor_t *sensor);
|
||||
|
||||
int bmkt_sensor_send_message (bmkt_sensor_t *sensor,
|
||||
uint8_t msg_id,
|
||||
uint8_t payload_size,
|
||||
uint8_t *payload,
|
||||
bmkt_resp_cb_t resp_cb,
|
||||
void *resp_data);
|
||||
int bmkt_sensor_handle_response (bmkt_sensor_t *sensor,
|
||||
uint8_t *resp_buf,
|
||||
int resp_len,
|
||||
bmkt_msg_resp_t *msg_resp);
|
||||
|
||||
int bmkt_sensor_send_async_read_command (bmkt_sensor_t *sensor);
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Synaptics Inc
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fpi-device.h"
|
||||
#include "fpi-ssm.h"
|
||||
|
||||
#define SYNAPTICS_VENDOR_ID 0x06cb
|
||||
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceSynaptics, fpi_device_synaptics, FPI, DEVICE_SYNAPTICS, FpDevice)
|
||||
|
||||
|
||||
#define MAX_TRANSFER_LEN 263 + 1 /* SPI Header */ + 2 /* VCSFW header */
|
||||
|
||||
#define USB_EP_REQUEST 0x01
|
||||
#define USB_EP_REPLY 0x81
|
||||
#define USB_EP_FINGERPRINT 0x82
|
||||
#define USB_EP_INTERRUPT 0x83
|
||||
|
||||
#define USB_ASYNC_MESSAGE_PENDING 0x4
|
||||
#define USB_INTERRUPT_DATA_SIZE 7
|
||||
|
||||
#define SENSOR_CMD_GET_VERSION 1
|
||||
#define SENSOR_CMD_ACE_COMMAND 167
|
||||
#define SENSOR_CMD_ASYNCMSG_READ 168
|
||||
|
||||
#define SENSOR_FW_CMD_HEADER_LEN 1
|
||||
#define SENSOR_FW_REPLY_HEADER_LEN 2
|
||||
|
||||
|
||||
/* Number of enroll stages */
|
||||
#define ENROLL_SAMPLES 8
|
||||
|
||||
|
||||
#define SYNAPTICS_DRIVER_FULLNAME "Synaptics Sensors"
|
||||
#include "bmkt.h"
|
||||
#include "bmkt_response.h"
|
||||
|
||||
|
||||
typedef struct bmkt_sensor_version
|
||||
{
|
||||
uint32_t build_time;
|
||||
uint32_t build_num;
|
||||
uint8_t version_major;
|
||||
uint8_t version_minor;
|
||||
uint8_t target;
|
||||
uint8_t product;
|
||||
uint8_t silicon_rev;
|
||||
uint8_t formal_release;
|
||||
uint8_t platform;
|
||||
uint8_t patch;
|
||||
uint8_t serial_number[6];
|
||||
uint16_t security;
|
||||
uint8_t iface;
|
||||
uint8_t device_type;
|
||||
} bmkt_sensor_version_t;
|
||||
|
||||
|
||||
struct syna_enroll_resp_data
|
||||
{
|
||||
int progress;
|
||||
};
|
||||
typedef enum syna_state {
|
||||
SYNA_STATE_UNINIT = 0,
|
||||
SYNA_STATE_IDLE,
|
||||
SYNA_STATE_ENROLL,
|
||||
SYNA_STATE_IDENTIFY,
|
||||
SYNA_STATE_IDENTIFY_DELAY_RESULT,
|
||||
SYNA_STATE_VERIFY,
|
||||
SYNA_STATE_VERIFY_DELAY_RESULT,
|
||||
SYNA_STATE_DELETE,
|
||||
} syna_state_t;
|
||||
|
||||
typedef enum {
|
||||
SYNAPTICS_CMD_SEND_PENDING = 0,
|
||||
SYNAPTICS_CMD_GET_RESP,
|
||||
SYNAPTICS_CMD_WAIT_INTERRUPT,
|
||||
SYNAPTICS_CMD_SEND_ASYNC,
|
||||
SYNAPTICS_CMD_RESTART,
|
||||
SYNAPTICS_CMD_NUM_STATES,
|
||||
} SynapticsCmdState;
|
||||
|
||||
|
||||
typedef void (*SynCmdMsgCallback) (FpiDeviceSynaptics *self,
|
||||
bmkt_response_t *resp,
|
||||
GError *error);
|
||||
|
||||
struct _FpiDeviceSynaptics
|
||||
{
|
||||
FpDevice parent;
|
||||
|
||||
guint8 cmd_seq_num;
|
||||
guint8 last_seq_num;
|
||||
FpiSsm *cmd_ssm;
|
||||
FpiUsbTransfer *cmd_pending_transfer;
|
||||
gboolean cmd_complete_on_removal;
|
||||
|
||||
bmkt_sensor_version_t mis_version;
|
||||
|
||||
GCancellable *interrupt_cancellable;
|
||||
|
||||
gint enroll_stage;
|
||||
gboolean finger_on_sensor;
|
||||
GPtrArray *list_result;
|
||||
|
||||
|
||||
struct syna_enroll_resp_data enroll_resp_data;
|
||||
syna_state_t state;
|
||||
};
|
||||
@@ -59,7 +59,6 @@ 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++]);
|
||||
|
||||
@@ -21,5 +21,4 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
uint16_t udf_crc (unsigned char *buffer,
|
||||
size_t size);
|
||||
uint16_t udf_crc(unsigned char *buffer, size_t size);
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
#define IMG_WIDTH_1000 288
|
||||
#define IMG_WIDTH_1001 216
|
||||
|
||||
struct sonly_regwrite
|
||||
{
|
||||
guint8 reg;
|
||||
guint8 value;
|
||||
struct sonly_regwrite {
|
||||
uint8_t reg;
|
||||
uint8_t value;
|
||||
};
|
||||
|
||||
/***** AWAIT FINGER *****/
|
||||
|
||||
@@ -23,16 +23,13 @@
|
||||
#include "drivers_api.h"
|
||||
#include "upektc.h"
|
||||
|
||||
#define UPEKTC_EP_IN (2 | FPI_USB_ENDPOINT_IN)
|
||||
#define UPEKTC_EP_OUT (3 | FPI_USB_ENDPOINT_OUT)
|
||||
#define UPEKET_EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define UPEKET_EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define UPEKTC_EP_IN (2 | LIBUSB_ENDPOINT_IN)
|
||||
#define UPEKTC_EP_OUT (3 | LIBUSB_ENDPOINT_OUT)
|
||||
#define UPEKET_EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define UPEKET_EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
#define BULK_TIMEOUT 4000
|
||||
|
||||
struct _FpiDeviceUpektc
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
struct upektc_dev {
|
||||
gboolean deactivating;
|
||||
const struct setup_cmd *setup_commands;
|
||||
size_t setup_commands_len;
|
||||
@@ -41,19 +38,15 @@ struct _FpiDeviceUpektc
|
||||
int init_idx;
|
||||
int sum_threshold;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceUpektc, fpi_device_upektc, FPI, DEVICE_UPEKTC,
|
||||
FpImageDevice);
|
||||
G_DEFINE_TYPE (FpiDeviceUpektc, fpi_device_upektc, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
enum upektc_driver_data {
|
||||
UPEKTC_2015,
|
||||
UPEKTC_3001,
|
||||
};
|
||||
|
||||
static void start_capture (FpImageDevice *dev);
|
||||
static void complete_deactivation (FpImageDevice *dev,
|
||||
GError *error);
|
||||
static void start_finger_detection (FpImageDevice *dev);
|
||||
static void start_capture(struct fp_img_dev *dev);
|
||||
static void complete_deactivation(struct fp_img_dev *dev);
|
||||
static void start_finger_detection(struct fp_img_dev *dev);
|
||||
|
||||
/****** INITIALIZATION/DEINITIALIZATION ******/
|
||||
|
||||
@@ -64,188 +57,205 @@ enum activate_states {
|
||||
};
|
||||
|
||||
static void
|
||||
upektc_next_init_cmd (FpiSsm *ssm,
|
||||
FpImageDevice *dev)
|
||||
upektc_next_init_cmd(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
self->init_idx += 1;
|
||||
if (self->init_idx == self->setup_commands_len)
|
||||
upekdev->init_idx += 1;
|
||||
if (upekdev->init_idx == upekdev->setup_commands_len)
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
else
|
||||
fpi_ssm_jump_to_state(ssm, WRITE_INIT);
|
||||
}
|
||||
|
||||
static void
|
||||
write_init_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void write_init_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
if (!error)
|
||||
{
|
||||
if (self->setup_commands[self->init_idx].response_len)
|
||||
fpi_ssm_next_state (transfer->ssm);
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
if (upekdev->setup_commands[upekdev->init_idx].response_len)
|
||||
fpi_ssm_next_state(ssm);
|
||||
else
|
||||
upektc_next_init_cmd (transfer->ssm, dev);
|
||||
upektc_next_init_cmd(ssm, dev);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
libusb_free_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, dev);
|
||||
else
|
||||
{
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
}
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
read_init_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
int r;
|
||||
|
||||
if (!error)
|
||||
upektc_next_init_cmd (transfer->ssm, dev);
|
||||
else
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
}
|
||||
|
||||
static void
|
||||
activate_run_state (FpiSsm *ssm, FpDevice *dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case WRITE_INIT:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer,
|
||||
self->ep_out,
|
||||
(unsigned char *) self->setup_commands[self->init_idx].cmd,
|
||||
UPEKTC_CMD_LEN,
|
||||
NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
write_init_cb, NULL);
|
||||
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);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, -ENOMEM);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case READ_DATA:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer,
|
||||
self->ep_in,
|
||||
self->setup_commands[self->init_idx].response_len);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
read_init_data_cb, NULL);
|
||||
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,
|
||||
read_init_data_cb, ssm, BULK_TIMEOUT);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
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));
|
||||
|
||||
fpi_image_device_activate_complete (dev, error);
|
||||
|
||||
if (!error)
|
||||
if (!fpi_ssm_get_error(ssm))
|
||||
start_finger_detection(dev);
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
|
||||
/****** FINGER PRESENCE DETECTION ******/
|
||||
|
||||
static int
|
||||
finger_present (unsigned char *img, size_t len, int sum_threshold)
|
||||
static int finger_present(unsigned char *img, size_t len, int sum_threshold)
|
||||
{
|
||||
int i, sum;
|
||||
|
||||
sum = 0;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (img[i] < 160)
|
||||
for (i = 0; i < len; i++) {
|
||||
if (img[i] < 160) {
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
|
||||
fp_dbg("finger_present: sum is %d\n", sum);
|
||||
return sum < sum_threshold ? 0 : 1;
|
||||
}
|
||||
|
||||
static void
|
||||
finger_det_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void finger_det_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
struct fp_img_dev *dev = transfer->user_data;
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
unsigned char *data = transfer->buffer;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fp_dbg ("data transfer status %s\n", error->message);
|
||||
fpi_image_device_session_error (dev, error);
|
||||
return;
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("data transfer status %d\n", transfer->status);
|
||||
fpi_imgdev_session_error(dev, -EIO);
|
||||
goto out;
|
||||
} else if (transfer->length != transfer->actual_length) {
|
||||
fp_dbg("expected %d, got %d bytes", transfer->length,
|
||||
transfer->actual_length);
|
||||
fpi_imgdev_session_error(dev, -EPROTO);
|
||||
}
|
||||
|
||||
if (finger_present (transfer->buffer, IMAGE_SIZE, self->sum_threshold))
|
||||
{
|
||||
if (finger_present(data, IMAGE_SIZE, upekdev->sum_threshold)) {
|
||||
/* finger present, start capturing */
|
||||
fpi_image_device_report_finger_status (dev, TRUE);
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
start_capture(dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* no finger, poll for a new histogram */
|
||||
start_finger_detection(dev);
|
||||
}
|
||||
|
||||
out:
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
finger_det_cmd_cb (FpiUsbTransfer *t, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void finger_det_cmd_cb(struct libusb_transfer *t)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
struct libusb_transfer *transfer;
|
||||
unsigned char *data;
|
||||
int r;
|
||||
struct fp_img_dev *dev = t->user_data;
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
if (error)
|
||||
{
|
||||
fp_dbg ("req transfer status %s\n", error->message);
|
||||
fpi_image_device_session_error (dev, error);
|
||||
return;
|
||||
if (t->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("req transfer status %d\n", t->status);
|
||||
fpi_imgdev_session_error(dev, -EIO);
|
||||
goto exit_free_transfer;
|
||||
} else if (t->length != t->actual_length) {
|
||||
fp_dbg("expected %d, sent %d bytes", t->length, t->actual_length);
|
||||
fpi_imgdev_session_error(dev, -EPROTO);
|
||||
goto exit_free_transfer;
|
||||
}
|
||||
|
||||
transfer = fpi_usb_transfer_new (device);
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk (transfer, self->ep_in,
|
||||
IMAGE_SIZE);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
finger_det_data_cb, NULL);
|
||||
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);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
}
|
||||
exit_free_transfer:
|
||||
libusb_free_transfer(t);
|
||||
}
|
||||
|
||||
static void
|
||||
start_finger_detection (FpImageDevice *dev)
|
||||
static void start_finger_detection(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
FpiUsbTransfer *transfer;
|
||||
|
||||
int r;
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
struct libusb_transfer *transfer;
|
||||
G_DEBUG_HERE();
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
complete_deactivation (dev, NULL);
|
||||
if (upekdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, self->ep_out,
|
||||
(unsigned char *) scan_cmd,
|
||||
UPEKTC_CMD_LEN, NULL);
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
finger_det_cmd_cb, NULL);
|
||||
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);
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
}
|
||||
}
|
||||
|
||||
/****** CAPTURE ******/
|
||||
@@ -256,208 +266,213 @@ enum capture_states {
|
||||
CAPTURE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
capture_read_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void capture_cmd_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpImage *img;
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fp_dbg ("request is not completed, %s", error->message);
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
return;
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
img = fp_image_new (IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
memcpy (img->data, transfer->buffer, IMAGE_SIZE);
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
fpi_image_device_report_finger_status (dev, FALSE);
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
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);
|
||||
unsigned char *data = transfer->buffer;
|
||||
struct fp_img *img;
|
||||
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("request is not completed, %d", transfer->status);
|
||||
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_failed(ssm, -EPROTO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
static void
|
||||
capture_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (_dev);
|
||||
img = fpi_img_new(IMAGE_SIZE);
|
||||
memcpy(img->data, data, IMAGE_SIZE);
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
out:
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
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(_dev);
|
||||
int r;
|
||||
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case CAPTURE_WRITE_CMD:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (_dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, self->ep_out,
|
||||
(unsigned char *) scan_cmd,
|
||||
UPEKTC_CMD_LEN, NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
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);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, -ENOMEM);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CAPTURE_READ_DATA:
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (_dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer, self->ep_in,
|
||||
IMAGE_SIZE);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL,
|
||||
capture_read_data_cb, NULL);
|
||||
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);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
fp_dbg("Capture completed");
|
||||
if (self->deactivating)
|
||||
complete_deactivation (dev, error);
|
||||
else if (error)
|
||||
fpi_image_device_session_error (dev, error);
|
||||
if (upekdev->deactivating)
|
||||
complete_deactivation(dev);
|
||||
else if (fpi_ssm_get_error(ssm))
|
||||
fpi_imgdev_session_error(dev, fpi_ssm_get_error(ssm));
|
||||
else
|
||||
start_finger_detection(dev);
|
||||
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
start_capture (FpImageDevice *dev)
|
||||
static void start_capture(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
FpiSsm *ssm;
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
complete_deactivation (dev, NULL);
|
||||
if (upekdev->deactivating) {
|
||||
complete_deactivation(dev);
|
||||
return;
|
||||
}
|
||||
|
||||
ssm = fpi_ssm_new (FP_DEVICE (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_start(ssm, capture_sm_complete);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES);
|
||||
|
||||
self->init_idx = 0;
|
||||
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, dev);
|
||||
upekdev->init_idx = 0;
|
||||
fpi_ssm_start(ssm, activate_sm_complete);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
self->deactivating = TRUE;
|
||||
upekdev->deactivating = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
complete_deactivation (FpImageDevice *dev, GError *error)
|
||||
static void complete_deactivation(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
|
||||
struct upektc_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
G_DEBUG_HERE();
|
||||
|
||||
self->deactivating = FALSE;
|
||||
fpi_image_device_deactivate_complete (dev, error);
|
||||
upekdev->deactivating = FALSE;
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_init (FpImageDevice *dev)
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
FpiDeviceUpektc *self = FPI_DEVICE_UPEKTC (dev);
|
||||
guint64 driver_data = fpi_device_get_driver_data (FP_DEVICE (dev));
|
||||
|
||||
/* TODO check that device has endpoints we're using */
|
||||
int r;
|
||||
struct upektc_dev *upekdev;
|
||||
|
||||
if (!g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error))
|
||||
{
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
return;
|
||||
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;
|
||||
}
|
||||
|
||||
switch (driver_data)
|
||||
{
|
||||
upekdev = g_malloc0(sizeof(struct upektc_dev));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), upekdev);
|
||||
switch (driver_data) {
|
||||
case UPEKTC_2015:
|
||||
self->ep_in = UPEKTC_EP_IN;
|
||||
self->ep_out = UPEKTC_EP_OUT;
|
||||
self->setup_commands = upektc_setup_commands;
|
||||
self->setup_commands_len = G_N_ELEMENTS (upektc_setup_commands);
|
||||
self->sum_threshold = UPEKTC_SUM_THRESHOLD;
|
||||
upekdev->ep_in = UPEKTC_EP_IN;
|
||||
upekdev->ep_out = UPEKTC_EP_OUT;
|
||||
upekdev->setup_commands = upektc_setup_commands;
|
||||
upekdev->setup_commands_len = G_N_ELEMENTS(upektc_setup_commands);
|
||||
upekdev->sum_threshold = UPEKTC_SUM_THRESHOLD;
|
||||
break;
|
||||
|
||||
case UPEKTC_3001:
|
||||
self->ep_in = UPEKET_EP_IN;
|
||||
self->ep_out = UPEKET_EP_OUT;
|
||||
self->setup_commands = upeket_setup_commands;
|
||||
self->setup_commands_len = G_N_ELEMENTS (upeket_setup_commands);
|
||||
self->sum_threshold = UPEKET_SUM_THRESHOLD;
|
||||
upekdev->ep_in = UPEKET_EP_IN;
|
||||
upekdev->ep_out = UPEKET_EP_OUT;
|
||||
upekdev->setup_commands = upeket_setup_commands;
|
||||
upekdev->setup_commands_len = G_N_ELEMENTS(upeket_setup_commands);
|
||||
upekdev->sum_threshold = UPEKET_SUM_THRESHOLD;
|
||||
break;
|
||||
|
||||
default:
|
||||
fp_err("Device variant %lu is not known\n", driver_data);
|
||||
g_assert_not_reached ();
|
||||
fpi_image_device_open_complete (dev, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
return;
|
||||
g_free(upekdev);
|
||||
fp_dev_set_instance_data(FP_DEV(dev), NULL);
|
||||
return -ENODEV;
|
||||
break;
|
||||
}
|
||||
fpi_image_device_open_complete (dev, NULL);
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deinit (FpImageDevice *dev)
|
||||
static void dev_deinit(struct fp_img_dev *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
void *user_data;
|
||||
user_data = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(user_data);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x0483, .pid = 0x2015, .driver_data = UPEKTC_2015 },
|
||||
{ .vid = 0x147e, .pid = 0x3001, .driver_data = UPEKTC_3001 },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x0483, .product = 0x2015, .driver_data = UPEKTC_2015 },
|
||||
{ .vendor = 0x147e, .product = 0x3001, .driver_data = UPEKTC_3001 },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_upektc_init (FpiDeviceUpektc *self)
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_upektc_class_init (FpiDeviceUpektcClass *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
struct fp_img_driver upektc_driver = {
|
||||
.driver = {
|
||||
.id = UPEKTC_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "UPEK TouchChip/Eikon Touch 300",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_PRESS,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = IMAGE_HEIGHT,
|
||||
.img_width = IMAGE_WIDTH,
|
||||
|
||||
dev_class->id = "upektc";
|
||||
dev_class->full_name = "UPEK TouchChip/Eikon Touch 300";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_PRESS;
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
|
||||
img_class->bz3_threshold = 30;
|
||||
|
||||
img_class->img_width = IMAGE_WIDTH;
|
||||
img_class->img_height = IMAGE_HEIGHT;
|
||||
}
|
||||
.bz3_threshold = 30,
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __UPEKTC_H
|
||||
#define __UPEKTC_H
|
||||
|
||||
#define UPEKTC_CMD_LEN 0x40
|
||||
#define IMAGE_WIDTH 208
|
||||
@@ -28,8 +29,7 @@
|
||||
#define UPEKTC_SUM_THRESHOLD 10000
|
||||
#define UPEKET_SUM_THRESHOLD 5000
|
||||
|
||||
struct setup_cmd
|
||||
{
|
||||
struct setup_cmd {
|
||||
unsigned char cmd[0x40];
|
||||
int response_len;
|
||||
};
|
||||
@@ -1935,3 +1935,5 @@ static const unsigned char scan_cmd[0x40] = {
|
||||
0x05, 0x90, 0xf6, 0x77, 0x84, 0xf5, 0x2f, 0x01,
|
||||
0x05, 0x90, 0xf6, 0x00, 0xc8, 0x00, 0xec, 0x00
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,13 +21,14 @@
|
||||
|
||||
#include "drivers_api.h"
|
||||
#include "upek_proto.h"
|
||||
#include "aeslib.h"
|
||||
#include "upektc_img.h"
|
||||
|
||||
static void start_capture (FpImageDevice *dev);
|
||||
static void start_deactivation (FpImageDevice *dev);
|
||||
static void start_capture(struct fp_img_dev *dev);
|
||||
static void start_deactivation(struct fp_img_dev *dev);
|
||||
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
#define CTRL_TIMEOUT 4000
|
||||
#define BULK_TIMEOUT 4000
|
||||
|
||||
@@ -39,26 +40,19 @@ static void start_deactivation (FpImageDevice *dev);
|
||||
#define MAX_RESPONSE_SIZE 2052
|
||||
#define SHORT_RESPONSE_SIZE 64
|
||||
|
||||
struct _FpiDeviceUpektcImg
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
struct upektc_img_dev {
|
||||
unsigned char cmd[MAX_CMD_SIZE];
|
||||
unsigned char response[MAX_RESPONSE_SIZE];
|
||||
unsigned char *image_bits;
|
||||
unsigned char image_bits[IMAGE_SIZE * 2];
|
||||
unsigned char seq;
|
||||
size_t image_size;
|
||||
size_t response_rest;
|
||||
gboolean deactivating;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpiDeviceUpektcImg, fpi_device_upektc_img, FPI,
|
||||
DEVICE_UPEKTC_IMG, FpImageDevice);
|
||||
G_DEFINE_TYPE (FpiDeviceUpektcImg, fpi_device_upektc_img, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
/****** HELPERS ******/
|
||||
|
||||
static void
|
||||
upektc_img_cmd_fix_seq (unsigned char *cmd_buf, unsigned char seq)
|
||||
static void upektc_img_cmd_fix_seq(unsigned char *cmd_buf, unsigned char seq)
|
||||
{
|
||||
uint8_t byte;
|
||||
|
||||
@@ -68,8 +62,7 @@ upektc_img_cmd_fix_seq (unsigned char *cmd_buf, unsigned char seq)
|
||||
cmd_buf[5] = byte;
|
||||
}
|
||||
|
||||
static void
|
||||
upektc_img_cmd_update_crc (unsigned char *cmd_buf, size_t size)
|
||||
static void upektc_img_cmd_update_crc(unsigned char *cmd_buf, size_t size)
|
||||
{
|
||||
/* CRC does not cover Ciao prefix (4 bytes) and CRC location (2 bytes) */
|
||||
uint16_t crc = udf_crc(cmd_buf + 4, size - 6);
|
||||
@@ -79,46 +72,58 @@ upektc_img_cmd_update_crc (unsigned char *cmd_buf, size_t size)
|
||||
}
|
||||
|
||||
static void
|
||||
upektc_img_submit_req (FpiSsm *ssm,
|
||||
FpImageDevice *dev,
|
||||
upektc_img_submit_req(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev,
|
||||
const unsigned char *buf,
|
||||
size_t buf_size,
|
||||
unsigned char seq,
|
||||
FpiUsbTransferCallback cb)
|
||||
libusb_transfer_cb_fn cb)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
int r;
|
||||
|
||||
BUG_ON(buf_size > MAX_CMD_SIZE);
|
||||
|
||||
memcpy (self->cmd, buf, buf_size);
|
||||
upektc_img_cmd_fix_seq (self->cmd, seq);
|
||||
upektc_img_cmd_update_crc (self->cmd, buf_size);
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_OUT, self->cmd, buf_size,
|
||||
NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL, cb, NULL);
|
||||
memcpy(upekdev->cmd, buf, buf_size);
|
||||
upektc_img_cmd_fix_seq(upekdev->cmd, seq);
|
||||
upektc_img_cmd_update_crc(upekdev->cmd, buf_size);
|
||||
|
||||
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, upekdev->cmd, buf_size,
|
||||
cb, ssm, BULK_TIMEOUT);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
upektc_img_read_data (FpiSsm *ssm,
|
||||
FpImageDevice *dev,
|
||||
upektc_img_read_data(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev,
|
||||
size_t buf_size,
|
||||
size_t buf_offset,
|
||||
FpiUsbTransferCallback cb)
|
||||
libusb_transfer_cb_fn cb)
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
int r;
|
||||
|
||||
BUG_ON (buf_offset + buf_size > MAX_RESPONSE_SIZE);
|
||||
BUG_ON(buf_size > MAX_RESPONSE_SIZE);
|
||||
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, EP_IN,
|
||||
self->response + buf_offset, buf_size,
|
||||
NULL);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, BULK_TIMEOUT, NULL, cb, NULL);
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
|
||||
|
||||
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, upekdev->response + buf_offset, buf_size,
|
||||
cb, ssm, BULK_TIMEOUT);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
|
||||
/****** CAPTURE ******/
|
||||
@@ -134,279 +139,230 @@ enum capture_states {
|
||||
CAPTURE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
capture_reqs_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void capture_reqs_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) ||
|
||||
(transfer->length != transfer->actual_length)) {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
return;
|
||||
}
|
||||
switch (fpi_ssm_get_cur_state (transfer->ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case CAPTURE_ACK_00_28_TERM:
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_READ_DATA_TERM);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA_TERM);
|
||||
break;
|
||||
|
||||
default:
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_READ_DATA);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
upektc_img_process_image_frame (unsigned char *image_buf, unsigned char *cmd_res)
|
||||
static int upektc_img_process_image_frame(unsigned char *image_buf, unsigned char *cmd_res)
|
||||
{
|
||||
int offset = 8;
|
||||
int len = ((cmd_res[5] & 0x0f) << 8) | (cmd_res[6]);
|
||||
|
||||
len -= 1;
|
||||
if (cmd_res[7] == 0x2c)
|
||||
{
|
||||
if (cmd_res[7] == 0x2c) {
|
||||
len -= 10;
|
||||
offset += 10;
|
||||
}
|
||||
if (cmd_res[7] == 0x20)
|
||||
if (cmd_res[7] == 0x20) {
|
||||
len -= 4;
|
||||
}
|
||||
memcpy(image_buf, cmd_res + offset, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static void
|
||||
capture_read_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void capture_read_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
unsigned char *data = self->response;
|
||||
FpImage *img;
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
unsigned char *data = upekdev->response;
|
||||
struct fp_img *img;
|
||||
size_t response_size;
|
||||
|
||||
if (error)
|
||||
{
|
||||
fp_dbg ("request is not completed, %s", error->message);
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("request is not completed, %d", transfer->status);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (upekdev->deactivating) {
|
||||
fp_dbg("Deactivate requested\n");
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
return;
|
||||
}
|
||||
|
||||
fp_dbg ("request completed, len: %.4x", (gint) transfer->actual_length);
|
||||
if (transfer->actual_length == 0)
|
||||
{
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
fpi_ssm_get_cur_state (transfer->ssm));
|
||||
fp_dbg("request completed, len: %.4x", transfer->actual_length);
|
||||
if (transfer->actual_length == 0) {
|
||||
fpi_ssm_jump_to_state(ssm, fpi_ssm_get_cur_state(ssm));
|
||||
return;
|
||||
}
|
||||
|
||||
if (fpi_ssm_get_cur_state (transfer->ssm) == CAPTURE_READ_DATA_TERM)
|
||||
{
|
||||
if (fpi_ssm_get_cur_state(ssm) == CAPTURE_READ_DATA_TERM) {
|
||||
fp_dbg("Terminating SSM\n");
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->response_rest)
|
||||
{
|
||||
if (!upekdev->response_rest) {
|
||||
response_size = ((data[5] & 0x0f) << 8) + data[6];
|
||||
response_size += 9; /* 7 bytes for header, 2 for CRC */
|
||||
if (response_size > transfer->actual_length)
|
||||
{
|
||||
if (response_size > transfer->actual_length) {
|
||||
fp_dbg("response_size is %lu, actual_length is %d\n",
|
||||
response_size, (gint) transfer->actual_length);
|
||||
response_size, transfer->actual_length);
|
||||
fp_dbg("Waiting for rest of transfer");
|
||||
BUG_ON (self->response_rest);
|
||||
self->response_rest = response_size - transfer->actual_length;
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_READ_DATA);
|
||||
BUG_ON(upekdev->response_rest);
|
||||
upekdev->response_rest = response_size - transfer->actual_length;
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
return;
|
||||
}
|
||||
}
|
||||
self->response_rest = 0;
|
||||
upekdev->response_rest = 0;
|
||||
|
||||
switch (data[4])
|
||||
{
|
||||
switch (data[4]) {
|
||||
case 0x00:
|
||||
switch (data[7])
|
||||
{
|
||||
switch (data[7]) {
|
||||
/* No finger */
|
||||
case 0x28:
|
||||
fp_dbg("18th byte is %.2x\n", data[18]);
|
||||
switch (data[18])
|
||||
{
|
||||
switch (data[18]) {
|
||||
case 0x0c:
|
||||
/* no finger */
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
CAPTURE_ACK_00_28);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28);
|
||||
break;
|
||||
|
||||
case 0x00:
|
||||
/* finger is present! */
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
CAPTURE_ACK_00_28);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28);
|
||||
break;
|
||||
|
||||
case 0x1e:
|
||||
/* short scan */
|
||||
fp_err("short scan, aborting\n");
|
||||
fpi_image_device_retry_scan (dev,
|
||||
FP_DEVICE_RETRY_TOO_SHORT);
|
||||
fpi_image_device_report_finger_status (dev,
|
||||
FALSE);
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
CAPTURE_ACK_00_28_TERM);
|
||||
fpi_imgdev_abort_scan(dev, FP_VERIFY_RETRY_TOO_SHORT);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28_TERM);
|
||||
break;
|
||||
|
||||
case 0x1d:
|
||||
/* too much horisontal movement */
|
||||
fp_err("too much horisontal movement, aborting\n");
|
||||
fpi_image_device_retry_scan (dev,
|
||||
FP_DEVICE_RETRY_CENTER_FINGER);
|
||||
fpi_image_device_report_finger_status (dev,
|
||||
FALSE);
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
CAPTURE_ACK_00_28_TERM);
|
||||
fpi_imgdev_abort_scan(dev, FP_VERIFY_RETRY_CENTER_FINGER);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28_TERM);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* some error happened, cancel scan */
|
||||
fp_err("something bad happened, stop scan\n");
|
||||
fpi_image_device_retry_scan (dev,
|
||||
FP_DEVICE_RETRY);
|
||||
fpi_image_device_report_finger_status (dev,
|
||||
FALSE);
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
CAPTURE_ACK_00_28_TERM);
|
||||
fpi_imgdev_abort_scan(dev, FP_VERIFY_RETRY);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28_TERM);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Image frame with additional info */
|
||||
case 0x2c:
|
||||
fpi_image_device_report_finger_status (dev,
|
||||
TRUE);
|
||||
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
/* Plain image frame */
|
||||
case 0x24:
|
||||
self->image_size +=
|
||||
upektc_img_process_image_frame (self->image_bits + self->image_size,
|
||||
upekdev->image_size +=
|
||||
upektc_img_process_image_frame(upekdev->image_bits + upekdev->image_size,
|
||||
data);
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
CAPTURE_ACK_FRAME);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_FRAME);
|
||||
break;
|
||||
|
||||
/* Last image frame */
|
||||
case 0x20:
|
||||
self->image_size +=
|
||||
upektc_img_process_image_frame (self->image_bits + self->image_size,
|
||||
upekdev->image_size +=
|
||||
upektc_img_process_image_frame(upekdev->image_bits + upekdev->image_size,
|
||||
data);
|
||||
BUG_ON (self->image_size != IMAGE_SIZE);
|
||||
fp_dbg ("Image size is %lu\n",
|
||||
self->image_size);
|
||||
img = fp_image_new (IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
memcpy (img->data, self->image_bits,
|
||||
IMAGE_SIZE);
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
fpi_image_device_report_finger_status (dev,
|
||||
FALSE);
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
BUG_ON(upekdev->image_size != IMAGE_SIZE);
|
||||
fp_dbg("Image size is %lu\n", upekdev->image_size);
|
||||
img = fpi_img_new(IMAGE_SIZE);
|
||||
img->flags = FP_IMG_PARTIAL;
|
||||
memcpy(img->data, upekdev->image_bits, IMAGE_SIZE);
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
break;
|
||||
|
||||
default:
|
||||
fp_err ("Unknown response!\n");
|
||||
fpi_ssm_mark_failed (transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
fp_err("Uknown response!\n");
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_ACK_08);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_08);
|
||||
break;
|
||||
|
||||
default:
|
||||
fp_err("Not handled response!\n");
|
||||
fpi_ssm_mark_failed (transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
capture_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case CAPTURE_INIT_CAPTURE:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_init_capture, sizeof(upek2020_init_capture),
|
||||
self->seq, capture_reqs_cb);
|
||||
self->seq++;
|
||||
upekdev->seq, capture_reqs_cb);
|
||||
upekdev->seq++;
|
||||
break;
|
||||
|
||||
case CAPTURE_READ_DATA:
|
||||
case CAPTURE_READ_DATA_TERM:
|
||||
if (!self->response_rest)
|
||||
if (!upekdev->response_rest)
|
||||
upektc_img_read_data(ssm, dev, SHORT_RESPONSE_SIZE, 0, capture_read_data_cb);
|
||||
else
|
||||
upektc_img_read_data(ssm, dev, MAX_RESPONSE_SIZE - SHORT_RESPONSE_SIZE,
|
||||
SHORT_RESPONSE_SIZE, capture_read_data_cb);
|
||||
break;
|
||||
|
||||
case CAPTURE_ACK_00_28:
|
||||
case CAPTURE_ACK_00_28_TERM:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_ack_00_28, sizeof(upek2020_ack_00_28),
|
||||
self->seq, capture_reqs_cb);
|
||||
self->seq++;
|
||||
upekdev->seq, capture_reqs_cb);
|
||||
upekdev->seq++;
|
||||
break;
|
||||
|
||||
case CAPTURE_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, dev, upek2020_ack_frame, sizeof(upek2020_ack_frame),
|
||||
self->seq, capture_reqs_cb);
|
||||
self->seq++;
|
||||
upekdev->seq, capture_reqs_cb);
|
||||
upekdev->seq++;
|
||||
break;
|
||||
}
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error_arg)
|
||||
static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
int err = fpi_ssm_get_error(ssm);
|
||||
|
||||
g_autoptr(GError) error = error_arg;
|
||||
fp_dbg("Capture completed, %d", err);
|
||||
fpi_ssm_free(ssm);
|
||||
|
||||
|
||||
/* Note: We assume that the error is a cancellation in the deactivation case */
|
||||
if (self->deactivating)
|
||||
if (upekdev->deactivating)
|
||||
start_deactivation(dev);
|
||||
else if (error)
|
||||
fpi_image_device_session_error (dev, g_steal_pointer (&error));
|
||||
else if (err)
|
||||
fpi_imgdev_session_error(dev, err);
|
||||
else
|
||||
start_capture(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
start_capture (FpImageDevice *dev)
|
||||
static void start_capture(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
FpiSsm *ssm;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
|
||||
self->image_size = 0;
|
||||
upekdev->image_size = 0;
|
||||
|
||||
ssm = fpi_ssm_new (FP_DEVICE (dev), capture_run_state,
|
||||
CAPTURE_NUM_STATES);
|
||||
ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev);
|
||||
fpi_ssm_start(ssm, capture_sm_complete);
|
||||
}
|
||||
|
||||
@@ -418,70 +374,73 @@ enum deactivate_states {
|
||||
DEACTIVATE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
deactivate_reqs_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void deactivate_reqs_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
if (!error)
|
||||
fpi_ssm_jump_to_state (transfer->ssm, CAPTURE_READ_DATA);
|
||||
else
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: process response properly */
|
||||
static void
|
||||
deactivate_read_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void deactivate_read_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
if (!error)
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
else
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
deactivate_run_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void deactivate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case DEACTIVATE_DEINIT:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_deinit, sizeof(upek2020_deinit),
|
||||
self->seq, deactivate_reqs_cb);
|
||||
self->seq++;
|
||||
upekdev->seq, deactivate_reqs_cb);
|
||||
upekdev->seq++;
|
||||
break;
|
||||
|
||||
case DEACTIVATE_READ_DEINIT_DATA:
|
||||
upektc_img_read_data(ssm, dev, SHORT_RESPONSE_SIZE, 0, deactivate_read_data_cb);
|
||||
break;
|
||||
}
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
deactivate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void deactivate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
int err = fpi_ssm_get_error(ssm);
|
||||
|
||||
fp_dbg("Deactivate completed");
|
||||
fpi_ssm_free(ssm);
|
||||
|
||||
self->deactivating = FALSE;
|
||||
fpi_image_device_deactivate_complete (dev, error);
|
||||
if (err) {
|
||||
fpi_imgdev_session_error(dev, err);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
start_deactivation (FpImageDevice *dev)
|
||||
upekdev->deactivating = FALSE;
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void start_deactivation(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
FpiSsm *ssm;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
|
||||
self->image_size = 0;
|
||||
upekdev->image_size = 0;
|
||||
|
||||
ssm = fpi_ssm_new (FP_DEVICE (dev), deactivate_run_state,
|
||||
DEACTIVATE_NUM_STATES);
|
||||
ssm = fpi_ssm_new(FP_DEV(dev), deactivate_run_state, DEACTIVATE_NUM_STATES, dev);
|
||||
fpi_ssm_start(ssm, deactivate_sm_complete);
|
||||
}
|
||||
|
||||
@@ -501,75 +460,89 @@ enum activate_states {
|
||||
ACTIVATE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
init_reqs_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void init_reqs_ctrl_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
if (!error)
|
||||
fpi_ssm_next_state (transfer->ssm);
|
||||
else
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_reqs_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: process response properly */
|
||||
static void
|
||||
init_read_data_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void init_read_data_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
if (!error)
|
||||
fpi_ssm_next_state (transfer->ssm);
|
||||
else
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activate_run_state (FpiSsm *ssm, FpDevice *dev)
|
||||
static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
FpImageDevice *idev = FP_IMAGE_DEVICE (dev);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
struct libusb_transfer *transfer;
|
||||
struct fp_img_dev *idev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(dev);
|
||||
int r;
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case ACTIVATE_CONTROL_REQ_1:
|
||||
case ACTIVATE_CONTROL_REQ_2:
|
||||
{
|
||||
transfer = fpi_usb_transfer_new (dev);
|
||||
unsigned char *data;
|
||||
|
||||
fpi_usb_transfer_fill_control (transfer,
|
||||
G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
|
||||
G_USB_DEVICE_REQUEST_TYPE_VENDOR,
|
||||
G_USB_DEVICE_RECIPIENT_DEVICE,
|
||||
0x0c, 0x100, 0x0400, 1);
|
||||
transfer->buffer[0] = '\0';
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, CTRL_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
transfer = fpi_usb_alloc();
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER |
|
||||
LIBUSB_TRANSFER_FREE_TRANSFER;
|
||||
|
||||
data = g_malloc0(LIBUSB_CONTROL_SETUP_SIZE + 1);
|
||||
libusb_fill_control_setup(data,
|
||||
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1);
|
||||
libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(dev), data,
|
||||
init_reqs_ctrl_cb, ssm, CTRL_TIMEOUT);
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTIVATE_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, idev, upek2020_init_2, sizeof(upek2020_init_2),
|
||||
0, init_reqs_cb);
|
||||
break;
|
||||
|
||||
case ACTIVATE_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, idev, upek2020_init_4, sizeof(upek2020_init_4),
|
||||
self->seq, init_reqs_cb);
|
||||
upekdev->seq, init_reqs_cb);
|
||||
/* Seq should be updated after 4th init */
|
||||
self->seq++;
|
||||
upekdev->seq++;
|
||||
break;
|
||||
|
||||
case ACTIVATE_READ_CTRL_RESP_1:
|
||||
case ACTIVATE_READ_CTRL_RESP_2:
|
||||
case ACTIVATE_READ_INIT_1_RESP:
|
||||
@@ -581,110 +554,94 @@ activate_run_state (FpiSsm *ssm, FpDevice *dev)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
int err = fpi_ssm_get_error(ssm);
|
||||
|
||||
fpi_image_device_activate_complete (dev, error);
|
||||
fpi_ssm_free(ssm);
|
||||
fp_dbg("%s status %d", __func__, err);
|
||||
fpi_imgdev_activate_complete(dev, err);
|
||||
|
||||
if (!error)
|
||||
if (!err)
|
||||
start_capture(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES);
|
||||
|
||||
self->seq = 0;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES, dev);
|
||||
upekdev->seq = 0;
|
||||
fpi_ssm_start(ssm, activate_sm_complete);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
self->deactivating = TRUE;
|
||||
upekdev->deactivating = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_init (FpImageDevice *dev)
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
GError *error = NULL;
|
||||
|
||||
/* TODO check that device has endpoints we're using */
|
||||
int r;
|
||||
struct upektc_img_dev *upekdev;
|
||||
|
||||
if (!g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error))
|
||||
{
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
return;
|
||||
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;
|
||||
}
|
||||
|
||||
self->image_bits = g_malloc0 (IMAGE_SIZE * 2);
|
||||
fpi_image_device_open_complete (dev, NULL);
|
||||
upekdev = g_malloc0(sizeof(struct upektc_img_dev));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), upekdev);
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deinit (FpImageDevice *dev)
|
||||
static void dev_deinit(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (dev);
|
||||
GError *error = NULL;
|
||||
|
||||
g_clear_pointer (&self->image_bits, g_free);
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(upekdev);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static int
|
||||
discover (GUsbDevice *usb_device)
|
||||
static int discover(struct libusb_device_descriptor *dsc, uint32_t *devtype)
|
||||
{
|
||||
gint16 pid = g_usb_device_get_pid (usb_device);
|
||||
gint16 bcd = g_usb_device_get_release (usb_device);
|
||||
|
||||
if (pid == 0x2020 && bcd == 1)
|
||||
return 100;
|
||||
if (pid == 0x2016 && bcd == 2)
|
||||
return 100;
|
||||
if (dsc->idProduct == 0x2020 && dsc->bcdDevice == 1)
|
||||
return 1;
|
||||
if (dsc->idProduct == 0x2016 && dsc->bcdDevice == 2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x147e, .pid = 0x2016, },
|
||||
{ .vid = 0x147e, .pid = 0x2020, },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x147e, .product = 0x2016 },
|
||||
{ .vendor = 0x147e, .product = 0x2020 },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_upektc_img_init (FpiDeviceUpektcImg *self)
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_upektc_img_class_init (FpiDeviceUpektcImgClass *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
struct fp_img_driver upektc_img_driver = {
|
||||
.driver = {
|
||||
.id = UPEKTC_IMG_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "Upek TouchChip Fingerprint Coprocessor",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
.discover = discover,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = IMAGE_HEIGHT,
|
||||
.img_width = IMAGE_WIDTH,
|
||||
.bz3_threshold = 20,
|
||||
|
||||
dev_class->id = "upektc_img";
|
||||
dev_class->full_name = "Upek TouchChip Fingerprint Coprocessor";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
dev_class->usb_discover = discover;
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
|
||||
img_class->bz3_threshold = 20;
|
||||
|
||||
img_class->img_width = IMAGE_WIDTH;
|
||||
img_class->img_height = IMAGE_HEIGHT;
|
||||
}
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __UPEKTC_IMG_H
|
||||
#define __UPEKTC_IMG_H
|
||||
|
||||
static const unsigned char upek2020_init_1[] = {
|
||||
'C', 'i', 'a', 'o',
|
||||
@@ -139,3 +140,5 @@ static const unsigned char upek2020_ack_frame[] = {
|
||||
0x30,
|
||||
0xac, 0x5b /* CRC */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
* powerdown? does windows do anything special on exit?
|
||||
*/
|
||||
|
||||
#define CTRL_IN 0xc0
|
||||
#define CTRL_OUT 0x40
|
||||
#define CTRL_TIMEOUT 1000
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
|
||||
#define IMG_WIDTH 300
|
||||
#define IMG_HEIGHT 288
|
||||
@@ -38,18 +40,12 @@
|
||||
#define RQ_SIZE (IMG_WIDTH * ROWS_PER_RQ)
|
||||
#define IMG_SIZE (IMG_WIDTH * IMG_HEIGHT)
|
||||
|
||||
struct _FpDeviceVcom5s
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
struct v5s_dev {
|
||||
int capture_iteration;
|
||||
FpImage *capture_img;
|
||||
struct fp_img *capture_img;
|
||||
gboolean loop_running;
|
||||
gboolean deactivating;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (FpDeviceVcom5s, fpi_device_vcom5s, FPI, DEVICE_VCOM5S,
|
||||
FpImageDevice);
|
||||
G_DEFINE_TYPE (FpDeviceVcom5s, fpi_device_vcom5s, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
enum v5s_regs {
|
||||
/* when using gain 0x29:
|
||||
@@ -76,42 +72,76 @@ enum v5s_cmd {
|
||||
|
||||
/***** REGISTER I/O *****/
|
||||
|
||||
static void
|
||||
sm_write_reg (FpiSsm *ssm,
|
||||
FpDevice *dev,
|
||||
unsigned char reg,
|
||||
unsigned char value)
|
||||
static void sm_write_reg_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
fp_dbg ("set %02x=%02x", reg, value);
|
||||
fpi_usb_transfer_fill_control (transfer,
|
||||
G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
|
||||
G_USB_DEVICE_REQUEST_TYPE_VENDOR,
|
||||
G_USB_DEVICE_RECIPIENT_DEVICE,
|
||||
reg, value, 0, 0);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, CTRL_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED)
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
else
|
||||
fpi_ssm_next_state(ssm);
|
||||
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
sm_exec_cmd (FpiSsm *ssm,
|
||||
FpDevice *dev,
|
||||
sm_write_reg(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev,
|
||||
unsigned char reg,
|
||||
unsigned char value)
|
||||
{
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
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_dev_get_usb_dev(FP_DEV(dev)), data, sm_write_reg_cb,
|
||||
ssm, CTRL_TIMEOUT);
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
|
||||
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_failed(ssm, -EIO);
|
||||
else
|
||||
fpi_ssm_next_state(ssm);
|
||||
|
||||
g_free(transfer->buffer);
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
sm_exec_cmd(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev,
|
||||
unsigned char cmd,
|
||||
unsigned char param)
|
||||
{
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (dev);
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
unsigned char *data;
|
||||
int r;
|
||||
|
||||
fp_dbg("cmd %02x param %02x", cmd, param);
|
||||
fpi_usb_transfer_fill_control (transfer,
|
||||
G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST,
|
||||
G_USB_DEVICE_REQUEST_TYPE_VENDOR,
|
||||
G_USB_DEVICE_RECIPIENT_DEVICE,
|
||||
cmd, param, 0, 0);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, CTRL_TIMEOUT, NULL,
|
||||
fpi_ssm_usb_transfer_cb, NULL);
|
||||
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE);
|
||||
libusb_fill_control_setup(data, CTRL_IN, cmd, param, 0, 0);
|
||||
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) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
|
||||
/***** FINGER DETECTION *****/
|
||||
@@ -126,16 +156,14 @@ sm_exec_cmd (FpiSsm *ssm,
|
||||
#define DETBOX_COL_END (DETBOX_COL_START + DETBOX_COLS)
|
||||
#define FINGER_PRESENCE_THRESHOLD 100
|
||||
|
||||
static gboolean
|
||||
finger_is_present (unsigned char *data)
|
||||
static gboolean finger_is_present(unsigned char *data)
|
||||
{
|
||||
int row;
|
||||
guint16 imgavg = 0;
|
||||
uint16_t imgavg = 0;
|
||||
|
||||
for (row = DETBOX_ROW_START; row < DETBOX_ROW_END; row++)
|
||||
{
|
||||
for (row = DETBOX_ROW_START; row < DETBOX_ROW_END; row++) {
|
||||
unsigned char *rowdata = data + (row * IMG_WIDTH);
|
||||
guint16 rowavg = 0;
|
||||
uint16_t rowavg = 0;
|
||||
int col;
|
||||
|
||||
for (col = DETBOX_COL_START; col < DETBOX_COL_END; col++)
|
||||
@@ -146,78 +174,74 @@ finger_is_present (unsigned char *data)
|
||||
imgavg /= DETBOX_ROWS;
|
||||
fp_dbg("img avg %d", imgavg);
|
||||
|
||||
return imgavg <= FINGER_PRESENCE_THRESHOLD;
|
||||
return (imgavg <= FINGER_PRESENCE_THRESHOLD);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***** IMAGE ACQUISITION *****/
|
||||
|
||||
static void capture_iterate (FpiSsm *ssm,
|
||||
FpDevice *dev);
|
||||
static void capture_iterate(fpi_ssm *ssm, struct fp_img_dev *dev);
|
||||
|
||||
static void
|
||||
capture_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void capture_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *imgdev = FP_IMAGE_DEVICE (device);
|
||||
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (device);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
if (error)
|
||||
{
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
return;
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (++self->capture_iteration == NR_REQS)
|
||||
{
|
||||
FpImage *img = self->capture_img;
|
||||
if (++vdev->capture_iteration == NR_REQS) {
|
||||
struct fp_img *img = vdev->capture_img;
|
||||
/* must clear this early, otherwise the call chain takes us into
|
||||
* loopsm_complete where we would free it, when in fact we are
|
||||
* supposed to be handing off this image */
|
||||
self->capture_img = NULL;
|
||||
vdev->capture_img = NULL;
|
||||
|
||||
fpi_image_device_report_finger_status (imgdev,
|
||||
finger_is_present (img->data));
|
||||
fpi_image_device_image_captured (imgdev, img);
|
||||
fpi_ssm_next_state (transfer->ssm);
|
||||
}
|
||||
else
|
||||
{
|
||||
capture_iterate (transfer->ssm, device);
|
||||
fpi_imgdev_report_finger_status(dev, finger_is_present(img->data));
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
fpi_ssm_next_state(ssm);
|
||||
} else {
|
||||
capture_iterate(ssm, dev);
|
||||
}
|
||||
|
||||
out:
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
capture_iterate (FpiSsm *ssm,
|
||||
FpDevice *dev)
|
||||
capture_iterate(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev);
|
||||
int iteration = self->capture_iteration;
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
int iteration = vdev->capture_iteration;
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
int r;
|
||||
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk_full (transfer,
|
||||
EP_IN,
|
||||
self->capture_img->data + (RQ_SIZE * iteration),
|
||||
RQ_SIZE,
|
||||
NULL);
|
||||
|
||||
fpi_usb_transfer_submit (transfer, CTRL_TIMEOUT, NULL, capture_cb, NULL);
|
||||
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;
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
sm_do_capture (FpiSsm *ssm,
|
||||
FpDevice *dev)
|
||||
sm_do_capture(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev);
|
||||
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (dev);
|
||||
struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
G_DEBUG_HERE();
|
||||
self->capture_img = fp_image_new (cls->img_width, cls->img_height);
|
||||
self->capture_iteration = 0;
|
||||
vdev->capture_img = fpi_img_new_for_imgdev(dev);
|
||||
vdev->capture_iteration = 0;
|
||||
capture_iterate(ssm, dev);
|
||||
}
|
||||
|
||||
@@ -232,136 +256,120 @@ enum loop_states {
|
||||
LOOP_NUM_STATES,
|
||||
};
|
||||
|
||||
static void
|
||||
loop_run_state (FpiSsm *ssm, FpDevice *dev)
|
||||
static void loop_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct v5s_dev *vdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case LOOP_SET_CONTRAST:
|
||||
sm_write_reg(ssm, dev, REG_CONTRAST, 0x01);
|
||||
break;
|
||||
|
||||
case LOOP_SET_GAIN:
|
||||
sm_write_reg(ssm, dev, REG_GAIN, 0x29);
|
||||
break;
|
||||
|
||||
case LOOP_CMD_SCAN:
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (vdev->deactivating) {
|
||||
fp_dbg("deactivating, marking completed");
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
sm_exec_cmd(ssm, dev, CMD_SCAN, 0x00);
|
||||
}
|
||||
break;
|
||||
|
||||
case LOOP_CAPTURE:
|
||||
sm_do_capture(ssm, dev);
|
||||
break;
|
||||
|
||||
case LOOP_CAPTURE_DONE:
|
||||
fpi_ssm_jump_to_state(ssm, LOOP_CMD_SCAN);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
loopsm_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
|
||||
static void loopsm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *imgdev = FP_IMAGE_DEVICE (dev);
|
||||
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct v5s_dev *vdev = FP_INSTANCE_DATA(_dev);
|
||||
int r = fpi_ssm_get_error(ssm);
|
||||
|
||||
g_object_unref (self->capture_img);
|
||||
self->capture_img = NULL;
|
||||
self->loop_running = FALSE;
|
||||
fpi_ssm_free(ssm);
|
||||
fp_img_free(vdev->capture_img);
|
||||
vdev->capture_img = NULL;
|
||||
vdev->loop_running = FALSE;
|
||||
|
||||
if (error && !self->deactivating)
|
||||
fpi_image_device_session_error (imgdev, error);
|
||||
else if (error)
|
||||
g_error_free (error);
|
||||
if (r)
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
|
||||
if (self->deactivating)
|
||||
fpi_image_device_deactivate_complete (imgdev, NULL);
|
||||
if (vdev->deactivating)
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev);
|
||||
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (dev), loop_run_state, LOOP_NUM_STATES);
|
||||
|
||||
self->deactivating = FALSE;
|
||||
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, dev);
|
||||
vdev->deactivating = FALSE;
|
||||
fpi_ssm_start(ssm, loopsm_complete);
|
||||
self->loop_running = TRUE;
|
||||
fpi_image_device_activate_complete (dev, NULL);
|
||||
vdev->loop_running = TRUE;
|
||||
fpi_imgdev_activate_complete(dev, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev);
|
||||
|
||||
if (self->loop_running)
|
||||
self->deactivating = TRUE;
|
||||
struct v5s_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
if (vdev->loop_running)
|
||||
vdev->deactivating = TRUE;
|
||||
else
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_init (FpImageDevice *dev)
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
int r;
|
||||
struct v5s_dev *v5s_dev;
|
||||
|
||||
g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error);
|
||||
v5s_dev = g_malloc0(sizeof(struct v5s_dev));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), v5s_dev);
|
||||
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
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));
|
||||
|
||||
if (r == 0)
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deinit (FpImageDevice *dev)
|
||||
static void dev_deinit(struct fp_img_dev *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
struct v5s_dev *v5s_dev;
|
||||
v5s_dev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(v5s_dev);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ .vid = 0x061a, .pid = 0x0110, },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x061a, .product = 0x0110 },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_vcom5s_init (FpDeviceVcom5s *self)
|
||||
{
|
||||
}
|
||||
struct fp_img_driver vcom5s_driver = {
|
||||
.driver = {
|
||||
.id = VCOM5S_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "Veridicom 5thSense",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_PRESS,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = IMG_HEIGHT,
|
||||
.img_width = IMG_WIDTH,
|
||||
|
||||
static void
|
||||
fpi_device_vcom5s_class_init (FpDeviceVcom5sClass *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
dev_class->id = "vcom5s";
|
||||
dev_class->full_name = "Veridicom 5thSense";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_PRESS;
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
|
||||
img_class->img_width = IMG_WIDTH;
|
||||
img_class->img_height = IMG_HEIGHT;
|
||||
}
|
||||
|
||||
@@ -17,10 +17,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fpi-image-device.h"
|
||||
|
||||
/* Timeout for all send/recv operations, except interrupt waiting and abort */
|
||||
#define VFS_USB_TIMEOUT 100
|
||||
/* Timeout for usb abort */
|
||||
@@ -51,8 +47,7 @@
|
||||
#define EP3_IN 0x83
|
||||
|
||||
/* Fingerprint horizontal line */
|
||||
struct vfs_line
|
||||
{
|
||||
struct vfs_line {
|
||||
/* It must be always 0x01 */
|
||||
unsigned char _0x01;
|
||||
/* It must be always 0xfe */
|
||||
@@ -79,10 +74,7 @@ struct vfs_line
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/* The main driver structure */
|
||||
struct _FpDeviceVfs0050
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
struct vfs_dev_t {
|
||||
/* One if we were asked to read fingerprint, zero otherwise */
|
||||
char active;
|
||||
|
||||
@@ -92,9 +84,15 @@ struct _FpDeviceVfs0050
|
||||
/* For dev_deactivate to check whether ssm still running or not */
|
||||
char ssm_active;
|
||||
|
||||
/* Current async transfer */
|
||||
struct libusb_transfer *transfer;
|
||||
|
||||
/* Should we call fpi_imgdev_activate_complete or fpi_imgdev_deactivate_complete */
|
||||
char need_report;
|
||||
|
||||
/* Should we wait more for interrupt */
|
||||
char wait_interrupt;
|
||||
|
||||
/* Received fingerprint raw lines */
|
||||
struct vfs_line *lines_buffer;
|
||||
|
||||
@@ -108,8 +106,6 @@ struct _FpDeviceVfs0050
|
||||
unsigned char interrupt[8];
|
||||
};
|
||||
|
||||
G_DECLARE_FINAL_TYPE (FpDeviceVfs0050, fpi_device_vfs0050, FPI, DEVICE_VFS0050, FpImageDevice)
|
||||
|
||||
/* SSM states for clear_ep2 */
|
||||
enum SUBSM1 {
|
||||
SUBSM1_COMMAND_04,
|
||||
|
||||
@@ -22,52 +22,64 @@
|
||||
#define FP_COMPONENT "vfs301"
|
||||
|
||||
#include "drivers_api.h"
|
||||
#include "vfs301.h"
|
||||
|
||||
G_DEFINE_TYPE (FpDeviceVfs301, fpi_device_vfs301, FP_TYPE_IMAGE_DEVICE)
|
||||
#include "vfs301_proto.h"
|
||||
|
||||
/************************** GENERIC STUFF *************************************/
|
||||
|
||||
static int
|
||||
submit_image (FpiSsm *ssm,
|
||||
FpImageDevice *dev)
|
||||
/* Submit asynchronous sleep */
|
||||
static void
|
||||
async_sleep(unsigned int msec,
|
||||
fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
|
||||
/* Add timeout */
|
||||
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);
|
||||
fpi_ssm_mark_failed(ssm, -ETIME);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
submit_image(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
vfs301_dev_t *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
int height;
|
||||
FpImage *img;
|
||||
struct fp_img *img;
|
||||
|
||||
#if 0
|
||||
/* XXX: This is probably handled by libfprint automagically? */
|
||||
if (vdev->scanline_count < 20)
|
||||
{
|
||||
if (vdev->scanline_count < 20) {
|
||||
fpi_ssm_jump_to_state(ssm, M_REQUEST_PRINT);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
img = fp_image_new (VFS301_FP_OUTPUT_WIDTH, self->scanline_count);
|
||||
img = fpi_img_new(VFS301_FP_OUTPUT_WIDTH * vdev->scanline_count);
|
||||
if (img == NULL)
|
||||
return 0;
|
||||
|
||||
vfs301_extract_image (self, img->data, &height);
|
||||
vfs301_extract_image(vdev, img->data, &height);
|
||||
|
||||
/* TODO: how to detect flip? should the resulting image be
|
||||
* oriented so that it is equal e.g. to a fingerprint on a paper,
|
||||
* or to the finger when I look at it?) */
|
||||
img->flags = FPI_IMAGE_COLORS_INVERTED | FPI_IMAGE_V_FLIPPED;
|
||||
img->flags = FP_IMG_COLORS_INVERTED | FP_IMG_V_FLIPPED;
|
||||
|
||||
/* The image buffer is larger at this point, but that does not
|
||||
* matter. */
|
||||
img->width = VFS301_FP_OUTPUT_WIDTH;
|
||||
img->height = height;
|
||||
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
img = fpi_img_realloc(img, img->height * img->width);
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Loop ssm states */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
/* Step 0 - Scan finger */
|
||||
M_REQUEST_PRINT,
|
||||
M_WAIT_PRINT,
|
||||
@@ -82,45 +94,43 @@ enum {
|
||||
};
|
||||
|
||||
/* Exec loop sequential state machine */
|
||||
static void
|
||||
m_loop_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void m_loop_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
vfs301_dev_t *vdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case M_REQUEST_PRINT:
|
||||
vfs301_proto_request_fingerprint (self);
|
||||
vfs301_proto_request_fingerprint(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev);
|
||||
fpi_ssm_next_state(ssm);
|
||||
break;
|
||||
|
||||
case M_WAIT_PRINT:
|
||||
/* Wait fingerprint scanning */
|
||||
fpi_ssm_next_state_delayed (ssm, 200, NULL);
|
||||
async_sleep(200, ssm, dev);
|
||||
break;
|
||||
|
||||
case M_CHECK_PRINT:
|
||||
if (!vfs301_proto_peek_event (self))
|
||||
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);
|
||||
break;
|
||||
|
||||
case M_READ_PRINT_START:
|
||||
fpi_image_device_report_finger_status (dev, TRUE);
|
||||
vfs301_proto_process_event_start (self);
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
vfs301_proto_process_event_start(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev);
|
||||
fpi_ssm_next_state(ssm);
|
||||
break;
|
||||
|
||||
case M_READ_PRINT_WAIT:
|
||||
/* Wait fingerprint scanning */
|
||||
fpi_ssm_next_state_delayed (ssm, 200, NULL);
|
||||
async_sleep(200, ssm, dev);
|
||||
break;
|
||||
|
||||
case M_READ_PRINT_POLL:
|
||||
{
|
||||
int rv = vfs301_proto_process_event_poll (self);
|
||||
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);
|
||||
@@ -130,152 +140,150 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
break;
|
||||
|
||||
case M_SUBMIT_PRINT:
|
||||
if (submit_image (ssm, dev))
|
||||
{
|
||||
if (submit_image(ssm, dev)) {
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
/* NOTE: finger off is expected only after submitting image... */
|
||||
fpi_image_device_report_finger_status (dev, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
} else {
|
||||
fpi_ssm_jump_to_state(ssm, M_REQUEST_PRINT);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Complete loop sequential state machine */
|
||||
static void
|
||||
m_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void m_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
g_warning ("State machine completed with an error: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
/* Free sequential state machine */
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
/* Exec init sequential state machine */
|
||||
static void
|
||||
m_init_state (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void m_init_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (_dev);
|
||||
struct fp_img_dev *dev = user_data;
|
||||
vfs301_dev_t *vdev = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
g_assert(fpi_ssm_get_cur_state(ssm) == 0);
|
||||
|
||||
vfs301_proto_init (self);
|
||||
vfs301_proto_init(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev);
|
||||
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
}
|
||||
|
||||
/* Complete init sequential state machine */
|
||||
static void
|
||||
m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
|
||||
static void m_init_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpiSsm *ssm_loop;
|
||||
struct fp_img_dev *dev = user_data;
|
||||
fpi_ssm *ssm_loop;
|
||||
|
||||
fpi_image_device_activate_complete (FP_IMAGE_DEVICE (dev), error);
|
||||
if (!error)
|
||||
{
|
||||
if (!fpi_ssm_get_error(ssm)) {
|
||||
/* Notify activate complete */
|
||||
fpi_imgdev_activate_complete(dev, 0);
|
||||
|
||||
/* Start loop ssm */
|
||||
ssm_loop = fpi_ssm_new (dev, m_loop_state, M_LOOP_NUM_STATES);
|
||||
ssm_loop = fpi_ssm_new(FP_DEV(dev), m_loop_state, M_LOOP_NUM_STATES, dev);
|
||||
fpi_ssm_start(ssm_loop, m_loop_complete);
|
||||
}
|
||||
|
||||
/* Free sequential state machine */
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
/* Activate device */
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpiSsm *ssm;
|
||||
fpi_ssm *ssm;
|
||||
|
||||
/* Start init ssm */
|
||||
ssm = fpi_ssm_new (FP_DEVICE (dev), m_init_state, 1);
|
||||
ssm = fpi_ssm_new(FP_DEV(dev), m_init_state, 1, dev);
|
||||
fpi_ssm_start(ssm, m_init_complete);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Deactivate device */
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVfs301 *self;
|
||||
vfs301_dev_t *vdev;
|
||||
|
||||
self = FPI_DEVICE_VFS301 (dev);
|
||||
vfs301_proto_deinit (self);
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
vfs301_proto_deinit(fpi_dev_get_usb_dev(FP_DEV(dev)), vdev);
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_open (FpImageDevice *dev)
|
||||
static int dev_open(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
|
||||
GError *error = NULL;
|
||||
vfs301_dev_t *vdev = NULL;
|
||||
int r;
|
||||
|
||||
/* Claim usb interface */
|
||||
g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error);
|
||||
|
||||
/* Initialize private structure */
|
||||
self->scanline_count = 0;
|
||||
|
||||
/* Notify open complete */
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
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));
|
||||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_close (FpImageDevice *dev)
|
||||
/* Initialize private structure */
|
||||
vdev = g_malloc0(sizeof(vfs301_dev_t));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), vdev);
|
||||
|
||||
vdev->scanline_buf = malloc(0);
|
||||
vdev->scanline_count = 0;
|
||||
|
||||
/* Notify open complete */
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dev_close(struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
|
||||
GError *error = NULL;
|
||||
vfs301_dev_t *vdev;
|
||||
|
||||
/* Release private structure */
|
||||
g_clear_pointer (&self->scanline_buf, g_free);
|
||||
vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
free(vdev->scanline_buf);
|
||||
g_free(vdev);
|
||||
|
||||
/* Release usb interface */
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
|
||||
/* Notify close complete */
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
/* Usb id table of device */
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ /* vfs301 */ .vid = 0x138a, .pid = 0x0005, },
|
||||
{ /* vfs300 */ .vid = 0x138a, .pid = 0x0008, },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] =
|
||||
{
|
||||
{ .vendor = 0x138a, .product = 0x0005 /* vfs301 */ },
|
||||
{ .vendor = 0x138a, .product = 0x0008 /* vfs300 */ },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_vfs301_init (FpDeviceVfs301 *self)
|
||||
/* Device driver definition */
|
||||
struct fp_img_driver vfs301_driver =
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_vfs301_class_init (FpDeviceVfs301Class *klass)
|
||||
/* Driver specification */
|
||||
.driver =
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
.id = VFS301_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "Validity VFS301",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
},
|
||||
|
||||
dev_class->id = "vfs301";
|
||||
dev_class->full_name = "Validity VFS301";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
/* Image specification */
|
||||
.flags = 0,
|
||||
.img_width = VFS301_FP_WIDTH,
|
||||
.img_height = -1,
|
||||
.bz3_threshold = 24,
|
||||
|
||||
img_class->img_open = dev_open;
|
||||
img_class->img_close = dev_close;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
|
||||
img_class->bz3_threshold = 24;
|
||||
|
||||
img_class->img_width = VFS301_FP_WIDTH;
|
||||
img_class->img_height = -1;
|
||||
}
|
||||
/* Routine specification */
|
||||
.open = dev_open,
|
||||
.close = dev_close,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* vfs301/vfs300 fingerprint reader driver
|
||||
* https://github.com/andree182/vfs301
|
||||
*
|
||||
* Copyright (c) 2011-2012 Andrej Krutak <dev@andree.sk>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fpi-usb-transfer.h"
|
||||
#include "fpi-image-device.h"
|
||||
|
||||
enum {
|
||||
VFS301_DEFAULT_WAIT_TIMEOUT = 300,
|
||||
|
||||
VFS301_SEND_ENDPOINT = 0x01,
|
||||
VFS301_RECEIVE_ENDPOINT_CTRL = 0x81,
|
||||
VFS301_RECEIVE_ENDPOINT_DATA = 0x82
|
||||
};
|
||||
|
||||
#define VFS301_FP_RECV_LEN_1 (84032)
|
||||
#define VFS301_FP_RECV_LEN_2 (84096)
|
||||
|
||||
struct _FpDeviceVfs301
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
/* buffer to hold raw scanlines */
|
||||
unsigned char *scanline_buf;
|
||||
int scanline_count;
|
||||
|
||||
enum {
|
||||
VFS301_ONGOING = 0,
|
||||
VFS301_ENDED = 1,
|
||||
VFS301_FAILURE = -1
|
||||
} recv_progress;
|
||||
int recv_exp_amt;
|
||||
};
|
||||
|
||||
G_DECLARE_FINAL_TYPE (FpDeviceVfs301, fpi_device_vfs301, FPI, DEVICE_VFS301, FpImageDevice)
|
||||
|
||||
enum {
|
||||
/* Width of the scanned data in px */
|
||||
VFS301_FP_WIDTH = 200,
|
||||
|
||||
/* sizeof(fp_line_t) */
|
||||
VFS301_FP_FRAME_SIZE = 288,
|
||||
/* Width of output line */
|
||||
#ifndef OUTPUT_RAW
|
||||
VFS301_FP_OUTPUT_WIDTH = VFS301_FP_WIDTH,
|
||||
#else
|
||||
VFS301_FP_OUTPUT_WIDTH = VFS301_FP_FRAME_SIZE,
|
||||
#endif
|
||||
|
||||
VFS301_FP_SUM_LINES = 3,
|
||||
|
||||
#ifdef SCAN_FINISH_DETECTION
|
||||
/* TODO: The following changes (seen ~60 and ~80) In that
|
||||
* case we'll need to calibrate this from empty data somehow... */
|
||||
VFS301_FP_SUM_MEDIAN = 60,
|
||||
VFS301_FP_SUM_EMPTY_RANGE = 5,
|
||||
#endif
|
||||
|
||||
/* Minimum average difference between returned lines */
|
||||
VFS301_FP_LINE_DIFF_THRESHOLD = 15,
|
||||
|
||||
/* Maximum waiting time for a single fingerprint frame */
|
||||
VFS301_FP_RECV_TIMEOUT = 2000
|
||||
};
|
||||
|
||||
/* Arrays of this structure is returned during the initialization as a response
|
||||
* to the 0x02D0 messages.
|
||||
* It seems to be always the same - what is it for? Some kind of confirmation?
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
unsigned char sync_0x01;
|
||||
unsigned char sync_0xfe;
|
||||
|
||||
unsigned char counter_lo;
|
||||
unsigned char counter_hi; /* FIXME ? */
|
||||
|
||||
unsigned char flags[3];
|
||||
|
||||
unsigned char sync_0x00;
|
||||
|
||||
unsigned char scan[VFS301_FP_WIDTH];
|
||||
} vfs301_init_line_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char sync_0x01;
|
||||
unsigned char sync_0xfe;
|
||||
|
||||
unsigned char counter_lo;
|
||||
unsigned char counter_hi;
|
||||
|
||||
unsigned char sync_0x08[2]; /* XXX: always? 0x08 0x08 */
|
||||
/* 0x08 | 0x18 - Looks like 0x08 marks good quality lines */
|
||||
unsigned char flag_1;
|
||||
unsigned char sync_0x00;
|
||||
|
||||
unsigned char scan[VFS301_FP_WIDTH];
|
||||
|
||||
/* A offsetted, stretched, inverted copy of scan... probably could
|
||||
* serve finger motion speed detection?
|
||||
* Seems to be subdivided to some 10B + 53B + 1B blocks */
|
||||
unsigned char mirror[64];
|
||||
|
||||
/* Some kind of sum of the scan, very low contrast */
|
||||
unsigned char sum1[2];
|
||||
unsigned char sum2[11];
|
||||
unsigned char sum3[3];
|
||||
} vfs301_line_t;
|
||||
|
||||
void vfs301_proto_init (FpDeviceVfs301 *dev);
|
||||
void vfs301_proto_deinit (FpDeviceVfs301 *dev);
|
||||
|
||||
void vfs301_proto_request_fingerprint (FpDeviceVfs301 *dev);
|
||||
|
||||
/** returns 0 if no event is ready, or 1 if there is one... */
|
||||
int vfs301_proto_peek_event (FpDeviceVfs301 *dev);
|
||||
void vfs301_proto_process_event_start (FpDeviceVfs301 *dev);
|
||||
int vfs301_proto_process_event_poll (FpDeviceVfs301 *dev);
|
||||
|
||||
void vfs301_extract_image (FpDeviceVfs301 *vfs,
|
||||
unsigned char *output,
|
||||
int *output_height);
|
||||
@@ -34,23 +34,21 @@
|
||||
#include <stdlib.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "fpi-usb-transfer.h"
|
||||
#include "vfs301.h"
|
||||
#include "fpi-usb.h"
|
||||
#include "vfs301_proto.h"
|
||||
#include "vfs301_proto_fragments.h"
|
||||
|
||||
/************************** USB STUFF *****************************************/
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
usb_print_packet (int dir, GError *error, const guint8 *data, int length)
|
||||
static void usb_print_packet(int dir, int rv, const unsigned char *data, int length)
|
||||
{
|
||||
fprintf (stderr, "%s, error %s, len %d\n", dir ? "send" : "recv", error ? error->message : "-", length);
|
||||
fprintf(stderr, "%s, rv %d, len %d\n", dir ? "send" : "recv", rv, length);
|
||||
|
||||
#ifdef PRINT_VERBOSE
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MIN (length, 128); i++)
|
||||
{
|
||||
for (i = 0; i < MIN(length, 128); i++) {
|
||||
fprintf(stderr, "%.2X ", data[i]);
|
||||
if (i % 8 == 7)
|
||||
fprintf(stderr, " ");
|
||||
@@ -63,136 +61,106 @@ usb_print_packet (int dir, GError *error, const guint8 *data, int length)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
usb_recv (FpDeviceVfs301 *dev, guint8 endpoint, int max_bytes, FpiUsbTransfer **out, GError **error)
|
||||
static int usb_recv(
|
||||
vfs301_dev_t *dev,
|
||||
struct libusb_device_handle *devh, unsigned char endpoint, int max_bytes)
|
||||
{
|
||||
GError *err = NULL;
|
||||
g_assert(max_bytes <= sizeof(dev->recv_buf));
|
||||
|
||||
g_autoptr(FpiUsbTransfer) transfer = NULL;
|
||||
|
||||
/* XXX: This function swallows any transfer errors, that is obviously
|
||||
* quite bad (it used to assert on no-error)! */
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk (transfer, endpoint, max_bytes);
|
||||
|
||||
fpi_usb_transfer_submit_sync (transfer, VFS301_DEFAULT_WAIT_TIMEOUT, &err);
|
||||
int r = libusb_bulk_transfer(
|
||||
devh, endpoint,
|
||||
dev->recv_buf, max_bytes,
|
||||
&dev->recv_len, VFS301_DEFAULT_WAIT_TIMEOUT
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
usb_print_packet (0, err, transfer->buffer, transfer->actual_length);
|
||||
usb_print_packet(0, r, dev->recv_buf, dev->recv_len);
|
||||
#endif
|
||||
if (err)
|
||||
{
|
||||
if (!error)
|
||||
g_warning ("Unhandled receive error: %s", err->message);
|
||||
g_propagate_error (error, err);
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (out)
|
||||
*out = g_steal_pointer (&transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
usb_send (FpDeviceVfs301 *dev, const guint8 *data, gssize length, GError **error)
|
||||
static int usb_send(
|
||||
struct libusb_device_handle *devh, const unsigned char *data, int length)
|
||||
{
|
||||
GError *err = NULL;
|
||||
int transferred = 0;
|
||||
|
||||
g_autoptr(FpiUsbTransfer) transfer = NULL;
|
||||
|
||||
/* XXX: This function swallows any transfer errors, that is obviously
|
||||
* quite bad (it used to assert on no-error)! */
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, VFS301_SEND_ENDPOINT, (guint8 *) data, length, g_free);
|
||||
|
||||
fpi_usb_transfer_submit_sync (transfer, VFS301_DEFAULT_WAIT_TIMEOUT, &err);
|
||||
int r = libusb_bulk_transfer(
|
||||
devh, VFS301_SEND_ENDPOINT,
|
||||
(unsigned char *)data, length, &transferred, VFS301_DEFAULT_WAIT_TIMEOUT
|
||||
);
|
||||
|
||||
#ifdef DEBUG
|
||||
usb_print_packet (1, err, data, length);
|
||||
usb_print_packet(1, r, data, length);
|
||||
#endif
|
||||
|
||||
if (err)
|
||||
{
|
||||
g_warning ("Error while sending data, continuing anyway: %s", err->message);
|
||||
g_propagate_error (error, err);
|
||||
}
|
||||
g_assert(r == 0);
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (transferred < length)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************** OUT MESSAGES GENERATION ***************************/
|
||||
|
||||
static guint8 *
|
||||
vfs301_proto_generate_0B (int subtype, gssize *len)
|
||||
static void vfs301_proto_generate_0B(int subtype, unsigned char *data, int *len)
|
||||
{
|
||||
guint8 *res = g_malloc0 (39);
|
||||
guint8 *data = res;
|
||||
|
||||
*data = 0x0B;
|
||||
*len = 1;
|
||||
data++;
|
||||
|
||||
memset(data, 0, 39);
|
||||
*len += 38;
|
||||
|
||||
data[20] = subtype;
|
||||
|
||||
switch (subtype)
|
||||
{
|
||||
switch (subtype) {
|
||||
case 0x04:
|
||||
data[34] = 0x9F;
|
||||
break;
|
||||
|
||||
case 0x05:
|
||||
data[34] = 0xAB;
|
||||
/* NOTE: There was a len++ here, which could never do anything */
|
||||
len++;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#define HEX_TO_INT(c) \
|
||||
(((c) >= '0' && (c) <= '9') ? ((c) - '0') : ((c) - 'A' + 10))
|
||||
|
||||
static guint8 *
|
||||
translate_str (const char **srcL, gssize *len)
|
||||
static void translate_str(const char **srcL, unsigned char *data, int *len)
|
||||
{
|
||||
guint8 *res = NULL;
|
||||
guint8 *dst;
|
||||
const char **src_pos;
|
||||
const char *src;
|
||||
gssize src_len = 0;
|
||||
unsigned char *dataOrig = data;
|
||||
|
||||
for (src_pos = srcL; *src_pos; src_pos++)
|
||||
{
|
||||
gint tmp;
|
||||
while (*srcL != NULL) {
|
||||
src = *srcL;
|
||||
while (*src != '\0') {
|
||||
g_assert(*src != '\0');
|
||||
g_assert(*(src +1) != '\0');
|
||||
*data = (unsigned char)((HEX_TO_INT(*src) << 4) | (HEX_TO_INT(*(src + 1))));
|
||||
|
||||
src = *src_pos;
|
||||
tmp = strlen (src);
|
||||
g_assert (tmp % 2 == 0);
|
||||
src_len += tmp;
|
||||
data++;
|
||||
src += 2;
|
||||
}
|
||||
|
||||
*len = src_len / 2;
|
||||
res = g_malloc0 (*len);
|
||||
dst = res;
|
||||
|
||||
for (src_pos = srcL; *src_pos; src_pos++)
|
||||
for (src = *src_pos; *src; src += 2, dst += 1)
|
||||
*dst = (guint8) ((HEX_TO_INT (src[0]) << 4) | (HEX_TO_INT (src[1])));
|
||||
|
||||
return res;
|
||||
srcL++;
|
||||
}
|
||||
|
||||
static guint8 *
|
||||
vfs301_proto_generate (int type, int subtype, gssize *len)
|
||||
{
|
||||
switch (type)
|
||||
*len = data - dataOrig;
|
||||
}
|
||||
|
||||
static void vfs301_proto_generate(int type, int subtype, unsigned char *data, int *len)
|
||||
{
|
||||
switch (type) {
|
||||
case 0x01:
|
||||
case 0x04:
|
||||
/* After cmd 0x04 is sent, a data is received on VALIDITY_RECEIVE_ENDPOINT_CTRL.
|
||||
@@ -205,18 +173,12 @@ vfs301_proto_generate (int type, int subtype, gssize *len)
|
||||
case 0x17:
|
||||
case 0x19:
|
||||
case 0x1A:
|
||||
{
|
||||
guint8 *data = g_malloc0 (1);
|
||||
*data = type;
|
||||
*len = 1;
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0B:
|
||||
return vfs301_proto_generate_0B (subtype, len);
|
||||
vfs301_proto_generate_0B(subtype, data, len);
|
||||
break;
|
||||
|
||||
case 0x02D0:
|
||||
{
|
||||
const char **dataLs[] = {
|
||||
@@ -228,93 +190,76 @@ vfs301_proto_generate (int type, int subtype, gssize *len)
|
||||
vfs301_02D0_06,
|
||||
vfs301_02D0_07,
|
||||
};
|
||||
g_assert ((int) subtype <= G_N_ELEMENTS (dataLs));
|
||||
return translate_str (dataLs[subtype - 1], len);
|
||||
g_assert((int)subtype <= (int)(sizeof(dataLs) / sizeof(dataLs[0])));
|
||||
translate_str(dataLs[subtype - 1], data, len);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0220:
|
||||
switch (subtype)
|
||||
{
|
||||
switch (subtype) {
|
||||
case 1:
|
||||
return translate_str (vfs301_0220_01, len);
|
||||
translate_str(vfs301_0220_01, data, len);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
return translate_str (vfs301_0220_02, len);
|
||||
translate_str(vfs301_0220_02, data, len);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
return translate_str (vfs301_0220_03, len);
|
||||
translate_str(vfs301_0220_03, data, len);
|
||||
break;
|
||||
|
||||
case 0xFA00:
|
||||
case 0x2C01:
|
||||
case 0x5E01: {
|
||||
guint8 *data;
|
||||
guint8 *field;
|
||||
case 0x5E01:
|
||||
translate_str(vfs301_next_scan_template, data, len);
|
||||
unsigned char *field = data + *len - (sizeof(S4_TAIL) - 1) / 2 - 4;
|
||||
|
||||
data = translate_str (vfs301_next_scan_template, len);
|
||||
field = data + *len - (sizeof (S4_TAIL) - 1) / 2 - 4;
|
||||
g_assert(*field == 0xDE);
|
||||
g_assert(*(field + 1) == 0xAD);
|
||||
g_assert(*(field + 2) == 0xDE);
|
||||
g_assert(*(field + 3) == 0xAD);
|
||||
|
||||
g_assert (field >= data && field < data + *len);
|
||||
g_assert (field[0] == 0xDE);
|
||||
g_assert (field[1] == 0xAD);
|
||||
g_assert (field[2] == 0xDE);
|
||||
g_assert (field[3] == 0xAD);
|
||||
|
||||
field[0] = (guint8) ((subtype >> 8) & 0xFF);
|
||||
field[1] = (guint8) (subtype & 0xFF);
|
||||
field[2] = field[0];
|
||||
field[3] = field[1];
|
||||
|
||||
return data;
|
||||
*field = (unsigned char)((subtype >> 8) & 0xFF);
|
||||
*(field + 1) = (unsigned char)(subtype & 0xFF);
|
||||
*(field + 2) = *field;
|
||||
*(field + 3) = *(field + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
g_assert(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
g_assert_not_reached();
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
break;
|
||||
}
|
||||
|
||||
g_assert_not_reached ();
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/************************** SCAN IMAGE PROCESSING *****************************/
|
||||
|
||||
#ifdef SCAN_FINISH_DETECTION
|
||||
static int
|
||||
img_is_finished_scan (fp_line_t *lines, int no_lines)
|
||||
static int img_is_finished_scan(fp_line_t *lines, int no_lines)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int rv = 1;
|
||||
|
||||
for (i = no_lines - VFS301_FP_SUM_LINES; i < no_lines; i++)
|
||||
{
|
||||
for (i = no_lines - VFS301_FP_SUM_LINES; i < no_lines; i++) {
|
||||
/* check the line for fingerprint data */
|
||||
for (j = 0; j < sizeof (lines[i].sum2); j++)
|
||||
for (j = 0; j < sizeof(lines[i].sum2); j++) {
|
||||
if (lines[i].sum2[j] > (VFS301_FP_SUM_MEDIAN + VFS301_FP_SUM_EMPTY_RANGE))
|
||||
rv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
scanline_diff (const guint8 *scanlines, int prev, int cur)
|
||||
static int scanline_diff(const unsigned char *scanlines, int prev, int cur)
|
||||
{
|
||||
const guint8 *line1 = scanlines + prev * VFS301_FP_OUTPUT_WIDTH;
|
||||
const guint8 *line2 = scanlines + cur * VFS301_FP_OUTPUT_WIDTH;
|
||||
const unsigned char *line1 = scanlines + prev * VFS301_FP_OUTPUT_WIDTH;
|
||||
const unsigned char *line2 = scanlines + cur * VFS301_FP_OUTPUT_WIDTH;
|
||||
int i;
|
||||
int diff;
|
||||
|
||||
@@ -326,8 +271,7 @@ scanline_diff (const guint8 *scanlines, int prev, int cur)
|
||||
|
||||
/* TODO: This doesn't work too well when there are parallel lines in the
|
||||
* fingerprint. */
|
||||
for (diff = 0, i = 0; i < VFS301_FP_WIDTH; i++)
|
||||
{
|
||||
for (diff = 0, i = 0; i < VFS301_FP_WIDTH; i++) {
|
||||
if (*line1 > *line2)
|
||||
diff += *line1 - *line2;
|
||||
else
|
||||
@@ -337,15 +281,15 @@ scanline_diff (const guint8 *scanlines, int prev, int cur)
|
||||
line2++;
|
||||
}
|
||||
|
||||
return (diff / VFS301_FP_WIDTH) > VFS301_FP_LINE_DIFF_THRESHOLD;
|
||||
return ((diff / VFS301_FP_WIDTH) > VFS301_FP_LINE_DIFF_THRESHOLD);
|
||||
}
|
||||
|
||||
/** Transform the input data to a normalized fingerprint scan */
|
||||
void
|
||||
vfs301_extract_image (FpDeviceVfs301 *vfs, guint8 *output, int *output_height
|
||||
void vfs301_extract_image(
|
||||
vfs301_dev_t *vfs, unsigned char *output, int *output_height
|
||||
)
|
||||
{
|
||||
const guint8 *scanlines = vfs->scanline_buf;
|
||||
const unsigned char *scanlines = vfs->scanline_buf;
|
||||
int last_line;
|
||||
int i;
|
||||
|
||||
@@ -361,10 +305,8 @@ vfs301_extract_image (FpDeviceVfs301 *vfs, guint8 *output, int *output_height
|
||||
* of bi/tri-linear resampling to get the output (so that we don't get so
|
||||
* many false edges etc.).
|
||||
*/
|
||||
for (i = 1; i < vfs->scanline_count; i++)
|
||||
{
|
||||
if (scanline_diff (scanlines, last_line, i))
|
||||
{
|
||||
for (i = 1; i < vfs->scanline_count; i++) {
|
||||
if (scanline_diff(scanlines, last_line, i)) {
|
||||
memcpy(
|
||||
output + VFS301_FP_OUTPUT_WIDTH * (*output_height),
|
||||
scanlines + VFS301_FP_OUTPUT_WIDTH * i,
|
||||
@@ -376,38 +318,35 @@ vfs301_extract_image (FpDeviceVfs301 *vfs, guint8 *output, int *output_height
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
img_process_data (int first_block, FpDeviceVfs301 *dev, const guint8 *buf, int len)
|
||||
static int img_process_data(
|
||||
int first_block, vfs301_dev_t *dev, const unsigned char *buf, int len
|
||||
)
|
||||
{
|
||||
vfs301_line_t *lines = (vfs301_line_t*)buf;
|
||||
int no_lines = len / sizeof(vfs301_line_t);
|
||||
int i;
|
||||
/*int no_nonempty;*/
|
||||
guint8 *cur_line;
|
||||
unsigned char *cur_line;
|
||||
int last_img_height;
|
||||
|
||||
#ifdef SCAN_FINISH_DETECTION
|
||||
int finished_scan;
|
||||
#endif
|
||||
|
||||
if (first_block)
|
||||
{
|
||||
if (first_block) {
|
||||
last_img_height = 0;
|
||||
dev->scanline_count = no_lines;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
last_img_height = dev->scanline_count;
|
||||
dev->scanline_count += no_lines;
|
||||
}
|
||||
|
||||
dev->scanline_buf = g_realloc (dev->scanline_buf, dev->scanline_count * VFS301_FP_OUTPUT_WIDTH);
|
||||
dev->scanline_buf = realloc(dev->scanline_buf, dev->scanline_count * VFS301_FP_OUTPUT_WIDTH);
|
||||
g_assert(dev->scanline_buf != NULL);
|
||||
|
||||
for (cur_line = dev->scanline_buf + last_img_height * VFS301_FP_OUTPUT_WIDTH, i = 0;
|
||||
i < no_lines;
|
||||
i++, cur_line += VFS301_FP_OUTPUT_WIDTH
|
||||
)
|
||||
{
|
||||
) {
|
||||
#ifndef OUTPUT_RAW
|
||||
memcpy(cur_line, lines[i].scan, VFS301_FP_OUTPUT_WIDTH);
|
||||
#else
|
||||
@@ -426,127 +365,115 @@ img_process_data (int first_block, FpDeviceVfs301 *dev, const guint8 *buf, int l
|
||||
|
||||
/************************** PROTOCOL STUFF ************************************/
|
||||
|
||||
static unsigned char usb_send_buf[0x2000];
|
||||
|
||||
#define USB_RECV(from, len) \
|
||||
usb_recv (dev, from, len, NULL, NULL)
|
||||
usb_recv(dev, devh, from, len)
|
||||
|
||||
#define USB_SEND(type, subtype) \
|
||||
{ \
|
||||
const guint8 *data; \
|
||||
gssize len; \
|
||||
data = vfs301_proto_generate (type, subtype, &len); \
|
||||
usb_send (dev, data, len, NULL); \
|
||||
int len; \
|
||||
vfs301_proto_generate(type, subtype, usb_send_buf, &len); \
|
||||
usb_send(devh, usb_send_buf, len); \
|
||||
}
|
||||
|
||||
#define RAW_DATA(x) x, sizeof(x)
|
||||
|
||||
#define IS_VFS301_FP_SEQ_START(b) ((b[0] == 0x01) && (b[1] == 0xfe))
|
||||
|
||||
static int
|
||||
vfs301_proto_process_data (FpDeviceVfs301 *dev, int first_block, const guint8 *buf, gint len)
|
||||
static int vfs301_proto_process_data(int first_block, vfs301_dev_t *dev)
|
||||
{
|
||||
int i;
|
||||
const unsigned char *buf = dev->recv_buf;
|
||||
int len = dev->recv_len;
|
||||
|
||||
if (first_block)
|
||||
{
|
||||
if (first_block) {
|
||||
g_assert(len >= VFS301_FP_FRAME_SIZE);
|
||||
|
||||
/* Skip bytes until start_sequence is found */
|
||||
for (i = 0; i < VFS301_FP_FRAME_SIZE; i++, buf++, len--)
|
||||
for (i = 0; i < VFS301_FP_FRAME_SIZE; i++, buf++, len--) {
|
||||
if (IS_VFS301_FP_SEQ_START(buf))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return img_process_data(first_block, dev, buf, len);
|
||||
}
|
||||
|
||||
void
|
||||
vfs301_proto_request_fingerprint (FpDeviceVfs301 *dev)
|
||||
void vfs301_proto_request_fingerprint(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev)
|
||||
{
|
||||
USB_SEND(0x0220, 0xFA00);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 000000000000 */
|
||||
}
|
||||
|
||||
int
|
||||
vfs301_proto_peek_event (FpDeviceVfs301 *dev)
|
||||
int vfs301_proto_peek_event(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpiUsbTransfer *transfer;
|
||||
|
||||
const char no_event[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
const char got_event[] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
USB_SEND(0x17, -1);
|
||||
usb_recv (dev, VFS301_RECEIVE_ENDPOINT_CTRL, 7, &transfer, &error);
|
||||
g_assert(USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 7) == 0);
|
||||
|
||||
/* XXX: This is obviously not a sane error handling! */
|
||||
g_assert (!error);
|
||||
|
||||
if (memcmp (transfer->buffer, no_event, sizeof (no_event)) == 0)
|
||||
if (memcmp(dev->recv_buf, no_event, sizeof(no_event)) == 0) {
|
||||
return 0;
|
||||
else if (memcmp (transfer->buffer, got_event, sizeof (no_event)) == 0)
|
||||
} else if (memcmp(dev->recv_buf, got_event, sizeof(no_event)) == 0) {
|
||||
return 1;
|
||||
else
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX: We sometimes need to receive data on from two endpoints at the same
|
||||
* time. However, as this driver is currently all synchronous (yikes),
|
||||
* we will run into timeouts randomly and need to then try again.
|
||||
*/
|
||||
#define PARALLEL_RECEIVE(e1, l1, e2, l2) \
|
||||
#define VARIABLE_ORDER(a, b) \
|
||||
{ \
|
||||
g_autoptr(GError) error = NULL; \
|
||||
usb_recv (dev, e1, l1, NULL, &error); \
|
||||
usb_recv (dev, e2, l2, NULL, NULL); \
|
||||
if (g_error_matches (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_TIMED_OUT)) \
|
||||
usb_recv (dev, e1, l1, NULL, NULL); \
|
||||
int _rv = a;\
|
||||
b; \
|
||||
if (_rv == -7) \
|
||||
a; \
|
||||
}
|
||||
|
||||
static void
|
||||
vfs301_proto_process_event_cb (FpiUsbTransfer *transfer,
|
||||
FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void vfs301_proto_process_event_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpDeviceVfs301 *dev = user_data;
|
||||
vfs301_dev_t *dev = transfer->user_data;
|
||||
struct libusb_device_handle *devh = transfer->dev_handle;
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Error receiving data: %s", error->message);
|
||||
g_error_free (error);
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
dev->recv_progress = VFS301_FAILURE;
|
||||
return;
|
||||
}
|
||||
else if (transfer->actual_length < transfer->length)
|
||||
{
|
||||
goto end;
|
||||
} else if (transfer->actual_length < dev->recv_exp_amt) {
|
||||
/* TODO: process the data anyway? */
|
||||
dev->recv_progress = VFS301_ENDED;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
FpiUsbTransfer *new;
|
||||
if (!vfs301_proto_process_data (dev,
|
||||
transfer->length == VFS301_FP_RECV_LEN_1,
|
||||
transfer->buffer,
|
||||
transfer->actual_length))
|
||||
{
|
||||
goto end;
|
||||
} else {
|
||||
dev->recv_len = transfer->actual_length;
|
||||
if (!vfs301_proto_process_data(dev->recv_exp_amt == VFS301_FP_RECV_LEN_1, dev)) {
|
||||
dev->recv_progress = VFS301_ENDED;
|
||||
goto end;
|
||||
}
|
||||
|
||||
dev->recv_exp_amt = VFS301_FP_RECV_LEN_2;
|
||||
libusb_fill_bulk_transfer(
|
||||
transfer, devh, VFS301_RECEIVE_ENDPOINT_DATA,
|
||||
dev->recv_buf, dev->recv_exp_amt,
|
||||
vfs301_proto_process_event_cb, dev, VFS301_FP_RECV_TIMEOUT);
|
||||
|
||||
if (libusb_submit_transfer(transfer) < 0) {
|
||||
printf("cb::continue fail\n");
|
||||
dev->recv_progress = VFS301_FAILURE;
|
||||
goto end;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
new = fpi_usb_transfer_new (device);
|
||||
|
||||
fpi_usb_transfer_fill_bulk (new, VFS301_RECEIVE_ENDPOINT_DATA, VFS301_FP_RECV_LEN_2);
|
||||
fpi_usb_transfer_submit (new, VFS301_FP_RECV_TIMEOUT, NULL,
|
||||
vfs301_proto_process_event_cb, NULL);
|
||||
return;
|
||||
}
|
||||
end:
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
void
|
||||
vfs301_proto_process_event_start (FpDeviceVfs301 *dev)
|
||||
void vfs301_proto_process_event_start(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
struct libusb_transfer *transfer;
|
||||
|
||||
/*
|
||||
* Notes:
|
||||
@@ -572,16 +499,24 @@ vfs301_proto_process_event_start (FpDeviceVfs301 *dev)
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 64);
|
||||
|
||||
/* now read the fingerprint data, while there are some */
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (dev));
|
||||
transfer = fpi_usb_alloc();
|
||||
dev->recv_progress = VFS301_ONGOING;
|
||||
dev->recv_exp_amt = VFS301_FP_RECV_LEN_1;
|
||||
|
||||
fpi_usb_transfer_fill_bulk (transfer, VFS301_RECEIVE_ENDPOINT_DATA, VFS301_FP_RECV_LEN_1);
|
||||
fpi_usb_transfer_submit (transfer, VFS301_FP_RECV_TIMEOUT, NULL,
|
||||
vfs301_proto_process_event_cb, NULL);
|
||||
libusb_fill_bulk_transfer(
|
||||
transfer, devh, VFS301_RECEIVE_ENDPOINT_DATA,
|
||||
dev->recv_buf, dev->recv_exp_amt,
|
||||
vfs301_proto_process_event_cb, dev, VFS301_FP_RECV_TIMEOUT);
|
||||
|
||||
if (libusb_submit_transfer(transfer) < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
dev->recv_progress = VFS301_FAILURE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
vfs301_proto_process_event_poll (FpDeviceVfs301 *dev)
|
||||
int /* vfs301_dev_t::recv_progress */ vfs301_proto_process_event_poll(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev)
|
||||
{
|
||||
if (dev->recv_progress != VFS301_ENDED)
|
||||
return dev->recv_progress;
|
||||
@@ -591,22 +526,21 @@ vfs301_proto_process_event_poll (FpDeviceVfs301 *dev)
|
||||
USB_SEND(0x04, -1);
|
||||
/* the following may come in random order, data may not come at all, don't
|
||||
* try for too long... */
|
||||
PARALLEL_RECEIVE (
|
||||
VFS301_RECEIVE_ENDPOINT_CTRL, 2, /* 1204 */
|
||||
VFS301_RECEIVE_ENDPOINT_DATA, 16384
|
||||
VARIABLE_ORDER(
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2), /* 1204 */
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 16384)
|
||||
);
|
||||
|
||||
USB_SEND(0x0220, 2);
|
||||
PARALLEL_RECEIVE (
|
||||
VFS301_RECEIVE_ENDPOINT_DATA, 5760, /* seems to always come */
|
||||
VFS301_RECEIVE_ENDPOINT_CTRL, 2 /* 0000 */
|
||||
VARIABLE_ORDER(
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 5760), /* seems to always come */
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2) /* 0000 */
|
||||
);
|
||||
|
||||
return dev->recv_progress;
|
||||
}
|
||||
|
||||
void
|
||||
vfs301_proto_init (FpDeviceVfs301 *dev)
|
||||
void vfs301_proto_init(struct libusb_device_handle *devh, vfs301_dev_t *dev)
|
||||
{
|
||||
USB_SEND(0x01, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 38);
|
||||
@@ -617,14 +551,14 @@ vfs301_proto_init (FpDeviceVfs301 *dev)
|
||||
USB_SEND(0x19, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 64);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 4); /* 6BB4D0BC */
|
||||
usb_send (dev, RAW_DATA (vfs301_06_1), NULL);
|
||||
usb_send(devh, RAW_DATA(vfs301_06_1));
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
|
||||
USB_SEND(0x01, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 38);
|
||||
USB_SEND(0x1A, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
usb_send (dev, RAW_DATA (vfs301_06_2), NULL);
|
||||
usb_send(devh, RAW_DATA(vfs301_06_2));
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
USB_SEND(0x0220, 1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
@@ -633,7 +567,7 @@ vfs301_proto_init (FpDeviceVfs301 *dev)
|
||||
|
||||
USB_SEND(0x1A, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
usb_send (dev, RAW_DATA (vfs301_06_3), NULL);
|
||||
usb_send(devh, RAW_DATA(vfs301_06_3));
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
|
||||
USB_SEND(0x01, -1);
|
||||
@@ -659,29 +593,29 @@ vfs301_proto_init (FpDeviceVfs301 *dev)
|
||||
USB_SEND(0x02D0, 7);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 832);
|
||||
usb_send (dev, RAW_DATA (vfs301_12), NULL);
|
||||
usb_send(devh, RAW_DATA(vfs301_12));
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
|
||||
USB_SEND(0x1A, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
usb_send (dev, RAW_DATA (vfs301_06_2), NULL);
|
||||
usb_send(devh, RAW_DATA(vfs301_06_2));
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
USB_SEND(0x0220, 2);
|
||||
PARALLEL_RECEIVE (
|
||||
VFS301_RECEIVE_ENDPOINT_CTRL, 2, /* 0000 */
|
||||
VFS301_RECEIVE_ENDPOINT_DATA, 5760
|
||||
VARIABLE_ORDER(
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2), /* 0000 */
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 5760)
|
||||
);
|
||||
|
||||
USB_SEND(0x1A, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
usb_send (dev, RAW_DATA (vfs301_06_1), NULL);
|
||||
usb_send(devh, RAW_DATA(vfs301_06_1));
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
|
||||
USB_SEND(0x1A, -1);
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
usb_send (dev, RAW_DATA (vfs301_06_4), NULL);
|
||||
usb_send(devh, RAW_DATA(vfs301_06_4));
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
usb_send (dev, RAW_DATA (vfs301_24), NULL); /* turns on white */
|
||||
usb_send(devh, RAW_DATA(vfs301_24)); /* turns on white */
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_CTRL, 2); /* 0000 */
|
||||
|
||||
USB_SEND(0x01, -1);
|
||||
@@ -692,7 +626,6 @@ vfs301_proto_init (FpDeviceVfs301 *dev)
|
||||
USB_RECV(VFS301_RECEIVE_ENDPOINT_DATA, 5760);
|
||||
}
|
||||
|
||||
void
|
||||
vfs301_proto_deinit (FpDeviceVfs301 *dev)
|
||||
void vfs301_proto_deinit(struct libusb_device_handle *devh, vfs301_dev_t *dev)
|
||||
{
|
||||
}
|
||||
|
||||
137
libfprint/drivers/vfs301_proto.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* vfs301/vfs300 fingerprint reader driver
|
||||
* https://github.com/andree182/vfs301
|
||||
*
|
||||
* Copyright (c) 2011-2012 Andrej Krutak <dev@andree.sk>
|
||||
*
|
||||
* 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 <libusb-1.0/libusb.h>
|
||||
|
||||
enum {
|
||||
VFS301_DEFAULT_WAIT_TIMEOUT = 300,
|
||||
|
||||
VFS301_SEND_ENDPOINT = 0x01,
|
||||
VFS301_RECEIVE_ENDPOINT_CTRL = 0x81,
|
||||
VFS301_RECEIVE_ENDPOINT_DATA = 0x82
|
||||
};
|
||||
|
||||
#define VFS301_FP_RECV_LEN_1 (84032)
|
||||
#define VFS301_FP_RECV_LEN_2 (84096)
|
||||
|
||||
typedef struct {
|
||||
/* buffer for received data */
|
||||
unsigned char recv_buf[0x20000];
|
||||
int recv_len;
|
||||
|
||||
/* buffer to hold raw scanlines */
|
||||
unsigned char *scanline_buf;
|
||||
int scanline_count;
|
||||
|
||||
enum {
|
||||
VFS301_ONGOING = 0,
|
||||
VFS301_ENDED = 1,
|
||||
VFS301_FAILURE = -1
|
||||
} recv_progress;
|
||||
int recv_exp_amt;
|
||||
} vfs301_dev_t;
|
||||
|
||||
enum {
|
||||
/* Width of the scanned data in px */
|
||||
VFS301_FP_WIDTH = 200,
|
||||
|
||||
/* sizeof(fp_line_t) */
|
||||
VFS301_FP_FRAME_SIZE = 288,
|
||||
/* Width of output line */
|
||||
#ifndef OUTPUT_RAW
|
||||
VFS301_FP_OUTPUT_WIDTH = VFS301_FP_WIDTH,
|
||||
#else
|
||||
VFS301_FP_OUTPUT_WIDTH = VFS301_FP_FRAME_SIZE,
|
||||
#endif
|
||||
|
||||
VFS301_FP_SUM_LINES = 3,
|
||||
|
||||
#ifdef SCAN_FINISH_DETECTION
|
||||
/* TODO: The following changes (seen ~60 and ~80) In that
|
||||
* case we'll need to calibrate this from empty data somehow... */
|
||||
VFS301_FP_SUM_MEDIAN = 60,
|
||||
VFS301_FP_SUM_EMPTY_RANGE = 5,
|
||||
#endif
|
||||
|
||||
/* Minimum average difference between returned lines */
|
||||
VFS301_FP_LINE_DIFF_THRESHOLD = 15,
|
||||
|
||||
/* Maximum waiting time for a single fingerprint frame */
|
||||
VFS301_FP_RECV_TIMEOUT = 2000
|
||||
};
|
||||
|
||||
/* Arrays of this structure is returned during the initialization as a response
|
||||
* to the 0x02D0 messages.
|
||||
* It seems to be always the same - what is it for? Some kind of confirmation?
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned char sync_0x01;
|
||||
unsigned char sync_0xfe;
|
||||
|
||||
unsigned char counter_lo;
|
||||
unsigned char counter_hi; /* FIXME ? */
|
||||
|
||||
unsigned char flags[3];
|
||||
|
||||
unsigned char sync_0x00;
|
||||
|
||||
unsigned char scan[VFS301_FP_WIDTH];
|
||||
} vfs301_init_line_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char sync_0x01;
|
||||
unsigned char sync_0xfe;
|
||||
|
||||
unsigned char counter_lo;
|
||||
unsigned char counter_hi;
|
||||
|
||||
unsigned char sync_0x08[2]; /* XXX: always? 0x08 0x08 */
|
||||
/* 0x08 | 0x18 - Looks like 0x08 marks good quality lines */
|
||||
unsigned char flag_1;
|
||||
unsigned char sync_0x00;
|
||||
|
||||
unsigned char scan[VFS301_FP_WIDTH];
|
||||
|
||||
/* A offseted, stretched, inverted copy of scan... probably could
|
||||
* serve finger motion speed detection?
|
||||
* Seems to be subdivided to some 10B + 53B + 1B blocks */
|
||||
unsigned char mirror[64];
|
||||
|
||||
/* Some kind of sum of the scan, very low contrast */
|
||||
unsigned char sum1[2];
|
||||
unsigned char sum2[11];
|
||||
unsigned char sum3[3];
|
||||
} vfs301_line_t;
|
||||
|
||||
void vfs301_proto_init(struct libusb_device_handle *devh, vfs301_dev_t *dev);
|
||||
void vfs301_proto_deinit(struct libusb_device_handle *devh, vfs301_dev_t *dev);
|
||||
|
||||
void vfs301_proto_request_fingerprint(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev);
|
||||
|
||||
/** returns 0 if no event is ready, or 1 if there is one... */
|
||||
int vfs301_proto_peek_event(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev);
|
||||
void vfs301_proto_process_event_start(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev);
|
||||
int vfs301_proto_process_event_poll(
|
||||
struct libusb_device_handle *devh, vfs301_dev_t *dev);
|
||||
|
||||
void vfs301_extract_image(vfs301_dev_t *vfs, unsigned char *output, int *output_height);
|
||||
@@ -1147,7 +1147,7 @@ static const unsigned char vfs301_24[] = { /* 119 B */
|
||||
*
|
||||
* The contents of PACKET() inside this blob seems to be some kind
|
||||
* of a micro-program, which specifies which columns contain what. LE seems
|
||||
* to be used also here. Not necessarily is 1 output column described
|
||||
* to be used also here. Not neccessarily is 1 output column described
|
||||
* by 1 operation. For example the vfs301_line_t::sum section seems
|
||||
* to perform 2 operations for each column - probably some kind of diff between
|
||||
* input lines?
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "vfs5011"
|
||||
|
||||
#include "drivers_api.h"
|
||||
#include "vfs5011_proto.h"
|
||||
|
||||
@@ -30,8 +28,7 @@ enum {
|
||||
ACTION_RECEIVE,
|
||||
};
|
||||
|
||||
struct usb_action
|
||||
{
|
||||
struct usb_action {
|
||||
int type;
|
||||
const char *name;
|
||||
int endpoint;
|
||||
@@ -66,162 +63,192 @@ struct usb_action
|
||||
.correct_reply_size = sizeof(EXPECTED) \
|
||||
},
|
||||
|
||||
struct usbexchange_data
|
||||
{
|
||||
struct usbexchange_data {
|
||||
int stepcount;
|
||||
FpImageDevice *device;
|
||||
struct fp_img_dev *device;
|
||||
struct usb_action *actions;
|
||||
void *receive_buf;
|
||||
int timeout;
|
||||
};
|
||||
|
||||
static void start_scan (FpImageDevice *dev);
|
||||
static void start_scan(struct fp_img_dev *dev);
|
||||
|
||||
static void
|
||||
async_send_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void async_send_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
struct usbexchange_data *data = fpi_ssm_get_data (transfer->ssm);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct usbexchange_data *data = fpi_ssm_get_user_data(ssm);
|
||||
struct usb_action *action;
|
||||
|
||||
g_assert (!(fpi_ssm_get_cur_state (transfer->ssm) >= data->stepcount));
|
||||
if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) {
|
||||
fp_err("Radiation detected!");
|
||||
fpi_imgdev_session_error(data->device, -EINVAL);
|
||||
fpi_ssm_mark_failed(ssm, -EINVAL);
|
||||
goto out;
|
||||
}
|
||||
|
||||
action = &data->actions[fpi_ssm_get_cur_state (transfer->ssm)];
|
||||
g_assert (!(action->type != ACTION_SEND));
|
||||
action = &data->actions[fpi_ssm_get_cur_state(ssm)];
|
||||
if (action->type != ACTION_SEND) {
|
||||
fp_err("Radiation detected!");
|
||||
fpi_imgdev_session_error(data->device, -EINVAL);
|
||||
fpi_ssm_mark_failed(ssm, -EINVAL);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
/* Transfer not completed, return IO error */
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
return;
|
||||
fp_err("transfer not completed, status = %d", transfer->status);
|
||||
fpi_imgdev_session_error(data->device, -EIO);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
}
|
||||
if (transfer->length != transfer->actual_length) {
|
||||
/* Data sended mismatch with expected, return protocol error */
|
||||
fp_err("length mismatch, got %d, expected %d",
|
||||
transfer->actual_length, transfer->length);
|
||||
fpi_imgdev_session_error(data->device, -EIO);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* success */
|
||||
fpi_ssm_next_state (transfer->ssm);
|
||||
fpi_ssm_next_state(ssm);
|
||||
|
||||
out:
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
async_recv_cb (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void async_recv_cb(struct libusb_transfer *transfer)
|
||||
{
|
||||
struct usbexchange_data *data = fpi_ssm_get_data (transfer->ssm);
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct usbexchange_data *data = fpi_ssm_get_user_data(ssm);
|
||||
struct usb_action *action;
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
/* Transfer not completed, return IO error */
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
return;
|
||||
fp_err("transfer not completed, status = %d", transfer->status);
|
||||
fpi_imgdev_session_error(data->device, -EIO);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
g_assert (!(fpi_ssm_get_cur_state (transfer->ssm) >= data->stepcount));
|
||||
if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) {
|
||||
fp_err("Radiation detected!");
|
||||
fpi_imgdev_session_error(data->device, -EINVAL);
|
||||
fpi_ssm_mark_failed(ssm, -EINVAL);
|
||||
goto out;
|
||||
}
|
||||
|
||||
action = &data->actions[fpi_ssm_get_cur_state (transfer->ssm)];
|
||||
g_assert (!(action->type != ACTION_RECEIVE));
|
||||
action = &data->actions[fpi_ssm_get_cur_state(ssm)];
|
||||
if (action->type != ACTION_RECEIVE) {
|
||||
fp_err("Radiation detected!");
|
||||
fpi_imgdev_session_error(data->device, -EINVAL);
|
||||
fpi_ssm_mark_failed(ssm, -EINVAL);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (action->data != NULL)
|
||||
{
|
||||
if (transfer->actual_length != action->correct_reply_size)
|
||||
{
|
||||
if (action->data != NULL) {
|
||||
if (transfer->actual_length != action->correct_reply_size) {
|
||||
fp_err("Got %d bytes instead of %d",
|
||||
(gint) transfer->actual_length,
|
||||
transfer->actual_length,
|
||||
action->correct_reply_size);
|
||||
fpi_ssm_mark_failed (transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
return;
|
||||
fpi_imgdev_session_error(data->device, -EIO);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
}
|
||||
if (memcmp(transfer->buffer, action->data,
|
||||
action->correct_reply_size) != 0)
|
||||
{
|
||||
action->correct_reply_size) != 0) {
|
||||
fp_dbg("Wrong reply:");
|
||||
fpi_ssm_mark_failed (transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
fpi_imgdev_session_error(data->device, -EIO);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
goto out;
|
||||
}
|
||||
} else
|
||||
fp_dbg("Got %d bytes out of %d", transfer->actual_length,
|
||||
transfer->length);
|
||||
|
||||
fpi_ssm_next_state(ssm);
|
||||
out:
|
||||
libusb_free_transfer(transfer);
|
||||
}
|
||||
|
||||
static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
struct usbexchange_data *data = user_data;
|
||||
if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) {
|
||||
fp_err("Bug detected: state %d out of range, only %d steps",
|
||||
fpi_ssm_get_cur_state(ssm), data->stepcount);
|
||||
fpi_imgdev_session_error(data->device, -EINVAL);
|
||||
fpi_ssm_mark_failed(ssm, -EINVAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fp_dbg ("Got %d bytes out of %d",
|
||||
(gint) transfer->actual_length,
|
||||
(gint) transfer->length);
|
||||
}
|
||||
|
||||
fpi_ssm_next_state (transfer->ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
usbexchange_loop (FpiSsm *ssm, FpDevice *_dev)
|
||||
{
|
||||
struct usbexchange_data *data = fpi_ssm_get_data (ssm);
|
||||
struct usb_action *action = &data->actions[fpi_ssm_get_cur_state(ssm)];
|
||||
FpiUsbTransfer *transfer;
|
||||
struct libusb_transfer *transfer;
|
||||
int ret = -EINVAL;
|
||||
|
||||
g_assert (fpi_ssm_get_cur_state (ssm) < data->stepcount);
|
||||
|
||||
switch (action->type)
|
||||
{
|
||||
switch (action->type) {
|
||||
case ACTION_SEND:
|
||||
fp_dbg("Sending %s", action->name);
|
||||
transfer = fpi_usb_transfer_new (_dev);
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, action->endpoint,
|
||||
action->data, action->size,
|
||||
NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit (transfer, data->timeout, NULL,
|
||||
async_send_cb, NULL);
|
||||
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,
|
||||
data->timeout);
|
||||
ret = libusb_submit_transfer(transfer);
|
||||
break;
|
||||
|
||||
case ACTION_RECEIVE:
|
||||
fp_dbg("Receiving %d bytes", action->size);
|
||||
transfer = fpi_usb_transfer_new (_dev);
|
||||
fpi_usb_transfer_fill_bulk_full (transfer, action->endpoint,
|
||||
data->receive_buf,
|
||||
action->size, NULL);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, data->timeout, NULL,
|
||||
async_recv_cb, NULL);
|
||||
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,
|
||||
data->timeout);
|
||||
ret = libusb_submit_transfer(transfer);
|
||||
break;
|
||||
|
||||
default:
|
||||
fp_err("Bug detected: invalid action %d", action->type);
|
||||
fpi_ssm_mark_failed (ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
fpi_imgdev_session_error(data->device, -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_failed(ssm, ret);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usb_exchange_async (FpiSsm *ssm,
|
||||
struct usbexchange_data *data,
|
||||
const char *exchange_name)
|
||||
static void usb_exchange_async(fpi_ssm *ssm,
|
||||
struct usbexchange_data *data)
|
||||
{
|
||||
FpiSsm *subsm = fpi_ssm_new_full (FP_DEVICE (data->device),
|
||||
fpi_ssm *subsm = fpi_ssm_new(FP_DEV(data->device),
|
||||
usbexchange_loop,
|
||||
data->stepcount,
|
||||
exchange_name);
|
||||
|
||||
fpi_ssm_set_data (subsm, data, NULL);
|
||||
data);
|
||||
fpi_ssm_start_subsm(ssm, subsm);
|
||||
}
|
||||
|
||||
/* ====================== utils ======================= */
|
||||
|
||||
/* Calculade squared standand deviation of sum of two lines */
|
||||
static int
|
||||
vfs5011_get_deviation2 (struct fpi_line_asmbl_ctx *ctx, GSList *row1, GSList *row2)
|
||||
static int vfs5011_get_deviation2(struct fpi_line_asmbl_ctx *ctx, GSList *row1, GSList *row2)
|
||||
{
|
||||
unsigned char *buf1, *buf2;
|
||||
int res = 0, mean = 0, i;
|
||||
const int size = 64;
|
||||
|
||||
buf1 = (unsigned char *) row1->data + 56;
|
||||
buf2 = (unsigned char *) row2->data + 168;
|
||||
buf1 = row1->data + 56;
|
||||
buf2 = row2->data + 168;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
mean += (int)buf1[i] + (int)buf2[i];
|
||||
|
||||
mean /= size;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
for (i = 0; i < size; i++) {
|
||||
int dev = (int)buf1[i] + (int)buf2[i] - mean;
|
||||
res += dev*dev;
|
||||
}
|
||||
@@ -229,12 +256,11 @@ vfs5011_get_deviation2 (struct fpi_line_asmbl_ctx *ctx, GSList *row1, GSList *ro
|
||||
return res / size;
|
||||
}
|
||||
|
||||
static unsigned char
|
||||
vfs5011_get_pixel (struct fpi_line_asmbl_ctx *ctx,
|
||||
static unsigned char vfs5011_get_pixel(struct fpi_line_asmbl_ctx *ctx,
|
||||
GSList *row,
|
||||
unsigned x)
|
||||
{
|
||||
unsigned char *data = (unsigned char *) row->data + 8;
|
||||
unsigned char *data = row->data + 8;
|
||||
|
||||
return data[x];
|
||||
}
|
||||
@@ -257,10 +283,7 @@ static struct fpi_line_asmbl_ctx assembling_ctx = {
|
||||
.get_pixel = vfs5011_get_pixel,
|
||||
};
|
||||
|
||||
struct _FpDeviceVfs5011
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
struct vfs5011_data {
|
||||
unsigned char *total_buffer;
|
||||
unsigned char *capture_buffer;
|
||||
unsigned char *row_buffer;
|
||||
@@ -272,12 +295,9 @@ struct _FpDeviceVfs5011
|
||||
gboolean loop_running;
|
||||
gboolean deactivating;
|
||||
struct usbexchange_data init_sequence;
|
||||
struct libusb_transfer *flying_transfer;
|
||||
};
|
||||
|
||||
G_DECLARE_FINAL_TYPE (FpDeviceVfs5011, fpi_device_vfs5011, FPI, DEVICE_VFS5011,
|
||||
FpImageDevice);
|
||||
G_DEFINE_TYPE (FpDeviceVfs5011, fpi_device_vfs5011, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
enum {
|
||||
DEV_ACTIVATE_REQUEST_FPRINT,
|
||||
DEV_ACTIVATE_INIT_COMPLETE,
|
||||
@@ -292,24 +312,22 @@ enum {
|
||||
DEV_OPEN_NUM_STATES
|
||||
};
|
||||
|
||||
static void
|
||||
capture_init (FpDeviceVfs5011 *self, int max_captured,
|
||||
static void capture_init(struct vfs5011_data *data, int max_captured,
|
||||
int max_recorded)
|
||||
{
|
||||
fp_dbg("capture_init");
|
||||
self->lastline = NULL;
|
||||
self->lines_captured = 0;
|
||||
self->lines_recorded = 0;
|
||||
self->empty_lines = 0;
|
||||
self->lines_total = 0;
|
||||
self->lines_total_allocated = 0;
|
||||
self->total_buffer = NULL;
|
||||
self->max_lines_captured = max_captured;
|
||||
self->max_lines_recorded = max_recorded;
|
||||
data->lastline = NULL;
|
||||
data->lines_captured = 0;
|
||||
data->lines_recorded = 0;
|
||||
data->empty_lines = 0;
|
||||
data->lines_total = 0;
|
||||
data->lines_total_allocated = 0;
|
||||
data->total_buffer = NULL;
|
||||
data->max_lines_captured = max_captured;
|
||||
data->max_lines_recorded = max_recorded;
|
||||
}
|
||||
|
||||
static int
|
||||
process_chunk (FpDeviceVfs5011 *self, int transferred)
|
||||
static int process_chunk(struct vfs5011_data *data, int transferred)
|
||||
{
|
||||
enum {
|
||||
DEVIATION_THRESHOLD = 15*15,
|
||||
@@ -321,52 +339,43 @@ process_chunk (FpDeviceVfs5011 *self, int transferred)
|
||||
int lines_captured = transferred/VFS5011_LINE_SIZE;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < lines_captured; i++)
|
||||
{
|
||||
unsigned char *linebuf = self->capture_buffer
|
||||
for (i = 0; i < lines_captured; i++) {
|
||||
unsigned char *linebuf = data->capture_buffer
|
||||
+ i * VFS5011_LINE_SIZE;
|
||||
|
||||
if (fpi_std_sq_dev(linebuf + 8, VFS5011_IMAGE_WIDTH)
|
||||
< DEVIATION_THRESHOLD)
|
||||
{
|
||||
if (self->lines_captured == 0)
|
||||
< DEVIATION_THRESHOLD) {
|
||||
if (data->lines_captured == 0)
|
||||
continue;
|
||||
else
|
||||
self->empty_lines++;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->empty_lines = 0;
|
||||
}
|
||||
if (self->empty_lines >= STOP_CHECK_LINES)
|
||||
{
|
||||
data->empty_lines++;
|
||||
} else
|
||||
data->empty_lines = 0;
|
||||
if (data->empty_lines >= STOP_CHECK_LINES) {
|
||||
fp_dbg("process_chunk: got %d empty lines, finishing",
|
||||
self->empty_lines);
|
||||
data->empty_lines);
|
||||
return 1;
|
||||
}
|
||||
|
||||
self->lines_captured++;
|
||||
if (self->lines_captured > self->max_lines_captured)
|
||||
{
|
||||
data->lines_captured++;
|
||||
if (data->lines_captured > data->max_lines_captured) {
|
||||
fp_dbg("process_chunk: captured %d lines, finishing",
|
||||
self->lines_captured);
|
||||
data->lines_captured);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((self->lastline == NULL) ||
|
||||
(fpi_mean_sq_diff_norm (self->lastline + 8,
|
||||
if ((data->lastline == NULL)
|
||||
|| (fpi_mean_sq_diff_norm(
|
||||
data->lastline + 8,
|
||||
linebuf + 8,
|
||||
VFS5011_IMAGE_WIDTH) >= DIFFERENCE_THRESHOLD))
|
||||
{
|
||||
self->lastline = g_malloc (VFS5011_LINE_SIZE);
|
||||
self->rows = g_slist_prepend (self->rows,
|
||||
self->lastline);
|
||||
memmove (self->lastline, linebuf, VFS5011_LINE_SIZE);
|
||||
self->lines_recorded++;
|
||||
if (self->lines_recorded >= self->max_lines_recorded)
|
||||
{
|
||||
VFS5011_IMAGE_WIDTH) >= DIFFERENCE_THRESHOLD)) {
|
||||
data->lastline = g_malloc(VFS5011_LINE_SIZE);
|
||||
data->rows = g_slist_prepend(data->rows, data->lastline);
|
||||
g_memmove(data->lastline, linebuf, VFS5011_LINE_SIZE);
|
||||
data->lines_recorded++;
|
||||
if (data->lines_recorded >= data->max_lines_recorded) {
|
||||
fp_dbg("process_chunk: recorded %d lines, finishing",
|
||||
self->lines_recorded);
|
||||
data->lines_recorded);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -375,97 +384,80 @@ process_chunk (FpDeviceVfs5011 *self, int transferred)
|
||||
}
|
||||
|
||||
static void
|
||||
submit_image (FpiSsm *ssm,
|
||||
FpDeviceVfs5011 *self,
|
||||
FpImageDevice *dev)
|
||||
submit_image(fpi_ssm *ssm,
|
||||
struct vfs5011_data *data,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
FpImage *img;
|
||||
struct fp_img *img;
|
||||
|
||||
if (self->lines_recorded == 0)
|
||||
{
|
||||
if (data->lines_recorded == 0) {
|
||||
/* == FP_ENROLL_RETRY_TOO_SHORT */
|
||||
fpi_image_device_retry_scan (dev, FP_DEVICE_RETRY_TOO_SHORT);
|
||||
fpi_imgdev_session_error(dev, FP_VERIFY_RETRY_TOO_SHORT);
|
||||
return;
|
||||
}
|
||||
|
||||
g_assert (self->rows != NULL);
|
||||
g_assert (data->rows != NULL);
|
||||
|
||||
self->rows = g_slist_reverse (self->rows);
|
||||
data->rows = g_slist_reverse(data->rows);
|
||||
|
||||
img = fpi_assemble_lines (&assembling_ctx, self->rows,
|
||||
self->lines_recorded);
|
||||
img = fpi_assemble_lines(&assembling_ctx, data->rows, data->lines_recorded);
|
||||
|
||||
g_slist_free_full (self->rows, g_free);
|
||||
self->rows = NULL;
|
||||
g_slist_free_full(data->rows, g_free);
|
||||
data->rows = NULL;
|
||||
|
||||
fp_dbg ("Image captured, committing");
|
||||
fp_dbg("Image captured, commiting");
|
||||
|
||||
fpi_image_device_image_captured (dev, img);
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
}
|
||||
|
||||
static void
|
||||
chunk_capture_callback (FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
static void chunk_capture_callback(struct libusb_transfer *transfer)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (device);
|
||||
FpDeviceVfs5011 *self;
|
||||
fpi_ssm *ssm = (fpi_ssm *)transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct vfs5011_data *data;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (dev);
|
||||
data = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
if (!error ||
|
||||
g_error_matches (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_TIMED_OUT))
|
||||
{
|
||||
if (error)
|
||||
g_error_free (error);
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) ||
|
||||
(transfer->status == LIBUSB_TRANSFER_TIMED_OUT)) {
|
||||
|
||||
if (transfer->actual_length > 0)
|
||||
fpi_image_device_report_finger_status (dev, TRUE);
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
|
||||
if (process_chunk (self, transfer->actual_length))
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
DEV_ACTIVATE_DATA_COMPLETE);
|
||||
if (process_chunk(data, transfer->actual_length))
|
||||
fpi_ssm_jump_to_state(ssm, DEV_ACTIVATE_DATA_COMPLETE);
|
||||
else
|
||||
fpi_ssm_jump_to_state (transfer->ssm,
|
||||
DEV_ACTIVATE_READ_DATA);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!self->deactivating)
|
||||
{
|
||||
fpi_ssm_jump_to_state(ssm, DEV_ACTIVATE_READ_DATA);
|
||||
} else {
|
||||
if (!data->deactivating) {
|
||||
fp_err("Failed to capture data");
|
||||
fpi_ssm_mark_failed (transfer->ssm, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_error_free (error);
|
||||
fpi_ssm_mark_completed (transfer->ssm);
|
||||
fpi_ssm_mark_failed(ssm, -1);
|
||||
} else {
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
}
|
||||
}
|
||||
libusb_free_transfer(transfer);
|
||||
data->flying_transfer = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
capture_chunk_async (FpDeviceVfs5011 *self,
|
||||
GUsbDevice *handle, int nline,
|
||||
int timeout, FpiSsm *ssm)
|
||||
static int capture_chunk_async(struct vfs5011_data *data,
|
||||
libusb_device_handle *handle, int nline,
|
||||
int timeout, fpi_ssm *ssm)
|
||||
{
|
||||
FpiUsbTransfer *transfer;
|
||||
|
||||
fp_dbg("capture_chunk_async: capture %d lines, already have %d",
|
||||
nline, self->lines_recorded);
|
||||
nline, data->lines_recorded);
|
||||
enum {
|
||||
DEVIATION_THRESHOLD = 15*15,
|
||||
DIFFERENCE_THRESHOLD = 600,
|
||||
STOP_CHECK_LINES = 50
|
||||
};
|
||||
|
||||
transfer = fpi_usb_transfer_new (FP_DEVICE (self));
|
||||
fpi_usb_transfer_fill_bulk_full (transfer,
|
||||
VFS5011_IN_ENDPOINT_DATA,
|
||||
self->capture_buffer,
|
||||
nline * VFS5011_LINE_SIZE, NULL);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit (transfer, timeout, fpi_device_get_cancellable (FP_DEVICE (self)),
|
||||
chunk_capture_callback, NULL);
|
||||
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,
|
||||
chunk_capture_callback, ssm, timeout);
|
||||
return libusb_submit_transfer(data->flying_transfer);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -656,248 +648,260 @@ struct usb_action vfs5011_initiate_capture[] = {
|
||||
|
||||
/* ====================== lifprint interface ======================= */
|
||||
|
||||
static void
|
||||
activate_loop (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
enum {READ_TIMEOUT = 0};
|
||||
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpDeviceVfs5011 *self;
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct vfs5011_data *data;
|
||||
int r;
|
||||
fpi_timeout *timeout;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (_dev);
|
||||
data = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
fp_dbg("main_loop: state %d", fpi_ssm_get_cur_state(ssm));
|
||||
|
||||
if (self->deactivating)
|
||||
{
|
||||
if (data->deactivating) {
|
||||
fp_dbg("deactivating, marking completed");
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case DEV_ACTIVATE_REQUEST_FPRINT:
|
||||
self->init_sequence.stepcount =
|
||||
data->init_sequence.stepcount =
|
||||
G_N_ELEMENTS(vfs5011_initiate_capture);
|
||||
self->init_sequence.actions = vfs5011_initiate_capture;
|
||||
self->init_sequence.device = dev;
|
||||
if (self->init_sequence.receive_buf == NULL)
|
||||
self->init_sequence.receive_buf =
|
||||
data->init_sequence.actions = vfs5011_initiate_capture;
|
||||
data->init_sequence.device = dev;
|
||||
if (data->init_sequence.receive_buf == NULL)
|
||||
data->init_sequence.receive_buf =
|
||||
g_malloc0(VFS5011_RECEIVE_BUF_SIZE);
|
||||
self->init_sequence.timeout = 1000;
|
||||
usb_exchange_async (ssm, &self->init_sequence, "ACTIVATE REQUEST");
|
||||
data->init_sequence.timeout = 1000;
|
||||
usb_exchange_async(ssm, &data->init_sequence);
|
||||
break;
|
||||
|
||||
case DEV_ACTIVATE_INIT_COMPLETE:
|
||||
if (self->init_sequence.receive_buf != NULL)
|
||||
g_free (self->init_sequence.receive_buf);
|
||||
self->init_sequence.receive_buf = NULL;
|
||||
capture_init (self, MAX_CAPTURE_LINES, MAXLINES);
|
||||
fpi_image_device_activate_complete (dev, NULL);
|
||||
if (data->init_sequence.receive_buf != NULL)
|
||||
g_free(data->init_sequence.receive_buf);
|
||||
data->init_sequence.receive_buf = NULL;
|
||||
capture_init(data, MAX_CAPTURE_LINES, MAXLINES);
|
||||
fpi_imgdev_activate_complete(dev, 0);
|
||||
fpi_ssm_next_state(ssm);
|
||||
break;
|
||||
|
||||
case DEV_ACTIVATE_READ_DATA:
|
||||
capture_chunk_async (self,
|
||||
fpi_device_get_usb_device (FP_DEVICE (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");
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
break;
|
||||
|
||||
case DEV_ACTIVATE_DATA_COMPLETE:
|
||||
fpi_ssm_next_state_delayed (ssm, 1, NULL);
|
||||
timeout = fpi_timeout_add(1, fpi_ssm_next_state_timeout_cb, _dev, ssm);
|
||||
|
||||
if (timeout == NULL) {
|
||||
/* Failed to add timeout */
|
||||
fp_err("failed to add timeout");
|
||||
fpi_imgdev_session_error(dev, -1);
|
||||
fpi_ssm_mark_failed(ssm, -1);
|
||||
}
|
||||
break;
|
||||
|
||||
case DEV_ACTIVATE_PREPARE_NEXT_CAPTURE:
|
||||
self->init_sequence.stepcount =
|
||||
data->init_sequence.stepcount =
|
||||
G_N_ELEMENTS(vfs5011_initiate_capture);
|
||||
self->init_sequence.actions = vfs5011_initiate_capture;
|
||||
self->init_sequence.device = dev;
|
||||
if (self->init_sequence.receive_buf == NULL)
|
||||
self->init_sequence.receive_buf =
|
||||
data->init_sequence.actions = vfs5011_initiate_capture;
|
||||
data->init_sequence.device = dev;
|
||||
if (data->init_sequence.receive_buf == NULL)
|
||||
data->init_sequence.receive_buf =
|
||||
g_malloc0(VFS5011_RECEIVE_BUF_SIZE);
|
||||
self->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT;
|
||||
usb_exchange_async (ssm, &self->init_sequence, "PREPARE CAPTURE");
|
||||
data->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT;
|
||||
usb_exchange_async(ssm, &data->init_sequence);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
activate_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void activate_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpDeviceVfs5011 *self;
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct vfs5011_data *data;
|
||||
int r = fpi_ssm_get_error(ssm);
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (_dev);
|
||||
data = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
fp_dbg("finishing");
|
||||
if (self->init_sequence.receive_buf != NULL)
|
||||
g_free (self->init_sequence.receive_buf);
|
||||
self->init_sequence.receive_buf = NULL;
|
||||
if (!self->deactivating && !error)
|
||||
{
|
||||
submit_image (ssm, self, dev);
|
||||
fpi_image_device_report_finger_status (dev, FALSE);
|
||||
if (data->init_sequence.receive_buf != NULL)
|
||||
g_free(data->init_sequence.receive_buf);
|
||||
data->init_sequence.receive_buf = NULL;
|
||||
if (!data->deactivating && !r) {
|
||||
submit_image(ssm, data, dev);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
}
|
||||
fpi_ssm_free(ssm);
|
||||
|
||||
self->loop_running = FALSE;
|
||||
data->loop_running = FALSE;
|
||||
|
||||
if (self->deactivating)
|
||||
fpi_image_device_deactivate_complete (dev, error);
|
||||
else if (error)
|
||||
fpi_image_device_session_error (dev, error);
|
||||
else
|
||||
if (data->deactivating) {
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
} else if (r) {
|
||||
fpi_imgdev_session_error(dev, r);
|
||||
} else {
|
||||
start_scan(dev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
open_loop (FpiSsm *ssm, FpDevice *_dev)
|
||||
static void open_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpDeviceVfs5011 *self;
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct vfs5011_data *data;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (_dev);
|
||||
data = FP_INSTANCE_DATA(_dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state (ssm))
|
||||
{
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case DEV_OPEN_START:
|
||||
self->init_sequence.stepcount =
|
||||
data->init_sequence.stepcount =
|
||||
G_N_ELEMENTS(vfs5011_initialization);
|
||||
self->init_sequence.actions = vfs5011_initialization;
|
||||
self->init_sequence.device = dev;
|
||||
self->init_sequence.receive_buf =
|
||||
data->init_sequence.actions = vfs5011_initialization;
|
||||
data->init_sequence.device = dev;
|
||||
data->init_sequence.receive_buf =
|
||||
g_malloc0(VFS5011_RECEIVE_BUF_SIZE);
|
||||
self->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT;
|
||||
usb_exchange_async (ssm, &self->init_sequence, "DEVICE OPEN");
|
||||
data->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT;
|
||||
usb_exchange_async(ssm, &data->init_sequence);
|
||||
break;
|
||||
}
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
open_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
|
||||
static void open_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
|
||||
FpDeviceVfs5011 *self;
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct vfs5011_data *data;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (_dev);
|
||||
g_free (self->init_sequence.receive_buf);
|
||||
self->init_sequence.receive_buf = NULL;
|
||||
data = FP_INSTANCE_DATA(_dev);
|
||||
g_free(data->init_sequence.receive_buf);
|
||||
data->init_sequence.receive_buf = NULL;
|
||||
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
fpi_ssm_free(ssm);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_open (FpImageDevice *dev)
|
||||
static int dev_open(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
{
|
||||
FpiSsm *ssm;
|
||||
GError *error = NULL;
|
||||
FpDeviceVfs5011 *self;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (dev);
|
||||
self->capture_buffer = g_new0 (unsigned char, CAPTURE_LINES * VFS5011_LINE_SIZE);
|
||||
struct vfs5011_data *data;
|
||||
int r;
|
||||
|
||||
if (!g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error))
|
||||
{
|
||||
fpi_image_device_open_complete (dev, error);
|
||||
return;
|
||||
data = (struct vfs5011_data *)g_malloc0(sizeof(*data));
|
||||
data->capture_buffer =
|
||||
(unsigned char *)g_malloc0(CAPTURE_LINES * VFS5011_LINE_SIZE);
|
||||
fp_dev_set_instance_data(FP_DEV(dev), data);
|
||||
|
||||
r = libusb_reset_device(fpi_dev_get_usb_dev(FP_DEV(dev)));
|
||||
if (r != 0) {
|
||||
fp_err("Failed to reset the device");
|
||||
return r;
|
||||
}
|
||||
|
||||
ssm = fpi_ssm_new (FP_DEVICE (dev), open_loop, DEV_OPEN_NUM_STATES);
|
||||
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;
|
||||
}
|
||||
|
||||
fpi_ssm *ssm;
|
||||
ssm = fpi_ssm_new(FP_DEV(dev), open_loop, DEV_OPEN_NUM_STATES, dev);
|
||||
fpi_ssm_start(ssm, open_loop_complete);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_close (FpImageDevice *dev)
|
||||
static void dev_close(struct fp_img_dev *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
FpDeviceVfs5011 *self = FPI_DEVICE_VFS5011 (dev);
|
||||
|
||||
;
|
||||
|
||||
g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
|
||||
0, 0, &error);
|
||||
|
||||
g_free (self->capture_buffer);
|
||||
g_slist_free_full (self->rows, g_free);
|
||||
|
||||
fpi_image_device_close_complete (dev, error);
|
||||
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) {
|
||||
g_free(data->capture_buffer);
|
||||
g_slist_free_full(data->rows, g_free);
|
||||
g_free(data);
|
||||
}
|
||||
fpi_imgdev_close_complete(dev);
|
||||
}
|
||||
|
||||
static void
|
||||
start_scan (FpImageDevice *dev)
|
||||
static void start_scan(struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVfs5011 *self;
|
||||
FpiSsm *ssm;
|
||||
struct vfs5011_data *data;
|
||||
fpi_ssm *ssm;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (dev);
|
||||
self->loop_running = TRUE;
|
||||
data = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
data->loop_running = TRUE;
|
||||
fp_dbg("creating ssm");
|
||||
ssm = fpi_ssm_new (FP_DEVICE (dev), activate_loop, DEV_ACTIVATE_NUM_STATES);
|
||||
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");
|
||||
}
|
||||
|
||||
static void
|
||||
dev_activate (FpImageDevice *dev)
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVfs5011 *self;
|
||||
struct vfs5011_data *data;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (dev);
|
||||
data = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fp_dbg("device initialized");
|
||||
self->deactivating = FALSE;
|
||||
data->deactivating = FALSE;
|
||||
|
||||
start_scan(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deactivate (FpImageDevice *dev)
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
{
|
||||
FpDeviceVfs5011 *self;
|
||||
int r;
|
||||
struct vfs5011_data *data;
|
||||
|
||||
self = FPI_DEVICE_VFS5011 (dev);
|
||||
if (self->loop_running)
|
||||
self->deactivating = TRUE;
|
||||
else
|
||||
fpi_image_device_deactivate_complete (dev, NULL);
|
||||
data = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
if (data->loop_running) {
|
||||
data->deactivating = TRUE;
|
||||
if (data->flying_transfer) {
|
||||
r = libusb_cancel_transfer(data->flying_transfer);
|
||||
if (r < 0)
|
||||
fp_dbg("cancel failed error %d", r);
|
||||
}
|
||||
} else
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
}
|
||||
|
||||
static const FpIdEntry id_table[] = {
|
||||
{ /* Validity device from some Toshiba laptops */ .vid = 0x138a, .pid = 0x0010, },
|
||||
{ /* vfs5011 */ .vid = 0x138a, .pid = 0x0011, },
|
||||
{ /* Validity device from Lenovo Preferred Pro USB Fingerprint Keyboard KUF1256 */ .vid = 0x138a, .pid = 0x0015, },
|
||||
{ /* Validity device from Lenovo T440 laptops */ .vid = 0x138a, .pid = 0x0017, },
|
||||
{ /* one more Validity device */ .vid = 0x138a, .pid = 0x0018, },
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x138a, .product = 0x0010 /* Validity device from some Toshiba laptops */ },
|
||||
{ .vendor = 0x138a, .product = 0x0011 /* vfs5011 */ },
|
||||
{ .vendor = 0x138a, .product = 0x0015 /* Validity device from Lenovo Preferred Pro USB Fingerprint Keyboard KUF1256 */ },
|
||||
{ .vendor = 0x138a, .product = 0x0017 /* Validity device from Lenovo T440 laptops */ },
|
||||
{ .vendor = 0x138a, .product = 0x0018 /* one more Validity device */ },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_vfs5011_init (FpDeviceVfs5011 *self)
|
||||
{
|
||||
}
|
||||
static void
|
||||
fpi_device_vfs5011_class_init (FpDeviceVfs5011Class *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
struct fp_img_driver vfs5011_driver = {
|
||||
.driver = {
|
||||
.id = VFS5011_ID,
|
||||
.name = "vfs5011",
|
||||
.full_name = "Validity VFS5011",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
},
|
||||
|
||||
dev_class->id = "vfs5011";
|
||||
dev_class->full_name = "Validity VFS5011";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
.flags = 0,
|
||||
.img_width = VFS5011_IMAGE_WIDTH,
|
||||
.img_height = -1,
|
||||
.bz3_threshold = 20,
|
||||
|
||||
img_class->img_open = dev_open;
|
||||
img_class->img_close = dev_close;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
.open = dev_open,
|
||||
.close = dev_close,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
};
|
||||
|
||||
img_class->bz3_threshold = 20;
|
||||
|
||||
img_class->img_width = VFS5011_IMAGE_WIDTH;
|
||||
img_class->img_height = -1;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef __VFS5011_PROTO_H
|
||||
#define __VFS5011_PROTO_H
|
||||
|
||||
#define VFS5011_LINE_SIZE 240
|
||||
#define VFS5011_IMAGE_WIDTH 160
|
||||
@@ -6,10 +7,10 @@
|
||||
enum {
|
||||
VFS5011_DEFAULT_WAIT_TIMEOUT = 3000,
|
||||
|
||||
VFS5011_OUT_ENDPOINT = 1 | FPI_USB_ENDPOINT_OUT,
|
||||
VFS5011_IN_ENDPOINT_CTRL = 1 | FPI_USB_ENDPOINT_IN,
|
||||
VFS5011_IN_ENDPOINT_DATA = 2 | FPI_USB_ENDPOINT_IN,
|
||||
VFS5011_IN_ENDPOINT_CTRL2 = 3 | FPI_USB_ENDPOINT_IN,
|
||||
VFS5011_OUT_ENDPOINT = 1 | LIBUSB_ENDPOINT_OUT,
|
||||
VFS5011_IN_ENDPOINT_CTRL = 1 | LIBUSB_ENDPOINT_IN,
|
||||
VFS5011_IN_ENDPOINT_DATA = 2 | LIBUSB_ENDPOINT_IN,
|
||||
VFS5011_IN_ENDPOINT_CTRL2 = 3 | LIBUSB_ENDPOINT_IN,
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -6181,3 +6182,5 @@ static unsigned char vfs5011_prepare_04[] = { /* 2903 B */
|
||||
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
|
||||
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,331 +0,0 @@
|
||||
/*
|
||||
* Virtual driver for image device debugging
|
||||
*
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a virtual driver to debug the image based drivers. A small
|
||||
* python script is provided to connect to it via a socket, allowing
|
||||
* prints to be sent to this device programatically.
|
||||
* Using this it is possible to test libfprint and fprintd.
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "virtual_image"
|
||||
|
||||
#include "fpi-log.h"
|
||||
|
||||
#include "../fpi-image.h"
|
||||
#include "../fpi-image-device.h"
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixsocketaddress.h>
|
||||
|
||||
struct _FpDeviceVirtualImage
|
||||
{
|
||||
FpImageDevice parent;
|
||||
|
||||
GSocketListener *listener;
|
||||
GSocketConnection *connection;
|
||||
GCancellable *cancellable;
|
||||
|
||||
gint socket_fd;
|
||||
gint client_fd;
|
||||
|
||||
gboolean automatic_finger;
|
||||
FpImage *recv_img;
|
||||
gint recv_img_hdr[2];
|
||||
};
|
||||
|
||||
G_DECLARE_FINAL_TYPE (FpDeviceVirtualImage, fpi_device_virtual_image, FPI, DEVICE_VIRTUAL_IMAGE, FpImageDevice)
|
||||
G_DEFINE_TYPE (FpDeviceVirtualImage, fpi_device_virtual_image, FP_TYPE_IMAGE_DEVICE)
|
||||
|
||||
static void start_listen (FpDeviceVirtualImage *dev);
|
||||
static void recv_image (FpDeviceVirtualImage *dev,
|
||||
GInputStream *stream);
|
||||
|
||||
static void
|
||||
recv_image_img_recv_cb (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpDeviceVirtualImage *self;
|
||||
FpImageDevice *device;
|
||||
gboolean success;
|
||||
gsize bytes = 0;
|
||||
|
||||
success = g_input_stream_read_all_finish (G_INPUT_STREAM (source_object), res, &bytes, &error);
|
||||
|
||||
if (!success || bytes == 0)
|
||||
{
|
||||
if (!success)
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
return;
|
||||
g_warning ("Error receiving header for image data: %s", error->message);
|
||||
}
|
||||
|
||||
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
|
||||
g_io_stream_close (G_IO_STREAM (self->connection), NULL, NULL);
|
||||
g_clear_object (&self->connection);
|
||||
return;
|
||||
}
|
||||
|
||||
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
|
||||
device = FP_IMAGE_DEVICE (self);
|
||||
|
||||
if (self->automatic_finger)
|
||||
fpi_image_device_report_finger_status (device, TRUE);
|
||||
fpi_image_device_image_captured (device, g_steal_pointer (&self->recv_img));
|
||||
if (self->automatic_finger)
|
||||
fpi_image_device_report_finger_status (device, FALSE);
|
||||
|
||||
/* And, listen for more images from the same client. */
|
||||
recv_image (self, G_INPUT_STREAM (source_object));
|
||||
}
|
||||
|
||||
static void
|
||||
recv_image_hdr_recv_cb (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpDeviceVirtualImage *self;
|
||||
gboolean success;
|
||||
gsize bytes;
|
||||
|
||||
success = g_input_stream_read_all_finish (G_INPUT_STREAM (source_object), res, &bytes, &error);
|
||||
|
||||
if (!success || bytes == 0)
|
||||
{
|
||||
if (!success)
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CLOSED))
|
||||
return;
|
||||
g_warning ("Error receiving header for image data: %s", error->message);
|
||||
}
|
||||
|
||||
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
|
||||
g_io_stream_close (G_IO_STREAM (self->connection), NULL, NULL);
|
||||
g_clear_object (&self->connection);
|
||||
return;
|
||||
}
|
||||
|
||||
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
|
||||
if (self->recv_img_hdr[0] > 5000 || self->recv_img_hdr[1] > 5000)
|
||||
{
|
||||
g_warning ("Image header suggests an unrealistically large image, disconnecting client.");
|
||||
g_io_stream_close (G_IO_STREAM (self->connection), NULL, NULL);
|
||||
g_clear_object (&self->connection);
|
||||
}
|
||||
|
||||
if (self->recv_img_hdr[0] < 0 || self->recv_img_hdr[1] < 0)
|
||||
{
|
||||
switch (self->recv_img_hdr[0])
|
||||
{
|
||||
case -1:
|
||||
/* -1 is a retry error, just pass it through */
|
||||
fpi_image_device_retry_scan (FP_IMAGE_DEVICE (self), self->recv_img_hdr[1]);
|
||||
break;
|
||||
|
||||
case -2:
|
||||
/* -2 is a fatal error, just pass it through*/
|
||||
fpi_image_device_session_error (FP_IMAGE_DEVICE (self),
|
||||
fpi_device_error_new (self->recv_img_hdr[1]));
|
||||
break;
|
||||
|
||||
case -3:
|
||||
/* -3 sets/clears automatic finger detection for images */
|
||||
self->automatic_finger = !!self->recv_img_hdr[1];
|
||||
break;
|
||||
|
||||
case -4:
|
||||
/* -4 submits a finger detection report */
|
||||
fpi_image_device_report_finger_status (FP_IMAGE_DEVICE (self),
|
||||
!!self->recv_img_hdr[1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* disconnect client, it didn't play fair */
|
||||
g_io_stream_close (G_IO_STREAM (self->connection), NULL, NULL);
|
||||
g_clear_object (&self->connection);
|
||||
}
|
||||
|
||||
/* And, listen for more images from the same client. */
|
||||
recv_image (self, G_INPUT_STREAM (source_object));
|
||||
return;
|
||||
}
|
||||
|
||||
self->recv_img = fp_image_new (self->recv_img_hdr[0], self->recv_img_hdr[1]);
|
||||
g_debug ("image data: %p", self->recv_img->data);
|
||||
g_input_stream_read_all_async (G_INPUT_STREAM (source_object),
|
||||
(guint8 *) self->recv_img->data,
|
||||
self->recv_img->width * self->recv_img->height,
|
||||
G_PRIORITY_DEFAULT,
|
||||
self->cancellable,
|
||||
recv_image_img_recv_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
recv_image (FpDeviceVirtualImage *dev, GInputStream *stream)
|
||||
{
|
||||
g_input_stream_read_all_async (stream,
|
||||
dev->recv_img_hdr,
|
||||
sizeof (dev->recv_img_hdr),
|
||||
G_PRIORITY_DEFAULT,
|
||||
dev->cancellable,
|
||||
recv_image_hdr_recv_cb,
|
||||
dev);
|
||||
}
|
||||
|
||||
static void
|
||||
new_connection_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
GSocketConnection *connection;
|
||||
GInputStream *stream;
|
||||
FpDeviceVirtualImage *dev = user_data;
|
||||
|
||||
connection = g_socket_listener_accept_finish (G_SOCKET_LISTENER (source_object),
|
||||
res,
|
||||
NULL,
|
||||
&error);
|
||||
if (!connection)
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
return;
|
||||
|
||||
g_warning ("Error accepting a new connection: %s", error->message);
|
||||
start_listen (dev);
|
||||
}
|
||||
|
||||
/* Always further connections (but we disconnect them immediately
|
||||
* if we already have a connection). */
|
||||
start_listen (dev);
|
||||
if (dev->connection)
|
||||
{
|
||||
g_io_stream_close (G_IO_STREAM (connection), NULL, NULL);
|
||||
g_object_unref (connection);
|
||||
return;
|
||||
}
|
||||
|
||||
dev->connection = connection;
|
||||
dev->automatic_finger = TRUE;
|
||||
stream = g_io_stream_get_input_stream (G_IO_STREAM (connection));
|
||||
|
||||
recv_image (dev, stream);
|
||||
|
||||
fp_dbg ("Got a new connection!");
|
||||
}
|
||||
|
||||
static void
|
||||
start_listen (FpDeviceVirtualImage *dev)
|
||||
{
|
||||
g_socket_listener_accept_async (dev->listener,
|
||||
dev->cancellable,
|
||||
new_connection_cb,
|
||||
dev);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_init (FpImageDevice *dev)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GSocketListener) listener = NULL;
|
||||
FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (dev);
|
||||
const char *env;
|
||||
g_autoptr(GSocketAddress) addr = NULL;
|
||||
G_DEBUG_HERE ();
|
||||
|
||||
self->client_fd = -1;
|
||||
|
||||
env = fpi_device_get_virtual_env (FP_DEVICE (self));
|
||||
|
||||
listener = g_socket_listener_new ();
|
||||
g_socket_listener_set_backlog (listener, 1);
|
||||
|
||||
/* Remove any left over socket. */
|
||||
g_unlink (env);
|
||||
|
||||
addr = g_unix_socket_address_new (env);
|
||||
|
||||
if (!g_socket_listener_add_address (listener,
|
||||
addr,
|
||||
G_SOCKET_TYPE_STREAM,
|
||||
G_SOCKET_PROTOCOL_DEFAULT,
|
||||
NULL,
|
||||
NULL,
|
||||
&error))
|
||||
{
|
||||
g_warning ("Could not listen on unix socket: %s", error->message);
|
||||
|
||||
fpi_image_device_open_complete (FP_IMAGE_DEVICE (dev), g_steal_pointer (&error));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
self->listener = g_steal_pointer (&listener);
|
||||
self->cancellable = g_cancellable_new ();
|
||||
|
||||
start_listen (self);
|
||||
|
||||
fpi_image_device_open_complete (dev, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
dev_deinit (FpImageDevice *dev)
|
||||
{
|
||||
FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (dev);
|
||||
|
||||
G_DEBUG_HERE ();
|
||||
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
g_clear_object (&self->cancellable);
|
||||
g_clear_object (&self->listener);
|
||||
g_clear_object (&self->connection);
|
||||
|
||||
fpi_image_device_close_complete (dev, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
fpi_device_virtual_image_init (FpDeviceVirtualImage *self)
|
||||
{
|
||||
}
|
||||
|
||||
static const FpIdEntry driver_ids[] = {
|
||||
{ .virtual_envvar = "FP_VIRTUAL_IMAGE" },
|
||||
{ .virtual_envvar = NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
fpi_device_virtual_image_class_init (FpDeviceVirtualImageClass *klass)
|
||||
{
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
|
||||
|
||||
dev_class->id = FP_COMPONENT;
|
||||
dev_class->full_name = "Virtual image device for debugging";
|
||||
dev_class->type = FP_DEVICE_TYPE_VIRTUAL;
|
||||
dev_class->id_table = driver_ids;
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
* Driver API definitions
|
||||
* Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2018 Bastien Nocera <hadess@hadess.net>
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -19,14 +18,22 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __DRIVERS_API_H__
|
||||
#define __DRIVERS_API_H__
|
||||
|
||||
#include "fpi-compat.h"
|
||||
#include "fpi-assembling.h"
|
||||
#include "fpi-device.h"
|
||||
#include "fpi-image-device.h"
|
||||
#include "fpi-image.h"
|
||||
#include <config.h>
|
||||
|
||||
#include "fprint.h"
|
||||
#include "fpi-log.h"
|
||||
#include "fpi-print.h"
|
||||
#include "fpi-usb-transfer.h"
|
||||
#include "fpi-dev.h"
|
||||
#include "fpi-dev-img.h"
|
||||
#include "fpi-core.h"
|
||||
#include "fpi-ssm.h"
|
||||
#include "fpi-poll.h"
|
||||
#include "fpi-dev.h"
|
||||
#include "fpi-usb.h"
|
||||
#include "fpi-img.h"
|
||||
#include "fpi-assembling.h"
|
||||
#include "drivers/driver_ids.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,402 +0,0 @@
|
||||
/*
|
||||
* FpContext - A FPrint context
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "context"
|
||||
#include <fpi-log.h>
|
||||
|
||||
#include "fpi-context.h"
|
||||
#include "fpi-device.h"
|
||||
#include <gusb.h>
|
||||
|
||||
/**
|
||||
* SECTION: fp-context
|
||||
* @title: FpContext
|
||||
* @short_description: Discover fingerprint devices
|
||||
*
|
||||
* The #FpContext allows you to discover fingerprint scanning hardware. This
|
||||
* is the starting point when integrating libfprint into your software.
|
||||
*
|
||||
* The <link linkend="device-added">device-added</link> and device-removed signals allow you to handle devices
|
||||
* that may be hotplugged at runtime.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GUsbContext *usb_ctx;
|
||||
GCancellable *cancellable;
|
||||
|
||||
gint pending_devices;
|
||||
gboolean enumerated;
|
||||
|
||||
GArray *drivers;
|
||||
GPtrArray *devices;
|
||||
} FpContextPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (FpContext, fp_context, G_TYPE_OBJECT)
|
||||
|
||||
enum {
|
||||
DEVICE_ADDED_SIGNAL,
|
||||
DEVICE_REMOVED_SIGNAL,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static const char *
|
||||
get_drivers_whitelist_env (void)
|
||||
{
|
||||
return g_getenv ("FP_DRIVERS_WHITELIST");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_driver_allowed (const gchar *driver)
|
||||
{
|
||||
g_auto(GStrv) whitelisted_drivers = NULL;
|
||||
const char *fp_drivers_whitelist_env;
|
||||
int i;
|
||||
|
||||
g_return_val_if_fail (driver, TRUE);
|
||||
|
||||
fp_drivers_whitelist_env = get_drivers_whitelist_env ();
|
||||
|
||||
if (!fp_drivers_whitelist_env)
|
||||
return TRUE;
|
||||
|
||||
whitelisted_drivers = g_strsplit (fp_drivers_whitelist_env, ":", -1);
|
||||
|
||||
for (i = 0; whitelisted_drivers[i]; ++i)
|
||||
if (g_strcmp0 (driver, whitelisted_drivers[i]) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
async_device_init_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpDevice *device;
|
||||
FpContext *context;
|
||||
FpContextPrivate *priv;
|
||||
|
||||
device = (FpDevice *) g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, &error);
|
||||
if (!device)
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
return;
|
||||
|
||||
context = FP_CONTEXT (user_data);
|
||||
priv = fp_context_get_instance_private (context);
|
||||
priv->pending_devices--;
|
||||
g_message ("Ignoring device due to initialization error: %s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
context = FP_CONTEXT (user_data);
|
||||
priv = fp_context_get_instance_private (context);
|
||||
priv->pending_devices--;
|
||||
g_ptr_array_add (priv->devices, device);
|
||||
g_signal_emit (context, signals[DEVICE_ADDED_SIGNAL], 0, device);
|
||||
}
|
||||
|
||||
static void
|
||||
usb_device_added_cb (FpContext *self, GUsbDevice *device, GUsbContext *usb_ctx)
|
||||
{
|
||||
FpContextPrivate *priv = fp_context_get_instance_private (self);
|
||||
GType found_driver = G_TYPE_NONE;
|
||||
const FpIdEntry *found_entry = NULL;
|
||||
gint found_score = 0;
|
||||
gint i;
|
||||
guint16 pid, vid;
|
||||
|
||||
pid = g_usb_device_get_pid (device);
|
||||
vid = g_usb_device_get_vid (device);
|
||||
|
||||
/* Find the best driver to handle this USB device. */
|
||||
for (i = 0; i < priv->drivers->len; i++)
|
||||
{
|
||||
GType driver = g_array_index (priv->drivers, GType, i);
|
||||
g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver);
|
||||
const FpIdEntry *entry;
|
||||
|
||||
if (cls->type != FP_DEVICE_TYPE_USB)
|
||||
continue;
|
||||
|
||||
for (entry = cls->id_table; entry->pid; entry++)
|
||||
{
|
||||
gint driver_score = 50;
|
||||
|
||||
if (entry->pid != pid || entry->vid != vid)
|
||||
continue;
|
||||
|
||||
if (cls->usb_discover)
|
||||
driver_score = cls->usb_discover (device);
|
||||
|
||||
/* Is this driver better than the one we had? */
|
||||
if (driver_score <= found_score)
|
||||
continue;
|
||||
|
||||
found_score = driver_score;
|
||||
found_driver = driver;
|
||||
found_entry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_driver == G_TYPE_NONE)
|
||||
{
|
||||
g_debug ("No driver found for USB device %04X:%04X", pid, vid);
|
||||
return;
|
||||
}
|
||||
|
||||
priv->pending_devices++;
|
||||
g_async_initable_new_async (found_driver,
|
||||
G_PRIORITY_LOW,
|
||||
priv->cancellable,
|
||||
async_device_init_done_cb,
|
||||
self,
|
||||
"fpi-usb-device", device,
|
||||
"fpi-driver-data", found_entry->driver_data,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
usb_device_removed_cb (FpContext *self, GUsbDevice *device, GUsbContext *usb_ctx)
|
||||
{
|
||||
FpContextPrivate *priv = fp_context_get_instance_private (self);
|
||||
gint i;
|
||||
|
||||
/* Do the lazy way and just look at each device. */
|
||||
for (i = 0; i < priv->devices->len; i++)
|
||||
{
|
||||
FpDevice *dev = g_ptr_array_index (priv->devices, i);
|
||||
FpDeviceClass *cls = FP_DEVICE_GET_CLASS (dev);
|
||||
|
||||
if (cls->type != FP_DEVICE_TYPE_USB)
|
||||
continue;
|
||||
|
||||
if (fpi_device_get_usb_device (dev) == device)
|
||||
{
|
||||
g_signal_emit (self, signals[DEVICE_REMOVED_SIGNAL], 0, dev);
|
||||
g_ptr_array_remove_index_fast (priv->devices, i);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fp_context_finalize (GObject *object)
|
||||
{
|
||||
FpContext *self = (FpContext *) object;
|
||||
FpContextPrivate *priv = fp_context_get_instance_private (self);
|
||||
|
||||
g_clear_pointer (&priv->devices, g_ptr_array_unref);
|
||||
|
||||
g_cancellable_cancel (priv->cancellable);
|
||||
g_clear_object (&priv->cancellable);
|
||||
g_clear_pointer (&priv->drivers, g_array_unref);
|
||||
|
||||
g_object_run_dispose (G_OBJECT (priv->usb_ctx));
|
||||
g_clear_object (&priv->usb_ctx);
|
||||
|
||||
G_OBJECT_CLASS (fp_context_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_context_class_init (FpContextClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = fp_context_finalize;
|
||||
|
||||
/**
|
||||
* FpContext::device-added:
|
||||
* @context: the #FpContext instance that emitted the signal
|
||||
* @device: A #FpDevice
|
||||
*
|
||||
* This signal is emitted when a fingerprint reader is added.
|
||||
**/
|
||||
signals[DEVICE_ADDED_SIGNAL] = g_signal_new ("device-added",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (FpContextClass, device_added),
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
FP_TYPE_DEVICE);
|
||||
|
||||
/**
|
||||
* FpContext::device-removed:
|
||||
* @context: the #FpContext instance that emitted the signal
|
||||
* @device: A #FpDevice
|
||||
*
|
||||
* This signal is emitted when a fingerprint reader is removed.
|
||||
**/
|
||||
signals[DEVICE_REMOVED_SIGNAL] = g_signal_new ("device-removed",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (FpContextClass, device_removed),
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
FP_TYPE_DEVICE);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_context_init (FpContext *self)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpContextPrivate *priv = fp_context_get_instance_private (self);
|
||||
guint i;
|
||||
|
||||
priv->drivers = fpi_get_driver_types ();
|
||||
|
||||
if (get_drivers_whitelist_env ())
|
||||
{
|
||||
for (i = 0; i < priv->drivers->len;)
|
||||
{
|
||||
GType driver = g_array_index (priv->drivers, GType, i);
|
||||
g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver);
|
||||
|
||||
if (!is_driver_allowed (cls->id))
|
||||
g_array_remove_index (priv->drivers, i);
|
||||
else
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
priv->devices = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
|
||||
priv->cancellable = g_cancellable_new ();
|
||||
priv->usb_ctx = g_usb_context_new (&error);
|
||||
if (!priv->usb_ctx)
|
||||
{
|
||||
fp_warn ("Could not initialise USB Subsystem: %s", error->message);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_usb_context_set_debug (priv->usb_ctx, G_LOG_LEVEL_INFO);
|
||||
g_signal_connect_object (priv->usb_ctx,
|
||||
"device-added",
|
||||
G_CALLBACK (usb_device_added_cb),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
g_signal_connect_object (priv->usb_ctx,
|
||||
"device-removed",
|
||||
G_CALLBACK (usb_device_removed_cb),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fp_context_new:
|
||||
*
|
||||
* Create a new #FpContext.
|
||||
*
|
||||
* Returns: (transfer full): a newly created #FpContext
|
||||
*/
|
||||
FpContext *
|
||||
fp_context_new (void)
|
||||
{
|
||||
return g_object_new (FP_TYPE_CONTEXT, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* fp_context_enumerate:
|
||||
* @context: a #FpContext
|
||||
*
|
||||
* Enumerate all devices. You should call this function exactly once
|
||||
* at startup. Please note that it iterates the mainloop until all
|
||||
* devices are enumerated.
|
||||
*/
|
||||
void
|
||||
fp_context_enumerate (FpContext *context)
|
||||
{
|
||||
FpContextPrivate *priv = fp_context_get_instance_private (context);
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (FP_IS_CONTEXT (context));
|
||||
|
||||
if (priv->enumerated)
|
||||
return;
|
||||
|
||||
priv->enumerated = TRUE;
|
||||
|
||||
/* USB devices are handled from callbacks */
|
||||
g_usb_context_enumerate (priv->usb_ctx);
|
||||
|
||||
/* Handle Virtual devices based on environment variables */
|
||||
for (i = 0; i < priv->drivers->len; i++)
|
||||
{
|
||||
GType driver = g_array_index (priv->drivers, GType, i);
|
||||
g_autoptr(FpDeviceClass) cls = g_type_class_ref (driver);
|
||||
const FpIdEntry *entry;
|
||||
|
||||
if (cls->type != FP_DEVICE_TYPE_VIRTUAL)
|
||||
continue;
|
||||
|
||||
for (entry = cls->id_table; entry->pid; entry++)
|
||||
{
|
||||
const gchar *val;
|
||||
|
||||
val = g_getenv (entry->virtual_envvar);
|
||||
if (!val || val[0] == '\0')
|
||||
continue;
|
||||
|
||||
g_debug ("Found virtual environment device: %s, %s", entry->virtual_envvar, val);
|
||||
priv->pending_devices++;
|
||||
g_async_initable_new_async (driver,
|
||||
G_PRIORITY_LOW,
|
||||
priv->cancellable,
|
||||
async_device_init_done_cb,
|
||||
context,
|
||||
"fpi-environ", val,
|
||||
"fpi-driver-data", entry->driver_data,
|
||||
NULL);
|
||||
g_debug ("created");
|
||||
}
|
||||
}
|
||||
|
||||
while (priv->pending_devices)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* fp_context_get_devices:
|
||||
* @context: a #FpContext
|
||||
*
|
||||
* Get all devices. fp_context_enumerate() will be called as needed.
|
||||
*
|
||||
* Returns: (transfer none) (element-type FpDevice): a new #GPtrArray of #GUsbDevice's.
|
||||
*/
|
||||
GPtrArray *
|
||||
fp_context_get_devices (FpContext *context)
|
||||
{
|
||||
FpContextPrivate *priv = fp_context_get_instance_private (context);
|
||||
|
||||
g_return_val_if_fail (FP_IS_CONTEXT (context), NULL);
|
||||
|
||||
fp_context_enumerate (context);
|
||||
|
||||
return priv->devices;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* FpContext - A FPrint context
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fp-device.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define FP_TYPE_CONTEXT (fp_context_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (FpContext, fp_context, FP, CONTEXT, GObject)
|
||||
|
||||
/**
|
||||
* FpContextClass:
|
||||
* @device_added: Called when a new device is added
|
||||
* @device_removed: Called when a device is removed
|
||||
*
|
||||
* Class structure for #FpContext instances.
|
||||
*/
|
||||
struct _FpContextClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*device_added) (FpContext *context,
|
||||
FpDevice *device);
|
||||
void (*device_removed) (FpContext *context,
|
||||
FpDevice *device);
|
||||
};
|
||||
|
||||
FpContext *fp_context_new (void);
|
||||
|
||||
void fp_context_enumerate (FpContext *context);
|
||||
|
||||
GPtrArray *fp_context_get_devices (FpContext *context);
|
||||
|
||||
G_END_DECLS
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* FpDevice - A fingerprint reader device
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fpi-device.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FpDeviceType type;
|
||||
|
||||
GUsbDevice *usb_device;
|
||||
const gchar *virtual_env;
|
||||
|
||||
gboolean is_open;
|
||||
|
||||
gchar *device_id;
|
||||
gchar *device_name;
|
||||
FpScanType scan_type;
|
||||
|
||||
guint64 driver_data;
|
||||
|
||||
gint nr_enroll_stages;
|
||||
GSList *sources;
|
||||
|
||||
/* We always make sure that only one task is run at a time. */
|
||||
FpiDeviceAction current_action;
|
||||
GTask *current_task;
|
||||
GAsyncReadyCallback current_user_cb;
|
||||
gulong current_cancellable_id;
|
||||
GSource *current_idle_cancel_source;
|
||||
GSource *current_task_idle_return_source;
|
||||
|
||||
/* State for tasks */
|
||||
gboolean wait_for_finger;
|
||||
} FpDevicePrivate;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FpPrint *print;
|
||||
|
||||
FpEnrollProgress enroll_progress_cb;
|
||||
gpointer enroll_progress_data;
|
||||
GDestroyNotify enroll_progress_destroy;
|
||||
} FpEnrollData;
|
||||
|
||||
void enroll_data_free (FpEnrollData *enroll_data);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FpPrint *enrolled_print; /* verify */
|
||||
GPtrArray *gallery; /* identify */
|
||||
|
||||
gboolean result_reported;
|
||||
FpPrint *match;
|
||||
FpPrint *print;
|
||||
GError *error;
|
||||
|
||||
FpMatchCb match_cb;
|
||||
gpointer match_data;
|
||||
GDestroyNotify match_destroy;
|
||||
} FpMatchData;
|
||||
|
||||
void match_data_free (FpMatchData *match_data);
|
||||
@@ -1,303 +0,0 @@
|
||||
/*
|
||||
* FpDevice - A fingerprint reader device
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fp-image.h"
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define FP_TYPE_DEVICE (fp_device_get_type ())
|
||||
#define FP_DEVICE_RETRY (fp_device_retry_quark ())
|
||||
#define FP_DEVICE_ERROR (fp_device_error_quark ())
|
||||
G_DECLARE_DERIVABLE_TYPE (FpDevice, fp_device, FP, DEVICE, GObject)
|
||||
|
||||
#include "fp-print.h"
|
||||
|
||||
/* NOTE: We keep the class struct private! */
|
||||
|
||||
/**
|
||||
* FpDeviceType:
|
||||
* @FP_DEVICE_TYPE_VIRTUAL: The device is a virtual device
|
||||
* @FP_DEVICE_TYPE_USB: The device is a USB device
|
||||
*/
|
||||
typedef enum {
|
||||
FP_DEVICE_TYPE_VIRTUAL,
|
||||
FP_DEVICE_TYPE_USB,
|
||||
} FpDeviceType;
|
||||
|
||||
/**
|
||||
* FpScanType:
|
||||
* @FP_SCAN_TYPE_SWIPE: Sensor requires swiping the finger.
|
||||
* @FP_SCAN_TYPE_PRESS: Sensor requires placing/pressing down the finger.
|
||||
*/
|
||||
typedef enum {
|
||||
FP_SCAN_TYPE_SWIPE,
|
||||
FP_SCAN_TYPE_PRESS,
|
||||
} FpScanType;
|
||||
|
||||
/**
|
||||
* FpDeviceRetry:
|
||||
* @FP_DEVICE_RETRY_GENERAL: The scan did not succeed due to poor scan quality
|
||||
* or other general user scanning problem.
|
||||
* @FP_DEVICE_RETRY_TOO_SHORT: The scan did not succeed because the finger
|
||||
* swipe was too short.
|
||||
* @FP_DEVICE_RETRY_CENTER_FINGER: The scan did not succeed because the finger
|
||||
* was not centered on the scanner.
|
||||
* @FP_DEVICE_RETRY_REMOVE_FINGER: The scan did not succeed due to quality or
|
||||
* pressure problems; the user should remove their finger from the scanner
|
||||
* before retrying.
|
||||
*
|
||||
* Error codes representing scan failures resulting in the user needing to
|
||||
* retry.
|
||||
*/
|
||||
typedef enum {
|
||||
FP_DEVICE_RETRY_GENERAL,
|
||||
FP_DEVICE_RETRY_TOO_SHORT,
|
||||
FP_DEVICE_RETRY_CENTER_FINGER,
|
||||
FP_DEVICE_RETRY_REMOVE_FINGER,
|
||||
} FpDeviceRetry;
|
||||
|
||||
/**
|
||||
* FpDeviceError:
|
||||
* @FP_DEVICE_ERROR_GENERAL: A general error occured.
|
||||
* @FP_DEVICE_ERROR_NOT_SUPPORTED: The device does not support the requested
|
||||
* operation.
|
||||
* @FP_DEVICE_ERROR_NOT_OPEN: The device needs to be opened to start this
|
||||
* operation.
|
||||
* @FP_DEVICE_ERROR_ALREADY_OPEN: The device has already been opened.
|
||||
* @FP_DEVICE_ERROR_BUSY: The device is busy with another request.
|
||||
* @FP_DEVICE_ERROR_PROTO: Protocol error
|
||||
* @FP_DEVICE_ERROR_DATA_INVALID: The passed data is invalid
|
||||
* @FP_DEVICE_ERROR_DATA_NOT_FOUND: Requested print was not found on device
|
||||
* @FP_DEVICE_ERROR_DATA_FULL: No space on device available for operation
|
||||
*
|
||||
* Error codes for device operations. More specific errors from other domains
|
||||
* such as #G_IO_ERROR or #G_USB_DEVICE_ERROR may also be reported.
|
||||
*/
|
||||
typedef enum {
|
||||
FP_DEVICE_ERROR_GENERAL,
|
||||
FP_DEVICE_ERROR_NOT_SUPPORTED,
|
||||
FP_DEVICE_ERROR_NOT_OPEN,
|
||||
FP_DEVICE_ERROR_ALREADY_OPEN,
|
||||
FP_DEVICE_ERROR_BUSY,
|
||||
FP_DEVICE_ERROR_PROTO,
|
||||
FP_DEVICE_ERROR_DATA_INVALID,
|
||||
FP_DEVICE_ERROR_DATA_NOT_FOUND,
|
||||
FP_DEVICE_ERROR_DATA_FULL,
|
||||
} FpDeviceError;
|
||||
|
||||
GQuark fp_device_retry_quark (void);
|
||||
GQuark fp_device_error_quark (void);
|
||||
|
||||
/**
|
||||
* FpEnrollProgress:
|
||||
* @device: a #FpDevice
|
||||
* @completed_stages: Number of completed stages
|
||||
* @print: (nullable) (transfer none): The last scaned print
|
||||
* @user_data: (nullable) (transfer none): User provided data
|
||||
* @error: (nullable) (transfer none): #GError or %NULL
|
||||
*
|
||||
* The passed error is guaranteed to be of type %FP_DEVICE_RETRY if set.
|
||||
*/
|
||||
typedef void (*FpEnrollProgress) (FpDevice *device,
|
||||
gint completed_stages,
|
||||
FpPrint *print,
|
||||
gpointer user_data,
|
||||
GError *error);
|
||||
|
||||
/**
|
||||
* FpMatchCb:
|
||||
* @device: a #FpDevice
|
||||
* @match: (nullable) (transfer none): The matching print if any matched @print
|
||||
* @print: (nullable) (transfer none): The newly scanned print
|
||||
* @user_data: (nullable) (transfer none): User provided data
|
||||
* @error: (nullable) (transfer none): #GError or %NULL
|
||||
*
|
||||
* Report the result of a match (identify or verify) operation.
|
||||
*
|
||||
* If @match is non-%NULL, then it is set to the matching #FpPrint as passed
|
||||
* to the match operation. In this case @error will always be %NULL.
|
||||
*
|
||||
* If @error is not %NULL then its domain is guaranteed to be
|
||||
* %FP_DEVICE_RETRY. All other error conditions will not be reported using
|
||||
* this callback. If such an error occurs before a match/no-match decision
|
||||
* can be made, then this callback will not be called. Should an error
|
||||
* happen afterwards, then you will get a match report through this callback
|
||||
* and an error when the operation finishes.
|
||||
*
|
||||
* If @match and @error are %NULL, then a finger was presented but it did not
|
||||
* match any known print.
|
||||
*
|
||||
* @print represents the newly scanned print. The driver may or may not
|
||||
* provide this information. Image based devices will provide it and it
|
||||
* allows access to the raw data.
|
||||
*
|
||||
* This callback exists because it makes sense for drivers to wait e.g. on
|
||||
* finger removal before completing the match operation. However, the
|
||||
* success/failure can often be reported at an earlier time, and there is
|
||||
* no need to make the user wait.
|
||||
*/
|
||||
typedef void (*FpMatchCb) (FpDevice *device,
|
||||
FpPrint *match,
|
||||
FpPrint *print,
|
||||
gpointer user_data,
|
||||
GError *error);
|
||||
|
||||
const gchar *fp_device_get_driver (FpDevice *device);
|
||||
const gchar *fp_device_get_device_id (FpDevice *device);
|
||||
const gchar *fp_device_get_name (FpDevice *device);
|
||||
gboolean fp_device_is_open (FpDevice *device);
|
||||
FpScanType fp_device_get_scan_type (FpDevice *device);
|
||||
gint fp_device_get_nr_enroll_stages (FpDevice *device);
|
||||
|
||||
gboolean fp_device_supports_identify (FpDevice *device);
|
||||
gboolean fp_device_supports_capture (FpDevice *device);
|
||||
gboolean fp_device_has_storage (FpDevice *device);
|
||||
|
||||
/* Opening the device */
|
||||
void fp_device_open (FpDevice *device,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
void fp_device_close (FpDevice *device,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
void fp_device_enroll (FpDevice *device,
|
||||
FpPrint *template_print,
|
||||
GCancellable *cancellable,
|
||||
FpEnrollProgress progress_cb,
|
||||
gpointer progress_data,
|
||||
GDestroyNotify progress_destroy,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
void fp_device_verify (FpDevice *device,
|
||||
FpPrint *enrolled_print,
|
||||
GCancellable *cancellable,
|
||||
FpMatchCb match_cb,
|
||||
gpointer match_data,
|
||||
GDestroyNotify match_destroy,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
void fp_device_identify (FpDevice *device,
|
||||
GPtrArray *prints,
|
||||
GCancellable *cancellable,
|
||||
FpMatchCb match_cb,
|
||||
gpointer match_data,
|
||||
GDestroyNotify match_destroy,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
void fp_device_capture (FpDevice *device,
|
||||
gboolean wait_for_finger,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
void fp_device_delete_print (FpDevice *device,
|
||||
FpPrint *enrolled_print,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
void fp_device_list_prints (FpDevice *device,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean fp_device_open_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
gboolean fp_device_close_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
FpPrint *fp_device_enroll_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
gboolean fp_device_verify_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
gboolean *match,
|
||||
FpPrint **print,
|
||||
GError **error);
|
||||
gboolean fp_device_identify_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
FpPrint **match,
|
||||
FpPrint **print,
|
||||
GError **error);
|
||||
FpImage * fp_device_capture_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
gboolean fp_device_delete_print_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
GPtrArray * fp_device_list_prints_finish (FpDevice *device,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
|
||||
|
||||
gboolean fp_device_open_sync (FpDevice *device,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean fp_device_close_sync (FpDevice *device,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
FpPrint * fp_device_enroll_sync (FpDevice *device,
|
||||
FpPrint *template_print,
|
||||
GCancellable *cancellable,
|
||||
FpEnrollProgress progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
gboolean fp_device_verify_sync (FpDevice *device,
|
||||
FpPrint *enrolled_print,
|
||||
GCancellable *cancellable,
|
||||
FpMatchCb match_cb,
|
||||
gpointer match_data,
|
||||
gboolean *match,
|
||||
FpPrint **print,
|
||||
GError **error);
|
||||
gboolean fp_device_identify_sync (FpDevice *device,
|
||||
GPtrArray *prints,
|
||||
GCancellable *cancellable,
|
||||
FpMatchCb match_cb,
|
||||
gpointer match_data,
|
||||
FpPrint **match,
|
||||
FpPrint **print,
|
||||
GError **error);
|
||||
FpImage * fp_device_capture_sync (FpDevice *device,
|
||||
gboolean wait_for_finger,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean fp_device_delete_print_sync (FpDevice *device,
|
||||
FpPrint *enrolled_print,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
GPtrArray * fp_device_list_prints_sync (FpDevice *device,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* FpImageDevice - An image based fingerprint reader device
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fpi-image-device.h"
|
||||
|
||||
#define IMG_ENROLL_STAGES 5
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FpiImageDeviceState state;
|
||||
gboolean active;
|
||||
gboolean cancelling;
|
||||
|
||||
gboolean enroll_await_on_pending;
|
||||
gint enroll_stage;
|
||||
|
||||
guint pending_activation_timeout_id;
|
||||
gboolean pending_activation_timeout_waiting_finger_off;
|
||||
|
||||
gint bz3_threshold;
|
||||
} FpImageDevicePrivate;
|
||||
|
||||
|
||||
void fpi_image_device_activate (FpImageDevice *image_device);
|
||||
void fpi_image_device_deactivate (FpImageDevice *image_device);
|
||||
@@ -1,326 +0,0 @@
|
||||
/*
|
||||
* FpImageDevice - An image based fingerprint reader device
|
||||
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define FP_COMPONENT "image_device"
|
||||
#include "fpi-log.h"
|
||||
|
||||
#include "fp-image-device-private.h"
|
||||
|
||||
#define BOZORTH3_DEFAULT_THRESHOLD 40
|
||||
|
||||
/**
|
||||
* SECTION: fp-image-device
|
||||
* @title: FpImageDevice
|
||||
* @short_description: Image device subclass
|
||||
*
|
||||
* This is a helper class for the commonly found image based devices.
|
||||
*/
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (FpImageDevice, fp_image_device, FP_TYPE_DEVICE)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_FPI_STATE,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties[N_PROPS];
|
||||
|
||||
enum {
|
||||
FPI_STATE_CHANGED,
|
||||
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/* TODO:
|
||||
* - sanitize_image seems a bit odd, in particular the sizing stuff.
|
||||
**/
|
||||
|
||||
/* Static helper functions */
|
||||
|
||||
static gboolean
|
||||
pending_activation_timeout (gpointer user_data)
|
||||
{
|
||||
FpImageDevice *self = FP_IMAGE_DEVICE (user_data);
|
||||
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
|
||||
|
||||
priv->pending_activation_timeout_id = 0;
|
||||
|
||||
if (priv->pending_activation_timeout_waiting_finger_off)
|
||||
fpi_device_action_error (FP_DEVICE (self),
|
||||
fpi_device_retry_new_msg (FP_DEVICE_RETRY_REMOVE_FINGER,
|
||||
"Remove finger before requesting another scan operation"));
|
||||
else
|
||||
fpi_device_action_error (FP_DEVICE (self),
|
||||
fpi_device_retry_new (FP_DEVICE_RETRY_GENERAL));
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
/* Callbacks/vfuncs */
|
||||
static void
|
||||
fp_image_device_open (FpDevice *device)
|
||||
{
|
||||
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (device);
|
||||
|
||||
/* Nothing special about opening an image device, just
|
||||
* forward the request. */
|
||||
cls->img_open (FP_IMAGE_DEVICE (device));
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_close (FpDevice *device)
|
||||
{
|
||||
FpImageDevice *self = FP_IMAGE_DEVICE (device);
|
||||
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self);
|
||||
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
|
||||
|
||||
/* In the close case we may need to wait/force deactivation first.
|
||||
* Three possible cases:
|
||||
* 1. We are inactive
|
||||
* -> immediately close
|
||||
* 2. We are waiting for finger off
|
||||
* -> imediately deactivate
|
||||
* 3. We are deactivating
|
||||
* -> handled by deactivate_complete */
|
||||
|
||||
if (!priv->active)
|
||||
cls->img_close (self);
|
||||
else if (priv->state != FPI_IMAGE_DEVICE_STATE_INACTIVE)
|
||||
fpi_image_device_deactivate (self);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_cancel_action (FpDevice *device)
|
||||
{
|
||||
FpImageDevice *self = FP_IMAGE_DEVICE (device);
|
||||
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
|
||||
FpiDeviceAction action;
|
||||
|
||||
action = fpi_device_get_current_action (device);
|
||||
|
||||
/* We can only cancel capture operations, in that case, deactivate and return
|
||||
* an error immediately. */
|
||||
if (action == FPI_DEVICE_ACTION_ENROLL ||
|
||||
action == FPI_DEVICE_ACTION_VERIFY ||
|
||||
action == FPI_DEVICE_ACTION_IDENTIFY ||
|
||||
action == FPI_DEVICE_ACTION_CAPTURE)
|
||||
{
|
||||
priv->cancelling = TRUE;
|
||||
fpi_image_device_deactivate (self);
|
||||
priv->cancelling = FALSE;
|
||||
|
||||
/* XXX: Some nicer way of doing this would be good. */
|
||||
fpi_device_action_error (FP_DEVICE (self),
|
||||
g_error_new (G_IO_ERROR,
|
||||
G_IO_ERROR_CANCELLED,
|
||||
"Device operation was cancelled"));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_start_capture_action (FpDevice *device)
|
||||
{
|
||||
FpImageDevice *self = FP_IMAGE_DEVICE (device);
|
||||
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
|
||||
FpiDeviceAction action;
|
||||
|
||||
/* There is just one action that we cannot support out
|
||||
* of the box, which is a capture without first waiting
|
||||
* for a finger to be on the device.
|
||||
*/
|
||||
action = fpi_device_get_current_action (device);
|
||||
if (action == FPI_DEVICE_ACTION_CAPTURE)
|
||||
{
|
||||
gboolean wait_for_finger;
|
||||
|
||||
fpi_device_get_capture_data (device, &wait_for_finger);
|
||||
|
||||
if (!wait_for_finger)
|
||||
{
|
||||
fpi_device_action_error (device, fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (action == FPI_DEVICE_ACTION_ENROLL)
|
||||
{
|
||||
FpPrint *enroll_print = NULL;
|
||||
|
||||
fpi_device_get_enroll_data (device, &enroll_print);
|
||||
fpi_print_set_type (enroll_print, FPI_PRINT_NBIS);
|
||||
}
|
||||
|
||||
priv->enroll_stage = 0;
|
||||
priv->enroll_await_on_pending = FALSE;
|
||||
|
||||
/* The device might still be deactivating from a previous call.
|
||||
* In that situation, try to wait for a bit before reporting back an
|
||||
* error (which will usually say that the user should remove the
|
||||
* finger).
|
||||
*/
|
||||
if (priv->state != FPI_IMAGE_DEVICE_STATE_INACTIVE || priv->active)
|
||||
{
|
||||
g_debug ("Got a new request while the device was still active");
|
||||
g_assert (priv->pending_activation_timeout_id == 0);
|
||||
priv->pending_activation_timeout_id =
|
||||
g_timeout_add (100, pending_activation_timeout, device);
|
||||
|
||||
if (priv->state == FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF)
|
||||
priv->pending_activation_timeout_waiting_finger_off = TRUE;
|
||||
else
|
||||
priv->pending_activation_timeout_waiting_finger_off = FALSE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* And activate the device; we rely on fpi_image_device_activate_complete()
|
||||
* to be called when done (or immediately). */
|
||||
fpi_image_device_activate (self);
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
static void
|
||||
fp_image_device_finalize (GObject *object)
|
||||
{
|
||||
FpImageDevice *self = (FpImageDevice *) object;
|
||||
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
|
||||
|
||||
g_assert (priv->active == FALSE);
|
||||
g_clear_handle_id (&priv->pending_activation_timeout_id, g_source_remove);
|
||||
|
||||
G_OBJECT_CLASS (fp_image_device_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_default_activate (FpImageDevice *self)
|
||||
{
|
||||
fpi_image_device_activate_complete (self, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_default_deactivate (FpImageDevice *self)
|
||||
{
|
||||
fpi_image_device_deactivate_complete (self, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
FpImageDevice *self = FP_IMAGE_DEVICE (object);
|
||||
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_FPI_STATE:
|
||||
g_value_set_enum (value, priv->state);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_constructed (GObject *obj)
|
||||
{
|
||||
FpImageDevice *self = FP_IMAGE_DEVICE (obj);
|
||||
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
|
||||
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (self);
|
||||
|
||||
/* Set default values. */
|
||||
fpi_device_set_nr_enroll_stages (FP_DEVICE (self), IMG_ENROLL_STAGES);
|
||||
|
||||
priv->bz3_threshold = BOZORTH3_DEFAULT_THRESHOLD;
|
||||
if (cls->bz3_threshold > 0)
|
||||
priv->bz3_threshold = cls->bz3_threshold;
|
||||
|
||||
G_OBJECT_CLASS (fp_image_device_parent_class)->constructed (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_class_init (FpImageDeviceClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
FpDeviceClass *fp_device_class = FP_DEVICE_CLASS (klass);
|
||||
|
||||
object_class->finalize = fp_image_device_finalize;
|
||||
object_class->get_property = fp_image_device_get_property;
|
||||
object_class->constructed = fp_image_device_constructed;
|
||||
|
||||
fp_device_class->open = fp_image_device_open;
|
||||
fp_device_class->close = fp_image_device_close;
|
||||
fp_device_class->enroll = fp_image_device_start_capture_action;
|
||||
fp_device_class->verify = fp_image_device_start_capture_action;
|
||||
fp_device_class->identify = fp_image_device_start_capture_action;
|
||||
fp_device_class->capture = fp_image_device_start_capture_action;
|
||||
|
||||
fp_device_class->cancel = fp_image_device_cancel_action;
|
||||
|
||||
/* Default implementations */
|
||||
klass->activate = fp_image_device_default_activate;
|
||||
klass->deactivate = fp_image_device_default_deactivate;
|
||||
|
||||
/**
|
||||
* FpImageDevice::fpi-image-device-state: (skip)
|
||||
*
|
||||
* This property is only for internal purposes.
|
||||
*
|
||||
* Stability: private
|
||||
*/
|
||||
properties[PROP_FPI_STATE] =
|
||||
g_param_spec_enum ("fpi-image-device-state",
|
||||
"Image Device State",
|
||||
"Private: The state of the image device",
|
||||
FPI_TYPE_IMAGE_DEVICE_STATE,
|
||||
FPI_IMAGE_DEVICE_STATE_INACTIVE,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
|
||||
|
||||
/**
|
||||
* FpImageDevice::fpi-image-device-state-changed: (skip)
|
||||
* @image_device: A #FpImageDevice
|
||||
* @new_state: The new state of the device
|
||||
*
|
||||
* This signal is only for internal purposes.
|
||||
*
|
||||
* Stability: private
|
||||
*/
|
||||
signals[FPI_STATE_CHANGED] =
|
||||
g_signal_new ("fpi-image-device-state-changed",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (FpImageDeviceClass, change_state),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, FPI_TYPE_IMAGE_DEVICE_STATE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
fp_image_device_init (FpImageDevice *self)
|
||||
{
|
||||
}
|
||||