Compare commits

...

1 commit

Author SHA1 Message Date
Bastien Nocera
197edac702 lib: Generate driver IDs, instead of hard-coding them
Instead of adding driver IDs by hand to a header file, generate the
driver ID from the (hopefully unique) name of the driver.

This means one file less for driver authors to modify, and one possible
source of merge conflicts less as well.

However, this means that already enrolled fingerprints will need to be
enrolled again, as the driver IDs will have changed compared to their
old on-disk value.
2019-06-12 16:50:01 +02:00
28 changed files with 13 additions and 87 deletions

View file

@ -71,10 +71,7 @@
<title>Driver IDs</title> <title>Driver IDs</title>
<para> <para>
Each driver is assigned a unique ID by the project maintainer. These Each driver is assigned a unique ID automatically based on the driver name.
assignments are
<ulink url="https://gitlab.freedesktop.org/libfprint/libfprint/blob/master/libfprint/drivers/driver_ids.h">
documented in the sources</ulink> and will never change.
</para> </para>
<para> <para>

View file

@ -17,7 +17,6 @@ private_headers = [
'aes2660.h', 'aes2660.h',
'aes3k.h', 'aes3k.h',
'aesx660.h', 'aesx660.h',
'driver_ids.h',
'elan.h', 'elan.h',
'upek_proto.h', 'upek_proto.h',
'upeksonly.h', 'upeksonly.h',

View file

@ -817,7 +817,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver aes1610_driver = { struct fp_img_driver aes1610_driver = {
.driver = { .driver = {
.id = AES1610_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "AuthenTec AES1610", .full_name = "AuthenTec AES1610",
.id_table = id_table, .id_table = id_table,

View file

@ -94,7 +94,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver aes1660_driver = { struct fp_img_driver aes1660_driver = {
.driver = { .driver = {
.id = AES1660_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "AuthenTec AES1660", .full_name = "AuthenTec AES1660",
.id_table = id_table, .id_table = id_table,

View file

@ -859,7 +859,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver aes2501_driver = { struct fp_img_driver aes2501_driver = {
.driver = { .driver = {
.id = AES2501_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "AuthenTec AES2501", .full_name = "AuthenTec AES2501",
.id_table = id_table, .id_table = id_table,

View file

@ -603,7 +603,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver aes2550_driver = { struct fp_img_driver aes2550_driver = {
.driver = { .driver = {
.id = AES2550_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "AuthenTec AES2550/AES2810", .full_name = "AuthenTec AES2550/AES2810",
.id_table = id_table, .id_table = id_table,

View file

@ -97,7 +97,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver aes2660_driver = { struct fp_img_driver aes2660_driver = {
.driver = { .driver = {
.id = AES2660_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "AuthenTec AES2660", .full_name = "AuthenTec AES2660",
.id_table = id_table, .id_table = id_table,

View file

@ -162,7 +162,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver aes3500_driver = { struct fp_img_driver aes3500_driver = {
.driver = { .driver = {
.id = AES3500_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "AuthenTec AES3500", .full_name = "AuthenTec AES3500",
.id_table = id_table, .id_table = id_table,

View file

@ -159,7 +159,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver aes4000_driver = { struct fp_img_driver aes4000_driver = {
.driver = { .driver = {
.id = AES4000_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "AuthenTec AES4000", .full_name = "AuthenTec AES4000",
.id_table = id_table, .id_table = id_table,

View file

@ -1,47 +0,0 @@
/*
* Driver IDs
* Copyright (C) 2012 Vasily Khoruzhick <anarsoul@gmail.com>
*
* 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
*/
#ifndef __DRIVER_IDS
#define __DRIVER_IDS
enum {
UPEKTS_ID = 1,
URU4000_ID = 2,
AES4000_ID = 3,
AES2501_ID = 4,
UPEKTC_ID = 5,
AES1610_ID = 6,
FDU2000_ID = 7,
VCOM5S_ID = 8,
UPEKSONLY_ID = 9,
VFS101_ID = 10,
VFS301_ID = 11,
AES2550_ID = 12,
/* UPEKE2_ID = 13 */
AES1660_ID = 14,
AES2660_ID = 15,
AES3500_ID = 16,
UPEKTC_IMG_ID = 17,
ETES603_ID = 18,
VFS5011_ID = 19,
VFS0050_ID = 20,
ELAN_ID = 21,
};
#endif

View file

@ -970,7 +970,6 @@ static void dev_deactivate(struct fp_img_dev *dev)
struct fp_img_driver elan_driver = { struct fp_img_driver elan_driver = {
.driver = { .driver = {
.id = ELAN_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "ElanTech Fingerprint Sensor", .full_name = "ElanTech Fingerprint Sensor",
.id_table = elan_id_table, .id_table = elan_id_table,

View file

@ -36,7 +36,6 @@
#define FP_COMPONENT "etes603" #define FP_COMPONENT "etes603"
#include "drivers_api.h" #include "drivers_api.h"
#include "driver_ids.h"
/* libusb defines */ /* libusb defines */
#define EP_IN 0x81 #define EP_IN 0x81
@ -1478,7 +1477,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver etes603_driver = { struct fp_img_driver etes603_driver = {
.driver = { .driver = {
.id = ETES603_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "EgisTec ES603", .full_name = "EgisTec ES603",
.id_table = id_table, .id_table = id_table,

View file

@ -302,7 +302,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver fdu2000_driver = { struct fp_img_driver fdu2000_driver = {
.driver = { .driver = {
.id = FDU2000_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "Secugen FDU 2000", .full_name = "Secugen FDU 2000",
.id_table = id_table, .id_table = id_table,

View file

@ -1345,7 +1345,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver upeksonly_driver = { struct fp_img_driver upeksonly_driver = {
.driver = { .driver = {
.id = UPEKSONLY_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "UPEK TouchStrip Sensor-Only", .full_name = "UPEK TouchStrip Sensor-Only",
.id_table = id_table, .id_table = id_table,

View file

@ -460,7 +460,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver upektc_driver = { struct fp_img_driver upektc_driver = {
.driver = { .driver = {
.id = UPEKTC_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "UPEK TouchChip/Eikon Touch 300", .full_name = "UPEK TouchChip/Eikon Touch 300",
.id_table = id_table, .id_table = id_table,

View file

@ -628,7 +628,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver upektc_img_driver = { struct fp_img_driver upektc_img_driver = {
.driver = { .driver = {
.id = UPEKTC_IMG_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "Upek TouchChip Fingerprint Coprocessor", .full_name = "Upek TouchChip Fingerprint Coprocessor",
.id_table = id_table, .id_table = id_table,

View file

@ -1421,7 +1421,6 @@ static const struct usb_id id_table[] = {
}; };
struct fp_driver upekts_driver = { struct fp_driver upekts_driver = {
.id = UPEKTS_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "UPEK TouchStrip", .full_name = "UPEK TouchStrip",
.id_table = id_table, .id_table = id_table,

View file

@ -1428,7 +1428,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver uru4000_driver = { struct fp_img_driver uru4000_driver = {
.driver = { .driver = {
.id = URU4000_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "Digital Persona U.are.U 4000/4000B/4500", .full_name = "Digital Persona U.are.U 4000/4000B/4500",
.id_table = id_table, .id_table = id_table,

View file

@ -357,7 +357,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver vcom5s_driver = { struct fp_img_driver vcom5s_driver = {
.driver = { .driver = {
.id = VCOM5S_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "Veridicom 5thSense", .full_name = "Veridicom 5thSense",
.id_table = id_table, .id_table = id_table,

View file

@ -770,7 +770,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver vfs0050_driver = { struct fp_img_driver vfs0050_driver = {
/* Driver specification */ /* Driver specification */
.driver = { .driver = {
.id = VFS0050_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "Validity VFS0050", .full_name = "Validity VFS0050",
.id_table = id_table, .id_table = id_table,

View file

@ -1526,7 +1526,6 @@ struct fp_img_driver vfs101_driver =
/* Driver specification */ /* Driver specification */
.driver = .driver =
{ {
.id = VFS101_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "Validity VFS101", .full_name = "Validity VFS101",
.id_table = id_table, .id_table = id_table,

View file

@ -268,7 +268,6 @@ struct fp_img_driver vfs301_driver =
/* Driver specification */ /* Driver specification */
.driver = .driver =
{ {
.id = VFS301_ID,
.name = FP_COMPONENT, .name = FP_COMPONENT,
.full_name = "Validity VFS301", .full_name = "Validity VFS301",
.id_table = id_table, .id_table = id_table,

View file

@ -887,7 +887,6 @@ static const struct usb_id id_table[] = {
struct fp_img_driver vfs5011_driver = { struct fp_img_driver vfs5011_driver = {
.driver = { .driver = {
.id = VFS5011_ID,
.name = "vfs5011", .name = "vfs5011",
.full_name = "Validity VFS5011", .full_name = "Validity VFS5011",
.id_table = id_table, .id_table = id_table,

View file

@ -34,6 +34,5 @@
#include "fpi-usb.h" #include "fpi-usb.h"
#include "fpi-img.h" #include "fpi-img.h"
#include "fpi-assembling.h" #include "fpi-assembling.h"
#include "drivers/driver_ids.h"
#endif #endif

View file

@ -35,7 +35,6 @@
#include "fpi-dev-img.h" #include "fpi-dev-img.h"
#include "fpi-data.h" #include "fpi-data.h"
#include "fpi-img.h" #include "fpi-img.h"
#include "drivers/driver_ids.h"
/* Global variables */ /* Global variables */
extern libusb_context *fpi_usb_ctx; extern libusb_context *fpi_usb_ctx;
@ -145,8 +144,6 @@ struct fp_img_dev {
size_t identify_match_offset; size_t identify_match_offset;
}; };
/* fp_driver structure definition */
/* fp_img_driver structure definition */ /* fp_img_driver structure definition */
#define container_of(ptr, type, member) ({ \ #define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \

View file

@ -137,10 +137,13 @@ GSList *opened_devices = NULL;
static GSList *registered_drivers = NULL; static GSList *registered_drivers = NULL;
#define DRV_ID(drv) g_str_hash(drv->name)
static void register_driver(struct fp_driver *drv) static void register_driver(struct fp_driver *drv)
{ {
if (drv->id == 0) { if (drv->name == NULL ||
fp_err("not registering driver %s: driver ID is 0", drv->name); strlen(drv->name) <= 2) {
fp_err("not registering driver %s, name is too short or absent", drv->name);
return; return;
} }
registered_drivers = g_slist_prepend(registered_drivers, (gpointer) drv); registered_drivers = g_slist_prepend(registered_drivers, (gpointer) drv);
@ -411,7 +414,7 @@ API_EXPORTED int fp_dscv_dev_supports_print_data(struct fp_dscv_dev *dev,
g_return_val_if_fail(dev, 0); g_return_val_if_fail(dev, 0);
g_return_val_if_fail(print, 0); g_return_val_if_fail(print, 0);
return fpi_print_data_compatible(dev->drv->id, dev->devtype, return fpi_print_data_compatible(DRV_ID(dev->drv), dev->devtype,
fpi_driver_get_data_type(dev->drv), print->driver_id, print->devtype, fpi_driver_get_data_type(dev->drv), print->driver_id, print->devtype,
print->type); print->type);
} }
@ -434,7 +437,7 @@ API_EXPORTED int fp_dscv_dev_supports_dscv_print(struct fp_dscv_dev *dev,
g_return_val_if_fail(dev, 0); g_return_val_if_fail(dev, 0);
g_return_val_if_fail(print, 0); g_return_val_if_fail(print, 0);
return fpi_print_data_compatible(dev->drv->id, dev->devtype, 0, return fpi_print_data_compatible(DRV_ID(dev->drv), dev->devtype, 0,
print->driver_id, print->devtype, 0); print->driver_id, print->devtype, 0);
} }
@ -559,7 +562,7 @@ API_EXPORTED int fp_dev_supports_print_data(struct fp_dev *dev,
g_return_val_if_fail(dev, 0); g_return_val_if_fail(dev, 0);
g_return_val_if_fail(data, 0); g_return_val_if_fail(data, 0);
return fpi_print_data_compatible(dev->drv->id, dev->devtype, return fpi_print_data_compatible(DRV_ID(dev->drv), dev->devtype,
fpi_driver_get_data_type(dev->drv), data->driver_id, data->devtype, fpi_driver_get_data_type(dev->drv), data->driver_id, data->devtype,
data->type); data->type);
} }
@ -582,7 +585,7 @@ API_EXPORTED int fp_dev_supports_dscv_print(struct fp_dev *dev,
g_return_val_if_fail(dev, 0); g_return_val_if_fail(dev, 0);
g_return_val_if_fail(print, 0); g_return_val_if_fail(print, 0);
return fpi_print_data_compatible(dev->drv->id, dev->devtype, return fpi_print_data_compatible(DRV_ID(dev->drv), dev->devtype,
0, print->driver_id, print->devtype, 0); 0, print->driver_id, print->devtype, 0);
} }
@ -628,7 +631,7 @@ API_EXPORTED uint16_t fp_driver_get_driver_id(struct fp_driver *drv)
{ {
g_return_val_if_fail(drv, 0); g_return_val_if_fail(drv, 0);
return drv->id; return DRV_ID(drv);
} }
/** /**

View file

@ -68,7 +68,6 @@ enum fp_driver_type {
}; };
struct fp_driver { struct fp_driver {
const uint16_t id;
const char *name; const char *name;
const char *full_name; const char *full_name;
const struct usb_id * const id_table; const struct usb_id * const id_table;

View file

@ -148,7 +148,7 @@ struct fp_print_data_item *fpi_print_data_item_new(size_t length)
struct fp_print_data *fpi_print_data_new(struct fp_dev *dev) struct fp_print_data *fpi_print_data_new(struct fp_dev *dev)
{ {
return print_data_new(dev->drv->id, dev->devtype, return print_data_new(fp_driver_get_driver_id(dev->drv), dev->devtype,
fpi_driver_get_data_type(dev->drv)); fpi_driver_get_data_type(dev->drv));
} }
@ -349,7 +349,7 @@ static char *__get_path_to_print(uint16_t driver_id, uint32_t devtype,
static char *get_path_to_print(struct fp_dev *dev, enum fp_finger finger) static char *get_path_to_print(struct fp_dev *dev, enum fp_finger finger)
{ {
return __get_path_to_print(dev->drv->id, dev->devtype, finger); return __get_path_to_print(fp_driver_get_driver_id(dev->drv), dev->devtype, finger);
} }
/** /**