Skip to content

Commit f67f61c

Browse files
boger.wangbenzea
authored andcommitted
goodixmoc: Add identify function
this device support verify and identify both, actually call the same interface.
1 parent d5f7f4d commit f67f61c

File tree

1 file changed

+80
-40
lines changed

1 file changed

+80
-40
lines changed

libfprint/drivers/goodixmoc/goodix.c

Lines changed: 80 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ typedef struct
7272
SynCmdMsgCallback callback;
7373
} CommandData;
7474

75+
static gboolean parse_print_data (GVariant *data,
76+
guint8 *finger,
77+
const guint8 **tid,
78+
gsize *tid_len,
79+
const guint8 **user_id,
80+
gsize *user_id_len);
7581
/******************************************************************************
7682
*
7783
* fp_cmd_xxx Function
@@ -340,30 +346,74 @@ fp_verify_capture_cb (FpiDeviceGoodixMoc *self,
340346
}
341347

342348
static void
343-
fp_verify_identify_cb (FpiDeviceGoodixMoc *self,
344-
gxfp_cmd_response_t *resp,
345-
GError *error)
349+
fp_verify_cb (FpiDeviceGoodixMoc *self,
350+
gxfp_cmd_response_t *resp,
351+
GError *error)
346352
{
347353
FpDevice *device = FP_DEVICE (self);
354+
FpPrint *print = NULL;
355+
GPtrArray *templates = NULL;
356+
gint cnt = 0;
357+
gboolean find = false;
348358

349359
if (error)
350360
{
351361
fpi_ssm_mark_failed (self->task_ssm, error);
352362
return;
353363
}
354-
if (!resp->verify.match)
355-
{
356-
fpi_device_verify_report (device, FPI_MATCH_FAIL, NULL, error);
357-
}
358-
else if (memcmp (&resp->verify.template.tid, &self->template_id, TEMPLATE_ID_SIZE) != 0)
364+
if (resp->verify.match)
359365
{
360-
fpi_device_verify_report (device, FPI_MATCH_FAIL, NULL, error);
366+
if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_VERIFY)
367+
{
368+
369+
templates = g_ptr_array_new_with_free_func (g_object_unref);
370+
fpi_device_get_verify_data (device, &print);
371+
g_ptr_array_add (templates, g_object_ref_sink (print));
372+
373+
}
374+
else
375+
{
376+
fpi_device_get_identify_data (device, &templates);
377+
}
378+
for (cnt = 0; cnt < templates->len; cnt++)
379+
{
380+
g_autoptr(GVariant) data = NULL;
381+
guint8 finger;
382+
const guint8 *user_id;
383+
gsize user_id_len = 0;
384+
const guint8 *tid;
385+
gsize tid_len = 0;
386+
print = g_ptr_array_index (templates, cnt);
387+
g_object_get (print, "fpi-data", &data, NULL);
388+
if (!parse_print_data (data, &finger, &tid, &tid_len, &user_id, &user_id_len))
389+
{
390+
fpi_ssm_mark_failed (self->task_ssm,
391+
fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
392+
"Parse print error"));
393+
return;
394+
}
395+
if (memcmp (&resp->verify.template.tid, tid, TEMPLATE_ID_SIZE) == 0)
396+
{
397+
find = true;
398+
break;
399+
}
400+
401+
}
402+
if (find)
403+
{
404+
if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_VERIFY)
405+
fpi_device_verify_report (device, FPI_MATCH_SUCCESS, NULL, error);
406+
else
407+
fpi_device_identify_report (device, print, print, error);
408+
}
361409
}
362-
else
410+
411+
if (!find)
363412
{
364-
fp_info ("Verify successful! for user: %s finger: %d",
365-
resp->verify.template.payload.data, resp->verify.template.finger_index);
366-
fpi_device_verify_report (device, FPI_MATCH_SUCCESS, NULL, NULL);
413+
if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_VERIFY)
414+
fpi_device_verify_report (device, FPI_MATCH_FAIL, NULL, error);
415+
else
416+
fpi_device_identify_report (device, NULL, NULL, error);
367417
}
368418

369419
fpi_ssm_mark_completed (self->task_ssm);
@@ -375,6 +425,7 @@ fp_verify_sm_run_state (FpiSsm *ssm, FpDevice *device)
375425
{
376426
FpiDeviceGoodixMoc *self = FPI_DEVICE_GOODIXMOC (device);
377427
guint8 param[3] = { 0 };
428+
guint8 nonce[TEMPLATE_ID_SIZE] = { 0 };
378429

379430
param[0] = 0x01;
380431
param[1] = self->sensorcfg->config[10];
@@ -393,9 +444,9 @@ fp_verify_sm_run_state (FpiSsm *ssm, FpDevice *device)
393444
case FP_VERIFY_IDENTIFY:
394445
goodix_sensor_cmd (self, MOC_CMD0_IDENTIFY, MOC_CMD1_DEFAULT,
395446
false,
396-
(const guint8 *) &self->template_id,
447+
(const guint8 *) nonce,
397448
TEMPLATE_ID_SIZE,
398-
fp_verify_identify_cb);
449+
fp_verify_cb);
399450
break;
400451
}
401452

@@ -409,9 +460,18 @@ fp_verify_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
409460
fp_info ("Verify complete!");
410461

411462
if (error && error->domain == FP_DEVICE_RETRY)
412-
fpi_device_verify_report (dev, FPI_MATCH_ERROR, NULL, error);
463+
{
464+
if (fpi_device_get_current_action (dev) == FPI_DEVICE_ACTION_VERIFY)
465+
fpi_device_verify_report (dev, FPI_MATCH_ERROR, NULL, error);
466+
else
467+
fpi_device_identify_report (dev, NULL, NULL, error);
468+
}
469+
470+
if (fpi_device_get_current_action (dev) == FPI_DEVICE_ACTION_VERIFY)
471+
fpi_device_verify_complete (dev, error);
413472

414-
fpi_device_verify_complete (dev, error);
473+
else
474+
fpi_device_identify_complete (dev, error);
415475

416476
self->task_ssm = NULL;
417477
}
@@ -1252,30 +1312,9 @@ gx_fp_exit (FpDevice *device)
12521312

12531313

12541314
static void
1255-
gx_fp_verify (FpDevice *device)
1315+
gx_fp_verify_identify (FpDevice *device)
12561316
{
1257-
12581317
FpiDeviceGoodixMoc *self = FPI_DEVICE_GOODIXMOC (device);
1259-
FpPrint *print = NULL;
1260-
1261-
g_autoptr(GVariant) data = NULL;
1262-
guint8 finger;
1263-
const guint8 *user_id;
1264-
gsize user_id_len = 0;
1265-
const guint8 *tid;
1266-
gsize tid_len = 0;
1267-
1268-
fpi_device_get_verify_data (device, &print);
1269-
1270-
g_object_get (print, "fpi-data", &data, NULL);
1271-
1272-
if (!parse_print_data (data, &finger, &tid, &tid_len, &user_id, &user_id_len))
1273-
{
1274-
fpi_device_verify_complete (device,
1275-
fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
1276-
return;
1277-
}
1278-
memcpy (&self->template_id, tid, tid_len);
12791318

12801319
self->task_ssm = fpi_ssm_new (device, fp_verify_sm_run_state,
12811320
FP_VERIFY_NUM_STATES);
@@ -1405,9 +1444,10 @@ fpi_device_goodixmoc_class_init (FpiDeviceGoodixMocClass *klass)
14051444
dev_class->open = gx_fp_init;
14061445
dev_class->close = gx_fp_exit;
14071446
dev_class->probe = gx_fp_probe;
1408-
dev_class->verify = gx_fp_verify;
14091447
dev_class->enroll = gx_fp_enroll;
14101448
dev_class->delete = gx_fp_template_delete;
14111449
dev_class->list = gx_fp_template_list;
14121450
dev_class->cancel = gx_fp_cancel;
1451+
dev_class->verify = gx_fp_verify_identify;
1452+
dev_class->identify = gx_fp_verify_identify;
14131453
}

0 commit comments

Comments
 (0)