blob: fd9ce46e9e978d81d4478800677b0663691688e3 [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>
Nick Vaccaroea09bc82016-04-19 15:07:46 -070021#include <hardware/hardware.h>
Sasha Levitskiy6eced702015-04-12 22:58:21 -070022
Sasha Levitskiya747c062014-03-24 16:14:42 -070023#define FINGERPRINT_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080024#define FINGERPRINT_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070025#define FINGERPRINT_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
Sasha Levitskiya747c062014-03-24 16:14:42 -070026#define FINGERPRINT_HARDWARE_MODULE_ID "fingerprint"
27
Sasha Levitskiy73082842014-04-18 11:14:11 -070028typedef enum fingerprint_msg_type {
Sasha Levitskiya747c062014-03-24 16:14:42 -070029 FINGERPRINT_ERROR = -1,
Sasha Levitskiyba45e052014-06-09 13:19:52 -070030 FINGERPRINT_ACQUIRED = 1,
Sasha Levitskiyba45e052014-06-09 13:19:52 -070031 FINGERPRINT_TEMPLATE_ENROLLING = 3,
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080032 FINGERPRINT_TEMPLATE_REMOVED = 4,
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070033 FINGERPRINT_AUTHENTICATED = 5,
34 FINGERPRINT_TEMPLATE_ENUMERATING = 6,
Sasha Levitskiy73082842014-04-18 11:14:11 -070035} fingerprint_msg_type_t;
Sasha Levitskiya747c062014-03-24 16:14:42 -070036
Jim Miller929e0a12015-07-24 18:25:40 -070037/*
38 * Fingerprint errors are meant to tell the framework to terminate the current operation and ask
39 * for the user to correct the situation. These will almost always result in messaging and user
40 * interaction to correct the problem.
41 *
42 * For example, FINGERPRINT_ERROR_CANCELED should follow any acquisition message that results in
43 * a situation where the current operation can't continue without user interaction. For example,
44 * if the sensor is dirty during enrollment and no further enrollment progress can be made,
45 * send FINGERPRINT_ACQUIRED_IMAGER_DIRTY followed by FINGERPRINT_ERROR_CANCELED.
46 */
Sasha Levitskiya747c062014-03-24 16:14:42 -070047typedef enum fingerprint_error {
Jim Miller929e0a12015-07-24 18:25:40 -070048 FINGERPRINT_ERROR_HW_UNAVAILABLE = 1, /* The hardware has an error that can't be resolved. */
49 FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2, /* Bad data; operation can't continue */
50 FINGERPRINT_ERROR_TIMEOUT = 3, /* The operation has timed out waiting for user input. */
Jim Miller1fb1e332015-03-24 19:25:47 -070051 FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
Jim Miller929e0a12015-07-24 18:25:40 -070052 FINGERPRINT_ERROR_CANCELED = 5, /* The current operation can't proceed. See above. */
53 FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint with given id can't be removed */
Sasha Levitskiy7e9204a2016-01-07 14:46:45 -080054 FINGERPRINT_ERROR_LOCKOUT = 7, /* the functionality is temporarily locked out */
Jim Miller1fb1e332015-03-24 19:25:47 -070055 FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
Sasha Levitskiya747c062014-03-24 16:14:42 -070056} fingerprint_error_t;
57
Jim Miller929e0a12015-07-24 18:25:40 -070058/*
59 * Fingerprint acquisition info is meant as feedback for the current operation. Anything but
60 * FINGERPRINT_ACQUIRED_GOOD will be shown to the user as feedback on how to take action on the
61 * current operation. For example, FINGERPRINT_ACQUIRED_IMAGER_DIRTY can be used to tell the user
62 * to clean the sensor. If this will cause the current operation to fail, an additional
63 * FINGERPRINT_ERROR_CANCELED can be sent to stop the operation in progress (e.g. enrollment).
64 * In general, these messages will result in a "Try again" message.
65 */
Jim Miller953524b2014-06-16 17:59:40 -070066typedef enum fingerprint_acquired_info {
67 FINGERPRINT_ACQUIRED_GOOD = 0,
Jim Miller929e0a12015-07-24 18:25:40 -070068 FINGERPRINT_ACQUIRED_PARTIAL = 1, /* sensor needs more data, i.e. longer swipe. */
69 FINGERPRINT_ACQUIRED_INSUFFICIENT = 2, /* image doesn't contain enough detail for recognition*/
70 FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3, /* sensor needs to be cleaned */
71 FINGERPRINT_ACQUIRED_TOO_SLOW = 4, /* mostly swipe-type sensors; not enough data collected */
72 FINGERPRINT_ACQUIRED_TOO_FAST = 5, /* for swipe and area sensors; tell user to slow down*/
Jim Miller1fb1e332015-03-24 19:25:47 -070073 FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
Jim Miller953524b2014-06-16 17:59:40 -070074} fingerprint_acquired_info_t;
Sasha Levitskiyba45e052014-06-09 13:19:52 -070075
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080076typedef struct fingerprint_finger_id {
77 uint32_t gid;
78 uint32_t fid;
79} fingerprint_finger_id_t;
80
Sasha Levitskiy73082842014-04-18 11:14:11 -070081typedef struct fingerprint_enroll {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080082 fingerprint_finger_id_t finger;
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -070083 /* samples_remaining goes from N (no data collected, but N scans needed)
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080084 * to 0 (no more data is needed to build a template). */
Jim Miller1fb1e332015-03-24 19:25:47 -070085 uint32_t samples_remaining;
Sasha Levitskiya70ab952015-06-02 11:29:12 -070086 uint64_t msg; /* Vendor specific message. Used for user guidance */
Sasha Levitskiy73082842014-04-18 11:14:11 -070087} fingerprint_enroll_t;
88
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070089typedef struct fingerprint_enumerated {
90 fingerprint_finger_id_t finger;
91 uint32_t remaining_templates;
92} fingerprint_enumerated_t;
93
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070094typedef struct fingerprint_removed {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080095 fingerprint_finger_id_t finger;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070096} fingerprint_removed_t;
97
Sasha Levitskiyba45e052014-06-09 13:19:52 -070098typedef struct fingerprint_acquired {
Jim Miller953524b2014-06-16 17:59:40 -070099 fingerprint_acquired_info_t acquired_info; /* information about the image */
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700100} fingerprint_acquired_t;
101
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800102typedef struct fingerprint_authenticated {
Sasha Levitskiy6eced702015-04-12 22:58:21 -0700103 fingerprint_finger_id_t finger;
104 hw_auth_token_t hat;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800105} fingerprint_authenticated_t;
106
Sasha Levitskiy73082842014-04-18 11:14:11 -0700107typedef struct fingerprint_msg {
108 fingerprint_msg_type_t type;
109 union {
Sasha Levitskiy73082842014-04-18 11:14:11 -0700110 fingerprint_error_t error;
111 fingerprint_enroll_t enroll;
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700112 fingerprint_enumerated_t enumerated;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700113 fingerprint_removed_t removed;
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700114 fingerprint_acquired_t acquired;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800115 fingerprint_authenticated_t authenticated;
Sasha Levitskiy73082842014-04-18 11:14:11 -0700116 } data;
117} fingerprint_msg_t;
118
119/* Callback function type */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700120typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
Sasha Levitskiy73082842014-04-18 11:14:11 -0700121
Sasha Levitskiya747c062014-03-24 16:14:42 -0700122/* Synchronous operation */
123typedef struct fingerprint_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700124 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700125 * Common methods of the fingerprint device. This *must* be the first member
126 * of fingerprint_device as users of this structure will cast a hw_device_t
127 * to fingerprint_device pointer in contexts where it's known
128 * the hw_device_t references a fingerprint_device.
Stewart Miles84d35492014-05-01 09:03:27 -0700129 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700130 struct hw_device_t common;
131
132 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700133 * Client provided callback function to receive notifications.
134 * Do not set by hand, use the function above instead.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700135 */
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700136 fingerprint_notify_t notify;
137
138 /*
139 * Set notification callback:
140 * Registers a user function that would receive notifications from the HAL
141 * The call will block if the HAL state machine is in busy state until HAL
142 * leaves the busy state.
143 *
144 * Function return: 0 if callback function is successfuly registered
145 * or a negative number in case of error, generally from the errno.h set.
146 */
147 int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700148
149 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700150 * Fingerprint pre-enroll enroll request:
151 * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
152 * This token will be wrapped by security for verification and passed to enroll() for
153 * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
154 * template was preceded by some kind of credential confirmation (e.g. device password).
155 *
156 * Function return: 0 if function failed
157 * otherwise, a uint64_t of token
158 */
159 uint64_t (*pre_enroll)(struct fingerprint_device *dev);
160
161 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700162 * Fingerprint enroll request:
163 * Switches the HAL state machine to collect and store a new fingerprint
164 * template. Switches back as soon as enroll is complete
165 * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
166 * fingerprint_msg.data.enroll.samples_remaining == 0)
167 * or after timeout_sec seconds.
168 * The fingerprint template will be assigned to the group gid. User has a choice
169 * to supply the gid or set it to 0 in which case a unique group id will be generated.
170 *
171 * Function return: 0 if enrollment process can be successfully started
172 * or a negative number in case of error, generally from the errno.h set.
173 * A notify() function may be called indicating the error condition.
174 */
175 int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
176 uint32_t gid, uint32_t timeout_sec);
177
178 /*
179 * Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
180 * This will be called at the end of a multi-finger enrollment session to indicate
181 * that no more fingers will be added.
182 *
183 * Function return: 0 if the request is accepted
184 * or a negative number in case of error, generally from the errno.h set.
185 */
186 int (*post_enroll)(struct fingerprint_device *dev);
187
188 /*
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700189 * get_authenticator_id:
190 * Returns a token associated with the current fingerprint set. This value will
191 * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
192 * set.
193 *
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700194 * Function return: current authenticator id or 0 if function failed.
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700195 */
196 uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
197
198 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700199 * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
200 * to all running clients. Switches the HAL state machine back to the idle state.
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700201 * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700202 *
203 * Function return: 0 if cancel request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700204 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700205 */
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700206 int (*cancel)(struct fingerprint_device *dev);
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700207
208 /*
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700209 * Enumerate all the fingerprint templates found in the directory set by
210 * set_active_group()
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700211 * For each template found notify() will be called with:
212 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENUMERATED
213 * fingerprint_msg.data.enumerated.finger indicating a template id
214 * fingerprint_msg.data.enumerated.remaining_templates indicating how many more
215 * enumeration messages to expect.
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700216 *
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700217 * Function return: 0 if enumerate request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700218 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700219 */
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700220 int (*enumerate)(struct fingerprint_device *dev);
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700221
222 /*
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700223 * Fingerprint remove request:
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700224 * Deletes a fingerprint template.
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700225 * Works only within the path set by set_active_group().
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700226 * notify() will be called with details on the template deleted.
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700227 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700228 * fingerprint_msg.data.removed.finger indicating the template id removed.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700229 *
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700230 * Function return: 0 if fingerprint template(s) can be successfully deleted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700231 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700232 */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700233 int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800234
235 /*
236 * Restricts the HAL operation to a set of fingerprints belonging to a
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700237 * group provided.
238 * The caller must provide a path to a storage location within the user's
239 * data directory.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800240 *
241 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700242 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800243 */
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700244 int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
245 const char *store_path);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800246
247 /*
248 * Authenticates an operation identifed by operation_id
249 *
250 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700251 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800252 */
Jim Miller1fb1e332015-03-24 19:25:47 -0700253 int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700254
Sasha Levitskiy7e9204a2016-01-07 14:46:45 -0800255 /*
256 * Resets a lockout by providing a valid hardware authentication token.
257 *
258 * Function return: 0 on success
259 * or a negative number in case of error, generally from the errno.h set.
260 */
261 int (*reset_lockout)(struct fingerprint_device *dev, const hw_auth_token_t *hat);
262
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700263 /* Reserved for backward binary compatibility */
Sasha Levitskiy7e9204a2016-01-07 14:46:45 -0800264 void *reserved[3];
Sasha Levitskiya747c062014-03-24 16:14:42 -0700265} fingerprint_device_t;
266
267typedef struct fingerprint_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700268 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700269 * Common methods of the fingerprint module. This *must* be the first member
270 * of fingerprint_module as users of this structure will cast a hw_module_t
271 * to fingerprint_module pointer in contexts where it's known
272 * the hw_module_t references a fingerprint_module.
Stewart Miles84d35492014-05-01 09:03:27 -0700273 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700274 struct hw_module_t common;
275} fingerprint_module_t;
276
Sasha Levitskiya747c062014-03-24 16:14:42 -0700277#endif /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */