blob: 86ced9b4ec1837f4eaef88885ed0c614a9011a1e [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
Nick Vaccaroea09bc82016-04-19 15:07:46 -070020#include <hardware/hardware.h>
Sasha Levitskiy6eced702015-04-12 22:58:21 -070021#include <hardware/hw_auth_token.h>
22
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 Levitskiy6f802102016-05-13 13:40:31 -070026#define FINGERPRINT_MODULE_API_VERSION_3_0 HARDWARE_MODULE_API_VERSION(3, 0)
Sasha Levitskiya747c062014-03-24 16:14:42 -070027#define FINGERPRINT_HARDWARE_MODULE_ID "fingerprint"
28
Sasha Levitskiy73082842014-04-18 11:14:11 -070029typedef enum fingerprint_msg_type {
Sasha Levitskiya747c062014-03-24 16:14:42 -070030 FINGERPRINT_ERROR = -1,
Sasha Levitskiyba45e052014-06-09 13:19:52 -070031 FINGERPRINT_ACQUIRED = 1,
Sasha Levitskiyba45e052014-06-09 13:19:52 -070032 FINGERPRINT_TEMPLATE_ENROLLING = 3,
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080033 FINGERPRINT_TEMPLATE_REMOVED = 4,
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070034 FINGERPRINT_AUTHENTICATED = 5,
35 FINGERPRINT_TEMPLATE_ENUMERATING = 6,
Sasha Levitskiy73082842014-04-18 11:14:11 -070036} fingerprint_msg_type_t;
Sasha Levitskiya747c062014-03-24 16:14:42 -070037
Jim Miller929e0a12015-07-24 18:25:40 -070038/*
39 * Fingerprint errors are meant to tell the framework to terminate the current operation and ask
40 * for the user to correct the situation. These will almost always result in messaging and user
41 * interaction to correct the problem.
42 *
43 * For example, FINGERPRINT_ERROR_CANCELED should follow any acquisition message that results in
44 * a situation where the current operation can't continue without user interaction. For example,
45 * if the sensor is dirty during enrollment and no further enrollment progress can be made,
46 * send FINGERPRINT_ACQUIRED_IMAGER_DIRTY followed by FINGERPRINT_ERROR_CANCELED.
47 */
Sasha Levitskiya747c062014-03-24 16:14:42 -070048typedef enum fingerprint_error {
Jim Miller929e0a12015-07-24 18:25:40 -070049 FINGERPRINT_ERROR_HW_UNAVAILABLE = 1, /* The hardware has an error that can't be resolved. */
50 FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2, /* Bad data; operation can't continue */
51 FINGERPRINT_ERROR_TIMEOUT = 3, /* The operation has timed out waiting for user input. */
Jim Miller1fb1e332015-03-24 19:25:47 -070052 FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
Jim Miller929e0a12015-07-24 18:25:40 -070053 FINGERPRINT_ERROR_CANCELED = 5, /* The current operation can't proceed. See above. */
54 FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint with given id can't be removed */
Jim Millere392a542017-01-06 19:18:04 -080055 FINGERPRINT_ERROR_LOCKOUT = 7, /* the fingerprint hardware is in lockout due to too many attempts */
Jim Miller1fb1e332015-03-24 19:25:47 -070056 FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
Sasha Levitskiya747c062014-03-24 16:14:42 -070057} fingerprint_error_t;
58
Jim Miller929e0a12015-07-24 18:25:40 -070059/*
60 * Fingerprint acquisition info is meant as feedback for the current operation. Anything but
61 * FINGERPRINT_ACQUIRED_GOOD will be shown to the user as feedback on how to take action on the
62 * current operation. For example, FINGERPRINT_ACQUIRED_IMAGER_DIRTY can be used to tell the user
63 * to clean the sensor. If this will cause the current operation to fail, an additional
64 * FINGERPRINT_ERROR_CANCELED can be sent to stop the operation in progress (e.g. enrollment).
65 * In general, these messages will result in a "Try again" message.
66 */
Jim Miller953524b2014-06-16 17:59:40 -070067typedef enum fingerprint_acquired_info {
68 FINGERPRINT_ACQUIRED_GOOD = 0,
Jim Miller929e0a12015-07-24 18:25:40 -070069 FINGERPRINT_ACQUIRED_PARTIAL = 1, /* sensor needs more data, i.e. longer swipe. */
70 FINGERPRINT_ACQUIRED_INSUFFICIENT = 2, /* image doesn't contain enough detail for recognition*/
71 FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3, /* sensor needs to be cleaned */
72 FINGERPRINT_ACQUIRED_TOO_SLOW = 4, /* mostly swipe-type sensors; not enough data collected */
73 FINGERPRINT_ACQUIRED_TOO_FAST = 5, /* for swipe and area sensors; tell user to slow down*/
Jim Millere392a542017-01-06 19:18:04 -080074 FINGERPRINT_ACQUIRED_DETECTED = 6, /* when the finger is first detected. Used to optimize wakeup.
75 Should be followed by one of the above messages */
Jim Miller1fb1e332015-03-24 19:25:47 -070076 FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
Jim Miller953524b2014-06-16 17:59:40 -070077} fingerprint_acquired_info_t;
Sasha Levitskiyba45e052014-06-09 13:19:52 -070078
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080079typedef struct fingerprint_finger_id {
80 uint32_t gid;
81 uint32_t fid;
82} fingerprint_finger_id_t;
83
Sasha Levitskiy73082842014-04-18 11:14:11 -070084typedef struct fingerprint_enroll {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080085 fingerprint_finger_id_t finger;
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -070086 /* samples_remaining goes from N (no data collected, but N scans needed)
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080087 * to 0 (no more data is needed to build a template). */
Jim Miller1fb1e332015-03-24 19:25:47 -070088 uint32_t samples_remaining;
Sasha Levitskiya70ab952015-06-02 11:29:12 -070089 uint64_t msg; /* Vendor specific message. Used for user guidance */
Sasha Levitskiy73082842014-04-18 11:14:11 -070090} fingerprint_enroll_t;
91
Sasha Levitskiy6f802102016-05-13 13:40:31 -070092typedef struct fingerprint_iterator {
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070093 fingerprint_finger_id_t finger;
94 uint32_t remaining_templates;
Sasha Levitskiy6f802102016-05-13 13:40:31 -070095} fingerprint_iterator_t;
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070096
Sasha Levitskiy6f802102016-05-13 13:40:31 -070097typedef fingerprint_iterator_t fingerprint_enumerated_t;
98typedef fingerprint_iterator_t fingerprint_removed_t;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070099
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700100typedef struct fingerprint_acquired {
Jim Miller953524b2014-06-16 17:59:40 -0700101 fingerprint_acquired_info_t acquired_info; /* information about the image */
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700102} fingerprint_acquired_t;
103
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800104typedef struct fingerprint_authenticated {
Sasha Levitskiy6eced702015-04-12 22:58:21 -0700105 fingerprint_finger_id_t finger;
106 hw_auth_token_t hat;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800107} fingerprint_authenticated_t;
108
Sasha Levitskiy73082842014-04-18 11:14:11 -0700109typedef struct fingerprint_msg {
110 fingerprint_msg_type_t type;
111 union {
Sasha Levitskiy73082842014-04-18 11:14:11 -0700112 fingerprint_error_t error;
113 fingerprint_enroll_t enroll;
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700114 fingerprint_enumerated_t enumerated;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700115 fingerprint_removed_t removed;
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700116 fingerprint_acquired_t acquired;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800117 fingerprint_authenticated_t authenticated;
Sasha Levitskiy73082842014-04-18 11:14:11 -0700118 } data;
119} fingerprint_msg_t;
120
121/* Callback function type */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700122typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
Sasha Levitskiy73082842014-04-18 11:14:11 -0700123
Sasha Levitskiya747c062014-03-24 16:14:42 -0700124/* Synchronous operation */
125typedef struct fingerprint_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700126 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700127 * Common methods of the fingerprint device. This *must* be the first member
128 * of fingerprint_device as users of this structure will cast a hw_device_t
129 * to fingerprint_device pointer in contexts where it's known
130 * the hw_device_t references a fingerprint_device.
Stewart Miles84d35492014-05-01 09:03:27 -0700131 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700132 struct hw_device_t common;
133
134 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700135 * Client provided callback function to receive notifications.
136 * Do not set by hand, use the function above instead.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700137 */
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700138 fingerprint_notify_t notify;
139
140 /*
141 * Set notification callback:
142 * Registers a user function that would receive notifications from the HAL
143 * The call will block if the HAL state machine is in busy state until HAL
144 * leaves the busy state.
145 *
146 * Function return: 0 if callback function is successfuly registered
147 * or a negative number in case of error, generally from the errno.h set.
148 */
149 int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700150
151 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700152 * Fingerprint pre-enroll enroll request:
153 * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
154 * This token will be wrapped by security for verification and passed to enroll() for
155 * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
156 * template was preceded by some kind of credential confirmation (e.g. device password).
157 *
158 * Function return: 0 if function failed
159 * otherwise, a uint64_t of token
160 */
161 uint64_t (*pre_enroll)(struct fingerprint_device *dev);
162
163 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700164 * Fingerprint enroll request:
165 * Switches the HAL state machine to collect and store a new fingerprint
166 * template. Switches back as soon as enroll is complete
167 * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
168 * fingerprint_msg.data.enroll.samples_remaining == 0)
169 * or after timeout_sec seconds.
170 * The fingerprint template will be assigned to the group gid. User has a choice
171 * to supply the gid or set it to 0 in which case a unique group id will be generated.
172 *
173 * Function return: 0 if enrollment process can be successfully started
174 * or a negative number in case of error, generally from the errno.h set.
175 * A notify() function may be called indicating the error condition.
176 */
177 int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
178 uint32_t gid, uint32_t timeout_sec);
179
180 /*
181 * Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
182 * This will be called at the end of a multi-finger enrollment session to indicate
183 * that no more fingers will be added.
184 *
185 * Function return: 0 if the request is accepted
186 * or a negative number in case of error, generally from the errno.h set.
187 */
188 int (*post_enroll)(struct fingerprint_device *dev);
189
190 /*
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700191 * get_authenticator_id:
192 * Returns a token associated with the current fingerprint set. This value will
193 * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
194 * set.
195 *
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700196 * Function return: current authenticator id or 0 if function failed.
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700197 */
198 uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
199
200 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700201 * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
202 * to all running clients. Switches the HAL state machine back to the idle state.
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700203 * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700204 *
205 * Function return: 0 if cancel request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700206 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700207 */
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700208 int (*cancel)(struct fingerprint_device *dev);
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700209
210 /*
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700211 * Enumerate all the fingerprint templates found in the directory set by
212 * set_active_group()
Sasha Levitskiy6f802102016-05-13 13:40:31 -0700213 * For each template found a notify() will be called with:
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700214 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENUMERATED
215 * fingerprint_msg.data.enumerated.finger indicating a template id
216 * fingerprint_msg.data.enumerated.remaining_templates indicating how many more
217 * enumeration messages to expect.
Kevin Chynba8e9322017-02-14 14:45:04 -0800218 * Note: If there are no fingerprints, then this should return 0 and the first fingerprint
219 * enumerated should have fingerid=0 and remaining=0
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700220 * Function return: 0 if enumerate request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700221 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700222 */
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700223 int (*enumerate)(struct fingerprint_device *dev);
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700224
225 /*
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700226 * Fingerprint remove request:
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700227 * Deletes a fingerprint template.
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700228 * Works only within the path set by set_active_group().
Sasha Levitskiy6f802102016-05-13 13:40:31 -0700229 * The fid parameter can be used as a widcard:
230 * * fid == 0 -- delete all the templates in the group.
231 * * fid != 0 -- delete this specific template from the group.
232 * For each template found a notify() will be called with:
233 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED
234 * fingerprint_msg.data.removed.finger indicating a template id deleted
235 * fingerprint_msg.data.removed.remaining_templates indicating how many more
236 * templates will be deleted by this operation.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700237 *
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700238 * Function return: 0 if fingerprint template(s) can be successfully deleted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700239 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700240 */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700241 int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800242
243 /*
244 * Restricts the HAL operation to a set of fingerprints belonging to a
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700245 * group provided.
246 * The caller must provide a path to a storage location within the user's
247 * data directory.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800248 *
249 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700250 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800251 */
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700252 int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
253 const char *store_path);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800254
255 /*
256 * Authenticates an operation identifed by operation_id
257 *
258 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700259 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800260 */
Jim Miller1fb1e332015-03-24 19:25:47 -0700261 int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700262
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700263 /* Reserved for backward binary compatibility */
Jim Millere453c522016-06-14 23:52:03 +0000264 void *reserved[4];
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 */