GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 74.8% 718 / 0 / 960
Functions: 89.6% 43 / 0 / 48
Branches: 48.9% 153 / 0 / 313

libfprint/drivers/fpcmoc/fpc.c
Line Branch Exec Source
1 /*
2 * Copyright (c) 2022 Fingerprint Cards AB <tech@fingerprints.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "drivers_api.h"
20 #include "fpc.h"
21
22 #define FP_COMPONENT "fpcmoc"
23 #define MAX_ENROLL_SAMPLES (25)
24 #define CTRL_TIMEOUT (2000)
25 #define DATA_TIMEOUT (5000)
26
27 /* Usb port setting */
28 #define EP_IN (1 | FPI_USB_ENDPOINT_IN)
29 #define EP_IN_MAX_BUF_SIZE (2048)
30
31 struct _FpiDeviceFpcMoc
32 {
33 FpDevice parent;
34 FpiSsm *task_ssm;
35 FpiSsm *cmd_ssm;
36 gboolean cmd_suspended;
37 gint enroll_stage;
38 gint immobile_stage;
39 gint max_enroll_stage;
40 gint max_immobile_stage;
41 gint max_stored_prints;
42 guint cmd_data_timeout;
43 guint8 *dbid;
44 gboolean do_cleanup;
45 GCancellable *interrupt_cancellable;
46 };
47
48
4/6
fpi_device_fpcmoc_class_intern_init:
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 121 times.
fpi_device_fpcmoc_get_type:
✓ Branch 2 → 3 taken 121 times.
✓ Branch 2 → 7 taken 24 times.
✓ Branch 4 → 5 taken 121 times.
✗ Branch 4 → 7 not taken.
387 G_DEFINE_TYPE (FpiDeviceFpcMoc, fpi_device_fpcmoc, FP_TYPE_DEVICE);
49
50 typedef void (*SynCmdMsgCallback) (FpiDeviceFpcMoc *self,
51 void *resp,
52 GError *error);
53
54 typedef struct
55 {
56 FpcCmdType cmdtype;
57 guint8 request;
58 guint16 value;
59 guint16 index;
60 guint8 *data;
61 gsize data_len;
62 SynCmdMsgCallback callback;
63 } CommandData;
64
65 static const FpIdEntry id_table[] = {
66 { .vid = 0x10A5, .pid = 0xFFE0, },
67 { .vid = 0x10A5, .pid = 0xA305, },
68 { .vid = 0x10A5, .pid = 0xA306, },
69 { .vid = 0x10A5, .pid = 0xDA04, },
70 { .vid = 0x10A5, .pid = 0xD805, },
71 { .vid = 0x10A5, .pid = 0xD205, },
72 { .vid = 0x10A5, .pid = 0x9524, },
73 { .vid = 0x10A5, .pid = 0x9544, },
74 { .vid = 0x10A5, .pid = 0xC844, },
75 { .vid = 0x10A5, .pid = 0x9B24, },
76 /* terminating entry */
77 { .vid = 0, .pid = 0, .driver_data = 0 },
78 };
79
80 static void
81 fpc_suspend_resume_cb (FpiUsbTransfer *transfer,
82 FpDevice *device,
83 gpointer user_data,
84 GError *error)
85 {
86 int ssm_state = fpi_ssm_get_cur_state (transfer->ssm);
87
88 fp_dbg ("%s current ssm state: %d", G_STRFUNC, ssm_state);
89
90 if (ssm_state == FPC_CMD_SUSPENDED)
91 {
92 if (error)
93 fpi_ssm_mark_failed (transfer->ssm, error);
94
95 fpi_device_suspend_complete (device, error);
96 /* The resume handler continues to the next state! */
97 }
98 else if (ssm_state == FPC_CMD_RESUME)
99 {
100 if (error)
101 fpi_ssm_mark_failed (transfer->ssm, error);
102 else
103 fpi_ssm_jump_to_state (transfer->ssm, FPC_CMD_GET_DATA);
104
105 fpi_device_resume_complete (device, error);
106 }
107 }
108
109 static void
110 103 fpc_cmd_receive_cb (FpiUsbTransfer *transfer,
111 FpDevice *device,
112 gpointer user_data,
113 GError *error)
114 {
115 103 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
116 103 CommandData *data = user_data;
117 103 int ssm_state = 0;
118
119
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 9 taken 103 times.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 9 not taken.
103 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && (self->cmd_suspended))
120 {
121 g_error_free (error);
122 fpi_ssm_jump_to_state (transfer->ssm, FPC_CMD_SUSPENDED);
123 return;
124 }
125
126
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 12 taken 103 times.
103 if (error)
127 {
128 fpi_ssm_mark_failed (transfer->ssm, error);
129 return;
130 }
131
132
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 103 times.
103 if (data == NULL)
133 {
134 fpi_ssm_mark_failed (transfer->ssm,
135 fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
136 return;
137 }
138
139 103 ssm_state = fpi_ssm_get_cur_state (transfer->ssm);
140 103 fp_dbg ("%s current ssm request: %d state: %d", G_STRFUNC, data->request, ssm_state);
141
142 /* clean cmd_ssm except capture command for suspend/resume case */
143
4/4
✓ Branch 18 → 19 taken 66 times.
✓ Branch 18 → 20 taken 37 times.
✓ Branch 19 → 20 taken 49 times.
✓ Branch 19 → 21 taken 17 times.
103 if (ssm_state != FPC_CMD_SEND || data->request != FPC_CMD_ARM)
144 86 self->cmd_ssm = NULL;
145
146
2/2
✓ Branch 21 → 22 taken 7 times.
✓ Branch 21 → 26 taken 96 times.
103 if (data->cmdtype == FPC_CMDTYPE_TO_DEVICE)
147 {
148 /* It should not receive any data. */
149
1/2
✓ Branch 22 → 23 taken 7 times.
✗ Branch 22 → 24 not taken.
7 if (data->callback)
150 7 data->callback (self, NULL, NULL);
151
152 7 fpi_ssm_mark_completed (transfer->ssm);
153 7 return;
154 }
155
2/2
✓ Branch 26 → 27 taken 74 times.
✓ Branch 26 → 42 taken 22 times.
96 else if (data->cmdtype == FPC_CMDTYPE_TO_DEVICE_EVTDATA)
156 {
157
2/2
✓ Branch 27 → 28 taken 37 times.
✓ Branch 27 → 30 taken 37 times.
74 if (ssm_state == FPC_CMD_SEND)
158 {
159 37 fpi_ssm_next_state (transfer->ssm);
160 37 return;
161 }
162
163
1/2
✓ Branch 30 → 31 taken 37 times.
✗ Branch 30 → 56 not taken.
37 if (ssm_state == FPC_CMD_GET_DATA)
164 {
165 37 fpc_cmd_response_t evt_data = {0};
166 37 fp_dbg ("%s recv evt data length: %ld", G_STRFUNC, transfer->actual_length);
167
1/2
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 37 taken 37 times.
37 if (transfer->actual_length == 0)
168 {
169 fp_err ("%s Expect data but actual_length = 0", G_STRFUNC);
170 fpi_ssm_mark_failed (transfer->ssm,
171 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
172 return;
173 }
174
175 37 memcpy (&evt_data, transfer->buffer, transfer->actual_length);
176
177
1/2
✓ Branch 37 → 38 taken 37 times.
✗ Branch 37 → 39 not taken.
37 if (data->callback)
178 37 data->callback (self, (guint8 *) &evt_data, NULL);
179
180 37 fpi_ssm_mark_completed (transfer->ssm);
181 37 return;
182 }
183 }
184
1/2
✓ Branch 42 → 43 taken 22 times.
✗ Branch 42 → 52 not taken.
22 else if (data->cmdtype == FPC_CMDTYPE_FROM_DEVICE)
185 {
186
1/2
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 48 taken 22 times.
22 if (transfer->actual_length == 0)
187 {
188 fp_err ("%s Expect data but actual_length = 0", G_STRFUNC);
189 fpi_ssm_mark_failed (transfer->ssm,
190 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
191 return;
192 }
193
194
1/2
✓ Branch 48 → 49 taken 22 times.
✗ Branch 48 → 50 not taken.
22 if (data->callback)
195 22 data->callback (self, transfer->buffer, NULL);
196
197 22 fpi_ssm_mark_completed (transfer->ssm);
198 22 return;
199 }
200 else
201 {
202 fp_err ("%s incorrect cmdtype (%x) ", G_STRFUNC, data->cmdtype);
203 fpi_ssm_mark_failed (transfer->ssm,
204 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
205 return;
206 }
207
208 /* should not run here... */
209 fpi_ssm_mark_failed (transfer->ssm,
210 fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
211 }
212
213 static void
214 66 fpc_send_ctrl_cmd (FpDevice *dev)
215 {
216 66 FpiUsbTransfer *transfer = NULL;
217 66 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (dev);
218 66 CommandData *cmd_data = fpi_ssm_get_data (self->cmd_ssm);
219 66 FpcCmdType cmdtype = FPC_CMDTYPE_UNKNOWN;
220
221
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 66 times.
66 if (!cmd_data)
222 {
223 fp_err ("%s No cmd_data is set ", G_STRFUNC);
224 fpi_ssm_mark_failed (self->cmd_ssm,
225 fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
226 }
227
228 66 cmdtype = cmd_data->cmdtype;
229
230
4/4
✓ Branch 7 → 8 taken 44 times.
✓ Branch 7 → 17 taken 22 times.
✓ Branch 8 → 9 taken 24 times.
✓ Branch 8 → 13 taken 20 times.
66 if ((cmdtype != FPC_CMDTYPE_FROM_DEVICE) && cmd_data->data_len &&
231
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 13 taken 24 times.
24 (cmd_data->data == NULL))
232 {
233 fp_err ("%s data buffer is null but len is not! ", G_STRFUNC);
234 fpi_ssm_mark_failed (self->cmd_ssm,
235 fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
236 }
237
238
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 17 taken 44 times.
44 if (cmdtype == FPC_CMDTYPE_UNKNOWN)
239 {
240 fp_err ("%s unknown cmd type ", G_STRFUNC);
241 fpi_ssm_mark_failed (self->cmd_ssm,
242 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
243 }
244
245 66 fp_dbg ("%s CMD: 0x%x, value: 0x%x, index: %x type: %d", G_STRFUNC,
246 cmd_data->request, cmd_data->value, cmd_data->index, cmdtype);
247
248 66 transfer = fpi_usb_transfer_new (dev);
249 66 fpi_usb_transfer_fill_control (transfer,
250 ((cmdtype == FPC_CMDTYPE_FROM_DEVICE) ?
251 (G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST) :
252 (G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE)),
253 G_USB_DEVICE_REQUEST_TYPE_VENDOR,
254 G_USB_DEVICE_RECIPIENT_DEVICE,
255 cmd_data->request,
256 cmd_data->value,
257 cmd_data->index,
258 cmd_data->data_len);
259
260 66 transfer->ssm = self->cmd_ssm;
261
2/2
✓ Branch 20 → 21 taken 44 times.
✓ Branch 20 → 24 taken 22 times.
66 if (cmdtype != FPC_CMDTYPE_FROM_DEVICE &&
262
2/2
✓ Branch 21 → 22 taken 24 times.
✓ Branch 21 → 24 taken 20 times.
44 cmd_data->data != NULL &&
263
1/2
✓ Branch 22 → 23 taken 24 times.
✗ Branch 22 → 24 not taken.
24 cmd_data->data_len != 0)
264 24 memcpy (transfer->buffer, cmd_data->data, cmd_data->data_len);
265
266 66 fpi_usb_transfer_submit (transfer, CTRL_TIMEOUT, NULL,
267 fpc_cmd_receive_cb,
268 fpi_ssm_get_data (transfer->ssm));
269 66 }
270
271 static void
272 66 fpc_cmd_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
273 {
274 66 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (dev);
275 66 CommandData *data = fpi_ssm_get_data (ssm);
276
277 66 self->cmd_ssm = NULL;
278 /* Notify about the SSM failure from here instead. */
279
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 66 times.
66 if (error)
280 {
281 fp_err ("%s error: %s ", G_STRFUNC, error->message);
282 if (data->callback)
283 data->callback (self, NULL, error);
284 }
285 66 }
286
287 static void
288 103 fpc_cmd_run_state (FpiSsm *ssm,
289 FpDevice *dev)
290 {
291 103 FpiUsbTransfer *transfer = NULL;
292 103 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (dev);
293
294
2/5
✓ Branch 3 → 4 taken 66 times.
✓ Branch 3 → 6 taken 37 times.
✗ Branch 3 → 11 not taken.
✗ Branch 3 → 15 not taken.
✗ Branch 3 → 19 not taken.
103 switch (fpi_ssm_get_cur_state (ssm))
295 {
296 66 case FPC_CMD_SEND:
297 66 fpc_send_ctrl_cmd (dev);
298 66 break;
299
300 37 case FPC_CMD_GET_DATA:
301 37 transfer = fpi_usb_transfer_new (dev);
302 37 transfer->ssm = ssm;
303 37 fpi_usb_transfer_fill_bulk (transfer, EP_IN, EP_IN_MAX_BUF_SIZE);
304 37 fpi_usb_transfer_submit (transfer,
305 self->cmd_data_timeout,
306 self->interrupt_cancellable,
307 fpc_cmd_receive_cb,
308 fpi_ssm_get_data (ssm));
309 37 break;
310
311 case FPC_CMD_SUSPENDED:
312 transfer = fpi_usb_transfer_new (dev);
313 transfer->ssm = ssm;
314 fpi_usb_transfer_fill_control (transfer,
315 G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
316 G_USB_DEVICE_REQUEST_TYPE_VENDOR,
317 G_USB_DEVICE_RECIPIENT_DEVICE,
318 FPC_CMD_INDICATE_S_STATE,
319 FPC_HOST_MS_SX,
320 0,
321 0);
322
323 fpi_usb_transfer_submit (transfer, CTRL_TIMEOUT, NULL,
324 fpc_suspend_resume_cb, NULL);
325 break;
326
327 case FPC_CMD_RESUME:
328 transfer = fpi_usb_transfer_new (dev);
329 transfer->ssm = ssm;
330 fpi_usb_transfer_fill_control (transfer,
331 G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
332 G_USB_DEVICE_REQUEST_TYPE_VENDOR,
333 G_USB_DEVICE_RECIPIENT_DEVICE,
334 FPC_CMD_INDICATE_S_STATE,
335 FPC_HOST_MS_S0,
336 0,
337 0);
338
339 fpi_usb_transfer_submit (transfer, CTRL_TIMEOUT, NULL,
340 fpc_suspend_resume_cb, NULL);
341 break;
342 }
343
344 103 }
345
346 static void
347 66 fpc_sensor_cmd (FpiDeviceFpcMoc *self,
348 gboolean wait_data_delay,
349 CommandData *cmd_data)
350 {
351 66 CommandData *data = NULL;
352
353
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 66 times.
66 g_return_if_fail (cmd_data);
354
1/2
✓ Branch 4 → 5 taken 66 times.
✗ Branch 4 → 7 not taken.
66 g_return_if_fail (cmd_data->cmdtype != FPC_CMDTYPE_UNKNOWN);
355
356 66 data = g_memdup2 (cmd_data, sizeof (CommandData));
357
358
2/2
✓ Branch 6 → 8 taken 17 times.
✓ Branch 6 → 9 taken 49 times.
66 g_clear_object (&self->interrupt_cancellable);
359
360
2/2
✓ Branch 9 → 10 taken 17 times.
✓ Branch 9 → 12 taken 49 times.
66 if (wait_data_delay)
361 {
362 17 self->cmd_data_timeout = 0;
363 17 self->interrupt_cancellable = g_cancellable_new ();
364 }
365 else
366 {
367 49 self->cmd_data_timeout = DATA_TIMEOUT;
368 }
369
370
1/2
✓ Branch 13 → 14 taken 66 times.
✗ Branch 13 → 17 not taken.
66 g_assert (self->cmd_ssm == NULL);
371 66 self->cmd_ssm = fpi_ssm_new (FP_DEVICE (self),
372 fpc_cmd_run_state,
373 FPC_CMD_NUM_STATES);
374
375 66 fpi_ssm_set_data (self->cmd_ssm, data, g_free);
376 66 fpi_ssm_start (self->cmd_ssm, fpc_cmd_ssm_done);
377 }
378
379 static void
380 1 fpc_dev_release_interface (FpiDeviceFpcMoc *self,
381 GError *error)
382 {
383 1 g_autoptr(GError) release_error = NULL;
384
385 /* Release usb interface */
386 1 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (self)),
387 0, 0, &release_error);
388 /* Retain passed error if set, otherwise propagate error from release. */
389
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 9 taken 1 time.
1 if (error)
390 {
391 fpi_device_close_complete (FP_DEVICE (self), error);
392 return;
393 }
394
395 /* Notify close complete */
396
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 1 time.
1 fpi_device_close_complete (FP_DEVICE (self), g_steal_pointer (&release_error));
397 }
398
399 static gboolean
400 57 check_data (void *data, GError **error)
401 {
402
1/2
✓ Branch 2 → 3 taken 57 times.
✗ Branch 2 → 7 not taken.
57 if (*error != NULL)
403 return FALSE;
404
405
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 57 times.
57 if (data == NULL)
406 {
407 g_propagate_error (error,
408 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
409 return FALSE;
410 }
411
412 return TRUE;
413 }
414
415 static void
416 36 fpc_evt_cb (FpiDeviceFpcMoc *self,
417 void *data,
418 GError *error)
419 {
420 36 pfpc_cmd_response_t presp = NULL;
421
422
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 36 times.
36 if (!check_data (data, &error))
423 {
424 fp_err ("%s error: %s", G_STRFUNC, error->message);
425 fpi_ssm_mark_failed (self->task_ssm, error);
426 return;
427 }
428
429 36 presp = (pfpc_cmd_response_t) data;
430
431
4/5
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 14 taken 1 time.
✓ Branch 7 → 16 taken 17 times.
✓ Branch 7 → 22 taken 17 times.
✗ Branch 7 → 25 not taken.
36 switch (presp->evt_hdr.cmdid)
432 {
433 1 case FPC_EVT_FID_DATA:
434 1 fp_dbg ("%s Enum Fids: status = %d, NumFids = %d", G_STRFUNC,
435 presp->evt_enum_fids.status, presp->evt_enum_fids.num_ids);
436
2/4
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 29 taken 1 time.
1 if (presp->evt_enum_fids.status || (presp->evt_enum_fids.num_ids > FPC_TEMPLATES_MAX))
437 {
438 fpi_ssm_mark_failed (self->task_ssm,
439 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
440 "Get Fids failed"));
441 return;
442 }
443 break;
444
445 1 case FPC_EVT_INIT_RESULT:
446 1 fp_dbg ("%s INIT: status=%d, Sensor = %d, HWID = 0x%04X, WxH = %d x %d", G_STRFUNC,
447 presp->evt_inited.hdr.status, presp->evt_inited.sensor,
448 presp->evt_inited.hw_id, presp->evt_inited.img_w, presp->evt_inited.img_h);
449
450 1 fp_dbg ("%s INIT: FW version: %s", G_STRFUNC, (gchar *) presp->evt_inited.fw_version);
451 1 break;
452
453 17 case FPC_EVT_FINGER_DWN:
454 17 fp_dbg ("%s Got finger down event (%d)", G_STRFUNC, presp->evt_hdr.status);
455 17 fpi_device_report_finger_status_changes (FP_DEVICE (self),
456 FP_FINGER_STATUS_PRESENT,
457 FP_FINGER_STATUS_NONE);
458
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 29 taken 17 times.
17 if (presp->evt_hdr.status != 0)
459 {
460 /* Redo the current task state if capture failed */
461 fpi_ssm_jump_to_state (self->task_ssm, fpi_ssm_get_cur_state (self->task_ssm));
462 return;
463 }
464 break;
465
466 17 case FPC_EVT_IMG:
467 17 fp_dbg ("%s Got capture event", G_STRFUNC);
468 17 fpi_device_report_finger_status_changes (FP_DEVICE (self),
469 FP_FINGER_STATUS_NONE,
470 FP_FINGER_STATUS_PRESENT);
471 17 break;
472
473 default:
474 fpi_ssm_mark_failed (self->task_ssm,
475 fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
476 "Unknown Evt (0x%x)!", presp->evt_hdr.cmdid));
477 return;
478 }
479
480 36 fpi_ssm_next_state (self->task_ssm);
481 }
482
483 static void
484 3 fpc_do_abort_cb (FpiDeviceFpcMoc *self,
485 void *data,
486 GError *error)
487 {
488
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 3 times.
3 if (error)
489 {
490 fp_err ("%s error: %s ", G_STRFUNC, error->message);
491 fpi_ssm_mark_failed (self->task_ssm, error);
492 return;
493 }
494
495 3 fp_dbg ("%s Do abort for reasons", G_STRFUNC);
496 3 fpi_ssm_next_state (self->task_ssm);
497 }
498
499 static void
500 fpc_do_cleanup_cb (FpiDeviceFpcMoc *self,
501 void *data,
502 GError *error)
503 {
504 if (error)
505 {
506 fp_err ("%s error: %s ", G_STRFUNC, error->message);
507 fpi_ssm_mark_failed (self->task_ssm, error);
508 return;
509 }
510
511 fp_dbg ("%s Do cleanup for reasons", G_STRFUNC);
512 self->do_cleanup = FALSE;
513 fpi_ssm_next_state (self->task_ssm);
514 }
515
516 static void
517 1 fpc_template_delete_cb (FpiDeviceFpcMoc *self,
518 void *resp,
519 GError *error)
520 {
521 1 FpDevice *device = FP_DEVICE (self);
522
523 1 fpi_device_delete_complete (device, error);
524 1 }
525
526 static gboolean
527 1 parse_print_data (GVariant *data,
528 guint8 *finger,
529 const guint8 **user_id,
530 gsize *user_id_len)
531 {
532 2 g_autoptr(GVariant) user_id_var = NULL;
533
534
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1 time.
1 g_return_val_if_fail (data, FALSE);
535
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 6 not taken.
1 g_return_val_if_fail (finger, FALSE);
536
1/2
✓ Branch 5 → 7 taken 1 time.
✗ Branch 5 → 8 not taken.
1 g_return_val_if_fail (user_id, FALSE);
537
1/2
✓ Branch 7 → 9 taken 1 time.
✗ Branch 7 → 11 not taken.
1 g_return_val_if_fail (user_id_len, FALSE);
538
539 1 *user_id = NULL;
540 1 *user_id_len = 0;
541 1 *finger = FPC_SUBTYPE_NOINFORMATION;
542
543
1/2
✓ Branch 10 → 12 taken 1 time.
✗ Branch 10 → 19 not taken.
1 if (!g_variant_check_format_string (data, "(y@ay)", FALSE))
544 return FALSE;
545
546 1 g_variant_get (data,
547 "(y@ay)",
548 finger,
549 &user_id_var);
550
551 1 *user_id = g_variant_get_fixed_array (user_id_var, user_id_len, 1);
552
553
1/2
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 19 not taken.
1 if (*user_id_len == 0 || *user_id_len > SECURITY_MAX_SID_SIZE)
554 return FALSE;
555
556
2/4
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 19 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 19 not taken.
1 if (*user_id_len <= 0 || *user_id[0] == '\0' || *user_id[0] == ' ')
557 return FALSE;
558
559
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
1 if (*finger != FPC_SUBTYPE_RESERVED)
560 return FALSE;
561
562 return TRUE;
563 }
564
565 /******************************************************************************
566 *
567 * fpc_template_xxx Function
568 *
569 *****************************************************************************/
570 static FpPrint *
571 3 fpc_print_from_data (FpiDeviceFpcMoc *self, fpc_fid_data_t *fid_data)
572 {
573 3 FpPrint *print = NULL;
574 3 GVariant *data;
575 3 GVariant *uid;
576 6 g_autofree gchar *userid = NULL;
577
578 3 userid = g_strndup ((gchar *) fid_data->identity, fid_data->identity_size);
579 3 print = fp_print_new (FP_DEVICE (self));
580
581 6 uid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
582 fid_data->identity,
583 3 fid_data->identity_size,
584 1);
585
586 6 data = g_variant_new ("(y@ay)",
587 3 fid_data->subfactor,
588 uid);
589
590 3 fpi_print_set_type (print, FPI_PRINT_RAW);
591 3 fpi_print_set_device_stored (print, TRUE);
592 3 g_object_set (print, "fpi-data", data, NULL);
593 3 g_object_set (print, "description", userid, NULL);
594 3 fpi_print_fill_from_user_id (print, userid);
595
596 3 return print;
597 }
598
599 static void
600 1 fpc_template_list_cb (FpiDeviceFpcMoc *self,
601 void *data,
602 GError *error)
603 {
604 1 g_autoptr(GPtrArray) list_result = NULL;
605 1 FpDevice *device = FP_DEVICE (self);
606 1 pfpc_cmd_response_t presp = NULL;
607
608
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 1 time.
1 if (error)
609 {
610 fpi_device_list_complete (FP_DEVICE (self), NULL, error);
611 return;
612 }
613
614
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 1 time.
1 if (data == NULL)
615 {
616 fpi_device_list_complete (FP_DEVICE (self),
617 NULL,
618 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
619 "Data is null"));
620 return;
621 }
622
623 1 presp = (pfpc_cmd_response_t) data;
624
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 13 taken 1 time.
1 if (presp->evt_hdr.cmdid != FPC_EVT_FID_DATA)
625 {
626 fpi_device_list_complete (FP_DEVICE (self),
627 NULL,
628 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
629 "Recv evt is incorrect: 0x%x",
630 presp->evt_hdr.cmdid));
631 return;
632 }
633
634
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 17 taken 1 time.
1 if (presp->evt_enum_fids.num_ids > FPC_TEMPLATES_MAX)
635 {
636 fpi_device_list_complete (FP_DEVICE (self),
637 NULL,
638 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_FULL,
639 "Database is full"));
640 return;
641 }
642
643 1 list_result = g_ptr_array_new_with_free_func (g_object_unref);
644
645
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 30 taken 1 time.
1 if (presp->evt_enum_fids.num_ids == 0)
646 {
647 fp_info ("Database is empty");
648 fpi_device_list_complete (device,
649 g_steal_pointer (&list_result),
650 NULL);
651 return;
652 }
653
654
2/2
✓ Branch 30 → 22 taken 1 time.
✓ Branch 30 → 31 taken 1 time.
2 for (int n = 0; n < presp->evt_enum_fids.num_ids; n++)
655 {
656 1 FpPrint *print = NULL;
657 1 fpc_fid_data_t *fid_data = &presp->evt_enum_fids.fid_data[n];
658
659
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 26 taken 1 time.
1 if ((fid_data->subfactor != FPC_SUBTYPE_RESERVED) &&
660 (fid_data->identity_type != FPC_IDENTITY_TYPE_RESERVED))
661 {
662 fp_info ("Incompatible template found (0x%x, 0x%x)",
663 fid_data->subfactor, fid_data->identity_type);
664 continue;
665 }
666
667 1 print = fpc_print_from_data (self, fid_data);
668
669 1 g_ptr_array_add (list_result, g_object_ref_sink (print));
670 }
671
672 1 fp_info ("Query templates complete!");
673 1 fpi_device_list_complete (device,
674 1 g_steal_pointer (&list_result),
675 NULL);
676 }
677
678 /******************************************************************************
679 *
680 * fpc_enroll_xxxx Function
681 *
682 *****************************************************************************/
683
684 static void
685 1 fpc_enroll_create_cb (FpiDeviceFpcMoc *self,
686 void *data,
687 GError *error)
688 {
689 1 FPC_BEGIN_ENROL *presp = NULL;
690
691
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 1 time.
1 if (!check_data (data, &error))
692 {
693 fp_err ("%s error: %s ", G_STRFUNC, error->message);
694 fpi_ssm_mark_failed (self->task_ssm, error);
695 return;
696 }
697
698 1 presp = (FPC_BEGIN_ENROL *) data;
699
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 1 time.
1 if (presp->status != 0)
700 {
701 error = fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
702 "End Enroll failed: %d",
703 presp->status);
704 }
705
706
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 1 time.
1 if (error)
707 {
708 fp_err ("%s error: %s ", G_STRFUNC, error->message);
709 fpi_ssm_mark_failed (self->task_ssm, error);
710 return;
711 }
712 else
713 {
714 1 self->do_cleanup = TRUE;
715 1 fpi_ssm_next_state (self->task_ssm);
716 }
717 }
718
719 static void
720 15 fpc_enroll_update_cb (FpiDeviceFpcMoc *self,
721 void *data,
722 GError *error)
723 {
724 15 FPC_ENROL *presp = NULL;
725
726
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 15 times.
15 if (!check_data (data, &error))
727 {
728 fp_err ("%s error: %s ", G_STRFUNC, error->message);
729 fpi_ssm_mark_failed (self->task_ssm, error);
730 return;
731 }
732
733 15 presp = (FPC_ENROL *) data;
734 15 fp_dbg ("Enrol Update status: %d, remaining: %d", presp->status, presp->remaining);
735
3/8
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 11 not taken.
✓ Branch 8 → 13 taken 1 time.
✓ Branch 8 → 16 taken 3 times.
✓ Branch 8 → 27 taken 11 times.
✗ Branch 8 → 31 not taken.
✗ Branch 8 → 34 not taken.
✗ Branch 8 → 37 not taken.
15 switch (presp->status)
736 {
737 case FPC_ENROL_STATUS_FAILED_COULD_NOT_COMPLETE:
738 error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
739 break;
740
741 case FPC_ENROL_STATUS_FAILED_ALREADY_ENROLED:
742 error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_DUPLICATE);
743 break;
744
745 1 case FPC_ENROL_STATUS_COMPLETED:
746 1 self->enroll_stage++;
747 1 fpi_device_enroll_progress (FP_DEVICE (self), self->enroll_stage, NULL, NULL);
748 1 fpi_ssm_jump_to_state (self->task_ssm, FPC_ENROLL_COMPLETE);
749 1 return;
750
751 3 case FPC_ENROL_STATUS_IMAGE_TOO_SIMILAR:
752 3 fp_dbg ("Sample overlapping ratio is too High");
753 /* here should tips remove finger and try again */
754
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 24 taken 3 times.
3 if (self->max_immobile_stage)
755 {
756 self->immobile_stage++;
757 if (self->immobile_stage > self->max_immobile_stage)
758 {
759 fp_dbg ("Skip similar handle due to customer enrollment %d(%d)",
760 self->immobile_stage, self->max_immobile_stage);
761 /* Skip too similar handle, treat as normal enroll progress. */
762 self->enroll_stage++;
763 fpi_device_enroll_progress (FP_DEVICE (self), self->enroll_stage, NULL, NULL);
764 /* Used for customer enrollment scheme */
765 if (self->enroll_stage >= (self->max_enroll_stage - self->max_immobile_stage))
766 {
767 fpi_ssm_jump_to_state (self->task_ssm, FPC_ENROLL_COMPLETE);
768 return;
769 }
770 break;
771 }
772 }
773 3 fpi_device_enroll_progress (FP_DEVICE (self),
774 self->enroll_stage,
775 NULL,
776 fpi_device_retry_new (FP_DEVICE_RETRY_REMOVE_FINGER));
777 3 break;
778
779 11 case FPC_ENROL_STATUS_PROGRESS:
780 11 self->enroll_stage++;
781 11 fpi_device_enroll_progress (FP_DEVICE (self), self->enroll_stage, NULL, NULL);
782 /* Used for customer enrollment scheme */
783
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 40 taken 11 times.
11 if (self->enroll_stage >= (self->max_enroll_stage - self->max_immobile_stage))
784 {
785 fpi_ssm_jump_to_state (self->task_ssm, FPC_ENROLL_COMPLETE);
786 return;
787 }
788 break;
789
790 case FPC_ENROL_STATUS_IMAGE_LOW_COVERAGE:
791 fpi_device_enroll_progress (FP_DEVICE (self),
792 self->enroll_stage,
793 NULL,
794 fpi_device_retry_new (FP_DEVICE_RETRY_CENTER_FINGER));
795 break;
796
797 case FPC_ENROL_STATUS_IMAGE_LOW_QUALITY:
798 fpi_device_enroll_progress (FP_DEVICE (self),
799 self->enroll_stage,
800 NULL,
801 fpi_device_retry_new (FP_DEVICE_RETRY_TOO_SHORT));
802 break;
803
804 default:
805 fp_err ("%s Unknown result code: %d ", G_STRFUNC, presp->status);
806 error = fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
807 "Enroll failed: %d",
808 presp->status);
809 break;
810 }
811
812
1/2
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 44 taken 14 times.
14 if (error)
813 {
814 fp_err ("%s error: %s ", G_STRFUNC, error->message);
815 fpi_ssm_mark_failed (self->task_ssm, error);
816 return;
817 }
818 else
819 {
820 14 fpi_ssm_jump_to_state (self->task_ssm, FPC_ENROLL_CAPTURE);
821 }
822 }
823
824 static void
825 1 fpc_enroll_complete_cb (FpiDeviceFpcMoc *self,
826 void *data,
827 GError *error)
828 {
829 1 FPC_END_ENROL *presp = NULL;
830
831 1 self->do_cleanup = FALSE;
832
833
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 8 not taken.
1 if (check_data (data, &error))
834 {
835 1 presp = (FPC_END_ENROL *) data;
836
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 1 time.
1 if (presp->status != 0)
837 {
838 error = fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
839 "End Enroll failed: %d",
840 presp->status);
841 }
842 else
843 {
844 1 fp_dbg ("Enrol End status: %d, fid: 0x%x",
845 presp->status, presp->fid);
846 }
847 }
848
849
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 12 taken 1 time.
1 if (error)
850 {
851 fp_err ("%s error: %s ", G_STRFUNC, error->message);
852 fpi_ssm_mark_failed (self->task_ssm, error);
853 return;
854 }
855 else
856 {
857 1 fpi_ssm_next_state (self->task_ssm);
858 }
859 }
860
861 static void
862 1 fpc_enroll_check_duplicate_cb (FpiDeviceFpcMoc *self,
863 void *data,
864 GError *error)
865 {
866 1 FPC_IDENTIFY *presp = NULL;
867
868
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 11 not taken.
1 if (check_data (data, &error))
869 {
870 1 presp = (FPC_IDENTIFY *) data;
871
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 11 taken 1 time.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 11 not taken.
1 if ((presp->status == 0) && (presp->subfactor == FPC_SUBTYPE_RESERVED) &&
872 (presp->identity_type == FPC_IDENTITY_TYPE_RESERVED) &&
873 (presp->identity_size <= SECURITY_MAX_SID_SIZE))
874 {
875 fp_info ("%s Got a duplicated template", G_STRFUNC);
876 error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_DUPLICATE);
877 }
878 }
879
880
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 15 taken 1 time.
1 if (error)
881 {
882 fp_err ("%s error: %s ", G_STRFUNC, error->message);
883 fpi_ssm_mark_failed (self->task_ssm, error);
884 return;
885 }
886 else
887 {
888 1 fpi_ssm_next_state (self->task_ssm);
889 }
890
891 }
892
893 static void
894 1 fpc_enroll_bindid_cb (FpiDeviceFpcMoc *self,
895 void *data,
896 GError *error)
897 {
898
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 1 time.
1 if (error)
899 {
900 fp_err ("%s error: %s ", G_STRFUNC, error->message);
901 fpi_ssm_mark_failed (self->task_ssm, error);
902 return;
903 }
904
905 1 fpi_ssm_next_state (self->task_ssm);
906 }
907
908 static void
909 1 fpc_enroll_commit_cb (FpiDeviceFpcMoc *self,
910 void *data,
911 GError *error)
912 {
913 1 gint32 *result = NULL;
914
915
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 7 not taken.
1 if (check_data (data, &error))
916 {
917 1 result = (gint32 *) data;
918
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 1 time.
1 if (*result != 0)
919 {
920 error = fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_FULL,
921 "Save DB failed: %d",
922 *result);
923 }
924 }
925
926
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 11 taken 1 time.
1 if (error)
927 {
928 fp_err ("%s error: %s ", G_STRFUNC, error->message);
929 fpi_ssm_mark_failed (self->task_ssm, error);
930 return;
931 }
932 else
933 {
934 1 fpi_ssm_mark_completed (self->task_ssm);
935 }
936 }
937
938
939 static void
940 53 fpc_enroll_sm_run_state (FpiSsm *ssm, FpDevice *device)
941 {
942 53 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
943 53 CommandData cmd_data = {0};
944 53 gsize recv_data_len = 0;
945
946
11/12
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 6 taken 1 time.
✓ Branch 3 → 8 taken 15 times.
✓ Branch 3 → 11 taken 15 times.
✓ Branch 3 → 13 taken 15 times.
✓ Branch 3 → 15 taken 1 time.
✓ Branch 3 → 17 taken 1 time.
✓ Branch 3 → 19 taken 1 time.
✓ Branch 3 → 32 taken 1 time.
✓ Branch 3 → 34 taken 1 time.
✓ Branch 3 → 36 taken 1 time.
✗ Branch 3 → 39 not taken.
53 switch (fpi_ssm_get_cur_state (ssm))
947 {
948 1 case FPC_ENROLL_ENUM:
949 {
950 1 FPC_FID_DATA pquery_data = {0};
951 1 gsize query_data_len = 0;
952 1 guint32 wildcard_value = FPC_IDENTITY_WILDCARD;
953 1 query_data_len = sizeof (FPC_FID_DATA);
954 1 pquery_data.identity_type = FPC_IDENTITY_TYPE_WILDCARD;
955 1 pquery_data.reserved = 16;
956 1 pquery_data.identity_size = sizeof (wildcard_value);
957 1 pquery_data.subfactor = (guint32) FPC_SUBTYPE_ANY;
958 1 memcpy (&pquery_data.data[0],
959 &wildcard_value, pquery_data.identity_size);
960
961 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE_EVTDATA;
962 1 cmd_data.request = FPC_CMD_ENUM;
963 1 cmd_data.value = 0x0;
964 1 cmd_data.index = 0x0;
965 1 cmd_data.data = (guint8 *) &pquery_data;
966 1 cmd_data.data_len = query_data_len;
967 1 cmd_data.callback = fpc_evt_cb;
968
969 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
970 }
971 1 break;
972
973 1 case FPC_ENROLL_CREATE:
974 {
975 1 recv_data_len = sizeof (FPC_BEGIN_ENROL);
976 1 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
977 1 cmd_data.request = FPC_CMD_BEGIN_ENROL;
978 1 cmd_data.value = 0x0;
979 1 cmd_data.index = 0x0;
980 1 cmd_data.data = NULL;
981 1 cmd_data.data_len = recv_data_len;
982 1 cmd_data.callback = fpc_enroll_create_cb;
983
984 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
985 }
986 1 break;
987
988 15 case FPC_ENROLL_CAPTURE:
989 {
990 15 guint32 capture_id = FPC_CAPTUREID_RESERVED;
991 15 fpi_device_report_finger_status_changes (device,
992 FP_FINGER_STATUS_NEEDED,
993 FP_FINGER_STATUS_NONE);
994 15 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE_EVTDATA;
995 15 cmd_data.request = FPC_CMD_ARM;
996 15 cmd_data.value = 0x1;
997 15 cmd_data.index = 0x0;
998 15 cmd_data.data = (guint8 *) &capture_id;
999 15 cmd_data.data_len = sizeof (guint32);
1000 15 cmd_data.callback = fpc_evt_cb;
1001
1002 15 fpc_sensor_cmd (self, TRUE, &cmd_data);
1003 }
1004 15 break;
1005
1006 15 case FPC_ENROLL_GET_IMG:
1007 {
1008 15 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE_EVTDATA;
1009 15 cmd_data.request = FPC_CMD_GET_IMG;
1010 15 cmd_data.value = 0x0;
1011 15 cmd_data.index = 0x0;
1012 15 cmd_data.data = NULL;
1013 15 cmd_data.data_len = 0;
1014 15 cmd_data.callback = fpc_evt_cb;
1015
1016 15 fpc_sensor_cmd (self, FALSE, &cmd_data);
1017 }
1018 15 break;
1019
1020 15 case FPC_ENROLL_UPDATE:
1021 {
1022 15 recv_data_len = sizeof (FPC_ENROL);
1023 15 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
1024 15 cmd_data.request = FPC_CMD_ENROL;
1025 15 cmd_data.value = 0x0;
1026 15 cmd_data.index = 0x0;
1027 15 cmd_data.data = NULL;
1028 15 cmd_data.data_len = recv_data_len;
1029 15 cmd_data.callback = fpc_enroll_update_cb;
1030
1031 15 fpc_sensor_cmd (self, FALSE, &cmd_data);
1032 }
1033 15 break;
1034
1035 1 case FPC_ENROLL_COMPLETE:
1036 {
1037 1 recv_data_len = sizeof (FPC_END_ENROL);
1038 1 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
1039 1 cmd_data.request = FPC_CMD_END_ENROL;
1040 1 cmd_data.value = 0x0;
1041 1 cmd_data.index = 0x0;
1042 1 cmd_data.data = NULL;
1043 1 cmd_data.data_len = recv_data_len;
1044 1 cmd_data.callback = fpc_enroll_complete_cb;
1045
1046 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1047 }
1048 1 break;
1049
1050 1 case FPC_ENROLL_CHECK_DUPLICATE:
1051 {
1052 1 recv_data_len = sizeof (FPC_IDENTIFY);
1053 1 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
1054 1 cmd_data.request = FPC_CMD_IDENTIFY;
1055 1 cmd_data.value = 0x0;
1056 1 cmd_data.index = 0x0;
1057 1 cmd_data.data = NULL;
1058 1 cmd_data.data_len = recv_data_len;
1059 1 cmd_data.callback = fpc_enroll_check_duplicate_cb;
1060
1061 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1062 }
1063 1 break;
1064
1065 1 case FPC_ENROLL_BINDID:
1066 {
1067 1 FPC_FID_DATA data = {0};
1068 1 gsize data_len = 0;
1069 1 FpPrint *print = NULL;
1070 1 GVariant *fpi_data = NULL;
1071 1 GVariant *uid = NULL;
1072 1 guint finger = FPC_SUBTYPE_RESERVED;
1073 2 g_autofree gchar *user_id = NULL;
1074 1 gssize user_id_len;
1075 1 g_autofree guint8 *payload = NULL;
1076
1077 1 fpi_device_get_enroll_data (device, &print);
1078
1079 1 user_id = fpi_print_generate_user_id (print);
1080
1081 1 user_id_len = strlen (user_id);
1082 1 user_id_len = MIN (SECURITY_MAX_SID_SIZE, user_id_len);
1083
1084 1 uid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
1085 user_id,
1086 user_id_len,
1087 1);
1088 1 fpi_data = g_variant_new ("(y@ay)",
1089 finger,
1090 uid);
1091
1092 1 fpi_print_set_type (print, FPI_PRINT_RAW);
1093 1 fpi_print_set_device_stored (print, TRUE);
1094 1 g_object_set (print, "fpi-data", fpi_data, NULL);
1095 1 g_object_set (print, "description", user_id, NULL);
1096
1097 1 fp_dbg ("user_id: %s, finger: 0x%x", user_id, finger);
1098
1099 1 data_len = sizeof (FPC_FID_DATA);
1100 1 data.identity_type = FPC_IDENTITY_TYPE_RESERVED;
1101 1 data.reserved = 16;
1102 1 data.identity_size = user_id_len;
1103 1 data.subfactor = (guint32) finger;
1104 1 memcpy (&data.data[0],
1105 user_id, user_id_len);
1106
1107 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE;
1108 1 cmd_data.request = FPC_CMD_BIND_IDENTITY;
1109 1 cmd_data.value = 0x0;
1110 1 cmd_data.index = 0x0;
1111 1 cmd_data.data = (guint8 *) &data;
1112 1 cmd_data.data_len = data_len;
1113 1 cmd_data.callback = fpc_enroll_bindid_cb;
1114
1115 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1116 }
1117 1 break;
1118
1119 1 case FPC_ENROLL_COMMIT:
1120 {
1121 1 recv_data_len = sizeof (gint32);
1122 1 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
1123 1 cmd_data.request = FPC_CMD_STORE_DB;
1124 1 cmd_data.value = 0x0;
1125 1 cmd_data.index = 0x0;
1126 1 cmd_data.data = NULL;
1127 1 cmd_data.data_len = recv_data_len;
1128 1 cmd_data.callback = fpc_enroll_commit_cb;
1129
1130 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1131 }
1132 1 break;
1133
1134 1 case FPC_ENROLL_DICARD:
1135 {
1136 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE;
1137 1 cmd_data.request = FPC_CMD_ABORT;
1138 1 cmd_data.value = 0x1;
1139 1 cmd_data.index = 0x0;
1140 1 cmd_data.data = NULL;
1141 1 cmd_data.data_len = 0;
1142 1 cmd_data.callback = fpc_do_abort_cb;
1143 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1144 }
1145 1 break;
1146
1147 1 case FPC_ENROLL_CLEANUP:
1148 {
1149
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 1 time.
1 if (self->do_cleanup == TRUE)
1150 {
1151 recv_data_len = sizeof (FPC_END_ENROL);
1152 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
1153 cmd_data.request = FPC_CMD_END_ENROL;
1154 cmd_data.value = 0x0;
1155 cmd_data.index = 0x0;
1156 cmd_data.data = NULL;
1157 cmd_data.data_len = recv_data_len;
1158 cmd_data.callback = fpc_do_cleanup_cb;
1159 fpc_sensor_cmd (self, FALSE, &cmd_data);
1160 }
1161 else
1162 {
1163 1 fpi_ssm_next_state (self->task_ssm);
1164 }
1165 }
1166 break;
1167 }
1168 53 }
1169
1170 static void
1171 1 fpc_enroll_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
1172 {
1173 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (dev);
1174 1 FpPrint *print = NULL;
1175
1176 1 fp_info ("Enrollment complete!");
1177
1178
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1 time.
1 if (error)
1179 {
1180 fpi_device_enroll_complete (dev, NULL, g_steal_pointer (&error));
1181 self->task_ssm = NULL;
1182 return;
1183 }
1184
1185 1 fpi_device_get_enroll_data (FP_DEVICE (self), &print);
1186 1 fpi_device_enroll_complete (FP_DEVICE (self), g_object_ref (print), NULL);
1187 1 self->task_ssm = NULL;
1188 }
1189
1190 /******************************************************************************
1191 *
1192 * fpc_verify_xxx function
1193 *
1194 *****************************************************************************/
1195
1196 static void
1197 2 fpc_verify_cb (FpiDeviceFpcMoc *self,
1198 void *data,
1199 GError *error)
1200 {
1201 2 g_autoptr(GPtrArray) templates = NULL;
1202 2 FpDevice *device = FP_DEVICE (self);
1203 2 gboolean found = FALSE;
1204 2 FpiDeviceAction current_action;
1205 2 FPC_IDENTIFY *presp = NULL;
1206
1207
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 2 times.
2 if (!check_data (data, &error))
1208 {
1209 fp_err ("%s error: %s ", G_STRFUNC, error->message);
1210 fpi_ssm_mark_failed (self->task_ssm, error);
1211 return;
1212 }
1213
1214 2 presp = (FPC_IDENTIFY *) data;
1215 2 current_action = fpi_device_get_current_action (device);
1216
1217
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 2 times.
2 g_assert (current_action == FPI_DEVICE_ACTION_VERIFY ||
1218 current_action == FPI_DEVICE_ACTION_IDENTIFY);
1219
1220
2/4
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 32 not taken.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 32 not taken.
2 if ((presp->status == 0) && (presp->subfactor == FPC_SUBTYPE_RESERVED) &&
1221
1/2
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 32 not taken.
2 (presp->identity_type == FPC_IDENTITY_TYPE_RESERVED) &&
1222
1/2
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 32 not taken.
2 (presp->identity_size <= SECURITY_MAX_SID_SIZE))
1223 {
1224 2 FpPrint *match = NULL;
1225 2 FpPrint *print = NULL;
1226 2 gint cnt = 0;
1227 2 fpc_fid_data_t fid_data = {0};
1228
1229 2 fid_data.subfactor = presp->subfactor;
1230 2 fid_data.identity_type = presp->identity_type;
1231 2 fid_data.identity_size = presp->identity_size;
1232 2 memcpy (fid_data.identity, &presp->data[0],
1233 fid_data.identity_size);
1234
1235 2 match = fpc_print_from_data (self, &fid_data);
1236
1237
2/2
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 18 taken 1 time.
2 if (current_action == FPI_DEVICE_ACTION_VERIFY)
1238 {
1239 1 templates = g_ptr_array_sized_new (1);
1240 1 fpi_device_get_verify_data (device, &print);
1241 1 g_ptr_array_add (templates, print);
1242 }
1243 else
1244 {
1245 1 fpi_device_get_identify_data (device, &templates);
1246 1 g_ptr_array_ref (templates);
1247 }
1248
1249
1/2
✓ Branch 24 → 21 taken 2 times.
✗ Branch 24 → 25 not taken.
2 for (cnt = 0; cnt < templates->len; cnt++)
1250 {
1251 2 print = g_ptr_array_index (templates, cnt);
1252
1253
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 25 taken 2 times.
2 if (fp_print_equal (print, match))
1254 {
1255 found = TRUE;
1256 break;
1257 }
1258 }
1259
1260
1/2
✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 31 not taken.
2 if (found)
1261 {
1262
2/2
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 28 taken 1 time.
2 if (current_action == FPI_DEVICE_ACTION_VERIFY)
1263 1 fpi_device_verify_report (device, FPI_MATCH_SUCCESS, match, error);
1264 else
1265 1 fpi_device_identify_report (device, print, match, error);
1266
1267 2 fpi_ssm_mark_completed (self->task_ssm);
1268 2 return;
1269 }
1270 }
1271
1272 if (!found)
1273 {
1274 if (current_action == FPI_DEVICE_ACTION_VERIFY)
1275 fpi_device_verify_report (device, FPI_MATCH_FAIL, NULL, error);
1276 else
1277 fpi_device_identify_report (device, NULL, NULL, error);
1278 }
1279
1280 /* This is the last state for verify/identify */
1281 fpi_ssm_mark_completed (self->task_ssm);
1282 }
1283
1284 static void
1285 8 fpc_verify_sm_run_state (FpiSsm *ssm, FpDevice *device)
1286 {
1287 8 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1288 8 CommandData cmd_data = {0};
1289
1290
4/5
✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 7 taken 2 times.
✓ Branch 3 → 9 taken 2 times.
✓ Branch 3 → 11 taken 2 times.
✗ Branch 3 → 13 not taken.
8 switch (fpi_ssm_get_cur_state (ssm))
1291 {
1292 2 case FPC_VERIFY_CAPTURE:
1293 {
1294 2 guint32 capture_id = FPC_CAPTUREID_RESERVED;
1295 2 fpi_device_report_finger_status_changes (device,
1296 FP_FINGER_STATUS_NEEDED,
1297 FP_FINGER_STATUS_NONE);
1298 2 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE_EVTDATA;
1299 2 cmd_data.request = FPC_CMD_ARM;
1300 2 cmd_data.value = 0x1;
1301 2 cmd_data.index = 0x0;
1302 2 cmd_data.data = (guint8 *) &capture_id;
1303 2 cmd_data.data_len = sizeof (guint32);
1304 2 cmd_data.callback = fpc_evt_cb;
1305
1306 2 fpc_sensor_cmd (self, TRUE, &cmd_data);
1307 }
1308 2 break;
1309
1310 2 case FPC_VERIFY_GET_IMG:
1311 {
1312 2 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE_EVTDATA;
1313 2 cmd_data.request = FPC_CMD_GET_IMG;
1314 2 cmd_data.value = 0x0;
1315 2 cmd_data.index = 0x0;
1316 2 cmd_data.data = NULL;
1317 2 cmd_data.data_len = 0;
1318 2 cmd_data.callback = fpc_evt_cb;
1319
1320 2 fpc_sensor_cmd (self, FALSE, &cmd_data);
1321 }
1322 2 break;
1323
1324 2 case FPC_VERIFY_IDENTIFY:
1325 {
1326 2 gsize recv_data_len = sizeof (FPC_IDENTIFY);
1327 2 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
1328 2 cmd_data.request = FPC_CMD_IDENTIFY;
1329 2 cmd_data.value = 0x0;
1330 2 cmd_data.index = 0x0;
1331 2 cmd_data.data = NULL;
1332 2 cmd_data.data_len = recv_data_len;
1333 2 cmd_data.callback = fpc_verify_cb;
1334
1335 2 fpc_sensor_cmd (self, FALSE, &cmd_data);
1336 }
1337 2 break;
1338
1339 2 case FPC_VERIFY_CANCEL:
1340 {
1341 2 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE;
1342 2 cmd_data.request = FPC_CMD_ABORT;
1343 2 cmd_data.value = 0x1;
1344 2 cmd_data.index = 0x0;
1345 2 cmd_data.data = NULL;
1346 2 cmd_data.data_len = 0;
1347 2 cmd_data.callback = fpc_do_abort_cb;
1348 2 fpc_sensor_cmd (self, FALSE, &cmd_data);
1349
1350 }
1351 2 break;
1352 }
1353 8 }
1354
1355 static void
1356 2 fpc_verify_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
1357 {
1358 2 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (dev);
1359
1360 2 fp_info ("Verify_identify complete!");
1361
1362
1/4
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 10 taken 2 times.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 10 not taken.
2 if (error && error->domain == FP_DEVICE_RETRY)
1363 {
1364 if (fpi_device_get_current_action (dev) == FPI_DEVICE_ACTION_VERIFY)
1365 fpi_device_verify_report (dev, FPI_MATCH_ERROR, NULL, g_steal_pointer (&error));
1366 else
1367 fpi_device_identify_report (dev, NULL, NULL, g_steal_pointer (&error));
1368 }
1369
1370
2/2
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 1 time.
2 if (fpi_device_get_current_action (dev) == FPI_DEVICE_ACTION_VERIFY)
1371 1 fpi_device_verify_complete (dev, g_steal_pointer (&error));
1372 else
1373 1 fpi_device_identify_complete (dev, g_steal_pointer (&error));
1374
1375 2 self->task_ssm = NULL;
1376 2 }
1377
1378 /******************************************************************************
1379 *
1380 * fpc_init_xxx function
1381 *
1382 *****************************************************************************/
1383 static void
1384 2 fpc_clear_storage_cb (FpiDeviceFpcMoc *self,
1385 void *resp,
1386 GError *error)
1387 {
1388
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 2 times.
2 if (error)
1389 {
1390 fp_err ("%s error: %s ", G_STRFUNC, error->message);
1391 fpi_ssm_mark_failed (self->task_ssm, error);
1392 return;
1393 }
1394
1395 2 fpi_ssm_next_state (self->task_ssm);
1396
1397 }
1398
1399 static void
1400 2 fpc_clear_sm_run_state (FpiSsm *ssm, FpDevice *device)
1401 {
1402 2 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1403 2 CommandData cmd_data = {0};
1404 2 FPC_DB_OP data = {0};
1405 2 gsize data_len = 0;
1406
1407
2/3
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 8 taken 1 time.
✗ Branch 3 → 12 not taken.
2 switch (fpi_ssm_get_cur_state (ssm))
1408 {
1409 1 case FPC_CLEAR_DELETE_DB:
1410 {
1411
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 6 not taken.
1 if (self->dbid)
1412 {
1413 1 data_len = sizeof (FPC_DB_OP);
1414 1 data.database_id_size = FPC_DB_ID_LEN;
1415 1 data.reserved = 8;
1416 1 memcpy (&data.data[0], self->dbid, FPC_DB_ID_LEN);
1417 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE;
1418 1 cmd_data.request = FPC_CMD_DELETE_DB;
1419 1 cmd_data.value = 0x0;
1420 1 cmd_data.index = 0x0;
1421 1 cmd_data.data = (guint8 *) &data;
1422 1 cmd_data.data_len = data_len;
1423 1 cmd_data.callback = fpc_clear_storage_cb;
1424 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1425 }
1426 else
1427 {
1428 fpi_ssm_mark_failed (self->task_ssm,
1429 fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED,
1430 "No DBID found"));
1431 }
1432
1433 }
1434 break;
1435
1436 1 case FPC_CLEAR_CREATE_DB:
1437 {
1438
1/2
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 10 not taken.
1 if (self->dbid)
1439 {
1440 1 data_len = sizeof (FPC_DB_OP);
1441 1 data.database_id_size = FPC_DB_ID_LEN;
1442 1 data.reserved = 8;
1443 1 memcpy (&data.data[0], self->dbid, FPC_DB_ID_LEN);
1444 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE;
1445 1 cmd_data.request = FPC_CMD_LOAD_DB;
1446 1 cmd_data.value = 0x1;
1447 1 cmd_data.index = 0x0;
1448 1 cmd_data.data = (guint8 *) &data;
1449 1 cmd_data.data_len = data_len;
1450 1 cmd_data.callback = fpc_clear_storage_cb;
1451 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1452 }
1453 else
1454 {
1455 fpi_ssm_mark_failed (self->task_ssm,
1456 fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED,
1457 "No DBID found"));
1458 }
1459 }
1460 break;
1461 }
1462 2 }
1463
1464 static void
1465 1 fpc_clear_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
1466 {
1467 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (dev);
1468
1469 1 fp_info ("Clear Storage complete!");
1470
1471 1 fpi_device_clear_storage_complete (dev, g_steal_pointer (&error));
1472 1 self->task_ssm = NULL;
1473 1 }
1474
1475 /******************************************************************************
1476 *
1477 * fpc_init_xxx function
1478 *
1479 *****************************************************************************/
1480
1481 static void
1482 1 fpc_init_load_db_cb (FpiDeviceFpcMoc *self,
1483 void *data,
1484 GError *error)
1485 {
1486 1 FPC_LOAD_DB *presp = NULL;
1487
1488
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 1 time.
1 if (error)
1489 {
1490 fp_err ("%s error: %s ", G_STRFUNC, error->message);
1491 fpi_ssm_mark_failed (self->task_ssm, error);
1492 return;
1493 }
1494
1495
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 10 taken 1 time.
1 if (data == NULL)
1496 {
1497 fpi_ssm_mark_failed (self->task_ssm,
1498 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
1499 return;
1500 }
1501 1 presp = (FPC_LOAD_DB *) data;
1502
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 1 time.
1 if (presp->status)
1503 {
1504 fp_err ("%s Load DB failed: %d - Expect to create a new one", G_STRFUNC, presp->status);
1505 fpi_ssm_next_state (self->task_ssm);
1506 return;
1507 }
1508
1509
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 1 time.
1 g_clear_pointer (&self->dbid, g_free);
1510 1 self->dbid = g_memdup2 (presp->data, FPC_DB_ID_LEN);
1511
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 21 taken 1 time.
1 if (self->dbid == NULL)
1512 {
1513 fpi_ssm_mark_failed (self->task_ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
1514 return;
1515 }
1516
1517 1 fp_dbg ("%s got dbid size: %d", G_STRFUNC, presp->database_id_size);
1518 1 fp_dbg ("%s dbid: 0x%02x%02x%02x%02x-%02x%02x-%02x%02x-" \
1519 "%02x%02x-%02x%02x%02x%02x%02x%02x",
1520 G_STRFUNC,
1521 presp->data[0], presp->data[1],
1522 presp->data[2], presp->data[3],
1523 presp->data[4], presp->data[5],
1524 presp->data[6], presp->data[7],
1525 presp->data[8], presp->data[9],
1526 presp->data[10], presp->data[11],
1527 presp->data[12], presp->data[13],
1528 presp->data[14], presp->data[15]);
1529 1 fpi_ssm_mark_completed (self->task_ssm);
1530 }
1531
1532 static void
1533 2 fpc_init_sm_run_state (FpiSsm *ssm, FpDevice *device)
1534 {
1535 2 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1536 2 guint32 session_id = FPC_SESSIONID_RESERVED;
1537 2 CommandData cmd_data = {0};
1538
1539
2/3
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 6 taken 1 time.
✗ Branch 3 → 8 not taken.
2 switch (fpi_ssm_get_cur_state (ssm))
1540 {
1541 1 case FPC_INIT:
1542 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE_EVTDATA;
1543 1 cmd_data.request = FPC_CMD_INIT;
1544 1 cmd_data.value = 0x1;
1545 1 cmd_data.index = 0x0;
1546 1 cmd_data.data = (guint8 *) &session_id;
1547 1 cmd_data.data_len = sizeof (session_id);
1548 1 cmd_data.callback = fpc_evt_cb;
1549
1550 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1551 1 break;
1552
1553 1 case FPC_INIT_LOAD_DB:
1554 {
1555 1 gsize recv_data_len = sizeof (FPC_LOAD_DB);
1556 1 cmd_data.cmdtype = FPC_CMDTYPE_FROM_DEVICE;
1557 1 cmd_data.request = FPC_CMD_LOAD_DB;
1558 1 cmd_data.value = 0x0;
1559 1 cmd_data.index = 0x0;
1560 1 cmd_data.data = NULL;
1561 1 cmd_data.data_len = recv_data_len;
1562 1 cmd_data.callback = fpc_init_load_db_cb;
1563
1564 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1565 }
1566 1 break;
1567 }
1568 2 }
1569
1570 static void
1571 1 fpc_init_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
1572 {
1573 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (dev);
1574
1575 1 fpi_device_open_complete (dev, g_steal_pointer (&error));
1576 1 self->task_ssm = NULL;
1577 1 }
1578
1579 /******************************************************************************
1580 *
1581 * Interface Function
1582 *
1583 *****************************************************************************/
1584
1585 static void
1586 1 fpc_dev_probe (FpDevice *device)
1587 {
1588 1 GUsbDevice *usb_dev;
1589 1 GError *error = NULL;
1590 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1591 1 g_autofree gchar *product = NULL;
1592 1 gint product_id = 0;
1593
1594 1 fp_dbg ("%s enter --> ", G_STRFUNC);
1595
1596 /* Claim usb interface */
1597 1 usb_dev = fpi_device_get_usb_device (device);
1598
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 1 time.
1 if (!g_usb_device_open (usb_dev, &error))
1599 {
1600 fp_dbg ("%s g_usb_device_open failed %s", G_STRFUNC, error->message);
1601 fpi_device_probe_complete (device, NULL, NULL, error);
1602 return;
1603 }
1604
1605
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 1 time.
1 if (!g_usb_device_reset (usb_dev, &error))
1606 {
1607 fp_dbg ("%s g_usb_device_reset failed %s", G_STRFUNC, error->message);
1608 g_usb_device_close (usb_dev, NULL);
1609 fpi_device_probe_complete (device, NULL, NULL, error);
1610 return;
1611 }
1612
1613
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 20 taken 1 time.
1 if (!g_usb_device_claim_interface (usb_dev, 0, 0, &error))
1614 {
1615 fp_dbg ("%s g_usb_device_claim_interface failed %s", G_STRFUNC, error->message);
1616 g_usb_device_close (usb_dev, NULL);
1617 fpi_device_probe_complete (device, NULL, NULL, error);
1618 return;
1619 }
1620
1621 1 product = g_usb_device_get_string_descriptor (usb_dev,
1622 g_usb_device_get_product_index (usb_dev),
1623 &error);
1624
1/2
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 24 not taken.
1 if (product)
1625 1 fp_dbg ("Device name: %s", product);
1626
1627
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 31 taken 1 time.
1 if (error)
1628 {
1629 fp_dbg ("%s g_usb_device_get_string_descriptor failed %s", G_STRFUNC, error->message);
1630 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (device)),
1631 0, 0, NULL);
1632 g_usb_device_close (usb_dev, NULL);
1633 fpi_device_probe_complete (device, NULL, NULL, error);
1634 return;
1635 }
1636
1637 1 product_id = g_usb_device_get_pid (usb_dev);
1638 /* Reserved for customer enroll scheme */
1639 1 self->max_immobile_stage = 0; /* By default is not customer enrollment */
1640
1/2
✓ Branch 32 → 33 taken 1 time.
✗ Branch 32 → 34 not taken.
1 switch (product_id)
1641 {
1642 1 case 0xFFE0:
1643 case 0xA305:
1644 case 0xA306:
1645 case 0xD805:
1646 case 0xDA04:
1647 case 0xD205:
1648 case 0x9524:
1649 case 0x9544:
1650 case 0xC844:
1651 1 self->max_enroll_stage = MAX_ENROLL_SAMPLES;
1652 1 break;
1653
1654 default:
1655 fp_warn ("Device %x is not supported", product_id);
1656 self->max_enroll_stage = MAX_ENROLL_SAMPLES;
1657 break;
1658 }
1659 1 fpi_device_set_nr_enroll_stages (device, self->max_enroll_stage);
1660 1 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (device)),
1661 0, 0, NULL);
1662 1 g_usb_device_close (usb_dev, NULL);
1663 1 fpi_device_probe_complete (device, NULL, product, error);
1664 }
1665
1666 static void
1667 1 fpc_dev_open (FpDevice *device)
1668 {
1669 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1670 1 GError *error = NULL;
1671
1672 1 fp_dbg ("%s enter -->", G_STRFUNC);
1673
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 1 time.
1 if (!g_usb_device_reset (fpi_device_get_usb_device (device), &error))
1674 {
1675 fpi_device_open_complete (FP_DEVICE (self), error);
1676 return;
1677 }
1678
1679 /* Claim usb interface */
1680
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 12 taken 1 time.
1 if (!g_usb_device_claim_interface (fpi_device_get_usb_device (device), 0, 0, &error))
1681 {
1682 fpi_device_open_complete (FP_DEVICE (self), error);
1683 return;
1684 }
1685
1686 1 self->task_ssm = fpi_ssm_new (device, fpc_init_sm_run_state,
1687 FPC_INIT_NUM_STATES);
1688
1689 1 fpi_ssm_start (self->task_ssm, fpc_init_ssm_done);
1690 }
1691
1692 static void
1693 1 fpc_dev_close (FpDevice *device)
1694 {
1695 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1696
1697 1 fp_dbg ("%s enter -->", G_STRFUNC);
1698
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 5 not taken.
1 g_clear_pointer (&self->dbid, g_free);
1699 1 g_cancellable_cancel (self->interrupt_cancellable);
1700
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 1 time.
1 g_clear_object (&self->interrupt_cancellable);
1701 1 fpc_dev_release_interface (self, NULL);
1702 1 }
1703
1704 static void
1705 2 fpc_dev_verify_identify (FpDevice *device)
1706 {
1707 2 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1708
1709 2 fp_dbg ("%s enter -->", G_STRFUNC);
1710 2 self->task_ssm = fpi_ssm_new_full (device, fpc_verify_sm_run_state,
1711 FPC_VERIFY_NUM_STATES,
1712 FPC_VERIFY_CANCEL,
1713 "verify_identify");
1714
1715 2 fpi_ssm_start (self->task_ssm, fpc_verify_ssm_done);
1716 2 }
1717
1718 static void
1719 1 fpc_dev_enroll (FpDevice *device)
1720 {
1721 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1722
1723 1 fp_dbg ("%s enter -->", G_STRFUNC);
1724
1725 1 self->enroll_stage = 0;
1726 1 self->immobile_stage = 0;
1727 1 self->task_ssm = fpi_ssm_new_full (device, fpc_enroll_sm_run_state,
1728 FPC_ENROLL_NUM_STATES,
1729 FPC_ENROLL_DICARD,
1730 "enroll");
1731
1732 1 fpi_ssm_start (self->task_ssm, fpc_enroll_ssm_done);
1733 1 }
1734
1735 static void
1736 1 fpc_dev_template_list (FpDevice *device)
1737 {
1738 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1739 1 CommandData cmd_data = {0};
1740 1 FPC_FID_DATA pquery_data = {0};
1741 1 gsize query_data_len = 0;
1742 1 guint32 wildcard_value = FPC_IDENTITY_WILDCARD;
1743
1744 1 fp_dbg ("%s enter -->", G_STRFUNC);
1745
1746 1 query_data_len = sizeof (FPC_FID_DATA);
1747 1 pquery_data.identity_type = FPC_IDENTITY_TYPE_WILDCARD;
1748 1 pquery_data.reserved = 16;
1749 1 pquery_data.identity_size = sizeof (wildcard_value);
1750 1 pquery_data.subfactor = (guint32) FPC_SUBTYPE_ANY;
1751 1 memcpy (&pquery_data.data[0],
1752 &wildcard_value, pquery_data.identity_size);
1753
1754 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE_EVTDATA;
1755 1 cmd_data.request = FPC_CMD_ENUM;
1756 1 cmd_data.value = 0x0;
1757 1 cmd_data.index = 0x0;
1758 1 cmd_data.data = (guint8 *) &pquery_data;
1759 1 cmd_data.data_len = query_data_len;
1760 1 cmd_data.callback = fpc_template_list_cb;
1761
1762 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1763 1 }
1764
1765 static void
1766 fpc_dev_suspend (FpDevice *device)
1767 {
1768 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1769 FpiDeviceAction action = fpi_device_get_current_action (device);
1770
1771 fp_dbg ("%s enter -->", G_STRFUNC);
1772
1773 if (action != FPI_DEVICE_ACTION_VERIFY && action != FPI_DEVICE_ACTION_IDENTIFY)
1774 {
1775 fpi_device_suspend_complete (device, fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED));
1776 return;
1777 }
1778
1779 g_assert (self->cmd_ssm);
1780 g_assert (fpi_ssm_get_cur_state (self->cmd_ssm) == FPC_CMD_GET_DATA);
1781 self->cmd_suspended = TRUE;
1782 g_cancellable_cancel (self->interrupt_cancellable);
1783 }
1784
1785 static void
1786 fpc_dev_resume (FpDevice *device)
1787 {
1788 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1789 FpiDeviceAction action = fpi_device_get_current_action (device);
1790
1791 fp_dbg ("%s enter -->", G_STRFUNC);
1792
1793 if (action != FPI_DEVICE_ACTION_VERIFY && action != FPI_DEVICE_ACTION_IDENTIFY)
1794 {
1795 g_assert_not_reached ();
1796 fpi_device_resume_complete (device, fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED));
1797 return;
1798 }
1799
1800 g_assert (self->cmd_ssm);
1801 g_assert (self->cmd_suspended);
1802 g_assert (fpi_ssm_get_cur_state (self->cmd_ssm) == FPC_CMD_SUSPENDED);
1803 self->cmd_suspended = FALSE;
1804
1805 g_clear_object (&self->interrupt_cancellable);
1806 self->interrupt_cancellable = g_cancellable_new ();
1807 fpi_ssm_jump_to_state (self->cmd_ssm, FPC_CMD_RESUME);
1808 }
1809
1810 static void
1811 fpc_dev_cancel (FpDevice *device)
1812 {
1813 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1814
1815 fp_dbg ("%s enter -->", G_STRFUNC);
1816 g_cancellable_cancel (self->interrupt_cancellable);
1817 }
1818
1819 static void
1820 1 fpc_dev_template_delete (FpDevice *device)
1821 {
1822 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1823 1 CommandData cmd_data = {0};
1824 1 FpPrint *print = NULL;
1825
1826 1 g_autoptr(GVariant) fpi_data = NULL;
1827 1 FPC_FID_DATA data = {0};
1828 1 gsize data_len = 0;
1829 1 guint8 finger = FPC_SUBTYPE_NOINFORMATION;
1830 1 const guint8 *user_id;
1831 1 gsize user_id_len = 0;
1832
1833 1 fp_dbg ("%s enter -->", G_STRFUNC);
1834
1835 1 fpi_device_get_delete_data (device, &print);
1836
1837 1 g_object_get (print, "fpi-data", &fpi_data, NULL);
1838
1839
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 12 taken 1 time.
1 if (!parse_print_data (fpi_data, &finger, &user_id, &user_id_len))
1840 {
1841 fpi_device_delete_complete (device,
1842 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
1843 return;
1844 }
1845
1846 1 data_len = sizeof (FPC_FID_DATA);
1847 1 data.identity_type = FPC_IDENTITY_TYPE_RESERVED;
1848 1 data.reserved = 16;
1849 1 data.identity_size = user_id_len;
1850 1 data.subfactor = (guint32) finger;
1851 1 memcpy (&data.data[0], user_id, user_id_len);
1852 1 cmd_data.cmdtype = FPC_CMDTYPE_TO_DEVICE;
1853 1 cmd_data.request = FPC_CMD_DELETE_TEMPLATE;
1854 1 cmd_data.value = 0x0;
1855 1 cmd_data.index = 0x0;
1856 1 cmd_data.data = (guint8 *) &data;
1857 1 cmd_data.data_len = data_len;
1858 1 cmd_data.callback = fpc_template_delete_cb;
1859
1860 1 fpc_sensor_cmd (self, FALSE, &cmd_data);
1861
1/2
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 16 not taken.
1 fp_dbg ("%s exit <--", G_STRFUNC);
1862 }
1863
1864 static void
1865 1 fpc_dev_clear_storage (FpDevice *device)
1866 {
1867 1 FpiDeviceFpcMoc *self = FPI_DEVICE_FPCMOC (device);
1868
1869 1 fp_dbg ("%s enter -->", G_STRFUNC);
1870 1 self->task_ssm = fpi_ssm_new_full (device, fpc_clear_sm_run_state,
1871 FPC_CLEAR_NUM_STATES,
1872 FPC_CLEAR_NUM_STATES,
1873 "Clear storage");
1874
1875 1 fpi_ssm_start (self->task_ssm, fpc_clear_ssm_done);
1876 1 }
1877
1878 static void
1879 1 fpi_device_fpcmoc_init (FpiDeviceFpcMoc *self)
1880 {
1881 1 fp_dbg ("%s enter -->", G_STRFUNC);
1882 1 G_DEBUG_HERE ();
1883 1 }
1884
1885 static void
1886 121 fpi_device_fpcmoc_class_init (FpiDeviceFpcMocClass *klass)
1887 {
1888 121 FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
1889
1890 121 dev_class->id = FP_COMPONENT;
1891 121 dev_class->full_name = "FPC MOC Fingerprint Sensor";
1892 121 dev_class->type = FP_DEVICE_TYPE_USB;
1893 121 dev_class->scan_type = FP_SCAN_TYPE_PRESS;
1894 121 dev_class->id_table = id_table;
1895 121 dev_class->nr_enroll_stages = MAX_ENROLL_SAMPLES;
1896 121 dev_class->temp_hot_seconds = -1;
1897
1898 121 dev_class->open = fpc_dev_open;
1899 121 dev_class->close = fpc_dev_close;
1900 121 dev_class->probe = fpc_dev_probe;
1901 121 dev_class->enroll = fpc_dev_enroll;
1902 121 dev_class->delete = fpc_dev_template_delete;
1903 121 dev_class->list = fpc_dev_template_list;
1904 121 dev_class->verify = fpc_dev_verify_identify;
1905 121 dev_class->identify = fpc_dev_verify_identify;
1906 121 dev_class->suspend = fpc_dev_suspend;
1907 121 dev_class->resume = fpc_dev_resume;
1908 121 dev_class->clear_storage = fpc_dev_clear_storage;
1909 121 dev_class->cancel = fpc_dev_cancel;
1910
1911 121 fpi_device_class_auto_initialize_features (dev_class);
1912 121 dev_class->features |= FP_DEVICE_FEATURE_DUPLICATES_CHECK;
1913 121 }
1914