elan: fix protocol error and calibration for ASUS 04f3:0c6e
Some Elan devices (notably 04f3:0c6e on ASUS laptops) do not implement the blocking behavior of pre_scan_cmd (0x40 0x3f). Instead of holding the USB response open until a finger is placed, they return immediately with a non-0x55 value when no finger is present. The existing driver treated this as a fatal protocol error. Fix: jump back to CAPTURE_WAIT_FINGER with a 50ms delay instead of failing, turning the driver into a polling loop that waits for 0x55 (finger present) before proceeding to capture. Additional tuning for 04f3:0c6e: - Increase ELAN_CALIBRATION_ATTEMPTS 10->30 and poll delay 50->100ms - Lower bz3_threshold 24->10 for single-press image matching - Lower ELAN_MIN_FRAMES 7->4 for short press/tap captures Tested on Rocky Linux 10.1 (ASUS laptop, FW 0x0161, sensor 150x52). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
9abb7a9334
47
README.md
Normal file
47
README.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# fprint-asus: libfprint patches for ASUS 04f3:0c6e fingerprint sensor
|
||||||
|
|
||||||
|
Patches for the Elan fingerprint sensor found in ASUS laptops (`04f3:0c6e`, FW 0x0161, 150x52 swipe sensor).
|
||||||
|
|
||||||
|
## Problem
|
||||||
|
|
||||||
|
The device does not implement the blocking behavior of `pre_scan_cmd` (command `0x40 0x3f`).
|
||||||
|
Instead of holding the USB response open until a finger is placed, it returns immediately with
|
||||||
|
a non-0x55 value when no finger is present. The upstream `elan` driver treats this as a fatal
|
||||||
|
protocol error (`FP_DEVICE_ERROR_PROTO`), causing every enrollment attempt to immediately fail
|
||||||
|
with `enroll-disconnected`.
|
||||||
|
|
||||||
|
## Patches applied to `libfprint/drivers/elan.c` and `elan.h`
|
||||||
|
|
||||||
|
| Change | Reason |
|
||||||
|
|---|---|
|
||||||
|
| `CAPTURE_READ_DATA`: retry instead of PROTO error | Device returns immediately with non-0x55 when no finger; retry until 0x55 |
|
||||||
|
| `ELAN_CALIBRATION_ATTEMPTS`: 10 → 30 | Give device more time to recalibrate between swipe stages |
|
||||||
|
| Calibration poll delay: 50ms → 100ms | Device needs ~100ms per calibration cycle |
|
||||||
|
| `bz3_threshold`: 24 → 10 | Accommodate smaller single-press images |
|
||||||
|
| `ELAN_MIN_FRAMES`: 7 → 4 | Allow short press/tap captures |
|
||||||
|
|
||||||
|
## Building and installing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Dependencies (Rocky/RHEL 10)
|
||||||
|
sudo dnf install git meson ninja-build gcc gcc-c++ glib2-devel libgusb-devel nss-devel pixman-devel gobject-introspection-devel
|
||||||
|
|
||||||
|
# Clone upstream libfprint and apply patches
|
||||||
|
git clone --depth=1 https://gitlab.freedesktop.org/libfprint/libfprint.git
|
||||||
|
cp libfprint/drivers/elan.c libfprint/drivers/elan.h libfprint/libfprint/drivers/
|
||||||
|
cd libfprint
|
||||||
|
meson setup _build --prefix=/usr --buildtype=release
|
||||||
|
ninja -C _build
|
||||||
|
sudo systemctl stop fprintd
|
||||||
|
sudo ninja -C _build install
|
||||||
|
sudo systemctl start fprintd
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
fprintd-enroll # enroll a finger (slow press/swipe)
|
||||||
|
fprintd-verify $USER # test verification
|
||||||
|
```
|
||||||
|
|
||||||
|
Tested on Rocky Linux 10.1 with ASUS laptop.
|
||||||
1013
libfprint/drivers/elan.c
Normal file
1013
libfprint/drivers/elan.c
Normal file
File diff suppressed because it is too large
Load Diff
235
libfprint/drivers/elan.h
Normal file
235
libfprint/drivers/elan.h
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
/*
|
||||||
|
* Elan driver for libfprint
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Igor Filatov <ia.filatov@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <glib.h>
|
||||||
|
|
||||||
|
#define ELAN_VEND_ID 0x04f3
|
||||||
|
|
||||||
|
/* a default device type */
|
||||||
|
#define ELAN_ALL_DEV 0
|
||||||
|
|
||||||
|
/* devices with quirks */
|
||||||
|
#define ELAN_0907 (1 << 0)
|
||||||
|
#define ELAN_0C03 (1 << 1)
|
||||||
|
#define ELAN_0C42 (1 << 2)
|
||||||
|
|
||||||
|
/* devices which don't require frame rotation before assembling */
|
||||||
|
#define ELAN_NOT_ROTATED ELAN_0C03
|
||||||
|
|
||||||
|
/* min FW version that supports calibration */
|
||||||
|
#define ELAN_MIN_CALIBRATION_FW 0x0138
|
||||||
|
|
||||||
|
/* max difference between background image mean and calibration mean
|
||||||
|
* (the response value of get_calib_mean_cmd)*/
|
||||||
|
#define ELAN_CALIBRATION_MAX_DELTA 500
|
||||||
|
|
||||||
|
/* times to retry reading calibration status during one session
|
||||||
|
* generally prevents calibration from looping indefinitely */
|
||||||
|
#define ELAN_CALIBRATION_ATTEMPTS 30
|
||||||
|
|
||||||
|
/* min and max frames in a capture */
|
||||||
|
#define ELAN_MIN_FRAMES 4
|
||||||
|
#define ELAN_MAX_FRAMES 30
|
||||||
|
|
||||||
|
/* crop frames to this height to improve stitching */
|
||||||
|
#define ELAN_MAX_FRAME_HEIGHT 50
|
||||||
|
|
||||||
|
/* number of frames to drop at the end of capture because frames captured
|
||||||
|
* while the finger is being lifted can be bad */
|
||||||
|
#define ELAN_SKIP_LAST_FRAMES 2
|
||||||
|
|
||||||
|
#define ELAN_CMD_LEN 0x2
|
||||||
|
#define ELAN_EP_CMD_OUT (0x1 | FPI_USB_ENDPOINT_OUT)
|
||||||
|
#define ELAN_EP_CMD_IN (0x3 | FPI_USB_ENDPOINT_IN)
|
||||||
|
#define ELAN_EP_IMG_IN (0x2 | FPI_USB_ENDPOINT_IN)
|
||||||
|
|
||||||
|
/* used as response length to tell the driver to skip reading response */
|
||||||
|
#define ELAN_CMD_SKIP_READ 0
|
||||||
|
|
||||||
|
/* usual command timeout and timeout for when we need to check if the finger is
|
||||||
|
* still on the device */
|
||||||
|
#define ELAN_CMD_TIMEOUT 10000
|
||||||
|
#define ELAN_FINGER_TIMEOUT 200
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (FpiDeviceElan, fpi_device_elan, FPI, DEVICE_ELAN,
|
||||||
|
FpImageDevice);
|
||||||
|
|
||||||
|
struct elan_cmd
|
||||||
|
{
|
||||||
|
unsigned char cmd[ELAN_CMD_LEN];
|
||||||
|
int response_len;
|
||||||
|
int response_in;
|
||||||
|
unsigned short devices;
|
||||||
|
gboolean never_cancel;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct elan_cmd get_sensor_dim_cmd = {
|
||||||
|
.cmd = {0x00, 0x0c},
|
||||||
|
.response_len = 0x4,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct elan_cmd get_fw_ver_cmd = {
|
||||||
|
.cmd = {0x40, 0x19},
|
||||||
|
.response_len = 0x2,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* unknown, returns 0x0 0x1 on 0907 */
|
||||||
|
static const struct elan_cmd activate_cmd_1 = {
|
||||||
|
.cmd = {0x40, 0x2a},
|
||||||
|
.response_len = 0x2,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_0907,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct elan_cmd get_image_cmd = {
|
||||||
|
.cmd = {0x00, 0x09},
|
||||||
|
/* raw frame sizes are calculated from image dimensions reported by the
|
||||||
|
* device */
|
||||||
|
.response_len = -1,
|
||||||
|
.response_in = ELAN_EP_IMG_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct elan_cmd read_sensor_status_cmd = {
|
||||||
|
.cmd = {0x40, 0x13},
|
||||||
|
.response_len = 0x1,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct elan_cmd get_calib_status_cmd = {
|
||||||
|
.cmd = {0x40, 0x23},
|
||||||
|
.response_len = 0x1,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct elan_cmd get_calib_mean_cmd = {
|
||||||
|
.cmd = {0x40, 0x24},
|
||||||
|
.response_len = 0x2,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct elan_cmd led_on_cmd = {
|
||||||
|
.cmd = {0x40, 0x31},
|
||||||
|
.response_len = ELAN_CMD_SKIP_READ,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* wait for finger
|
||||||
|
* subsequent read will not complete until finger is placed on the reader */
|
||||||
|
static const struct elan_cmd pre_scan_cmd = {
|
||||||
|
.cmd = {0x40, 0x3f},
|
||||||
|
.response_len = 0x1,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* led off, stop waiting for finger */
|
||||||
|
static const struct elan_cmd stop_cmd = {
|
||||||
|
.cmd = {0x00, 0x0b},
|
||||||
|
.response_len = ELAN_CMD_SKIP_READ,
|
||||||
|
.response_in = ELAN_EP_CMD_IN,
|
||||||
|
.devices = ELAN_ALL_DEV,
|
||||||
|
.never_cancel = TRUE,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const FpIdEntry elan_id_table[] = {
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0903, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0907, .driver_data = ELAN_0907},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c01, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c02, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c03, .driver_data = ELAN_0C03},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c04, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c05, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c06, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c07, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c08, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c09, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c0a, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c0b, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c0c, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c0d, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c0e, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c0f, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c10, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c11, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c12, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c13, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c14, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c15, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c16, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c17, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c18, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c19, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c1a, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c1b, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c1c, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c1d, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c1e, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c1f, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c20, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c21, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c22, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c23, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c24, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c25, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c26, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c27, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c28, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c29, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c2a, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c2b, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c2c, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c2d, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c2e, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c2f, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c30, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c31, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c32, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c33, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c3d, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c42, .driver_data = ELAN_0C42},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c4b, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c4d, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c4f, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c63, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c6e, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = ELAN_VEND_ID, .pid = 0x0c58, .driver_data = ELAN_ALL_DEV},
|
||||||
|
{.vid = 0, .pid = 0, .driver_data = 0},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void elan_cmd_done (FpiSsm *ssm);
|
||||||
|
static void elan_cmd_read (FpiSsm *ssm,
|
||||||
|
FpDevice *dev);
|
||||||
|
|
||||||
|
static void elan_calibrate (FpiDeviceElan *self);
|
||||||
|
static void elan_capture (FpiDeviceElan *self);
|
||||||
|
|
||||||
|
static void dev_change_state (FpImageDevice *dev,
|
||||||
|
FpiImageDeviceState state);
|
||||||
Loading…
x
Reference in New Issue
Block a user