Repository navigation
Expand file tree
/
Copy pathfpsensor_utils.cc
More file actions
66 lines (54 loc) · 1.71 KB
/
Copy pathfpsensor_utils.cc
File metadata and controls
66 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Copyright 2024 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "ec_commands.h"
#include "fpsensor/fpsensor_utils.h"
#include "overflow.h"
#include <stdio.h>
#include <cctype>
#include <string>
bool fp_match_success(int match_result)
{
return match_result == EC_MKBP_FP_ERR_MATCH_YES ||
match_result == EC_MKBP_FP_ERR_MATCH_YES_UPDATED ||
match_result == EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED;
}
enum ec_error_list validate_fp_buffer_offset(const uint32_t buffer_size,
const uint32_t offset,
const uint32_t size)
{
uint32_t bytes_requested;
if (check_add_overflow(size, offset, &bytes_requested))
return EC_ERROR_OVERFLOW;
if (bytes_requested > buffer_size)
return EC_ERROR_INVAL;
return EC_SUCCESS;
}
bool is_finger_needed(uint32_t mode)
{
int capture_type = FP_CAPTURE_TYPE(mode);
return !((mode & FP_MODE_CAPTURE) &&
(capture_type == FP_CAPTURE_DEFECT_PXL_TEST ||
capture_type == FP_CAPTURE_ABNORMAL_TEST ||
capture_type == FP_CAPTURE_NOISE_TEST ||
capture_type == FP_CAPTURE_PATTERN0 ||
capture_type == FP_CAPTURE_PATTERN1 ||
capture_type == FP_CAPTURE_RESET_TEST));
}
bool skip_image_offset(enum fp_capture_type capture_type)
{
return !(capture_type == FP_CAPTURE_VENDOR_FORMAT ||
capture_type == FP_CAPTURE_QUALITY_TEST);
}
const std::string fourcc_to_string(uint32_t value)
{
std::string str(4, '.');
auto get_char = [&value](int index) {
const unsigned char ch = (value >> (index * 8)) & 0xFF;
return std::isprint(ch) ? ch : '.';
};
snprintf(str.data(), str.size() + 1, "%c%c%c%c", get_char(0),
get_char(1), get_char(2), get_char(3));
return str;
}