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