GCC Code Coverage Report


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