Add AES2501 driver
[libfprint.git] / libfprint / fp_internal.h
blob969c63780acbee2ba97724566fbce009675ad084
1 /*
2 * Internal/private definitions for libfprint
3 * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef __FPRINT_INTERNAL_H__
21 #define __FPRINT_INTERNAL_H__
23 #include <config.h>
24 #include <stdint.h>
26 #include <glib.h>
27 #include <usb.h>
29 #include <fprint.h>
31 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
33 #define container_of(ptr, type, member) ({ \
34 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
35 (type *)( (char *)__mptr - offsetof(type,member) );})
37 enum fpi_log_level {
38 LOG_LEVEL_DEBUG,
39 LOG_LEVEL_INFO,
40 LOG_LEVEL_WARNING,
41 LOG_LEVEL_ERROR,
44 void fpi_log(enum fpi_log_level, const char *component, const char *function,
45 const char *format, ...);
47 #ifndef FP_COMPONENT
48 #define FP_COMPONENT NULL
49 #endif
51 #ifdef ENABLE_LOGGING
52 #define _fpi_log(level, fmt...) fpi_log(level, FP_COMPONENT, __FUNCTION__, fmt)
53 #else
54 #define _fpi_log(level, fmt...)
55 #endif
57 #ifdef ENABLE_DEBUG_LOGGING
58 #define fp_dbg(fmt...) _fpi_log(LOG_LEVEL_DEBUG, fmt)
59 #else
60 #define fp_dbg(fmt...)
61 #endif
63 #define fp_info(fmt...) _fpi_log(LOG_LEVEL_INFO, fmt)
64 #define fp_warn(fmt...) _fpi_log(LOG_LEVEL_WARNING, fmt)
65 #define fp_err(fmt...) _fpi_log(LOG_LEVEL_ERROR, fmt)
67 struct fp_dev {
68 struct fp_driver *drv;
69 usb_dev_handle *udev;
70 uint32_t devtype;
71 void *priv;
73 int nr_enroll_stages;
75 /* drivers should not mess with these */
76 int __enroll_stage;
79 struct fp_img_dev {
80 struct fp_dev *dev;
81 usb_dev_handle *udev;
82 void *priv;
85 int fpi_imgdev_capture(struct fp_img_dev *imgdev, int unconditional,
86 struct fp_img **image);
87 int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev);
88 int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev);
90 struct usb_id {
91 uint16_t vendor;
92 uint16_t product;
93 unsigned long driver_data;
96 enum fp_driver_type {
97 DRIVER_PRIMITIVE = 0,
98 DRIVER_IMAGING = 1,
101 struct fp_driver {
102 const uint16_t id;
103 const char *name;
104 const char *full_name;
105 const struct usb_id * const id_table;
106 enum fp_driver_type type;
108 void *priv;
110 /* Device operations */
111 int (*discover)(const struct usb_id *usb_id, uint32_t *devtype);
112 int (*init)(struct fp_dev *dev, unsigned long driver_data);
113 void (*exit)(struct fp_dev *dev);
114 int (*enroll)(struct fp_dev *dev, gboolean initial, int stage,
115 struct fp_print_data **print_data, struct fp_img **img);
116 int (*verify)(struct fp_dev *dev, struct fp_print_data *data,
117 struct fp_img **img);
120 enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv);
122 /* flags for fp_img_driver.flags */
123 #define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0)
125 struct fp_img_driver {
126 struct fp_driver driver;
127 uint16_t flags;
128 int img_width;
129 int img_height;
130 unsigned int enlarge_factor;
131 int bz3_threshold;
133 /* Device operations */
134 int (*init)(struct fp_img_dev *dev, unsigned long driver_data);
135 void (*exit)(struct fp_img_dev *dev);
136 int (*await_finger_on)(struct fp_img_dev *dev);
137 int (*await_finger_off)(struct fp_img_dev *dev);
138 int (*capture)(struct fp_img_dev *dev, gboolean unconditional,
139 struct fp_img **image);
142 extern struct fp_driver upekts_driver;
143 extern struct fp_img_driver uru4000_driver;
144 extern struct fp_img_driver aes2501_driver;
145 extern struct fp_img_driver aes4000_driver;
147 void fpi_img_driver_setup(struct fp_img_driver *idriver);
149 #define fpi_driver_to_img_driver(drv) \
150 container_of((drv), struct fp_img_driver, driver)
152 struct fp_dscv_dev {
153 struct usb_device *udev;
154 struct fp_driver *drv;
155 unsigned long driver_data;
156 uint32_t devtype;
159 struct fp_dscv_print {
160 uint16_t driver_id;
161 uint32_t devtype;
162 enum fp_finger finger;
163 char *path;
166 enum fp_print_data_type {
167 PRINT_DATA_RAW = 0, /* memset-imposed default */
168 PRINT_DATA_NBIS_MINUTIAE,
171 struct fp_print_data {
172 uint16_t driver_id;
173 uint32_t devtype;
174 enum fp_print_data_type type;
175 size_t length;
176 unsigned char data[0];
179 struct fpi_print_data_fp1 {
180 char prefix[3];
181 uint16_t driver_id;
182 uint32_t devtype;
183 unsigned char data_type;
184 unsigned char data[0];
185 } __attribute__((__packed__));
187 void fpi_data_exit(void);
188 struct fp_print_data *fpi_print_data_new(struct fp_dev *dev, size_t length);
189 gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1,
190 enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2,
191 enum fp_print_data_type type2);
193 /* bit values for fp_img.flags */
194 #define FP_IMG_V_FLIPPED (1<<0)
195 #define FP_IMG_H_FLIPPED (1<<1)
196 #define FP_IMG_COLORS_INVERTED (1<<2)
198 struct fp_img {
199 int width;
200 int height;
201 size_t length;
202 uint16_t flags;
203 unsigned char data[0];
206 struct fp_img *fpi_img_new(size_t length);
207 struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev);
208 struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize);
209 gboolean fpi_img_is_sane(struct fp_img *img);
210 int fpi_img_detect_minutiae(struct fp_img_dev *imgdev, struct fp_img *img,
211 struct fp_print_data **ret);
212 int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
213 struct fp_print_data *new_print);
215 #endif