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
= discovered_devs
[0];
29 struct fp_driver
*drv
;
33 drv
= fp_dscv_dev_get_driver(ddev
);
34 printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv
));
38 struct fp_print_data
*enroll(struct fp_dev
*dev
) {
39 struct fp_print_data
*enrolled_print
= NULL
;
42 printf("You will need to successfully scan your finger %d times to "
43 "complete the process.\n", fp_dev_get_nr_enroll_stages(dev
));
47 printf("\nScan your finger now.\n");
48 r
= fp_enroll_finger(dev
, &enrolled_print
);
50 printf("Enroll failed with error %d\n", r
);
54 case FP_ENROLL_COMPLETE
:
55 printf("Enroll complete!\n");
58 printf("Enroll failed, something wen't wrong :(\n");
61 printf("Enroll stage passed. Yay!\n");
64 printf("Didn't quite catch that. Please try again.\n");
66 case FP_ENROLL_RETRY_TOO_SHORT
:
67 printf("Your swipe was too short, please try again.\n");
69 case FP_ENROLL_RETRY_CENTER_FINGER
:
70 printf("Didn't catch that, please center your finger on the "
71 "sensor and try again.\n");
73 case FP_ENROLL_RETRY_REMOVE_FINGER
:
74 printf("Scan failed, please remove your finger and then try "
78 } while (r
!= FP_ENROLL_COMPLETE
);
80 if (!enrolled_print
) {
81 fprintf(stderr
, "Enroll complete but no print?\n");
85 printf("Enrollment completed!\n\n");
86 return enrolled_print
;
89 int verify(struct fp_dev
*dev
, struct fp_print_data
*data
)
95 printf("\nScan your finger now.\n");
96 r
= fp_verify_finger(dev
, data
);
98 printf("verification failed with error %d :(\n", r
);
102 case FP_VERIFY_NO_MATCH
:
103 printf("NO MATCH!\n");
105 case FP_VERIFY_MATCH
:
108 case FP_VERIFY_RETRY
:
109 printf("Scan didn't quite work. Please try again.\n");
111 case FP_VERIFY_RETRY_TOO_SHORT
:
112 printf("Swipe was too short, please try again.\n");
114 case FP_VERIFY_RETRY_CENTER_FINGER
:
115 printf("Please center your finger on the sensor and try again.\n");
117 case FP_VERIFY_RETRY_REMOVE_FINGER
:
118 printf("Please remove finger from the sensor and try again.\n");
127 struct fp_dscv_dev
*ddev
;
128 struct fp_dscv_dev
**discovered_devs
;
130 struct fp_print_data
*data
;
134 fprintf(stderr
, "Failed to initialize libfprint\n");
139 discovered_devs
= fp_discover_devs();
140 if (!discovered_devs
) {
141 fprintf(stderr
, "Could not discover devices\n");
145 ddev
= discover_device(discovered_devs
);
147 fprintf(stderr
, "No devices detected.\n");
151 dev
= fp_dev_open(ddev
);
152 fp_dscv_devs_free(discovered_devs
);
154 fprintf(stderr
, "Could not open device.\n");
158 printf("Opened device. It's now time to enroll your finger.\n\n");
164 printf("Normally we'd save that print to disk, and recall it at some "
165 "point later when we want to authenticate the user who just "
166 "enrolled. In the interests of demonstration, we'll authenticate "
167 "that user immediately.\n");
173 printf("Verify again? [Y/n]? ");
174 fgets(buffer
, sizeof(buffer
), stdin
);
175 if (buffer
[0] != '\n' && buffer
[0] != 'y' && buffer
[0] != 'Y')
179 fp_print_data_free(data
);