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 #define LOG_TAG "FingerprintHal"
17
18 #include <errno.h>
19 #include <string.h>
20 #include <cutils/log.h>
21 #include <hardware/hardware.h>
22 #include <hardware/fingerprint.h>
23
fingerprint_close(hw_device_t * dev)24 static int fingerprint_close(hw_device_t *dev)
25 {
26 if (dev) {
27 free(dev);
28 return 0;
29 } else {
30 return -1;
31 }
32 }
33
fingerprint_enroll(struct fingerprint_device __unused * dev,uint32_t __unused timeout_sec)34 static int fingerprint_enroll(struct fingerprint_device __unused *dev,
35 uint32_t __unused timeout_sec) {
36 return FINGERPRINT_ERROR;
37 }
38
fingerprint_remove(struct fingerprint_device __unused * dev,uint32_t __unused fingerprint_id)39 static int fingerprint_remove(struct fingerprint_device __unused *dev,
40 uint32_t __unused fingerprint_id) {
41 return FINGERPRINT_ERROR;
42 }
43
set_notify_callback(struct fingerprint_device * dev,fingerprint_notify_t notify)44 static int set_notify_callback(struct fingerprint_device *dev,
45 fingerprint_notify_t notify) {
46 /* Decorate with locks */
47 dev->notify = notify;
48 return FINGERPRINT_ERROR;
49 }
50
fingerprint_open(const hw_module_t * module,const char __unused * id,hw_device_t ** device)51 static int fingerprint_open(const hw_module_t* module, const char __unused *id,
52 hw_device_t** device)
53 {
54 if (device == NULL) {
55 ALOGE("NULL device on open");
56 return -EINVAL;
57 }
58
59 fingerprint_device_t *dev = malloc(sizeof(fingerprint_device_t));
60 memset(dev, 0, sizeof(fingerprint_device_t));
61
62 dev->common.tag = HARDWARE_DEVICE_TAG;
63 dev->common.version = HARDWARE_MODULE_API_VERSION(1, 0);
64 dev->common.module = (struct hw_module_t*) module;
65 dev->common.close = fingerprint_close;
66
67 dev->enroll = fingerprint_enroll;
68 dev->remove = fingerprint_remove;
69 dev->set_notify = set_notify_callback;
70 dev->notify = NULL;
71
72 *device = (hw_device_t*) dev;
73 return 0;
74 }
75
76 static struct hw_module_methods_t fingerprint_module_methods = {
77 .open = fingerprint_open,
78 };
79
80 fingerprint_module_t HAL_MODULE_INFO_SYM = {
81 .common = {
82 .tag = HARDWARE_MODULE_TAG,
83 .module_api_version = FINGERPRINT_MODULE_API_VERSION_1_0,
84 .hal_api_version = HARDWARE_HAL_API_VERSION,
85 .id = FINGERPRINT_HARDWARE_MODULE_ID,
86 .name = "Demo Fingerprint HAL",
87 .author = "The Android Open Source Project",
88 .methods = &fingerprint_module_methods,
89 },
90 };
91