Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DONOTMERGE/UNTESTED] Tama support #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
30 changes: 27 additions & 3 deletions fpc_imp_yoshino_nile.c → fpc_imp_yoshino_nile_tama.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -488,6 +494,11 @@ err_t fpc_auth_step(fpc_imp_data_t *data, uint32_t *print_id)
}

ALOGD("Print identified as %d\n", identify_cmd.id);
#if defined(USE_FPC_YOSHINO)
ALOGD("res: %d cov: %d, qual: %d, covered zones: %d, score: %d, idx: %u\n",
identify_cmd.res, identify_cmd.coverage, identify_cmd.qual, identify_cmd.covered_zones,
identify_cmd.score, identify_cmd.idx);
#endif

*print_id = identify_cmd.id;
return identify_cmd.status;
Expand Down Expand Up @@ -615,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;
Expand Down
222 changes: 222 additions & 0 deletions tz_api_tama.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>

#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
7 changes: 6 additions & 1 deletion tz_api_yoshino.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ typedef struct {
uint32_t command;
int32_t status;
uint32_t id;
uint32_t unk1[2];
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 {
Expand Down