/**
 * Check if the device_id setted for obj is available.
 * 
 * @param env the Java Environment pointer. 
 * @param obj the jobject of the type jlibfprint/JlibFprint.
 * @param device output variable, it sets *device to the fp_dev specified in obj if is available.
 * @return true if the fp-device specified in obj is available and a pointer to it was setted in *device.
 */
bool get_device_id(JNIEnv* env, jobject obj, fp_dev** device)
{
    const jclass jlibClass = env->FindClass("jlibfprint/JlibFprint");
    jfieldID device_id = env->GetFieldID(jlibClass, "deviceID", "I");
    
    int devId = env->GetIntField(obj, device_id);
    bool found = (devId >= 0); // If devId < 0 => Not found
    fp_dscv_dev **fpList = fp_discover_devs();    
        
    /* devId is a list, we need to scan and check if it terminates before devId */
    for (int i = 0; i <= devId; i++) // All ids < devID must be != NULL
        if (fpList[i] == NULL) 
        {
            found = false;
            break;
        }
    
    if (found)
    {
        *device = fp_dev_open(fpList[devId]);   
        if (*device == NULL) found = false;
    }
    fp_dscv_devs_free(fpList);
    return found;
}
Exemple #2
0
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;
}
// Get the first fingerprint device
// @return int	< 0 denotes an error	> 0 denotes success
int get_fingerprint_device(struct fp_dev **device) {
    struct fp_dscv_dev **devices;
    int rtn;

	// Discover devices
    if (!(devices = fp_discover_devs())) {
        rtn = -1;
    }
    else {
    	// Open the first discovered device
        if (!(*device = fp_dev_open(*devices))) {
            rtn = -2;
        }
        else {
			rtn = 1;
        }

		// Free discovered devices
        fp_dscv_devs_free(devices);
    }

    return rtn;
}
Exemple #4
0
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;
}
Exemple #5
0
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;
}
Exemple #6
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;
}
Exemple #7
0
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;
}
Exemple #8
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. 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;
}
Exemple #9
0
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;
}