blob: ac88c10322c5c947c5772fb6dd1e334d8e6d35f6 [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
Jim Miller929e0a12015-07-24 18:25:40 -070034/*
35 * Fingerprint errors are meant to tell the framework to terminate the current operation and ask
36 * for the user to correct the situation. These will almost always result in messaging and user
37 * interaction to correct the problem.
38 *
39 * For example, FINGERPRINT_ERROR_CANCELED should follow any acquisition message that results in
40 * a situation where the current operation can't continue without user interaction. For example,
41 * if the sensor is dirty during enrollment and no further enrollment progress can be made,
42 * send FINGERPRINT_ACQUIRED_IMAGER_DIRTY followed by FINGERPRINT_ERROR_CANCELED.
43 */
Sasha Levitskiya747c062014-03-24 16:14:42 -070044typedef enum fingerprint_error {
Jim Miller929e0a12015-07-24 18:25:40 -070045 FINGERPRINT_ERROR_HW_UNAVAILABLE = 1, /* The hardware has an error that can't be resolved. */
46 FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2, /* Bad data; operation can't continue */
47 FINGERPRINT_ERROR_TIMEOUT = 3, /* The operation has timed out waiting for user input. */
Jim Miller1fb1e332015-03-24 19:25:47 -070048 FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
Jim Miller929e0a12015-07-24 18:25:40 -070049 FINGERPRINT_ERROR_CANCELED = 5, /* The current operation can't proceed. See above. */
50 FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint with given id can't be removed */
Jim Miller1fb1e332015-03-24 19:25:47 -070051 FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
Sasha Levitskiya747c062014-03-24 16:14:42 -070052} fingerprint_error_t;
53
Jim Miller929e0a12015-07-24 18:25:40 -070054/*
55 * Fingerprint acquisition info is meant as feedback for the current operation. Anything but
56 * FINGERPRINT_ACQUIRED_GOOD will be shown to the user as feedback on how to take action on the
57 * current operation. For example, FINGERPRINT_ACQUIRED_IMAGER_DIRTY can be used to tell the user
58 * to clean the sensor. If this will cause the current operation to fail, an additional
59 * FINGERPRINT_ERROR_CANCELED can be sent to stop the operation in progress (e.g. enrollment).
60 * In general, these messages will result in a "Try again" message.
61 */
Jim Miller953524b2014-06-16 17:59:40 -070062typedef enum fingerprint_acquired_info {
63 FINGERPRINT_ACQUIRED_GOOD = 0,
Jim Miller929e0a12015-07-24 18:25:40 -070064 FINGERPRINT_ACQUIRED_PARTIAL = 1, /* sensor needs more data, i.e. longer swipe. */
65 FINGERPRINT_ACQUIRED_INSUFFICIENT = 2, /* image doesn't contain enough detail for recognition*/
66 FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3, /* sensor needs to be cleaned */
67 FINGERPRINT_ACQUIRED_TOO_SLOW = 4, /* mostly swipe-type sensors; not enough data collected */
68 FINGERPRINT_ACQUIRED_TOO_FAST = 5, /* for swipe and area sensors; tell user to slow down*/
Jim Miller1fb1e332015-03-24 19:25:47 -070069 FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
Jim Miller953524b2014-06-16 17:59:40 -070070} fingerprint_acquired_info_t;
Sasha Levitskiyba45e052014-06-09 13:19:52 -070071
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080072typedef struct fingerprint_finger_id {
73 uint32_t gid;
74 uint32_t fid;
75} fingerprint_finger_id_t;
76
Sasha Levitskiy73082842014-04-18 11:14:11 -070077typedef struct fingerprint_enroll {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080078 fingerprint_finger_id_t finger;
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -070079 /* samples_remaining goes from N (no data collected, but N scans needed)
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080080 * to 0 (no more data is needed to build a template). */
Jim Miller1fb1e332015-03-24 19:25:47 -070081 uint32_t samples_remaining;
Sasha Levitskiya70ab952015-06-02 11:29:12 -070082 uint64_t msg; /* Vendor specific message. Used for user guidance */
Sasha Levitskiy73082842014-04-18 11:14:11 -070083} fingerprint_enroll_t;
84
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070085typedef struct fingerprint_removed {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080086 fingerprint_finger_id_t finger;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070087} fingerprint_removed_t;
88
Sasha Levitskiyba45e052014-06-09 13:19:52 -070089typedef struct fingerprint_acquired {
Jim Miller953524b2014-06-16 17:59:40 -070090 fingerprint_acquired_info_t acquired_info; /* information about the image */
Sasha Levitskiyba45e052014-06-09 13:19:52 -070091} fingerprint_acquired_t;
92
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080093typedef struct fingerprint_authenticated {
Sasha Levitskiy6eced702015-04-12 22:58:21 -070094 fingerprint_finger_id_t finger;
95 hw_auth_token_t hat;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080096} fingerprint_authenticated_t;
97
Sasha Levitskiy73082842014-04-18 11:14:11 -070098typedef struct fingerprint_msg {
99 fingerprint_msg_type_t type;
100 union {
Sasha Levitskiy73082842014-04-18 11:14:11 -0700101 fingerprint_error_t error;
102 fingerprint_enroll_t enroll;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700103 fingerprint_removed_t removed;
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700104 fingerprint_acquired_t acquired;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800105 fingerprint_authenticated_t authenticated;
Sasha Levitskiy73082842014-04-18 11:14:11 -0700106 } data;
107} fingerprint_msg_t;
108
109/* Callback function type */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700110typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
Sasha Levitskiy73082842014-04-18 11:14:11 -0700111
Sasha Levitskiya747c062014-03-24 16:14:42 -0700112/* Synchronous operation */
113typedef struct fingerprint_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700114 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700115 * Common methods of the fingerprint device. This *must* be the first member
116 * of fingerprint_device as users of this structure will cast a hw_device_t
117 * to fingerprint_device pointer in contexts where it's known
118 * the hw_device_t references a fingerprint_device.
Stewart Miles84d35492014-05-01 09:03:27 -0700119 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700120 struct hw_device_t common;
121
122 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700123 * Client provided callback function to receive notifications.
124 * Do not set by hand, use the function above instead.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700125 */
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700126 fingerprint_notify_t notify;
127
128 /*
129 * Set notification callback:
130 * Registers a user function that would receive notifications from the HAL
131 * The call will block if the HAL state machine is in busy state until HAL
132 * leaves the busy state.
133 *
134 * Function return: 0 if callback function is successfuly registered
135 * or a negative number in case of error, generally from the errno.h set.
136 */
137 int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700138
139 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700140 * Fingerprint pre-enroll enroll request:
141 * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
142 * This token will be wrapped by security for verification and passed to enroll() for
143 * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
144 * template was preceded by some kind of credential confirmation (e.g. device password).
145 *
146 * Function return: 0 if function failed
147 * otherwise, a uint64_t of token
148 */
149 uint64_t (*pre_enroll)(struct fingerprint_device *dev);
150
151 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700152 * Fingerprint enroll request:
153 * Switches the HAL state machine to collect and store a new fingerprint
154 * template. Switches back as soon as enroll is complete
155 * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
156 * fingerprint_msg.data.enroll.samples_remaining == 0)
157 * or after timeout_sec seconds.
158 * The fingerprint template will be assigned to the group gid. User has a choice
159 * to supply the gid or set it to 0 in which case a unique group id will be generated.
160 *
161 * Function return: 0 if enrollment process can be successfully started
162 * or a negative number in case of error, generally from the errno.h set.
163 * A notify() function may be called indicating the error condition.
164 */
165 int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
166 uint32_t gid, uint32_t timeout_sec);
167
168 /*
169 * Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
170 * This will be called at the end of a multi-finger enrollment session to indicate
171 * that no more fingers will be added.
172 *
173 * Function return: 0 if the request is accepted
174 * or a negative number in case of error, generally from the errno.h set.
175 */
176 int (*post_enroll)(struct fingerprint_device *dev);
177
178 /*
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700179 * get_authenticator_id:
180 * Returns a token associated with the current fingerprint set. This value will
181 * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
182 * set.
183 *
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700184 * Function return: current authenticator id or 0 if function failed.
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700185 */
186 uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
187
188 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700189 * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
190 * to all running clients. Switches the HAL state machine back to the idle state.
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700191 * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700192 *
193 * Function return: 0 if cancel request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700194 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700195 */
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700196 int (*cancel)(struct fingerprint_device *dev);
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700197
198 /*
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700199 * Enumerate all the fingerprint templates found in the directory set by
200 * set_active_group()
201 * This is a synchronous call. The function takes:
202 * - A pointer to an array of fingerprint_finger_id_t.
203 * - The size of the array provided, in fingerprint_finger_id_t elements.
204 * Max_size is a bi-directional parameter and returns the actual number
205 * of elements copied to the caller supplied array.
206 * In the absence of errors the function returns the total number of templates
207 * in the user directory.
208 * If the caller has no good guess on the size of the array he should call this
209 * function witn *max_size == 0 and use the return value for the array allocation.
210 * The caller of this function has a complete list of the templates when *max_size
211 * is the same as the function return.
212 *
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700213 * Function return: Total number of fingerprint templates in the current storage directory.
214 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700215 */
216 int (*enumerate)(struct fingerprint_device *dev, fingerprint_finger_id_t *results,
217 uint32_t *max_size);
218
219 /*
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700220 * Fingerprint remove request:
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700221 * Deletes a fingerprint template.
222 * Works only within a path set by set_active_group().
223 * notify() will be called with details on the template deleted.
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700224 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700225 * fingerprint_msg.data.removed.id indicating the template id removed.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700226 *
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700227 * Function return: 0 if fingerprint template(s) can be successfully deleted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700228 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700229 */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700230 int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800231
232 /*
233 * Restricts the HAL operation to a set of fingerprints belonging to a
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700234 * group provided.
235 * The caller must provide a path to a storage location within the user's
236 * data directory.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800237 *
238 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700239 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800240 */
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700241 int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
242 const char *store_path);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800243
244 /*
245 * Authenticates an operation identifed by operation_id
246 *
247 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700248 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800249 */
Jim Miller1fb1e332015-03-24 19:25:47 -0700250 int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700251
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700252 /* Reserved for backward binary compatibility */
253 void *reserved[4];
Sasha Levitskiya747c062014-03-24 16:14:42 -0700254} fingerprint_device_t;
255
256typedef struct fingerprint_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700257 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700258 * Common methods of the fingerprint module. This *must* be the first member
259 * of fingerprint_module as users of this structure will cast a hw_module_t
260 * to fingerprint_module pointer in contexts where it's known
261 * the hw_module_t references a fingerprint_module.
Stewart Miles84d35492014-05-01 09:03:27 -0700262 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700263 struct hw_module_t common;
264} fingerprint_module_t;
265
Sasha Levitskiya747c062014-03-24 16:14:42 -0700266#endif /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */