GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 79.7% 445 / 0 / 558
Functions: 100.0% 41 / 0 / 41
Branches: 51.5% 102 / 0 / 198

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