mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2025-11-15 07:38:12 +00:00
egismoc: Use FpiByteWriter to generate the get check command
This commit is contained in:
@@ -906,8 +906,9 @@ egismoc_get_check_cmd (FpDevice *device,
|
|||||||
{
|
{
|
||||||
fp_dbg ("Get check command");
|
fp_dbg ("Get check command");
|
||||||
FpiDeviceEgisMoc *self = FPI_DEVICE_EGISMOC (device);
|
FpiDeviceEgisMoc *self = FPI_DEVICE_EGISMOC (device);
|
||||||
|
g_auto(FpiByteWriter) writer = {0};
|
||||||
g_autofree guchar *result = NULL;
|
g_autofree guchar *result = NULL;
|
||||||
gsize pos = 0;
|
gboolean written = TRUE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The final command body should contain:
|
* The final command body should contain:
|
||||||
@@ -944,10 +945,10 @@ egismoc_get_check_cmd (FpDevice *device,
|
|||||||
+ cmd_check_suffix_len;
|
+ cmd_check_suffix_len;
|
||||||
|
|
||||||
/* pre-fill entire payload with 00s */
|
/* pre-fill entire payload with 00s */
|
||||||
result = g_new0 (guchar, total_length);
|
fpi_byte_writer_init_with_size (&writer, total_length, TRUE);
|
||||||
|
|
||||||
/* start with 00 00 (just move starting offset up by 2) */
|
/* start with 00 00 (just move starting offset up by 2) */
|
||||||
pos = 2;
|
written &= fpi_byte_writer_set_pos (&writer, 2);
|
||||||
|
|
||||||
/* Size Counter bytes */
|
/* Size Counter bytes */
|
||||||
/* "easiest" way to handle 2-bytes size for counter is to hard-code logic for
|
/* "easiest" way to handle 2-bytes size for counter is to hard-code logic for
|
||||||
@@ -956,69 +957,63 @@ egismoc_get_check_cmd (FpDevice *device,
|
|||||||
* (assumed max is 10) */
|
* (assumed max is 10) */
|
||||||
if (self->enrolled_ids->len > 6)
|
if (self->enrolled_ids->len > 6)
|
||||||
{
|
{
|
||||||
memset (result + pos, 0x01, sizeof (guchar));
|
written &= fpi_byte_writer_put_uint8 (&writer, 0x01);
|
||||||
pos += sizeof (guchar);
|
written &= fpi_byte_writer_put_uint8 (&writer,
|
||||||
memset (result + pos, ((self->enrolled_ids->len - 7) * 0x20) + 0x09,
|
((self->enrolled_ids->len - 7) * 0x20)
|
||||||
sizeof (guchar));
|
+ 0x09);
|
||||||
pos += sizeof (guchar);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* first byte is 0x00, just skip it */
|
/* first byte is 0x00, just skip it */
|
||||||
pos += sizeof (guchar);
|
written &= fpi_byte_writer_change_pos (&writer, 1);
|
||||||
memset (result + pos, ((self->enrolled_ids->len + 1) * 0x20) + 0x09,
|
written &= fpi_byte_writer_put_uint8 (&writer,
|
||||||
sizeof (guchar));
|
((self->enrolled_ids->len + 1) * 0x20) +
|
||||||
pos += sizeof (guchar);
|
0x09);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* command prefix */
|
/* command prefix */
|
||||||
if (fpi_device_get_driver_data (device) & EGISMOC_DRIVER_CHECK_PREFIX_TYPE2)
|
if (fpi_device_get_driver_data (device) & EGISMOC_DRIVER_CHECK_PREFIX_TYPE2)
|
||||||
{
|
written &= fpi_byte_writer_put_data (&writer, cmd_check_prefix_type2,
|
||||||
memcpy (result + pos, cmd_check_prefix_type2, cmd_check_prefix_type2_len);
|
cmd_check_prefix_type2_len);
|
||||||
pos += cmd_check_prefix_type2_len;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
written &= fpi_byte_writer_put_data (&writer, cmd_check_prefix_type1,
|
||||||
memcpy (result + pos, cmd_check_prefix_type1, cmd_check_prefix_type1_len);
|
cmd_check_prefix_type1_len);
|
||||||
pos += cmd_check_prefix_type1_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 2-bytes size logic for counter again */
|
/* 2-bytes size logic for counter again */
|
||||||
if (self->enrolled_ids->len > 6)
|
if (self->enrolled_ids->len > 6)
|
||||||
{
|
{
|
||||||
memset (result + pos, 0x01, sizeof (guchar));
|
written &= fpi_byte_writer_put_uint8 (&writer, 0x01);
|
||||||
pos += sizeof (guchar);
|
written &= fpi_byte_writer_put_uint8 (&writer,
|
||||||
memset (result + pos, (self->enrolled_ids->len - 7) * 0x20, sizeof (guchar));
|
(self->enrolled_ids->len - 7) * 0x20);
|
||||||
pos += sizeof (guchar);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* first byte is 0x00, just skip it */
|
/* first byte is 0x00, just skip it */
|
||||||
pos += sizeof (guchar);
|
written &= fpi_byte_writer_change_pos (&writer, 1);
|
||||||
memset (result + pos, (self->enrolled_ids->len + 1) * 0x20, sizeof (guchar));
|
written &= fpi_byte_writer_put_uint8 (&writer,
|
||||||
pos += sizeof (guchar);
|
(self->enrolled_ids->len + 1) * 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add 00s "separator" to offset position */
|
/* add 00s "separator" to offset position */
|
||||||
pos += EGISMOC_CMD_CHECK_SEPARATOR_LENGTH;
|
written &= fpi_byte_writer_change_pos (&writer,
|
||||||
|
EGISMOC_CMD_CHECK_SEPARATOR_LENGTH);
|
||||||
|
|
||||||
/* append all currently registered 32-byte fingerprint IDs */
|
for (guint i = 0; i < self->enrolled_ids->len && written; i++)
|
||||||
const gsize print_id_length = sizeof (guchar) * EGISMOC_FINGERPRINT_DATA_SIZE;
|
|
||||||
|
|
||||||
for (guint i = 0; i < self->enrolled_ids->len; i++)
|
|
||||||
{
|
{
|
||||||
gchar *device_print_id = g_ptr_array_index (self->enrolled_ids, i);
|
written &= fpi_byte_writer_put_data (&writer,
|
||||||
memcpy (result + pos + (print_id_length * i), device_print_id, print_id_length);
|
g_ptr_array_index (self->enrolled_ids, i),
|
||||||
|
EGISMOC_FINGERPRINT_DATA_SIZE);
|
||||||
}
|
}
|
||||||
pos += body_length;
|
|
||||||
|
|
||||||
/* command suffix */
|
/* command suffix */
|
||||||
memcpy (result + pos, cmd_check_suffix, cmd_check_suffix_len);
|
written &= fpi_byte_writer_put_data (&writer, cmd_check_suffix,
|
||||||
|
cmd_check_suffix_len);
|
||||||
|
g_assert (written);
|
||||||
|
|
||||||
if (length_out)
|
if (length_out)
|
||||||
*length_out = total_length;
|
*length_out = total_length;
|
||||||
|
|
||||||
return g_steal_pointer (&result);
|
return fpi_byte_writer_reset_and_get_data (&writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user