From 4bb0222e11f4dfbc8df09d9706ec9a3469357e73 Mon Sep 17 00:00:00 2001 From: Jens Andersen Date: Sat, 27 Oct 2018 15:55:37 +0200 Subject: [PATCH] tama: Add initial support --- Android.mk | 9 +- ...hino_nile.c => fpc_imp_yoshino_nile_tama.c | 25 +- tz_api_tama.h | 222 ++++++++++++++++++ 3 files changed, 251 insertions(+), 5 deletions(-) rename fpc_imp_yoshino_nile.c => fpc_imp_yoshino_nile_tama.c (97%) create mode 100644 tz_api_tama.h diff --git a/Android.mk b/Android.mk index 77598af..9ac1482 100644 --- a/Android.mk +++ b/Android.mk @@ -17,14 +17,19 @@ LOCAL_SRC_FILES += fpc_imp_loire_tone.c endif ifeq ($(filter-out yoshino,$(SOMC_PLATFORM)),) -LOCAL_SRC_FILES += fpc_imp_yoshino_nile.c +LOCAL_SRC_FILES += fpc_imp_yoshino_nile_tama.c endif ifeq ($(filter-out nile,$(SOMC_PLATFORM)),) -LOCAL_SRC_FILES += fpc_imp_yoshino_nile.c +LOCAL_SRC_FILES += fpc_imp_yoshino_nile_tama.c LOCAL_CFLAGS += -DUSE_FPC_NILE endif +ifeq ($(filter-out tama,$(SOMC_PLATFORM)),) +LOCAL_SRC_FILES += fpc_imp_yoshino_nile_tama.c +LOCAL_CFLAGS += -DUSE_FPC_TAMA +endif + LOCAL_SHARED_LIBRARIES := \ libcutils \ liblog \ diff --git a/fpc_imp_yoshino_nile.c b/fpc_imp_yoshino_nile_tama.c similarity index 97% rename from fpc_imp_yoshino_nile.c rename to fpc_imp_yoshino_nile_tama.c index 41abd4b..3f3bb27 100644 --- a/fpc_imp_yoshino_nile.c +++ b/fpc_imp_yoshino_nile_tama.c @@ -20,6 +20,8 @@ #ifdef USE_FPC_NILE #include "tz_api_nile.h" +#elif USE_FPC_TAMA +#include "tz_api_tama.h" #else #include "tz_api_yoshino.h" #endif @@ -51,9 +53,10 @@ typedef struct { } fpc_data_t; err_t fpc_deep_sleep(fpc_imp_data_t *data); +err_t fpc_sensor_wake(fpc_imp_data_t *data); static const char *error_strings[] = { -#ifdef USE_FPC_NILE +#if defined(USE_FPC_NILE) || defined(USE_FPC_TAMA) "FPC_ERROR_TEMPLATE_CORRUPTED", "FPC_ERROR_DB", "FPC_ERROR_CRYPTO", @@ -377,12 +380,11 @@ err_t fpc_capture_image(fpc_imp_data_t *data) ALOGE("Error starting device\n"); return -1; } - //fpc_deep_sleep(data); - int ret = fpc_wait_finger_lost(data); ALOGD("fpc_wait_finger_lost = 0x%08X", ret); if(!ret) { + fpc_sensor_wake(data); // while(1) { ALOGD("Finger lost as expected"); @@ -400,6 +402,10 @@ err_t fpc_capture_image(fpc_imp_data_t *data) ret = 1000; } +#ifdef USE_FPC_TAMA + fpc_deep_sleep(data); +#endif + if (fpc_set_power(FPC_PWROFF) < 0) { ALOGE("Error stopping device\n"); return -1; @@ -620,6 +626,19 @@ err_t fpc_update_template(fpc_imp_data_t *data) return -1; } +err_t fpc_sensor_wake(fpc_imp_data_t *data) { + err_t result = 0; +#ifdef USE_FPC_TAMA + fpc_data_t *ldata = (fpc_data_t*)data; + + result = send_normal_command(ldata, FPC_GROUP_SENSOR, FPC_SENSOR_WAKE); + + ALOGI("Sensor wake Result: %d\n", result); +#endif + return result; + +} + err_t fpc_deep_sleep(fpc_imp_data_t *data) { err_t result; fpc_data_t *ldata = (fpc_data_t*)data; diff --git a/tz_api_tama.h b/tz_api_tama.h new file mode 100644 index 0000000..80e1a40 --- /dev/null +++ b/tz_api_tama.h @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2016 Shane Francis / Jens Andersen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TZAPI_H_ +#define __TZAPI_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define FP_TZAPP_PATH "/odm/firmware/" +#define FP_TZAPP_NAME "fpctzfingerprint" + +#define KM_TZAPP_PATH "/system/etc/firmware" +#define KM_TZAPP_ALT_PATH "" +#define KM_TZAPP_NAME "keymaster64" +#define KM_TZAPP_ALT_NAME "keymaster" + +#define BUFFER_SIZE 64 +#define TZ_RESPONSE_OFFSET 256 +#define FINGERPRINT_MAX_COUNT 5 +#define AUTH_RESULT_LENGTH 69 + +enum fingerprint_group_t { + FPC_GROUP_DB = 0x2, + FPC_GROUP_FPCDATA = 0x3, + FPC_GROUP_DEBUG = 0x6, // I think? + FPC_GROUP_QC = 0x07, + FPC_GROUP_INFO = 0x09, + FPC_GROUP_SENSOR = 0xA, + FPC_GROUP_TEMPLATE = 0xB, +}; + +enum fingerprint_db_cmd_t { + FPC_LOAD_DB = 0x0B, + FPC_STORE_DB = 0x0C, +}; + +enum fingerprint_fpcdata_cmd_t { + FPC_SET_AUTH_CHALLENGE = 0x01, + FPC_GET_AUTH_CHALLENGE = 0x02, + FPC_AUTHORIZE_ENROL = 0x03, + FPC_GET_AUTH_RESULT = 0x04, + FPC_SET_KEY_DATA = 0x05, +}; + +//enumerate tz app command ID's +enum fingerprint_sensor_cmd_t { + FPC_SENSOR_WAKE = 0x00, + FPC_WAIT_FINGER_LOST = 0x01, + FPC_WAIT_FINGER_DOWN = 0x02, + FPC_CAPTURE_IMAGE = 0x3, + FPC_DEEP_SLEEP = 0x04, + FPC_GET_OTP_INFO = 0x06, +// FPC_INIT Is unused on Yoshino +}; + +enum fingerprint_templates_cmd_t { + FPC_BEGIN_ENROL = 0x00, + FPC_ENROL_STEP = 0x01, + FPC_END_ENROL = 0x02, + FPC_IDENTIFY = 0x03, + FPC_UPDATE_TEMPLATE = 0x04, + FPC_LOAD_EMPTY_DB = 0x06, + FPC_GET_FINGERPRINTS = 0x07, + FPC_SET_GID = 0x09, + FPC_DELETE_FINGERPRINT = 0x08, + FPC_GET_TEMPLATE_ID = 0x0A, +}; + +enum fingerprint_debug_cmd_t { + FPC_GET_SENSOR_INFO = 0x03, +}; + +enum fingerprint_qc_cmd_t { + FPC_SET_QC_AUTH_NONCE = 0x01, + FPC_GET_QC_AUTH_RESULT = 0x02, + FPC_IS_USER_VALID = 0x03, +}; + +enum fingerprint_info_cmd_t { + FPC_GET_FPC_INFO = 0x02, +}; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + uint32_t ret_val; //Some cases this is used for return value of the command +} fpc_send_std_cmd_t; + +typedef struct { + uint32_t cmd_id; + uint32_t ret_val; //Some cases this is used for return value of the command + uint32_t length; //Some length of data supplied by previous modified command +} keymaster_cmd_t; + +typedef struct { + int32_t status; + uint32_t offset; + uint32_t length; +} keymaster_return_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + uint64_t challenge; + int32_t status; +} fpc_send_auth_cmd_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + int32_t status; + uint32_t gid; +} fpc_set_gid_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + int32_t status; + uint32_t length; + char data[]; +} fpc_send_keydata_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + uint64_t challenge; + int32_t status; +} fpc_load_auth_challenge_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + int32_t status; + uint32_t remaining_touches; +} fpc_enrol_step_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + int32_t status; + uint32_t print_id; +} fpc_end_enrol_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + int32_t status; + uint32_t length; + char* data; +} fpc_send_buffer_t; + +typedef struct +{ + uint32_t commandgroup; + uint32_t command; + int32_t status; + uint32_t id; + uint32_t coverage; + uint32_t qual; + uint32_t covered_zones; + uint32_t res; + uint32_t score; + uint32_t idx; +} fpc_send_identify_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + int32_t status; + uint32_t length; + uint32_t fingerprints[FINGERPRINT_MAX_COUNT]; +} fpc_fingerprint_list_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + int32_t status; + uint32_t fingerprint_id; +} fpc_fingerprint_delete_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + uint32_t result; + uint32_t length; + uint8_t auth_result[AUTH_RESULT_LENGTH]; // In practice this is always 69 bytes +} fpc_get_auth_result_t; + +typedef struct { + uint32_t length; //Length of data on ion buffer + uint32_t v_addr; //Virtual address of ion mmap buffer +} fpc_send_mod_cmd_t; + +typedef struct { + uint32_t group_id; + uint32_t cmd_id; + uint32_t result; + uint32_t unk1; + uint64_t auth_id; +} fpc_get_db_id_cmd_t; + +#ifdef __cplusplus +} +#endif +#endif