1 /*
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>
17 #include <malloc.h>
18 #include <string.h>
19
20 #include <log/log.h>
21
22 #include <hardware/hardware.h>
23 #include <hardware/nfc.h>
24
25 /*
26 * NCI HAL method implementations. These must be overriden
27 */
hal_open(const struct nfc_nci_device *,nfc_stack_callback_t *,nfc_stack_data_callback_t *)28 static int hal_open(const struct nfc_nci_device* /*dev*/,
29 nfc_stack_callback_t* /*p_cback*/,
30 nfc_stack_data_callback_t* /*p_data_cback*/) {
31 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
32 return 0;
33 }
34
hal_write(const struct nfc_nci_device *,uint16_t,const uint8_t *)35 static int hal_write(const struct nfc_nci_device* /*dev*/,
36 uint16_t /*data_len*/, const uint8_t* /*p_data*/) {
37 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
38 return 0;
39 }
40
hal_core_initialized(const struct nfc_nci_device *,uint8_t *)41 static int hal_core_initialized(const struct nfc_nci_device* /*dev*/,
42 uint8_t* /*p_core_init_rsp_params*/) {
43 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
44 return 0;
45 }
46
hal_pre_discover(const struct nfc_nci_device *)47 static int hal_pre_discover(const struct nfc_nci_device* /*dev*/) {
48 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
49 return 0;
50 }
51
hal_close(const struct nfc_nci_device *)52 static int hal_close(const struct nfc_nci_device* /*dev*/) {
53 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
54 return 0;
55 }
56
hal_control_granted(const struct nfc_nci_device *)57 static int hal_control_granted (const struct nfc_nci_device* /*p_dev*/)
58 {
59 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
60 return 0;
61 }
62
63
hal_power_cycle(const struct nfc_nci_device *)64 static int hal_power_cycle (const struct nfc_nci_device* /*p_dev*/)
65 {
66 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
67 return 0;
68 }
69
70 /*
71 * Generic device handling below - can generally be left unchanged.
72 */
73 /* Close an opened nfc device instance */
nfc_close(hw_device_t * dev)74 static int nfc_close(hw_device_t *dev) {
75 free(dev);
76 return 0;
77 }
78
nfc_open(const hw_module_t * module,const char * name,hw_device_t ** device)79 static int nfc_open(const hw_module_t* module, const char* name,
80 hw_device_t** device) {
81 if (strcmp(name, NFC_NCI_CONTROLLER) == 0) {
82 nfc_nci_device_t *dev = static_cast<nfc_nci_device_t*>(
83 calloc(1, sizeof(nfc_nci_device_t)));
84
85 dev->common.tag = HARDWARE_DEVICE_TAG;
86 dev->common.version = 0x00010000; // [31:16] major, [15:0] minor
87 dev->common.module = (struct hw_module_t*) module;
88 dev->common.close = nfc_close;
89
90 // NCI HAL method pointers
91 dev->open = hal_open;
92 dev->write = hal_write;
93 dev->core_initialized = hal_core_initialized;
94 dev->pre_discover = hal_pre_discover;
95 dev->close = hal_close;
96 dev->control_granted = hal_control_granted;
97 dev->power_cycle = hal_power_cycle;
98
99 *device = (hw_device_t*) dev;
100
101 return 0;
102 } else {
103 return -EINVAL;
104 }
105 }
106
107
108 static struct hw_module_methods_t nfc_module_methods = {
109 .open = nfc_open,
110 };
111
112 struct nfc_nci_module_t HAL_MODULE_INFO_SYM = {
113 .common = {
114 .tag = HARDWARE_MODULE_TAG,
115 .module_api_version = 0x0100, // [15:8] major, [7:0] minor (1.0)
116 .hal_api_version = 0x00, // 0 is only valid value
117 .id = NFC_NCI_HARDWARE_MODULE_ID,
118 .name = "Default NFC NCI HW HAL",
119 .author = "The Android Open Source Project",
120 .methods = &nfc_module_methods,
121 },
122 };
123