GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 83.2% 558 / 0 / 671
Functions: 100.0% 45 / 0 / 45
Branches: 59.2% 145 / 0 / 245

libfprint/drivers/realtek/realtek.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2022-2023 Realtek Corp.
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 #define FP_COMPONENT "realtek"
20
21 #include "drivers_api.h"
22
23 #include "fpi-byte-reader.h"
24
25 #include "realtek.h"
26
27
4/6
fpi_device_realtek_class_intern_init:
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 128 times.
fpi_device_realtek_get_type:
✓ Branch 2 → 3 taken 128 times.
✓ Branch 2 → 7 taken 24 times.
✓ Branch 4 → 5 taken 128 times.
✗ Branch 4 → 7 not taken.
408 G_DEFINE_TYPE (FpiDeviceRealtek, fpi_device_realtek, FP_TYPE_DEVICE)
28
29 static const FpIdEntry id_table[] = {
30 { .vid = 0x0bda, .pid = 0x5813, },
31 { .vid = 0x0bda, .pid = 0x5816, },
32 { .vid = 0x2541, .pid = 0xfa03, },
33 { .vid = 0x3274, .pid = 0x9003, },
34 { .vid = 0, .pid = 0, .driver_data = 0 }, /* terminating entry */
35 };
36
37 static gboolean
38 4 parse_print_data (GVariant *data,
39 guint8 *finger,
40 const guint8 **user_id,
41 gsize *user_id_len)
42 {
43 8 g_autoptr(GVariant) user_id_var = NULL;
44
45
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 4 times.
4 g_return_val_if_fail (data, FALSE);
46
1/2
✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 6 not taken.
4 g_return_val_if_fail (finger, FALSE);
47
1/2
✓ Branch 5 → 7 taken 4 times.
✗ Branch 5 → 8 not taken.
4 g_return_val_if_fail (user_id, FALSE);
48
1/2
✓ Branch 7 → 9 taken 4 times.
✗ Branch 7 → 11 not taken.
4 g_return_val_if_fail (user_id_len, FALSE);
49
50 4 *user_id = NULL;
51 4 *user_id_len = 0;
52 4 *finger = 0;
53
54
1/2
✓ Branch 10 → 12 taken 4 times.
✗ Branch 10 → 18 not taken.
4 if (!g_variant_check_format_string (data, "(y@ay)", FALSE))
55 return FALSE;
56
57 4 g_variant_get (data,
58 "(y@ay)",
59 finger,
60 &user_id_var);
61
62 4 *user_id = g_variant_get_fixed_array (user_id_var, user_id_len, 1);
63
64
1/2
✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 18 not taken.
4 if (*user_id_len == 0 || *user_id_len > DEFAULT_UID_LEN)
65 return FALSE;
66
67
1/2
✓ Branch 15 → 16 taken 4 times.
✗ Branch 15 → 18 not taken.
4 if (*user_id[0] == '\0' || *user_id[0] == ' ')
68 return FALSE;
69
70
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 4 times.
4 if (*finger != SUB_FINGER_01)
71 return FALSE;
72
73 return TRUE;
74 }
75
76 static void
77 164 fp_cmd_ssm_done_data_free (CommandData *data)
78 {
79 164 g_free (data);
80 164 }
81
82 /* data callbacks */
83
84 static void
85 51 fp_task_ssm_generic_cb (FpiDeviceRealtek *self,
86 uint8_t *buffer_in,
87 GError *error)
88 {
89
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 51 times.
51 if (error)
90 {
91 fpi_ssm_mark_failed (self->task_ssm, error);
92 return;
93 }
94
95 51 fpi_ssm_next_state (self->task_ssm);
96 }
97
98 static void
99 3 fp_get_device_info_cb (FpiDeviceRealtek *self,
100 uint8_t *buffer_in,
101 GError *error)
102 {
103
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 3 times.
3 if (error)
104 {
105 fpi_ssm_mark_failed (self->task_ssm, error);
106 return;
107 }
108
109 3 self->template_len = TEMPLATE_LEN_COMMON;
110
111 3 fpi_ssm_next_state (self->task_ssm);
112 }
113
114 static void
115 2 fp_update_template_cb (FpiDeviceRealtek *self,
116 uint8_t *buffer_in,
117 GError *error)
118 {
119
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 2 times.
2 if (error)
120 {
121 fpi_ssm_mark_failed (self->task_ssm, error);
122 return;
123 }
124
125 2 fpi_ssm_jump_to_state (self->task_ssm, FP_RTK_VERIFY_NUM_STATES);
126 }
127
128 static void
129 3 fp_enroll_commit_cb (FpiDeviceRealtek *self,
130 uint8_t *buffer_in,
131 GError *error)
132 {
133
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 3 times.
3 if (error)
134 {
135 fpi_ssm_mark_failed (self->task_ssm, error);
136 return;
137 }
138
139 3 fpi_ssm_jump_to_state (self->task_ssm, FP_RTK_ENROLL_NUM_STATES);
140 }
141
142 static void
143 40 fp_finish_capture_cb (FpiDeviceRealtek *self,
144 uint8_t *buffer_in,
145 GError *error)
146 {
147
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 40 times.
40 if (error)
148 {
149 fpi_ssm_mark_failed (self->task_ssm, error);
150 return;
151 }
152
153 /* We hope this polling CMD can be completed before the action is cancelled */
154 40 GCancellable *cancellable = fpi_device_get_cancellable (FP_DEVICE (self));
155
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 11 taken 40 times.
40 if (g_cancellable_is_cancelled (cancellable))
156 {
157 fpi_ssm_mark_failed (self->task_ssm,
158 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
159 "Action is cancelled!"));
160 return;
161 }
162
163 40 gint capture_status = buffer_in[0];
164
1/2
✓ Branch 11 → 12 taken 40 times.
✗ Branch 11 → 14 not taken.
40 if (capture_status == 0)
165 {
166 40 fpi_device_report_finger_status_changes (FP_DEVICE (self),
167 FP_FINGER_STATUS_PRESENT,
168 FP_FINGER_STATUS_NEEDED);
169 40 fpi_ssm_next_state (self->task_ssm);
170 }
171 else
172 {
173 fpi_ssm_jump_to_state (self->task_ssm,
174 fpi_ssm_get_cur_state (self->task_ssm));
175 }
176 }
177
178 static void
179 40 fp_accept_sample_cb (FpiDeviceRealtek *self,
180 uint8_t *buffer_in,
181 GError *error)
182 {
183 40 fpi_device_report_finger_status_changes (FP_DEVICE (self),
184 FP_FINGER_STATUS_NONE,
185 FP_FINGER_STATUS_PRESENT);
186
187
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 40 times.
40 if (error)
188 {
189 fpi_ssm_mark_failed (self->task_ssm, error);
190 return;
191 }
192
193 40 gint in_status = buffer_in[0];
194
195
2/2
✓ Branch 6 → 7 taken 4 times.
✓ Branch 6 → 9 taken 36 times.
40 if (self->fp_purpose != FP_RTK_PURPOSE_ENROLL)
196 {
197 /* verify or identify purpose process */
198 4 fpi_ssm_next_state (self->task_ssm);
199 4 return;
200 }
201 else
202 {
203 /* enroll purpose process */
204
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 13 taken 36 times.
36 if (in_status == FP_RTK_CMD_ERR)
205 {
206 fpi_ssm_mark_failed (self->task_ssm,
207 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
208 "Command error!"));
209 return;
210 }
211
212
2/2
✓ Branch 13 → 14 taken 32 times.
✓ Branch 13 → 23 taken 4 times.
36 if (self->enroll_stage < self->max_enroll_stage)
213 {
214
1/2
✓ Branch 14 → 15 taken 32 times.
✗ Branch 14 → 17 not taken.
32 if (in_status == FP_RTK_SUCCESS)
215 {
216 32 self->enroll_stage++;
217 32 fpi_device_enroll_progress (FP_DEVICE (self), self->enroll_stage, NULL, NULL);
218 32 fpi_ssm_jump_to_state (self->task_ssm, FP_RTK_ENROLL_CAPTURE);
219 }
220 else if (in_status == FP_RTK_MATCH_FAIL)
221 {
222 fpi_ssm_mark_failed (self->task_ssm,
223 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
224 "InStatus invalid!"));
225 }
226 else
227 {
228 fpi_device_enroll_progress (FP_DEVICE (self),
229 self->enroll_stage,
230 NULL,
231 fpi_device_retry_new (FP_DEVICE_RETRY_GENERAL));
232
233 fpi_ssm_jump_to_state (self->task_ssm, FP_RTK_ENROLL_CAPTURE);
234 }
235 return;
236 }
237
238
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 27 taken 4 times.
4 if (in_status != FP_RTK_SUCCESS)
239 {
240 fpi_ssm_mark_failed (self->task_ssm,
241 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
242 "Enrollment failed (status 0x%02x)",
243 in_status));
244 return;
245 }
246
247 4 fpi_ssm_next_state (self->task_ssm);
248 }
249 }
250
251 static FpPrint *
252 6 fp_print_from_data (FpiDeviceRealtek *self, uint8_t *buffer)
253 {
254 6 FpPrint *print;
255 6 GVariant *data;
256 6 GVariant *uid;
257 6 guint finger;
258 6 gsize userid_len;
259 12 g_autofree gchar *userid = NULL;
260
261 6 userid = g_strndup ((gchar *) buffer + 1, DEFAULT_UID_LEN);
262 6 finger = *(buffer);
263
264 6 print = fp_print_new (FP_DEVICE (self));
265 6 userid_len = MIN (DEFAULT_UID_LEN, strlen (userid));
266
267 6 uid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
268 userid,
269 userid_len,
270 1);
271
272 6 data = g_variant_new ("(y@ay)",
273 finger,
274 uid);
275
276 6 fpi_print_set_type (print, FPI_PRINT_RAW);
277 6 fpi_print_set_device_stored (print, TRUE);
278 6 g_object_set (print, "fpi-data", data, NULL);
279 6 g_object_set (print, "description", userid, NULL);
280 6 fpi_print_fill_from_user_id (print, userid);
281
282 6 return print;
283 }
284
285 static void
286 4 fp_identify_feature_cb (FpiDeviceRealtek *self,
287 uint8_t *buffer_in,
288 GError *error)
289 {
290 4 FpDevice *device = FP_DEVICE (self);
291 4 FpPrint *match = NULL;
292 4 FpPrint *print = NULL;
293 4 FpiDeviceAction current_action;
294
295 4 g_autoptr(GPtrArray) templates = NULL;
296 4 gboolean found = FALSE;
297
298 4 current_action = fpi_device_get_current_action (device);
299
300
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 4 times.
4 if (error)
301 {
302 fpi_ssm_mark_failed (self->task_ssm, error);
303 return;
304 }
305
306 4 gint in_status = buffer_in[0];
307
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 4 times.
4 if (in_status == FP_RTK_CMD_ERR)
308 {
309 fpi_ssm_mark_failed (self->task_ssm,
310 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
311 "Command error!"));
312 return;
313 }
314
315
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 13 taken 4 times.
4 if (in_status >= FP_RTK_TOO_HIGH && in_status <= FP_RTK_MERGE_FAILURE)
316 {
317 fpi_ssm_mark_failed (self->task_ssm,
318 fpi_device_retry_new (FP_DEVICE_RETRY_GENERAL));
319 return;
320 }
321
322
1/2
✓ Branch 13 → 14 taken 4 times.
✗ Branch 13 → 32 not taken.
4 if (in_status == FP_RTK_SUCCESS)
323 {
324 4 match = fp_print_from_data (self, buffer_in + 1);
325
326
2/2
✓ Branch 15 → 16 taken 2 times.
✓ Branch 15 → 19 taken 2 times.
4 if (current_action == FPI_DEVICE_ACTION_VERIFY)
327 {
328 2 templates = g_ptr_array_sized_new (1);
329 2 fpi_device_get_verify_data (device, &print);
330 2 g_ptr_array_add (templates, print);
331 }
332 else
333 {
334 2 fpi_device_get_identify_data (device, &templates);
335 2 g_ptr_array_ref (templates);
336 }
337
338
1/2
✓ Branch 25 → 22 taken 4 times.
✗ Branch 25 → 26 not taken.
4 for (gint cnt = 0; cnt < templates->len; cnt++)
339 {
340 4 print = g_ptr_array_index (templates, cnt);
341
342
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 4 times.
4 if (fp_print_equal (print, match))
343 {
344 found = TRUE;
345 break;
346 }
347 }
348
349
1/2
✓ Branch 26 → 27 taken 4 times.
✗ Branch 26 → 32 not taken.
4 if (found)
350 {
351
2/2
✓ Branch 27 → 28 taken 2 times.
✓ Branch 27 → 30 taken 2 times.
4 if (current_action == FPI_DEVICE_ACTION_VERIFY)
352 {
353 2 fpi_device_verify_report (device, FPI_MATCH_SUCCESS, match, error);
354 2 fpi_ssm_next_state (self->task_ssm);
355 }
356 else
357 {
358 2 fpi_device_identify_report (device, print, match, error);
359 2 fpi_ssm_jump_to_state (self->task_ssm, FP_RTK_VERIFY_NUM_STATES);
360 }
361 return;
362 }
363 }
364
365 if (!found)
366 {
367 if (current_action == FPI_DEVICE_ACTION_VERIFY)
368 fpi_device_verify_report (device, FPI_MATCH_FAIL, NULL, error);
369 else
370 fpi_device_identify_report (device, NULL, NULL, error);
371
372 fpi_ssm_jump_to_state (self->task_ssm, FP_RTK_VERIFY_NUM_STATES);
373 }
374 }
375
376 static void
377 4 fp_get_delete_pos_cb (FpiDeviceRealtek *self,
378 uint8_t *buffer_in,
379 GError *error)
380 {
381 4 FpPrint *print = NULL;
382
383 4 g_autoptr(GVariant) data = NULL;
384 4 gsize user_id_len = 0;
385 4 const guint8 *user_id;
386 4 guint8 finger;
387 4 gboolean found = FALSE;
388 4 gchar temp_userid[DEFAULT_UID_LEN + 1] = {0};
389
390
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 4 times.
4 if (error)
391 {
392 fpi_ssm_mark_failed (self->task_ssm, error);
393 return;
394 }
395
396 4 fpi_device_get_delete_data (FP_DEVICE (self), &print);
397 4 g_object_get (print, "fpi-data", &data, NULL);
398
399
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 18 taken 4 times.
4 if (!parse_print_data (data, &finger, &user_id, &user_id_len))
400 {
401 fpi_device_delete_complete (FP_DEVICE (self),
402 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
403 return;
404 }
405
406
2/2
✓ Branch 18 → 11 taken 13 times.
✓ Branch 18 → 19 taken 1 time.
14 for (gint i = 0; i < self->template_num; i++)
407 {
408
2/2
✓ Branch 11 → 12 taken 3 times.
✓ Branch 11 → 17 taken 10 times.
13 if (buffer_in[i * self->template_len] != 0)
409 {
410 3 memcpy (temp_userid, buffer_in + i * self->template_len + UID_OFFSET, DEFAULT_UID_LEN);
411
1/2
✓ Branch 14 → 15 taken 3 times.
✗ Branch 14 → 17 not taken.
3 if (g_strcmp0 (fp_print_get_description (print), (const char *) temp_userid) == 0)
412 {
413 3 self->pos_index = i;
414 3 found = TRUE;
415 3 break;
416 }
417 }
418 }
419
420 4 if (!found)
421 {
422 1 fpi_ssm_mark_failed (self->task_ssm,
423 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
424 "Get template position failed!"));
425 1 return;
426 }
427
428
1/2
✓ Branch 16 → 22 taken 3 times.
✗ Branch 16 → 23 not taken.
3 fpi_ssm_next_state (self->task_ssm);
429 }
430
431 static void
432 3 fp_get_enroll_num_cb (FpiDeviceRealtek *self,
433 uint8_t *buffer_in,
434 GError *error)
435 {
436
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 3 times.
3 if (error)
437 {
438 fpi_ssm_mark_failed (self->task_ssm, error);
439 return;
440 }
441
442 3 self->template_num = buffer_in[1];
443
444 3 fpi_ssm_next_state (self->task_ssm);
445 }
446
447 static void
448 4 fp_verify_get_template_cb (FpiDeviceRealtek *self,
449 uint8_t *buffer_in,
450 GError *error)
451 {
452
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 4 times.
4 if (error)
453 {
454 fpi_ssm_mark_failed (self->task_ssm, error);
455 return;
456 }
457
458 4 fpi_ssm_next_state (self->task_ssm);
459 }
460
461 static void
462 4 fp_enroll_get_template_cb (FpiDeviceRealtek *self,
463 uint8_t *buffer_in,
464 GError *error)
465 {
466 4 g_autofree guchar *seq_list = NULL;
467 4 gboolean found = FALSE;
468
469
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 9 taken 4 times.
4 if (error)
470 {
471 fpi_ssm_mark_failed (self->task_ssm, error);
472 return;
473 }
474
475
1/2
✓ Branch 9 → 5 taken 5 times.
✗ Branch 9 → 10 not taken.
5 for (gint i = 0; i < self->template_num; i++)
476 {
477
2/2
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 8 taken 1 time.
5 if (buffer_in[i * self->template_len] == 0)
478 {
479 4 self->pos_index = i;
480 4 found = TRUE;
481 4 break;
482 }
483 }
484
485 4 if (!found)
486 {
487 fpi_ssm_mark_failed (self->task_ssm,
488 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
489 "No free template was found!"));
490 return;
491 }
492
493 4 fpi_ssm_next_state (self->task_ssm);
494 }
495
496 static void
497 4 fp_check_duplicate_cb (FpiDeviceRealtek *self,
498 uint8_t *buffer_in,
499 GError *error)
500 {
501
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 4 times.
4 if (error)
502 {
503 fpi_ssm_mark_failed (self->task_ssm, error);
504 return;
505 }
506
507 4 gint in_status = buffer_in[0];
508
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 4 times.
4 if (in_status == FP_RTK_CMD_ERR)
509 {
510 fpi_ssm_mark_failed (self->task_ssm,
511 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
512 "Command error!"));
513 return;
514 }
515
516
2/2
✓ Branch 9 → 10 taken 1 time.
✓ Branch 9 → 12 taken 3 times.
4 if (in_status == FP_RTK_SUCCESS)
517 {
518 1 fpi_ssm_mark_failed (self->task_ssm,
519 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_DUPLICATE,
520 "Current fingerprint is duplicate!"));
521 }
522
1/2
✓ Branch 12 → 13 taken 3 times.
✗ Branch 12 → 14 not taken.
3 else if (in_status == FP_RTK_MATCH_FAIL)
523 {
524 3 fpi_ssm_next_state (self->task_ssm);
525 }
526 else
527 {
528 fpi_ssm_mark_failed (self->task_ssm,
529 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
530 "InStatus invalid!"));
531 }
532 }
533
534 static void
535 2 fp_list_cb (FpiDeviceRealtek *self,
536 uint8_t *buffer_in,
537 GError *error)
538 {
539 2 gboolean found = FALSE;
540
541 2 g_autoptr(GPtrArray) list_result = NULL;
542
543
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 2 times.
2 if (error)
544 {
545 fpi_device_list_complete (FP_DEVICE (self), NULL, error);
546 return;
547 }
548
549 2 list_result = g_ptr_array_new_with_free_func (g_object_unref);
550
551
2/2
✓ Branch 12 → 7 taken 10 times.
✓ Branch 12 → 13 taken 2 times.
14 for (gint i = 0; i < self->template_num; i++)
552 {
553
2/2
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 11 taken 8 times.
10 if (buffer_in[i * self->template_len] != 0)
554 {
555 2 FpPrint *print = NULL;
556 2 print = fp_print_from_data (self, buffer_in + i * self->template_len + SUBFACTOR_OFFSET);
557 2 g_ptr_array_add (list_result, g_object_ref_sink (print));
558 2 found = TRUE;
559 }
560 }
561
562
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 17 taken 2 times.
2 if (!found)
563 {
564 fpi_device_list_complete (FP_DEVICE (self),
565 g_steal_pointer (&list_result),
566 fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_FULL,
567 "Database is empty"));
568 return;
569 }
570
571 2 fp_info ("Query templates complete!");
572 2 fpi_device_list_complete (FP_DEVICE (self),
573 2 g_steal_pointer (&list_result),
574 NULL);
575 }
576
577 static void
578 3 fp_clear_storage_cb (FpiDeviceRealtek *self,
579 uint8_t *buffer_in,
580 GError *error)
581 {
582 3 FpDevice *device = FP_DEVICE (self);
583
584
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 3 times.
3 if (error)
585 {
586 fpi_device_clear_storage_complete (device, error);
587 return;
588 }
589
590 3 fp_info ("Successfully cleared storage");
591 3 fpi_device_clear_storage_complete (device, NULL);
592 }
593
594
595 static gint
596 164 parse_status (guint8 *buffer, gint status_type)
597 {
598 164 switch (status_type)
599 {
600 case FP_RTK_MSG_NO_STATUS:
601 return 0;
602 116 break;
603
604 116 case FP_RTK_MSG_DEFAULT:
605 116 return buffer[0];
606 break;
607
608 default:
609 return 1;
610 116 break;
611 }
612 }
613
614 static void
615 269 fp_cmd_receive_cb (FpiUsbTransfer *transfer,
616 FpDevice *device,
617 gpointer user_data,
618 GError *error)
619 {
620 269 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
621 269 CommandData *data = user_data;
622 269 gint ssm_state = 0;
623 269 gint status_flag = 1;
624
625
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 269 times.
269 if (error)
626 {
627 fpi_ssm_mark_failed (transfer->ssm, error);
628 return;
629 }
630
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 269 times.
269 if (data == NULL)
631 {
632 fpi_ssm_mark_failed (transfer->ssm,
633 fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
634 return;
635 }
636
637 269 ssm_state = fpi_ssm_get_cur_state (transfer->ssm);
638
639 /* skip zero length package */
640
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 269 times.
269 if (transfer->actual_length == 0)
641 {
642 fpi_ssm_jump_to_state (transfer->ssm, ssm_state);
643 return;
644 }
645
646 /* get data */
647
2/2
✓ Branch 13 → 14 taken 105 times.
✓ Branch 13 → 22 taken 164 times.
269 if (ssm_state == FP_RTK_CMD_TRANS_DATA)
648 {
649 105 g_autofree guchar *read_buf = NULL;
650
651
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 18 taken 105 times.
105 if ((gsize) transfer->actual_length < self->trans_data_len)
652 {
653 fpi_ssm_mark_failed (transfer->ssm,
654 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
655 "Truncated data received"));
656 return;
657 }
658
659 105 read_buf = g_malloc0 (sizeof (guchar) * (self->trans_data_len));
660 105 memcpy (read_buf, transfer->buffer, self->trans_data_len);
661 105 self->read_data = g_steal_pointer (&read_buf);
662
663 105 fpi_ssm_next_state (transfer->ssm);
664 105 return;
665 }
666
667 /* get status */
668
2/3
✓ Branch 22 → 23 taken 116 times.
✗ Branch 22 → 24 not taken.
✓ Branch 22 → 27 taken 48 times.
164 status_flag = parse_status (transfer->buffer, self->message_type);
669
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 27 taken 116 times.
116 if (status_flag != 0)
670 {
671 fpi_ssm_mark_failed (transfer->ssm,
672 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
673 "Status check failed"));
674 return;
675 }
676
677
1/2
✓ Branch 27 → 28 taken 164 times.
✗ Branch 27 → 29 not taken.
164 if (data->callback)
678 164 data->callback (self, self->read_data, NULL);
679
680
2/2
✓ Branch 29 → 30 taken 105 times.
✓ Branch 29 → 31 taken 59 times.
164 if (self->read_data)
681 105 g_clear_pointer (&self->read_data, g_free);
682
683 164 fpi_ssm_mark_completed (transfer->ssm);
684 }
685
686 static void
687 492 fp_cmd_run_state (FpiSsm *ssm, FpDevice *dev)
688 {
689 492 FpiUsbTransfer *transfer = NULL;
690 492 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (dev);
691
692
3/4
✓ Branch 3 → 4 taken 164 times.
✓ Branch 3 → 7 taken 164 times.
✓ Branch 3 → 22 taken 164 times.
✗ Branch 3 → 27 not taken.
492 switch (fpi_ssm_get_cur_state (ssm))
693 {
694 164 case FP_RTK_CMD_SEND:
695
1/2
✓ Branch 4 → 5 taken 164 times.
✗ Branch 4 → 6 not taken.
164 if (self->cmd_transfer)
696 {
697 164 self->cmd_transfer->ssm = ssm;
698 164 fpi_usb_transfer_submit (g_steal_pointer (&self->cmd_transfer),
699 CMD_TIMEOUT,
700 NULL,
701 fpi_ssm_usb_transfer_cb,
702 NULL);
703 }
704 else
705 {
706 fpi_ssm_next_state (ssm);
707 }
708 break;
709
710 164 case FP_RTK_CMD_TRANS_DATA:
711
2/2
✓ Branch 7 → 8 taken 56 times.
✓ Branch 7 → 10 taken 108 times.
164 if (self->cmd_type == FP_RTK_CMD_BULK_ONLY)
712 {
713 56 fpi_ssm_jump_to_state (ssm, FP_RTK_CMD_GET_STATUS);
714 56 break;
715 }
716
717
2/2
✓ Branch 10 → 11 taken 3 times.
✓ Branch 10 → 14 taken 105 times.
108 if (self->cmd_type == FP_RTK_CMD_BULK_WRITE)
718 {
719
1/2
✓ Branch 11 → 12 taken 3 times.
✗ Branch 11 → 13 not taken.
3 if (self->data_transfer)
720 {
721 3 self->data_transfer->ssm = ssm;
722 3 fpi_usb_transfer_submit (g_steal_pointer (&self->data_transfer),
723 DATA_TIMEOUT,
724 NULL,
725 fpi_ssm_usb_transfer_cb,
726 NULL);
727 }
728 else
729 {
730 fpi_ssm_next_state (ssm);
731 }
732 }
733 else /* CMD_READ */
734 {
735 105 transfer = fpi_usb_transfer_new (dev);
736 105 transfer->ssm = ssm;
737 105 fpi_usb_transfer_fill_bulk (transfer, EP_IN, EP_IN_MAX_BUF_SIZE);
738
739 210 fpi_usb_transfer_submit (transfer,
740
2/2
✓ Branch 19 → 20 taken 103 times.
✓ Branch 19 → 21 taken 2 times.
105 self->cmd_cancellable ? 0 : DATA_TIMEOUT,
741
2/2
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 19 taken 103 times.
105 self->cmd_cancellable ? fpi_device_get_cancellable (dev) : NULL,
742 fp_cmd_receive_cb,
743 fpi_ssm_get_data (ssm));
744 }
745 break;
746
747 164 case FP_RTK_CMD_GET_STATUS:
748 164 transfer = fpi_usb_transfer_new (dev);
749 164 transfer->ssm = ssm;
750 164 fpi_usb_transfer_fill_bulk (transfer, EP_IN, EP_IN_MAX_BUF_SIZE);
751 164 fpi_usb_transfer_submit (transfer,
752 STATUS_TIMEOUT,
753 NULL,
754 fp_cmd_receive_cb,
755 fpi_ssm_get_data (ssm));
756 164 break;
757 }
758 492 }
759
760 static void
761 164 fp_cmd_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
762 {
763 164 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (dev);
764 164 CommandData *data = fpi_ssm_get_data (ssm);
765
766 164 self->cmd_ssm = NULL;
767
768
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 164 times.
164 if (error)
769 {
770 if (data->callback)
771 data->callback (self, NULL, error);
772 else
773 g_error_free (error);
774 }
775 164 }
776
777 static FpiUsbTransfer *
778 167 prepare_bulk_transfer (FpDevice *dev,
779 guint8 *data,
780 gsize data_len,
781 GDestroyNotify free_func)
782 {
783 334 g_autoptr(FpiUsbTransfer) transfer = NULL;
784
785
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 167 times.
167 g_return_val_if_fail (data || data_len == 0, NULL);
786
787 167 transfer = fpi_usb_transfer_new (dev);
788
789 167 fpi_usb_transfer_fill_bulk_full (transfer,
790 EP_OUT,
791 data,
792 data_len,
793 free_func);
794
795 167 return g_steal_pointer (&transfer);
796 }
797
798
799 static void
800 3 fp_ctrl_cmd_cb (FpiUsbTransfer *transfer,
801 FpDevice *device,
802 gpointer user_data,
803 GError *error)
804 {
805 3 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
806
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 3 times.
6 g_autofree CommandData *data = g_steal_pointer (&user_data);
807
808
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 3 times.
3 g_return_if_fail (data != NULL);
809
810
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 3 times.
3 if (error)
811 {
812 fpi_ssm_mark_failed (transfer->ssm, error);
813 return;
814 }
815
816
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 9 taken 3 times.
3 if (transfer->direction == G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE)
817 {
818 if (data->callback)
819 data->callback (self, NULL, NULL);
820 }
821 else
822 {
823
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 14 taken 3 times.
3 if (transfer->actual_length == 0)
824 {
825 fp_info ("Control transfer receive data failed!");
826 fpi_ssm_mark_failed (transfer->ssm,
827 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
828 return;
829 }
830
831
1/2
✓ Branch 14 → 15 taken 3 times.
✗ Branch 14 → 16 not taken.
3 if (data->callback)
832 3 data->callback (self, transfer->buffer, NULL);
833 }
834 }
835
836 static void
837 3 rtk_send_ctrl_cmd (FpiDeviceRealtek *self,
838 struct rtk_cmd_ctrl *ctrl_cmd,
839 guint8 *cmd_data,
840 SynCmdMsgCallback callback)
841 {
842 3 FpiUsbTransfer *transfer = NULL;
843 3 g_autofree CommandData *data = g_new0 (CommandData, 1);
844
845 3 data->callback = callback;
846
847 3 transfer = fpi_usb_transfer_new (FP_DEVICE (self));
848 3 fpi_usb_transfer_fill_control (transfer,
849 3 ctrl_cmd->direction,
850 G_USB_DEVICE_REQUEST_TYPE_VENDOR,
851 G_USB_DEVICE_RECIPIENT_DEVICE,
852 3 ctrl_cmd->request,
853 3 ctrl_cmd->value,
854 3 ctrl_cmd->index,
855 3 ctrl_cmd->len);
856
857 3 transfer->ssm = self->task_ssm;
858
2/4
✓ Branch 5 → 6 taken 3 times.
✗ Branch 5 → 9 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 9 taken 3 times.
3 if (ctrl_cmd->direction == G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST &&
859 cmd_data != NULL && ctrl_cmd->len != 0)
860 memcpy (transfer->buffer, cmd_data, ctrl_cmd->len);
861
862 3 fpi_usb_transfer_submit (transfer,
863 CMD_TIMEOUT,
864 NULL,
865 fp_ctrl_cmd_cb,
866 g_steal_pointer (&data));
867 3 }
868
869 static void
870 164 rtk_sensor_bulk_cmd (FpiDeviceRealtek *self,
871 guint8 *cmd,
872 guint8 *trans_data,
873 FpRtkMsgType message_type,
874 gboolean bwait_data_delay,
875 SynCmdMsgCallback callback)
876 {
877 328 g_autoptr(FpiUsbTransfer) cmd_transfer = NULL;
878 328 g_autoptr(FpiUsbTransfer) data_transfer = NULL;
879 164 CommandData *data = g_new0 (CommandData, 1);
880
881 164 self->cmd_type = GET_BULK_CMD_TYPE (cmd[0]);
882 164 self->message_type = message_type;
883 164 self->trans_data_len = GET_TRANS_DATA_LEN (cmd[11], cmd[10]);
884 164 self->cmd_cancellable = bwait_data_delay;
885
886 164 cmd_transfer = prepare_bulk_transfer (FP_DEVICE (self), cmd, FP_RTK_CMD_BULK_TOTAL_LEN, NULL);
887
2/2
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 8 taken 161 times.
164 self->cmd_transfer = g_steal_pointer (&cmd_transfer);
888
889
3/4
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 8 taken 161 times.
✓ Branch 5 → 6 taken 3 times.
✗ Branch 5 → 8 not taken.
164 if ((self->cmd_type == FP_RTK_CMD_BULK_WRITE) && trans_data)
890 {
891 3 data_transfer = prepare_bulk_transfer (FP_DEVICE (self), trans_data, self->trans_data_len, g_free);
892 3 self->data_transfer = g_steal_pointer (&data_transfer);
893 }
894
895 164 self->cmd_ssm = fpi_ssm_new (FP_DEVICE (self),
896 fp_cmd_run_state,
897 FP_RTK_CMD_NUM_STATES);
898
899 164 data->callback = callback;
900 164 fpi_ssm_set_data (self->cmd_ssm, data, (GDestroyNotify) fp_cmd_ssm_done_data_free);
901
902 164 fpi_ssm_start (self->cmd_ssm, fp_cmd_ssm_done);
903 164 }
904
905 static void
906 4 fp_verify_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
907 {
908 4 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (dev);
909
910 4 fp_info ("Verify complete!");
911
912
1/4
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 10 taken 4 times.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 10 not taken.
4 if (error && error->domain == FP_DEVICE_RETRY)
913 {
914 if (fpi_device_get_current_action (dev) == FPI_DEVICE_ACTION_VERIFY)
915 fpi_device_verify_report (dev, FPI_MATCH_ERROR, NULL, g_steal_pointer (&error));
916 else
917 fpi_device_identify_report (dev, NULL, NULL, g_steal_pointer (&error));
918 }
919
920
2/2
✓ Branch 11 → 12 taken 2 times.
✓ Branch 11 → 13 taken 2 times.
4 if (fpi_device_get_current_action (dev) == FPI_DEVICE_ACTION_VERIFY)
921 2 fpi_device_verify_complete (dev, error);
922 else
923 2 fpi_device_identify_complete (dev, error);
924
925 4 self->task_ssm = NULL;
926 4 }
927
928 static void
929 4 fp_enroll_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
930 {
931 4 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (dev);
932 4 FpPrint *print = NULL;
933
934 4 fp_info ("Enrollment complete!");
935
936
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 3 times.
4 if (error)
937 {
938 1 fpi_device_enroll_complete (dev, NULL, error);
939 1 self->task_ssm = NULL;
940 1 return;
941 }
942
943 3 fpi_device_get_enroll_data (FP_DEVICE (self), &print);
944 3 fpi_device_enroll_complete (FP_DEVICE (self), g_object_ref (print), NULL);
945 3 self->task_ssm = NULL;
946 }
947
948 static void
949 3 fp_init_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
950 {
951 3 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (dev);
952
953 3 fp_info ("Init complete!");
954
955 3 fpi_device_open_complete (dev, error);
956 3 self->task_ssm = NULL;
957 3 }
958
959 static void
960 4 fp_delete_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
961 {
962 4 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (dev);
963
964 4 fp_info ("Delete print complete!");
965
966 4 fpi_device_delete_complete (dev, error);
967 4 self->task_ssm = NULL;
968 4 }
969
970 static void
971 22 fp_verify_sm_run_state (FpiSsm *ssm, FpDevice *device)
972 {
973 22 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
974 22 guint8 *cmd_buf = NULL;
975
976
6/8
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 10 taken 4 times.
✓ Branch 3 → 13 taken 4 times.
✓ Branch 3 → 15 taken 4 times.
✓ Branch 3 → 17 taken 4 times.
✓ Branch 3 → 19 taken 2 times.
✗ Branch 3 → 21 not taken.
✗ Branch 3 → 23 not taken.
22 switch (fpi_ssm_get_cur_state (ssm))
977 {
978 4 case FP_RTK_VERIFY_GET_TEMPLATE:
979
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 4 times.
4 if (self->template_num <= 0)
980 {
981 fpi_ssm_mark_failed (ssm,
982 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
983 "No templates enrolled"));
984 break;
985 }
986
987 4 co_get_template.data_len[0] = GET_LEN_L (self->template_len * self->template_num);
988 4 co_get_template.data_len[1] = GET_LEN_H (self->template_len * self->template_num);
989 4 cmd_buf = (guint8 *) &co_get_template;
990 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_verify_get_template_cb);
991 4 break;
992
993 4 case FP_RTK_VERIFY_CAPTURE:
994 4 fpi_device_report_finger_status_changes (device,
995 FP_FINGER_STATUS_NEEDED,
996 FP_FINGER_STATUS_NONE);
997
998 4 cmd_buf = (guint8 *) &co_start_capture;
999 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_task_ssm_generic_cb);
1000 4 break;
1001
1002 4 case FP_RTK_VERIFY_FINISH_CAPTURE:
1003 4 cmd_buf = (guint8 *) &co_finish_capture;
1004 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_finish_capture_cb);
1005 4 break;
1006
1007 4 case FP_RTK_VERIFY_ACCEPT_SAMPLE:
1008 4 co_accept_sample.param[0] = self->fp_purpose;
1009 4 cmd_buf = (guint8 *) &co_accept_sample;
1010 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_NO_STATUS, 0, fp_accept_sample_cb);
1011 4 break;
1012
1013 4 case FP_RTK_VERIFY_INDENTIFY_FEATURE:
1014 4 cmd_buf = (guint8 *) &nor_identify_feature;
1015 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_NO_STATUS, 0, fp_identify_feature_cb);
1016 4 break;
1017
1018 2 case FP_RTK_VERIFY_UPDATE_TEMPLATE:
1019 2 cmd_buf = (guint8 *) &co_update_template;
1020 2 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_update_template_cb);
1021 2 break;
1022
1023 case FP_RTK_VERIFY_CANCEL_CAPTURE:
1024 co_cancel_capture.param[0] = self->fp_purpose;
1025 cmd_buf = (guint8 *) &co_cancel_capture;
1026 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_task_ssm_generic_cb);
1027 break;
1028 }
1029 22 }
1030
1031 static void
1032 124 fp_enroll_sm_run_state (FpiSsm *ssm, FpDevice *device)
1033 {
1034 248 g_autofree gchar *user_id = NULL;
1035 124 g_autofree guint8 *payload = NULL;
1036 124 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1037 124 FpPrint *print = NULL;
1038 124 guint8 *cmd_buf = NULL;
1039 124 GVariant *uid = NULL;
1040 124 GVariant *data = NULL;
1041 124 gsize user_id_len;
1042 124 guint finger;
1043
1044
8/9
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 10 taken 4 times.
✓ Branch 3 → 12 taken 36 times.
✓ Branch 3 → 15 taken 36 times.
✓ Branch 3 → 17 taken 36 times.
✓ Branch 3 → 19 taken 4 times.
✓ Branch 3 → 21 taken 3 times.
✓ Branch 3 → 33 taken 1 time.
✗ Branch 3 → 34 not taken.
124 switch (fpi_ssm_get_cur_state (ssm))
1045 {
1046 4 case FP_RTK_ENROLL_GET_TEMPLATE:
1047
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 4 times.
4 if (self->template_num <= 0)
1048 {
1049 fpi_ssm_mark_failed (ssm,
1050 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
1051 "No templates enrolled"));
1052 break;
1053 }
1054
1055 4 co_get_template.data_len[0] = GET_LEN_L (self->template_len * self->template_num);
1056 4 co_get_template.data_len[1] = GET_LEN_H (self->template_len * self->template_num);
1057
1058 4 cmd_buf = (guint8 *) &co_get_template;
1059 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_enroll_get_template_cb);
1060 4 break;
1061
1062 4 case FP_RTK_ENROLL_BEGIN_POS:
1063 4 nor_enroll_begin.param[0] = self->pos_index;
1064 4 cmd_buf = (guint8 *) &nor_enroll_begin;
1065 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_task_ssm_generic_cb);
1066 4 break;
1067
1068 36 case FP_RTK_ENROLL_CAPTURE:
1069 36 fpi_device_report_finger_status_changes (device,
1070 FP_FINGER_STATUS_NEEDED,
1071 FP_FINGER_STATUS_NONE);
1072
1073 36 cmd_buf = (guint8 *) &co_start_capture;
1074 36 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_task_ssm_generic_cb);
1075 36 break;
1076
1077 36 case FP_RTK_ENROLL_FINISH_CAPTURE:
1078 36 cmd_buf = (guint8 *) &co_finish_capture;
1079 36 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_finish_capture_cb);
1080 36 break;
1081
1082 36 case FP_RTK_ENROLL_ACCEPT_SAMPLE:
1083 36 co_accept_sample.param[0] = self->fp_purpose;
1084 36 cmd_buf = (guint8 *) &co_accept_sample;
1085 36 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_NO_STATUS, 0, fp_accept_sample_cb);
1086 36 break;
1087
1088 4 case FP_RTK_ENROLL_CHECK_DUPLICATE:
1089 4 cmd_buf = (guint8 *) &co_check_duplicate;
1090 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_NO_STATUS, 0, fp_check_duplicate_cb);
1091 4 break;
1092
1093 3 case FP_RTK_ENROLL_COMMIT:
1094 3 gchar *valid_uid = NULL;
1095 3 gint payload_len;
1096
1097 3 payload_len = UID_PAYLOAD_LEN_DEFAULT;
1098
1099 3 fpi_device_get_enroll_data (device, &print);
1100 3 user_id = fpi_print_generate_user_id (print);
1101 3 user_id_len = MIN (DEFAULT_UID_LEN, strlen (user_id));
1102
1103 3 payload = g_malloc0 (payload_len);
1104 3 memcpy (payload, user_id, user_id_len);
1105 3 valid_uid = (gchar *) payload;
1106
1107 3 finger = SUB_FINGER_01;
1108 3 uid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
1109 valid_uid,
1110 user_id_len,
1111 1);
1112 3 data = g_variant_new ("(y@ay)",
1113 finger,
1114 uid);
1115
1116 3 fpi_print_set_type (print, FPI_PRINT_RAW);
1117 3 fpi_print_set_device_stored (print, TRUE);
1118 3 g_object_set (print, "fpi-data", data, NULL);
1119 3 g_object_set (print, "description", valid_uid, NULL);
1120
1121 3 g_debug ("user_id: %s, finger: 0x%x", user_id, finger);
1122
1123 3 nor_enroll_commit.param[0] = SUB_FINGER_01;
1124 3 nor_enroll_commit.data_len[0] = GET_LEN_L (payload_len);
1125 3 nor_enroll_commit.data_len[1] = GET_LEN_H (payload_len);
1126
1127 3 cmd_buf = (guint8 *) &nor_enroll_commit;
1128 3 rtk_sensor_bulk_cmd (self, cmd_buf, g_steal_pointer (&payload),
1129 FP_RTK_MSG_DEFAULT, 1, fp_enroll_commit_cb);
1130 3 break;
1131
1132 1 case FP_RTK_ENROLL_CANCEL_CAPTURE:
1133 1 co_cancel_capture.param[0] = self->fp_purpose;
1134 1 cmd_buf = (guint8 *) &co_cancel_capture;
1135 1 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_task_ssm_generic_cb);
1136 }
1137 124 }
1138
1139 static void
1140 9 fp_init_sm_run_state (FpiSsm *ssm, FpDevice *device)
1141 {
1142 9 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1143 9 guint8 *cmd_buf = NULL;
1144
1145
3/4
✓ Branch 3 → 4 taken 3 times.
✓ Branch 3 → 6 taken 3 times.
✓ Branch 3 → 8 taken 3 times.
✗ Branch 3 → 10 not taken.
9 switch (fpi_ssm_get_cur_state (ssm))
1146 {
1147 3 case FP_RTK_INIT_GET_DEVICE_INFO:
1148 3 rtk_send_ctrl_cmd (self, &get_device_info, NULL, fp_get_device_info_cb);
1149 3 break;
1150
1151 3 case FP_RTK_INIT_SELECT_OS:
1152 3 co_select_system.param[0] = 0x01;
1153 3 cmd_buf = (guint8 *) &co_select_system;
1154 3 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_task_ssm_generic_cb);
1155 3 break;
1156
1157 3 case FP_RTK_INIT_GET_ENROLL_NUM:
1158 3 cmd_buf = (guint8 *) &co_get_enroll_num;
1159 3 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_get_enroll_num_cb);
1160 3 break;
1161 }
1162 9 }
1163
1164 static void
1165 7 fp_delete_sm_run_state (FpiSsm *ssm, FpDevice *device)
1166 {
1167 7 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1168 7 guint8 *cmd_buf = NULL;
1169
1170
2/3
✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 10 taken 3 times.
✗ Branch 3 → 12 not taken.
7 switch (fpi_ssm_get_cur_state (ssm))
1171 {
1172 4 case FP_RTK_DELETE_GET_POS:
1173
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 4 times.
4 if (self->template_num <= 0)
1174 {
1175 fpi_ssm_mark_failed (ssm,
1176 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
1177 "No templates enrolled"));
1178 break;
1179 }
1180
1181 4 co_get_template.data_len[0] = GET_LEN_L (self->template_len * self->template_num);
1182 4 co_get_template.data_len[1] = GET_LEN_H (self->template_len * self->template_num);
1183
1184 4 cmd_buf = (guint8 *) &co_get_template;
1185 4 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_get_delete_pos_cb);
1186 4 break;
1187
1188 3 case FP_RTK_DELETE_PRINT:
1189 3 co_delete_record.param[0] = self->pos_index;
1190 3 cmd_buf = (guint8 *) &co_delete_record;
1191 3 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_task_ssm_generic_cb);
1192 3 break;
1193 }
1194 7 }
1195
1196
1197 static void
1198 4 identify_verify (FpDevice *device)
1199 {
1200 4 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1201 4 FpiDeviceAction current_action;
1202
1203 4 G_DEBUG_HERE ();
1204 4 current_action = fpi_device_get_current_action (device);
1205
1206
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 4 times.
4 g_assert (current_action == FPI_DEVICE_ACTION_VERIFY ||
1207 current_action == FPI_DEVICE_ACTION_IDENTIFY);
1208
1209 4 self->fp_purpose = FP_RTK_PURPOSE_IDENTIFY;
1210
1211
1/2
✓ Branch 7 → 8 taken 4 times.
✗ Branch 7 → 11 not taken.
4 g_assert (!self->task_ssm);
1212
1213 4 self->task_ssm = fpi_ssm_new_full (device,
1214 fp_verify_sm_run_state,
1215 FP_RTK_VERIFY_NUM_STATES,
1216 FP_RTK_VERIFY_CANCEL_CAPTURE,
1217 "Verify & Identify");
1218
1219 4 fpi_ssm_start (self->task_ssm, fp_verify_ssm_done);
1220 4 }
1221
1222 static void
1223 4 enroll (FpDevice *device)
1224 {
1225 4 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1226
1227 4 G_DEBUG_HERE ();
1228 4 self->enroll_stage = 0;
1229 4 self->fp_purpose = FP_RTK_PURPOSE_ENROLL;
1230
1231
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 4 times.
4 g_assert (!self->task_ssm);
1232
1233 4 self->task_ssm = fpi_ssm_new_full (device,
1234 fp_enroll_sm_run_state,
1235 FP_RTK_ENROLL_NUM_STATES,
1236 FP_RTK_ENROLL_CANCEL_CAPTURE,
1237 "Enroll");
1238
1239 4 fpi_ssm_start (self->task_ssm, fp_enroll_ssm_done);
1240 4 }
1241
1242 static void
1243 3 dev_probe (FpDevice *device)
1244 {
1245 3 GUsbDevice *usb_dev;
1246 3 GError *error = NULL;
1247 3 g_autofree gchar *product = NULL;
1248 3 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1249
1250 3 G_DEBUG_HERE ();
1251 /* Claim usb interface */
1252 3 usb_dev = fpi_device_get_usb_device (device);
1253
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3 times.
3 if (!g_usb_device_open (usb_dev, &error))
1254 {
1255 fpi_device_probe_complete (device, NULL, NULL, error);
1256 return;
1257 }
1258
1259
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 13 taken 3 times.
3 if (!g_usb_device_reset (usb_dev, &error))
1260 {
1261 g_usb_device_close (usb_dev, NULL);
1262 fpi_device_probe_complete (device, NULL, NULL, error);
1263 return;
1264 }
1265
1266
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 18 taken 3 times.
3 if (!g_usb_device_claim_interface (usb_dev, 0, 0, &error))
1267 {
1268 g_usb_device_close (usb_dev, NULL);
1269 fpi_device_probe_complete (device, NULL, NULL, error);
1270 return;
1271 }
1272
1273 3 product = g_usb_device_get_string_descriptor (usb_dev,
1274 g_usb_device_get_product_index (usb_dev),
1275 &error);
1276
1277
1/2
✓ Branch 20 → 21 taken 3 times.
✗ Branch 20 → 22 not taken.
3 if (product)
1278 3 fp_dbg ("Device name: %s", product);
1279
1280 3 self->max_enroll_stage = MAX_ENROLL_SAMPLES;
1281 3 fpi_device_set_nr_enroll_stages (device, self->max_enroll_stage);
1282
1283 3 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (device)), 0, 0, NULL);
1284 3 g_usb_device_close (usb_dev, NULL);
1285
1286 3 fpi_device_probe_complete (device, NULL, product, error);
1287 }
1288
1289 static void
1290 3 dev_init (FpDevice *device)
1291 {
1292 3 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1293 3 GError *error = NULL;
1294
1295 3 G_DEBUG_HERE ();
1296
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3 times.
3 if (!g_usb_device_reset (fpi_device_get_usb_device (device), &error))
1297 {
1298 fpi_device_open_complete (FP_DEVICE (self), error);
1299 return;
1300 }
1301
1302 /* Claim usb interface */
1303
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 3 times.
3 if (!g_usb_device_claim_interface (fpi_device_get_usb_device (device), 0, 0, &error))
1304 {
1305 fpi_device_open_complete (FP_DEVICE (self), error);
1306 return;
1307 }
1308
1309
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 3 times.
3 g_assert (!self->task_ssm);
1310
1311 3 self->task_ssm = fpi_ssm_new_full (device,
1312 fp_init_sm_run_state,
1313 FP_RTK_INIT_NUM_STATES,
1314 FP_RTK_INIT_NUM_STATES,
1315 "Init");
1316
1317 3 fpi_ssm_start (self->task_ssm, fp_init_ssm_done);
1318 }
1319
1320 static void
1321 3 dev_exit (FpDevice *device)
1322 {
1323 3 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1324
1325 6 g_autoptr(GError) release_error = NULL;
1326
1327 3 G_DEBUG_HERE ();
1328
1329 3 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (self)), 0, 0, &release_error);
1330
1331
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 3 times.
3 fpi_device_close_complete (device, release_error);
1332 3 }
1333
1334 static void
1335 4 delete_print (FpDevice *device)
1336 {
1337 4 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1338
1339 4 G_DEBUG_HERE ();
1340
1341
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 4 times.
4 g_assert (!self->task_ssm);
1342
1343 4 self->task_ssm = fpi_ssm_new_full (device,
1344 fp_delete_sm_run_state,
1345 FP_RTK_DELETE_NUM_STATES,
1346 FP_RTK_DELETE_NUM_STATES,
1347 "Delete print");
1348
1349 4 fpi_ssm_start (self->task_ssm, fp_delete_ssm_done);
1350 4 }
1351
1352 static void
1353 3 clear_storage (FpDevice *device)
1354 {
1355 3 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1356 3 guint8 *cmd_buf = NULL;
1357
1358 3 G_DEBUG_HERE ();
1359 3 co_delete_record.param[0] = 0xff;
1360 3 cmd_buf = (guint8 *) &co_delete_record;
1361 3 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 0, fp_clear_storage_cb);
1362 3 }
1363
1364 static void
1365 2 list_print (FpDevice *device)
1366 {
1367 2 FpiDeviceRealtek *self = FPI_DEVICE_REALTEK (device);
1368 2 guint8 *cmd_buf = NULL;
1369
1370 2 G_DEBUG_HERE ();
1371
1372
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 2 times.
2 if (self->template_num < 0)
1373 {
1374 fpi_device_list_complete (device, NULL,
1375 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
1376 "Get template number failed!"));
1377 return;
1378 }
1379
1380
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 2 times.
2 if (self->template_num == 0)
1381 {
1382 g_autoptr(GPtrArray) list_result = g_ptr_array_new_with_free_func (g_object_unref);
1383 fpi_device_list_complete (device, g_steal_pointer (&list_result), NULL);
1384 return;
1385 }
1386
1387 2 co_get_template.data_len[0] = GET_LEN_L (self->template_len * self->template_num);
1388 2 co_get_template.data_len[1] = GET_LEN_H (self->template_len * self->template_num);
1389
1390 2 cmd_buf = (guint8 *) &co_get_template;
1391 2 rtk_sensor_bulk_cmd (self, cmd_buf, NULL, FP_RTK_MSG_DEFAULT, 1, fp_list_cb);
1392 }
1393
1394 static void
1395 3 fpi_device_realtek_init (FpiDeviceRealtek *self)
1396 {
1397 3 }
1398
1399 static void
1400 128 fpi_device_realtek_class_init (FpiDeviceRealtekClass *klass)
1401 {
1402 128 FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
1403
1404 128 dev_class->id = FP_COMPONENT;
1405 128 dev_class->full_name = "Realtek MOC Fingerprint Sensor";
1406
1407 128 dev_class->type = FP_DEVICE_TYPE_USB;
1408 128 dev_class->scan_type = FP_SCAN_TYPE_PRESS;
1409 128 dev_class->id_table = id_table;
1410 128 dev_class->nr_enroll_stages = MAX_ENROLL_SAMPLES;
1411 128 dev_class->temp_hot_seconds = -1;
1412
1413 128 dev_class->open = dev_init;
1414 128 dev_class->close = dev_exit;
1415 128 dev_class->probe = dev_probe;
1416 128 dev_class->verify = identify_verify;
1417 128 dev_class->identify = identify_verify;
1418 128 dev_class->enroll = enroll;
1419 128 dev_class->delete = delete_print;
1420 128 dev_class->clear_storage = clear_storage;
1421 128 dev_class->list = list_print;
1422
1423 128 fpi_device_class_auto_initialize_features (dev_class);
1424 128 }
1425