blob: e7c825f16a94bc4063b5e9769bcb7591e57e48ea [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 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 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 Levitskiy6f802102016-05-13 13:40:31 -070089typedef struct fingerprint_iterator {
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070090 fingerprint_finger_id_t finger;
91 uint32_t remaining_templates;
Sasha Levitskiy6f802102016-05-13 13:40:31 -070092} fingerprint_iterator_t;
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -070093
Sasha Levitskiy6f802102016-05-13 13:40:31 -070094typedef fingerprint_iterator_t fingerprint_enumerated_t;
95typedef fingerprint_iterator_t fingerprint_removed_t;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070096
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 Levitskiyc7ffe162015-10-28 13:58:44 -0700111 fingerprint_enumerated_t enumerated;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700112 fingerprint_removed_t removed;
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700113 fingerprint_acquired_t acquired;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800114 fingerprint_authenticated_t authenticated;
Sasha Levitskiy73082842014-04-18 11:14:11 -0700115 } data;
116} fingerprint_msg_t;
117
118/* Callback function type */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700119typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
Sasha Levitskiy73082842014-04-18 11:14:11 -0700120
Sasha Levitskiya747c062014-03-24 16:14:42 -0700121/* Synchronous operation */
122typedef struct fingerprint_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700123 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700124 * Common methods of the fingerprint device. This *must* be the first member
125 * of fingerprint_device as users of this structure will cast a hw_device_t
126 * to fingerprint_device pointer in contexts where it's known
127 * the hw_device_t references a fingerprint_device.
Stewart Miles84d35492014-05-01 09:03:27 -0700128 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700129 struct hw_device_t common;
130
131 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700132 * Client provided callback function to receive notifications.
133 * Do not set by hand, use the function above instead.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700134 */
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700135 fingerprint_notify_t notify;
136
137 /*
138 * Set notification callback:
139 * Registers a user function that would receive notifications from the HAL
140 * The call will block if the HAL state machine is in busy state until HAL
141 * leaves the busy state.
142 *
143 * Function return: 0 if callback function is successfuly registered
144 * or a negative number in case of error, generally from the errno.h set.
145 */
146 int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700147
148 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700149 * Fingerprint pre-enroll enroll request:
150 * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
151 * This token will be wrapped by security for verification and passed to enroll() for
152 * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
153 * template was preceded by some kind of credential confirmation (e.g. device password).
154 *
155 * Function return: 0 if function failed
156 * otherwise, a uint64_t of token
157 */
158 uint64_t (*pre_enroll)(struct fingerprint_device *dev);
159
160 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700161 * Fingerprint enroll request:
162 * Switches the HAL state machine to collect and store a new fingerprint
163 * template. Switches back as soon as enroll is complete
164 * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
165 * fingerprint_msg.data.enroll.samples_remaining == 0)
166 * or after timeout_sec seconds.
167 * The fingerprint template will be assigned to the group gid. User has a choice
168 * to supply the gid or set it to 0 in which case a unique group id will be generated.
169 *
170 * Function return: 0 if enrollment process can be successfully started
171 * or a negative number in case of error, generally from the errno.h set.
172 * A notify() function may be called indicating the error condition.
173 */
174 int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
175 uint32_t gid, uint32_t timeout_sec);
176
177 /*
178 * Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
179 * This will be called at the end of a multi-finger enrollment session to indicate
180 * that no more fingers will be added.
181 *
182 * Function return: 0 if the request is accepted
183 * or a negative number in case of error, generally from the errno.h set.
184 */
185 int (*post_enroll)(struct fingerprint_device *dev);
186
187 /*
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700188 * get_authenticator_id:
189 * Returns a token associated with the current fingerprint set. This value will
190 * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
191 * set.
192 *
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700193 * Function return: current authenticator id or 0 if function failed.
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700194 */
195 uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
196
197 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700198 * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
199 * to all running clients. Switches the HAL state machine back to the idle state.
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700200 * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700201 *
202 * Function return: 0 if cancel request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700203 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700204 */
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700205 int (*cancel)(struct fingerprint_device *dev);
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700206
207 /*
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700208 * Enumerate all the fingerprint templates found in the directory set by
209 * set_active_group()
Sasha Levitskiy6f802102016-05-13 13:40:31 -0700210 * For each template found a notify() will be called with:
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700211 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENUMERATED
212 * fingerprint_msg.data.enumerated.finger indicating a template id
213 * fingerprint_msg.data.enumerated.remaining_templates indicating how many more
214 * enumeration messages to expect.
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700215 *
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700216 * Function return: 0 if enumerate request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700217 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700218 */
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700219 int (*enumerate)(struct fingerprint_device *dev);
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700220
221 /*
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700222 * Fingerprint remove request:
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700223 * Deletes a fingerprint template.
Sasha Levitskiyc7ffe162015-10-28 13:58:44 -0700224 * Works only within the path set by set_active_group().
Sasha Levitskiy6f802102016-05-13 13:40:31 -0700225 * The fid parameter can be used as a widcard:
226 * * fid == 0 -- delete all the templates in the group.
227 * * fid != 0 -- delete this specific template from the group.
228 * For each template found a notify() will be called with:
229 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED
230 * fingerprint_msg.data.removed.finger indicating a template id deleted
231 * fingerprint_msg.data.removed.remaining_templates indicating how many more
232 * templates will be deleted by this operation.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700233 *
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700234 * Function return: 0 if fingerprint template(s) can be successfully deleted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700235 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700236 */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700237 int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800238
239 /*
240 * Restricts the HAL operation to a set of fingerprints belonging to a
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700241 * group provided.
242 * The caller must provide a path to a storage location within the user's
243 * data directory.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800244 *
245 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700246 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800247 */
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700248 int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
249 const char *store_path);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800250
251 /*
252 * Authenticates an operation identifed by operation_id
253 *
254 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700255 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800256 */
Jim Miller1fb1e332015-03-24 19:25:47 -0700257 int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700258
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700259 /* Reserved for backward binary compatibility */
Jim Millere453c522016-06-14 23:52:03 +0000260 void *reserved[4];
Sasha Levitskiya747c062014-03-24 16:14:42 -0700261} fingerprint_device_t;
262
263typedef struct fingerprint_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700264 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700265 * Common methods of the fingerprint module. This *must* be the first member
266 * of fingerprint_module as users of this structure will cast a hw_module_t
267 * to fingerprint_module pointer in contexts where it's known
268 * the hw_module_t references a fingerprint_module.
Stewart Miles84d35492014-05-01 09:03:27 -0700269 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700270 struct hw_module_t common;
271} fingerprint_module_t;
272
Sasha Levitskiya747c062014-03-24 16:14:42 -0700273#endif /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */