~registry/libfprint/master

« back to all changes in this revision

Viewing changes to libfprint/drivers/goodixmoc/goodix.c

  • Committer: Benjamin Berg
  • Author(s): boger.wang
  • Date: 2020-09-14 09:55:55 UTC
  • Revision ID: git-v1:f67f61c63816d67fd07b77ba37a0da0e5b1f5763
goodixmoc: Add identify function

this device support verify and identify both, actually call the same
interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
  SynCmdMsgCallback callback;
73
73
} CommandData;
74
74
 
 
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);
75
81
/******************************************************************************
76
82
 *
77
83
 *  fp_cmd_xxx Function
340
346
}
341
347
 
342
348
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)
346
352
{
347
353
  FpDevice *device = FP_DEVICE (self);
 
354
  FpPrint *print = NULL;
 
355
  GPtrArray *templates = NULL;
 
356
  gint cnt = 0;
 
357
  gboolean find = false;
348
358
 
349
359
  if (error)
350
360
    {
351
361
      fpi_ssm_mark_failed (self->task_ssm, error);
352
362
      return;
353
363
    }
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)
359
 
    {
360
 
      fpi_device_verify_report (device, FPI_MATCH_FAIL, NULL, error);
361
 
    }
362
 
  else
363
 
    {
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);
 
364
  if (resp->verify.match)
 
365
    {
 
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
        }
 
409
    }
 
410
 
 
411
  if (!find)
 
412
    {
 
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);
367
417
    }
368
418
 
369
419
  fpi_ssm_mark_completed (self->task_ssm);
375
425
{
376
426
  FpiDeviceGoodixMoc *self = FPI_DEVICE_GOODIXMOC (device);
377
427
  guint8 param[3] = { 0 };
 
428
  guint8 nonce[TEMPLATE_ID_SIZE] = { 0 };
378
429
 
379
430
  param[0] = 0x01;
380
431
  param[1] = self->sensorcfg->config[10];
393
444
    case FP_VERIFY_IDENTIFY:
394
445
      goodix_sensor_cmd (self, MOC_CMD0_IDENTIFY, MOC_CMD1_DEFAULT,
395
446
                         false,
396
 
                         (const guint8 *) &self->template_id,
 
447
                         (const guint8 *) nonce,
397
448
                         TEMPLATE_ID_SIZE,
398
 
                         fp_verify_identify_cb);
 
449
                         fp_verify_cb);
399
450
      break;
400
451
    }
401
452
 
409
460
  fp_info ("Verify complete!");
410
461
 
411
462
  if (error && error->domain == FP_DEVICE_RETRY)
412
 
    fpi_device_verify_report (dev, FPI_MATCH_ERROR, NULL, error);
413
 
 
414
 
  fpi_device_verify_complete (dev, 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);
 
472
 
 
473
  else
 
474
    fpi_device_identify_complete (dev, error);
415
475
 
416
476
  self->task_ssm = NULL;
417
477
}
1252
1312
 
1253
1313
 
1254
1314
static void
1255
 
gx_fp_verify (FpDevice *device)
 
1315
gx_fp_verify_identify (FpDevice *device)
1256
1316
{
1257
 
 
1258
1317
  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);
1279
1318
 
1280
1319
  self->task_ssm = fpi_ssm_new (device, fp_verify_sm_run_state,
1281
1320
                                FP_VERIFY_NUM_STATES);
1405
1444
  dev_class->open   = gx_fp_init;
1406
1445
  dev_class->close  = gx_fp_exit;
1407
1446
  dev_class->probe  = gx_fp_probe;
1408
 
  dev_class->verify = gx_fp_verify;
1409
1447
  dev_class->enroll = gx_fp_enroll;
1410
1448
  dev_class->delete = gx_fp_template_delete;
1411
1449
  dev_class->list   = gx_fp_template_list;
1412
1450
  dev_class->cancel = gx_fp_cancel;
 
1451
  dev_class->verify   = gx_fp_verify_identify;
 
1452
  dev_class->identify = gx_fp_verify_identify;
1413
1453
}