1 /****************************************************************************** 2 * 3 * Copyright 2022, 2024 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 #include <android-base/logging.h> 20 #include <android/binder_manager.h> 21 #include <android/binder_process.h> 22 23 #include <thread> 24 25 #include "Nfc.h" 26 #include "NxpNfc.h" 27 #include "phNxpNciHal_Adaptation.h" 28 #include "phNxpNciHal_Recovery.h" 29 #include "phNxpNciHal_WiredSeIface.h" 30 31 using ::aidl::android::hardware::nfc::Nfc; 32 using ::aidl::vendor::nxp::nxpnfc_aidl::INxpNfc; 33 using ::aidl::vendor::nxp::nxpnfc_aidl::NxpNfc; 34 using namespace std; 35 36 extern WiredSeHandle gWiredSeHandle; 37 startNxpNfcAidlService()38void startNxpNfcAidlService() { 39 ALOGI("NXP NFC Extn Service is starting."); 40 std::shared_ptr<NxpNfc> nxp_nfc_service = ndk::SharedRefBase::make<NxpNfc>(); 41 const std::string nxpNfcInstName = 42 std::string() + NxpNfc::descriptor + "/default"; 43 ALOGI("NxpNfc Registering service: %s", nxpNfcInstName.c_str()); 44 binder_status_t status = AServiceManager_addService( 45 nxp_nfc_service->asBinder().get(), nxpNfcInstName.c_str()); 46 ALOGI("NxpNfc Registered INxpNfc service status: %d", status); 47 CHECK(status == STATUS_OK); 48 ABinderProcess_joinThreadPool(); 49 } 50 main()51int main() { 52 ALOGI("NFC AIDL HAL starting up"); 53 if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) { 54 ALOGE("failed to set thread pool max thread count"); 55 return 1; 56 } 57 std::shared_ptr<Nfc> nfc_service = ndk::SharedRefBase::make<Nfc>(); 58 59 const std::string nfcInstName = std::string() + Nfc::descriptor + "/default"; 60 binder_status_t status = AServiceManager_addService( 61 nfc_service->asBinder().get(), nfcInstName.c_str()); 62 CHECK(status == STATUS_OK); 63 64 #if (NXP_NFC_RECOVERY == TRUE) 65 phNxpNciHal_RecoverFWTearDown(); 66 #endif 67 thread t1(startNxpNfcAidlService); 68 // Starts Wired SE HAL instance if platform supports 69 if (phNxpNciHal_WiredSeStart(&gWiredSeHandle) != NFCSTATUS_SUCCESS) { 70 ALOGE("Wired Se HAL Disabled"); 71 } 72 ABinderProcess_joinThreadPool(); 73 return 0; 74 } 75