2007-10-08 16:15:21 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2007-10-13 23:45:49 +00:00
|
|
|
#include <unistd.h>
|
2007-10-08 16:15:21 +00:00
|
|
|
|
|
|
|
#include <libfprint/fprint.h>
|
|
|
|
|
|
|
|
struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
|
|
|
|
{
|
2007-12-01 13:00:33 +00:00
|
|
|
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));
|
2007-10-08 16:15:21 +00:00
|
|
|
return ddev;
|
|
|
|
}
|
|
|
|
|
2007-10-08 18:53:50 +00:00
|
|
|
struct fp_print_data *enroll(struct fp_dev *dev) {
|
|
|
|
struct fp_print_data *enrolled_print = NULL;
|
2007-10-13 23:45:49 +00:00
|
|
|
int r;
|
2007-10-08 18:53:50 +00:00
|
|
|
|
|
|
|
printf("You will need to successfully scan your finger %d times to "
|
|
|
|
"complete the process.\n", fp_dev_get_nr_enroll_stages(dev));
|
|
|
|
|
|
|
|
do {
|
2007-10-13 23:45:49 +00:00
|
|
|
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) {
|
2007-10-08 18:53:50 +00:00
|
|
|
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;
|
2007-10-12 14:27:23 +00:00
|
|
|
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;
|
2007-10-13 23:45:49 +00:00
|
|
|
case FP_ENROLL_RETRY_REMOVE_FINGER:
|
|
|
|
printf("Scan failed, please remove your finger and then try "
|
|
|
|
"again.\n");
|
|
|
|
break;
|
2007-10-08 18:53:50 +00:00
|
|
|
}
|
2007-10-13 23:45:49 +00:00
|
|
|
} while (r != FP_ENROLL_COMPLETE);
|
2007-10-08 18:53:50 +00:00
|
|
|
|
|
|
|
if (!enrolled_print) {
|
|
|
|
fprintf(stderr, "Enroll complete but no print?\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-13 23:58:45 +00:00
|
|
|
printf("Enrollment completed!\n\n");
|
2007-10-08 18:53:50 +00:00
|
|
|
return enrolled_print;
|
|
|
|
}
|
|
|
|
|
2007-10-13 23:58:45 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-10-08 16:15:21 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
2007-11-13 14:32:31 +00:00
|
|
|
int r = 1;
|
2007-10-08 16:15:21 +00:00
|
|
|
struct fp_dscv_dev *ddev;
|
|
|
|
struct fp_dscv_dev **discovered_devs;
|
2007-10-08 18:53:50 +00:00
|
|
|
struct fp_dev *dev;
|
|
|
|
struct fp_print_data *data;
|
2007-10-08 16:15:21 +00:00
|
|
|
|
2018-05-24 10:42:47 +00:00
|
|
|
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
|
|
|
setenv ("LIBUSB_DEBUG", "3", 0);
|
|
|
|
|
2007-10-08 16:15:21 +00:00
|
|
|
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");
|
2007-11-13 14:32:31 +00:00
|
|
|
goto out;
|
2007-10-08 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ddev = discover_device(discovered_devs);
|
|
|
|
if (!ddev) {
|
|
|
|
fprintf(stderr, "No devices detected.\n");
|
2007-11-13 14:32:31 +00:00
|
|
|
goto out;
|
2007-10-08 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
2007-10-08 18:53:50 +00:00
|
|
|
dev = fp_dev_open(ddev);
|
2007-10-08 16:15:21 +00:00
|
|
|
fp_dscv_devs_free(discovered_devs);
|
2007-10-08 18:53:50 +00:00
|
|
|
if (!dev) {
|
|
|
|
fprintf(stderr, "Could not open device.\n");
|
2007-11-13 14:32:31 +00:00
|
|
|
goto out;
|
2007-10-08 18:53:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Opened device. It's now time to enroll your finger.\n\n");
|
|
|
|
data = enroll(dev);
|
|
|
|
if (!data)
|
|
|
|
goto out_close;
|
|
|
|
|
2007-10-13 23:58:45 +00:00
|
|
|
|
|
|
|
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);
|
2007-10-08 18:53:50 +00:00
|
|
|
out_close:
|
|
|
|
fp_dev_close(dev);
|
2007-11-13 14:32:31 +00:00
|
|
|
out:
|
|
|
|
fp_exit();
|
2007-10-16 13:23:30 +00:00
|
|
|
return r;
|
2007-10-08 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
2007-10-08 18:53:50 +00:00
|
|
|
|