cleanup todos

renamed frame to template
for unfied naming

Added myself to copyright

readded checking

Revert "readded checking"

This reverts commit 1c0b88ff3311171ddae1fd095c499f320dcca697.

clearing context after use

removed some sleeps

saving max out size and max template

tests

Revert "tests"

This reverts commit 94cf2a5d804eac5cfb2fc97d91c0d0a6770b720b.

fixed reference count error

check for successful upload

split ssm into multiple functions

improved code

removed chrfpmoc from tests since tests are broken
This commit is contained in:
Felix 2024-12-24 16:21:02 +01:00 committed by Xelef2000
parent cb52c445a8
commit 24140f40fb
8 changed files with 886 additions and 806 deletions

14
flake.lock generated
View file

@ -5,11 +5,11 @@
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1730504689,
"narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=",
"lastModified": 1733312601,
"narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "506278e768c2a08bec68eb62932193e341f55c90",
"rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9",
"type": "github"
},
"original": {
@ -35,14 +35,14 @@
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1730504152,
"narHash": "sha256-lXvH/vOfb4aGYyvFmZK/HlsNsr/0CVWlwYvo2rxJk3s=",
"lastModified": 1733096140,
"narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz"
"url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz"
"url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz"
}
},
"root": {

View file

@ -41,7 +41,11 @@
gtk-doc
gdb
valgrind
(pkgs.callPackage ./cros-ectool.nix { })
umockdev
python312Packages.pygobject3
python312Packages.pygobject-stubs
tshark
# (pkgs.callPackage ./cros-ectool.nix { })
# Add libfprint with an override
(pkgs.libfprint.overrideAttrs (oldAttrs: {

File diff suppressed because it is too large Load diff

View file

@ -31,8 +31,7 @@
#include "fpi-device.h"
#include "fpi-ssm.h"
G_DECLARE_FINAL_TYPE (FpiDeviceCrfpMoc, fpi_device_crfpmoc, FPI, DEVICE_CRFPMOC, FpDevice)
G_DECLARE_FINAL_TYPE(FpiDeviceCrfpMoc, fpi_device_crfpmoc, FPI, DEVICE_CRFPMOC, FpDevice)
#define CRFPMOC_DRIVER_FULLNAME "ChromeOS Fingerprint Match-on-Chip"
@ -62,8 +61,6 @@ G_DECLARE_FINAL_TYPE (FpiDeviceCrfpMoc, fpi_device_crfpmoc, FPI, DEVICE_CRFPMOC,
#define CRFPMOC_FPSTATS_MATCHING_INV (1U << 1)
/* New Fingerprint sensor event, the event data is fp_events bitmap. */
#define CRFPMOC_EC_MKBP_EVENT_FINGERPRINT 5
@ -79,6 +76,10 @@ G_DECLARE_FINAL_TYPE (FpiDeviceCrfpMoc, fpi_device_crfpmoc, FPI, DEVICE_CRFPMOC,
#define CRFPMOC_EC_CMD_FP_FRAME 0x0404
/* Should be made dynamic */
#define CRFPMOC_DEFAULT_SEED "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
#define CRFPMOC_DEFAULT_CONTEXT "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
/* constants defining the 'offset' field which also contains the frame index */
#define CRFPMOC_FP_FRAME_INDEX_SHIFT 28
/* Frame buffer where the captured image is stored */
@ -88,15 +89,15 @@ G_DECLARE_FINAL_TYPE (FpiDeviceCrfpMoc, fpi_device_crfpmoc, FPI, DEVICE_CRFPMOC,
#define CRFPMOC_FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
#define CRFPMOC_FP_FRAME_OFFSET_MASK 0x0FFFFFFF
struct crfpmoc_ec_params_fp_frame {
/*
* The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
* in the high nibble, and the real offset within the frame in
* FP_FRAME_OFFSET_MASK.
*/
guint32 offset;
guint32 size;
struct crfpmoc_ec_params_fp_frame
{
/*
* The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
* in the high nibble, and the real offset within the frame in
* FP_FRAME_OFFSET_MASK.
*/
guint32 offset;
guint32 size;
} __attribute__((packed));
/* Load a template into the MCU */
@ -104,40 +105,41 @@ struct crfpmoc_ec_params_fp_frame {
/* Flag in the 'size' field indicating that the full template has been sent */
#define CRFPMOC_FP_TEMPLATE_COMMIT 0x80000000
struct crfpmoc_ec_params_fp_template {
guint32 offset;
guint32 size;
guint8 data[];
} __attribute__((packed));
struct crfpmoc_ec_params_fp_template
{
guint32 offset;
guint32 size;
guint8 data[];
} __attribute__((packed));
#define CRFPMOC_EC_CMD_GET_PROTOCOL_INFO 0x000B
struct crfpmoc_ec_response_get_protocol_info {
/* Fields which exist if at least protocol version 3 supported */
guint32 protocol_versions;
guint16 max_request_packet_size;
guint16 max_response_packet_size;
guint32 flags;
struct crfpmoc_ec_response_get_protocol_info
{
/* Fields which exist if at least protocol version 3 supported */
guint32 protocol_versions;
guint16 max_request_packet_size;
guint16 max_response_packet_size;
guint32 flags;
} __attribute__((packed));
// crfpmoc_ec_host_response and crfpmoc_ec_host_request are only here for the size of the struct
struct crfpmoc_ec_host_response {
guint8 struct_version;
guint8 checksum;
guint16 result;
guint16 data_len;
guint16 reserved;
struct crfpmoc_ec_host_response
{
guint8 struct_version;
guint8 checksum;
guint16 result;
guint16 data_len;
guint16 reserved;
} __attribute__((packed));
struct crfpmoc_ec_host_request {
guint8 struct_version;
guint8 checksum;
guint16 command;
guint8 command_version;
guint8 reserved;
guint16 data_len;
struct crfpmoc_ec_host_request
{
guint8 struct_version;
guint8 checksum;
guint16 command;
guint8 command_version;
guint8 reserved;
guint16 data_len;
} __attribute__((packed));
#define CRFPMOC_EC_CMD_FP_ENC_STATUS 0x0409
@ -145,14 +147,14 @@ struct crfpmoc_ec_host_request {
/* FP TPM seed has been set or not */
#define CRFPMOC_FP_ENC_STATUS_SEED_SET (1U << 0)
struct crfpmoc_ec_response_fp_encryption_status {
/* Used bits in encryption engine status */
guint32 valid_flags;
/* Encryption engine status */
guint32 status;
struct crfpmoc_ec_response_fp_encryption_status
{
/* Used bits in encryption engine status */
guint32 valid_flags;
/* Encryption engine status */
guint32 status;
} __attribute__((packed));
struct crfpmoc_ec_params_fp_mode
{
guint32 mode; /* as defined by CRFPMOC_FP_MODE_ constants */
@ -174,38 +176,38 @@ struct crfpmoc_ec_response_fp_stats
guint32 hi;
} overall_t0;
guint8 timestamps_invalid;
gint8 template_matched;
gint8 template_matched;
} __attribute__((packed));
struct crfpmoc_ec_params_fp_seed {
/*
* Version of the structure format (N=3).
*/
guint16 struct_version;
/* Reserved bytes, set to 0. */
guint16 reserved;
/* Seed from the TPM. */
guint8 seed[CRFPMOC_FP_CONTEXT_TPM_BYTES];
struct crfpmoc_ec_params_fp_seed
{
/*
* Version of the structure format (N=3).
*/
guint16 struct_version;
/* Reserved bytes, set to 0. */
guint16 reserved;
/* Seed from the TPM. */
guint8 seed[CRFPMOC_FP_CONTEXT_TPM_BYTES];
} __attribute__((packed));
/* Clear the current fingerprint user context and set a new one */
#define CRFPMOC_EC_CMD_FP_CONTEXT 0x0406
enum crfpmoc_fp_context_action {
CRFPMOC_FP_CONTEXT_ASYNC = 0,
CRFPMOC_FP_CONTEXT_GET_RESULT = 1,
enum crfpmoc_fp_context_action
{
CRFPMOC_FP_CONTEXT_ASYNC = 0,
CRFPMOC_FP_CONTEXT_GET_RESULT = 1,
};
/* Version 1 of the command is "asynchronous". */
struct crfpmoc_ec_params_fp_context_v1 {
guint8 action; /**< enum fp_context_action */
guint8 reserved[3]; /**< padding for alignment */
guint32 userid[CRFPMOC_FP_CONTEXT_USERID_WORDS];
struct crfpmoc_ec_params_fp_context_v1
{
guint8 action; /**< enum fp_context_action */
guint8 reserved[3]; /**< padding for alignment */
guint32 userid[CRFPMOC_FP_CONTEXT_USERID_WORDS];
} __attribute__((packed));
struct crfpmoc_ec_response_fp_info
{
/* Sensor identification */
@ -221,10 +223,10 @@ struct crfpmoc_ec_response_fp_info
guint16 bpp;
guint16 errors;
/* Template/finger current information */
guint32 template_size; /* max template size in bytes */
guint16 template_max; /* maximum number of fingers/templates */
guint16 template_valid; /* number of valid fingers/templates */
guint32 template_dirty; /* bitmap of templates with MCU side changes */
guint32 template_size; /* max template size in bytes */
guint16 template_max; /* maximum number of fingers/templates */
guint16 template_valid; /* number of valid fingers/templates */
guint32 template_dirty; /* bitmap of templates with MCU side changes */
guint32 template_version; /* version of the template format */
} __attribute__((packed));
@ -256,7 +258,7 @@ union __attribute__((packed)) crfpmoc_ec_response_get_next_data_v1
struct
{
/* For aligning the fifo_info */
guint8 reserved[3];
guint8 reserved[3];
struct crfpmoc_ec_response_motion_sense_fifo_info info;
} sensor_fifo;
@ -270,12 +272,12 @@ union __attribute__((packed)) crfpmoc_ec_response_get_next_data_v1
guint32 cec_events;
guint8 cec_message[16];
guint8 cec_message[16];
};
struct crfpmoc_ec_response_get_next_event_v1
{
guint8 event_type;
guint8 event_type;
/* Followed by event data if any */
union crfpmoc_ec_response_get_next_data_v1 data;
} __attribute__((packed));
@ -295,18 +297,19 @@ struct crfpmoc_cros_ec_command_v2
guint32 outsize;
guint32 insize;
guint32 result;
guint8 data[0];
guint8 data[0];
};
#define CRFPMOC_CROS_EC_DEV_IOC_V2 0xEC
#define CRFPMOC_CROS_EC_DEV_IOCXCMD_V2 \
_IOWR (CRFPMOC_CROS_EC_DEV_IOC_V2, 0, struct crfpmoc_cros_ec_command_v2)
#define CRFPMOC_CROS_EC_DEV_IOCEVENTMASK_V2 _IO (CRFPMOC_CROS_EC_DEV_IOC_V2, 2)
_IOWR(CRFPMOC_CROS_EC_DEV_IOC_V2, 0, struct crfpmoc_cros_ec_command_v2)
#define CRFPMOC_CROS_EC_DEV_IOCEVENTMASK_V2 _IO(CRFPMOC_CROS_EC_DEV_IOC_V2, 2)
/*
* Host command response codes (16-bit).
*/
enum crfpmoc_ec_status {
enum crfpmoc_ec_status
{
EC_RES_SUCCESS = 0,
EC_RES_INVALID_COMMAND = 1,
EC_RES_ERROR = 2,
@ -315,19 +318,19 @@ enum crfpmoc_ec_status {
EC_RES_INVALID_RESPONSE = 5,
EC_RES_INVALID_VERSION = 6,
EC_RES_INVALID_CHECKSUM = 7,
EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
EC_RES_UNAVAILABLE = 9, /* No response available */
EC_RES_TIMEOUT = 10, /* We got a timeout */
EC_RES_OVERFLOW = 11, /* Table / data overflow */
EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
EC_RES_BUS_ERROR = 15, /* Communications bus error */
EC_RES_BUSY = 16, /* Up but too busy. Should retry */
EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
EC_RES_UNAVAILABLE = 9, /* No response available */
EC_RES_TIMEOUT = 10, /* We got a timeout */
EC_RES_OVERFLOW = 11, /* Table / data overflow */
EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
EC_RES_BUS_ERROR = 15, /* Communications bus error */
EC_RES_BUSY = 16, /* Up but too busy. Should retry */
EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
EC_RES_COUNT,
@ -336,7 +339,8 @@ enum crfpmoc_ec_status {
/* SSM task states and various status enums */
typedef enum {
typedef enum
{
ENROLL_SENSOR_ENROLL,
ENROLL_WAIT_FINGER,
ENROLL_SENSOR_CHECK,
@ -344,7 +348,9 @@ typedef enum {
ENROLL_STATES,
} EnrollStates;
typedef enum {
typedef enum
{
VERIFY_UPLOAD_TEMPLATE,
VERIFY_SENSOR_MATCH,
VERIFY_WAIT_FINGER,
VERIFY_SENSOR_CHECK,
@ -352,8 +358,8 @@ typedef enum {
VERIFY_STATES,
} VerifyStates;
typedef enum {
typedef enum
{
CLEAR_STORAGE_SENSOR_RESET,
CLEAR_STORAGE_STATES,
} ClearStorageStates;

View file

@ -56,11 +56,14 @@ p = d.enroll_sync(template, None, enroll_progress, None)
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
print("enroll done")
print(p)
print("verifying")
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
verify_res, verify_print = d.verify_sync(p)
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
print("verify done")
print(verify_res, verify_print)
assert verify_res == True
identified = False

View file

@ -59,7 +59,7 @@ drivers_tests = [
'realtek',
'realtek-5816',
'focaltech_moc',
'crfpmoc',
# 'crfpmoc',
]
if get_option('introspection')