2 * Core functions for libfprint
3 * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "fp_internal.h"
30 * \mainpage libfprint API Reference
31 * libfprint is an open source library to provide access to fingerprint
32 * scanning devices. For more info, see the
33 * <a href="http://www.reactivated.net/fprint/Libfprint">libfprint project
36 * This documentation is aimed at application developers who wish to integrate
37 * fingerprint-related functionality into their software. libfprint has been
38 * designed so that you only have to do this once - by integrating your
39 * software with libfprint, you'll be supporting all the fingerprint readers
40 * that we have got our hands on. As such, the API is rather general (and
41 * therefore hopefully easy to comprehend!), and does it's best to hide the
42 * technical details that required to operate the hardware.
44 * This documentation is not aimed at developers wishing to develop and
45 * contribute fingerprint device drivers to libfprint.
47 * Feedback on this API and it's associated documentation is appreciated. Was
48 * anything unclear? Does anything seem unreasonably complicated? Is anything
49 * missing? Let us know on the
50 * <a href="http://www.reactivated.net/fprint/Mailing_list">mailing list</a>.
52 * \section enrollment Enrollment
54 * Before you dive into the API, it's worth introducing a couple of concepts.
56 * The process of enrolling a finger is where you effectively scan your
57 * finger for the purposes of teaching the system what your finger looks like.
58 * This means that you scan your fingerprint, then the system processes it and
59 * stores some data about your fingerprint to refer to later.
61 * \section verification Verification
63 * Verification is what most people think of when they think about fingerprint
64 * scanning. The process of verification is effectively performing a fresh
65 * fingerprint scan, and then comparing that scan to a finger that was
66 * previously enrolled.
68 * As an example scenario, verification can be used to implement what people
69 * would picture as fingerprint login (i.e. fingerprint replaces password).
71 * - I enroll my fingerprint through some software that trusts I am who I say
72 * I am. This is a prerequisite before I can perform fingerprint-based
73 * login for my account.
74 * - Some time later, I want to login to my computer. I enter my username,
75 * but instead of prompting me for a password, it asks me to scan my finger.
77 * - The system compares the finger I just scanned to the one that was
78 * enrolled earlier. If the system decides that the fingerprints match,
79 * I am successfully logged in. Otherwise, the system informs me that I am
80 * not authorised to login as that user.
82 * \section identification Identification
84 * libfprint supports enrollment and verification as described above. Although
85 * libfprint does not yet support identification (it is planned), it is worth
86 * introducing the concept to give you a complete picture.
88 * Identification is the process of comparing a freshly scanned fingerprint
89 * to a <em>collection</em> of previously enrolled fingerprints. For example,
90 * imagine there are 100 people in an organisation, and they all have enrolled
91 * their fingerprints. One user walks up to a fingerprint scanner and scans
92 * their finger. With <em>no other knowledge</em> of who that user might be,
93 * the system examines their fingerprint, looks in the database, and determines
94 * that the user is user number #61.
96 * In other words, verification might be seen as a one-to-one fingerprint
97 * comparison where you know the identity of the user that you wish to
98 * authenticate, whereas identification is a one-to-many comparison where you
99 * do not know the identity of the user that you wish to authenticate.
101 * \section compat_general Device and print compatibility
102 * Moving off generic conceptual ideas and onto libfprint-specific
103 * implementation details, here are some introductory notes regarding how
104 * libfprint copes with compatibility of fingerprints.
106 * libfprint deals with a whole variety of different fingerprint readers and
107 * the design includes considerations of compatibility and interoperability
108 * between multiple devices. Your application should also be prepared to
109 * work with more than one type of fingerprint reader and should consider that
110 * enrolled fingerprint X may not be compatible with the device the user has
113 * libfprint implements the principle that fingerprints from different devices
114 * are not necessarily compatible. For example, different devices may see
115 * significantly different areas of fingerprint surface, and comparing images
116 * between the devices would be unreliable. Also, devices can stretch and
117 * distort images in different ways.
119 * libfprint also implements the principle that in some cases, fingerprints
120 * <em>are</em> compatible between different devices. If you go and buy two
121 * identical fingerprint readers, it seems logical that you should be able
122 * to enroll on one and verify on another without problems.
124 * libfprint takes a fairly simplistic approach to these issues. Internally,
125 * fingerprint hardware is driven by individual drivers. libfprint enforces
126 * that a fingerprint that came from a device backed by driver X is never
127 * compared to a fingerprint that came from a device backed by driver Y.
129 * Additionally, libfprint is designed for the situation where a single driver
130 * may support a range of devices which differ in imaging or scanning
131 * properties. For example, a driver may support two ranges of devices which
132 * even though are programmed over the same interface, one device sees
133 * substantially less of the finger flesh, therefore images from the two
134 * device types should be incompatible despite being from the same driver. To
135 * implement this, each driver assigns a <em>device type</em> to each device
136 * that it detects based on its imaging characteristics. libfprint ensures that
137 * two prints being compared have the same device type.
139 * In summary, libfprint represents fingerprints in several internal structures
140 * and each representation will offer you a way of determining the
141 * \ref driver_id "driver ID" and \ref devtype "devtype" of the print in
142 * question. Prints are only compatible if the driver ID <b>and</b> devtypes
143 * match. libfprint does offer you some "is this print compatible?" helper
144 * functions, so you don't have to worry about these details too much.
146 * \section Synchronity/asynchronity
148 * Currently, all data acquisition operations are synchronous and can
149 * potentially block for extended periods of time. For example, the enroll
150 * function will block for an unpredictable amount of time until the user
151 * scans their finger.
153 * Alternative asynchronous/non-blocking functionality will be offered in
154 * future but has not been implemented yet.
156 * \section getting_started Getting started
158 * libfprint includes several simple functional examples under the examples/
159 * directory in the libfprint source distribution. Those are good starting
162 * Usually the first thing you want to do is determine which fingerprint
163 * devices are present. This is done through \ref dscv_dev "device discovery".
165 * Once you have found a device you would like to operate, you should open it.
166 * Refer to \ref dev "device operations". This section also details enrollment,
167 * image capture, and verification.
170 * That should be enough to get you started, but do remember there are
171 * documentation pages on other aspects of libfprint's API (see the modules
175 /** @defgroup core Core library operations */
178 * @defgroup dev Device operations
179 * In order to interact with fingerprint scanners, your software will
180 * interface primarily with libfprint's representation of devices, detailed
183 * \section enrolling Enrolling
184 * Enrolling is represented within libfprint as a multi-stage process. This
185 * slightly complicates things for application developers, but is required
186 * for a smooth process.
188 * Some devices require the user to scan their finger multiple times in
189 * order to complete the enrollment process. libfprint must return control
190 * to your application inbetween each scan in order for your application to
191 * instruct the user to swipe their finger again. Each scan is referred to
192 * as a stage, so a device that requires 3 scans for enrollment corresponds
193 * to you running 3 enrollment stages using libfprint.
195 * The fp_dev_get_nr_enroll_stages() function can be used to find out how
196 * many enroll stages are needed.
198 * In order to complete an enroll stage, you call an enroll function such
199 * as fp_enroll_finger(). The return of this function does not necessarily
200 * indicate that a stage has completed though, as the user may not have
201 * produced a good enough scan. Each stage may have to be retried several
204 * The exact semantics of the enroll functions are described in the
205 * fp_enroll_finger() documentation. You should pay careful attention to the
208 * \section imaging Imaging
209 * libfprint provides you with some ways to retrieve images of scanned
210 * fingers, such as the fp_dev_img_capture() function, or some enroll/verify
211 * function variants which provide images. You may wish to do something with
212 * such images in your application.
214 * However, you must be aware that not all hardware supported by libfprint
215 * operates like this. Most hardware does operate simply by sending
216 * fingerprint images to the host computer for further processing, but some
217 * devices do all fingerprint processing in hardware and do not present images
218 * to the host computer.
220 * You can use fp_dev_supports_imaging() to see if image capture is possible
221 * on a particular device. Your application must be able to cope with the
222 * fact that libfprint does support regular operations (e.g. enrolling and
223 * verification) on some devices which do not provide images.
225 * \section devtype Devtypes
226 * Internally, the \ref drv "driver" behind a device assigns a 32-bit
227 * <em>devtype</em> identifier to the device. This cannot be used as a unique
228 * ID for a specific device as many devices under the same range may share
229 * the same devtype. The devtype may even be 0 in all cases.
231 * The only reason you may be interested in retrieving the devtype for a
232 * device is for the purpose of checking if some print data is compatible
233 * with a device. libfprint uses the devtype as one way of checking that the
234 * print you are verifying is compatible with the device in question - the
235 * devtypes must be equal. This effectively allows drivers to support more
236 * than one type of device where the data from each one is not compatible with
237 * the other. Note that libfprint does provide you with helper functions to
238 * determine whether a print is compatible with a device, so under most
239 * circumstances, you don't have to worry about devtypes at all.
242 /** @defgroup dscv_dev Device discovery
243 * These functions allow you to scan the system for supported fingerprint
244 * scanning hardware. This is your starting point when integrating libfprint
245 * into your software.
247 * When you've identified a discovered device that you would like to control,
248 * you can open it with fp_dev_open(). Note that discovered devices may no
249 * longer be available at the time when you want to open them, for example
250 * the user may have unplugged the device.
253 /** @defgroup drv Driver operations
254 * Internally, libfprint is abstracted into various drivers to communicate
255 * with the different types of supported fingerprint readers. libfprint works
256 * hard so that you don't have to care about these internal abstractions,
257 * however there are some situations where you may be interested in a little
258 * behind-the-scenes driver info.
260 * You can obtain the driver for a device using fp_dev_get_driver(), which
261 * you can pass to the functions documented on this page.
263 * \section driver_id Driver IDs
264 * Each driver is assigned a unique ID by the project maintainer. These
266 * <a href="http://www.reactivated.net/fprint/Driver_ID_assignments">
267 * documented on the wiki</a> and will never change.
269 * The only reason you may be interested in retrieving the driver ID for a
270 * driver is for the purpose of checking if some print data is compatible
271 * with a device. libfprint uses the driver ID as one way of checking that
272 * the print you are trying to verify is compatible with the device in
273 * question - it ensures that enrollment data from one driver is never fed to
274 * another. Note that libfprint does provide you with helper functions to
275 * determine whether a print is compatible with a device, so under most
276 * circumstances, you don't have to worry about driver IDs at all.
279 static GSList
*registered_drivers
= NULL
;
280 static GSList
*opened_devices
= NULL
;
282 void fpi_log(enum fpi_log_level level
, const char *component
,
283 const char *function
, const char *format
, ...)
286 FILE *stream
= stdout
;
293 case LOG_LEVEL_WARNING
:
297 case LOG_LEVEL_ERROR
:
301 case LOG_LEVEL_DEBUG
:
311 fprintf(stream
, "%s:%s [%s] ", component
? component
: "fp", prefix
,
314 va_start (args
, format
);
315 vfprintf(stream
, format
, args
);
318 fprintf(stream
, "\n");
321 static void register_driver(struct fp_driver
*drv
)
324 fp_err("not registering driver %s: driver ID is 0");
327 registered_drivers
= g_slist_prepend(registered_drivers
, (gpointer
) drv
);
328 fp_dbg("registered driver %s", drv
->name
);
331 static struct fp_driver
* const primitive_drivers
[] = {
335 static struct fp_img_driver
* const img_drivers
[] = {
340 static void register_drivers(void)
344 for (i
= 0; i
< ARRAY_SIZE(primitive_drivers
); i
++)
345 register_driver(primitive_drivers
[i
]);
347 for (i
= 0; i
< ARRAY_SIZE(img_drivers
); i
++) {
348 struct fp_img_driver
*imgdriver
= img_drivers
[i
];
349 fpi_img_driver_setup(imgdriver
);
350 register_driver(&imgdriver
->driver
);
354 static struct fp_driver
*find_supporting_driver(struct usb_device
*udev
,
355 const struct usb_id
**usb_id
)
357 GSList
*elem
= registered_drivers
;
360 struct fp_driver
*drv
= elem
->data
;
361 const struct usb_id
*id
;
363 for (id
= drv
->id_table
; id
->vendor
; id
++)
364 if (udev
->descriptor
.idVendor
== id
->vendor
&&
365 udev
->descriptor
.idProduct
== id
->product
) {
366 fp_dbg("driver %s supports USB device %04x:%04x",
367 drv
->name
, id
->vendor
, id
->product
);
371 } while (elem
= g_slist_next(elem
));
375 static struct fp_dscv_dev
*discover_dev(struct usb_device
*udev
)
377 const struct usb_id
*usb_id
;
378 struct fp_driver
*drv
= find_supporting_driver(udev
, &usb_id
);
379 struct fp_dscv_dev
*ddev
;
380 uint32_t devtype
= 0;
386 int r
= drv
->discover(usb_id
, &devtype
);
388 fp_err("%s discover failed, code %d", drv
->name
, r
);
393 ddev
= g_malloc0(sizeof(*ddev
));
396 ddev
->driver_data
= usb_id
->driver_data
;
397 ddev
->devtype
= devtype
;
401 /** \ingroup dscv_dev
402 * Scans the system and returns a list of discovered devices. This is your
403 * entry point into finding a fingerprint reader to operate.
404 * \returns a NULL-terminated list of discovered devices. Must be freed with
405 * fp_dscv_devs_free() after use.
407 API_EXPORTED
struct fp_dscv_dev
**fp_discover_devs(void)
409 GSList
*tmplist
= NULL
;
410 struct fp_dscv_dev
**list
;
411 struct usb_device
*udev
;
415 if (registered_drivers
== NULL
)
421 /* Check each device against each driver, temporarily storing successfully
422 * discovered devices in a GSList.
424 * Quite inefficient but excusable as we'll only be dealing with small
425 * sets of drivers against small sets of USB devices */
426 for (bus
= usb_get_busses(); bus
; bus
= bus
->next
)
427 for (udev
= bus
->devices
; udev
; udev
= udev
->next
) {
428 struct fp_dscv_dev
*ddev
= discover_dev(udev
);
431 tmplist
= g_slist_prepend(tmplist
, (gpointer
) ddev
);
435 /* Convert our temporary GSList into a standard NULL-terminated pointer
437 list
= g_malloc(sizeof(*list
) * (dscv_count
+ 1));
438 if (dscv_count
> 0) {
439 GSList
*elem
= tmplist
;
442 list
[i
++] = elem
->data
;
443 } while (elem
= g_slist_next(elem
));
445 list
[dscv_count
] = NULL
; /* NULL-terminate */
447 g_slist_free(tmplist
);
451 /** \ingroup dscv_dev
452 * Free a list of discovered devices. This function destroys the list and all
453 * discovered devices that it included, so make sure you have opened your
454 * discovered device <b>before</b> freeing the list.
455 * \param devs the list of discovered devices
457 API_EXPORTED
void fp_dscv_devs_free(struct fp_dscv_dev
**devs
)
463 for (i
= 0; devs
[i
]; i
++)
468 /** \ingroup dscv_dev
469 * Gets the \ref drv "driver" for a discovered device.
470 * \param dev the discovered device
471 * \returns the driver backing the device
473 API_EXPORTED
struct fp_driver
*fp_dscv_dev_get_driver(struct fp_dscv_dev
*dev
)
478 /** \ingroup dscv_dev
479 * Gets the \ref devtype "devtype" for a discovered device.
480 * \param dev the discovered device
481 * \returns the devtype of the device
483 API_EXPORTED
uint32_t fp_dscv_dev_get_devtype(struct fp_dscv_dev
*dev
)
488 enum fp_print_data_type
fpi_driver_get_data_type(struct fp_driver
*drv
)
491 case DRIVER_PRIMITIVE
:
492 return PRINT_DATA_RAW
;
494 return PRINT_DATA_NBIS_MINUTIAE
;
496 fp_err("unrecognised drv type %d", drv
->type
);
497 return PRINT_DATA_RAW
;
501 /** \ingroup dscv_dev
502 * Determines if a specific \ref print_data "stored print" appears to be
503 * compatible with a discovered device.
504 * \param dev the discovered device
505 * \param data the print for compatibility checking
506 * \returns 1 if the print is compatible with the device, 0 otherwise
508 API_EXPORTED
int fp_dscv_dev_supports_print_data(struct fp_dscv_dev
*dev
,
509 struct fp_print_data
*data
)
511 return fpi_print_data_compatible(dev
->drv
->id
, dev
->devtype
,
512 fpi_driver_get_data_type(dev
->drv
), data
->driver_id
, data
->devtype
,
516 /** \ingroup dscv_dev
517 * Determines if a specific \ref dscv_print "discovered print" appears to be
518 * compatible with a discovered device.
519 * \param dev the discovered device
520 * \param data the discovered print for compatibility checking
521 * \returns 1 if the print is compatible with the device, 0 otherwise
523 API_EXPORTED
int fp_dscv_dev_supports_dscv_print(struct fp_dscv_dev
*dev
,
524 struct fp_dscv_print
*data
)
526 return fpi_print_data_compatible(dev
->drv
->id
, dev
->devtype
, 0,
527 data
->driver_id
, data
->devtype
, 0);
530 /** \ingroup dscv_dev
531 * Searches a list of discovered devices for a device that appears to be
532 * compatible with a \ref print_data "stored print".
533 * \param devs a list of discovered devices
534 * \param data the print under inspection
535 * \returns the first discovered device that appears to support the print, or
536 * NULL if no apparently compatible devices could be found
538 API_EXPORTED
struct fp_dscv_dev
*fp_dscv_dev_for_print_data(struct fp_dscv_dev
**devs
,
539 struct fp_print_data
*data
)
541 struct fp_dscv_dev
*ddev
;
544 for (i
= 0; ddev
= devs
[i
]; i
++)
545 if (fp_dscv_dev_supports_print_data(ddev
, data
))
550 /** \ingroup dscv_dev
551 * Searches a list of discovered devices for a device that appears to be
552 * compatible with a \ref dscv_print "discovered print".
553 * \param devs a list of discovered devices
554 * \param print the print under inspection
555 * \returns the first discovered device that appears to support the print, or
556 * NULL if no apparently compatible devices could be found
558 API_EXPORTED
struct fp_dscv_dev
*fp_dscv_dev_for_dscv_print(struct fp_dscv_dev
**devs
,
559 struct fp_dscv_print
*print
)
561 struct fp_dscv_dev
*ddev
;
564 for (i
= 0; ddev
= devs
[i
]; i
++)
565 if (fp_dscv_dev_supports_dscv_print(ddev
, print
))
571 * Opens and initialises a device. This is the function you call in order
572 * to convert a \ref dscv_dev "discovered device" into an actual device handle
573 * that you can perform operations with.
574 * \param ddev the discovered device to open
575 * \returns the opened device handle, or NULL on error
577 API_EXPORTED
struct fp_dev
*fp_dev_open(struct fp_dscv_dev
*ddev
)
580 struct fp_driver
*drv
= ddev
->drv
;
583 usb_dev_handle
*udevh
= usb_open(ddev
->udev
);
585 fp_err("usb_open failed");
589 dev
= g_malloc0(sizeof(*dev
));
592 dev
->__enroll_stage
= -1;
595 r
= drv
->init(dev
, ddev
->driver_data
);
597 fp_err("device initialisation failed, driver=%s", drv
->name
);
605 opened_devices
= g_slist_prepend(opened_devices
, (gpointer
) dev
);
609 /* performs close operation without modifying opened_devices list */
610 static void do_close(struct fp_dev
*dev
)
614 usb_close(dev
->udev
);
619 * Close a device. You must call this function when you are finished using
620 * a fingerprint device.
621 * \param dev the device to close
623 API_EXPORTED
void fp_dev_close(struct fp_dev
*dev
)
627 if (g_slist_index(opened_devices
, (gconstpointer
) dev
) == -1)
628 fp_err("device %p not in opened list!", dev
);
629 opened_devices
= g_slist_remove(opened_devices
, (gconstpointer
) dev
);
634 * Get the \ref drv "driver" for a fingerprint device.
635 * \param dev the device
636 * \returns the driver controlling the device
638 API_EXPORTED
struct fp_driver
*fp_dev_get_driver(struct fp_dev
*dev
)
644 * Gets the number of \ref enrolling "enroll stages" required to enroll a
645 * fingerprint with the device.
646 * \param dev the device
647 * \returns the number of enroll stages
649 API_EXPORTED
int fp_dev_get_nr_enroll_stages(struct fp_dev
*dev
)
651 return dev
->nr_enroll_stages
;
655 * Gets the \ref devtype "devtype" for a device.
656 * \param dev the device
657 * \returns the devtype
659 API_EXPORTED
uint32_t fp_dev_get_devtype(struct fp_dev
*dev
)
665 * Determines if a stored print is compatible with a certain device.
666 * \param dev the device
667 * \param data the stored print
668 * \returns 1 if the print is compatible with the device, 0 if not
670 API_EXPORTED
int fp_dev_supports_print_data(struct fp_dev
*dev
,
671 struct fp_print_data
*data
)
673 return fpi_print_data_compatible(dev
->drv
->id
, dev
->devtype
,
674 fpi_driver_get_data_type(dev
->drv
), data
->driver_id
, data
->devtype
,
679 * Determines if a \ref dscv_print "discovered print" appears to be compatible
680 * with a certain device.
681 * \param dev the device
682 * \param data the discovered print
683 * \returns 1 if the print is compatible with the device, 0 if not
685 API_EXPORTED
int fp_dev_supports_dscv_print(struct fp_dev
*dev
,
686 struct fp_dscv_print
*data
)
688 return fpi_print_data_compatible(dev
->drv
->id
, dev
->devtype
,
689 0, data
->driver_id
, data
->devtype
, 0);
693 * Retrieves the name of the driver. For example: "upekts"
694 * \param drv the driver
695 * \returns the driver name. Must not be modified or freed.
697 API_EXPORTED
const char *fp_driver_get_name(struct fp_driver
*drv
)
703 * Retrieves a descriptive name of the driver. For example: "UPEK TouchStrip"
704 * \param drv the driver
705 * \returns the descriptive name. Must not be modified or freed.
707 API_EXPORTED
const char *fp_driver_get_full_name(struct fp_driver
*drv
)
709 return drv
->full_name
;
713 * Retrieves the driver ID code for a driver.
714 * \param drv the driver
715 * \returns the driver ID
717 API_EXPORTED
uint16_t fp_driver_get_driver_id(struct fp_driver
*drv
)
722 static struct fp_img_dev
*dev_to_img_dev(struct fp_dev
*dev
)
724 if (dev
->drv
->type
!= DRIVER_IMAGING
)
730 * Determines if a device has imaging capabilities. If a device has imaging
731 * capabilities you are able to perform imaging operations such as retrieving
732 * scan images using fp_dev_img_capture(). However, not all devices are
733 * imaging devices - some do all processing in hardware. This function will
734 * indicate which class a device in question falls into.
735 * \param dev the fingerprint device
736 * \returns 1 if the device is an imaging device, 0 if the device does not
737 * provide images to the host computer
739 API_EXPORTED
int fp_dev_supports_imaging(struct fp_dev
*dev
)
741 return dev
->drv
->type
== DRIVER_IMAGING
;
745 * Captures an \ref img "image" from a device. The returned image is the raw
746 * image provided by the device, you may wish to \ref img_std "standardize" it.
748 * If set, the <tt>unconditional</tt> flag indicates that the device should
749 * capture an image unconditionally, regardless of whether a finger is there
750 * or not. If unset, this function will block until a finger is detected on
753 * \param dev the device
754 * \param unconditional whether to unconditionally capture an image, or to only capture when a finger is detected
755 * \param image a location to return the captured image. Must be freed with
756 * fp_img_free() after use.
757 * \return 0 on success, non-zero on error. -ENOTSUP indicates that either the
758 * unconditional flag was set but the device does not support this, or that the
759 * device does not support imaging.
760 * \sa fp_dev_supports_imaging()
762 API_EXPORTED
int fp_dev_img_capture(struct fp_dev
*dev
, int unconditional
,
763 struct fp_img
**image
)
765 struct fp_img_dev
*imgdev
= dev_to_img_dev(dev
);
767 fp_dbg("image capture on non-imaging device");
771 return fpi_imgdev_capture(imgdev
, unconditional
, image
);
775 * Gets the expected width of images that will be captured from the device.
776 * This function will return -1 for devices that are not
777 * \ref imaging "imaging devices". If the width of images from this device
778 * can vary, 0 will be returned.
779 * \param dev the device
780 * \returns the expected image width, or 0 for variable, or -1 for non-imaging
783 API_EXPORTED
int fp_dev_get_img_width(struct fp_dev
*dev
)
785 struct fp_img_dev
*imgdev
= dev_to_img_dev(dev
);
787 fp_dbg("get image width for non-imaging device");
791 return fpi_imgdev_get_img_width(imgdev
);
795 * Gets the expected height of images that will be captured from the device.
796 * This function will return -1 for devices that are not
797 * \ref imaging "imaging devices". If the height of images from this device
798 * can vary, 0 will be returned.
799 * \param dev the device
800 * \returns the expected image height, or 0 for variable, or -1 for non-imaging
803 API_EXPORTED
int fp_dev_get_img_height(struct fp_dev
*dev
)
805 struct fp_img_dev
*imgdev
= dev_to_img_dev(dev
);
807 fp_dbg("get image height for non-imaging device");
811 return fpi_imgdev_get_img_height(imgdev
);
815 * Performs an enroll stage. See \ref enrolling for an explanation of enroll
818 * If no enrollment is in process, this kicks of the process and runs the
819 * first stage. If an enrollment is already in progress, calling this
820 * function runs the next stage, which may well be the last.
822 * A negative error code may be returned from any stage. When this occurs,
823 * further calls to the enroll function will start a new enrollment process,
824 * i.e. a negative error code indicates that the enrollment process has been
825 * aborted. These error codes only ever indicate unexpected internal errors
828 * The RETRY codes from #fp_enroll_result may be returned from any enroll
829 * stage. These codes indicate that the scan was not succesful in that the
830 * user did not position their finger correctly or similar. When a RETRY code
831 * is returned, the enrollment stage is <b>not</b> advanced, so the next call
832 * into this function will retry the current stage again. The current stage may
833 * need to be retried several times.
835 * The fp_enroll_result#FP_ENROLL_FAIL code may be returned from any enroll
836 * stage. This code indicates that even though the scans themselves have been
837 * acceptable, data processing applied to these scans produces incomprehensible
838 * results. In other words, the user may have been scanning a different finger
839 * for each stage or something like that. Like negative error codes, this
840 * return code indicates that the enrollment process has been aborted.
842 * The fp_enroll_result#FP_ENROLL_PASS code will only ever be returned for
843 * non-final stages. This return code indicates that the scan was acceptable
844 * and the next call into this function will advance onto the next enroll
847 * The fp_enroll_result#FP_ENROLL_COMPLETE code will only ever be returned
848 * from the final enroll stage. It indicates that enrollment completed
849 * successfully, and that print_data has been assigned to point to the
850 * resultant enrollment data. The print_data parameter will not be modified
851 * during any other enrollment stages, hence it is actually legal to pass NULL
852 * as this argument for all but the final stage.
854 * \param dev the device
855 * \param print_data a location to return the resultant enrollment data from
856 * the final stage. Must be freed with fp_print_data_free() after use.
857 * \return negative code on error, otherwise a code from #fp_verify_result
859 API_EXPORTED
int fp_enroll_finger(struct fp_dev
*dev
,
860 struct fp_print_data
**print_data
)
862 struct fp_driver
*drv
= dev
->drv
;
864 int stage
= dev
->__enroll_stage
;
865 gboolean initial
= FALSE
;
867 if (!dev
->nr_enroll_stages
|| !drv
->enroll
) {
868 fp_err("driver %s has 0 enroll stages or no enroll func",
875 dev
->__enroll_stage
= ++stage
;
878 if (stage
>= dev
->nr_enroll_stages
) {
879 fp_err("exceeding number of enroll stages for device claimed by "
880 "driver %s (%d stages)", drv
->name
, dev
->nr_enroll_stages
);
881 dev
->__enroll_stage
= -1;
884 fp_dbg("%s will handle enroll stage %d/%d%s", drv
->name
, stage
,
885 dev
->nr_enroll_stages
- 1, initial
? " (initial)" : "");
887 ret
= drv
->enroll(dev
, initial
, stage
, print_data
);
889 fp_err("enroll failed with code %d", ret
);
890 dev
->__enroll_stage
= -1;
895 fp_dbg("enroll stage passed");
896 dev
->__enroll_stage
= stage
+ 1;
898 case FP_ENROLL_COMPLETE
:
899 fp_dbg("enroll complete");
900 dev
->__enroll_stage
= -1;
902 case FP_ENROLL_RETRY
:
903 fp_dbg("enroll should retry");
905 case FP_ENROLL_RETRY_TOO_SHORT
:
906 fp_dbg("swipe was too short, enroll should retry");
908 case FP_ENROLL_RETRY_CENTER_FINGER
:
909 fp_dbg("finger was not centered, enroll should retry");
911 case FP_ENROLL_RETRY_REMOVE_FINGER
:
912 fp_dbg("scan failed, remove finger and retry");
915 fp_err("enroll failed");
916 dev
->__enroll_stage
= -1;
919 fp_err("unrecognised return code %d", ret
);
920 dev
->__enroll_stage
= -1;
927 * Performs a new scan and verify it against a previously enrolled print.
928 * \param dev the device to perform the scan.
929 * \param enrolled_print the print to verify against. Must have been previously
930 * enrolled with a device compatible to the device selected to perform the scan.
931 * \return negative code on error, otherwise a code from #fp_verify_result
933 API_EXPORTED
int fp_verify_finger(struct fp_dev
*dev
,
934 struct fp_print_data
*enrolled_print
)
936 struct fp_driver
*drv
= dev
->drv
;
939 if (!enrolled_print
) {
940 fp_err("no print given");
945 fp_err("driver %s has no verify func", drv
->name
);
949 if (!fp_dev_supports_print_data(dev
, enrolled_print
)) {
950 fp_err("print is not compatible with device");
954 fp_dbg("to be handled by %s", drv
->name
);
955 r
= drv
->verify(dev
, enrolled_print
);
957 fp_dbg("verify error %d", r
);
962 case FP_VERIFY_NO_MATCH
:
963 fp_dbg("result: no match");
965 case FP_VERIFY_MATCH
:
966 fp_dbg("result: match");
968 case FP_VERIFY_RETRY
:
969 fp_dbg("verify should retry");
971 case FP_VERIFY_RETRY_TOO_SHORT
:
972 fp_dbg("swipe was too short, verify should retry");
974 case FP_VERIFY_RETRY_CENTER_FINGER
:
975 fp_dbg("finger was not centered, verify should retry");
977 case FP_VERIFY_RETRY_REMOVE_FINGER
:
978 fp_dbg("scan failed, remove finger and retry");
981 fp_err("unrecognised return code %d", r
);
989 * Initialise libfprint. This function must be called before you attempt to
990 * use the library in any way.
991 * \return 0 on success, non-zero on error.
993 API_EXPORTED
int fp_init(void)
1002 * Deinitialise libfprint. This function should be called during your program
1003 * exit sequence. You must not use any libfprint functions after calling this
1004 * function, unless you call fp_init() again.
1006 API_EXPORTED
void fp_exit(void)
1008 GSList
*elem
= opened_devices
;
1013 fp_dbg("naughty app left a device open on exit!");
1014 do_close((struct fp_dev
*) elem
->data
);
1015 } while (elem
= g_slist_next(elem
));
1016 g_slist_free(opened_devices
);
1017 opened_devices
= NULL
;
1021 g_slist_free(registered_drivers
);
1022 registered_drivers
= NULL
;