Add upeksonly driver for UPEK TouchStrip sensor-only devices
[libfprint.git] / libfprint / core.c
blob1a45e1d6a4ec7a329366b06a1e3c3f049d982ddc
1 /*
2 * Core functions for libfprint
3 * Copyright (C) 2007-2008 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
20 #include <config.h>
21 #include <errno.h>
22 #include <stdio.h>
24 #include <glib.h>
25 #include <libusb.h>
27 #include "fp_internal.h"
29 libusb_context *fpi_usb_ctx = NULL;
30 GSList *opened_devices = NULL;
32 /**
33 * \mainpage libfprint API Reference
34 * libfprint is an open source library to provide access to fingerprint
35 * scanning devices. For more info, see the
36 * <a href="http://www.reactivated.net/fprint/Libfprint">libfprint project
37 * homepage</a>.
39 * This documentation is aimed at application developers who wish to integrate
40 * fingerprint-related functionality into their software. libfprint has been
41 * designed so that you only have to do this once - by integrating your
42 * software with libfprint, you'll be supporting all the fingerprint readers
43 * that we have got our hands on. As such, the API is rather general (and
44 * therefore hopefully easy to comprehend!), and does it's best to hide the
45 * technical details that required to operate the hardware.
47 * This documentation is not aimed at developers wishing to develop and
48 * contribute fingerprint device drivers to libfprint.
50 * Feedback on this API and it's associated documentation is appreciated. Was
51 * anything unclear? Does anything seem unreasonably complicated? Is anything
52 * missing? Let us know on the
53 * <a href="http://www.reactivated.net/fprint/Mailing_list">mailing list</a>.
55 * \section enrollment Enrollment
57 * Before you dive into the API, it's worth introducing a couple of concepts.
59 * The process of enrolling a finger is where you effectively scan your
60 * finger for the purposes of teaching the system what your finger looks like.
61 * This means that you scan your fingerprint, then the system processes it and
62 * stores some data about your fingerprint to refer to later.
64 * \section verification Verification
66 * Verification is what most people think of when they think about fingerprint
67 * scanning. The process of verification is effectively performing a fresh
68 * fingerprint scan, and then comparing that scan to a finger that was
69 * previously enrolled.
71 * As an example scenario, verification can be used to implement what people
72 * would picture as fingerprint login (i.e. fingerprint replaces password).
73 * For example:
74 * - I enroll my fingerprint through some software that trusts I am who I say
75 * I am. This is a prerequisite before I can perform fingerprint-based
76 * login for my account.
77 * - Some time later, I want to login to my computer. I enter my username,
78 * but instead of prompting me for a password, it asks me to scan my finger.
79 * I scan my finger.
80 * - The system compares the finger I just scanned to the one that was
81 * enrolled earlier. If the system decides that the fingerprints match,
82 * I am successfully logged in. Otherwise, the system informs me that I am
83 * not authorised to login as that user.
85 * \section identification Identification
87 * Identification is the process of comparing a freshly scanned fingerprint
88 * to a <em>collection</em> of previously enrolled fingerprints. For example,
89 * imagine there are 100 people in an organisation, and they all have enrolled
90 * their fingerprints. One user walks up to a fingerprint scanner and scans
91 * their finger. With <em>no other knowledge</em> of who that user might be,
92 * the system examines their fingerprint, looks in the database, and determines
93 * that the user is user number #61.
95 * In other words, verification might be seen as a one-to-one fingerprint
96 * comparison where you know the identity of the user that you wish to
97 * authenticate, whereas identification is a one-to-many comparison where you
98 * do not know the identity of the user that you wish to authenticate.
100 * \section compat_general Device and print compatibility
101 * Moving off generic conceptual ideas and onto libfprint-specific
102 * implementation details, here are some introductory notes regarding how
103 * libfprint copes with compatibility of fingerprints.
105 * libfprint deals with a whole variety of different fingerprint readers and
106 * the design includes considerations of compatibility and interoperability
107 * between multiple devices. Your application should also be prepared to
108 * work with more than one type of fingerprint reader and should consider that
109 * enrolled fingerprint X may not be compatible with the device the user has
110 * plugged in today.
112 * libfprint implements the principle that fingerprints from different devices
113 * are not necessarily compatible. For example, different devices may see
114 * significantly different areas of fingerprint surface, and comparing images
115 * between the devices would be unreliable. Also, devices can stretch and
116 * distort images in different ways.
118 * libfprint also implements the principle that in some cases, fingerprints
119 * <em>are</em> compatible between different devices. If you go and buy two
120 * identical fingerprint readers, it seems logical that you should be able
121 * to enroll on one and verify on another without problems.
123 * libfprint takes a fairly simplistic approach to these issues. Internally,
124 * fingerprint hardware is driven by individual drivers. libfprint enforces
125 * that a fingerprint that came from a device backed by driver X is never
126 * compared to a fingerprint that came from a device backed by driver Y.
128 * Additionally, libfprint is designed for the situation where a single driver
129 * may support a range of devices which differ in imaging or scanning
130 * properties. For example, a driver may support two ranges of devices which
131 * even though are programmed over the same interface, one device sees
132 * substantially less of the finger flesh, therefore images from the two
133 * device types should be incompatible despite being from the same driver. To
134 * implement this, each driver assigns a <em>device type</em> to each device
135 * that it detects based on its imaging characteristics. libfprint ensures that
136 * two prints being compared have the same device type.
138 * In summary, libfprint represents fingerprints in several internal structures
139 * and each representation will offer you a way of determining the
140 * \ref driver_id "driver ID" and \ref devtype "devtype" of the print in
141 * question. Prints are only compatible if the driver ID <b>and</b> devtypes
142 * match. libfprint does offer you some "is this print compatible?" helper
143 * functions, so you don't have to worry about these details too much.
145 * \section sync Synchronity/asynchronity
147 * Currently, all data acquisition operations are synchronous and can
148 * potentially block for extended periods of time. For example, the enroll
149 * function will block for an unpredictable amount of time until the user
150 * scans their finger.
152 * Alternative asynchronous/non-blocking functionality will be offered in
153 * future but has not been implemented yet.
155 * \section getting_started Getting started
157 * libfprint includes several simple functional examples under the examples/
158 * directory in the libfprint source distribution. Those are good starting
159 * points.
161 * Usually the first thing you want to do is determine which fingerprint
162 * devices are present. This is done through \ref dscv_dev "device discovery".
164 * Once you have found a device you would like to operate, you should open it.
165 * Refer to \ref dev "device operations". This section also details enrollment,
166 * image capture, and verification.
169 * That should be enough to get you started, but do remember there are
170 * documentation pages on other aspects of libfprint's API (see the modules
171 * page).
174 /** @defgroup core Core library operations */
177 * @defgroup dev Device operations
178 * In order to interact with fingerprint scanners, your software will
179 * interface primarily with libfprint's representation of devices, detailed
180 * on this page.
182 * \section enrolling Enrolling
183 * Enrolling is represented within libfprint as a multi-stage process. This
184 * slightly complicates things for application developers, but is required
185 * for a smooth process.
187 * Some devices require the user to scan their finger multiple times in
188 * order to complete the enrollment process. libfprint must return control
189 * to your application inbetween each scan in order for your application to
190 * instruct the user to swipe their finger again. Each scan is referred to
191 * as a stage, so a device that requires 3 scans for enrollment corresponds
192 * to you running 3 enrollment stages using libfprint.
194 * The fp_dev_get_nr_enroll_stages() function can be used to find out how
195 * many enroll stages are needed.
197 * In order to complete an enroll stage, you call an enroll function such
198 * as fp_enroll_finger(). The return of this function does not necessarily
199 * indicate that a stage has completed though, as the user may not have
200 * produced a good enough scan. Each stage may have to be retried several
201 * times.
203 * The exact semantics of the enroll functions are described in the
204 * fp_enroll_finger() documentation. You should pay careful attention to the
205 * details.
207 * \section imaging Imaging
208 * libfprint provides you with some ways to retrieve images of scanned
209 * fingers, such as the fp_dev_img_capture() function, or some enroll/verify
210 * function variants which provide images. You may wish to do something with
211 * such images in your application.
213 * However, you must be aware that not all hardware supported by libfprint
214 * operates like this. Most hardware does operate simply by sending
215 * fingerprint images to the host computer for further processing, but some
216 * devices do all fingerprint processing in hardware and do not present images
217 * to the host computer.
219 * You can use fp_dev_supports_imaging() to see if image capture is possible
220 * on a particular device. Your application must be able to cope with the
221 * fact that libfprint does support regular operations (e.g. enrolling and
222 * verification) on some devices which do not provide images.
224 * \section devtype Devtypes
225 * Internally, the \ref drv "driver" behind a device assigns a 32-bit
226 * <em>devtype</em> identifier to the device. This cannot be used as a unique
227 * ID for a specific device as many devices under the same range may share
228 * the same devtype. The devtype may even be 0 in all cases.
230 * The only reason you may be interested in retrieving the devtype for a
231 * device is for the purpose of checking if some print data is compatible
232 * with a device. libfprint uses the devtype as one way of checking that the
233 * print you are verifying is compatible with the device in question - the
234 * devtypes must be equal. This effectively allows drivers to support more
235 * than one type of device where the data from each one is not compatible with
236 * the other. Note that libfprint does provide you with helper functions to
237 * determine whether a print is compatible with a device, so under most
238 * circumstances, you don't have to worry about devtypes at all.
241 /** @defgroup dscv_dev Device discovery
242 * These functions allow you to scan the system for supported fingerprint
243 * scanning hardware. This is your starting point when integrating libfprint
244 * into your software.
246 * When you've identified a discovered device that you would like to control,
247 * you can open it with fp_dev_open(). Note that discovered devices may no
248 * longer be available at the time when you want to open them, for example
249 * the user may have unplugged the device.
252 /** @defgroup drv Driver operations
253 * Internally, libfprint is abstracted into various drivers to communicate
254 * with the different types of supported fingerprint readers. libfprint works
255 * hard so that you don't have to care about these internal abstractions,
256 * however there are some situations where you may be interested in a little
257 * behind-the-scenes driver info.
259 * You can obtain the driver for a device using fp_dev_get_driver(), which
260 * you can pass to the functions documented on this page.
262 * \section driver_id Driver IDs
263 * Each driver is assigned a unique ID by the project maintainer. These
264 * assignments are
265 * <a href="http://www.reactivated.net/fprint/Driver_ID_assignments">
266 * documented on the wiki</a> and will never change.
268 * The only reason you may be interested in retrieving the driver ID for a
269 * driver is for the purpose of checking if some print data is compatible
270 * with a device. libfprint uses the driver ID as one way of checking that
271 * the print you are trying to verify is compatible with the device in
272 * question - it ensures that enrollment data from one driver is never fed to
273 * another. Note that libfprint does provide you with helper functions to
274 * determine whether a print is compatible with a device, so under most
275 * circumstances, you don't have to worry about driver IDs at all.
278 static GSList *registered_drivers = NULL;
280 void fpi_log(enum fpi_log_level level, const char *component,
281 const char *function, const char *format, ...)
283 va_list args;
284 FILE *stream = stdout;
285 const char *prefix;
287 switch (level) {
288 case LOG_LEVEL_INFO:
289 prefix = "info";
290 break;
291 case LOG_LEVEL_WARNING:
292 stream = stderr;
293 prefix = "warning";
294 break;
295 case LOG_LEVEL_ERROR:
296 stream = stderr;
297 prefix = "error";
298 break;
299 case LOG_LEVEL_DEBUG:
300 stream = stderr;
301 prefix = "debug";
302 break;
303 default:
304 stream = stderr;
305 prefix = "unknown";
306 break;
309 fprintf(stream, "%s:%s [%s] ", component ? component : "fp", prefix,
310 function);
312 va_start (args, format);
313 vfprintf(stream, format, args);
314 va_end (args);
316 fprintf(stream, "\n");
319 static void register_driver(struct fp_driver *drv)
321 if (drv->id == 0) {
322 fp_err("not registering driver %s: driver ID is 0");
323 return;
325 registered_drivers = g_slist_prepend(registered_drivers, (gpointer) drv);
326 fp_dbg("registered driver %s", drv->name);
329 static struct fp_driver * const primitive_drivers[] = {
330 &upekts_driver,
333 static struct fp_img_driver * const img_drivers[] = {
334 &aes4000_driver,
335 &aes2501_driver,
336 &uru4000_driver,
337 &vcom5s_driver,
338 &upeksonly_driver,
339 /* &aes1610_driver,
340 &upektc_driver,
341 &fdu2000_driver, */
344 static void register_drivers(void)
346 unsigned int i;
348 for (i = 0; i < G_N_ELEMENTS(primitive_drivers); i++)
349 register_driver(primitive_drivers[i]);
351 for (i = 0; i < G_N_ELEMENTS(img_drivers); i++) {
352 struct fp_img_driver *imgdriver = img_drivers[i];
353 fpi_img_driver_setup(imgdriver);
354 register_driver(&imgdriver->driver);
358 static struct fp_driver *find_supporting_driver(libusb_device *udev,
359 const struct usb_id **usb_id)
361 int ret;
362 GSList *elem = registered_drivers;
363 struct libusb_device_descriptor dsc;
365 ret = libusb_get_device_descriptor(udev, &dsc);
366 if (ret < 0) {
367 fp_err("Failed to get device descriptor");
368 return NULL;
371 do {
372 struct fp_driver *drv = elem->data;
373 const struct usb_id *id;
375 for (id = drv->id_table; id->vendor; id++)
376 if (dsc.idVendor == id->vendor && dsc.idProduct == id->product) {
377 fp_dbg("driver %s supports USB device %04x:%04x",
378 drv->name, id->vendor, id->product);
379 *usb_id = id;
380 return drv;
382 } while ((elem = g_slist_next(elem)));
383 return NULL;
386 static struct fp_dscv_dev *discover_dev(libusb_device *udev)
388 const struct usb_id *usb_id;
389 struct fp_driver *drv = find_supporting_driver(udev, &usb_id);
390 struct fp_dscv_dev *ddev;
391 uint32_t devtype = 0;
393 if (!drv)
394 return NULL;
396 if (drv->discover) {
397 int r = drv->discover(usb_id, &devtype);
398 if (r < 0)
399 fp_err("%s discover failed, code %d", drv->name, r);
400 if (r <= 0)
401 return NULL;
404 ddev = g_malloc0(sizeof(*ddev));
405 ddev->drv = drv;
406 ddev->udev = udev;
407 ddev->driver_data = usb_id->driver_data;
408 ddev->devtype = devtype;
409 return ddev;
412 /** \ingroup dscv_dev
413 * Scans the system and returns a list of discovered devices. This is your
414 * entry point into finding a fingerprint reader to operate.
415 * \returns a NULL-terminated list of discovered devices. Must be freed with
416 * fp_dscv_devs_free() after use.
418 API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void)
420 GSList *tmplist = NULL;
421 struct fp_dscv_dev **list;
422 libusb_device *udev;
423 libusb_device **devs;
424 int dscv_count = 0;
425 int r;
426 int i = 0;
428 if (registered_drivers == NULL)
429 return NULL;
431 r = libusb_get_device_list(fpi_usb_ctx, &devs);
432 if (r < 0) {
433 fp_err("couldn't enumerate USB devices, error %d", r);
434 return NULL;
437 /* Check each device against each driver, temporarily storing successfully
438 * discovered devices in a GSList.
440 * Quite inefficient but excusable as we'll only be dealing with small
441 * sets of drivers against small sets of USB devices */
442 while ((udev = devs[i++]) != NULL) {
443 struct fp_dscv_dev *ddev = discover_dev(udev);
444 if (!ddev)
445 continue;
446 tmplist = g_slist_prepend(tmplist, (gpointer) ddev);
447 dscv_count++;
450 /* Convert our temporary GSList into a standard NULL-terminated pointer
451 * array. */
452 list = g_malloc(sizeof(*list) * (dscv_count + 1));
453 if (dscv_count > 0) {
454 GSList *elem = tmplist;
455 i = 0;
456 do {
457 list[i++] = elem->data;
458 } while ((elem = g_slist_next(elem)));
460 list[dscv_count] = NULL; /* NULL-terminate */
462 g_slist_free(tmplist);
463 return list;
466 /** \ingroup dscv_dev
467 * Free a list of discovered devices. This function destroys the list and all
468 * discovered devices that it included, so make sure you have opened your
469 * discovered device <b>before</b> freeing the list.
470 * \param devs the list of discovered devices. If NULL, function simply
471 * returns.
473 API_EXPORTED void fp_dscv_devs_free(struct fp_dscv_dev **devs)
475 int i;
476 if (!devs)
477 return;
479 for (i = 0; devs[i]; i++)
480 g_free(devs[i]);
481 g_free(devs);
484 /** \ingroup dscv_dev
485 * Gets the \ref drv "driver" for a discovered device.
486 * \param dev the discovered device
487 * \returns the driver backing the device
489 API_EXPORTED struct fp_driver *fp_dscv_dev_get_driver(struct fp_dscv_dev *dev)
491 return dev->drv;
494 /** \ingroup dscv_dev
495 * Gets the \ref devtype "devtype" for a discovered device.
496 * \param dev the discovered device
497 * \returns the devtype of the device
499 API_EXPORTED uint32_t fp_dscv_dev_get_devtype(struct fp_dscv_dev *dev)
501 return dev->devtype;
504 enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv)
506 switch (drv->type) {
507 case DRIVER_PRIMITIVE:
508 return PRINT_DATA_RAW;
509 case DRIVER_IMAGING:
510 return PRINT_DATA_NBIS_MINUTIAE;
511 default:
512 fp_err("unrecognised drv type %d", drv->type);
513 return PRINT_DATA_RAW;
517 /** \ingroup dscv_dev
518 * Determines if a specific \ref print_data "stored print" appears to be
519 * compatible with a discovered device.
520 * \param dev the discovered device
521 * \param data the print for compatibility checking
522 * \returns 1 if the print is compatible with the device, 0 otherwise
524 API_EXPORTED int fp_dscv_dev_supports_print_data(struct fp_dscv_dev *dev,
525 struct fp_print_data *data)
527 return fpi_print_data_compatible(dev->drv->id, dev->devtype,
528 fpi_driver_get_data_type(dev->drv), data->driver_id, data->devtype,
529 data->type);
532 /** \ingroup dscv_dev
533 * Determines if a specific \ref dscv_print "discovered print" appears to be
534 * compatible with a discovered device.
535 * \param dev the discovered device
536 * \param data the discovered print for compatibility checking
537 * \returns 1 if the print is compatible with the device, 0 otherwise
539 API_EXPORTED int fp_dscv_dev_supports_dscv_print(struct fp_dscv_dev *dev,
540 struct fp_dscv_print *data)
542 return fpi_print_data_compatible(dev->drv->id, dev->devtype, 0,
543 data->driver_id, data->devtype, 0);
546 /** \ingroup dscv_dev
547 * Searches a list of discovered devices for a device that appears to be
548 * compatible with a \ref print_data "stored print".
549 * \param devs a list of discovered devices
550 * \param data the print under inspection
551 * \returns the first discovered device that appears to support the print, or
552 * NULL if no apparently compatible devices could be found
554 API_EXPORTED struct fp_dscv_dev *fp_dscv_dev_for_print_data(struct fp_dscv_dev **devs,
555 struct fp_print_data *data)
557 struct fp_dscv_dev *ddev;
558 int i;
560 for (i = 0; (ddev = devs[i]); i++)
561 if (fp_dscv_dev_supports_print_data(ddev, data))
562 return ddev;
563 return NULL;
566 /** \ingroup dscv_dev
567 * Searches a list of discovered devices for a device that appears to be
568 * compatible with a \ref dscv_print "discovered print".
569 * \param devs a list of discovered devices
570 * \param print the print under inspection
571 * \returns the first discovered device that appears to support the print, or
572 * NULL if no apparently compatible devices could be found
574 API_EXPORTED struct fp_dscv_dev *fp_dscv_dev_for_dscv_print(struct fp_dscv_dev **devs,
575 struct fp_dscv_print *print)
577 struct fp_dscv_dev *ddev;
578 int i;
580 for (i = 0; (ddev = devs[i]); i++)
581 if (fp_dscv_dev_supports_dscv_print(ddev, print))
582 return ddev;
583 return NULL;
586 /** \ingroup dev
587 * Get the \ref drv "driver" for a fingerprint device.
588 * \param dev the device
589 * \returns the driver controlling the device
591 API_EXPORTED struct fp_driver *fp_dev_get_driver(struct fp_dev *dev)
593 return dev->drv;
596 /** \ingroup dev
597 * Gets the number of \ref enrolling "enroll stages" required to enroll a
598 * fingerprint with the device.
599 * \param dev the device
600 * \returns the number of enroll stages
602 API_EXPORTED int fp_dev_get_nr_enroll_stages(struct fp_dev *dev)
604 return dev->nr_enroll_stages;
607 /** \ingroup dev
608 * Gets the \ref devtype "devtype" for a device.
609 * \param dev the device
610 * \returns the devtype
612 API_EXPORTED uint32_t fp_dev_get_devtype(struct fp_dev *dev)
614 return dev->devtype;
617 /** \ingroup dev
618 * Determines if a stored print is compatible with a certain device.
619 * \param dev the device
620 * \param data the stored print
621 * \returns 1 if the print is compatible with the device, 0 if not
623 API_EXPORTED int fp_dev_supports_print_data(struct fp_dev *dev,
624 struct fp_print_data *data)
626 return fpi_print_data_compatible(dev->drv->id, dev->devtype,
627 fpi_driver_get_data_type(dev->drv), data->driver_id, data->devtype,
628 data->type);
631 /** \ingroup dev
632 * Determines if a \ref dscv_print "discovered print" appears to be compatible
633 * with a certain device.
634 * \param dev the device
635 * \param data the discovered print
636 * \returns 1 if the print is compatible with the device, 0 if not
638 API_EXPORTED int fp_dev_supports_dscv_print(struct fp_dev *dev,
639 struct fp_dscv_print *data)
641 return fpi_print_data_compatible(dev->drv->id, dev->devtype,
642 0, data->driver_id, data->devtype, 0);
645 /** \ingroup drv
646 * Retrieves the name of the driver. For example: "upekts"
647 * \param drv the driver
648 * \returns the driver name. Must not be modified or freed.
650 API_EXPORTED const char *fp_driver_get_name(struct fp_driver *drv)
652 return drv->name;
655 /** \ingroup drv
656 * Retrieves a descriptive name of the driver. For example: "UPEK TouchStrip"
657 * \param drv the driver
658 * \returns the descriptive name. Must not be modified or freed.
660 API_EXPORTED const char *fp_driver_get_full_name(struct fp_driver *drv)
662 return drv->full_name;
665 /** \ingroup drv
666 * Retrieves the driver ID code for a driver.
667 * \param drv the driver
668 * \returns the driver ID
670 API_EXPORTED uint16_t fp_driver_get_driver_id(struct fp_driver *drv)
672 return drv->id;
675 static struct fp_img_dev *dev_to_img_dev(struct fp_dev *dev)
677 if (dev->drv->type != DRIVER_IMAGING)
678 return NULL;
679 return dev->priv;
682 /** \ingroup dev
683 * Determines if a device has imaging capabilities. If a device has imaging
684 * capabilities you are able to perform imaging operations such as retrieving
685 * scan images using fp_dev_img_capture(). However, not all devices are
686 * imaging devices - some do all processing in hardware. This function will
687 * indicate which class a device in question falls into.
688 * \param dev the fingerprint device
689 * \returns 1 if the device is an imaging device, 0 if the device does not
690 * provide images to the host computer
692 API_EXPORTED int fp_dev_supports_imaging(struct fp_dev *dev)
694 return dev->drv->type == DRIVER_IMAGING;
697 /** \ingroup dev
698 * Determines if a device is capable of \ref identification "identification"
699 * through fp_identify_finger() and similar. Not all devices support this
700 * functionality.
701 * \param dev the fingerprint device
702 * \returns 1 if the device is capable of identification, 0 otherwise.
704 API_EXPORTED int fp_dev_supports_identification(struct fp_dev *dev)
706 return dev->drv->identify_start != NULL;
709 /** \ingroup dev
710 * Captures an \ref img "image" from a device. The returned image is the raw
711 * image provided by the device, you may wish to \ref img_std "standardize" it.
713 * If set, the <tt>unconditional</tt> flag indicates that the device should
714 * capture an image unconditionally, regardless of whether a finger is there
715 * or not. If unset, this function will block until a finger is detected on
716 * the sensor.
718 * \param dev the device
719 * \param unconditional whether to unconditionally capture an image, or to only capture when a finger is detected
720 * \param image a location to return the captured image. Must be freed with
721 * fp_img_free() after use.
722 * \return 0 on success, non-zero on error. -ENOTSUP indicates that either the
723 * unconditional flag was set but the device does not support this, or that the
724 * device does not support imaging.
725 * \sa fp_dev_supports_imaging()
727 API_EXPORTED int fp_dev_img_capture(struct fp_dev *dev, int unconditional,
728 struct fp_img **image)
730 struct fp_img_dev *imgdev = dev_to_img_dev(dev);
731 if (!imgdev) {
732 fp_dbg("image capture on non-imaging device");
733 return -ENOTSUP;
736 //return fpi_imgdev_capture(imgdev, unconditional, image);
737 /* FIXME reimplement async */
738 return -ENOTSUP;
741 /** \ingroup dev
742 * Gets the expected width of images that will be captured from the device.
743 * This function will return -1 for devices that are not
744 * \ref imaging "imaging devices". If the width of images from this device
745 * can vary, 0 will be returned.
746 * \param dev the device
747 * \returns the expected image width, or 0 for variable, or -1 for non-imaging
748 * devices.
750 API_EXPORTED int fp_dev_get_img_width(struct fp_dev *dev)
752 struct fp_img_dev *imgdev = dev_to_img_dev(dev);
753 if (!imgdev) {
754 fp_dbg("get image width for non-imaging device");
755 return -1;
758 return fpi_imgdev_get_img_width(imgdev);
761 /** \ingroup dev
762 * Gets the expected height of images that will be captured from the device.
763 * This function will return -1 for devices that are not
764 * \ref imaging "imaging devices". If the height of images from this device
765 * can vary, 0 will be returned.
766 * \param dev the device
767 * \returns the expected image height, or 0 for variable, or -1 for non-imaging
768 * devices.
770 API_EXPORTED int fp_dev_get_img_height(struct fp_dev *dev)
772 struct fp_img_dev *imgdev = dev_to_img_dev(dev);
773 if (!imgdev) {
774 fp_dbg("get image height for non-imaging device");
775 return -1;
778 return fpi_imgdev_get_img_height(imgdev);
781 /** \ingroup core
782 * Initialise libfprint. This function must be called before you attempt to
783 * use the library in any way.
784 * \return 0 on success, non-zero on error.
786 API_EXPORTED int fp_init(void)
788 int r;
789 fp_dbg("");
791 r = libusb_init(&fpi_usb_ctx);
792 if (r < 0)
793 return r;
795 register_drivers();
796 fpi_poll_init();
797 return 0;
800 /** \ingroup core
801 * Deinitialise libfprint. This function should be called during your program
802 * exit sequence. You must not use any libfprint functions after calling this
803 * function, unless you call fp_init() again.
805 API_EXPORTED void fp_exit(void)
807 fp_dbg("");
809 if (opened_devices) {
810 GSList *copy = g_slist_copy(opened_devices);
811 GSList *elem = copy;
812 fp_dbg("naughty app left devices open on exit!");
815 fp_dev_close((struct fp_dev *) elem->data);
816 while ((elem = g_slist_next(elem)));
818 g_slist_free(copy);
819 g_slist_free(opened_devices);
820 opened_devices = NULL;
823 fpi_data_exit();
824 fpi_poll_exit();
825 g_slist_free(registered_drivers);
826 registered_drivers = NULL;
827 libusb_exit(fpi_usb_ctx);