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