GCC Code Coverage Report


Directory: ./
File: libfprint/drivers/fpcmoc/fpc.c
Date: 2025-12-06 02:24:24
Exec Total Coverage
Lines: 719 959 75.0%
Functions: 43 48 89.6%
Branches: 152 309 49.2%

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