static void mwin_cb_dev_changed(GtkWidget *widget, gpointer user_data) { GtkTreeIter iter; GtkWidget *dialog; struct fp_dscv_dev *ddev; int r; for_each_tab_call_op(clear); if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(mwin_devcombo), &iter)) { mwin_devstatus_update("No devices found."); return; } gtk_tree_model_get(GTK_TREE_MODEL(mwin_devmodel), &iter, 1, &ddev, -1); fp_dscv_prints_free(fp_dscv_prints); fp_dscv_prints = NULL; fp_dev_close(fpdev); dialog = run_please_wait_dialog("Opening device..."); r = fp_async_dev_open(ddev, dev_open_cb, dialog); if (r) mwin_devstatus_update("Could not open device."); }
int main(int argc, char **argv) { int r; r = fp_init(); if (r < 0) return r; gtk_init(&argc, &argv); gtk_window_set_default_icon_name("fprint_demo"); r = setup_pollfds(); if (r < 0) return r; mwin_create(); mwin_populate_devs(); mwin_select_first_dev(); gtk_main(); if (fpdev) fp_dev_close(fpdev); fp_exit(); return 0; }
/** * Enrolls a finger and returns the associated fp-data. * * @param env the Java Environment pointer. * @param obj the jobject of the type jlibfprint/JlibFprint. * @return the jlibfprint/JlibFprint$fp_print_data with the data just given by the scanner. * @throws an enroll_exception is raised is something gone wrong. */ JNIEXPORT jobject JNICALL Java_jlibfprint_JlibFprint_enroll_1finger(JNIEnv* env, jobject ref) { const jclass fpClass = env->FindClass("jlibfprint/JlibFprint$fp_print_data"); const jclass eeClass = env->FindClass("jlibfprint/JlibFprint$EnrollException"); /* Starts the library */ if (fp_init()) // Se differente da 0 => Exception { jobject enrollException = env->AllocObject(eeClass); jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I"); env->SetIntField(enrollException, eeExcp_id, UNABLE_TO_LOAD_LIBFPRINT); env->Throw((jthrowable)enrollException); return NULL; } fp_dev *device; fp_print_data* pdp; /* Gets the pointer to the device */ if (!get_device_id(env, ref, &device)) { jobject enrollException = env->AllocObject(eeClass); jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I"); env->SetIntField(enrollException, eeExcp_id, DEVICE_NOT_FOUND); env->Throw((jthrowable)enrollException); return NULL; } /* Enrolls the finger */ int ef = fp_enroll_finger(device, &pdp); /* Create a new obj to store the data */ jobject obj = env->AllocObject(fpClass); /* Raises an exception if the enrollment was not completed */ if (ef != FP_ENROLL_COMPLETE) { jobject enrollException = env->AllocObject(eeClass); jfieldID eeExcp_id = env->GetFieldID(eeClass, "enroll_exception", "I"); env->SetIntField(enrollException, eeExcp_id, ef); env->Throw((jthrowable)enrollException); } else { /* Fills the object with the enrollment data */ cfp2jfp(env, obj, pdp); memset(pdp, 0, sizeof(fp_print_data)); fp_print_data_free(pdp); } fp_dev_close(device); fp_exit(); return obj; }
void mwin_refresh_prints(void) { fp_dscv_prints_free(fp_dscv_prints); fp_dscv_prints = NULL; fp_dscv_prints = fp_discover_prints(); if (!fp_dscv_prints) { mwin_devstatus_update("Error loading enrolled prints."); if (fpdev) fp_dev_close(fpdev); fpdev = NULL; gtk_label_set_text(GTK_LABEL(mwin_drvname_label), NULL); gtk_label_set_text(GTK_LABEL(mwin_imgcapa_label), NULL); for_each_tab_call_op(clear); } else { for_each_tab_call_op(refresh); } }
int main(){ //initialize if (fp_init()){ printf("libfprint patladi!\n"); exit(1); //failure } //dev discovery struct fp_dscv_dev** ddevicelist; struct fp_dscv_dev* ddevice; if (!(ddevicelist = fp_discover_devs())){ //listeyi al printf("Device discovery calismadi!\n"); exit(1); //failure } if(!(ddevice = ddevicelist[0])){ //bos? TODO: 2 alet varsa nolacak? printf("Alet nerde?\n"); exit(1); //failure } print_driver_info(ddevice); //open dev struct fp_dev* device; if(!(device = fp_dev_open(ddevice))){ printf("Okuyucu baslamadi!\n"); exit(1); //failure } //get image fp_img_save_to_file(get_image(device), "./parmak.pgm"); //TODO: nasi freelenir lan bu? //cleanup fp_dev_close(device); fp_exit(); return 0; }
/** \ingroup dev * Opens and initialises a device. This is the function you call in order * to convert a \ref dscv_dev "discovered device" into an actual device handle * that you can perform operations with. * \param ddev the discovered device to open * \returns the opened device handle, or NULL on error */ API_EXPORTED struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev) { struct fp_dev *dev = NULL; struct sync_open_data *odata = g_malloc0(sizeof(*odata)); int r; fp_dbg(""); r = fp_async_dev_open(ddev, sync_open_cb, odata); if (r) goto out; while (!odata->dev) if (fp_handle_events() < 0) goto out; if (odata->status == 0) dev = odata->dev; else fp_dev_close(odata->dev); out: g_free(odata); return dev; }
/** \ingroup core * Deinitialise libfprint. This function should be called during your program * exit sequence. You must not use any libfprint functions after calling this * function, unless you call fp_init() again. */ API_EXPORTED void fp_exit(void) { fp_dbg(""); if (opened_devices) { GSList *copy = g_slist_copy(opened_devices); GSList *elem = copy; fp_dbg("naughty app left devices open on exit!"); do fp_dev_close((struct fp_dev *) elem->data); while ((elem = g_slist_next(elem))); g_slist_free(copy); g_slist_free(opened_devices); opened_devices = NULL; } fpi_data_exit(); fpi_poll_exit(); g_slist_free(registered_drivers); registered_drivers = NULL; libusb_exit(fpi_usb_ctx); }
int main(int argc, char *argv[]) { int r = 1, i; int next_option; enum fp_finger finger = RIGHT_INDEX; struct fp_dscv_dev *ddev; struct fp_dscv_dev **discovered_devs; struct fp_dev *dev; struct fp_print_data *data; const char * const short_options = "hf:"; const struct option long_options[] = { { "help", 0, NULL, 'h'}, { "enroll-finger", 1, NULL, 'f'}, { NULL, 0, NULL, 0} }; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': /* Printing usage */ printf("Usage: %s options\n", argv[0]); printf(" -h --help Display this usage information.\n" " -f --enroll-finger index Enroll finger with index.\n\n"); printf(" Valid indexes are:\n"); for (i = LEFT_THUMB; i <= RIGHT_LITTLE; i++) { printf(" %d - %s\n", i, finger_names[i]); } exit(1); break; case 'f': sscanf(optarg, "%d", &finger); if (finger < LEFT_THUMB || finger > RIGHT_LITTLE) { printf("%s: Invalid finger index.\n", argv[0]); printf("%s: Valid indexes are:\n", argv[0]); for (i = LEFT_THUMB; i <= RIGHT_LITTLE; i++) { printf("%s: %d - %s\n", argv[0], i, finger_names[i]); } exit(1); } break; case -1: /* Done with options. */ break; default: /* Unexpected option */ exit(1); } } while (next_option != -1); printf("This program will enroll your finger, " "unconditionally overwriting any selected print that was enrolled " "previously. If you want to continue, press enter, otherwise hit " "Ctrl+C\n"); getchar(); 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"); goto out; } ddev = discover_device(discovered_devs); if (!ddev) { fprintf(stderr, "No devices detected.\n"); goto out; } dev = fp_dev_open(ddev); fp_dscv_devs_free(discovered_devs); if (!dev) { fprintf(stderr, "Could not open device.\n"); goto out; } printf("Opened device. It's now time to enroll your finger.\n\n"); data = enroll(dev, finger); if (!data) goto out_close; r = fp_print_data_save(data, finger); if (r < 0) fprintf(stderr, "Data save failed, code %d\n", r); fp_print_data_free(data); out_close: fp_dev_close(dev); out: fp_exit(); return r; }
int main(){ //initialize if (fp_init()){ printf("libfprint patladi!\n"); exit(1); //failure } //dev discovery struct fp_dscv_dev** ddevicelist; struct fp_dscv_dev* ddevice; if (!(ddevicelist = fp_discover_devs())){ //listeyi al printf("Device discovery calismadi!\n"); exit(1); //failure } if(!(ddevice = ddevicelist[0])){ //bos? TODO: 2 alet varsa nolacak? printf("Alet nerde?\n"); exit(1); //failure } print_driver_info(ddevice); //open device struct fp_dev* device; if(!(device = fp_dev_open(ddevice))){ printf("Okuyucu baslamadi!\n"); exit(1); //failure } //enroll //printf("%d", fp_dev_get_nr_enroll_stages(device)); //tek olmali, cunku laptop. int done = 0; struct fp_print_data* guvenliparmak = NULL; while(!done){ switch(fp_enroll_finger_img(device, &guvenliparmak, NULL)){ case FP_ENROLL_FAIL: printf("Parmakizi alimi tamamlanamadi!\n"); exit(1); //fail case FP_ENROLL_COMPLETE: done = 1; printf("Parmakizi alimi basariyla tamamlandi.\n"); break; case FP_ENROLL_PASS: printf("Tanima asamasi basarili..\n"); break; default: printf("Yeniden deneyin!\n"); break; } } fp_print_data_free(guvenliparmak); //cleanup fp_dev_close(device); fp_exit(); return 0; }
int main(void) { struct fp_dscv_dev *ddev; struct fp_dscv_dev **discovered_devs; struct fp_dev *dev; struct fp_print_data *data; int r = fp_init(); if (r < 0) { fprintf(stderr, "Failed to initialize libfprint\n"); exit(1); } fp_set_debug(3); discovered_devs = fp_discover_devs(); if (!discovered_devs) { fprintf(stderr, "Could not discover devices\n"); goto out; } ddev = discover_device(discovered_devs); if (!ddev) { fprintf(stderr, "No devices detected.\n"); goto out; } dev = fp_dev_open(ddev); fp_dscv_devs_free(discovered_devs); if (!dev) { fprintf(stderr, "Could not open device.\n"); goto out; } printf("Opened device. It's now time to enroll your finger.\n\n"); data = enroll(dev); if (!data) goto out_close; 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); out_close: fp_dev_close(dev); out: fp_exit(); return r; }
int main (int argc, char **argv) { int r = 1; struct fp_dscv_dev *ddev; struct fp_dscv_dev **discovered_devs; struct fp_dev *dev; struct fp_print_data *data; int finger; finger = atoi(argv[3]); printf ("This program will enroll your right index finger, " "unconditionally overwriting any right-index print that was enrolled " "previously. If you want to continue, press enter, otherwise hit " "Ctrl+C\n"); getchar (); r = fp_init (); if (r < 0) { fprintf (stderr, "Failed to initialize libfprint\n"); exit (1); } fp_set_debug (3); discovered_devs = fp_discover_devs (); if (!discovered_devs) { fprintf (stderr, "Could not discover devices\n"); goto out; } ddev = discover_device (discovered_devs); if (!ddev) { fprintf (stderr, "No devices detected.\n"); goto out; } dev = fp_dev_open (ddev); fp_dscv_devs_free (discovered_devs); if (!dev) { fprintf (stderr, "Could not open device.\n"); goto out; } printf ("Opened device. It's now time to enroll your finger.\n\n"); data = enroll (dev); if (!data) goto out_close; r = fp_print_data_save (data, finger, argv[1], argv[2]); if (r < 0) fprintf (stderr, "Data save failed, code %d\n", r); fp_print_data_free (data); out_close: fp_dev_close (dev); out: fp_exit (); return r; }
int main(void) { struct fp_dscv_dev *ddev; struct fp_dscv_dev **discovered_devs; struct fp_dev *dev; struct fp_print_data *data; int r = fp_init(); if (r < 0) { fprintf(stderr, "Failed to initialize libfprint\n"); exit(1); } fp_set_debug(3); discovered_devs = fp_discover_devs(); if (!discovered_devs) { fprintf(stderr, "Could not discover devices\n"); goto out; } ddev = discover_device(discovered_devs); if (!ddev) { fprintf(stderr, "No devices detected.\n"); goto out; } dev = fp_dev_open(ddev); fp_dscv_devs_free(discovered_devs); if (!dev) { fprintf(stderr, "Could not open device.\n"); goto out; } 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); out: fp_exit(); return r; }
int main(void) { int r = 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) { printf("Failed to initialize fprint\n"); exit(1); } fp_set_debug(3); discovered_devs = fp_discover_devs(); if (!discovered_devs) { printf("Could not discover devices\n"); goto out; } ddev = discover_device(discovered_devs); if (!ddev) { printf("No devices detected.\n"); goto out; } dev = fp_dev_open(ddev); fp_dscv_devs_free(discovered_devs); if (!dev) { printf("Could not open device.\n"); goto out; } printf("Opened device. " "enrolling...\n"); r = fp_print_data_load(dev, RIGHT_INDEX, &data); if (r != 0) { printf("Failed to load fingerprint,\n"); goto out_close; } printf("Print loaded. Try 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); out: fp_exit(); return r; }