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