GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.6% 109 / 0 / 114
Functions: 100.0% 13 / 0 / 13
Branches: 67.6% 23 / 0 / 34

libfprint/drivers/vfs301.c
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/6
fpi_device_vfs301_class_intern_init:
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 125 times.
fpi_device_vfs301_get_type:
✓ Branch 2 → 3 taken 125 times.
✓ Branch 2 → 7 taken 24 times.
✓ Branch 4 → 5 taken 125 times.
✗ Branch 4 → 7 not taken.
399 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 3 → 4 taken 1 time.
✗ Branch 3 → 7 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 18 g_autoptr(GError) error = NULL;
89 9 FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
90 9 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (_dev);
91
92
7/8
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 6 taken 2 times.
✓ Branch 3 → 8 taken 2 times.
✓ Branch 3 → 14 taken 1 time.
✓ Branch 3 → 18 taken 1 time.
✓ Branch 3 → 20 taken 1 time.
✓ Branch 3 → 27 taken 1 time.
✗ Branch 3 → 32 not taken.
9 switch (fpi_ssm_get_cur_state (ssm))
93 {
94 1 case M_REQUEST_PRINT:
95 1 vfs301_proto_request_fingerprint (self);
96 1 fpi_ssm_next_state (ssm);
97 1 break;
98
99 2 case M_WAIT_PRINT:
100 /* Wait fingerprint scanning */
101 2 fpi_ssm_next_state_delayed (ssm, 200);
102 2 break;
103
104 2 case M_CHECK_PRINT:
105 {
106 2 int rv = vfs301_proto_peek_event (self, &error);
107
108
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 2 times.
2 if (rv == VFS301_FAILURE)
109 fpi_ssm_mark_failed (ssm, error);
110
2/2
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 1 time.
2 else if (rv == VFS301_ONGOING)
111 1 fpi_ssm_jump_to_state (ssm, M_WAIT_PRINT);
112 else
113 1 fpi_ssm_next_state (ssm);
114 }
115 break;
116
117 1 case M_READ_PRINT_START:
118 1 fpi_image_device_report_finger_status (dev, TRUE);
119 1 vfs301_proto_process_event_start (self);
120 1 fpi_ssm_next_state (ssm);
121 1 break;
122
123 1 case M_READ_PRINT_WAIT:
124 /* Wait fingerprint scanning */
125 1 fpi_ssm_next_state_delayed (ssm, 200);
126 1 break;
127
128 1 case M_READ_PRINT_POLL:
129 {
130 1 int rv = vfs301_proto_process_event_poll (self);
131
132
1/2
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 24 taken 1 time.
1 if (rv == VFS301_FAILURE)
133 fpi_ssm_mark_failed (ssm,
134 fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
135
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 1 time.
1 else if (rv == VFS301_ONGOING)
136 fpi_ssm_jump_to_state (ssm, M_READ_PRINT_WAIT);
137 else
138 1 fpi_ssm_next_state (ssm);
139 }
140 break;
141
142 1 case M_SUBMIT_PRINT:
143
1/2
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 31 not taken.
1 if (submit_image (ssm, dev))
144 {
145 1 fpi_ssm_mark_completed (ssm);
146 /* NOTE: finger off is expected only after submitting image... */
147 1 fpi_image_device_report_finger_status (dev, FALSE);
148 }
149 else
150 {
151 fpi_ssm_jump_to_state (ssm, M_REQUEST_PRINT);
152 }
153 break;
154
155 default:
156
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 9 times.
9 g_assert_not_reached ();
157 }
158 9 }
159
160 /* Exec init sequential state machine */
161 static void
162 1 m_init_state (FpiSsm *ssm, FpDevice *_dev)
163 {
164 1 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (_dev);
165
166
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1 time.
1 g_assert (fpi_ssm_get_cur_state (ssm) == 0);
167
168 1 vfs301_proto_init (self);
169
170 1 fpi_ssm_mark_completed (ssm);
171 1 }
172
173 /* Complete init sequential state machine */
174 static void
175 1 m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
176 {
177 1 fpi_image_device_activate_complete (FP_IMAGE_DEVICE (dev), error);
178 1 }
179
180 /* Activate device */
181 static void
182 1 dev_activate (FpImageDevice *dev)
183 {
184 1 FpiSsm *ssm;
185
186 /* Start init ssm */
187 1 ssm = fpi_ssm_new (FP_DEVICE (dev), m_init_state, 1);
188 1 fpi_ssm_start (ssm, m_init_complete);
189 1 }
190
191 /* Deactivate device */
192 static void
193 1 dev_deactivate (FpImageDevice *dev)
194 {
195 1 FpDeviceVfs301 *self;
196
197 1 self = FPI_DEVICE_VFS301 (dev);
198 1 vfs301_proto_deinit (self);
199 1 fpi_image_device_deactivate_complete (dev, NULL);
200 1 }
201
202 static void
203 8 dev_change_state (FpImageDevice *dev, FpiImageDeviceState state)
204 {
205 8 FpiSsm *ssm_loop;
206
207
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 5 taken 7 times.
8 if (state != FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON)
208 return;
209
210 /* Start a capture operation. */
211 1 ssm_loop = fpi_ssm_new (FP_DEVICE (dev), m_loop_state, M_LOOP_NUM_STATES);
212 1 fpi_ssm_start (ssm_loop, NULL);
213 }
214
215 static void
216 1 dev_open (FpImageDevice *dev)
217 {
218 1 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
219 1 GError *error = NULL;
220
221 /* Claim usb interface */
222 1 g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error);
223
224 /* Initialize private structure */
225 1 self->scanline_count = 0;
226
227 /* Notify open complete */
228 1 fpi_image_device_open_complete (dev, error);
229 1 }
230
231 static void
232 1 dev_close (FpImageDevice *dev)
233 {
234 1 FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (dev);
235 1 GError *error = NULL;
236
237 /* Release private structure */
238
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 4 not taken.
1 g_clear_pointer (&self->scanline_buf, g_free);
239
240 /* Release usb interface */
241 1 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)),
242 0, 0, &error);
243
244 /* Notify close complete */
245 1 fpi_image_device_close_complete (dev, error);
246 1 }
247
248 /* Usb id table of device */
249 static const FpIdEntry id_table[] = {
250 { /* vfs301 */ .vid = 0x138a, .pid = 0x0005, },
251 { /* vfs300 */ .vid = 0x138a, .pid = 0x0008, },
252 { .vid = 0, .pid = 0, .driver_data = 0 },
253 };
254
255 static void
256 1 fpi_device_vfs301_init (FpDeviceVfs301 *self)
257 {
258 1 }
259 static void
260 125 fpi_device_vfs301_class_init (FpDeviceVfs301Class *klass)
261 {
262 125 FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
263 125 FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (klass);
264
265 125 dev_class->id = "vfs301";
266 125 dev_class->full_name = "Validity VFS301";
267 125 dev_class->type = FP_DEVICE_TYPE_USB;
268 125 dev_class->id_table = id_table;
269 125 dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
270
271 125 img_class->img_open = dev_open;
272 125 img_class->img_close = dev_close;
273 125 img_class->activate = dev_activate;
274 125 img_class->deactivate = dev_deactivate;
275 125 img_class->change_state = dev_change_state;
276
277 125 img_class->bz3_threshold = 24;
278
279 125 img_class->img_width = VFS301_FP_WIDTH;
280 125 img_class->img_height = -1;
281 }
282