blob: 552b5d790956d9172f01e2b01f030c118c47d3d7 [file] [log] [blame]
Sasha Levitskiya747c062014-03-24 16:14:42 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H
18#define ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H
19
Sasha Levitskiy6eced702015-04-12 22:58:21 -070020#include <hardware/hw_auth_token.h>
21
Sasha Levitskiya747c062014-03-24 16:14:42 -070022#define FINGERPRINT_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080023#define FINGERPRINT_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Sasha Levitskiya747c062014-03-24 16:14:42 -070024#define FINGERPRINT_HARDWARE_MODULE_ID "fingerprint"
25
Sasha Levitskiy73082842014-04-18 11:14:11 -070026typedef enum fingerprint_msg_type {
Sasha Levitskiya747c062014-03-24 16:14:42 -070027 FINGERPRINT_ERROR = -1,
Sasha Levitskiyba45e052014-06-09 13:19:52 -070028 FINGERPRINT_ACQUIRED = 1,
Sasha Levitskiyba45e052014-06-09 13:19:52 -070029 FINGERPRINT_TEMPLATE_ENROLLING = 3,
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080030 FINGERPRINT_TEMPLATE_REMOVED = 4,
31 FINGERPRINT_AUTHENTICATED = 5
Sasha Levitskiy73082842014-04-18 11:14:11 -070032} fingerprint_msg_type_t;
Sasha Levitskiya747c062014-03-24 16:14:42 -070033
34typedef enum fingerprint_error {
35 FINGERPRINT_ERROR_HW_UNAVAILABLE = 1,
Sasha Levitskiyba45e052014-06-09 13:19:52 -070036 FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2,
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070037 FINGERPRINT_ERROR_TIMEOUT = 3,
Jim Miller1fb1e332015-03-24 19:25:47 -070038 FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
39 FINGERPRINT_ERROR_CANCELED = 5,
40 FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint id can't be removed */
41 FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
Sasha Levitskiya747c062014-03-24 16:14:42 -070042} fingerprint_error_t;
43
Jim Miller953524b2014-06-16 17:59:40 -070044typedef enum fingerprint_acquired_info {
45 FINGERPRINT_ACQUIRED_GOOD = 0,
46 FINGERPRINT_ACQUIRED_PARTIAL = 1,
47 FINGERPRINT_ACQUIRED_INSUFFICIENT = 2,
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080048 FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3,
49 FINGERPRINT_ACQUIRED_TOO_SLOW = 4,
50 FINGERPRINT_ACQUIRED_TOO_FAST = 5,
Jim Miller1fb1e332015-03-24 19:25:47 -070051 FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
Jim Miller953524b2014-06-16 17:59:40 -070052} fingerprint_acquired_info_t;
Sasha Levitskiyba45e052014-06-09 13:19:52 -070053
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080054typedef struct fingerprint_finger_id {
55 uint32_t gid;
56 uint32_t fid;
57} fingerprint_finger_id_t;
58
59/* The progress indication may be augmented by a bitmap encoded indication
60* of what finger area is considered as collected.
61* Bit numbers mapped to physical location:
62*
63* distal
64* +--+--+--+--+--+
65* | 4| 3| 2| 1| 0|
66* | 9| 8| 7| 6| 5|
67* medial |14|13|12|11|10| lateral
68* |19|18|17|16|15|
69* |24|23|22|21|20|
70* +--+--+--+--+--+
71* proximal
72*
73*/
74typedef uint32_t finger_map_bmp;
75
76typedef enum fingerprint_enroll_msg_type {
77 FINGERPRINT_ENROLL_MSG_NONE = 0,
78 FINGERPRINT_ENROLL_MSG_PREDEFINED = 1, /* TODO: define standard enroll cues */
79 FINGERPRINT_ENROLL_MSG_BITMAP = 2, /* typeof(fingerprint_enroll.msg) == *finger_map_bmp */
80 FINGERPRINT_ENROLL_MSG_VENDOR = 3
81} fingerprint_enroll_msg_type_t;
82
Sasha Levitskiy73082842014-04-18 11:14:11 -070083typedef struct fingerprint_enroll {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080084 fingerprint_finger_id_t finger;
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -070085 /* samples_remaining goes from N (no data collected, but N scans needed)
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080086 * to 0 (no more data is needed to build a template). */
Jim Miller1fb1e332015-03-24 19:25:47 -070087 uint32_t samples_remaining;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080088 fingerprint_enroll_msg_type_t msg_type;
89 size_t msg_size;
90 void *msg;
Sasha Levitskiy73082842014-04-18 11:14:11 -070091} fingerprint_enroll_t;
92
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070093typedef struct fingerprint_removed {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080094 fingerprint_finger_id_t finger;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070095} fingerprint_removed_t;
96
Sasha Levitskiyba45e052014-06-09 13:19:52 -070097typedef struct fingerprint_acquired {
Jim Miller953524b2014-06-16 17:59:40 -070098 fingerprint_acquired_info_t acquired_info; /* information about the image */
Sasha Levitskiyba45e052014-06-09 13:19:52 -070099} fingerprint_acquired_t;
100
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800101typedef struct fingerprint_authenticated {
Sasha Levitskiy6eced702015-04-12 22:58:21 -0700102 fingerprint_finger_id_t finger;
103 hw_auth_token_t hat;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800104} fingerprint_authenticated_t;
105
Sasha Levitskiy73082842014-04-18 11:14:11 -0700106typedef struct fingerprint_msg {
107 fingerprint_msg_type_t type;
108 union {
Sasha Levitskiy73082842014-04-18 11:14:11 -0700109 fingerprint_error_t error;
110 fingerprint_enroll_t enroll;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700111 fingerprint_removed_t removed;
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700112 fingerprint_acquired_t acquired;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800113 fingerprint_authenticated_t authenticated;
Sasha Levitskiy73082842014-04-18 11:14:11 -0700114 } data;
115} fingerprint_msg_t;
116
117/* Callback function type */
118typedef void (*fingerprint_notify_t)(fingerprint_msg_t msg);
119
Sasha Levitskiya747c062014-03-24 16:14:42 -0700120/* Synchronous operation */
121typedef struct fingerprint_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700122 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700123 * Common methods of the fingerprint device. This *must* be the first member
124 * of fingerprint_device as users of this structure will cast a hw_device_t
125 * to fingerprint_device pointer in contexts where it's known
126 * the hw_device_t references a fingerprint_device.
Stewart Miles84d35492014-05-01 09:03:27 -0700127 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700128 struct hw_device_t common;
129
130 /*
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700131 * Fingerprint enroll request:
Sasha Levitskiy73082842014-04-18 11:14:11 -0700132 * Switches the HAL state machine to collect and store a new fingerprint
133 * template. Switches back as soon as enroll is complete
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700134 * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
Sasha Levitskiy73082842014-04-18 11:14:11 -0700135 * fingerprint_msg.data.enroll.samples_remaining == 0)
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700136 * or after timeout_sec seconds.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800137 * The fingerprint template will be assigned to the group gid. User has a choice
138 * to supply the gid or set it to 0 in which case a unique group id will be generated.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700139 *
Sasha Levitskiy73082842014-04-18 11:14:11 -0700140 * Function return: 0 if enrollment process can be successfully started
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700141 * -1 otherwise. A notify() function may be called
142 * indicating the error condition.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700143 */
Sasha Levitskiy6eced702015-04-12 22:58:21 -0700144 int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
145 uint32_t gid, uint32_t timeout_sec);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700146
147 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700148 * Fingerprint pre-enroll enroll request:
149 * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
150 * This token will be wrapped by security for verification and passed to enroll() for
151 * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
152 * template was preceded by some kind of credential confirmation (e.g. device password).
153 *
154 * Function return: 0 if function failed
155 * otherwise, a uint64_t of token
156 */
157 uint64_t (*pre_enroll)(struct fingerprint_device *dev);
158
159 /*
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700160 * get_authenticator_id:
161 * Returns a token associated with the current fingerprint set. This value will
162 * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
163 * set.
164 *
165 * Function return: current authenticator id.
166 */
167 uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
168
169 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700170 * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
171 * to all running clients. Switches the HAL state machine back to the idle state.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700172 * will indicate switch back to the scan mode.
173 *
174 * Function return: 0 if cancel request is accepted
175 * -1 otherwise.
176 */
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700177 int (*cancel)(struct fingerprint_device *dev);
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700178
179 /*
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700180 * Fingerprint remove request:
Sasha Levitskiy73082842014-04-18 11:14:11 -0700181 * deletes a fingerprint template.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800182 * If the fingerprint id is 0 and the group is 0 then the entire template
183 * database will be removed. A combinaiton of fingerprint id 0 and a valid
184 * group id deletes all fingreprints in that group.
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700185 * notify() will be called for each template deleted with
186 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
187 * fingerprint_msg.data.removed.id indicating each template id removed.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700188 *
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700189 * Function return: 0 if fingerprint template(s) can be successfully deleted
Sasha Levitskiy73082842014-04-18 11:14:11 -0700190 * -1 otherwise.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700191 */
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800192 int (*remove)(struct fingerprint_device *dev, fingerprint_finger_id_t finger);
193
194 /*
195 * Restricts the HAL operation to a set of fingerprints belonging to a
196 * group provided. Gid of 0 signals global operation.
197 *
198 * Function return: 0 on success
199 * -1 if the group does not exist.
200 */
201 int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid);
202
203 /*
204 * Authenticates an operation identifed by operation_id
205 *
206 * Function return: 0 on success
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700207 * -1 if the operation cannot be completed
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800208 */
Jim Miller1fb1e332015-03-24 19:25:47 -0700209 int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700210
211 /*
Sasha Levitskiy73082842014-04-18 11:14:11 -0700212 * Set notification callback:
213 * Registers a user function that would receive notifications from the HAL
214 * The call will block if the HAL state machine is in busy state until HAL
215 * leaves the busy state.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700216 *
Sasha Levitskiy73082842014-04-18 11:14:11 -0700217 * Function return: 0 if callback function is successfuly registered
218 * -1 otherwise.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700219 */
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700220 int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
Sasha Levitskiy73082842014-04-18 11:14:11 -0700221
222 /*
223 * Client provided callback function to receive notifications.
224 * Do not set by hand, use the function above instead.
225 */
226 fingerprint_notify_t notify;
Sasha Levitskiya747c062014-03-24 16:14:42 -0700227} fingerprint_device_t;
228
229typedef struct fingerprint_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700230 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700231 * Common methods of the fingerprint module. This *must* be the first member
232 * of fingerprint_module as users of this structure will cast a hw_module_t
233 * to fingerprint_module pointer in contexts where it's known
234 * the hw_module_t references a fingerprint_module.
Stewart Miles84d35492014-05-01 09:03:27 -0700235 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700236 struct hw_module_t common;
237} fingerprint_module_t;
238
Sasha Levitskiya747c062014-03-24 16:14:42 -0700239#endif /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */