From ea6d5ba6d65aa7ed4b900b23263bc4d8abe4a868 Mon Sep 17 00:00:00 2001
From: Vasily Khoruzhick <anarsoul@gmail.com>
Date: Sat, 10 Nov 2012 18:37:41 +0300
Subject: [PATCH] lib: Fix mess with driver IDs

ID is just a some magic number to make fingerprint from one scanner model
incompatible with another scanner model. Get rid of "magic", declare enum
and use it.

https://bugs.freedesktop.org/show_bug.cgi?id=56956
---
 libfprint/drivers/aes1610.c    |  4 +++-
 libfprint/drivers/aes2501.c    |  4 +++-
 libfprint/drivers/aes2550.c    |  4 +++-
 libfprint/drivers/aes4000.c    |  4 +++-
 libfprint/drivers/driver_ids.h | 39 ++++++++++++++++++++++++++++++++++
 libfprint/drivers/fdu2000.c    |  4 +++-
 libfprint/drivers/upeke2.c     |  4 +++-
 libfprint/drivers/upeksonly.c  |  4 +++-
 libfprint/drivers/upektc.c     |  4 +++-
 libfprint/drivers/upekts.c     |  4 +++-
 libfprint/drivers/uru4000.c    |  4 +++-
 libfprint/drivers/vcom5s.c     |  4 +++-
 libfprint/drivers/vfs101.c     |  4 +++-
 libfprint/drivers/vfs301.c     |  4 +++-
 14 files changed, 78 insertions(+), 13 deletions(-)
 create mode 100644 libfprint/drivers/driver_ids.h

diff --git a/libfprint/drivers/aes1610.c b/libfprint/drivers/aes1610.c
index 20bbe69..96e87b3 100644
--- a/libfprint/drivers/aes1610.c
+++ b/libfprint/drivers/aes1610.c
@@ -32,6 +32,8 @@
 #include <aeslib.h>
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 static void start_capture(struct fp_img_dev *dev);
 static void complete_deactivation(struct fp_img_dev *dev);
 static int adjust_gain(unsigned char *buffer, int status);
@@ -935,7 +937,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver aes1610_driver = {
 	.driver = {
-		.id = 6,
+		.id = AES1610_ID,
 		.name = FP_COMPONENT,
 		.full_name = "AuthenTec AES1610",
 		.id_table = id_table,
diff --git a/libfprint/drivers/aes2501.c b/libfprint/drivers/aes2501.c
index 1b82737..246d45e 100644
--- a/libfprint/drivers/aes2501.c
+++ b/libfprint/drivers/aes2501.c
@@ -30,7 +30,9 @@
 
 #include <aeslib.h>
 #include <fp_internal.h>
+
 #include "aes2501.h"
+#include "driver_ids.h"
 
 static void start_capture(struct fp_img_dev *dev);
 static void complete_deactivation(struct fp_img_dev *dev);
@@ -963,7 +965,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver aes2501_driver = {
 	.driver = {
-		.id = 4,
+		.id = AES2501_ID,
 		.name = FP_COMPONENT,
 		.full_name = "AuthenTec AES2501",
 		.id_table = id_table,
diff --git a/libfprint/drivers/aes2550.c b/libfprint/drivers/aes2550.c
index 6d68696..9c2eb69 100644
--- a/libfprint/drivers/aes2550.c
+++ b/libfprint/drivers/aes2550.c
@@ -30,7 +30,9 @@
 
 #include <aeslib.h>
 #include <fp_internal.h>
+
 #include "aes2550.h"
+#include "driver_ids.h"
 
 static void start_capture(struct fp_img_dev *dev);
 static void complete_deactivation(struct fp_img_dev *dev);
@@ -735,7 +737,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver aes2550_driver = {
 	.driver = {
-		.id = 4,
+		.id = AES2550_ID,
 		.name = FP_COMPONENT,
 		.full_name = "AuthenTec AES2550/AES2810",
 		.id_table = id_table,
diff --git a/libfprint/drivers/aes4000.c b/libfprint/drivers/aes4000.c
index 02dc9e8..7fefde2 100644
--- a/libfprint/drivers/aes4000.c
+++ b/libfprint/drivers/aes4000.c
@@ -27,6 +27,8 @@
 #include <aeslib.h>
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 #define CTRL_TIMEOUT	1000
 #define EP_IN			(1 | LIBUSB_ENDPOINT_IN)
 #define EP_OUT			(2 | LIBUSB_ENDPOINT_OUT)
@@ -249,7 +251,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver aes4000_driver = {
 	.driver = {
-		.id = 3,
+		.id = AES4000_ID,
 		.name = FP_COMPONENT,
 		.full_name = "AuthenTec AES4000",
 		.id_table = id_table,
diff --git a/libfprint/drivers/driver_ids.h b/libfprint/drivers/driver_ids.h
new file mode 100644
index 0000000..f5f22b0
--- /dev/null
+++ b/libfprint/drivers/driver_ids.h
@@ -0,0 +1,39 @@
+/*
+ * 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,
+};
+
+#endif
diff --git a/libfprint/drivers/fdu2000.c b/libfprint/drivers/fdu2000.c
index c9afb0b..ebd7103 100644
--- a/libfprint/drivers/fdu2000.c
+++ b/libfprint/drivers/fdu2000.c
@@ -26,6 +26,8 @@
 #define FP_COMPONENT "fdu2000"
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 #ifndef HAVE_MEMMEM
 gpointer
 memmem(const gpointer haystack, size_t haystack_len, const gpointer needle, size_t needle_len) {
@@ -305,7 +307,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver fdu2000_driver = {
 	.driver = {
-		.id = 7,
+		.id = FDU2000_ID,
 		.name = FP_COMPONENT,
 		.full_name = "Secugen FDU 2000",
 		.id_table = id_table,
diff --git a/libfprint/drivers/upeke2.c b/libfprint/drivers/upeke2.c
index 94bc8ae..ed8f43d 100644
--- a/libfprint/drivers/upeke2.c
+++ b/libfprint/drivers/upeke2.c
@@ -37,6 +37,8 @@
 
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 #define EP_IN (1 | LIBUSB_ENDPOINT_IN)
 #define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
 #define TIMEOUT 5000
@@ -1456,7 +1458,7 @@ static const struct usb_id id_table[] = {
 };
 
 struct fp_driver upeke2_driver = {
-	.id = 1,
+	.id = UPEKE2_ID,
 	.name = FP_COMPONENT,
 	.full_name = "UPEK Eikon 2",
 	.id_table = id_table,
diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c
index 50df8ca..84f864b 100644
--- a/libfprint/drivers/upeksonly.c
+++ b/libfprint/drivers/upeksonly.c
@@ -30,6 +30,8 @@
 
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 #define CTRL_TIMEOUT	1000
 #define IMG_WIDTH 288
 #define NUM_BULK_TRANSFERS 24
@@ -1267,7 +1269,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver upeksonly_driver = {
 	.driver = {
-		.id = 9,
+		.id = UPEKSONLY_ID,
 		.name = FP_COMPONENT,
 		.full_name = "UPEK TouchStrip Sensor-Only",
 		.id_table = id_table,
diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c
index f361051..a254a14 100644
--- a/libfprint/drivers/upektc.c
+++ b/libfprint/drivers/upektc.c
@@ -24,7 +24,9 @@
 #include <string.h>
 #include <libusb.h>
 #include <fp_internal.h>
+
 #include "upektc.h"
+#include "driver_ids.h"
 
 #define EP_IN (2 | LIBUSB_ENDPOINT_IN)
 #define EP_OUT (3 | LIBUSB_ENDPOINT_OUT)
@@ -446,7 +448,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver upektc_driver = {
 	.driver = {
-		.id = 5,
+		.id = UPEKTC_ID,
 		.name = FP_COMPONENT,
 		.full_name = "UPEK TouchChip",
 		.id_table = id_table,
diff --git a/libfprint/drivers/upekts.c b/libfprint/drivers/upekts.c
index a67cd94..b347949 100644
--- a/libfprint/drivers/upekts.c
+++ b/libfprint/drivers/upekts.c
@@ -35,6 +35,8 @@
 
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 #define EP_IN (1 | LIBUSB_ENDPOINT_IN)
 #define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
 #define TIMEOUT 5000
@@ -1464,7 +1466,7 @@ static const struct usb_id id_table[] = {
 };
 
 struct fp_driver upekts_driver = {
-	.id = 1,
+	.id = UPEKTS_ID,
 	.name = FP_COMPONENT,
 	.full_name = "UPEK TouchStrip",
 	.id_table = id_table,
diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c
index f42b609..eb76b92 100644
--- a/libfprint/drivers/uru4000.c
+++ b/libfprint/drivers/uru4000.c
@@ -30,6 +30,8 @@
 
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 #define EP_INTR			(1 | LIBUSB_ENDPOINT_IN)
 #define EP_DATA			(2 | LIBUSB_ENDPOINT_IN)
 #define USB_RQ			0x04
@@ -1359,7 +1361,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver uru4000_driver = {
 	.driver = {
-		.id = 2,
+		.id = URU4000_ID,
 		.name = FP_COMPONENT,
 		.full_name = "Digital Persona U.are.U 4000/4000B/4500",
 		.id_table = id_table,
diff --git a/libfprint/drivers/vcom5s.c b/libfprint/drivers/vcom5s.c
index 0bc5724..4b442b2 100644
--- a/libfprint/drivers/vcom5s.c
+++ b/libfprint/drivers/vcom5s.c
@@ -34,6 +34,8 @@
 
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 #define CTRL_IN 0xc0
 #define CTRL_OUT 0x40
 #define CTRL_TIMEOUT	1000
@@ -368,7 +370,7 @@ static const struct usb_id id_table[] = {
 
 struct fp_img_driver vcom5s_driver = {
 	.driver = {
-		.id = 8,
+		.id = VCOM5S_ID,
 		.name = FP_COMPONENT,
 		.full_name = "Veridicom 5thSense",
 		.id_table = id_table,
diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c
index c2d9a1c..95e654f 100644
--- a/libfprint/drivers/vfs101.c
+++ b/libfprint/drivers/vfs101.c
@@ -25,6 +25,8 @@
 
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 /* Input-Output usb endpoint */
 #define EP_IN(n)	(n | LIBUSB_ENDPOINT_IN)
 #define EP_OUT(n)	(n | LIBUSB_ENDPOINT_OUT)
@@ -1549,7 +1551,7 @@ struct fp_img_driver vfs101_driver =
 	/* Driver specification */
 	.driver =
 	{
-		.id = 10,
+		.id = VFS101_ID,
 		.name = FP_COMPONENT,
 		.full_name = "Validity VFS101",
 		.id_table = id_table,
diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c
index a27a945..c0e3612 100644
--- a/libfprint/drivers/vfs301.c
+++ b/libfprint/drivers/vfs301.c
@@ -34,6 +34,8 @@
 
 #include <fp_internal.h>
 
+#include "driver_ids.h"
+
 /************************** GENERIC STUFF *************************************/
 
 /* Callback of asynchronous sleep */
@@ -285,7 +287,7 @@ struct fp_img_driver vfs301_driver =
 	/* Driver specification */
 	.driver =
 	{
-		.id = 11,
+		.id = VFS301_ID,
 		.name = FP_COMPONENT,
 		.full_name = "Validity VFS301",
 		.id_table = id_table,