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