2016-02-17 14:23:55 +00:00
|
|
|
/*
|
2016-09-06 10:49:54 +00:00
|
|
|
* Copyright (C) 2016 The Android Open Source Project
|
2016-02-17 14:23:55 +00:00
|
|
|
* Copyright (C) 2016 The Mokee Project
|
|
|
|
* Copyright (C) 2016 The CyanogenMod Project
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "FingerprintHal_msm8974"
|
|
|
|
#define LOG_NDEBUG 1
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <endian.h>
|
2016-09-06 10:49:54 +00:00
|
|
|
#include <fcntl.h>
|
2016-02-17 14:23:55 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <malloc.h>
|
2016-09-06 10:49:54 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sqlite3.h>
|
2016-02-17 14:23:55 +00:00
|
|
|
#include <string.h>
|
2016-09-06 10:49:54 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-02-17 14:23:55 +00:00
|
|
|
#include <cutils/log.h>
|
2016-09-06 10:49:54 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2016-02-17 14:23:55 +00:00
|
|
|
#include <hardware/hardware.h>
|
|
|
|
#include <hardware/fingerprint.h>
|
|
|
|
|
|
|
|
#include "fp_klte.h"
|
2016-09-06 10:49:54 +00:00
|
|
|
#include "fingerprint_tz.h"
|
|
|
|
#include "hash.h"
|
|
|
|
|
|
|
|
typedef struct vcs_fingerprint_device_t {
|
|
|
|
fingerprint_device_t device; // "inheritance"
|
|
|
|
uint64_t op_id;
|
|
|
|
uint64_t challenge;
|
|
|
|
uint64_t user_id;
|
|
|
|
uint64_t group_id;
|
|
|
|
uint64_t secure_user_id;
|
|
|
|
uint64_t authenticator_id;
|
|
|
|
uint32_t active_gid;
|
|
|
|
sqlite3 *db;
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
} vcs_fingerprint_device_t;
|
|
|
|
|
|
|
|
extern trust_zone_t tz;
|
|
|
|
vcs_sensor_t sensor;
|
|
|
|
|
|
|
|
/***************************************Sensor***************************************/
|
|
|
|
int sensor_uninit() {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
int ret = 0;
|
|
|
|
if (!sensor.init)
|
|
|
|
return ret;
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_RESET_SPI_CONFIGURATION);
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_DISABLE_SPI_CLOCK);
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_DEVICE_SUSPEND);
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_POWER_OFF);
|
|
|
|
sensor.init = false;
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-17 14:23:55 +00:00
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
int sensor_init() {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
int ret = 0;
|
|
|
|
int clock = 0;
|
|
|
|
if (sensor.init)
|
|
|
|
return ret;
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_POWER_ON);
|
|
|
|
clock = 65535;
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_SET_CLK, &clock);
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_DEVICE_RESET);
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_SET_SPI_CONFIGURATION);
|
|
|
|
clock = 4800;
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_SET_CLK, &clock);
|
|
|
|
sensor.init = true;
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-17 14:23:55 +00:00
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
void sensor_process_signal(int signum) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
ALOGV("%s: signal %d received", __FUNCTION__, signum);
|
|
|
|
int flag = 0;
|
|
|
|
if (tz.timeout.timeout_thread) {
|
|
|
|
pthread_mutex_lock(&tz.timeout.lock);
|
|
|
|
pthread_cond_signal(&tz.timeout.cond);
|
|
|
|
pthread_mutex_unlock(&tz.timeout.lock);
|
|
|
|
//pthread_join(tz.timeout.timeout_thread, NULL);
|
|
|
|
tz.timeout.timeout_thread = 0;
|
|
|
|
}
|
|
|
|
pthread_mutex_lock(&sensor.lock);
|
|
|
|
if (get_tz_state() != STATE_IDLE && get_tz_state() != STATE_CANCEL)
|
|
|
|
sensor.signal = true;
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_SET_DRDY_INT, &flag);
|
|
|
|
pthread_cond_signal(&sensor.cond);
|
|
|
|
pthread_mutex_unlock(&sensor.lock);
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
int sensor_register() {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
struct vfsspi_iocRegSignal usrSignal;
|
|
|
|
int ret = 0;
|
|
|
|
struct sigaction sa_usr;
|
|
|
|
sa_usr.sa_flags = 0;
|
|
|
|
sa_usr.sa_handler = sensor_process_signal;
|
|
|
|
sigaction(SIGUSR2, &sa_usr, NULL);
|
|
|
|
usrSignal.userPID = getpid();
|
|
|
|
usrSignal.signalID = SIGUSR2;
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_REGISTER_DRDY_SIGNAL, &usrSignal);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sensor_capture_start() {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
int ret = 0;
|
|
|
|
int flag = 1;
|
|
|
|
ret = ioctl(sensor.fd, VFSSPI_IOCTL_SET_DRDY_INT, &flag);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************Database***************************************/
|
|
|
|
int db_check_and_create_table(void* device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
char* errmsg;
|
|
|
|
int ret = 0;
|
|
|
|
char cmd[MAX_DATABASE_CMD];
|
|
|
|
sprintf(cmd, "create table gid_%d(id integer, data blob, payload blob)", vdev->active_gid);
|
|
|
|
ret = sqlite3_exec(vdev->db, cmd, NULL, NULL, &errmsg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int db_convert_old_db(vcs_fingerprint_device_t* vdev) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
int ret = 0;
|
|
|
|
sqlite3 *db;
|
|
|
|
sqlite3_stmt *stat;
|
|
|
|
char cmd[MAX_DATABASE_CMD];
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
memset(tz.finger, 0, MAX_NUM_FINGERS * sizeof(finger_t));
|
|
|
|
ret = sqlite3_open(SAMSUNG_FP_DB_PATH, &db);
|
|
|
|
if (ret != SQLITE_OK) {
|
|
|
|
ALOGE("Open samsung finger database failed!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(cmd, "select * from enrollments");
|
|
|
|
sqlite3_prepare(db, cmd, -1, &stat, 0);
|
|
|
|
while(1) {
|
|
|
|
int ret = sqlite3_step(stat);
|
|
|
|
if (ret != SQLITE_ROW) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int id = sqlite3_column_int(stat, 1);
|
|
|
|
const void *data = sqlite3_column_blob(stat, 2);
|
|
|
|
int len = sqlite3_column_bytes(stat, 2);
|
|
|
|
memcpy(tz.finger[id].data, data, len);
|
|
|
|
ALOGV("read fingerprint data from samsung fp database: id=%d", id);
|
|
|
|
tz.finger[id].exist = true;
|
|
|
|
}
|
|
|
|
sqlite3_finalize(stat);
|
|
|
|
|
|
|
|
memset(cmd, 0, MAX_DATABASE_CMD);
|
|
|
|
sprintf(cmd, "select * from properties");
|
|
|
|
sqlite3_prepare(db, cmd, -1, &stat, 0);
|
|
|
|
sqlite3_step(stat);
|
|
|
|
const void *payload = sqlite3_column_blob(stat, 2);
|
|
|
|
int len = sqlite3_column_bytes(stat, 2);
|
|
|
|
for (idx = 1; idx <= MAX_NUM_FINGERS; idx++) {
|
|
|
|
if (tz.finger[idx].exist) {
|
|
|
|
memcpy(tz.finger[idx].payload, payload, len);
|
|
|
|
db_write_to_db(vdev, false, idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sqlite3_finalize(stat);
|
|
|
|
|
|
|
|
ret = sqlite3_close(db);
|
|
|
|
if (ret != SQLITE_OK) {
|
|
|
|
ALOGE("Close samsung finger database failed!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = remove(SAMSUNG_FP_DB_PATH);
|
|
|
|
if (ret) {
|
|
|
|
ALOGE("Cannot remove Samsung fingerprint database");
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
int db_read_to_tz(void* device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
char* errmsg;
|
|
|
|
int ret = 0;
|
|
|
|
char cmd[MAX_DATABASE_CMD];
|
|
|
|
sqlite3_stmt *stat;
|
|
|
|
|
|
|
|
db_check_and_create_table(vdev);
|
|
|
|
|
|
|
|
if (!access(SAMSUNG_FP_DB_PATH, 0)) {
|
|
|
|
ALOGI("Samsung fingerprint database exist! Convert it");
|
|
|
|
return db_convert_old_db(vdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(tz.finger, 0, MAX_NUM_FINGERS * sizeof(finger_t));
|
|
|
|
sprintf(cmd, "select * from gid_%d", vdev->active_gid);
|
|
|
|
sqlite3_prepare(vdev->db, cmd, -1, &stat, 0);
|
|
|
|
while(1) {
|
|
|
|
int ret = sqlite3_step(stat);
|
|
|
|
if (ret != SQLITE_ROW) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int id = sqlite3_column_int(stat, 0);
|
|
|
|
const void *data = sqlite3_column_blob(stat, 1);
|
|
|
|
memcpy(tz.finger[id].data, data, FINGER_DATA_MAX_LENGTH);
|
|
|
|
const void *payload = sqlite3_column_blob(stat, 2);
|
|
|
|
memcpy(tz.finger[id].payload, payload, PAYLOAD_MAX_LENGTH);
|
|
|
|
ALOGV("read fingerprint data from database: id=%d", id);
|
|
|
|
tz.finger[id].exist = true;
|
|
|
|
}
|
|
|
|
sqlite3_finalize(stat);
|
|
|
|
|
|
|
|
return 0;
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
int db_write_to_db(void* device, bool remove, int fid) {
|
2016-02-17 14:23:55 +00:00
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
char* errmsg;
|
|
|
|
int ret = 0;
|
|
|
|
char cmd[MAX_DATABASE_CMD];
|
|
|
|
sqlite3_stmt *stat;
|
|
|
|
if (remove) {
|
|
|
|
sprintf(cmd, "delete from gid_%d where id=%d", vdev->active_gid, fid);
|
|
|
|
ret = sqlite3_exec(vdev->db, cmd, NULL, NULL, &errmsg);
|
|
|
|
if (ret != SQLITE_OK) {
|
|
|
|
ALOGE("Remove finger from database failed!");
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
2016-09-06 10:49:54 +00:00
|
|
|
memset(&tz.finger[fid], 0, sizeof(finger_t));
|
|
|
|
} else {
|
|
|
|
sprintf(cmd, "insert into gid_%d(id, data, payload) values( %d, ?, ?)", vdev->active_gid, fid);
|
|
|
|
sqlite3_prepare(vdev->db, cmd, -1, &stat, 0);
|
|
|
|
sqlite3_bind_blob(stat, 1, tz.finger[fid].data, (int)FINGER_DATA_MAX_LENGTH, NULL);
|
|
|
|
sqlite3_bind_blob(stat, 2, tz.finger[fid].payload, (int)PAYLOAD_MAX_LENGTH, NULL);
|
|
|
|
ret = sqlite3_step(stat);
|
|
|
|
sqlite3_finalize(stat);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int db_init(void* device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
int ret = 0;
|
|
|
|
ret = sqlite3_open(FINGER_DATABASE_FILENAME, &vdev->db);
|
|
|
|
if (ret != SQLITE_OK) {
|
|
|
|
ALOGE("Open finger database failed!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return db_read_to_tz(vdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int db_uninit(void* device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
int ret = 0;
|
|
|
|
ret = sqlite3_close(vdev->db);
|
|
|
|
if (ret != SQLITE_OK) {
|
|
|
|
ALOGE("Close finger database failed!");
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
2016-09-06 10:49:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-02-17 14:23:55 +00:00
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
/***************************************notice***************************************/
|
|
|
|
fingerprint_acquired_info_t convert_ret_to_acquired_info(int acquired_ret) { //TODO
|
|
|
|
ALOGV("----------------> %s ----------------->acquired_ret=%d", __FUNCTION__, acquired_ret);
|
|
|
|
fingerprint_acquired_info_t ret = FINGERPRINT_ACQUIRED_GOOD;
|
|
|
|
switch (acquired_ret) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = FINGERPRINT_ACQUIRED_INSUFFICIENT;
|
|
|
|
}
|
2016-02-17 14:23:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
void send_error_notice(void* device, int error_info_int) {
|
2016-02-17 14:23:55 +00:00
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
fingerprint_error_t error_info = (fingerprint_error_t)error_info_int;
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
fingerprint_msg_t msg = {0};
|
|
|
|
msg.type = FINGERPRINT_ERROR;
|
|
|
|
msg.data.error = error_info;
|
2016-09-06 10:49:54 +00:00
|
|
|
ALOGV("recevied error notice! error_info=%d", (int)error_info);
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
vdev->device.notify(&msg);
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
void send_acquired_notice(void* device, int acquired_ret) {
|
2016-02-17 14:23:55 +00:00
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
fingerprint_acquired_info_t acquired_info = convert_ret_to_acquired_info(acquired_ret);
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
fingerprint_msg_t acqu_msg = {0};
|
|
|
|
acqu_msg.type = FINGERPRINT_ACQUIRED;
|
|
|
|
acqu_msg.data.acquired.acquired_info = acquired_info;
|
|
|
|
ALOGI("acqu_info=%d", (int)acquired_info);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
vdev->device.notify(&acqu_msg);
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
void send_enroll_notice(void* device, int fid, int remaining) {
|
2016-02-17 14:23:55 +00:00
|
|
|
ALOGV("----------------> %s -----------------> fid %d", __FUNCTION__, fid);
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
if (fid == 0) {
|
2016-09-06 10:49:54 +00:00
|
|
|
ALOGE("Fingerprint ID is zero (invalid)");
|
2016-02-17 14:23:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (vdev->secure_user_id == 0) {
|
2016-09-06 10:49:54 +00:00
|
|
|
ALOGE("Secure user ID is zero (invalid)");
|
2016-02-17 14:23:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
|
|
|
|
fingerprint_msg_t msg = {0};
|
|
|
|
msg.type = FINGERPRINT_TEMPLATE_ENROLLING;
|
|
|
|
msg.data.enroll.finger.fid = fid;
|
|
|
|
msg.data.enroll.samples_remaining = remaining;
|
|
|
|
vdev->device.notify(&msg);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
void send_authenticated_notice(void* device, int fid) {
|
2016-02-17 14:23:55 +00:00
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
send_acquired_notice(vdev, FINGERPRINT_ACQUIRED_GOOD);
|
|
|
|
|
|
|
|
fingerprint_msg_t auth_msg = {0};
|
|
|
|
auth_msg.type = FINGERPRINT_AUTHENTICATED;
|
|
|
|
auth_msg.data.authenticated.finger.fid = fid;
|
|
|
|
auth_msg.data.authenticated.finger.gid = 0; // unused
|
|
|
|
auth_msg.data.authenticated.hat.version = HW_AUTH_TOKEN_VERSION;
|
|
|
|
auth_msg.data.authenticated.hat.authenticator_type =
|
|
|
|
htobe32(HW_AUTH_FINGERPRINT);
|
|
|
|
auth_msg.data.authenticated.hat.challenge = vdev->op_id;
|
|
|
|
auth_msg.data.authenticated.hat.authenticator_id = vdev->authenticator_id;
|
|
|
|
auth_msg.data.authenticated.hat.user_id = vdev->secure_user_id;
|
|
|
|
struct timespec ts;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
auth_msg.data.authenticated.hat.timestamp =
|
|
|
|
htobe64((uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
vdev->device.notify(&auth_msg);
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
void send_remove_notice(void* device, int fid) {
|
2016-02-17 14:23:55 +00:00
|
|
|
ALOGV("----------------> %s ----------------->fid=%d", __FUNCTION__, fid);
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
fingerprint_msg_t msg = {0};
|
|
|
|
msg.type = FINGERPRINT_TEMPLATE_REMOVED;
|
|
|
|
msg.data.removed.finger.fid = fid;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
vdev->device.notify(&msg);
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
/***************************************HAL function***************************************/
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
static uint64_t fingerprint_get_auth_id(struct fingerprint_device* device) {
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
uint64_t authenticator_id = 0;
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
2016-09-06 10:49:54 +00:00
|
|
|
vdev->authenticator_id = hash_file(FINGER_DATABASE_FILENAME);
|
2016-02-17 14:23:55 +00:00
|
|
|
authenticator_id = vdev->authenticator_id;
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return authenticator_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_set_active_group(struct fingerprint_device *device, uint32_t gid,
|
|
|
|
const char __unused *path) {
|
2016-09-06 10:49:54 +00:00
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
2016-02-17 14:23:55 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
vdev->active_gid = gid;
|
2016-09-06 10:49:54 +00:00
|
|
|
db_read_to_tz(vdev);
|
2016-02-17 14:23:55 +00:00
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_authenticate(struct fingerprint_device *device,
|
|
|
|
uint64_t operation_id, __unused uint32_t gid)
|
|
|
|
{
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
int ret = 0;
|
|
|
|
ALOGI("auth: op_id=%llu ",operation_id);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
|
|
|
|
vdev->op_id = operation_id;
|
2016-09-06 10:49:54 +00:00
|
|
|
ret = vcs_start_authenticate(vdev);
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
return ret;
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_enroll(struct fingerprint_device *device,
|
|
|
|
const hw_auth_token_t *hat,
|
|
|
|
uint32_t __unused gid,
|
2016-09-06 10:49:54 +00:00
|
|
|
uint32_t timeout_sec) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
2016-02-17 14:23:55 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
int idx = 1;
|
|
|
|
|
|
|
|
if (!hat) {
|
|
|
|
ALOGW("%s: null auth token", __func__);
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
}
|
|
|
|
if (hat->challenge == vdev->challenge) {
|
|
|
|
vdev->secure_user_id = hat->user_id;
|
|
|
|
} else {
|
|
|
|
ALOGW("%s: invalid auth token", __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hat->version != HW_AUTH_TOKEN_VERSION) {
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
}
|
|
|
|
if (hat->challenge != vdev->challenge && !(hat->authenticator_type & HW_AUTH_FINGERPRINT)) {
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
vdev->user_id = hat->user_id;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
for (idx = 1; idx <= MAX_NUM_FINGERS; idx++) {
|
|
|
|
if (!tz.finger[idx].exist) {
|
2016-02-17 14:23:55 +00:00
|
|
|
break;
|
2016-09-06 10:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idx > MAX_NUM_FINGERS) {
|
|
|
|
send_error_notice(vdev, FINGERPRINT_ERROR_NO_SPACE);
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
return -1;
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
2016-09-06 10:49:54 +00:00
|
|
|
ret = vcs_start_enroll(vdev, timeout_sec);
|
2016-02-17 14:23:55 +00:00
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
ALOGV("enroll ret=%d",ret);
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t fingerprint_pre_enroll(struct fingerprint_device *device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
uint64_t challenge = 0;
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
challenge = hash_string(tz.auth_token);
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
vdev->challenge = challenge;
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return challenge;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_post_enroll(struct fingerprint_device* device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
vdev->challenge = 0;
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_cancel(struct fingerprint_device *device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
int ret = 0;
|
2016-09-06 10:49:54 +00:00
|
|
|
int flag = 0;
|
|
|
|
|
|
|
|
if (tz.timeout.timeout_thread) {
|
|
|
|
pthread_mutex_lock(&tz.timeout.lock);
|
|
|
|
pthread_cond_signal(&tz.timeout.cond);
|
|
|
|
pthread_mutex_unlock(&tz.timeout.lock);
|
|
|
|
pthread_join(tz.timeout.timeout_thread, NULL);
|
|
|
|
tz.timeout.timeout_thread = 0;
|
|
|
|
}
|
|
|
|
if (get_tz_state() != STATE_IDLE && get_tz_state() != STATE_CANCEL) {
|
|
|
|
set_tz_state(STATE_CANCEL);
|
|
|
|
ioctl(sensor.fd, VFSSPI_IOCTL_SET_DRDY_INT, &flag);
|
|
|
|
pthread_mutex_lock(&sensor.lock);
|
|
|
|
pthread_cond_signal(&sensor.cond);
|
|
|
|
pthread_mutex_unlock(&sensor.lock);
|
|
|
|
while (1) {
|
|
|
|
usleep(100000);
|
|
|
|
if (tz.state == STATE_IDLE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_enumerate(struct fingerprint_device *device,
|
|
|
|
fingerprint_finger_id_t *results, uint32_t *max_size) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
if (device == NULL || results == NULL || max_size == NULL) {
|
|
|
|
ALOGE("Cannot enumerate saved fingerprints with uninitialized params");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int num = 0;
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
2016-02-17 14:23:55 +00:00
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
num = vcs_get_enrolled_finger_num();
|
2016-02-17 14:23:55 +00:00
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_remove(struct fingerprint_device *device,
|
|
|
|
uint32_t __unused gid, uint32_t fid) {
|
2016-09-06 10:49:54 +00:00
|
|
|
int ret = 0;
|
2016-02-17 14:23:55 +00:00
|
|
|
ALOGV("----------------> %s -----------------> fid %d", __FUNCTION__, fid);
|
|
|
|
if (device == NULL) {
|
|
|
|
ALOGE("Can't remove fingerprint (gid=%d, fid=%d); "
|
|
|
|
"device not initialized properly",
|
|
|
|
gid, fid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
|
|
|
|
if (fid == 0) {
|
|
|
|
// Delete all fingerprints
|
2016-09-06 10:49:54 +00:00
|
|
|
int idx = 1;
|
|
|
|
for (idx = 1; idx <= MAX_NUM_FINGERS; idx++)
|
|
|
|
if (tz.finger[idx].exist) {
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
ret = db_write_to_db(vdev, true, idx);
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
if (ret == 0) {
|
|
|
|
send_remove_notice(vdev, idx);
|
2016-02-17 14:23:55 +00:00
|
|
|
}
|
2016-09-06 10:49:54 +00:00
|
|
|
}
|
2016-02-17 14:23:55 +00:00
|
|
|
} else {
|
|
|
|
// Delete one fingerprint
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
2016-09-06 10:49:54 +00:00
|
|
|
ret = db_write_to_db(vdev, true, fid);
|
2016-02-17 14:23:55 +00:00
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
2016-09-06 10:49:54 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
send_remove_notice(vdev, fid);
|
|
|
|
}
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
2016-09-06 10:49:54 +00:00
|
|
|
ALOGE("Can't remove finger %d", fid);
|
2016-02-17 14:23:55 +00:00
|
|
|
send_error_notice(vdev, FINGERPRINT_ERROR_UNABLE_TO_REMOVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_notify_callback(struct fingerprint_device *device,
|
|
|
|
fingerprint_notify_t notify) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
if (device == NULL || notify == NULL) {
|
|
|
|
ALOGE("Failed to set notify callback @ %p for fingerprint device %p",
|
|
|
|
device, notify);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
device->notify = notify;
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
ALOGD("fingerprint callback notification set");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_close(hw_device_t* device) {
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
if (device == NULL) {
|
|
|
|
ALOGE("fingerprint hw device is NULL");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vcs_fingerprint_device_t* vdev = (vcs_fingerprint_device_t*)device;
|
|
|
|
|
2017-07-26 14:38:45 +00:00
|
|
|
fingerprint_cancel(&vdev->device);
|
|
|
|
|
2016-02-17 14:23:55 +00:00
|
|
|
pthread_mutex_lock(&vdev->lock);
|
2016-09-06 10:49:54 +00:00
|
|
|
db_uninit(vdev);
|
2017-07-26 14:38:45 +00:00
|
|
|
sensor_init();
|
2016-09-06 10:49:54 +00:00
|
|
|
vcs_init();
|
|
|
|
vcs_stop_auth_session();
|
|
|
|
vcs_uninit();
|
|
|
|
sensor_uninit();
|
2016-02-17 14:23:55 +00:00
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
|
|
|
pthread_mutex_destroy(&vdev->lock);
|
2016-09-06 10:49:54 +00:00
|
|
|
pthread_mutex_destroy(&sensor.lock);
|
|
|
|
pthread_mutex_destroy(&tz.lock);
|
|
|
|
pthread_mutex_destroy(&tz.timeout.lock);
|
2016-02-17 14:23:55 +00:00
|
|
|
free(vdev);
|
2017-07-26 14:38:45 +00:00
|
|
|
vdev = NULL;
|
|
|
|
|
|
|
|
if (close(sensor.fd) < 0) {
|
|
|
|
ALOGE("Close sensor error!");
|
|
|
|
}
|
|
|
|
sensor.fd = -1;
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fingerprint_open(const hw_module_t* module, const char __unused *id,
|
|
|
|
hw_device_t** device)
|
|
|
|
{
|
|
|
|
|
|
|
|
ALOGV("----------------> %s ----------------->", __FUNCTION__);
|
|
|
|
if (device == NULL) {
|
|
|
|
ALOGE("NULL device on open");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
vcs_fingerprint_device_t *vdev = (vcs_fingerprint_device_t*)calloc(
|
|
|
|
1, sizeof(vcs_fingerprint_device_t));
|
|
|
|
|
|
|
|
if (vdev == NULL) {
|
|
|
|
ALOGE("Insufficient memory for fingerprint device");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
vdev->device.common.tag = HARDWARE_DEVICE_TAG;
|
2017-12-23 00:04:30 +00:00
|
|
|
vdev->device.common.version = FINGERPRINT_MODULE_API_VERSION_2_1;
|
2016-02-17 14:23:55 +00:00
|
|
|
vdev->device.common.module = (struct hw_module_t*)module;
|
|
|
|
vdev->device.common.close = fingerprint_close;
|
|
|
|
|
|
|
|
vdev->device.pre_enroll = fingerprint_pre_enroll;
|
|
|
|
vdev->device.enroll = fingerprint_enroll;
|
|
|
|
vdev->device.post_enroll = fingerprint_post_enroll;
|
|
|
|
vdev->device.get_authenticator_id = fingerprint_get_auth_id;
|
|
|
|
vdev->device.set_active_group = fingerprint_set_active_group;
|
|
|
|
vdev->device.authenticate = fingerprint_authenticate;
|
|
|
|
vdev->device.cancel = fingerprint_cancel;
|
|
|
|
vdev->device.enumerate = fingerprint_enumerate;
|
|
|
|
vdev->device.remove = fingerprint_remove;
|
|
|
|
vdev->device.set_notify = set_notify_callback;
|
|
|
|
vdev->device.notify = NULL;
|
|
|
|
|
|
|
|
vdev->active_gid = 0;
|
2016-09-06 10:49:54 +00:00
|
|
|
memset(&tz, 0, sizeof(trust_zone_t));
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
pthread_mutex_init(&vdev->lock, NULL);
|
2016-09-06 10:49:54 +00:00
|
|
|
pthread_mutex_init(&sensor.lock, NULL);
|
|
|
|
pthread_mutex_init(&tz.lock, NULL);
|
|
|
|
pthread_mutex_init(&tz.timeout.lock, NULL);
|
|
|
|
pthread_cond_init(&tz.timeout.cond, NULL);
|
|
|
|
pthread_cond_init(&sensor.cond, NULL);
|
2017-07-26 14:38:45 +00:00
|
|
|
sensor.signal = false;
|
2016-09-06 10:49:54 +00:00
|
|
|
tz.timeout.timeout_thread = 0;
|
2016-02-17 14:23:55 +00:00
|
|
|
|
|
|
|
*device = &vdev->device.common;
|
|
|
|
|
2016-09-06 10:49:54 +00:00
|
|
|
memset(&sensor, 0, sizeof(vcs_sensor_t));
|
|
|
|
sensor.fd = open(SENSOR_FILE_NAME, O_RDWR);
|
|
|
|
if (sensor.fd < 0) {
|
|
|
|
ALOGE("Open sensor error!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sensor_init();
|
|
|
|
sensor_register();
|
|
|
|
sensor_uninit();
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->lock);
|
|
|
|
sensor_init();
|
|
|
|
db_init(vdev);
|
|
|
|
vcs_init();
|
|
|
|
vcs_uninit();
|
|
|
|
vcs_init();
|
|
|
|
vcs_start_auth_session();
|
|
|
|
vcs_uninit();
|
|
|
|
sensor_uninit();
|
|
|
|
pthread_mutex_unlock(&vdev->lock);
|
|
|
|
|
2016-02-17 14:23:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct hw_module_methods_t fingerprint_module_methods = {
|
|
|
|
.open = fingerprint_open,
|
|
|
|
};
|
|
|
|
|
|
|
|
fingerprint_module_t HAL_MODULE_INFO_SYM = {
|
|
|
|
.common = {
|
|
|
|
.tag = HARDWARE_MODULE_TAG,
|
2017-12-23 00:04:30 +00:00
|
|
|
.module_api_version = FINGERPRINT_MODULE_API_VERSION_2_1,
|
2016-02-17 14:23:55 +00:00
|
|
|
.hal_api_version = HARDWARE_HAL_API_VERSION,
|
|
|
|
.id = FINGERPRINT_HARDWARE_MODULE_ID,
|
|
|
|
.name = "KLTE Fingerprint HAL",
|
|
|
|
.author = "ljzyal(ljzyal@gmail.com)",
|
|
|
|
.methods = &fingerprint_module_methods,
|
|
|
|
},
|
|
|
|
};
|