diff --git a/README b/README index d3353bbf..a4afb3c3 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -This is a experimental libfprint driver implementation for Goodix drivers. +This is an experimental libfprint driver implementation for Goodix drivers. Currently in the works: - 27c6x5110 (80x64 resolution) diff --git a/libfprint/drivers/goodix5110.c b/libfprint/drivers/goodix5110.c deleted file mode 100644 index 8a3e565d..00000000 --- a/libfprint/drivers/goodix5110.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Goodix 5110 driver for libfprint - * - * Copyright (C) 2021 Alexander Meiler - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#define FP_COMPONENT "goodix5110" - -#include "drivers_api.h" -#include "goodix5110.h" - -struct _FpiDeviceGoodix -{ - FpImageDevice parent; - - /* device config */ - // unsigned short dev_type; - char *fw_ver; - // void (*process_frame) (unsigned short *raw_frame, - // GSList ** frames); - /* end device config */ - - /* commands */ - const struct goodix_cmd *cmd; - int cmd_timeout; - /* end commands */ - - /* state */ - gboolean active; - gboolean deactivating; - unsigned char *last_read; - // unsigned char calib_atts_left; - // unsigned char calib_status; - unsigned short *background; - // unsigned char frame_width; - // unsigned char frame_height; - // unsigned char raw_frame_height; - // int num_frames; - // GSList *frames; - /* end state */ -}; -G_DEFINE_TYPE (FpiDeviceGoodix, fpi_device_goodix, FP_TYPE_IMAGE_DEVICE); - -static void -goodix_cmd_done (FpiSsm *ssm) -{ - G_DEBUG_HERE (); - fpi_ssm_next_state (ssm); -} - -static void -goodix_cmd_read (FpiSsm *ssm, FpDevice *dev, int response_len) -{ - FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - FpiUsbTransfer *transfer; - GCancellable *cancellable = NULL; - //int response_len = self->cmd->response_len; - - G_DEBUG_HERE (); - - if (self->cmd->response_len == GOODIX_CMD_SKIP_READ) - { - fp_dbg ("skipping read, not expecting anything"); - goodix_cmd_done (ssm); - return; - } - - g_clear_pointer (&self->last_read, g_free); - - transfer = fpi_usb_transfer_new (dev); - transfer->ssm = ssm; - transfer->short_is_error = TRUE; - - fpi_usb_transfer_fill_bulk (transfer, - GOODIX_EP_CMD_IN, - response_len); - - fpi_usb_transfer_submit (transfer, self->cmd_timeout, cancellable, goodix_cmd_cb, NULL); -} - -static void -goodix_cmd_cb (FpiUsbTransfer *transfer, FpDevice *dev, - gpointer user_data, GError *error) -{ - FpiSsm *ssm = transfer->ssm; - FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - - G_DEBUG_HERE (); - - if (error) - { - /* XXX: In the cancellation case we used to not - * mark the SSM as failed?! */ - fpi_ssm_mark_failed (transfer->ssm, error); - return; - } - - /* XXX: We used to reset the device in error cases! */ - if (transfer->endpoint & FPI_USB_ENDPOINT_IN) - { - /* just finished receiving */ - self->last_read = g_memdup (transfer->buffer, transfer->actual_length); - //fp_dbg("%lu", transfer->actual_length); - if(self->cmd->cmd == read_fw.cmd) - { - if(transfer->actual_length == self->cmd->response_len) - { - // We got ACK, now wait for the firmware string packet - G_DEBUG_HERE (); - goodix_cmd_read (ssm, dev, self->cmd->response_len_2); - } - else - { - // Reading the firmware version - self->fw_ver = g_memdup (&self->last_read[7], self->cmd->response_len_2); - G_DEBUG_HERE (); - goodix_cmd_done (ssm); - } - } - else - { - goodix_cmd_done (ssm); - } - } - else - { - /* just finished sending */ - G_DEBUG_HERE (); - goodix_cmd_read (ssm, dev, self->cmd->response_len); - } -} - -static void -goodix_run_cmd (FpiSsm *ssm, - FpDevice *dev, - const struct goodix_cmd *cmd, - int cmd_timeout) -{ - FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - FpiUsbTransfer *transfer; - GCancellable *cancellable = NULL; - - self->cmd = cmd; - - transfer = fpi_usb_transfer_new (dev); - transfer->ssm = ssm; - transfer->short_is_error = TRUE; - - fpi_usb_transfer_fill_bulk_full (transfer, - GOODIX_EP_CMD_OUT, - (guint8 *) cmd->cmd, - GOODIX_CMD_LEN, - NULL); - - fpi_usb_transfer_submit (transfer, - cmd_timeout, - cancellable, - goodix_cmd_cb, - NULL); -} - -/* ------------------------------------------------------------------------------- */ - -/* ---- ACTIVE SECTION START ---- */ - -enum activate_states { - ACTIVATE_NOP1, - ACTIVATE_ENABLE_CHIP, - ACTIVATE_NOP2, - ACTIVATE_GET_FW_VER, - ACTIVATE_VERIFY_FW_VER, - ACTIVATE_NUM_STATES -}; - -static void -activate_run_state (FpiSsm *ssm, FpDevice *dev) -{ - FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - - G_DEBUG_HERE (); - - switch (fpi_ssm_get_cur_state (ssm)) - { - // NOP seems to do nothing, but the Windows driver does it in places too - case ACTIVATE_NOP1: - case ACTIVATE_NOP2: - goodix_run_cmd(ssm, dev, &nop, GOODIX_CMD_TIMEOUT); - break; - - case ACTIVATE_ENABLE_CHIP: - goodix_run_cmd(ssm, dev, &enable_chip, GOODIX_CMD_TIMEOUT); - break; - - case ACTIVATE_GET_FW_VER: - goodix_run_cmd(ssm, dev, &read_fw, GOODIX_CMD_TIMEOUT); - break; - - case ACTIVATE_VERIFY_FW_VER: - if(strcmp(self->fw_ver, GOODIX_FIRMWARE_VERSION_SUPPORTED) == 0) - { - // The firmware version supports the 0xF2 command to directly read from the MCU SRAM - fpi_ssm_mark_completed (ssm); - } - else - { - // The firmware version is unsupported - fpi_ssm_mark_failed (ssm, fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL, "Unsupported firmware!")); - } - } -} - -static void -activate_complete (FpiSsm *ssm, FpDevice *dev, GError *error) -{ - FpImageDevice *idev = FP_IMAGE_DEVICE (dev); - - G_DEBUG_HERE (); - - fpi_image_device_activate_complete (idev, error); - -} - -static void -goodix_activate (FpImageDevice *dev) -{ - FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - - G_DEBUG_HERE (); - goodix_dev_reset_state (self); - - FpiSsm *ssm = - fpi_ssm_new (FP_DEVICE (dev), activate_run_state, - ACTIVATE_NUM_STATES); - - fpi_ssm_start (ssm, activate_complete); -} - -/* ---- ACTIVE SECTION END ---- */ - -/* ------------------------------------------------------------------------------- */ - -/* ---- DEV SECTION START ---- */ - -static void -dev_init (FpImageDevice *dev) -{ - GError *error = NULL; - // FpiDeviceGoodix *self; - - G_DEBUG_HERE (); - - if (!g_usb_device_claim_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), 0, 0, &error)) - { - fpi_image_device_open_complete (dev, error); - return; - } - - // self = FPI_DEVICE_GOODIX (dev); - - fpi_image_device_open_complete (dev, NULL); -} - -static void -goodix_dev_reset_state (FpiDeviceGoodix *goodixdev) -{ - G_DEBUG_HERE (); - - goodixdev->cmd = NULL; - goodixdev->cmd_timeout = GOODIX_CMD_TIMEOUT; - - g_free (goodixdev->last_read); - goodixdev->last_read = NULL; -} - -static void -dev_deinit (FpImageDevice *dev) -{ - GError *error = NULL; - FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - - G_DEBUG_HERE (); - - goodix_dev_reset_state (self); - g_free (self->background); - g_usb_device_release_interface (fpi_device_get_usb_device (FP_DEVICE (dev)), - 0, 0, &error); - fpi_image_device_close_complete (dev, error); -} - -static void -dev_activate (FpImageDevice *dev) -{ - G_DEBUG_HERE (); - goodix_activate (dev); -} - -static void -dev_change_state (FpImageDevice *dev, FpiImageDeviceState state) -{ - //FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - - G_DEBUG_HERE (); -} - -static void -dev_deactivate (FpImageDevice *dev) -{ - FpiDeviceGoodix *self = FPI_DEVICE_GOODIX (dev); - - G_DEBUG_HERE (); - - if (!self->active) - /* The device is inactive already, complete the operation immediately. */ - fpi_image_device_deactivate_complete (dev, NULL); - else - /* The device is not yet inactive, flag that we are deactivating (and - * need to signal back deactivation). - * Note that any running capture will be cancelled already if needed. */ - self->deactivating = TRUE; -} - -/* ---- DEV SECTION END ---- */ - -/* ------------------------------------------------------------------------------- */ - -/* ---- FPI SECTION START ---- */ - -static void -fpi_device_goodix_init (FpiDeviceGoodix *self) -{ - // nothing to be done here, move along -} - -static void -fpi_device_goodix_class_init (FpiDeviceGoodixClass *class) -{ - FpDeviceClass *dev_class = FP_DEVICE_CLASS (class); - FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS (class); - - dev_class->id = "goodix"; - dev_class->full_name = "Goodix 5110 Fingerprint Sensor"; - dev_class->type = FP_DEVICE_TYPE_USB; - dev_class->id_table = goodix_id_table; - dev_class->scan_type = FP_SCAN_TYPE_SWIPE; - - img_class->img_open = dev_init; - img_class->img_close = dev_deinit; - img_class->activate = dev_activate; - img_class->deactivate = dev_deactivate; - img_class->change_state = dev_change_state; - - // ToDo - img_class->bz3_threshold = 24; -} - -/* ---- FPI SECTION END ---- */ \ No newline at end of file diff --git a/libfprint/drivers/goodix5110.h b/libfprint/drivers/goodix5110.h deleted file mode 100644 index 1c6409f3..00000000 --- a/libfprint/drivers/goodix5110.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Goodix 5110 driver for libfprint - * - * Copyright (C) 2021 Alexander Meiler - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - - #pragma once - -#include -#include - -#define GOODIX_VEND_ID 0x27c6 - -#define GOODIX_CMD_LEN 64 -#define GOODIX_EP_CMD_OUT 0x1 -#define GOODIX_EP_CMD_IN 0x81 - -// Needed for commands which don't send an answer back (currently known only NOP) -#define GOODIX_CMD_SKIP_READ -1 - -// 10 seconds USB read timeout -#define GOODIX_CMD_TIMEOUT 10000 - -#define GOODIX_FIRMWARE_VERSION_SUPPORTED "GF_ST411SEC_APP_12109" - -struct goodix_cmd -{ - uint8_t cmd[64]; - int response_len; - int response_len_2; -}; - -static const struct goodix_cmd nop = { - .cmd = {0xA0, 0x08, 0x00, 0xA8, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5}, - .response_len = GOODIX_CMD_SKIP_READ, -}; - -static const struct goodix_cmd enable_chip = { - .cmd = {0xA0, 0X06, 0x00, 0xA6, 0x96, 0x03, 0x00, 0x01, 0x00, 0x10}, - .response_len = 10, -}; - -static const struct goodix_cmd read_fw = { - .cmd = {0xA0, 0x06, 0x00, 0xA6, 0xA8, 0x03, 0x00, 0x00, 0x00, 0xFF}, - .response_len = 10, - .response_len_2 = 30, -}; - -G_DECLARE_FINAL_TYPE (FpiDeviceGoodix, fpi_device_goodix, FPI, DEVICE_GOODIX, - FpImageDevice); - -// VID=0 PID=0 is needed for termination -static const FpIdEntry goodix_id_table[] = { - {.vid = GOODIX_VEND_ID, .pid = 0x5110, .driver_data = 0}, - {.vid = 0, .pid = 0, .driver_data = 0}, -}; - -static void goodix_dev_reset_state (FpiDeviceGoodix *goodixdev); -static void goodix_cmd_cb (FpiUsbTransfer *transfer, FpDevice *dev, gpointer user_data, GError *error); \ No newline at end of file diff --git a/libfprint/meson.build b/libfprint/meson.build index cf5cb2af..42770e37 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -186,9 +186,9 @@ foreach driver: drivers 'drivers/nb1010.c', ] endif - if driver == 'goodix' + if driver == 'goodixtls' drivers_sources += [ - 'drivers/goodix5110.c', + 'drivers/goodixtls/goodix.c', ] endif endforeach @@ -240,6 +240,7 @@ deps = [ imaging_dep, mathlib_dep, nss_dep, + openssl_dep, ] # These are empty and only exist so that the include directories are created diff --git a/meson.build b/meson.build index bbd157a2..8844b83e 100644 --- a/meson.build +++ b/meson.build @@ -83,6 +83,7 @@ gio_dep = dependency('gio-unix-2.0', version: '>=' + glib_min_version) gobject_dep = dependency('gobject-2.0', version: '>=' + glib_min_version) gusb_dep = dependency('gusb', version: '>= 0.2.0') mathlib_dep = cc.find_library('m', required: false) +openssl_dep = dependency('', required: false) # The following dependencies are only used for tests cairo_dep = dependency('cairo', required: false) @@ -122,7 +123,7 @@ default_drivers = [ 'upekts', 'goodixmoc', 'nb1010', - 'goodix' + 'goodixtls' ] # FIXME: All the drivers should be fixed by adjusting the byte order. @@ -176,6 +177,12 @@ foreach driver: drivers endif libfprint_conf.set10('HAVE_PIXMAN', true) + endif + if driver == 'goodixtls' + openssl_dep = dependency('openssl', required: false) + if not openssl_dep.found() + error('OpenSSL is required for the Goodix TLS driver') + endif endif if udev_drivers.contains(driver) gudev_dep = dependency('gudev-1.0', required: false)