• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2019-2021 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 
19 #define LOG_TAG "nxpnfc@2.0-service"
20 #include <android/hardware/nfc/1.1/INfc.h>
21 #include <unistd.h>
22 #include <vendor/nxp/nxpnfc/2.0/INxpNfc.h>
23 
24 #include <hidl/LegacySupport.h>
25 #include "Nfc.h"
26 #include "NxpNfc.h"
27 #include "eSEClientExtns.h"
28 
29 #if (NXP_NFC_RECOVERY == TRUE)
30 #include "phNxpNciHal_Recovery.h"
31 #endif
32 
33 // Generated HIDL files
34 using android::OK;
35 using android::sp;
36 using android::status_t;
37 using android::hardware::configureRpcThreadpool;
38 using android::hardware::joinRpcThreadpool;
39 using android::hardware::nfc::V1_2::INfc;
40 using android::hardware::nfc::V1_2::implementation::Nfc;
41 using vendor::nxp::nxpnfc::V2_0::INxpNfc;
42 using vendor::nxp::nxpnfc::V2_0::implementation::NxpNfc;
43 
main()44 int main() {
45   status_t status;
46 
47   sp<INfc> nfc_service = nullptr;
48   sp<INxpNfc> nxp_nfc_service = nullptr;
49 
50   try {
51     ALOGD("NFC HAL Service 1.2 is starting.");
52     nfc_service = new Nfc();
53     if (nfc_service == nullptr) {
54       ALOGE("Can not create an instance of NFC HAL Iface, exiting.");
55       return -1;
56     }
57 
58     configureRpcThreadpool(1, true /*callerWillJoin*/);
59 #if (NXP_NFC_RECOVERY == TRUE)
60     phNxpNciHal_RecoverFWTearDown();
61 #endif
62 #ifdef NXP_BOOTTIME_UPDATE
63     initializeEseClient();
64     checkEseClientUpdate();
65 #endif
66     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 
73     ALOGI("NXP NFC Extn Service 1.0 is starting.");
74     nxp_nfc_service = new NxpNfc();
75     if (nxp_nfc_service == nullptr) {
76       ALOGE("Can not create an instance of NXP NFC Extn Iface, exiting.");
77       return -1;
78     }
79     status = nxp_nfc_service->registerAsService();
80     if (status != OK) {
81       ALOGE("Could not register service for NXP NFC Extn Iface (%d).", status);
82     }
83 #ifdef NXP_BOOTTIME_UPDATE
84     ALOGE("Before calling JCOP JCOS_doDownload");
85     perform_eSEClientUpdate();
86     ALOGE("After calling JCOS_doDownload");
87 #endif
88     ALOGI("NFC service is ready");
89     joinRpcThreadpool();
90   } catch (const std::length_error& le) {
91   } catch (const std::__1::ios_base::failure& e) {
92   } catch (std::__1::system_error& e) {
93   }
94   return 1;
95 }
96