xref: /aosp_15_r20/hardware/libhardware/modules/nfc-nci/nfc_nci_example.cpp (revision e01b6f769022e40d0923dee176e8dc7cd1d52984)
1*e01b6f76SAndroid Build Coastguard Worker /*
2*e01b6f76SAndroid Build Coastguard Worker  * Copyright (C) 2012 The Android Open Source Project
3*e01b6f76SAndroid Build Coastguard Worker  *
4*e01b6f76SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*e01b6f76SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*e01b6f76SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*e01b6f76SAndroid Build Coastguard Worker  *
8*e01b6f76SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*e01b6f76SAndroid Build Coastguard Worker  *
10*e01b6f76SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*e01b6f76SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*e01b6f76SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e01b6f76SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*e01b6f76SAndroid Build Coastguard Worker  * limitations under the License.
15*e01b6f76SAndroid Build Coastguard Worker  */
16*e01b6f76SAndroid Build Coastguard Worker #include <errno.h>
17*e01b6f76SAndroid Build Coastguard Worker #include <malloc.h>
18*e01b6f76SAndroid Build Coastguard Worker #include <string.h>
19*e01b6f76SAndroid Build Coastguard Worker 
20*e01b6f76SAndroid Build Coastguard Worker #include <log/log.h>
21*e01b6f76SAndroid Build Coastguard Worker 
22*e01b6f76SAndroid Build Coastguard Worker #include <hardware/hardware.h>
23*e01b6f76SAndroid Build Coastguard Worker #include <hardware/nfc.h>
24*e01b6f76SAndroid Build Coastguard Worker 
25*e01b6f76SAndroid Build Coastguard Worker /*
26*e01b6f76SAndroid Build Coastguard Worker  * NCI HAL method implementations. These must be overriden
27*e01b6f76SAndroid Build Coastguard Worker  */
hal_open(const struct nfc_nci_device *,nfc_stack_callback_t *,nfc_stack_data_callback_t *)28*e01b6f76SAndroid Build Coastguard Worker static int hal_open(const struct nfc_nci_device* /*dev*/,
29*e01b6f76SAndroid Build Coastguard Worker                     nfc_stack_callback_t* /*p_cback*/,
30*e01b6f76SAndroid Build Coastguard Worker                     nfc_stack_data_callback_t* /*p_data_cback*/) {
31*e01b6f76SAndroid Build Coastguard Worker     ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
32*e01b6f76SAndroid Build Coastguard Worker     return 0;
33*e01b6f76SAndroid Build Coastguard Worker }
34*e01b6f76SAndroid Build Coastguard Worker 
hal_write(const struct nfc_nci_device *,uint16_t,const uint8_t *)35*e01b6f76SAndroid Build Coastguard Worker static int hal_write(const struct nfc_nci_device* /*dev*/,
36*e01b6f76SAndroid Build Coastguard Worker                      uint16_t /*data_len*/, const uint8_t* /*p_data*/) {
37*e01b6f76SAndroid Build Coastguard Worker     ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
38*e01b6f76SAndroid Build Coastguard Worker     return 0;
39*e01b6f76SAndroid Build Coastguard Worker }
40*e01b6f76SAndroid Build Coastguard Worker 
hal_core_initialized(const struct nfc_nci_device *,uint8_t *)41*e01b6f76SAndroid Build Coastguard Worker static int hal_core_initialized(const struct nfc_nci_device* /*dev*/,
42*e01b6f76SAndroid Build Coastguard Worker                                 uint8_t* /*p_core_init_rsp_params*/) {
43*e01b6f76SAndroid Build Coastguard Worker     ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
44*e01b6f76SAndroid Build Coastguard Worker     return 0;
45*e01b6f76SAndroid Build Coastguard Worker }
46*e01b6f76SAndroid Build Coastguard Worker 
hal_pre_discover(const struct nfc_nci_device *)47*e01b6f76SAndroid Build Coastguard Worker static int hal_pre_discover(const struct nfc_nci_device* /*dev*/) {
48*e01b6f76SAndroid Build Coastguard Worker     ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
49*e01b6f76SAndroid Build Coastguard Worker     return 0;
50*e01b6f76SAndroid Build Coastguard Worker }
51*e01b6f76SAndroid Build Coastguard Worker 
hal_close(const struct nfc_nci_device *)52*e01b6f76SAndroid Build Coastguard Worker static int hal_close(const struct nfc_nci_device* /*dev*/) {
53*e01b6f76SAndroid Build Coastguard Worker     ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
54*e01b6f76SAndroid Build Coastguard Worker     return 0;
55*e01b6f76SAndroid Build Coastguard Worker }
56*e01b6f76SAndroid Build Coastguard Worker 
hal_control_granted(const struct nfc_nci_device *)57*e01b6f76SAndroid Build Coastguard Worker static int hal_control_granted (const struct nfc_nci_device* /*p_dev*/)
58*e01b6f76SAndroid Build Coastguard Worker {
59*e01b6f76SAndroid Build Coastguard Worker     ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
60*e01b6f76SAndroid Build Coastguard Worker     return 0;
61*e01b6f76SAndroid Build Coastguard Worker }
62*e01b6f76SAndroid Build Coastguard Worker 
63*e01b6f76SAndroid Build Coastguard Worker 
hal_power_cycle(const struct nfc_nci_device *)64*e01b6f76SAndroid Build Coastguard Worker static int hal_power_cycle (const struct nfc_nci_device* /*p_dev*/)
65*e01b6f76SAndroid Build Coastguard Worker {
66*e01b6f76SAndroid Build Coastguard Worker     ALOGE("NFC-NCI HAL: %s", __FUNCTION__);
67*e01b6f76SAndroid Build Coastguard Worker     return 0;
68*e01b6f76SAndroid Build Coastguard Worker }
69*e01b6f76SAndroid Build Coastguard Worker 
70*e01b6f76SAndroid Build Coastguard Worker /*
71*e01b6f76SAndroid Build Coastguard Worker  * Generic device handling below - can generally be left unchanged.
72*e01b6f76SAndroid Build Coastguard Worker  */
73*e01b6f76SAndroid Build Coastguard Worker /* Close an opened nfc device instance */
nfc_close(hw_device_t * dev)74*e01b6f76SAndroid Build Coastguard Worker static int nfc_close(hw_device_t *dev) {
75*e01b6f76SAndroid Build Coastguard Worker     free(dev);
76*e01b6f76SAndroid Build Coastguard Worker     return 0;
77*e01b6f76SAndroid Build Coastguard Worker }
78*e01b6f76SAndroid Build Coastguard Worker 
nfc_open(const hw_module_t * module,const char * name,hw_device_t ** device)79*e01b6f76SAndroid Build Coastguard Worker static int nfc_open(const hw_module_t* module, const char* name,
80*e01b6f76SAndroid Build Coastguard Worker                     hw_device_t** device) {
81*e01b6f76SAndroid Build Coastguard Worker     if (strcmp(name, NFC_NCI_CONTROLLER) == 0) {
82*e01b6f76SAndroid Build Coastguard Worker         nfc_nci_device_t *dev = static_cast<nfc_nci_device_t*>(
83*e01b6f76SAndroid Build Coastguard Worker                 calloc(1, sizeof(nfc_nci_device_t)));
84*e01b6f76SAndroid Build Coastguard Worker 
85*e01b6f76SAndroid Build Coastguard Worker         dev->common.tag = HARDWARE_DEVICE_TAG;
86*e01b6f76SAndroid Build Coastguard Worker         dev->common.version = 0x00010000; // [31:16] major, [15:0] minor
87*e01b6f76SAndroid Build Coastguard Worker         dev->common.module = (struct hw_module_t*) module;
88*e01b6f76SAndroid Build Coastguard Worker         dev->common.close = nfc_close;
89*e01b6f76SAndroid Build Coastguard Worker 
90*e01b6f76SAndroid Build Coastguard Worker         // NCI HAL method pointers
91*e01b6f76SAndroid Build Coastguard Worker         dev->open = hal_open;
92*e01b6f76SAndroid Build Coastguard Worker         dev->write = hal_write;
93*e01b6f76SAndroid Build Coastguard Worker         dev->core_initialized = hal_core_initialized;
94*e01b6f76SAndroid Build Coastguard Worker         dev->pre_discover = hal_pre_discover;
95*e01b6f76SAndroid Build Coastguard Worker         dev->close = hal_close;
96*e01b6f76SAndroid Build Coastguard Worker         dev->control_granted = hal_control_granted;
97*e01b6f76SAndroid Build Coastguard Worker         dev->power_cycle = hal_power_cycle;
98*e01b6f76SAndroid Build Coastguard Worker 
99*e01b6f76SAndroid Build Coastguard Worker         *device = (hw_device_t*) dev;
100*e01b6f76SAndroid Build Coastguard Worker 
101*e01b6f76SAndroid Build Coastguard Worker         return 0;
102*e01b6f76SAndroid Build Coastguard Worker     } else {
103*e01b6f76SAndroid Build Coastguard Worker         return -EINVAL;
104*e01b6f76SAndroid Build Coastguard Worker     }
105*e01b6f76SAndroid Build Coastguard Worker }
106*e01b6f76SAndroid Build Coastguard Worker 
107*e01b6f76SAndroid Build Coastguard Worker 
108*e01b6f76SAndroid Build Coastguard Worker static struct hw_module_methods_t nfc_module_methods = {
109*e01b6f76SAndroid Build Coastguard Worker     .open = nfc_open,
110*e01b6f76SAndroid Build Coastguard Worker };
111*e01b6f76SAndroid Build Coastguard Worker 
112*e01b6f76SAndroid Build Coastguard Worker struct nfc_nci_module_t HAL_MODULE_INFO_SYM = {
113*e01b6f76SAndroid Build Coastguard Worker     .common = {
114*e01b6f76SAndroid Build Coastguard Worker         .tag = HARDWARE_MODULE_TAG,
115*e01b6f76SAndroid Build Coastguard Worker         .module_api_version = 0x0100, // [15:8] major, [7:0] minor (1.0)
116*e01b6f76SAndroid Build Coastguard Worker         .hal_api_version = 0x00, // 0 is only valid value
117*e01b6f76SAndroid Build Coastguard Worker         .id = NFC_NCI_HARDWARE_MODULE_ID,
118*e01b6f76SAndroid Build Coastguard Worker         .name = "Default NFC NCI HW HAL",
119*e01b6f76SAndroid Build Coastguard Worker         .author = "The Android Open Source Project",
120*e01b6f76SAndroid Build Coastguard Worker         .methods = &nfc_module_methods,
121*e01b6f76SAndroid Build Coastguard Worker     },
122*e01b6f76SAndroid Build Coastguard Worker };
123