blob: ea5eb476035f6d78bb75d24c0f35b69c06098e0b [file] [log] [blame]
Martijn Coenen1c970f12012-09-12 17:59:39 -04001/*
2 * Copyright (C) 2012 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#include <errno.h>
Elliott Hughes07c08552015-01-29 21:19:10 -080017#include <malloc.h>
Martijn Coenen1c970f12012-09-12 17:59:39 -040018#include <string.h>
19
20#include <cutils/log.h>
21#include <hardware/hardware.h>
22#include <hardware/nfc.h>
23
24
25/*
Greg Kaiser0a3bb222016-07-08 18:03:16 -070026 * We want to silence the "unused argument" that gcc and clang give.
27 * Other compilers generating this warning will need to provide their
28 * custom attribute to silence this.
29 */
30#if defined(__GNUC__) || defined(__clang__)
31#define UNUSED_ARGUMENT __attribute((unused))
32#else
33#define UNUSED_ARGUMENT
34#endif
35
36/*
Martijn Coenen1c970f12012-09-12 17:59:39 -040037 * NCI HAL method implementations. These must be overriden
38 */
Greg Kaiser0a3bb222016-07-08 18:03:16 -070039static int hal_open(const struct nfc_nci_device *dev UNUSED_ARGUMENT,
40 nfc_stack_callback_t *p_cback UNUSED_ARGUMENT,
41 nfc_stack_data_callback_t *p_data_cback UNUSED_ARGUMENT) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040042 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
43 return 0;
44}
45
Greg Kaiser0a3bb222016-07-08 18:03:16 -070046static int hal_write(const struct nfc_nci_device *dev UNUSED_ARGUMENT,
47 uint16_t data_len UNUSED_ARGUMENT,
48 const uint8_t *p_data UNUSED_ARGUMENT) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040049 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
50 return 0;
51}
52
Greg Kaiser0a3bb222016-07-08 18:03:16 -070053static int hal_core_initialized(
54 const struct nfc_nci_device *dev UNUSED_ARGUMENT,
55 uint8_t* p_core_init_rsp_params UNUSED_ARGUMENT) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040056 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
57 return 0;
58}
59
Greg Kaiser0a3bb222016-07-08 18:03:16 -070060static int hal_pre_discover(
61 const struct nfc_nci_device *dev UNUSED_ARGUMENT) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040062 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
63 return 0;
64}
65
Greg Kaiser0a3bb222016-07-08 18:03:16 -070066static int hal_close(const struct nfc_nci_device *dev UNUSED_ARGUMENT) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040067 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
68 return 0;
69}
70
Greg Kaiser0a3bb222016-07-08 18:03:16 -070071static int hal_control_granted (
72 const struct nfc_nci_device *p_dev UNUSED_ARGUMENT)
Martijn Coenen1c970f12012-09-12 17:59:39 -040073{
74 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
75 return 0;
76}
77
78
Greg Kaiser0a3bb222016-07-08 18:03:16 -070079static int hal_power_cycle (
80 const struct nfc_nci_device *p_dev UNUSED_ARGUMENT)
Martijn Coenen1c970f12012-09-12 17:59:39 -040081{
82 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
83 return 0;
84}
85
86/*
87 * Generic device handling below - can generally be left unchanged.
88 */
89/* Close an opened nfc device instance */
90static int nfc_close(hw_device_t *dev) {
91 free(dev);
92 return 0;
93}
94
95static int nfc_open(const hw_module_t* module, const char* name,
96 hw_device_t** device) {
97 if (strcmp(name, NFC_NCI_CONTROLLER) == 0) {
98 nfc_nci_device_t *dev = calloc(1, sizeof(nfc_nci_device_t));
99
100 dev->common.tag = HARDWARE_DEVICE_TAG;
101 dev->common.version = 0x00010000; // [31:16] major, [15:0] minor
102 dev->common.module = (struct hw_module_t*) module;
103 dev->common.close = nfc_close;
104
105 // NCI HAL method pointers
106 dev->open = hal_open;
107 dev->write = hal_write;
108 dev->core_initialized = hal_core_initialized;
109 dev->pre_discover = hal_pre_discover;
110 dev->close = hal_close;
111 dev->control_granted = hal_control_granted;
112 dev->power_cycle = hal_power_cycle;
113
114 *device = (hw_device_t*) dev;
115
116 return 0;
117 } else {
118 return -EINVAL;
119 }
120}
121
122
123static struct hw_module_methods_t nfc_module_methods = {
124 .open = nfc_open,
125};
126
127struct nfc_nci_module_t HAL_MODULE_INFO_SYM = {
128 .common = {
129 .tag = HARDWARE_MODULE_TAG,
130 .module_api_version = 0x0100, // [15:8] major, [7:0] minor (1.0)
131 .hal_api_version = 0x00, // 0 is only valid value
132 .id = NFC_NCI_HARDWARE_MODULE_ID,
133 .name = "Default NFC NCI HW HAL",
134 .author = "The Android Open Source Project",
135 .methods = &nfc_module_methods,
136 },
137};