GCC Code Coverage Report


Directory: ./
File: libfprint/drivers/elanmoc/elanmoc.c
Date: 2024-05-04 14:54:39
Exec Total Coverage
Lines: 443 557 79.5%
Functions: 41 41 100.0%
Branches: 102 197 51.8%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2021 Elan Microelectronics Inc
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 "elanmoc"
20
21 #include "drivers_api.h"
22 #include "fpi-byte-reader.h"
23 #include "elanmoc.h"
24
25
4/5
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 117 times.
✓ Branch 3 taken 117 times.
✗ Branch 4 not taken.
750 G_DEFINE_TYPE (FpiDeviceElanmoc, fpi_device_elanmoc, FP_TYPE_DEVICE)
26
27 static const FpIdEntry id_table[] = {
28 { .vid = 0x04f3, .pid = 0x0c7d, },
29 { .vid = 0x04f3, .pid = 0x0c7e, },
30 { .vid = 0x04f3, .pid = 0x0c82, },
31 { .vid = 0x04f3, .pid = 0x0c88, },
32 { .vid = 0x04f3, .pid = 0x0c8c, },
33 { .vid = 0x04f3, .pid = 0x0c8d, },
34 { .vid = 0x04f3, .pid = 0x0c99, },
35 { .vid = 0, .pid = 0, .driver_data = 0 }, /* terminating entry */
36 };
37
38 typedef void (*SynCmdMsgCallback) (FpiDeviceElanmoc *self,
39 uint8_t *buffer_in,
40 gsize length_in,
41 GError *error);
42
43 typedef struct
44 {
45 SynCmdMsgCallback callback;
46 } CommandData;
47
48 static uint8_t *
49 38 elanmoc_compose_cmd (
50 const struct elanmoc_cmd *cmd_info
51 )
52 {
53 76 g_autofree uint8_t *cmd_buf = NULL;
54
55 38 cmd_buf = g_new0 (uint8_t, cmd_info->cmd_len);
56
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 36 times.
38 if(cmd_info->cmd_len < ELAN_MAX_HDR_LEN)
57 2 memcpy (cmd_buf, &cmd_info->cmd_header, cmd_info->cmd_len);
58 else
59 36 memcpy (cmd_buf, &cmd_info->cmd_header, ELAN_MAX_HDR_LEN);
60
61 38 return g_steal_pointer (&cmd_buf);
62 }
63
64 static void
65 4 elanmoc_cmd_ack_cb (FpiDeviceElanmoc *self,
66 uint8_t *buffer_in,
67 gsize length_in,
68 GError *error)
69 {
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (error)
71 {
72 fpi_ssm_mark_failed (self->task_ssm, error);
73 return;
74 }
75
76
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (length_in == 0)
77 {
78 1 fpi_ssm_next_state (self->task_ssm);
79 1 return;
80 }
81
82
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if (buffer_in[0] != 0x40 && buffer_in[1] != 0x00 )
83 {
84 fpi_ssm_mark_failed (self->task_ssm,
85 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
86 "Can't get response!!"));
87 }
88 else
89 {
90 3 fpi_ssm_next_state (self->task_ssm);
91 }
92 }
93
94 static void
95 37 fp_cmd_receive_cb (FpiUsbTransfer *transfer,
96 FpDevice *device,
97 gpointer userdata,
98 GError *error)
99 {
100 37 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
101 37 CommandData *data = userdata;
102 37 int ssm_state = 0;
103
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (error)
105 {
106 fpi_ssm_mark_failed (transfer->ssm, error);
107 return;
108 }
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (data == NULL)
110 {
111 fpi_ssm_mark_failed (transfer->ssm,
112 fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
113 return;
114 }
115 37 ssm_state = fpi_ssm_get_cur_state (transfer->ssm);
116
117 /* skip zero length package */
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (transfer->actual_length == 0)
119 {
120 fpi_ssm_jump_to_state (transfer->ssm, ssm_state);
121 return;
122 }
123
124
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 if (data->callback)
125 37 data->callback (self, transfer->buffer, transfer->actual_length, NULL);
126
127 37 fpi_ssm_mark_completed (transfer->ssm);
128 }
129
130 typedef enum {
131 FP_CMD_SEND = 0,
132 FP_CMD_GET,
133 FP_CMD_NUM_STATES,
134 } FpCmdState;
135
136 static void
137 76 fp_cmd_run_state (FpiSsm *ssm,
138 FpDevice *dev)
139 {
140 76 FpiUsbTransfer *transfer;
141 76 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
142
143
2/3
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
76 switch (fpi_ssm_get_cur_state (ssm))
144 {
145 38 case FP_CMD_SEND:
146
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 if (self->cmd_transfer)
147 {
148 38 self->cmd_transfer->ssm = ssm;
149 38 fpi_usb_transfer_submit (g_steal_pointer (&self->cmd_transfer),
150 ELAN_MOC_CMD_TIMEOUT,
151 NULL,
152 fpi_ssm_usb_transfer_cb,
153 NULL);
154 }
155 else
156 {
157 fpi_ssm_next_state (ssm);
158 }
159 break;
160
161 38 case FP_CMD_GET:
162
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 37 times.
38 if (self->cmd_len_in == 0)
163 {
164 1 CommandData *data = fpi_ssm_get_data (ssm);
165
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (data->callback)
166 1 data->callback (self, NULL, 0, 0);
167 1 fpi_ssm_mark_completed (ssm);
168 1 return;
169 }
170 37 transfer = fpi_usb_transfer_new (dev);
171 37 transfer->ssm = ssm;
172
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 13 times.
61 fpi_usb_transfer_fill_bulk (transfer, self->cmd_cancelable ? ELAN_EP_MOC_CMD_IN : ELAN_EP_CMD_IN, self->cmd_len_in);
173 37 fpi_usb_transfer_submit (transfer,
174
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 13 times.
37 self->cmd_cancelable ? 0 : ELAN_MOC_CMD_TIMEOUT,
175
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 24 times.
37 self->cmd_cancelable ? fpi_device_get_cancellable (dev) : NULL,
176 fp_cmd_receive_cb,
177 fpi_ssm_get_data (ssm));
178 37 break;
179
180 }
181
182 }
183
184 static void
185 38 fp_cmd_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
186 {
187 38 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
188 38 CommandData *data = fpi_ssm_get_data (ssm);
189
190 38 self->cmd_ssm = NULL;
191
192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (error)
193 {
194 if (data->callback)
195 data->callback (self, NULL, 0, error);
196 else
197 g_error_free (error);
198 }
199 38 }
200
201 static void
202 39 fp_cmd_ssm_done_data_free (CommandData *data)
203 {
204 39 g_free (data);
205 39 }
206
207 static void
208 38 elanmoc_get_cmd (FpDevice *device, guint8 *buffer_out,
209 gsize length_out, gsize length_in, gboolean cancelable, SynCmdMsgCallback callback)
210 {
211 38 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
212
213 76 g_autoptr(FpiUsbTransfer) transfer = NULL;
214 38 CommandData *data = g_new0 (CommandData, 1);
215
216 38 transfer = fpi_usb_transfer_new (device);
217 38 transfer->short_is_error = TRUE;
218 38 fpi_usb_transfer_fill_bulk_full (transfer, ELAN_EP_CMD_OUT, buffer_out,
219 length_out, g_free);
220 38 data->callback = callback;
221
222 38 self->cmd_transfer = g_steal_pointer (&transfer);
223 38 self->cmd_len_in = length_in;
224 38 self->cmd_cancelable = cancelable;
225
226 38 self->cmd_ssm = fpi_ssm_new (FP_DEVICE (self),
227 fp_cmd_run_state,
228 FP_CMD_NUM_STATES);
229
230 38 fpi_ssm_set_data (self->cmd_ssm, data, (GDestroyNotify) fp_cmd_ssm_done_data_free);
231
232 38 fpi_ssm_start (self->cmd_ssm, fp_cmd_ssm_done);
233 38 }
234
235 enum enroll_states {
236 ENROLL_RSP_RETRY,
237 ENROLL_RSP_ENROLL_REPORT,
238 ENROLL_RSP_ENROLL_OK,
239 ENROLL_RSP_ENROLL_CANCEL_REPORT,
240 ENROLL_NUM_STATES,
241 };
242
243 static void
244 12 enroll_status_report (FpiDeviceElanmoc *self, int enroll_status_id,
245 int data, GError *error)
246 {
247 12 FpDevice *device = FP_DEVICE (self);
248
249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (error)
250 {
251 fpi_device_enroll_complete (device, NULL, error);
252 return;
253 }
254
255
3/5
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
12 switch (enroll_status_id)
256 {
257 2 case ENROLL_RSP_RETRY:
258 {
259 2 fpi_device_enroll_progress (device, self->num_frames, NULL,
260 fpi_device_retry_new (FP_DEVICE_RETRY_CENTER_FINGER));
261 2 break;
262 }
263
264 9 case ENROLL_RSP_ENROLL_REPORT:
265 {
266 9 fpi_device_enroll_progress (device, self->num_frames, NULL, NULL);
267 9 break;
268 }
269
270 1 case ENROLL_RSP_ENROLL_OK:
271 {
272 1 FpPrint *print = NULL;
273 1 fp_info ("Enrollment was successful!");
274 1 fpi_device_get_enroll_data (device, &print);
275 1 fpi_device_enroll_complete (device, g_object_ref (print), NULL);
276 1 break;
277 }
278
279 case ENROLL_RSP_ENROLL_CANCEL_REPORT:
280 {
281 fpi_device_enroll_complete (device, NULL,
282 fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
283 "Enrollment failed (%d) (ENROLL_RSP_ENROLL_CANCEL_REPORT)",
284 data));
285 }
286 }
287 }
288
289 static void
290 3 elanmoc_get_enrolled_cb (FpiDeviceElanmoc *self,
291 uint8_t *buffer_in,
292 gsize length_in,
293 GError *error)
294 {
295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (error)
296 {
297 fpi_ssm_mark_failed (self->task_ssm, error);
298 return;
299 }
300
301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (buffer_in[0] != 0x40)
302 {
303 fpi_ssm_mark_failed (self->task_ssm,
304 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
305 "Can't get response!!"));
306 }
307 else
308 {
309 3 fp_info ("elanmoc Current enrolled fingers in the Chipset: %d (0x%.2X 0x%.2X)", buffer_in[1],
310 buffer_in[0],
311 buffer_in[1]);
312 3 self->curr_enrolled = buffer_in[1];
313 3 fpi_ssm_next_state (self->task_ssm);
314 }
315 }
316
317 static void
318 1 elanmoc_reenroll_cb (FpiDeviceElanmoc *self,
319 uint8_t *buffer_in,
320 gsize length_in,
321 GError *error)
322 {
323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (error)
324 {
325 fpi_ssm_mark_failed (self->task_ssm, error);
326 return;
327 }
328
329
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (buffer_in[0] != 0x40)
330 {
331 fpi_ssm_mark_failed (self->task_ssm,
332 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
333 "Can't get response!!"));
334 }
335 else
336 {
337
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 if ((self->curr_enrolled == (ELAN_MAX_ENROLL_NUM + 1)) && (buffer_in[1] == 0x00))
338 {
339 fp_warn ("elanmoc_reenroll_cb over enroll max");
340 fpi_ssm_mark_failed (self->task_ssm,
341 fpi_device_error_new (FP_DEVICE_ERROR_DATA_FULL));
342 return;
343 }
344
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (buffer_in[1] == 0x00)
345 fp_info ("##### Normal Enrollment Case! #####");
346
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if (buffer_in[1] == 0x01)
347 1 fp_info ("##### Re-Enrollment Case! #####");
348 1 self->num_frames = 0;
349 1 fpi_ssm_next_state (self->task_ssm);
350 }
351 }
352
353 static void
354 11 elanmoc_enroll_cb (FpiDeviceElanmoc *self,
355 uint8_t *buffer_in,
356 gsize length_in,
357 GError *error)
358 {
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (error)
360 {
361 fpi_ssm_mark_failed (self->task_ssm, error);
362 return;
363 }
364
365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (buffer_in[0] != 0x40)
366 {
367 fpi_ssm_mark_failed (self->task_ssm,
368 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
369 "Can't get response!!"));
370 }
371 else
372 {
373
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if (buffer_in[1] == ELAN_MSG_OK)
374 {
375 9 self->num_frames += 1;
376 9 enroll_status_report (self, ENROLL_RSP_ENROLL_REPORT, self->num_frames, NULL);
377 }
378 else
379 {
380 2 enroll_status_report (self, ENROLL_RSP_RETRY, self->num_frames, NULL);
381 }
382
383
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
11 if (self->num_frames == self->max_moc_enroll_time && buffer_in[1] == ELAN_MSG_OK)
384 1 fpi_ssm_next_state (self->task_ssm);
385
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 else if (self->num_frames < self->max_moc_enroll_time)
386 10 fpi_ssm_jump_to_state (self->task_ssm, MOC_ENROLL_WAIT_FINGER);
387 else
388 fpi_ssm_mark_failed (self->task_ssm, error);
389 }
390 }
391
392 static void
393 1 elanmoc_commit_cb (FpiDeviceElanmoc *self,
394 uint8_t *buffer_in,
395 gsize length_in,
396 GError *error)
397 {
398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (error)
399 {
400 fpi_ssm_mark_failed (self->task_ssm, error);
401 return;
402 }
403
404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (length_in == 0)
405 {
406 fpi_ssm_next_state (self->task_ssm);
407 return;
408 }
409
410
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 if (buffer_in[0] != 0x40 && buffer_in[1] != 0x00 )
411 {
412 fpi_ssm_mark_failed (self->task_ssm,
413 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
414 "Can't get response!!"));
415 }
416 else
417 {
418 1 fp_info ("elanmoc_commit_cb success");
419 1 enroll_status_report (self, ENROLL_RSP_ENROLL_OK, self->num_frames, NULL);
420 1 fpi_ssm_next_state (self->task_ssm);
421 }
422 }
423
424 static void
425 14 elan_enroll_run_state (FpiSsm *ssm, FpDevice *dev)
426 {
427 14 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
428 14 guint8 *cmd_buf = NULL;
429 14 guint8 *data = NULL;
430
431
4/5
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
14 switch (fpi_ssm_get_cur_state (ssm))
432 {
433 1 case MOC_ENROLL_GET_ENROLLED_NUM:
434 1 cmd_buf = elanmoc_compose_cmd (&enrolled_number_cmd);
435 1 elanmoc_get_cmd (dev, cmd_buf, enrolled_number_cmd.cmd_len, enrolled_number_cmd.resp_len, 0, elanmoc_get_enrolled_cb);
436 1 break;
437
438 1 case MOC_ENROLL_REENROLL_CHECK:
439 1 data = fpi_ssm_get_data (ssm);
440 1 cmd_buf = elanmoc_compose_cmd (&elanmoc_check_reenroll_cmd);
441 1 memcpy (cmd_buf + 3, data, ELAN_USERDATE_SIZE);
442 1 elanmoc_get_cmd (dev, cmd_buf, elanmoc_check_reenroll_cmd.cmd_len, elanmoc_check_reenroll_cmd.resp_len, 0, elanmoc_reenroll_cb);
443 1 break;
444
445 11 case MOC_ENROLL_WAIT_FINGER:
446 11 cmd_buf = elanmoc_compose_cmd (&elanmoc_enroll_cmd);
447 11 cmd_buf[3] = self->curr_enrolled;
448 11 cmd_buf[4] = self->max_moc_enroll_time;
449 11 cmd_buf[5] = self->num_frames;
450 11 elanmoc_get_cmd (dev, cmd_buf, elanmoc_enroll_cmd.cmd_len, elanmoc_enroll_cmd.resp_len, 1, elanmoc_enroll_cb);
451 11 break;
452
453 1 case MOC_ENROLL_COMMIT_RESULT:
454 1 data = fpi_ssm_get_data (ssm);
455 1 cmd_buf = elanmoc_compose_cmd (&elanmoc_enroll_commit_cmd);
456 1 memcpy (cmd_buf + 5, data, ELAN_USERDATE_SIZE);
457 1 elanmoc_get_cmd (dev, cmd_buf, elanmoc_enroll_commit_cmd.cmd_len, elanmoc_enroll_commit_cmd.resp_len, 0, elanmoc_commit_cb);
458 1 break;
459 }
460 14 }
461
462 static void
463 5 task_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
464 {
465 5 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
466
467 5 self->task_ssm = NULL;
468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 g_clear_pointer (&self->list_result, g_ptr_array_unref);
469
470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (error)
471 fpi_device_action_error (dev, error);
472 5 }
473
474 static FpPrint *
475 3 create_print_from_response (FpiDeviceElanmoc *self,
476 uint8_t *buffer_in,
477 gsize length_in,
478 GError **error)
479 {
480 3 FpPrint *print;
481 3 GVariant *data;
482 3 GVariant *uid;
483 6 g_autofree gchar *userid = NULL;
484 3 g_autofree gchar *userid_safe = NULL;
485 3 int userid_len = 0;
486
487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (buffer_in[0] != 0x43)
488 {
489 g_propagate_error (error,
490 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
491 "Can't get response!!"));
492 return NULL;
493 }
494
495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (buffer_in[1] != ELAN_MSG_OK)
496 {
497 g_propagate_error (error,
498 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
499 "Device returned error %d rather than print!", buffer_in[1]));
500 return NULL;
501 }
502
503 3 userid_len = buffer_in[4];
504
505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (userid_len > length_in - 5)
506 {
507 g_propagate_error (error,
508 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
509 "Packet too short for payload length!"));
510 return NULL;
511 }
512
513 3 userid = g_memdup2 (&buffer_in[5], userid_len);
514 3 userid_safe = g_strndup ((const char *) &buffer_in[5], userid_len);
515 3 print = fp_print_new (FP_DEVICE (self));
516 3 uid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, userid, userid_len, 1);
517
518 /* The first two bytes are meant to store a UUID,
519 * but will always be zero for prints created by libfprint.
520 */
521 6 data = g_variant_new ("(yy@ay)",
522 3 buffer_in[2],
523 3 buffer_in[3],
524 uid);
525
526 3 fpi_print_set_type (print, FPI_PRINT_RAW);
527 3 fpi_print_set_device_stored (print, TRUE);
528 3 g_object_set (print, "fpi-data", data, NULL);
529 3 g_object_set (print, "description", userid_safe, NULL);
530
531 3 fpi_print_fill_from_user_id (print, userid_safe);
532
533 3 return print;
534 }
535
536 static void
537 10 elanmoc_get_userid_cb (FpiDeviceElanmoc *self,
538 uint8_t *buffer_in,
539 gsize length_in,
540 GError *error)
541 {
542 10 FpPrint *print;
543
544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (error)
545 {
546 fpi_ssm_mark_failed (self->task_ssm, error);
547 return;
548 }
549
550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (buffer_in[0] != 0x43)
551 {
552 fpi_ssm_mark_failed (self->task_ssm,
553 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
554 "Can't get response!!"));
555 return;
556 }
557
558 10 self->list_index++;
559
560 /* Skip 0xfe messages */
561
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (buffer_in[1] != 0xfe)
562 {
563 1 print = create_print_from_response (self, buffer_in, length_in, &error);
564
565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!print)
566 {
567 fpi_ssm_mark_failed (self->task_ssm, error);
568 return;
569 }
570
571 1 g_ptr_array_add (self->list_result, g_object_ref_sink (print));
572 }
573
574
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
10 if(self->list_index <= ELAN_MAX_ENROLL_NUM)
575 {
576 9 fpi_ssm_jump_to_state (self->task_ssm, MOC_LIST_GET_FINGER);
577 }
578 else
579 {
580 1 fpi_device_list_complete (FP_DEVICE (self), g_steal_pointer (&self->list_result), NULL);
581 1 fpi_ssm_next_state (self->task_ssm);
582 }
583 }
584
585 static void
586 11 elan_list_run_state (FpiSsm *ssm, FpDevice *dev)
587 {
588 11 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
589 11 guint8 *cmd_buf = NULL;
590
591
2/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
11 switch (fpi_ssm_get_cur_state (ssm))
592 {
593 1 case MOC_LIST_GET_ENROLLED:
594 1 cmd_buf = elanmoc_compose_cmd (&enrolled_number_cmd);
595 1 elanmoc_get_cmd (dev, cmd_buf, enrolled_number_cmd.cmd_len, enrolled_number_cmd.resp_len, 0, elanmoc_get_enrolled_cb);
596 1 self->list_index = 0;
597 1 break;
598
599 10 case MOC_LIST_GET_FINGER:
600 10 cmd_buf = elanmoc_compose_cmd (&elanmoc_get_userid_cmd);
601 10 cmd_buf[2] = self->list_index;
602 10 elanmoc_get_cmd (dev, cmd_buf, elanmoc_get_userid_cmd.cmd_len, elanmoc_get_userid_cmd.resp_len, 0, elanmoc_get_userid_cb);
603 10 break;
604 }
605 11 }
606
607 static void
608 1 elanmoc_list (FpDevice *device)
609 {
610 1 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
611
612 1 self->list_result = g_ptr_array_new_with_free_func (g_object_unref);
613 1 self->task_ssm = fpi_ssm_new (FP_DEVICE (self),
614 elan_list_run_state,
615 MOC_LIST_NUM_STATES);
616 1 fpi_ssm_start (self->task_ssm, task_ssm_done);
617 1 }
618
619 enum verify_status {
620 RSP_VERIFY_FAIL,
621 RSP_VERIFY_OK,
622 RSP_VERIFY_STATES,
623 };
624
625 static void
626 2 elanmoc_match_report_cb (FpiDeviceElanmoc *self,
627 uint8_t *buffer_in,
628 gsize length_in,
629 GError *error)
630 {
631 2 FpDevice *device = FP_DEVICE (self);
632 2 FpPrint *print = NULL;
633 2 FpPrint *verify_print = NULL;
634 2 GPtrArray *prints;
635 2 gboolean found = FALSE;
636 2 guint index;
637
638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (error)
639 {
640 fpi_ssm_mark_failed (self->task_ssm, error);
641 return;
642 }
643
644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (buffer_in[0] != 0x43)
645 {
646 fpi_ssm_mark_failed (self->task_ssm,
647 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
648 "Can't get response!!"));
649 return;
650 }
651
652 2 print = create_print_from_response (self, buffer_in, length_in, &error);
653
654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!print)
655 {
656 fpi_ssm_mark_failed (self->task_ssm, error);
657 return;
658 }
659
660 2 fp_info ("Verify/Identify successful for: %s", fp_print_get_description (print));
661
662
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_IDENTIFY)
663 {
664 1 fpi_device_get_identify_data (device, &prints);
665 1 found = g_ptr_array_find_with_equal_func (prints,
666 print,
667 (GEqualFunc) fp_print_equal,
668 &index);
669
670
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (found)
671 1 fpi_device_identify_report (device, g_ptr_array_index (prints, index), print, NULL);
672 else
673 fpi_device_identify_report (device, NULL, print, NULL);
674
675 1 fpi_device_identify_complete (device, NULL);
676 }
677 else
678 {
679 1 fpi_device_get_verify_data (device, &verify_print);
680
681
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (fp_print_equal (verify_print, print))
682 1 fpi_device_verify_report (device, FPI_MATCH_SUCCESS, print, NULL);
683 else
684 fpi_device_verify_report (device, FPI_MATCH_FAIL, print, NULL);
685 1 fpi_device_verify_complete (device, NULL);
686 }
687 }
688
689 static void
690 2 identify_status_report (FpiDeviceElanmoc *self, int verify_status_id,
691 int data, GError *error)
692 {
693 2 FpDevice *device = FP_DEVICE (self);
694 2 guint8 *cmd_buf = NULL;
695
696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (error)
697 {
698 if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_VERIFY)
699 fpi_device_verify_complete (device, error);
700 else
701 fpi_device_identify_complete (device, error);
702 return;
703 }
704
705
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 switch (verify_status_id)
706 {
707 case RSP_VERIFY_FAIL:
708 {
709 if (data == ELAN_MSG_VERIFY_ERR)
710 {
711 if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_VERIFY)
712 {
713 fpi_device_verify_report (device, FPI_MATCH_FAIL, NULL, NULL);
714 fpi_device_verify_complete (device, NULL);
715 }
716 else
717 {
718 fpi_device_identify_report (device, NULL, NULL, NULL);
719 fpi_device_identify_complete (device, NULL);
720 }
721 }
722 else
723 {
724 GError *retry_error;
725
726 switch (data)
727 {
728 case ELAN_MSG_TOO_HIGH:
729 case ELAN_MSG_TOO_LOW:
730 case ELAN_MSG_TOO_RIGHT:
731 case ELAN_MSG_TOO_LEFT:
732 retry_error = fpi_device_retry_new (FP_DEVICE_RETRY_CENTER_FINGER);
733 break;
734
735 default:
736 retry_error = fpi_device_retry_new (FP_DEVICE_RETRY_GENERAL);
737 }
738
739 if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_VERIFY)
740 {
741 fpi_device_verify_report (device, FPI_MATCH_ERROR, NULL, retry_error);
742 fpi_device_verify_complete (device, NULL);
743 }
744 else
745 {
746 fpi_device_identify_report (device, NULL, NULL, retry_error);
747 fpi_device_identify_complete (device, NULL);
748 }
749 }
750 break;
751 }
752
753 2 case RSP_VERIFY_OK:
754 {
755 2 fp_dbg ("Verify was successful! for user: %d mesg_code: %d ", data, verify_status_id);
756 2 cmd_buf = elanmoc_compose_cmd (&elanmoc_get_userid_cmd);
757 2 cmd_buf[2] = data;
758 2 elanmoc_get_cmd (device, cmd_buf, elanmoc_get_userid_cmd.cmd_len, elanmoc_get_userid_cmd.resp_len, 0, elanmoc_match_report_cb);
759 2 break;
760 }
761 }
762 }
763
764 enum identify_states {
765 IDENTIFY_SET_MODE,
766 IDENTIFY_WAIT_FINGER,
767 IDENTIFY_NUM_STATES,
768 };
769
770 static void
771 2 elanmoc_identify_cb (FpiDeviceElanmoc *self,
772 uint8_t *buffer_in,
773 gsize length_in,
774 GError *error)
775 {
776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (error)
777 {
778 fpi_ssm_mark_failed (self->task_ssm, error);
779 return;
780 }
781
782
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (buffer_in[1] == ELAN_MSG_VERIFY_ERR)
783 identify_status_report (self, RSP_VERIFY_FAIL,
784 buffer_in[1], error);
785
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if (buffer_in[1] <= ELAN_MAX_ENROLL_NUM)
786 2 identify_status_report (self, RSP_VERIFY_OK, buffer_in[1], error);
787 else
788 identify_status_report (self, RSP_VERIFY_FAIL, buffer_in[1], error);
789 2 fpi_ssm_next_state (self->task_ssm);
790
791 }
792
793 static void
794 4 elan_identify_run_state (FpiSsm *ssm, FpDevice *dev)
795 {
796 4 guint8 *cmd_buf = NULL;
797
798 4 fp_info ("elanmoc %s ", __func__);
799
2/3
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 switch (fpi_ssm_get_cur_state (ssm))
800 {
801 2 case IDENTIFY_SET_MODE:
802 2 fp_info ("elanmoc %s IDENTIFY_SET_MODE", __func__);
803 2 cmd_buf = elanmoc_compose_cmd (&elanmoc_set_mod_cmd);
804 2 cmd_buf[3] = 0x03;
805 2 elanmoc_get_cmd (dev, cmd_buf, elanmoc_set_mod_cmd.cmd_len, elanmoc_set_mod_cmd.resp_len, 0, elanmoc_cmd_ack_cb);
806 2 break;
807
808 2 case IDENTIFY_WAIT_FINGER:
809 2 fp_info ("elanmoc %s VERIFY_WAIT_FINGER", __func__);
810 2 cmd_buf = elanmoc_compose_cmd (&elanmoc_verify_cmd);
811 2 elanmoc_get_cmd (dev, cmd_buf, elanmoc_verify_cmd.cmd_len, elanmoc_verify_cmd.resp_len, 1, elanmoc_identify_cb);
812 2 break;
813 }
814 4 }
815
816 static void
817 1 elanmoc_enroll (FpDevice *device)
818 {
819 1 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
820 1 FpPrint *print = NULL;
821 1 GVariant *data = NULL;
822 1 GVariant *uid = NULL;
823 2 g_autofree gchar *user_id = NULL;
824 1 gsize user_id_len;
825 1 guint8 *userdata = g_malloc0 (ELAN_USERDATE_SIZE);
826
827 1 fpi_device_get_enroll_data (device, &print);
828 1 user_id = fpi_print_generate_user_id (print);
829 1 user_id_len = strlen (user_id);
830 1 user_id_len = MIN (ELAN_MAX_USER_ID_LEN, user_id_len);
831
832 1 uid = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
833 user_id,
834 user_id_len, 1);
835
836 1 data = g_variant_new ("(yy@ay)",
837 0, 0,
838 uid);
839
840 1 fpi_print_set_type (print, FPI_PRINT_RAW);
841 1 fpi_print_set_device_stored (print, TRUE);
842 1 g_object_set (print, "fpi-data", data, NULL);
843 1 g_object_set (print, "description", user_id, NULL);
844
845 1 userdata[0] = 0;
846 1 userdata[1] = 0;
847 1 userdata[2] = user_id_len;
848
849 1 memcpy (userdata + 3, user_id, user_id_len);
850 1 self->task_ssm = fpi_ssm_new (FP_DEVICE (self),
851 elan_enroll_run_state,
852 MOC_ENROLL_NUM_STATES);
853 1 fpi_ssm_set_data (self->task_ssm, userdata, (GDestroyNotify) fp_cmd_ssm_done_data_free);
854 1 fpi_ssm_start (self->task_ssm, task_ssm_done);
855 1 }
856
857 static void
858 1 elanmoc_delete_cb (FpiDeviceElanmoc *self,
859 uint8_t *buffer_in,
860 gsize length_in,
861 GError *error)
862 {
863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (error)
864 {
865 fpi_ssm_mark_failed (self->task_ssm, error);
866 return;
867 }
868
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 if (buffer_in[0] != 0x40 && buffer_in[1] != 0x00)
869 {
870 fpi_ssm_mark_failed (self->task_ssm,
871 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
872 "Can't get response!!"));
873 }
874 else
875 {
876 1 fpi_device_delete_complete (FP_DEVICE (self), NULL);
877 1 fpi_ssm_next_state (self->task_ssm);
878 }
879 }
880
881 static void
882 1 elan_delete_run_state (FpiSsm *ssm, FpDevice *dev)
883 {
884 1 guint8 *cmd_buf = NULL;
885 1 guint8 *data = fpi_ssm_get_data (ssm);
886
887
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 switch (fpi_ssm_get_cur_state (ssm))
888 {
889 1 case DELETE_SEND_CMD:
890 1 cmd_buf = elanmoc_compose_cmd (&elanmoc_delete_cmd);
891 1 memcpy (cmd_buf + 3, data, ELAN_USERDATE_SIZE);
892 1 elanmoc_get_cmd (dev, cmd_buf, elanmoc_delete_cmd.cmd_len, elanmoc_delete_cmd.resp_len, 0, elanmoc_delete_cb);
893 1 break;
894 }
895 1 }
896
897 static void
898 1 elanmoc_delete_print (FpDevice *device)
899 {
900 1 g_autoptr(GVariant) data = NULL;
901
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 g_autoptr(GVariant) user_id_var = NULL;
902 1 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
903 1 FpPrint *print = NULL;
904 1 const guint8 *user_id;
905
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 g_autofree char *user_id_safe = NULL;
906 1 gsize user_id_len = 0;
907 1 guint8 *userid_buf = NULL;
908
909 1 fpi_device_get_delete_data (device, &print);
910 1 g_object_get (print, "fpi-data", &data, NULL);
911
912
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!g_variant_check_format_string (data, "(yy@ay)", FALSE))
913 {
914 fpi_device_delete_complete (device,
915 fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
916 return;
917 }
918
919 1 userid_buf = g_malloc0 (ELAN_USERDATE_SIZE);
920
921 1 g_variant_get (data,
922 "(yy@ay)",
923 &userid_buf[0],
924 &userid_buf[1],
925 &user_id_var);
926 1 user_id = g_variant_get_fixed_array (user_id_var, &user_id_len, 1);
927 1 user_id_safe = g_strndup ((const char *) user_id, user_id_len);
928 1 user_id_len = MIN (ELAN_MAX_USER_ID_LEN, user_id_len);
929 1 userid_buf[2] = user_id_len;
930 1 memcpy (userid_buf + 3, user_id, user_id_len);
931
932 1 fp_info ("Delete Finger, user_id = %s!", user_id_safe);
933 1 self->task_ssm = fpi_ssm_new (device,
934 elan_delete_run_state,
935 DELETE_NUM_STATES);
936 1 fpi_ssm_set_data (self->task_ssm, userid_buf, g_free);
937 1 fpi_ssm_start (self->task_ssm, task_ssm_done);
938 }
939
940 static void
941 2 elanmoc_identify (FpDevice *device)
942 {
943 2 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
944
945 2 self->task_ssm = fpi_ssm_new (device,
946 elan_identify_run_state,
947 IDENTIFY_NUM_STATES);
948 2 fpi_ssm_start (self->task_ssm, task_ssm_done);
949 2 }
950
951 static void
952 1 task_ssm_init_done (FpiSsm *ssm, FpDevice *dev, GError *error)
953 {
954 1 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
955
956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (error)
957 g_usb_device_release_interface (fpi_device_get_usb_device (dev),
958 0, 0, NULL);
959
960 1 fpi_device_open_complete (FP_DEVICE (self), error);
961 1 }
962
963 static void
964 1 elanmoc_cmd_ver_cb (FpiDeviceElanmoc *self,
965 uint8_t *buffer_in,
966 gsize length_in,
967 GError *error)
968 {
969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (error)
970 {
971 fpi_ssm_mark_failed (self->task_ssm, error);
972 return;
973 }
974
975 1 self->fw_ver = (buffer_in[0] << 8 | buffer_in[1]);
976 1 fp_info ("elanmoc FW Version %x ", self->fw_ver);
977 1 fpi_ssm_next_state (self->task_ssm);
978 }
979
980 static void
981 1 elanmoc_cmd_dim_cb (FpiDeviceElanmoc *self,
982 uint8_t *buffer_in,
983 gsize length_in,
984 GError *error)
985 {
986
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (error)
987 {
988 fpi_ssm_mark_failed (self->task_ssm, error);
989 return;
990 }
991
992 1 self->x_trace = buffer_in[0];
993 1 self->y_trace = buffer_in[2];
994 1 fp_info ("elanmoc last_read DIM 0x%.2X(%d) 0x%.2X(%d)", self->x_trace, self->x_trace,
995 self->y_trace, self->y_trace);
996 1 fpi_ssm_next_state (self->task_ssm);
997 }
998
999 static void
1000 1 elanmoc_get_status_cb (FpiDeviceElanmoc *self,
1001 uint8_t *buffer_in,
1002 gsize length_in,
1003 GError *error)
1004 {
1005 1 guint8 *cmd_buf = NULL;
1006
1007
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (error)
1008 {
1009 fpi_ssm_mark_failed (self->task_ssm, error);
1010 return;
1011 }
1012
1013
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 if (buffer_in[1] != 0x03 && self->cmd_retry_cnt != 0)
1014 {
1015 self->cmd_retry_cnt--;
1016 cmd_buf = elanmoc_compose_cmd (&cal_status_cmd);
1017 elanmoc_get_cmd (FP_DEVICE (self), cmd_buf, cal_status_cmd.cmd_len, cal_status_cmd.resp_len, 0, elanmoc_get_status_cb);
1018 }
1019 else
1020 {
1021
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(self->cmd_retry_cnt == 0)
1022 {
1023 fpi_ssm_mark_failed (self->task_ssm,
1024 fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
1025 "Sensor not ready"));
1026 return;
1027 }
1028 1 fpi_ssm_next_state (self->task_ssm);
1029 }
1030 }
1031
1032 static void
1033 5 dev_init_handler (FpiSsm *ssm, FpDevice *dev)
1034 {
1035 5 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
1036 5 guint8 *cmd_buf = NULL;
1037
1038
5/6
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
5 switch (fpi_ssm_get_cur_state (ssm))
1039 {
1040 1 case DEV_WAIT_READY:
1041 1 self->cmd_retry_cnt = ELAN_MOC_CAL_RETRY;
1042 1 cmd_buf = elanmoc_compose_cmd (&cal_status_cmd);
1043 1 elanmoc_get_cmd (dev, cmd_buf, cal_status_cmd.cmd_len, cal_status_cmd.resp_len, 0, elanmoc_get_status_cb);
1044 1 break;
1045
1046 1 case DEV_SET_MODE:
1047 1 cmd_buf = elanmoc_compose_cmd (&elanmoc_set_mod_cmd);
1048 1 cmd_buf[3] = 0x03;
1049 1 elanmoc_get_cmd (dev, cmd_buf, elanmoc_set_mod_cmd.cmd_len, elanmoc_set_mod_cmd.resp_len, 0, elanmoc_cmd_ack_cb);
1050 1 break;
1051
1052 1 case DEV_GET_VER:
1053 1 cmd_buf = elanmoc_compose_cmd (&fw_ver_cmd);
1054 1 elanmoc_get_cmd (dev, cmd_buf, fw_ver_cmd.cmd_len, fw_ver_cmd.resp_len, 0, elanmoc_cmd_ver_cb);
1055 1 break;
1056
1057 1 case DEV_GET_DIM:
1058 1 cmd_buf = elanmoc_compose_cmd (&sensor_dim_cmd);
1059 1 elanmoc_get_cmd (dev, cmd_buf, sensor_dim_cmd.cmd_len, sensor_dim_cmd.resp_len, 0, elanmoc_cmd_dim_cb);
1060 1 break;
1061
1062 1 case DEV_GET_ENROLLED:
1063 1 cmd_buf = elanmoc_compose_cmd (&enrolled_number_cmd);
1064 1 elanmoc_get_cmd (dev, cmd_buf, enrolled_number_cmd.cmd_len, enrolled_number_cmd.resp_len, 0, elanmoc_get_enrolled_cb);
1065 1 break;
1066
1067 }
1068 5 }
1069
1070 static void
1071 1 elanmoc_open (FpDevice *device)
1072 {
1073 1 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
1074 1 GError *error = NULL;
1075 1 gint productid = 0;
1076
1077
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!g_usb_device_reset (fpi_device_get_usb_device (device), &error))
1078 goto error;
1079
1080
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!g_usb_device_claim_interface (fpi_device_get_usb_device (device), 0, 0, &error))
1081 goto error;
1082
1083 1 productid = g_usb_device_get_pid (fpi_device_get_usb_device (device));
1084
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 switch (productid)
1085 {
1086 case 0x0c8c:
1087 self->max_moc_enroll_time = 11;
1088 break;
1089
1090 case 0x0c99:
1091 self->max_moc_enroll_time = 14;
1092 break;
1093
1094 case 0x0c8d:
1095 self->max_moc_enroll_time = 17;
1096 break;
1097
1098 1 default:
1099 1 self->max_moc_enroll_time = ELAN_MOC_ENROLL_TIMES;
1100 1 break;
1101 }
1102
1103 1 fpi_device_set_nr_enroll_stages (device, self->max_moc_enroll_time);
1104
1105 1 self->task_ssm = fpi_ssm_new (FP_DEVICE (self), dev_init_handler, DEV_INIT_STATES);
1106 1 fpi_ssm_start (self->task_ssm, task_ssm_init_done);
1107 1 return;
1108
1109 error:
1110 fpi_device_open_complete (FP_DEVICE (self), error);
1111 }
1112
1113 static void
1114 1 task_ssm_exit_done (FpiSsm *ssm, FpDevice *dev, GError *error)
1115 {
1116 1 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (dev);
1117
1118 1 g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (self)), 0, 0, &error);
1119 1 fpi_device_close_complete (FP_DEVICE (self), error);
1120 1 self->task_ssm = NULL;
1121 1 }
1122
1123 static void
1124 1 dev_exit_handler (FpiSsm *ssm, FpDevice *dev)
1125 {
1126 1 guint8 *cmd_buf = NULL;
1127
1128
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 switch (fpi_ssm_get_cur_state (ssm))
1129 {
1130 1 case DEV_EXIT_ABOVE:
1131 1 cmd_buf = elanmoc_compose_cmd (&elanmoc_above_cmd);
1132 1 elanmoc_get_cmd (dev, cmd_buf, elanmoc_above_cmd.cmd_len, elanmoc_above_cmd.resp_len, 0, elanmoc_cmd_ack_cb);
1133 1 break;
1134 }
1135 1 }
1136
1137 static void
1138 1 elanmoc_close (FpDevice *device)
1139 {
1140 1 FpiDeviceElanmoc *self = FPI_DEVICE_ELANMOC (device);
1141
1142 1 fp_info ("Elanmoc dev_exit");
1143 1 self->task_ssm = fpi_ssm_new (FP_DEVICE (self), dev_exit_handler, DEV_EXIT_STATES);
1144 1 fpi_ssm_start (self->task_ssm, task_ssm_exit_done);
1145 1 }
1146
1147 static void
1148 1 fpi_device_elanmoc_init (FpiDeviceElanmoc *self)
1149 {
1150 1 G_DEBUG_HERE ();
1151 1 }
1152
1153 static void
1154 117 fpi_device_elanmoc_class_init (FpiDeviceElanmocClass *klass)
1155 {
1156 117 FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
1157
1158 117 dev_class->id = FP_COMPONENT;
1159 117 dev_class->full_name = ELAN_MOC_DRIVER_FULLNAME;
1160
1161 117 dev_class->type = FP_DEVICE_TYPE_USB;
1162 117 dev_class->scan_type = FP_SCAN_TYPE_PRESS;
1163 117 dev_class->id_table = id_table;
1164 117 dev_class->nr_enroll_stages = ELAN_MOC_ENROLL_TIMES;
1165 117 dev_class->temp_hot_seconds = -1;
1166
1167 117 dev_class->open = elanmoc_open;
1168 117 dev_class->close = elanmoc_close;
1169 117 dev_class->verify = elanmoc_identify;
1170 117 dev_class->enroll = elanmoc_enroll;
1171 117 dev_class->identify = elanmoc_identify;
1172 117 dev_class->delete = elanmoc_delete_print;
1173 117 dev_class->list = elanmoc_list;
1174
1175 117 fpi_device_class_auto_initialize_features (dev_class);
1176 117 }
1177