GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 80.5% 438 / 0 / 544
Functions: 100.0% 41 / 0 / 41
Branches: 52.7% 99 / 0 / 188

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