diff --git a/TODO b/TODO index 472960b..730ad01 100644 --- a/TODO +++ b/TODO @@ -1,14 +1,14 @@ LIBRARY ======= -fingerprint data representation +debugging messages +fingerprint data classifcation by device or device type storage mechanism -enrollment verification imaging support external imaging APIs identification external API documentation -test suite against NISTIR +test suite against NFIQ compliance set DRIVERS ======= diff --git a/examples/verify.c b/examples/verify.c index 7ada2c6..1a424fd 100644 --- a/examples/verify.c +++ b/examples/verify.c @@ -25,11 +25,10 @@ struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) { struct fp_dscv_dev *ddev = NULL; - struct fp_dscv_dev *tmpdev; int i; - for (i = 0; tmpdev = discovered_devs[i]; i++) { - const struct fp_driver *drv = fp_dscv_dev_get_driver(tmpdev); + for (i = 0; ddev = discovered_devs[i]; i++) { + const 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; @@ -38,11 +37,49 @@ struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs) return ddev; } +struct fp_print_data *enroll(struct fp_dev *dev) { + struct fp_print_data *enrolled_print = NULL; + enum fp_enroll_status status; + + printf("You will need to successfully scan your finger %d times to " + "complete the process.\n", fp_dev_get_nr_enroll_stages(dev)); + + do { + printf("Scan your finger now.\n"); + status = fp_enroll_finger(dev, &enrolled_print); + switch (status) { + 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; + } + } while (status != FP_ENROLL_COMPLETE); + + if (!enrolled_print) { + fprintf(stderr, "Enroll complete but no print?\n"); + return NULL; + } + + printf("got a print!\n"); + return enrolled_print; +} + int main(void) { int r; + int ret = 1; 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) { @@ -62,6 +99,21 @@ int main(void) exit(1); } + dev = fp_dev_open(ddev); fp_dscv_devs_free(discovered_devs); + if (!dev) { + fprintf(stderr, "Could not open device.\n"); + } + + printf("Opened device. It's now time to enroll your finger.\n\n"); + data = enroll(dev); + if (!data) + goto out_close; + + ret = 0; +out_close: + fp_dev_close(dev); + return ret; } + diff --git a/libfprint/core.c b/libfprint/core.c index 2fbaa48..d2fe52f 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -162,6 +162,11 @@ API_EXPORTED const struct fp_driver *fp_dev_get_driver(struct fp_dev *dev) return dev->drv; } +API_EXPORTED int fp_dev_get_nr_enroll_stages(struct fp_dev *dev) +{ + return dev->nr_enroll_stages; +} + API_EXPORTED const char *fp_driver_get_name(const struct fp_driver *drv) { return drv->name; @@ -172,6 +177,16 @@ API_EXPORTED const char *fp_driver_get_full_name(const struct fp_driver *drv) return drv->full_name; } +API_EXPORTED enum fp_enroll_status fp_enroll_finger(struct fp_dev *dev, + struct fp_print_data **print_data) +{ + const struct fp_driver *drv = dev->drv; + if (!dev->nr_enroll_stages || !drv->enroll) + return FP_ENROLL_FAIL; + + return drv->enroll(dev, print_data); +} + API_EXPORTED int fp_init(void) { usb_init(); @@ -179,3 +194,4 @@ API_EXPORTED int fp_init(void) return 0; } + diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 34d1231..0d380c4 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -32,6 +32,8 @@ struct fp_dev { const struct fp_driver *drv; usb_dev_handle *udev; void *priv; + + int nr_enroll_stages; }; struct usb_id { @@ -48,6 +50,8 @@ struct fp_driver { /* Device operations */ int (*init)(struct fp_dev *dev); void (*exit)(struct fp_dev *dev); + enum fp_enroll_status (*enroll)(struct fp_dev *dev, + struct fp_print_data **print_data); }; extern const struct fp_driver upekts_driver; diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 14a5f38..6a2ac9a 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -35,11 +35,23 @@ const struct fp_driver *fp_dscv_dev_get_driver(struct fp_dscv_dev *dev); struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev); void fp_dev_close(struct fp_dev *dev); const struct fp_driver *fp_dev_get_driver(struct fp_dev *dev); +int fp_dev_get_nr_enroll_stages(struct fp_dev *dev); /* Drivers */ const char *fp_driver_get_name(const struct fp_driver *drv); const char *fp_driver_get_full_name(const struct fp_driver *drv); +/* Enrolment */ +enum fp_enroll_status { + FP_ENROLL_COMPLETE, + FP_ENROLL_FAIL, + FP_ENROLL_PASS, + FP_ENROLL_RETRY, +}; + +enum fp_enroll_status fp_enroll_finger(struct fp_dev *dev, + struct fp_print_data **print_data); + /* Data handling */ void fp_print_data_free(struct fp_print_data *data);