2709c6dc8c
The basic model is that image drivers declare a fp_img_driver structure rather than a fp_driver struct. fp_img_driver will contain primitive imaging operations such as 'scan finger and return image'. The imgdev layer will generically implement the primitive fp_driver operations, and the imgdev layer will fix up the enroll/verify/etc pointers at driver registration time. Removed const from all fp_driver declarations, as these are now modified dynamically in the case of imaging drivers.
138 lines
3.4 KiB
C
138 lines
3.4 KiB
C
/*
|
|
* 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>
|
|
*
|
|
* 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 = NULL;
|
|
int i;
|
|
|
|
for (i = 0; ddev = discovered_devs[i]; i++) {
|
|
struct fp_driver *drv = fp_dscv_dev_get_driver(ddev);
|
|
printf("Found device claimed by %s driver\n",
|
|
fp_driver_get_full_name(drv));
|
|
return ddev;
|
|
}
|
|
|
|
return ddev;
|
|
}
|
|
|
|
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;
|
|
struct fp_dscv_dev *ddev;
|
|
struct fp_dscv_dev **discovered_devs;
|
|
struct fp_dev *dev;
|
|
struct fp_print_data *data;
|
|
|
|
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");
|
|
exit(1);
|
|
}
|
|
|
|
ddev = discover_device(discovered_devs);
|
|
if (!ddev) {
|
|
fprintf(stderr, "No devices detected.\n");
|
|
exit(1);
|
|
}
|
|
|
|
dev = fp_dev_open(ddev);
|
|
fp_dscv_devs_free(discovered_devs);
|
|
if (!dev) {
|
|
fprintf(stderr, "Could not open device.\n");
|
|
exit(1);
|
|
}
|
|
|
|
printf("Opened device. Loading previously enrolled right index finger "
|
|
"data...\n");
|
|
|
|
r = fp_print_data_load(dev, RIGHT_INDEX, &data);
|
|
if (r != 0) {
|
|
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);
|
|
return r;
|
|
}
|
|
|
|
|