GCC Code Coverage Report


Directory: ./
File: libfprint/drivers/elanmoc/elanmoc.c
Date: 2025-12-06 02:24:24
Exec Total Coverage
Lines: 443 557 79.5%
Functions: 41 41 100.0%
Branches: 101 196 51.5%

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