1 /******************************************************************************
2 *
3 * Copyright 2019 NXP
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18 #include "eSEClientExtns.h"
19
20 #include <dlfcn.h>
21 #include <hidl/LegacySupport.h>
22 #include <unistd.h>
23
24 void* HalLibnfc_handle = NULL;
25
26 /*******************************************************************************
27 **
28 ** Function initializeEseClient()
29 **
30 ** Description Loads the module dynamically to access the functions.
31 **
32 ** Parameters none
33 **
34 ** Returns void
35 *******************************************************************************/
initializeEseClient()36 void initializeEseClient() {
37 // Getting pointer to Ese Client module
38 HalLibnfc_handle = dlopen("/system/vendor/lib64/hal_libnfc.so", RTLD_NOW);
39
40 if (HalLibnfc_handle == NULL) {
41 /*fail to load the library*/
42 ALOGE("Error : opening (/system/vendor/lib64/hal_libnfc.so) !!");
43 return;
44 }
45 }
46 /*******************************************************************************
47 **
48 ** Function checkEseClientUpdate()
49 **
50 ** Description Interface API to dynamically invoke checkEseClientUpdate
51 ** method.
52 **
53 ** Parameters none
54 **
55 ** Returns void
56 *******************************************************************************/
checkEseClientUpdate()57 void checkEseClientUpdate() {
58 if (HalLibnfc_handle == NULL) return;
59
60 fpCheckEseClientUpdate_t fpCheckEseClientUpdate = NULL;
61
62 /*find the address of function and data objects*/
63 fpCheckEseClientUpdate =
64 (fpCheckEseClientUpdate_t)dlsym(HalLibnfc_handle, "checkEseClientUpdate");
65
66 if (!fpCheckEseClientUpdate) {
67 ALOGE("Error while linking (checkEseClientUpdate) %s!!", dlerror());
68 } else {
69 ALOGD("Success: while linking (checkEseClientUpdate) !!");
70 /* invoke function*/
71 fpCheckEseClientUpdate();
72 }
73 }
74 /*******************************************************************************
75 **
76 ** Function perform_eSEClientUpdate()
77 **
78 ** Description Interface API to dynamically invoke perform_eSEClientUpdate
79 ** method.
80 **
81 ** Parameters none
82 **
83 ** Returns void
84 *******************************************************************************/
perform_eSEClientUpdate()85 void perform_eSEClientUpdate() {
86 if (HalLibnfc_handle == NULL) return;
87
88 fpPerformEseClientUpdate_t fpPerformEseClientUpdate = NULL;
89
90 /*find the address of function and data objects*/
91 fpPerformEseClientUpdate = (fpPerformEseClientUpdate_t)dlsym(
92 HalLibnfc_handle, "perform_eSEClientUpdate");
93
94 if (!fpPerformEseClientUpdate) {
95 ALOGE("Error while linking (perform_eSEClientUpdate) !!");
96 } else {
97 ALOGD("Success while linking (perform_eSEClientUpdate) !!");
98 fpPerformEseClientUpdate();
99 }
100 }
101 /*******************************************************************************
102 **
103 ** Function eSEClientUpdate_NFC_Thread
104 **
105 ** Description Interface API to dynamically invoke
106 ** eSEClientUpdate_NFC_Thread method.
107 **
108 ** Parameters none
109 **
110 ** Returns void
111 *******************************************************************************/
eSEClientUpdate_NFC_Thread()112 void eSEClientUpdate_NFC_Thread() {
113 if (HalLibnfc_handle == NULL) return;
114
115 fpEseClientUpdate_Nfc_Thread_t fpEseClientUpdate_Nfc_Thread = NULL;
116
117 /*find the address of function and data objects*/
118 fpEseClientUpdate_Nfc_Thread = (fpEseClientUpdate_Nfc_Thread_t)dlsym(
119 HalLibnfc_handle, "eSEClientUpdate_NFC_Thread");
120
121 if (!fpEseClientUpdate_Nfc_Thread) {
122 ALOGE("Error while linking (eSEClientUpdate_NFC_Thread) !!");
123 } else {
124 ALOGD("Success while linking (eSEClientUpdate_NFC_Thread) !!");
125 /* invoke function*/
126 fpEseClientUpdate_Nfc_Thread();
127 }
128 }
129 /*******************************************************************************
130 **
131 ** Function seteSEClientState
132 **
133 ** Description Interface API to dynamically invoke seteSEClientState
134 ** method.
135 **
136 ** Parameters int
137 **
138 ** Returns none
139 *******************************************************************************/
seteSEClientState(uint8_t state)140 void seteSEClientState(uint8_t state) {
141 if (HalLibnfc_handle == NULL) return;
142
143 fpSeteSEClientState_t fpSeteSEClientState = NULL;
144
145 ALOGD("seteSEClientState state %d", state);
146
147 /*find the address of function and data objects*/
148 fpSeteSEClientState =
149 (fpSeteSEClientState_t)dlsym(HalLibnfc_handle, "seteSEClientState");
150
151 if (!fpSeteSEClientState) {
152 ALOGE("Error while linking (seteSEClientState) !!");
153 } else {
154 ALOGD("Success while linking (seteSEClientState) !!");
155 /* invoke function, passing value of integer as a parameter */
156 fpSeteSEClientState(state);
157 }
158 }
159 /*******************************************************************************
160 **
161 ** Function deinitializeEseClient(void)
162 **
163 ** Description Resets the module handle & all the function pointers
164 **
165 ** Parameters none
166 **
167 ** Returns void
168 *******************************************************************************/
deinitializeEseClient()169 void deinitializeEseClient() {
170 if (HalLibnfc_handle != NULL) {
171 ALOGD("closing hal_libnfc.so");
172 dlclose(HalLibnfc_handle);
173 HalLibnfc_handle = NULL;
174 }
175 }
176