blob: 0471b6b7165f50046ced4dfc400be09b14b49006 [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
Mark Salyzynd88dfe82017-04-11 08:56:09 -070020#include <log/log.h>
21
Martijn Coenen1c970f12012-09-12 17:59:39 -040022#include <hardware/hardware.h>
23#include <hardware/nfc.h>
24
Martijn Coenen1c970f12012-09-12 17:59:39 -040025/*
26 * NCI HAL method implementations. These must be overriden
27 */
Greg Kaiser23c710e2017-04-25 09:07:37 -070028static 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*/) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040031 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
32 return 0;
33}
34
Greg Kaiser23c710e2017-04-25 09:07:37 -070035static int hal_write(const struct nfc_nci_device* /*dev*/,
36 uint16_t /*data_len*/, const uint8_t* /*p_data*/) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040037 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
38 return 0;
39}
40
Greg Kaiser23c710e2017-04-25 09:07:37 -070041static int hal_core_initialized(const struct nfc_nci_device* /*dev*/,
42 uint8_t* /*p_core_init_rsp_params*/) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040043 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
44 return 0;
45}
46
Greg Kaiser23c710e2017-04-25 09:07:37 -070047static int hal_pre_discover(const struct nfc_nci_device* /*dev*/) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040048 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
49 return 0;
50}
51
Greg Kaiser23c710e2017-04-25 09:07:37 -070052static int hal_close(const struct nfc_nci_device* /*dev*/) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040053 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
54 return 0;
55}
56
Greg Kaiser23c710e2017-04-25 09:07:37 -070057static int hal_control_granted (const struct nfc_nci_device* /*p_dev*/)
Martijn Coenen1c970f12012-09-12 17:59:39 -040058{
59 ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
60 return 0;
61}
62
63
Greg Kaiser23c710e2017-04-25 09:07:37 -070064static int hal_power_cycle (const struct nfc_nci_device* /*p_dev*/)
Martijn Coenen1c970f12012-09-12 17:59:39 -040065{
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 */
74static int nfc_close(hw_device_t *dev) {
75 free(dev);
76 return 0;
77}
78
79static int nfc_open(const hw_module_t* module, const char* name,
Greg Kaiser23c710e2017-04-25 09:07:37 -070080 hw_device_t** device) {
Martijn Coenen1c970f12012-09-12 17:59:39 -040081 if (strcmp(name, NFC_NCI_CONTROLLER) == 0) {
Greg Kaiser23c710e2017-04-25 09:07:37 -070082 nfc_nci_device_t *dev = static_cast<nfc_nci_device_t*>(
83 calloc(1, sizeof(nfc_nci_device_t)));
Martijn Coenen1c970f12012-09-12 17:59:39 -040084
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
108static struct hw_module_methods_t nfc_module_methods = {
109 .open = nfc_open,
110};
111
112struct 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};