From d5f7f4dfaa0588bff2e899e8b91d519f2a7e1ad1 Mon Sep 17 00:00:00 2001 From: "boger.wang" Date: Fri, 11 Sep 2020 22:36:52 +0800 Subject: [PATCH] goodixmoc: Prevent incorrect firmware type running only firmware type:APP can function well, if device flash in a factory or test firmware, report a error tips user update firmware by fwupd --- libfprint/drivers/goodixmoc/goodix.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libfprint/drivers/goodixmoc/goodix.c b/libfprint/drivers/goodixmoc/goodix.c index 1eed70e..dfdd2fd 100644 --- a/libfprint/drivers/goodixmoc/goodix.c +++ b/libfprint/drivers/goodixmoc/goodix.c @@ -879,7 +879,8 @@ fp_init_version_cb (FpiDeviceGoodixMoc *self, gxfp_cmd_response_t *resp, GError *error) { - char nullstring[GX_VERSION_LEN + 1] = { 0 }; + g_autofree gchar *fw_type = NULL; + g_autofree gchar *fw_version = NULL; if (error) { @@ -888,16 +889,20 @@ fp_init_version_cb (FpiDeviceGoodixMoc *self, } G_STATIC_ASSERT (sizeof (resp->version_info.fwtype) == 8); - G_STATIC_ASSERT (sizeof (resp->version_info.algversion) == 8); G_STATIC_ASSERT (sizeof (resp->version_info.fwversion) == 8); - memcpy (nullstring, resp->version_info.fwtype, sizeof (resp->version_info.fwtype)); - fp_info ("Firmware type: %s", nullstring); - memcpy (nullstring, resp->version_info.algversion, sizeof (resp->version_info.algversion)); - fp_info ("Algversion version: %s", nullstring); - memcpy (nullstring, resp->version_info.fwversion, sizeof (resp->version_info.fwversion)); - fp_info ("Firmware version: %s", nullstring); + fw_type = g_strndup ((const char *) resp->version_info.fwtype, sizeof (resp->version_info.fwtype)); + fp_info ("Firmware type: %s", fw_type); + if (g_strcmp0 (fw_type, "APP") != 0) + { + fpi_ssm_mark_failed (self->task_ssm, + fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED, + "Please update firmware using fwupd")); + return; + } + fw_version = g_strndup ((const char *) resp->version_info.fwversion, sizeof (resp->version_info.fwversion)); + fp_info ("Firmware version: %s", fw_version); fpi_ssm_next_state (self->task_ssm); }