Add bozorth3 from NBIS; implement verify for image devices
[libfprint.git] / libfprint / fp_internal.h
blob12ec764dc5db85c382919d621163056bdf47de7c
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>
25 #include <stdint.h>
27 #include <glib.h>
28 #include <usb.h>
30 #ifdef __DARWIN_NULL
31 /* Darwin does endianness slightly differently */
32 #include <machine/endian.h>
33 #define __BYTE_ORDER BYTE_ORDER
34 #define __LITTLE_ENDIAN LITTLE_ENDIAN
35 #define __BIG_ENDIAN BIG_ENDIAN
36 #else /* Linux */
37 #include <endian.h>
38 #endif
40 #include <fprint.h>
42 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
44 #define container_of(ptr, type, member) ({ \
45 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
46 (type *)( (char *)__mptr - offsetof(type,member) );})
48 enum fpi_log_level {
49 LOG_LEVEL_DEBUG,
50 LOG_LEVEL_INFO,
51 LOG_LEVEL_WARNING,
52 LOG_LEVEL_ERROR,
55 void fpi_log(enum fpi_log_level, const char *component, const char *function,
56 const char *format, ...);
58 #ifndef FP_COMPONENT
59 #define FP_COMPONENT NULL
60 #endif
62 #ifdef ENABLE_LOGGING
63 #define _fpi_log(level, fmt...) fpi_log(level, FP_COMPONENT, __FUNCTION__, fmt)
64 #else
65 #define _fpi_log(level, fmt...)
66 #endif
68 #ifdef ENABLE_DEBUG_LOGGING
69 #define fp_dbg(fmt...) _fpi_log(LOG_LEVEL_DEBUG, fmt)
70 #else
71 #define fp_dbg(fmt...)
72 #endif
74 #define fp_info(fmt...) _fpi_log(LOG_LEVEL_INFO, fmt)
75 #define fp_warn(fmt...) _fpi_log(LOG_LEVEL_WARNING, fmt)
76 #define fp_err(fmt...) _fpi_log(LOG_LEVEL_ERROR, fmt)
78 struct fp_dev {
79 struct fp_driver *drv;
80 usb_dev_handle *udev;
81 void *priv;
83 int nr_enroll_stages;
85 /* drivers should not mess with these */
86 int __enroll_stage;
89 struct fp_img_dev {
90 struct fp_dev *dev;
91 usb_dev_handle *udev;
92 void *priv;
95 struct usb_id {
96 uint16_t vendor;
97 uint16_t product;
98 unsigned long driver_data;
101 enum fp_driver_type {
102 DRIVER_PRIMITIVE = 0,
103 DRIVER_IMAGING = 1,
106 struct fp_driver {
107 const char *name;
108 const char *full_name;
109 const struct usb_id * const id_table;
110 enum fp_driver_type type;
112 void *priv;
114 /* Device operations */
115 int (*init)(struct fp_dev *dev, unsigned long driver_data);
116 void (*exit)(struct fp_dev *dev);
117 int (*enroll)(struct fp_dev *dev, gboolean initial, int stage,
118 struct fp_print_data **print_data);
119 int (*verify)(struct fp_dev *dev, struct fp_print_data *data);
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;
131 /* Device operations */
132 int (*init)(struct fp_img_dev *dev, unsigned long driver_data);
133 void (*exit)(struct fp_img_dev *dev);
134 int (*await_finger_on)(struct fp_img_dev *dev);
135 int (*await_finger_off)(struct fp_img_dev *dev);
136 int (*capture)(struct fp_img_dev *dev, gboolean unconditional,
137 struct fp_img **image);
140 extern struct fp_driver upekts_driver;
141 extern struct fp_img_driver uru4000_driver;
142 extern struct fp_img_driver aes4000_driver;
144 void fpi_img_driver_setup(struct fp_img_driver *idriver);
146 #define fpi_driver_to_img_driver(drv) \
147 container_of((drv), struct fp_img_driver, driver)
149 struct fp_dscv_dev {
150 struct usb_device *udev;
151 struct fp_driver *drv;
152 unsigned long driver_data;
155 struct fp_print_data {
156 const char *driver_name;
157 size_t length;
158 unsigned char buffer[0];
161 struct fp_print_data *fpi_print_data_new(struct fp_dev *dev, size_t length);
162 int fpi_print_data_compatible(struct fp_dev *dev, struct fp_print_data *data);
164 /* bit values for fp_img.flags */
165 #define FP_IMG_V_FLIPPED (1<<0)
166 #define FP_IMG_H_FLIPPED (1<<1)
167 #define FP_IMG_COLORS_INVERTED (1<<2)
169 struct fp_img {
170 int width;
171 int height;
172 size_t length;
173 uint16_t flags;
174 unsigned char data[0];
177 struct fp_img *fpi_img_new(size_t length);
178 struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev);
179 struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize);
180 gboolean fpi_img_is_sane(struct fp_img *img);
181 int fpi_img_detect_minutiae(struct fp_img_dev *imgdev, struct fp_img *img,
182 struct fp_print_data **ret);
183 int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
184 struct fp_print_data *new_print);
186 #define bswap16(x) (((x & 0xff) << 8) | (x >> 8))
187 #if __BYTE_ORDER == __LITTLE_ENDIAN
188 #define cpu_to_le16(x) (x)
189 #define le16_to_cpu(x) (x)
190 #define cpu_to_be16(x) bswap16(x)
191 #define be16_to_cpu(x) bswap16(x)
192 #elif __BYTE_ORDER == __BIG_ENDIAN
193 #define cpu_to_le16(x) bswap16(x)
194 #define le16_to_cpu(x) bswap16(x)
195 #define cpu_to_be16(x) (x)
196 #define be16_to_cpu(x) (x)
197 #else
198 #error "Unrecognized endianness"
199 #endif
201 #endif