1 /******************************************************************************
2  *
3  *  Copyright 2018 NXP
4  *  Copyright 2018 ST Microelectronics
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 
20 #define LOG_TAG "stnfc@1.2-service.st"
21 #include <android-base/properties.h>
22 #include <android/hardware/nfc/1.1/INfc.h>
23 #include <dlfcn.h>
24 
25 #include <hidl/LegacySupport.h>
26 #include "Nfc.h"
27 
28 #if defined(ST_LIB_32)
29 #define VENDOR_LIB_PATH "/vendor/lib/"
30 #else
31 #define VENDOR_LIB_PATH "/vendor/lib64/"
32 #endif
33 #define VENDOR_LIB_EXT ".so"
34 
35 // Generated HIDL files
36 using android::OK;
37 using android::sp;
38 using android::status_t;
39 using android::hardware::configureRpcThreadpool;
40 using android::hardware::joinRpcThreadpool;
41 using android::hardware::nfc::V1_2::INfc;
42 using android::hardware::nfc::V1_2::implementation::Nfc;
43 
44 typedef int (*STEseReset)(void);
45 
main()46 int main() {
47   ALOGD(" ST NFC HAL Service 1.2 is starting.");
48   sp<INfc> nfc_service = new Nfc();
49 
50   std::string valueStr =
51       android::base::GetProperty("persist.vendor.nfc.streset", "");
52   if (valueStr.length() > 0) {
53     valueStr = VENDOR_LIB_PATH + valueStr + VENDOR_LIB_EXT;
54     void* stdll = dlopen(valueStr.c_str(), RTLD_NOW);
55     ALOGD("ST NFC HAL STReset starting.");
56     if (stdll) {
57       ALOGD("STReset Start");
58       STEseReset fn = (STEseReset)dlsym(stdll, "boot_reset");
59       if (fn) {
60         int ret = fn();
61         ALOGD("STReset Result=%d", ret);
62       }
63     } else {
64       ALOGE("%s not found, do nothing.", valueStr.c_str());
65     }
66     ALOGD("ST NFC HAL STReset Done.");
67   }
68 
69   configureRpcThreadpool(1, true /*callerWillJoin*/);
70   status_t status = nfc_service->registerAsService();
71   if (status != OK) {
72     LOG_ALWAYS_FATAL("Could not register service for NFC HAL Iface (%d).",
73                      status);
74     return -1;
75   }
76   ALOGD(" ST NFC service is ready");
77   joinRpcThreadpool();
78   return 1;
79 }
80