fprint-list-udev-rules.c 3.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * Copyright (C) 2009 Red Hat <mjg@redhat.com> 
 * Copyright (C) 2008 Bastien Nocera <hadess@hadess.net>
 * Copyright (C) 2008 Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <config.h>
#include <stdio.h>

#include "fp_internal.h"

static const struct usb_id whitelist_id_table[] = {
27 28 29 30 31
    /* Unsupported (for now) Validity Sensors finger print readers */
    { .vendor = 0x138a, .product = 0x0090 }, /* Found on e.g. Lenovo T460s */
    { .vendor = 0x138a, .product = 0x0091 },
    { .vendor = 0x138a, .product = 0x0094 },
    { .vendor = 0x138a, .product = 0x0097 }, /* Found on e.g. Lenovo T470s */
32 33 34 35 36
    { 0, 0, 0, },
};

static const struct usb_id blacklist_id_table[] = {
    { .vendor = 0x0483, .product = 0x2016 },
37 38
    /* https://bugs.freedesktop.org/show_bug.cgi?id=66659 */
    { .vendor = 0x045e, .product = 0x00bb },
39 40 41 42 43
    { 0, 0, 0 },
};

struct fp_driver whitelist = {
    .id_table = whitelist_id_table,
44
    .full_name = "Hardcoded whitelist"
45 46
};

47 48
GHashTable *printed = NULL;

49 50
static void print_driver (struct fp_driver *driver)
{
51 52 53
    int i, j, blacklist, num_printed;

    num_printed = 0;
54 55

    for (i = 0; driver->id_table[i].vendor != 0; i++) {
56 57
        char *key;

58 59 60
	blacklist = 0;
	for (j = 0; blacklist_id_table[j].vendor != 0; j++) {
	    if (driver->id_table[i].vendor == blacklist_id_table[j].vendor &&
Bastien Nocera's avatar
Bastien Nocera committed
61
		driver->id_table[i].product == blacklist_id_table[j].product) {
62
		blacklist = 1;
63
		break;
64 65 66 67 68
	    }
	}
	if (blacklist)
	    continue;

69 70 71 72 73 74 75 76 77
	key = g_strdup_printf ("%04x:%04x", driver->id_table[i].vendor, driver->id_table[i].product);

	if (g_hash_table_lookup (printed, key) != NULL) {
	    g_free (key);
	    continue;
	}

	g_hash_table_insert (printed, key, GINT_TO_POINTER (1));

78 79 80
	if (num_printed == 0)
	    printf ("# %s\n", driver->full_name);

81
	printf ("SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ATTRS{dev}==\"*\", TEST==\"power/control\", ATTR{power/control}=\"auto\"\n", driver->id_table[i].vendor, driver->id_table[i].product);
82
	printf ("SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", ENV{LIBFPRINT_DRIVER}=\"%s\"\n", driver->id_table[i].vendor, driver->id_table[i].product, driver->full_name);
83
	num_printed++;
84
    }
85 86 87

    if (num_printed > 0)
        printf ("\n");
88 89 90 91 92 93 94 95 96
}

int main (int argc, char **argv)
{
    struct fp_driver **list;
    guint i;

    list = fprint_get_drivers ();

97 98
    printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

99 100 101 102 103 104
    for (i = 0; list[i] != NULL; i++) {
	print_driver (list[i]);
    }

    print_driver (&whitelist);

105 106
    g_hash_table_destroy (printed);

107 108
    return 0;
}