fp_internal.h 7.9 KB
Newer Older
1 2
/*
 * Internal/private definitions for libfprint
3
 * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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 __FPRINT_INTERNAL_H__
#define __FPRINT_INTERNAL_H__

Daniel Drake's avatar
Daniel Drake committed
23
#include <config.h>
24

25
#include <stdint.h>
26
#include <errno.h>
Daniel Drake's avatar
Daniel Drake committed
27
#include <glib.h>
28
#include <libusb.h>
29

30
#include "fprint.h"
31
#include "fpi-log.h"
32
#include "fpi-dev.h"
33
#include "fpi-dev-img.h"
34
#include "fpi-data.h"
35
#include "fpi-img.h"
36
#include "drivers/driver_ids.h"
37

Bastien Nocera's avatar
Bastien Nocera committed
38 39 40 41 42
/* Global variables */
extern libusb_context *fpi_usb_ctx;
extern GSList *opened_devices;

/* fp_dev structure definition */
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
enum fp_dev_state {
	DEV_STATE_INITIAL = 0,
	DEV_STATE_ERROR,
	DEV_STATE_INITIALIZING,
	DEV_STATE_INITIALIZED,
	DEV_STATE_DEINITIALIZING,
	DEV_STATE_DEINITIALIZED,
	DEV_STATE_ENROLL_STARTING,
	DEV_STATE_ENROLLING,
	DEV_STATE_ENROLL_STOPPING,
	DEV_STATE_VERIFY_STARTING,
	DEV_STATE_VERIFYING,
	DEV_STATE_VERIFY_DONE,
	DEV_STATE_VERIFY_STOPPING,
	DEV_STATE_IDENTIFY_STARTING,
	DEV_STATE_IDENTIFYING,
	DEV_STATE_IDENTIFY_DONE,
	DEV_STATE_IDENTIFY_STOPPING,
61 62 63 64
	DEV_STATE_CAPTURE_STARTING,
	DEV_STATE_CAPTURING,
	DEV_STATE_CAPTURE_DONE,
	DEV_STATE_CAPTURE_STOPPING,
65 66
};

67
struct fp_dev {
68
	struct fp_driver *drv;
69
	uint32_t devtype;
Daniel Drake's avatar
Daniel Drake committed
70

71 72
	/* only valid if drv->type == DRIVER_IMAGING */
	struct fp_img_dev *img_dev;
73 74
	/* Link to the instance specific struct */
	void *instance_data;
75

Daniel Drake's avatar
Daniel Drake committed
76
	int nr_enroll_stages;
Daniel Drake's avatar
Daniel Drake committed
77

78 79 80
	/* FIXME: This will eventually have a bus type */
	libusb_device_handle *udev;

81 82 83 84 85
	/* read-only to drivers */
	struct fp_print_data *verify_data;

	/* drivers should not mess with any of the below */
	enum fp_dev_state state;
Daniel Drake's avatar
Daniel Drake committed
86
	int __enroll_stage;
87
	int unconditional_capture;
88 89 90 91 92

	/* async I/O callbacks and data */
	/* FIXME: convert this to generic state operational data mechanism? */
	fp_dev_open_cb open_cb;
	void *open_cb_data;
93
	fp_operation_stop_cb close_cb;
94 95 96
	void *close_cb_data;
	fp_enroll_stage_cb enroll_stage_cb;
	void *enroll_stage_cb_data;
97
	fp_operation_stop_cb enroll_stop_cb;
98
	void *enroll_stop_cb_data;
99
	fp_img_operation_cb verify_cb;
100
	void *verify_cb_data;
101
	fp_operation_stop_cb verify_stop_cb;
102
	void *verify_stop_cb_data;
103
	fp_identify_cb identify_cb;
104
	void *identify_cb_data;
105
	fp_operation_stop_cb identify_stop_cb;
106
	void *identify_stop_cb_data;
107
	fp_img_operation_cb capture_cb;
108
	void *capture_cb_data;
109
	fp_operation_stop_cb capture_stop_cb;
110
	void *capture_stop_cb_data;
111 112 113

	/* FIXME: better place to put this? */
	struct fp_print_data **identify_gallery;
114 115
};

Bastien Nocera's avatar
Bastien Nocera committed
116
/* fp_img_dev structure definition */
117
struct fp_img_dev {
118 119
	struct fp_dev *parent;

120 121 122 123
	enum fp_imgdev_action action;
	int action_state;

	struct fp_print_data *acquire_data;
124
	struct fp_print_data *enroll_data;
125
	struct fp_img *acquire_img;
126
	int enroll_stage;
127 128 129 130
	int action_result;

	/* FIXME: better place to put this? */
	size_t identify_match_offset;
131 132
};

Bastien Nocera's avatar
Bastien Nocera committed
133
/* fp_driver structure definition */
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

/**
 * usb_id:
 * @vendor: the USB vendor ID
 * @product: the USB product ID
 * @driver_data: data to differentiate devices of different
 *   vendor and product IDs.
 *
 * The struct #usb_id is used to declare devices supported by a
 * particular driver. The @driver_data information is used to
 * differentiate different models of devices which only need
 * small changes compared to the default driver behaviour to function.
 *
 * For example, a device might have a different initialisation from
 * the stock device, so the driver could do:
 *
 * |[<!-- language="C" -->
 *    if (driver_data == MY_DIFFERENT_DEVICE_QUIRK) {
 *        ...
 *    } else {
 *        ...
 *    }
 * ]|
 *
 * The default value is zero, so the @driver_data needs to be a
 * non-zero to be useful.
 */
161 162 163 164 165 166
struct usb_id {
	uint16_t vendor;
	uint16_t product;
	unsigned long driver_data;
};

167 168 169 170 171 172 173
/**
 * fp_driver_type:
 * @DRIVER_PRIMITIVE: primitive, non-imaging, driver
 * @DRIVER_IMAGING: imaging driver
 *
 * The type of device the driver supports.
 */
174 175 176 177 178
enum fp_driver_type {
	DRIVER_PRIMITIVE = 0,
	DRIVER_IMAGING = 1,
};

179
struct fp_driver {
180
	const uint16_t id;
181 182 183
	const char *name;
	const char *full_name;
	const struct usb_id * const id_table;
184
	enum fp_driver_type type;
185
	enum fp_scan_type scan_type;
186

187
	/* Device operations */
188
	int (*discover)(struct libusb_device_descriptor *dsc, uint32_t *devtype);
189 190
	int (*open)(struct fp_dev *dev, unsigned long driver_data);
	void (*close)(struct fp_dev *dev);
191 192 193 194 195 196
	int (*enroll_start)(struct fp_dev *dev);
	int (*enroll_stop)(struct fp_dev *dev);
	int (*verify_start)(struct fp_dev *dev);
	int (*verify_stop)(struct fp_dev *dev, gboolean iterating);
	int (*identify_start)(struct fp_dev *dev);
	int (*identify_stop)(struct fp_dev *dev, gboolean iterating);
197 198
	int (*capture_start)(struct fp_dev *dev);
	int (*capture_stop)(struct fp_dev *dev);
199 200
};

Bastien Nocera's avatar
Bastien Nocera committed
201 202 203 204 205 206
/* fp_img_driver structure definition */
#define container_of(ptr, type, member) ({                      \
        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
        (type *)( (char *)__mptr - offsetof(type,member) );})
#define fpi_driver_to_img_driver(drv) \
	container_of((drv), struct fp_img_driver, driver)
207

208 209
struct fp_img_driver {
	struct fp_driver driver;
210
	uint16_t flags;
211 212
	int img_width;
	int img_height;
213
	int bz3_threshold;
214 215

	/* Device operations */
216 217
	int (*open)(struct fp_img_dev *dev, unsigned long driver_data);
	void (*close)(struct fp_img_dev *dev);
218 219 220
	int (*activate)(struct fp_img_dev *dev, enum fp_imgdev_state state);
	int (*change_state)(struct fp_img_dev *dev, enum fp_imgdev_state state);
	void (*deactivate)(struct fp_img_dev *dev);
221 222
};

Bastien Nocera's avatar
Bastien Nocera committed
223
/* fp_dscv_dev structure definition */
224
struct fp_dscv_dev {
225
	struct libusb_device *udev;
226
	struct fp_driver *drv;
227
	unsigned long driver_data;
228
	uint32_t devtype;
229 230
};

Bastien Nocera's avatar
Bastien Nocera committed
231
/* fp_dscv_print structure definition */
Daniel Drake's avatar
Daniel Drake committed
232 233 234 235 236 237 238
struct fp_dscv_print {
	uint16_t driver_id;
	uint32_t devtype;
	enum fp_finger finger;
	char *path;
};

Bastien Nocera's avatar
Bastien Nocera committed
239
/* fp_minutia structure definition */
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
struct fp_minutia {
	int x;
	int y;
	int ex;
	int ey;
	int direction;
	double reliability;
	int type;
	int appearing;
	int feature_id;
	int *nbrs;
	int *ridge_counts;
	int num_nbrs;
};

Bastien Nocera's avatar
Bastien Nocera committed
255
/* fp_minutiae structure definition */
256 257 258 259 260 261
struct fp_minutiae {
	int alloc;
	int num;
	struct fp_minutia **list;
};

Bastien Nocera's avatar
Bastien Nocera committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
/* Defined in fpi-dev-img.c */
void fpi_img_driver_setup(struct fp_img_driver *idriver);
int fpi_imgdev_get_img_width(struct fp_img_dev *imgdev);
int fpi_imgdev_get_img_height(struct fp_img_dev *imgdev);

/* Exported for use in command-line tools
 * Defined in fpi-core.c */
struct fp_driver **fprint_get_drivers (void);

/* Defined in fpi-core.c */
enum fp_print_data_type fpi_driver_get_data_type(struct fp_driver *drv);

/* Defined in fpi-data.c */
void fpi_data_exit(void);
gboolean fpi_print_data_compatible(uint16_t driver_id1, uint32_t devtype1,
	enum fp_print_data_type type1, uint16_t driver_id2, uint32_t devtype2,
	enum fp_print_data_type type2);

/* Defined in fpi-img.c */
281
gboolean fpi_img_is_sane(struct fp_img *img);
282
int fpi_img_to_print_data(struct fp_img_dev *imgdev, struct fp_img *img,
283
	struct fp_print_data **ret);
284 285
int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
	struct fp_print_data *new_print);
286
int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print,
287
	struct fp_print_data **gallery, int match_threshold, size_t *match_offset);
288

Bastien Nocera's avatar
Bastien Nocera committed
289
/* Defined in fpi-poll.c */
290
void fpi_timeout_cancel_all_for_dev(struct fp_dev *dev);
Daniel Drake's avatar
Daniel Drake committed
291
void fpi_poll_init(void);
292 293
void fpi_poll_exit(void);

Bastien Nocera's avatar
Bastien Nocera committed
294 295
#include "drivers_definitions.h"

296
#endif