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