libfprint/libfprint/drivers/validity/validity.h
Leonardo Francisco 3c17c1a40d validity: Add capture program infrastructure (Iteration 5)
Implement the capture command building infrastructure ported from
python-validity's sensor.py and timeslot.py. This provides all the
algorithms needed to construct sensor capture commands for calibration,
enrollment, and identification modes.

New components:
- TLV chunk parsing (split/merge) for capture programs
- Timeslot DSP instruction decoder (16 opcodes, 1-3 bytes each)
- Timeslot table patching (Call repeat multiplication, factory cal)
- Line Update Type 1 algorithm for 0xb5-class sensors
- build_cmd_02(): main capture command builder
- Factory bits parsing (subtag 3 cal values, subtag 7 cal data)
- Frame averaging with multi-line deinterlacing
- Calibration data processing (scale/accumulate/clip)
- Clean slate format with SHA256 verification
- Bitpack compression for factory calibration values
- Finger ID mapping (FpFinger <-> VCSFW subtype 1-10)
- LED control commands (glow_start_scan, glow_end_scan)
- CaptureProg lookup table for firmware 6.x type-1 devices
- OPEN_CAPTURE_SETUP state in the open SSM

27 unit tests covering all components.
Full test suite: 36 OK, 0 Fail, 2 Skipped.
2026-04-10 22:18:43 +00:00

122 lines
3.4 KiB
C

/*
* Validity/Synaptics VCSFW fingerprint sensor driver
*
* Copyright (C) 2024 libfprint contributors
*
* 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 "fpi-device.h"
#include "fpi-ssm.h"
#include "validity_capture.h"
#include "validity_sensor.h"
#include "validity_tls.h"
/* USB Endpoint addresses */
#define VALIDITY_EP_CMD_OUT 0x01
#define VALIDITY_EP_CMD_IN 0x81
#define VALIDITY_EP_DATA_IN 0x82
#define VALIDITY_EP_INT_IN 0x83
/* USB transfer parameters */
#define VALIDITY_USB_TIMEOUT 15000
#define VALIDITY_USB_INT_TIMEOUT 100
#define VALIDITY_MAX_TRANSFER_LEN (100 * 1024)
#define VALIDITY_USB_INT_DATA_SIZE 1024
#define VALIDITY_USB_SEND_HEADER_LEN 1
/* Number of enroll stages */
#define VALIDITY_ENROLL_STAGES 8
/* Interrupt response bits */
#define VALIDITY_INT_FINGER_DOWN 0x02
#define VALIDITY_INT_SCAN_COMPLETE 0x04
typedef enum {
VALIDITY_DEV_90 = 0, /* 138a:0090 */
VALIDITY_DEV_97, /* 138a:0097 */
VALIDITY_DEV_9A, /* 06cb:009a */
VALIDITY_DEV_9D, /* 138a:009d */
} ValidityDeviceType;
/* Firmware version info from GET_VERSION (cmd 0x01) */
typedef struct
{
guint32 build_time;
guint32 build_num;
guint8 version_major;
guint8 version_minor;
guint8 target;
guint8 product;
guint8 silicon_rev;
guint8 formal_release;
guint8 platform;
guint8 patch;
guint8 serial_number[6];
guint16 security;
guint8 iface;
guint8 device_type;
} ValidityVersionInfo;
/* Open SSM states */
typedef enum {
VALIDITY_OPEN_CLAIM_INTERFACE = 0,
VALIDITY_OPEN_SEND_INIT,
VALIDITY_OPEN_NUM_STATES,
} ValidityOpenState;
/* Close SSM states */
typedef enum {
VALIDITY_CLOSE_RELEASE_INTERFACE = 0,
VALIDITY_CLOSE_NUM_STATES,
} ValidityCloseState;
#define FPI_TYPE_DEVICE_VALIDITY (fpi_device_validity_get_type ())
G_DECLARE_FINAL_TYPE (FpiDeviceValidity, fpi_device_validity,
FPI, DEVICE_VALIDITY, FpDevice)
struct _FpiDeviceValidity
{
FpDevice parent;
ValidityDeviceType dev_type;
ValidityVersionInfo version_info;
GCancellable *interrupt_cancellable;
/* TLS session state */
ValidityTlsState tls;
/* Sensor identification and HAL state (post-TLS) */
ValiditySensorState sensor;
/* Capture program infrastructure and calibration state */
ValidityCaptureState capture;
/* Firmware extension status */
gboolean fwext_loaded;
/* Command SSM: manages the send-cmd/recv-response cycle */
FpiSsm *cmd_ssm;
/* Open SSM: back-pointer for non-subsm child SSMs */
FpiSsm *open_ssm;
/* Pending response data stashed for higher-level SSM consumption */
guint16 cmd_response_status;
guint8 *cmd_response_data;
gsize cmd_response_len;
};