2 * Example fingerprint verification program
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
24 #include <libfprint/fprint.h>
26 struct fp_dscv_dev
*discover_device(struct fp_dscv_dev
**discovered_devs
)
28 struct fp_dscv_dev
*ddev
= NULL
;
31 for (i
= 0; ddev
= discovered_devs
[i
]; i
++) {
32 struct fp_driver
*drv
= fp_dscv_dev_get_driver(ddev
);
33 printf("Found device claimed by %s driver\n",
34 fp_driver_get_full_name(drv
));
41 struct fp_print_data
*enroll(struct fp_dev
*dev
) {
42 struct fp_print_data
*enrolled_print
= NULL
;
45 printf("You will need to successfully scan your finger %d times to "
46 "complete the process.\n", fp_dev_get_nr_enroll_stages(dev
));
50 printf("\nScan your finger now.\n");
51 r
= fp_enroll_finger(dev
, &enrolled_print
);
53 printf("Enroll failed with error %d\n", r
);
57 case FP_ENROLL_COMPLETE
:
58 printf("Enroll complete!\n");
61 printf("Enroll failed, something wen't wrong :(\n");
64 printf("Enroll stage passed. Yay!\n");
67 printf("Didn't quite catch that. Please try again.\n");
69 case FP_ENROLL_RETRY_TOO_SHORT
:
70 printf("Your swipe was too short, please try again.\n");
72 case FP_ENROLL_RETRY_CENTER_FINGER
:
73 printf("Didn't catch that, please center your finger on the "
74 "sensor and try again.\n");
76 case FP_ENROLL_RETRY_REMOVE_FINGER
:
77 printf("Scan failed, please remove your finger and then try "
81 } while (r
!= FP_ENROLL_COMPLETE
);
83 if (!enrolled_print
) {
84 fprintf(stderr
, "Enroll complete but no print?\n");
88 printf("Enrollment completed!\n\n");
89 return enrolled_print
;
92 int verify(struct fp_dev
*dev
, struct fp_print_data
*data
)
98 printf("\nScan your finger now.\n");
99 r
= fp_verify_finger(dev
, data
);
101 printf("verification failed with error %d :(\n", r
);
105 case FP_VERIFY_NO_MATCH
:
106 printf("NO MATCH!\n");
108 case FP_VERIFY_MATCH
:
111 case FP_VERIFY_RETRY
:
112 printf("Scan didn't quite work. Please try again.\n");
114 case FP_VERIFY_RETRY_TOO_SHORT
:
115 printf("Swipe was too short, please try again.\n");
117 case FP_VERIFY_RETRY_CENTER_FINGER
:
118 printf("Please center your finger on the sensor and try again.\n");
120 case FP_VERIFY_RETRY_REMOVE_FINGER
:
121 printf("Please remove finger from the sensor and try again.\n");
130 struct fp_dscv_dev
*ddev
;
131 struct fp_dscv_dev
**discovered_devs
;
133 struct fp_print_data
*data
;
137 fprintf(stderr
, "Failed to initialize libfprint\n");
141 discovered_devs
= fp_discover_devs();
142 if (!discovered_devs
) {
143 fprintf(stderr
, "Could not discover devices\n");
147 ddev
= discover_device(discovered_devs
);
149 fprintf(stderr
, "No devices detected.\n");
153 dev
= fp_dev_open(ddev
);
154 fp_dscv_devs_free(discovered_devs
);
156 fprintf(stderr
, "Could not open device.\n");
160 printf("Opened device. It's now time to enroll your finger.\n\n");
166 printf("Normally we'd save that print to disk, and recall it at some "
167 "point later when we want to authenticate the user who just "
168 "enrolled. In the interests of demonstration, we'll authenticate "
169 "that user immediately.\n");
175 printf("Verify again? [Y/n]? ");
176 fgets(buffer
, sizeof(buffer
), stdin
);
177 if (buffer
[0] != '\n' && buffer
[0] != 'y' && buffer
[0] != 'Y')
181 fp_print_data_free(data
);