blob: 075e18bfc6e74582ea3e3528fe5bfb717d9f458a [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
Sasha Levitskiy73082842014-04-18 11:14:11 -070059typedef struct fingerprint_enroll {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080060 fingerprint_finger_id_t finger;
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -070061 /* samples_remaining goes from N (no data collected, but N scans needed)
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080062 * to 0 (no more data is needed to build a template). */
Jim Miller1fb1e332015-03-24 19:25:47 -070063 uint32_t samples_remaining;
Sasha Levitskiya70ab952015-06-02 11:29:12 -070064 uint64_t msg; /* Vendor specific message. Used for user guidance */
Sasha Levitskiy73082842014-04-18 11:14:11 -070065} fingerprint_enroll_t;
66
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070067typedef struct fingerprint_removed {
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080068 fingerprint_finger_id_t finger;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070069} fingerprint_removed_t;
70
Sasha Levitskiyba45e052014-06-09 13:19:52 -070071typedef struct fingerprint_acquired {
Jim Miller953524b2014-06-16 17:59:40 -070072 fingerprint_acquired_info_t acquired_info; /* information about the image */
Sasha Levitskiyba45e052014-06-09 13:19:52 -070073} fingerprint_acquired_t;
74
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080075typedef struct fingerprint_authenticated {
Sasha Levitskiy6eced702015-04-12 22:58:21 -070076 fingerprint_finger_id_t finger;
77 hw_auth_token_t hat;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080078} fingerprint_authenticated_t;
79
Sasha Levitskiy73082842014-04-18 11:14:11 -070080typedef struct fingerprint_msg {
81 fingerprint_msg_type_t type;
82 union {
Sasha Levitskiy73082842014-04-18 11:14:11 -070083 fingerprint_error_t error;
84 fingerprint_enroll_t enroll;
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -070085 fingerprint_removed_t removed;
Sasha Levitskiyba45e052014-06-09 13:19:52 -070086 fingerprint_acquired_t acquired;
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -080087 fingerprint_authenticated_t authenticated;
Sasha Levitskiy73082842014-04-18 11:14:11 -070088 } data;
89} fingerprint_msg_t;
90
91/* Callback function type */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -070092typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
Sasha Levitskiy73082842014-04-18 11:14:11 -070093
Sasha Levitskiya747c062014-03-24 16:14:42 -070094/* Synchronous operation */
95typedef struct fingerprint_device {
Stewart Miles84d35492014-05-01 09:03:27 -070096 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -070097 * Common methods of the fingerprint device. This *must* be the first member
98 * of fingerprint_device as users of this structure will cast a hw_device_t
99 * to fingerprint_device pointer in contexts where it's known
100 * the hw_device_t references a fingerprint_device.
Stewart Miles84d35492014-05-01 09:03:27 -0700101 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700102 struct hw_device_t common;
103
104 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700105 * Client provided callback function to receive notifications.
106 * Do not set by hand, use the function above instead.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700107 */
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700108 fingerprint_notify_t notify;
109
110 /*
111 * Set notification callback:
112 * Registers a user function that would receive notifications from the HAL
113 * The call will block if the HAL state machine is in busy state until HAL
114 * leaves the busy state.
115 *
116 * Function return: 0 if callback function is successfuly registered
117 * or a negative number in case of error, generally from the errno.h set.
118 */
119 int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700120
121 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700122 * Fingerprint pre-enroll enroll request:
123 * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
124 * This token will be wrapped by security for verification and passed to enroll() for
125 * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
126 * template was preceded by some kind of credential confirmation (e.g. device password).
127 *
128 * Function return: 0 if function failed
129 * otherwise, a uint64_t of token
130 */
131 uint64_t (*pre_enroll)(struct fingerprint_device *dev);
132
133 /*
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700134 * Fingerprint enroll request:
135 * Switches the HAL state machine to collect and store a new fingerprint
136 * template. Switches back as soon as enroll is complete
137 * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
138 * fingerprint_msg.data.enroll.samples_remaining == 0)
139 * or after timeout_sec seconds.
140 * The fingerprint template will be assigned to the group gid. User has a choice
141 * to supply the gid or set it to 0 in which case a unique group id will be generated.
142 *
143 * Function return: 0 if enrollment process can be successfully started
144 * or a negative number in case of error, generally from the errno.h set.
145 * A notify() function may be called indicating the error condition.
146 */
147 int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
148 uint32_t gid, uint32_t timeout_sec);
149
150 /*
151 * Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
152 * This will be called at the end of a multi-finger enrollment session to indicate
153 * that no more fingers will be added.
154 *
155 * Function return: 0 if the request is accepted
156 * or a negative number in case of error, generally from the errno.h set.
157 */
158 int (*post_enroll)(struct fingerprint_device *dev);
159
160 /*
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700161 * get_authenticator_id:
162 * Returns a token associated with the current fingerprint set. This value will
163 * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
164 * set.
165 *
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700166 * Function return: current authenticator id or 0 if function failed.
Sasha Levitskiy468b5672015-04-16 14:45:04 -0700167 */
168 uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
169
170 /*
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700171 * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
172 * to all running clients. Switches the HAL state machine back to the idle state.
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700173 * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700174 *
175 * Function return: 0 if cancel request is accepted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700176 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700177 */
Jim Miller1e1f7ba2015-04-08 22:55:51 -0700178 int (*cancel)(struct fingerprint_device *dev);
Sasha Levitskiy969466c2014-05-07 09:07:11 -0700179
180 /*
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700181 * Enumerate all the fingerprint templates found in the directory set by
182 * set_active_group()
183 * This is a synchronous call. The function takes:
184 * - A pointer to an array of fingerprint_finger_id_t.
185 * - The size of the array provided, in fingerprint_finger_id_t elements.
186 * Max_size is a bi-directional parameter and returns the actual number
187 * of elements copied to the caller supplied array.
188 * In the absence of errors the function returns the total number of templates
189 * in the user directory.
190 * If the caller has no good guess on the size of the array he should call this
191 * function witn *max_size == 0 and use the return value for the array allocation.
192 * The caller of this function has a complete list of the templates when *max_size
193 * is the same as the function return.
194 *
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700195 * Function return: Total number of fingerprint templates in the current storage directory.
196 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiye0a29882015-04-28 15:49:05 -0700197 */
198 int (*enumerate)(struct fingerprint_device *dev, fingerprint_finger_id_t *results,
199 uint32_t *max_size);
200
201 /*
Sasha Levitskiy3b9ee8d2014-04-23 10:04:57 -0700202 * Fingerprint remove request:
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700203 * Deletes a fingerprint template.
204 * Works only within a path set by set_active_group().
205 * notify() will be called with details on the template deleted.
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700206 * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700207 * fingerprint_msg.data.removed.id indicating the template id removed.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700208 *
Sasha Levitskiy0d1cd3f2014-04-30 13:29:43 -0700209 * Function return: 0 if fingerprint template(s) can be successfully deleted
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700210 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiya747c062014-03-24 16:14:42 -0700211 */
Sasha Levitskiyd4331fd2015-06-08 13:14:15 -0700212 int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800213
214 /*
215 * Restricts the HAL operation to a set of fingerprints belonging to a
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700216 * group provided.
217 * The caller must provide a path to a storage location within the user's
218 * data directory.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800219 *
220 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700221 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800222 */
Sasha Levitskiy7eb72352015-05-07 14:40:16 -0700223 int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
224 const char *store_path);
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800225
226 /*
227 * Authenticates an operation identifed by operation_id
228 *
229 * Function return: 0 on success
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700230 * or a negative number in case of error, generally from the errno.h set.
Sasha Levitskiy3b7402e2014-12-11 06:49:36 -0800231 */
Jim Miller1fb1e332015-03-24 19:25:47 -0700232 int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
Sasha Levitskiya747c062014-03-24 16:14:42 -0700233
Sasha Levitskiya36ffbe2015-06-24 16:32:43 -0700234 /* Reserved for backward binary compatibility */
235 void *reserved[4];
Sasha Levitskiya747c062014-03-24 16:14:42 -0700236} fingerprint_device_t;
237
238typedef struct fingerprint_module {
Stewart Miles84d35492014-05-01 09:03:27 -0700239 /**
Sasha Levitskiyba45e052014-06-09 13:19:52 -0700240 * Common methods of the fingerprint module. This *must* be the first member
241 * of fingerprint_module as users of this structure will cast a hw_module_t
242 * to fingerprint_module pointer in contexts where it's known
243 * the hw_module_t references a fingerprint_module.
Stewart Miles84d35492014-05-01 09:03:27 -0700244 */
Sasha Levitskiya747c062014-03-24 16:14:42 -0700245 struct hw_module_t common;
246} fingerprint_module_t;
247
Sasha Levitskiya747c062014-03-24 16:14:42 -0700248#endif /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */