GCC Code Coverage Report


Directory: ./
File: libfprint/drivers/elanmoc/elanmoc.c
Date: 2026-01-20 16:36:38
Exec Total Coverage
Lines: 443 557 79.5%
Functions: 41 41 100.0%
Branches: 101 196 51.5%

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