GCC Code Coverage Report


Directory: ./
File: libfprint/drivers/vfs301.c
Date: 2024-09-16 14:36:32
Exec Total Coverage
Lines: 103 107 96.3%
Functions: 13 13 100.0%
Branches: 21 29 72.4%

Line Branch Exec Source
1 /*
2 * vfs301/vfs300 fingerprint reader driver
3 * https://github.com/andree182/vfs301
4 *
5 * Copyright (c) 2011-2012 Andrej Krutak <dev@andree.sk>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #define FP_COMPONENT "vfs301"
23
24 #include "drivers_api.h"
25 #include "vfs301.h"
26
27
4/5
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 120 times.
✗ Branch 4 not taken.
768 G_DEFINE_TYPE (FpDeviceVfs301, fpi_device_vfs301, FP_TYPE_IMAGE_DEVICE)
28
29 /************************** GENERIC STUFF *************************************/
30
31 static int
32 1 submit_image (FpiSsm *ssm,
33 FpImageDevice *dev)
34 {
35 1 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
36 1 int height;
37 1 FpImage *img;
38
39 #if 0
40 /* XXX: This is probably handled by libfprint automagically? */
41 if (vdev->scanline_count < 20)
42 {
43 fpi_ssm_jump_to_state (ssm, M_REQUEST_PRINT);
44 return 0;
45 }
46 #endif
47
48 1 img = fp_image_new (VFS301_FP_OUTPUT_WIDTH, self->scanline_count);
49
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (img == NULL)
50 return 0;
51
52 1 vfs301_extract_image (self, img->data, &height);
53
54 /* TODO: how to detect flip? should the resulting image be
55 * oriented so that it is equal e.g. to a fingerprint on a paper,
56 * or to the finger when I look at it?) */
57 1 img->flags = FPI_IMAGE_COLORS_INVERTED | FPI_IMAGE_V_FLIPPED;
58
59 /* The image buffer is larger at this point, but that does not
60 * matter. */
61 1 img->width = VFS301_FP_OUTPUT_WIDTH;
62 1 img->height = height;
63
64 1 fpi_image_device_image_captured (dev, img);
65
66 1 return 1;
67 }
68
69 /* Loop ssm states */
70 enum {
71 /* Step 0 - Scan finger */
72 M_REQUEST_PRINT,
73 M_WAIT_PRINT,
74 M_CHECK_PRINT,
75 M_READ_PRINT_START,
76 M_READ_PRINT_WAIT,
77 M_READ_PRINT_POLL,
78 M_SUBMIT_PRINT,
79
80 /* Number of states */
81 M_LOOP_NUM_STATES,
82 };
83
84 /* Exec loop sequential state machine */
85 static void
86 9 m_loop_state (FpiSsm *ssm, FpDevice *_dev)
87 {
88 9 FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
89 9 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (_dev);
90
91
7/8
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
9 switch (fpi_ssm_get_cur_state (ssm))
92 {
93 1 case M_REQUEST_PRINT:
94 1 vfs301_proto_request_fingerprint (self);
95 1 fpi_ssm_next_state (ssm);
96 1 break;
97
98 2 case M_WAIT_PRINT:
99 /* Wait fingerprint scanning */
100 2 fpi_ssm_next_state_delayed (ssm, 200);
101 2 break;
102
103 2 case M_CHECK_PRINT:
104
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 if (!vfs301_proto_peek_event (self))
105 1 fpi_ssm_jump_to_state (ssm, M_WAIT_PRINT);
106 else
107 1 fpi_ssm_next_state (ssm);
108 break;
109
110 1 case M_READ_PRINT_START:
111 1 fpi_image_device_report_finger_status (dev, TRUE);
112 1 vfs301_proto_process_event_start (self);
113 1 fpi_ssm_next_state (ssm);
114 1 break;
115
116 1 case M_READ_PRINT_WAIT:
117 /* Wait fingerprint scanning */
118 1 fpi_ssm_next_state_delayed (ssm, 200);
119 1 break;
120
121 1 case M_READ_PRINT_POLL:
122 {
123 1 int rv = vfs301_proto_process_event_poll (self);
124
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 g_assert (rv != VFS301_FAILURE);
125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (rv == VFS301_ONGOING)
126 fpi_ssm_jump_to_state (ssm, M_READ_PRINT_WAIT);
127 else
128 1 fpi_ssm_next_state (ssm);
129 }
130 break;
131
132 1 case M_SUBMIT_PRINT:
133
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (submit_image (ssm, dev))
134 {
135 1 fpi_ssm_mark_completed (ssm);
136 /* NOTE: finger off is expected only after submitting image... */
137 1 fpi_image_device_report_finger_status (dev, FALSE);
138 }
139 else
140 {
141 fpi_ssm_jump_to_state (ssm, M_REQUEST_PRINT);
142 }
143 break;
144
145 default:
146 g_assert_not_reached ();
147 }
148 9 }
149
150 /* Exec init sequential state machine */
151 static void
152 1 m_init_state (FpiSsm *ssm, FpDevice *_dev)
153 {
154 1 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (_dev);
155
156
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 g_assert (fpi_ssm_get_cur_state (ssm) == 0);
157
158 1 vfs301_proto_init (self);
159
160 1 fpi_ssm_mark_completed (ssm);
161 1 }
162
163 /* Complete init sequential state machine */
164 static void
165 1 m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
166 {
167 1 fpi_image_device_activate_complete (FP_IMAGE_DEVICE (dev), error);
168 1 }
169
170 /* Activate device */
171 static void
172 1 dev_activate (FpImageDevice *dev)
173 {
174 1 FpiSsm *ssm;
175
176 /* Start init ssm */
177 1 ssm = fpi_ssm_new (FP_DEVICE (dev), m_init_state, 1);
178 1 fpi_ssm_start (ssm, m_init_complete);
179 1 }
180
181 /* Deactivate device */
182 static void
183 1 dev_deactivate (FpImageDevice *dev)
184 {
185 1 FpDeviceVfs301 *self;
186
187 1 self = FPI_DEVICE_VFS301 (dev);
188 1 vfs301_proto_deinit (self);
189 1 fpi_image_device_deactivate_complete (dev, NULL);
190 1 }
191
192 static void
193 8 dev_change_state (FpImageDevice *dev, FpiImageDeviceState state)
194 {
195 8 FpiSsm *ssm_loop;
196
197
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (state != FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON)
198 return;
199
200 /* Start a capture operation. */
201 1 ssm_loop = fpi_ssm_new (FP_DEVICE (dev), m_loop_state, M_LOOP_NUM_STATES);
202 1 fpi_ssm_start (ssm_loop, NULL);
203 }
204
205 static void
206 1 dev_open (FpImageDevice *dev)
207 {
208 1 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
209 1 GError *error = NULL;
210
211 /* Claim usb interface */
212 1 g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error);
213
214 /* Initialize private structure */
215 1 self->scanline_count = 0;
216
217 /* Notify open complete */
218 1 fpi_image_device_open_complete (dev, error);
219 1 }
220
221 static void
222 1 dev_close (FpImageDevice *dev)
223 {
224 1 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
225 1 GError *error = NULL;
226
227 /* Release private structure */
228
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 g_clear_pointer (&self->scanline_buf, g_free);
229
230 /* Release usb interface */
231 1 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
232 0, 0, &error);
233
234 /* Notify close complete */
235 1 fpi_image_device_close_complete (dev, error);
236 1 }
237
238 /* Usb id table of device */
239 static const FpIdEntry id_table[] = {
240 { /* vfs301 */ .vid = 0x138a, .pid = 0x0005, },
241 { /* vfs300 */ .vid = 0x138a, .pid = 0x0008, },
242 { .vid = 0, .pid = 0, .driver_data = 0 },
243 };
244
245 static void
246 1 fpi_device_vfs301_init (FpDeviceVfs301 *self)
247 {
248 1 }
249 static void
250 120 fpi_device_vfs301_class_init (FpDeviceVfs301Class *klass)
251 {
252 120 FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
253 120 FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
254
255 120 dev_class->id = "vfs301";
256 120 dev_class->full_name = "Validity VFS301";
257 120 dev_class->type = FP_DEVICE_TYPE_USB;
258 120 dev_class->id_table = id_table;
259 120 dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
260
261 120 img_class->img_open = dev_open;
262 120 img_class->img_close = dev_close;
263 120 img_class->activate = dev_activate;
264 120 img_class->deactivate = dev_deactivate;
265 120 img_class->change_state = dev_change_state;
266
267 120 img_class->bz3_threshold = 24;
268
269 120 img_class->img_width = VFS301_FP_WIDTH;
270 120 img_class->img_height = -1;
271 }
272