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 #define VENDOR_LIB_PATH "/vendor/lib64/"
29 #define VENDOR_LIB_EXT ".so"
30
31 // Generated HIDL files
32 using android::OK;
33 using android::sp;
34 using android::status_t;
35 using android::hardware::configureRpcThreadpool;
36 using android::hardware::joinRpcThreadpool;
37 using android::hardware::nfc::V1_2::INfc;
38 using android::hardware::nfc::V1_2::implementation::Nfc;
39
40 typedef int (*STEseReset)(void);
41
main()42 int main() {
43 ALOGD(" ST NFC HAL Service 1.2 is starting.");
44 sp<INfc> nfc_service = new Nfc();
45
46 std::string valueStr =
47 android::base::GetProperty("persist.vendor.nfc.streset", "");
48 if (valueStr.length() > 0) {
49 valueStr = VENDOR_LIB_PATH + valueStr + VENDOR_LIB_EXT;
50 void* stdll = dlopen(valueStr.c_str(), RTLD_NOW);
51 ALOGD("ST NFC HAL STReset starting.");
52 if (stdll) {
53 ALOGD("STReset Start");
54 STEseReset fn = (STEseReset)dlsym(stdll, "boot_reset");
55 if (fn) {
56 int ret = fn();
57 ALOGD("STReset Result=%d", ret);
58 }
59 } else {
60 ALOGE("%s not found, do nothing.", valueStr.c_str());
61 }
62 ALOGD("ST NFC HAL STReset Done.");
63 }
64
65 configureRpcThreadpool(1, true /*callerWillJoin*/);
66 status_t status = nfc_service->registerAsService();
67 if (status != OK) {
68 LOG_ALWAYS_FATAL("Could not register service for NFC HAL Iface (%d).",
69 status);
70 return -1;
71 }
72 ALOGD(" ST NFC service is ready");
73 joinRpcThreadpool();
74 return 1;
75 }
76