diff options
Diffstat (limited to 'common/fpsensor/fpsensor.c')
-rw-r--r-- | common/fpsensor/fpsensor.c | 109 |
1 files changed, 41 insertions, 68 deletions
diff --git a/common/fpsensor/fpsensor.c b/common/fpsensor/fpsensor.c index 7c032ddae8..08a456dc0e 100644 --- a/common/fpsensor/fpsensor.c +++ b/common/fpsensor/fpsensor.c @@ -51,9 +51,6 @@ static timestamp_t encryption_deadline; /* Delay between 2 s of the sensor to detect finger removal */ #define FINGER_POLLING_DELAY (100*MSEC) -/* Fp sensor driver interface. */ -struct fp_sensor_interface *fp_driver; - /* Timing statistics. */ static uint32_t capture_time_us; static uint32_t matching_time_us; @@ -112,17 +109,14 @@ static uint32_t fp_process_enroll(void) /* begin/continue enrollment */ CPRINTS("[%d]Enrolling ...", templ_valid); - res = fp_driver->fp_finger_enroll(fp_buffer, &percent); - + res = fp_finger_enroll(fp_buffer, &percent); CPRINTS("[%d]Enroll =>%d (%d%%)", templ_valid, res, percent); if (res < 0) return EC_MKBP_FP_ENROLL | EC_MKBP_FP_ERRCODE(EC_MKBP_FP_ERR_ENROLL_INTERNAL); templ_dirty |= BIT(templ_valid); if (percent == 100) { - res = fp_driver->fp_enrollment_finish( - fp_template + - templ_valid * fp_driver->algorithm_template_size); + res = fp_enrollment_finish(fp_template[templ_valid]); if (res) { res = EC_MKBP_FP_ERR_ENROLL_INTERNAL; } else { @@ -149,8 +143,8 @@ static uint32_t fp_process_match(void) fp_disable_positive_match_secret(&positive_match_secret_state); CPRINTS("Matching/%d ...", templ_valid); if (templ_valid) { - res = fp_driver->fp_finger_match(fp_template, templ_valid, - fp_buffer, &fgr, &updated); + res = fp_finger_match(fp_template[0], templ_valid, fp_buffer, + &fgr, &updated); CPRINTS("Match =>%d (finger %d)", res, fgr); if (res < 0 || fgr < 0 || fgr >= FP_MAX_FINGER_COUNT) { res = EC_MKBP_FP_ERR_MATCH_NO_INTERNAL; @@ -174,9 +168,8 @@ static uint32_t fp_process_match(void) static void fp_process_finger(void) { timestamp_t t0 = get_time(); - int res = fp_driver->fp_sensor_acquire_image_with_mode_( - fp_buffer, FP_CAPTURE_TYPE(sensor_mode)); - + int res = fp_sensor_acquire_image_with_mode(fp_buffer, + FP_CAPTURE_TYPE(sensor_mode)); capture_time_us = time_since32(t0); if (!res) { uint32_t evt = EC_MKBP_FP_IMAGE_READY; @@ -217,7 +210,7 @@ void fp_task(void) #ifdef HAVE_FP_PRIVATE_DRIVER /* Reset and initialize the sensor IC */ - fp_driver->fp_sensor_init(); + fp_sensor_init(); while (1) { uint32_t evt; @@ -232,29 +225,28 @@ void fp_task(void) gpio_disable_interrupt(GPIO_FPS_INT); if ((mode ^ enroll_session) & FP_MODE_ENROLL_SESSION) { if (mode & FP_MODE_ENROLL_SESSION) { - if (fp_driver->fp_enrollment_begin()) + if (fp_enrollment_begin()) sensor_mode &= ~FP_MODE_ENROLL_SESSION; } else { - fp_driver->fp_enrollment_finish(NULL); + fp_enrollment_finish(NULL); } enroll_session = sensor_mode & FP_MODE_ENROLL_SESSION; } if (is_test_capture(mode)) { - fp_driver->fp_sensor_acquire_image_with_mode_( - fp_buffer, FP_CAPTURE_TYPE(mode)); + fp_sensor_acquire_image_with_mode(fp_buffer, + FP_CAPTURE_TYPE(mode)); sensor_mode &= ~FP_MODE_CAPTURE; send_mkbp_event(EC_MKBP_FP_IMAGE_READY); continue; } else if (sensor_mode & FP_MODE_ANY_DETECT_FINGER) { /* wait for a finger on the sensor */ - fp_driver->fp_sensor_configure_detect_(); + fp_sensor_configure_detect(); } - if (sensor_mode & FP_MODE_DEEPSLEEP) { + if (sensor_mode & FP_MODE_DEEPSLEEP) /* Shutdown the sensor */ - fp_driver->fp_sensor_low_power(); - } + fp_sensor_low_power(); if (sensor_mode & FP_MODE_FINGER_UP) /* Poll the sensor to detect finger removal */ timeout_us = FINGER_POLLING_DELAY; @@ -266,17 +258,17 @@ void fp_task(void) fp_reset_and_clear_context(); sensor_mode &= ~FP_MODE_RESET_SENSOR; } else if (mode & FP_MODE_SENSOR_MAINTENANCE) { - fp_driver->fp_maintenance(); + fp_maintenance(); sensor_mode &= ~FP_MODE_SENSOR_MAINTENANCE; } else { - fp_driver->fp_sensor_low_power(); + fp_sensor_low_power(); } } else if (evt & (TASK_EVENT_SENSOR_IRQ | TASK_EVENT_TIMER)) { overall_t0 = get_time(); timestamps_invalid = 0; gpio_disable_interrupt(GPIO_FPS_INT); if (sensor_mode & FP_MODE_ANY_DETECT_FINGER) { - st = fp_driver->fp_sensor_finger_status_(); + st = fp_sensor_finger_status(); if (st == FINGER_PRESENT && sensor_mode & FP_MODE_FINGER_DOWN) { CPRINTS("Finger!"); @@ -296,10 +288,10 @@ void fp_task(void) fp_process_finger(); if (sensor_mode & FP_MODE_ANY_WAIT_IRQ) { - fp_driver->fp_sensor_configure_detect_(); + fp_sensor_configure_detect(); gpio_enable_interrupt(GPIO_FPS_INT); } else { - fp_driver->fp_sensor_low_power(); + fp_sensor_low_power(); } } } @@ -349,11 +341,11 @@ static enum ec_status fp_command_info(struct host_cmd_handler_args *args) struct ec_response_fp_info *r = args->response; #ifdef HAVE_FP_PRIVATE_DRIVER - if (fp_driver->fp_sensor_get_info(r) < 0) + if (fp_sensor_get_info(r) < 0) #endif return EC_RES_UNAVAILABLE; - r->template_size = fp_driver->encrypted_template_size; + r->template_size = FP_ALGORITHM_ENCRYPTED_TEMPLATE_SIZE; r->template_max = FP_MAX_FINGER_COUNT; r->template_valid = templ_valid; r->template_dirty = templ_dirty; @@ -405,12 +397,8 @@ static enum ec_status fp_command_frame(struct host_cmd_handler_args *args) if (!is_raw_capture(sensor_mode)) offset += FP_SENSOR_IMAGE_OFFSET; - /* - * Check the requested data is within the template size. - * This is stricter than checking buffer overflow. - */ - ret = validate_fp_buffer_offset( - fp_driver->algorithm_template_size, offset, size); + ret = validate_fp_buffer_offset(sizeof(fp_buffer), offset, + size); if (ret != EC_SUCCESS) return EC_RES_INVALID_PARAM; @@ -428,12 +416,7 @@ static enum ec_status fp_command_frame(struct host_cmd_handler_args *args) return EC_RES_INVALID_PARAM; if (fgr >= templ_valid) return EC_RES_UNAVAILABLE; - /* - * Check the requested data is within the encrypted template size. - * This is stricter than checking buffer overflow. - */ - ret = validate_fp_buffer_offset(fp_driver->encrypted_template_size, - offset, size); + ret = validate_fp_buffer_offset(sizeof(fp_enc_buffer), offset, size); if (ret != EC_SUCCESS) return EC_RES_INVALID_PARAM; @@ -444,10 +427,9 @@ static enum ec_status fp_command_frame(struct host_cmd_handler_args *args) uint8_t *encrypted_template = fp_enc_buffer + sizeof(*enc_info); /* Positive match salt is after the template. */ uint8_t *positive_match_salt = - encrypted_template + fp_driver->algorithm_template_size; - size_t encrypted_blob_size = - fp_driver->algorithm_template_size + - sizeof(fp_positive_match_salt[0]); + encrypted_template + sizeof(fp_template[0]); + size_t encrypted_blob_size = sizeof(fp_template[0]) + + sizeof(fp_positive_match_salt[0]); /* b/114160734: Not more than 1 encrypted message per second. */ if (!timestamp_expired(encryption_deadline, &now)) @@ -490,9 +472,8 @@ static enum ec_status fp_command_frame(struct host_cmd_handler_args *args) * Copy the payload to |fp_enc_buffer| where it will be * encrypted in-place. */ - memcpy(encrypted_template, - fp_template + fgr * fp_driver->algorithm_template_size, - fp_driver->algorithm_template_size); + memcpy(encrypted_template, fp_template[fgr], + sizeof(fp_template[0])); memcpy(positive_match_salt, fp_positive_match_salt[fgr], sizeof(fp_positive_match_salt[0])); @@ -576,12 +557,7 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args) if (args->params_size != size + offsetof(struct ec_params_fp_template, data)) return EC_RES_INVALID_PARAM; - /* - * Check the received data fits within the encrypted template size. - * This is stricter than checking buffer overflow. - */ - ret = validate_fp_buffer_offset(fp_driver->encrypted_template_size, - offset, size); + ret = validate_fp_buffer_offset(sizeof(fp_enc_buffer), offset, size); if (ret != EC_SUCCESS) return EC_RES_INVALID_PARAM; @@ -592,7 +568,7 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args) uint8_t *encrypted_template = fp_enc_buffer + sizeof(*enc_info); /* Positive match salt is after the template. */ uint8_t *positive_match_salt = - encrypted_template + fp_driver->algorithm_template_size; + encrypted_template + sizeof(fp_template[0]); size_t encrypted_blob_size; /* @@ -612,11 +588,10 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args) } if (enc_info->struct_version <= 3) { - encrypted_blob_size = - fp_driver->algorithm_template_size; + encrypted_blob_size = sizeof(fp_template[0]); } else { encrypted_blob_size = - fp_driver->algorithm_template_size + + sizeof(fp_template[0]) + sizeof(fp_positive_match_salt[0]); } @@ -639,8 +614,8 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args) fp_clear_finger_context(idx); return EC_RES_UNAVAILABLE; } - memcpy(fp_template + idx * fp_driver->algorithm_template_size, - encrypted_template, fp_driver->algorithm_template_size); + memcpy(fp_template[idx], encrypted_template, + sizeof(fp_template[0])); if (template_needs_validation_value(enc_info)) { CPRINTS("fgr%d: Generating positive match salt.", idx); init_trng(); @@ -651,10 +626,8 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args) if (bytes_are_trivial(positive_match_salt, sizeof(fp_positive_match_salt[0]))) { CPRINTS("fgr%d: Trivial positive match salt.", idx); - always_memset( - fp_template + - idx * fp_driver->algorithm_template_size, - 0, fp_driver->algorithm_template_size); + always_memset(fp_template[idx], 0, + sizeof(fp_template[0])); return EC_RES_INVALID_PARAM; } memcpy(fp_positive_match_salt[idx], positive_match_salt, @@ -717,11 +690,11 @@ static void upload_pgm_image(uint8_t *frame) CPRINTF("#IGNORE for ZModem\r**\030B00"); msleep(2000); /* let the download program start */ /* Print 8-bpp PGM ASCII header */ - CPRINTF("P2\n%d %d\n255\n", fp_driver->res_x, fp_driver->res_y); + CPRINTF("P2\n%d %d\n255\n", FP_SENSOR_RES_X, FP_SENSOR_RES_Y); - for (y = 0; y < fp_driver->res_y; y++) { + for (y = 0; y < FP_SENSOR_RES_Y; y++) { watchdog_reload(); - for (x = 0; x < fp_driver->res_x; x++, ptr++) + for (x = 0; x < FP_SENSOR_RES_X; x++, ptr++) CPRINTF("%d ", *ptr); CPRINTF("\n"); cflush(); @@ -873,7 +846,7 @@ DECLARE_CONSOLE_COMMAND(fpclear, command_fpclear, NULL, int command_fpmaintenance(int argc, char **argv) { #ifdef HAVE_FP_PRIVATE_DRIVER - return fp_driver->fp_maintenance(); + return fp_maintenance(); #else return EC_SUCCESS; #endif /* #ifdef HAVE_FP_PRIVATE_DRIVER */ |