Clean up on exit, and convert to singly-linked-lists
[libfprint.git] / libfprint / fp_internal.h
blob435ec46eea0982c26da1337a87283fe93ea0b6d2
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);
116 int (*verify)(struct fp_dev *dev, struct fp_print_data *data);
119 enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv);
121 /* flags for fp_img_driver.flags */
122 #define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0)
124 struct fp_img_driver {
125 struct fp_driver driver;
126 uint16_t flags;
127 int img_width;
128 int img_height;
129 unsigned int enlarge_factor;
130 int bz3_threshold;
132 /* Device operations */
133 int (*init)(struct fp_img_dev *dev, unsigned long driver_data);
134 void (*exit)(struct fp_img_dev *dev);
135 int (*await_finger_on)(struct fp_img_dev *dev);
136 int (*await_finger_off)(struct fp_img_dev *dev);
137 int (*capture)(struct fp_img_dev *dev, gboolean unconditional,
138 struct fp_img **image);
141 extern struct fp_driver upekts_driver;
142 extern struct fp_img_driver uru4000_driver;
143 extern struct fp_img_driver aes4000_driver;
145 void fpi_img_driver_setup(struct fp_img_driver *idriver);
147 #define fpi_driver_to_img_driver(drv) \
148 container_of((drv), struct fp_img_driver, driver)
150 struct fp_dscv_dev {
151 struct usb_device *udev;
152 struct fp_driver *drv;
153 unsigned long driver_data;
154 uint32_t devtype;
157 struct fp_dscv_print {
158 uint16_t driver_id;
159 uint32_t devtype;
160 enum fp_finger finger;
161 char *path;
164 enum fp_print_data_type {
165 PRINT_DATA_RAW = 0, /* memset-imposed default */
166 PRINT_DATA_NBIS_MINUTIAE,
169 struct fp_print_data {
170 uint16_t driver_id;
171 uint32_t devtype;
172 enum fp_print_data_type type;
173 size_t length;
174 unsigned char data[0];
177 struct fpi_print_data_fp1 {
178 char prefix[3];
179 uint16_t driver_id;
180 uint32_t devtype;
181 unsigned char data_type;
182 unsigned char data[0];
183 } __attribute__((__packed__));
185 void fpi_data_exit(void);
186 struct fp_print_data *fpi_print_data_new(struct fp_dev *dev, size_t length);
187 gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1,
188 enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2,
189 enum fp_print_data_type type2);
191 /* bit values for fp_img.flags */
192 #define FP_IMG_V_FLIPPED (1<<0)
193 #define FP_IMG_H_FLIPPED (1<<1)
194 #define FP_IMG_COLORS_INVERTED (1<<2)
196 struct fp_img {
197 int width;
198 int height;
199 size_t length;
200 uint16_t flags;
201 unsigned char data[0];
204 struct fp_img *fpi_img_new(size_t length);
205 struct fp_img *fpi_img_new_for_imgdev(struct fp_img_dev *dev);
206 struct fp_img *fpi_img_resize(struct fp_img *img, size_t newsize);
207 gboolean fpi_img_is_sane(struct fp_img *img);
208 int fpi_img_detect_minutiae(struct fp_img_dev *imgdev, struct fp_img *img,
209 struct fp_print_data **ret);
210 int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
211 struct fp_print_data *new_print);
213 #endif