Home | History | Annotate | Download | only in hardware
      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_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
     25 #define FINGERPRINT_HARDWARE_MODULE_ID "fingerprint"
     26 
     27 typedef enum fingerprint_msg_type {
     28     FINGERPRINT_ERROR = -1,
     29     FINGERPRINT_ACQUIRED = 1,
     30     FINGERPRINT_TEMPLATE_ENROLLING = 3,
     31     FINGERPRINT_TEMPLATE_REMOVED = 4,
     32     FINGERPRINT_AUTHENTICATED = 5,
     33     FINGERPRINT_TEMPLATE_ENUMERATING = 6,
     34 } fingerprint_msg_type_t;
     35 
     36 /*
     37  * Fingerprint errors are meant to tell the framework to terminate the current operation and ask
     38  * for the user to correct the situation. These will almost always result in messaging and user
     39  * interaction to correct the problem.
     40  *
     41  * For example, FINGERPRINT_ERROR_CANCELED should follow any acquisition message that results in
     42  * a situation where the current operation can't continue without user interaction. For example,
     43  * if the sensor is dirty during enrollment and no further enrollment progress can be made,
     44  * send FINGERPRINT_ACQUIRED_IMAGER_DIRTY followed by FINGERPRINT_ERROR_CANCELED.
     45  */
     46 typedef enum fingerprint_error {
     47     FINGERPRINT_ERROR_HW_UNAVAILABLE = 1, /* The hardware has an error that can't be resolved. */
     48     FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2, /* Bad data; operation can't continue */
     49     FINGERPRINT_ERROR_TIMEOUT = 3, /* The operation has timed out waiting for user input. */
     50     FINGERPRINT_ERROR_NO_SPACE = 4, /* No space available to store a template */
     51     FINGERPRINT_ERROR_CANCELED = 5, /* The current operation can't proceed. See above. */
     52     FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6, /* fingerprint with given id can't be removed */
     53     FINGERPRINT_ERROR_VENDOR_BASE = 1000 /* vendor-specific error messages start here */
     54 } fingerprint_error_t;
     55 
     56 /*
     57  * Fingerprint acquisition info is meant as feedback for the current operation.  Anything but
     58  * FINGERPRINT_ACQUIRED_GOOD will be shown to the user as feedback on how to take action on the
     59  * current operation. For example, FINGERPRINT_ACQUIRED_IMAGER_DIRTY can be used to tell the user
     60  * to clean the sensor.  If this will cause the current operation to fail, an additional
     61  * FINGERPRINT_ERROR_CANCELED can be sent to stop the operation in progress (e.g. enrollment).
     62  * In general, these messages will result in a "Try again" message.
     63  */
     64 typedef enum fingerprint_acquired_info {
     65     FINGERPRINT_ACQUIRED_GOOD = 0,
     66     FINGERPRINT_ACQUIRED_PARTIAL = 1, /* sensor needs more data, i.e. longer swipe. */
     67     FINGERPRINT_ACQUIRED_INSUFFICIENT = 2, /* image doesn't contain enough detail for recognition*/
     68     FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3, /* sensor needs to be cleaned */
     69     FINGERPRINT_ACQUIRED_TOO_SLOW = 4, /* mostly swipe-type sensors; not enough data collected */
     70     FINGERPRINT_ACQUIRED_TOO_FAST = 5, /* for swipe and area sensors; tell user to slow down*/
     71     FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000 /* vendor-specific acquisition messages start here */
     72 } fingerprint_acquired_info_t;
     73 
     74 typedef struct fingerprint_finger_id {
     75     uint32_t gid;
     76     uint32_t fid;
     77 } fingerprint_finger_id_t;
     78 
     79 typedef struct fingerprint_enroll {
     80     fingerprint_finger_id_t finger;
     81     /* samples_remaining goes from N (no data collected, but N scans needed)
     82      * to 0 (no more data is needed to build a template). */
     83     uint32_t samples_remaining;
     84     uint64_t msg; /* Vendor specific message. Used for user guidance */
     85 } fingerprint_enroll_t;
     86 
     87 typedef struct fingerprint_enumerated {
     88     fingerprint_finger_id_t finger;
     89     uint32_t remaining_templates;
     90 } fingerprint_enumerated_t;
     91 
     92 typedef struct fingerprint_removed {
     93     fingerprint_finger_id_t finger;
     94 } fingerprint_removed_t;
     95 
     96 typedef struct fingerprint_acquired {
     97     fingerprint_acquired_info_t acquired_info; /* information about the image */
     98 } fingerprint_acquired_t;
     99 
    100 typedef struct fingerprint_authenticated {
    101     fingerprint_finger_id_t finger;
    102     hw_auth_token_t hat;
    103 } fingerprint_authenticated_t;
    104 
    105 typedef struct fingerprint_msg {
    106     fingerprint_msg_type_t type;
    107     union {
    108         fingerprint_error_t error;
    109         fingerprint_enroll_t enroll;
    110         fingerprint_enumerated_t enumerated;
    111         fingerprint_removed_t removed;
    112         fingerprint_acquired_t acquired;
    113         fingerprint_authenticated_t authenticated;
    114     } data;
    115 } fingerprint_msg_t;
    116 
    117 /* Callback function type */
    118 typedef void (*fingerprint_notify_t)(const fingerprint_msg_t *msg);
    119 
    120 /* Synchronous operation */
    121 typedef struct fingerprint_device {
    122     /**
    123      * Common methods of the fingerprint device. This *must* be the first member
    124      * of fingerprint_device as users of this structure will cast a hw_device_t
    125      * to fingerprint_device pointer in contexts where it's known
    126      * the hw_device_t references a fingerprint_device.
    127      */
    128     struct hw_device_t common;
    129 
    130     /*
    131      * Client provided callback function to receive notifications.
    132      * Do not set by hand, use the function above instead.
    133      */
    134     fingerprint_notify_t notify;
    135 
    136     /*
    137      * Set notification callback:
    138      * Registers a user function that would receive notifications from the HAL
    139      * The call will block if the HAL state machine is in busy state until HAL
    140      * leaves the busy state.
    141      *
    142      * Function return: 0 if callback function is successfuly registered
    143      *                  or a negative number in case of error, generally from the errno.h set.
    144      */
    145     int (*set_notify)(struct fingerprint_device *dev, fingerprint_notify_t notify);
    146 
    147     /*
    148      * Fingerprint pre-enroll enroll request:
    149      * Generates a unique token to upper layers to indicate the start of an enrollment transaction.
    150      * This token will be wrapped by security for verification and passed to enroll() for
    151      * verification before enrollment will be allowed. This is to ensure adding a new fingerprint
    152      * template was preceded by some kind of credential confirmation (e.g. device password).
    153      *
    154      * Function return: 0 if function failed
    155      *                  otherwise, a uint64_t of token
    156      */
    157     uint64_t (*pre_enroll)(struct fingerprint_device *dev);
    158 
    159     /*
    160      * Fingerprint enroll request:
    161      * Switches the HAL state machine to collect and store a new fingerprint
    162      * template. Switches back as soon as enroll is complete
    163      * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING &&
    164      *  fingerprint_msg.data.enroll.samples_remaining == 0)
    165      * or after timeout_sec seconds.
    166      * The fingerprint template will be assigned to the group gid. User has a choice
    167      * to supply the gid or set it to 0 in which case a unique group id will be generated.
    168      *
    169      * Function return: 0 if enrollment process can be successfully started
    170      *                  or a negative number in case of error, generally from the errno.h set.
    171      *                  A notify() function may be called indicating the error condition.
    172      */
    173     int (*enroll)(struct fingerprint_device *dev, const hw_auth_token_t *hat,
    174                     uint32_t gid, uint32_t timeout_sec);
    175 
    176     /*
    177      * Finishes the enroll operation and invalidates the pre_enroll() generated challenge.
    178      * This will be called at the end of a multi-finger enrollment session to indicate
    179      * that no more fingers will be added.
    180      *
    181      * Function return: 0 if the request is accepted
    182      *                  or a negative number in case of error, generally from the errno.h set.
    183      */
    184     int (*post_enroll)(struct fingerprint_device *dev);
    185 
    186     /*
    187      * get_authenticator_id:
    188      * Returns a token associated with the current fingerprint set. This value will
    189      * change whenever a new fingerprint is enrolled, thus creating a new fingerprint
    190      * set.
    191      *
    192      * Function return: current authenticator id or 0 if function failed.
    193      */
    194     uint64_t (*get_authenticator_id)(struct fingerprint_device *dev);
    195 
    196     /*
    197      * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED
    198      * to all running clients. Switches the HAL state machine back to the idle state.
    199      * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge.
    200      *
    201      * Function return: 0 if cancel request is accepted
    202      *                  or a negative number in case of error, generally from the errno.h set.
    203      */
    204     int (*cancel)(struct fingerprint_device *dev);
    205 
    206     /*
    207      * Enumerate all the fingerprint templates found in the directory set by
    208      * set_active_group()
    209      * For each template found notify() will be called with:
    210      * fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENUMERATED
    211      * fingerprint_msg.data.enumerated.finger indicating a template id
    212      * fingerprint_msg.data.enumerated.remaining_templates indicating how many more
    213      * enumeration messages to expect.
    214      *
    215      * Function return: 0 if enumerate request is accepted
    216      *                  or a negative number in case of error, generally from the errno.h set.
    217      */
    218     int (*enumerate)(struct fingerprint_device *dev);
    219 
    220     /*
    221      * Fingerprint remove request:
    222      * Deletes a fingerprint template.
    223      * Works only within the path set by set_active_group().
    224      * notify() will be called with details on the template deleted.
    225      * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED and
    226      * fingerprint_msg.data.removed.finger indicating the template id removed.
    227      *
    228      * Function return: 0 if fingerprint template(s) can be successfully deleted
    229      *                  or a negative number in case of error, generally from the errno.h set.
    230      */
    231     int (*remove)(struct fingerprint_device *dev, uint32_t gid, uint32_t fid);
    232 
    233     /*
    234      * Restricts the HAL operation to a set of fingerprints belonging to a
    235      * group provided.
    236      * The caller must provide a path to a storage location within the user's
    237      * data directory.
    238      *
    239      * Function return: 0 on success
    240      *                  or a negative number in case of error, generally from the errno.h set.
    241      */
    242     int (*set_active_group)(struct fingerprint_device *dev, uint32_t gid,
    243                             const char *store_path);
    244 
    245     /*
    246      * Authenticates an operation identifed by operation_id
    247      *
    248      * Function return: 0 on success
    249      *                  or a negative number in case of error, generally from the errno.h set.
    250      */
    251     int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
    252 
    253     /* Reserved for backward binary compatibility */
    254     void *reserved[4];
    255 } fingerprint_device_t;
    256 
    257 typedef struct fingerprint_module {
    258     /**
    259      * Common methods of the fingerprint module. This *must* be the first member
    260      * of fingerprint_module as users of this structure will cast a hw_module_t
    261      * to fingerprint_module pointer in contexts where it's known
    262      * the hw_module_t references a fingerprint_module.
    263      */
    264     struct hw_module_t common;
    265 } fingerprint_module_t;
    266 
    267 #endif  /* ANDROID_INCLUDE_HARDWARE_FINGERPRINT_H */
    268