OSDN Git Service

Fingerprint: Avoid passing structures where simple types should suffice.
[android-x86/hardware-libhardware.git] / include / hardware / fingerprint.h
1 /*
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
20 #include <hardware/hw_auth_token.h>
21
22 #define FINGERPRINT_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
23 #define FINGERPRINT_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
24 #define FINGERPRINT_HARDWARE_MODULE_ID "fingerprint"
25
26 typedef enum fingerprint_msg_type {
27     FINGERPRINT_ERROR = -1,
28     FINGERPRINT_ACQUIRED = 1,
29     FINGERPRINT_TEMPLATE_ENROLLING = 3,
30     FINGERPRINT_TEMPLATE_REMOVED = 4,
31     FINGERPRINT_AUTHENTICATED = 5
32 } fingerprint_msg_type_t;
33
34 typedef enum fingerprint_error {
35     FINGERPRINT_ERROR_HW_UNAVAILABLE = 1,
36     FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2,
37     FINGERPRINT_ERROR_TIMEOUT = 3,
38     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 */
42 } fingerprint_error_t;
43
44 typedef enum fingerprint_acquired_info {
45     FINGERPRINT_ACQUIRED_GOOD = 0,
46     FINGERPRINT_ACQUIRED_PARTIAL = 1,
47     FINGERPRINT_ACQUIRED_INSUFFICIENT = 2,
48     FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3,
49     FINGERPRINT_ACQUIRED_TOO_SLOW = 4,
50     FINGERPRINT_ACQUIRED_TOO_FAST = 5,
51     FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
52 } fingerprint_acquired_info_t;
53
54 typedef struct fingerprint_finger_id {
55     uint32_t gid;
56     uint32_t fid;
57 } fingerprint_finger_id_t;
58
59 typedef struct fingerprint_enroll {
60     fingerprint_finger_id_t finger;
61     /* samples_remaining goes from N (no data collected, but N scans needed)
62      * to 0 (no more data is needed to build a template). */
63     uint32_t samples_remaining;
64     uint64_t msg; /* Vendor specific message. Used for user guidance */
65 } fingerprint_enroll_t;
66
67 typedef struct fingerprint_removed {
68     fingerprint_finger_id_t finger;
69 } fingerprint_removed_t;
70
71 typedef struct fingerprint_acquired {
72     fingerprint_acquired_info_t acquired_info; /* information about the image */
73 } fingerprint_acquired_t;
74
75 typedef struct fingerprint_authenticated {
76     fingerprint_finger_id_t finger;
77     hw_auth_token_t hat;
78 } fingerprint_authenticated_t;
79
80 typedef struct fingerprint_msg {
81     fingerprint_msg_type_t type;
82     union {
83         fingerprint_error_t error;
84         fingerprint_enroll_t enroll;
85         fingerprint_removed_t removed;
86         fingerprint_acquired_t acquired;
87         fingerprint_authenticated_t authenticated;
88     } data;
89 } fingerprint_msg_t;
90
91 /* Callback function type */
92 typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
93
94 /* Synchronous operation */
95 typedef struct fingerprint_device {
96     /**
97      * 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.
101      */
102     struct hw_device_t common;
103
104     /*
105      * Fingerprint enroll request:
106      * Switches the HAL state machine to collect and store a new fingerprint
107      * template. Switches back as soon as enroll is complete
108      * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
109      *  fingerprint_msg.data.enroll.samples_remaining == 0)
110      * or after timeout_sec seconds.
111      * The fingerprint template will be assigned to the group gid. User has a choice
112      * to supply the gid or set it to 0 in which case a unique group id will be generated.
113      *
114      * Function return: 0 if enrollment process can be successfully started
115      *                 -1 otherwise. A notify() function may be called
116      *                    indicating the error condition.
117      */
118     int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
119                     uint32_t gid, uint32_t timeout_sec);
120
121     /*
122      * 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     /*
134      * get_authenticator_id:
135      * Returns a token associated with the current fingerprint set. This value will
136      * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
137      * set.
138      *
139      * Function return: current authenticator id.
140      */
141     uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
142
143     /*
144      * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
145      * to all running clients. Switches the HAL state machine back to the idle state.
146      * will indicate switch back to the scan mode.
147      *
148      * Function return: 0 if cancel request is accepted
149      *                 -1 otherwise.
150      */
151     int (*cancel)(struct fingerprint_device *dev);
152
153     /*
154      * Enumerate all the fingerprint templates found in the directory set by
155      * set_active_group()
156      * This is a synchronous call. The function takes:
157      * - A pointer to an array of fingerprint_finger_id_t.
158      * - The size of the array provided, in fingerprint_finger_id_t elements.
159      * Max_size is a bi-directional parameter and returns the actual number
160      * of elements copied to the caller supplied array.
161      * In the absence of errors the function returns the total number of templates
162      * in the user directory.
163      * If the caller has no good guess on the size of the array he should call this
164      * function witn *max_size == 0 and use the return value for the array allocation.
165      * The caller of this function has a complete list of the templates when *max_size
166      * is the same as the function return.
167      *
168      * Function return: Total number of fingerprint templates in the current
169                         storage directory.
170      *                 -1 on error.
171      */
172     int (*enumerate)(struct fingerprint_device *dev, fingerprint_finger_id_t *results,
173         uint32_t *max_size);
174
175     /*
176      * Fingerprint remove request:
177      * Deletes a fingerprint template.
178      * Works only within a path set by set_active_group().
179      * notify() will be called with details on the template deleted.
180      * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
181      * fingerprint_msg.data.removed.id indicating the template id removed.
182      *
183      * Function return: 0 if fingerprint template(s) can be successfully deleted
184      *                 -1 otherwise.
185      */
186     int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
187
188     /*
189      * Restricts the HAL operation to a set of fingerprints belonging to a
190      * group provided.
191      * The caller must provide a path to a storage location within the user's
192      * data directory.
193      *
194      * Function return: 0 on success
195      *                 -1 if the group does not exist.
196      */
197     int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
198                             const char *store_path);
199
200     /*
201      * Authenticates an operation identifed by operation_id
202      *
203      * Function return: 0 on success
204      *                 -1 if the operation cannot be completed
205      */
206     int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
207
208     /*
209      * Set notification callback:
210      * Registers a user function that would receive notifications from the HAL
211      * The call will block if the HAL state machine is in busy state until HAL
212      * leaves the busy state.
213      *
214      * Function return: 0 if callback function is successfuly registered
215      *                 -1 otherwise.
216      */
217     int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
218
219     /*
220      * Client provided callback function to receive notifications.
221      * Do not set by hand, use the function above instead.
222      */
223     fingerprint_notify_t notify;
224 } fingerprint_device_t;
225
226 typedef struct fingerprint_module {
227     /**
228      * Common methods of the fingerprint module. This *must* be the first member
229      * of fingerprint_module as users of this structure will cast a hw_module_t
230      * to fingerprint_module pointer in contexts where it's known
231      * the hw_module_t references a fingerprint_module.
232      */
233     struct hw_module_t common;
234 } fingerprint_module_t;
235
236 #endif  /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */