Snap for 10103804 from fcda8a64e6d32a2faa6c53c08893640abcd41d7c to mainline-tzdata5-release

Change-Id: Ife52e303a901c6ca8085978a7ac4f643265ed716
diff --git a/snxxx/1.0/VirtualISO.cpp b/snxxx/1.0/VirtualISO.cpp
index 0b3a383..3683208 100644
--- a/snxxx/1.0/VirtualISO.cpp
+++ b/snxxx/1.0/VirtualISO.cpp
@@ -237,7 +237,7 @@
         LOG(INFO) << "seDeInit Failed";
       }
     }
-    /*If manageChanle is failed in any of above cases
+    /*If manageChannel is failed in any of above cases
     send the callback and return*/
     status = phNxpEse_ResetEndPoint_Cntxt(1);
     if (status != ESESTATUS_SUCCESS) {
@@ -257,12 +257,12 @@
 
   if ((resApduBuff.channelNumber > 0x03) &&
       (resApduBuff.channelNumber < 0x14)) {
-    /* update CLA byte accoridng to GP spec Table 11-12*/
+    /* update CLA byte according to GP spec Table 11-12*/
     cpdu.cla =
         0x40 + (resApduBuff.channelNumber - 4); /* Class of instruction */
   } else if ((resApduBuff.channelNumber > 0x00) &&
              (resApduBuff.channelNumber < 0x04)) {
-    /* update CLA byte accoridng to GP spec Table 11-11*/
+    /* update CLA byte according to GP spec Table 11-11*/
     cpdu.cla = resApduBuff.channelNumber; /* Class of instruction */
   } else {
     LOG(ERROR) << StringPrintf("%s: Invalid Channel no: %02x", __func__,
@@ -448,9 +448,9 @@
     phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
     phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
     cpdu.cla = channelNumber; /* Class of instruction */
-    // For Suplementary Channel update CLA byte according to GP
+    // For Supplementary Channel update CLA byte according to GP
     if ((channelNumber > 0x03) && (channelNumber < 0x14)) {
-      /* update CLA byte accoridng to GP spec Table 11-12*/
+      /* update CLA byte according to GP spec Table 11-12*/
       cpdu.cla = 0x40 + (channelNumber - 4); /* Class of instruction */
     }
     cpdu.ins = 0x70;          /* Instruction code */
@@ -599,7 +599,6 @@
   status = phNxpEse_close(deInitStatus);
   if (status == ESESTATUS_SUCCESS && mIsDeInitDone) {
     sestatus = SecureElementStatus::SUCCESS;
-    ;
   } else {
     LOG(ERROR) << "seHalDeInit: Failed";
   }
diff --git a/snxxx/1.1/SecureElement.cpp b/snxxx/1.1/SecureElement.cpp
index 991add7..dafde01 100755
--- a/snxxx/1.1/SecureElement.cpp
+++ b/snxxx/1.1/SecureElement.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -99,17 +99,26 @@
 
   status = phNxpEse_open(initParams);
   if (status == ESESTATUS_SUCCESS || ESESTATUS_BUSY == status) {
+    ESESTATUS initStatus = ESESTATUS_SUCCESS;
     ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
-    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0) &&
-        ESESTATUS_SUCCESS == phNxpEse_init(initParams)) {
-      if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
-        LOG(INFO) << "ESE SPI init complete!!!";
-        mIsInitDone = true;
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0)) {
+      initStatus = phNxpEse_init(initParams);
+      if (initStatus == ESESTATUS_SUCCESS) {
+        if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
+          LOG(INFO) << "ESE SPI init complete!!!";
+          mIsInitDone = true;
+        }
+        deInitStatus = phNxpEse_deInit();
+        if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
       }
-      deInitStatus = phNxpEse_deInit();
-      if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
     }
     status = phNxpEse_close(deInitStatus);
+    /*Enable terminal post recovery(i.e. close success) from transmit failure */
+    if (status == ESESTATUS_SUCCESS &&
+        (initStatus == ESESTATUS_TRANSCEIVE_FAILED ||
+         initStatus == ESESTATUS_FAILED)) {
+      mIsInitDone = true;
+    }
   }
   if (status == ESESTATUS_SUCCESS && mIsInitDone) {
     mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
@@ -158,17 +167,26 @@
 
   status = phNxpEse_open(initParams);
   if (status == ESESTATUS_SUCCESS || ESESTATUS_BUSY == status) {
+    ESESTATUS initStatus = ESESTATUS_SUCCESS;
     ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
-    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0) &&
-        ESESTATUS_SUCCESS == phNxpEse_init(initParams)) {
-      if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
-        LOG(INFO) << "ESE SPI init complete!!!";
-        mIsInitDone = true;
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0)) {
+      initStatus = phNxpEse_init(initParams);
+      if (initStatus == ESESTATUS_SUCCESS) {
+        if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
+          LOG(INFO) << "ESE SPI init complete!!!";
+          mIsInitDone = true;
+        }
+        deInitStatus = phNxpEse_deInit();
+        if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
       }
-      deInitStatus = phNxpEse_deInit();
-      if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
     }
     status = phNxpEse_close(deInitStatus);
+    /*Enable terminal post recovery(i.e. close success) from transmit failure */
+    if (status == ESESTATUS_SUCCESS &&
+        (initStatus == ESESTATUS_TRANSCEIVE_FAILED ||
+         initStatus == ESESTATUS_FAILED)) {
+      mIsInitDone = true;
+    }
   }
   if (status == ESESTATUS_SUCCESS && mIsInitDone) {
     mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
@@ -361,7 +379,7 @@
         LOG(INFO) << "seDeInit Failed";
       }
     }
-    /*If manageChanle is failed in any of above cases
+    /*If manageChannel is failed in any of above cases
     send the callback and return*/
     status = phNxpEse_ResetEndPoint_Cntxt(0);
     if (status != ESESTATUS_SUCCESS) {
@@ -381,12 +399,12 @@
 
   if ((resApduBuff.channelNumber > 0x03) &&
       (resApduBuff.channelNumber < 0x14)) {
-    /* update CLA byte accoridng to GP spec Table 11-12*/
+    /* update CLA byte according to GP spec Table 11-12*/
     cpdu.cla =
         0x40 + (resApduBuff.channelNumber - 4); /* Class of instruction */
   } else if ((resApduBuff.channelNumber > 0x00) &&
              (resApduBuff.channelNumber < 0x04)) {
-    /* update CLA byte accoridng to GP spec Table 11-11*/
+    /* update CLA byte according to GP spec Table 11-11*/
     cpdu.cla = resApduBuff.channelNumber; /* Class of instruction */
   } else {
     LOG(ERROR) << StringPrintf("%s: Invalid Channel no: %02x", __func__,
@@ -579,9 +597,9 @@
     phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
     phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
     cpdu.cla = channelNumber; /* Class of instruction */
-    // For Suplementary Channel update CLA byte according to GP
+    // For Supplementary Channel update CLA byte according to GP
     if ((channelNumber > 0x03) && (channelNumber < 0x14)) {
-      /* update CLA byte accoridng to GP spec Table 11-12*/
+      /* update CLA byte according to GP spec Table 11-12*/
       cpdu.cla = 0x40 + (channelNumber - 4); /* Class of instruction */
     }
     cpdu.ins = 0x70;          /* Instruction code */
diff --git a/snxxx/1.2/Android.bp b/snxxx/1.2/Android.bp
new file mode 100644
index 0000000..5ca335d
--- /dev/null
+++ b/snxxx/1.2/Android.bp
@@ -0,0 +1,94 @@
+//
+// Copyright 2023 NXP
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "hardware_nxp_secure_element_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["hardware_nxp_secure_element_license"],
+}
+
+cc_binary {
+    relative_install_path: "hw",
+    name: "android.hardware.secure_element_snxxx@1.2-service",
+    init_rc: ["android.hardware.secure_element_snxxx@1.2-service.rc"],
+    proprietary: true,
+    defaults: ["hidl_defaults"],
+    enabled: true,
+    srcs: [
+        "NxpEseService.cpp",
+        "SecureElement.cpp",
+        "VirtualISO.cpp",
+        ":ExtnsFile",
+        ":OsuHalCommonFile",
+    ],
+
+    shared_libs: [
+        "android.hardware.secure_element@1.0",
+        "android.hardware.secure_element@1.1",
+        "android.hardware.secure_element@1.2",
+        "ese_spi_nxp_snxxx",
+        "libbase",
+        "libbinder",
+        "libbinder_ndk",
+        "libcutils",
+        "libdl",
+        "libhardware",
+        "libhidlbase",
+        "liblog",
+        "libutils",
+        "libchrome",
+        "vendor.nxp.nxpese@1.0",
+        "vendor.nxp.nxpnfc@2.0",
+        "vendor.nxp.nxpnfc_aidl-V1-ndk",
+        "android.hardware.nfc@1.0",
+        "android.hardware.nfc@1.1",
+        "android.hardware.nfc@1.2",
+        "android.hardware.nfc-V1-ndk",
+        "libmemunreachable",
+    ],
+
+    include_dirs: [
+        "hardware/nxp/secure_element/snxxx/extns/impl",
+        "hardware/nxp/secure_element/snxxx/libese-spi/common/include",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/common",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/inc",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/lib",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/pal",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/pal/spi",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/utils",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/spm",
+        "hardware/nxp/secure_element/snxxx/libese-spi/src/include",
+        "hardware/nxp/secure_element/snxxx/ese-clients/inc",
+        "hardware/nxp/secure_element/snxxx/OsuHal/inc",
+    ],
+    cflags: [
+        "-DANDROID",
+        "-DJCOP_VER_3_1=1",
+        "-DJCOP_VER_3_2=2",
+        "-DJCOP_VER_3_3=3",
+        "-DJCOP_VER_4_0=4",
+        "-DJCOP_VER_5_x=5",
+        "-DBUILDCFG=1",
+        "-DNXP_EXTNS=TRUE",
+        "-DNFC_NXP_ESE_VER=JCOP_VER_5_x",
+        "-Wall",
+        "-Werror",
+        "-fexceptions",
+    ],
+
+}
diff --git a/snxxx/1.2/NxpEseService.cpp b/snxxx/1.2/NxpEseService.cpp
index eba57e0..b3ff2b9 100755
--- a/snxxx/1.2/NxpEseService.cpp
+++ b/snxxx/1.2/NxpEseService.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
  *
  ******************************************************************************/
 #define LOG_TAG "nxpese@1.2-service"
+#include <aidl/android/hardware/nfc/INfc.h>
 #include <android/hardware/nfc/1.2/INfc.h>
 #include <android/hardware/secure_element/1.2/ISecureElement.h>
 #include <hidl/LegacySupport.h>
@@ -42,33 +43,46 @@
 using android::hardware::defaultPassthroughServiceImplementation;
 using android::hardware::joinRpcThreadpool;
 using android::hardware::registerPassthroughServiceImplementation;
-using android::hardware::nfc::V1_2::INfc;
+using INfc = android::hardware::nfc::V1_2::INfc;
 using android::hardware::secure_element::V1_2::ISecureElement;
 using android::hardware::secure_element::V1_2::implementation::SecureElement;
 using vendor::nxp::nxpese::V1_0::INxpEse;
 using vendor::nxp::nxpese::V1_0::implementation::NxpEse;
 using vendor::nxp::virtual_iso::V1_0::implementation::VirtualISO;
+using INfcAidl = ::aidl::android::hardware::nfc::INfc;
 
 using android::OK;
 using android::sp;
 using android::status_t;
 
+std::string NFC_AIDL_HAL_SERVICE_NAME = "android.hardware.nfc.INfc/default";
+
 static inline void waitForNFCHAL() {
   int retry = 0;
   android::sp<INfc> nfc_service = nullptr;
+  std::shared_ptr<INfcAidl> nfc_aidl_service = nullptr;
 
   ALOGI("Waiting for NFC HAL .. ");
   do {
-    nfc_service = INfc::tryGetService();
-    if (nfc_service != nullptr) {
+    ::ndk::SpAIBinder binder(
+        AServiceManager_checkService(NFC_AIDL_HAL_SERVICE_NAME.c_str()));
+    nfc_aidl_service = INfcAidl::fromBinder(binder);
+    if (nfc_aidl_service != nullptr) {
       ALOGI("NFC HAL service is registered");
       break;
     }
     /* Wait for 100 MS for HAL RETRY*/
     usleep(NFC_GET_SERVICE_DELAY_MS * 1000);
   } while (retry++ < MAX_NFC_GET_RETRY);
-  if (nfc_service == nullptr) {
-    ALOGE("Failed to get NFC HAL Service");
+
+  if (nfc_aidl_service == nullptr) {
+    ALOGE("Failed to get NFC AIDLHAL Service, trying to get HIDL service");
+    nfc_service = INfc::tryGetService();
+    if (nfc_service != nullptr) {
+      ALOGI("NFC HAL service is registered");
+    } else {
+      ALOGE("Failed to get NFC HAL Service");
+    }
   }
 }
 
diff --git a/snxxx/1.2/SecureElement.cpp b/snxxx/1.2/SecureElement.cpp
index 520d545..42f2cd2 100755
--- a/snxxx/1.2/SecureElement.cpp
+++ b/snxxx/1.2/SecureElement.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -23,24 +23,25 @@
 #endif
 #include <android-base/logging.h>
 #include <android-base/stringprintf.h>
+#include <hidl/HidlTransportSupport.h>
 
 #include "hal_nxpese.h"
 #include "phNxpEse_Apdu_Api.h"
 #include "phNxpEse_Api.h"
 /* Mutex to synchronize multiple transceive */
-
+#include <memunreachable/memunreachable.h>
 namespace android {
 namespace hardware {
 namespace secure_element {
 namespace V1_2 {
 namespace implementation {
 
-#define LOG_TAG "nxpese@1.2-service"
 #define DEFAULT_BASIC_CHANNEL 0x00
 #define INVALID_LEN_SW1 0x64
 #define INVALID_LEN_SW2 0xFF
 #define SW1_BYTES_REMAINING 0x61
-
+#define NUM_OF_CH4 0x04
+#define NUM_OF_CH5 0x05
 typedef struct gsTransceiveBuffer {
   phNxpEse_data cmdData;
   phNxpEse_data rspData;
@@ -53,7 +54,6 @@
 static sTransceiveBuffer_t gsTxRxBuffer;
 static hidl_vec<uint8_t> gsRspDataBuff(256);
 sp<V1_0::ISecureElementHalCallback> SecureElement::mCallbackV1_0 = nullptr;
-sp<V1_1::ISecureElementHalCallback> SecureElement::mCallbackV1_1 = nullptr;
 std::vector<bool> SecureElement::mOpenedChannels;
 using vendor::nxp::nxpese::V1_0::implementation::NxpEse;
 SecureElement::SecureElement()
@@ -104,24 +104,35 @@
   phNxpEse_setWtxCountLimit(OsuHalExtn::getInstance().getOSUMaxWtxCount());
   status = phNxpEse_open(initParams);
   if (status == ESESTATUS_SUCCESS || ESESTATUS_BUSY == status) {
+    ESESTATUS initStatus = ESESTATUS_SUCCESS;
     ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
-    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0) &&
-        ESESTATUS_SUCCESS == phNxpEse_init(initParams)) {
-      /*update OS mode during first init*/
-      IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0)) {
+      initStatus = phNxpEse_init(initParams);
+      if (ESESTATUS_SUCCESS == initStatus) {
+        /*update OS mode during first init*/
+        IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
 
-      if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
-        LOG(INFO) << "ESE SPI init complete!!!";
-        mIsInitDone = true;
+        if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
+          LOG(INFO) << "ESE SPI init complete!!!";
+          mIsInitDone = true;
+        }
+        deInitStatus = phNxpEse_deInit();
+        if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
       }
-      deInitStatus = phNxpEse_deInit();
-      if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
     }
     status = phNxpEse_close(deInitStatus);
+    /*Enable terminal post recovery(i.e. close success) from transmit failure */
+    if (status == ESESTATUS_SUCCESS &&
+        (initStatus == ESESTATUS_TRANSCEIVE_FAILED ||
+         initStatus == ESESTATUS_FAILED)) {
+      IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+      mIsInitDone = true;
+    }
   }
   phNxpEse_setWtxCountLimit(RESET_APP_WTX_COUNT);
   if (status == ESESTATUS_SUCCESS && mIsInitDone) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mHasPriorityAccess = phNxpEse_isPriorityAccessEnabled();
+    mMaxChannelCount = getMaxChannelCnt();
     mOpenedChannels.resize(mMaxChannelCount, false);
     clientCallback->onStateChange(true);
     mCallbackV1_0 = clientCallback;
@@ -131,7 +142,45 @@
   }
   return Void();
 }
+void SecureElement::registerCallback(
+    const sp<V1_1::ISecureElementHalCallback>& callback) {
+  if (callback == nullptr) {
+    return;
+  }
+  mCallbacks.push_back(callback);
 
+  LOG(INFO) << __func__ << " New client " << callback.get()
+            << " registered . total clients = " << mCallbacks.size();
+
+  auto linkRet = callback->linkToDeath(this, 0u /* cookie */);
+  if (!linkRet.withDefault(false)) {
+    LOG(WARNING) << __func__ << " Cannot link to death: "
+                 << (linkRet.isOk() ? "linkToDeath returns false"
+                                    : linkRet.description());
+  }
+}
+
+void SecureElement::unregisterCallback(const sp<IBase>& callback) {
+  if (callback == nullptr) return;
+  bool removed = false;
+
+  for (auto it = mCallbacks.begin(); it != mCallbacks.end();) {
+    if (interfacesEqual(*it, callback)) {
+      it = mCallbacks.erase(it);
+      removed = true;
+    } else {
+      ++it;
+    }
+  }
+  callback->unlinkToDeath(this).isOk();  // ignore errors
+
+  if (removed)
+    LOG(INFO) << __func__ << " client " << callback.get()
+              << " removed. Total clients = " << mCallbacks.size();
+  else
+    LOG(WARNING) << __func__ << " Failed to remove client. total clients = "
+                 << mCallbacks.size();
+}
 Return<void> SecureElement::init_1_1(
     const sp<
         ::android::hardware::secure_element::V1_1::ISecureElementHalCallback>&
@@ -144,22 +193,19 @@
   initParams.initMode = ESE_MODE_NORMAL;
   initParams.mediaType = ESE_PROTOCOL_MEDIA_SPI_APDU_GATE;
   initParams.fPtr_WtxNtf = SecureElement::NotifySeWaitExtension;
-  if (clientCallback == nullptr) {
-    return Void();
-  } else {
-    clientCallback->linkToDeath(this, 0 /*cookie*/);
-  }
+
+  if (clientCallback == nullptr) return Void();
+
   LOG(INFO) << "SecureElement::init called here";
 #ifdef NXP_BOOTTIME_UPDATE
   if (ese_update != ESE_UPDATE_COMPLETED) {
-    mCallbackV1_1 = clientCallback;
     clientCallback->onStateChange_1_1(false, "NXP SE update going on");
     LOG(INFO) << "ESE JCOP Download in progress";
     NxpEse::setSeCallBack_1_1(clientCallback);
     return Void();
-    // Register
   }
 #endif
+  registerCallback(clientCallback);
   if (mIsEseInitialized) {
     clientCallback->onStateChange_1_1(true, "NXP SE HAL init ok");
     return Void();
@@ -168,30 +214,43 @@
   phNxpEse_setWtxCountLimit(OsuHalExtn::getInstance().getOSUMaxWtxCount());
   status = phNxpEse_open(initParams);
   if (status == ESESTATUS_SUCCESS || ESESTATUS_BUSY == status) {
+    ESESTATUS initStatus = ESESTATUS_SUCCESS;
     ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
-    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0) &&
-        ESESTATUS_SUCCESS == phNxpEse_init(initParams)) {
-      /*update OS mode during first init*/
-      IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0)) {
+      initStatus = phNxpEse_init(initParams);
+      if (initStatus == ESESTATUS_SUCCESS) {
+        /*update OS mode during first init*/
+        IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
 
-      if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
-        LOG(INFO) << "ESE SPI init complete!!!";
-        mIsInitDone = true;
+        if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
+          LOG(INFO) << "ESE SPI init complete!!!";
+          mIsInitDone = true;
+        }
+        deInitStatus = phNxpEse_deInit();
+        if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
       }
-      deInitStatus = phNxpEse_deInit();
-      if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
     }
     status = phNxpEse_close(deInitStatus);
+    /*Enable terminal post recovery(i.e. close success) from transmit failure */
+    if (status == ESESTATUS_SUCCESS &&
+        (initStatus == ESESTATUS_TRANSCEIVE_FAILED ||
+         initStatus == ESESTATUS_FAILED)) {
+      IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+      mIsInitDone = true;
+    }
   }
   phNxpEse_setWtxCountLimit(RESET_APP_WTX_COUNT);
   if (status == ESESTATUS_SUCCESS && mIsInitDone) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mHasPriorityAccess = phNxpEse_isPriorityAccessEnabled();
+    mMaxChannelCount = getMaxChannelCnt();
     mOpenedChannels.resize(mMaxChannelCount, false);
     clientCallback->onStateChange_1_1(true, "NXP SE HAL init ok");
-    mCallbackV1_1 = clientCallback;
   } else {
     LOG(ERROR) << "eSE-Hal Init failed";
     clientCallback->onStateChange_1_1(false, "NXP SE HAL init failed");
+    // remove it from the list of registered callbacks
+    // Client anyway has to call the init again
+    unregisterCallback(clientCallback);
   }
   return Void();
 }
@@ -340,6 +399,23 @@
   resApduBuff.channelNumber = 0xff;
   memset(&resApduBuff, 0x00, sizeof(resApduBuff));
 
+  /*
+   * Basic channel & reserved channel if any is removed
+   * from count
+   */
+  uint8_t maxLogicalChannelSupported =
+      mMaxChannelCount - getReserveChannelCnt(aid) - 1;
+
+  uint8_t openedLogicalChannelCount = mOpenedchannelCount;
+  if (mOpenedChannels[0]) openedLogicalChannelCount--;
+
+  if (openedLogicalChannelCount >= maxLogicalChannelSupported) {
+    LOG(ERROR) << StringPrintf("%s: Reached Max supported(%d) Logical Channel",
+                               __func__, openedLogicalChannelCount);
+    _hidl_cb(resApduBuff, SecureElementStatus::CHANNEL_NOT_AVAILABLE);
+    return Void();
+  }
+
   LOG(INFO) << "Acquired the lock from SPI openLogicalChannel";
 
   // In dedicated mode openLogical not allowed
@@ -358,7 +434,7 @@
   }
 
   if (mOpenedChannels.size() == 0x00) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mMaxChannelCount = getMaxChannelCnt();
     mOpenedChannels.resize(mMaxChannelCount, false);
   }
 
@@ -565,10 +641,6 @@
       _hidl_cb(result, SecureElementStatus::SUCCESS);
     }
     return Void();
-  } else if (mode == OsuHalExtn::OSU_BLOCKED_MODE) {
-    _hidl_cb(result, SecureElementStatus::IOERROR);
-    return Void();
-  } else {
   }
 
   if (!mIsEseInitialized) {
@@ -580,8 +652,26 @@
     }
   }
 
+  phNxpEse_data atrData;
+  if (phNxpEse_getAtr(&atrData) != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_getAtr failed";
+  }
+  if (atrData.p_data != NULL) {
+    phNxpEse_free(atrData.p_data);
+  }
+
+  if (phNxpEse_GetOsMode() == OSU_MODE) {
+    if (mOpenedchannelCount == 0) {
+      if (seHalDeInit() != SecureElementStatus::SUCCESS) {
+        LOG(INFO) << "seDeInit Failed";
+      }
+    }
+    _hidl_cb(result, SecureElementStatus::IOERROR);
+    return Void();
+  }
+
   if (mOpenedChannels.size() == 0x00) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mMaxChannelCount = getMaxChannelCnt();
     mOpenedChannels.resize(mMaxChannelCount, false);
   }
   phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
@@ -744,11 +834,18 @@
   }
 }
 
-void SecureElement::serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) {
-  LOG(ERROR) << " SecureElement serviceDied!!!";
-  mIsEseInitialized = false;
-  if (seHalDeInit() != SecureElementStatus::SUCCESS) {
-    LOG(ERROR) << "SE Deinit not successful";
+void SecureElement::serviceDied(uint64_t /*cookie*/, const wp<IBase>& who) {
+  LOG(ERROR) << "Remote client Died!!!";
+  unregisterCallback(who.promote());
+  if (mCallbacks.empty()) {
+    LOG(ERROR) << "No alive registered client, resetting the state";
+    mIsEseInitialized = false;
+    if (seHalDeInit() != SecureElementStatus::SUCCESS) {
+      LOG(ERROR) << "SE Deinit not successful";
+    }
+  } else {
+    LOG(INFO) << "There are " << mCallbacks.size()
+              << " alive registered clients left";
   }
 }
 ESESTATUS SecureElement::seHalInit() {
@@ -803,7 +900,6 @@
   status = phNxpEse_close(deInitStatus);
   if (status == ESESTATUS_SUCCESS && mIsDeInitDone) {
     sestatus = SecureElementStatus::SUCCESS;
-    ;
   } else {
     LOG(ERROR) << "seHalDeInit: Failed";
   }
@@ -815,37 +911,50 @@
 
   return sestatus;
 }
+void SecureElement::notifyClients(bool connected, std::string reason) {
+  LOG(INFO) << "Notifying current state to all " << mCallbacks.size()
+            << " clients";
+
+  for (auto it = mCallbacks.begin(); it != mCallbacks.end();) {
+    auto ret = (*it)->onStateChange_1_1(connected, reason);
+    if (!ret.isOk() && ret.isDeadObject()) {
+      LOG(WARNING) << "client  is dead";
+      it = mCallbacks.erase(it);
+    } else {
+      ++it;
+    }
+  }
+}
 Return<::android::hardware::secure_element::V1_0::SecureElementStatus>
 SecureElement::reset() {
   ESESTATUS status = ESESTATUS_SUCCESS;
   SecureElementStatus sestatus = SecureElementStatus::FAILED;
-  LOG(ERROR) << "%s: Enter" << __func__;
+  LOG(INFO) << __func__ << " Enter";
   if (!mIsEseInitialized) {
     ESESTATUS status = seHalInit();
     if (status != ESESTATUS_SUCCESS) {
-      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+      LOG(ERROR) << __func__ << " seHalInit Failed!!!";
     }
   }
   if (status == ESESTATUS_SUCCESS) {
-    mCallbackV1_1->onStateChange_1_1(false, "reset the SE");
+    notifyClients(false, "reset the SE");
     status = phNxpEse_reset();
     if (status != ESESTATUS_SUCCESS) {
-      LOG(ERROR) << "%s: SecureElement reset failed!!" << __func__;
+      LOG(ERROR) << __func__ << " SecureElement reset failed!!";
     } else {
       sestatus = SecureElementStatus::SUCCESS;
       if (mOpenedChannels.size() == 0x00) {
-        mMaxChannelCount =
-            (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+        mMaxChannelCount = getMaxChannelCnt();
         mOpenedChannels.resize(mMaxChannelCount, false);
       }
       for (uint8_t xx = 0; xx < mMaxChannelCount; xx++) {
         mOpenedChannels[xx] = false;
       }
       mOpenedchannelCount = 0;
-      mCallbackV1_1->onStateChange_1_1(true, "SE initialized");
+      notifyClients(true, "SE initialized");
     }
   }
-  LOG(ERROR) << "%s: Exit" << __func__;
+  LOG(ERROR) << __func__ << ": Exit";
   return sestatus;
 }
 
@@ -910,6 +1019,45 @@
   return sestatus;
 }
 
+uint8_t SecureElement::getReserveChannelCnt(const hidl_vec<uint8_t>& aid) {
+  const hidl_vec<uint8_t> weaverAid = {0xA0, 0x00, 0x00, 0x03,
+                                       0x96, 0x10, 0x10};
+  const hidl_vec<uint8_t> araAid = {0xA0, 0x00, 0x00, 0x01, 0x51,
+                                    0x41, 0x43, 0x4C, 0x00};
+  uint8_t reserveChannel = 0;
+  // Check priority access enabled then only reserve channel
+  if (mHasPriorityAccess && aid != weaverAid && aid != araAid) {
+    // Exclude basic channel
+    reserveChannel = 1;
+  }
+  return reserveChannel;
+}
+
+uint8_t SecureElement::getMaxChannelCnt() {
+  /*
+   * 1) SN1xx max channel supported 4.
+   * 2) SN220 up to v2 max channel supported 5 (If priority access)
+   *    otherwise 4 channel.
+   * 3) SN220 v3 and higher shall be updated accordingly.
+   */
+  uint8_t cnt = 0;
+  if (GET_CHIP_OS_VERSION() < OS_VERSION_6_2)
+    cnt = NUM_OF_CH4;
+  else if (GET_CHIP_OS_VERSION() == OS_VERSION_6_2)
+    cnt = (mHasPriorityAccess ? NUM_OF_CH5 : NUM_OF_CH4);
+  else
+    cnt = NUM_OF_CH5;
+
+  return cnt;
+}
+
+Return<void> SecureElement::debug(const hidl_handle& /* fd */,
+                                  const hidl_vec<hidl_string>& /* options */) {
+  LOG(INFO) << "\n SecureElement-SecureElement HAL MemoryLeak Info = \n"
+            << ::android::GetUnreachableMemoryString(true, 10000).c_str();
+  return Void();
+}
+
 }  // namespace implementation
 }  // namespace V1_2
 }  // namespace secure_element
diff --git a/snxxx/1.2/SecureElement.h b/snxxx/1.2/SecureElement.h
index 8853444..0f503c0 100755
--- a/snxxx/1.2/SecureElement.h
+++ b/snxxx/1.2/SecureElement.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2020  NXP
+ *  Copyright 2020,2022  NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -26,6 +26,9 @@
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
 #include <pthread.h>
+
+#include <vector>
+
 #include "OsuHalExtn.h"
 #include "phNxpEse_Api.h"
 
@@ -81,6 +84,10 @@
 struct SecureElement : public V1_2::ISecureElement,
                        public hidl_death_recipient {
   SecureElement();
+  // Methods from ::android::hidl::base::V1_0::IBase follow.
+  Return<void> debug(const hidl_handle& handle,
+                     const hidl_vec<hidl_string>& options) override;
+
   Return<void> init(
       const sp<
           ::android::hardware::secure_element::V1_0::ISecureElementHalCallback>&
@@ -112,10 +119,20 @@
   bool mIsEseInitialized = false;
   static std::vector<bool> mOpenedChannels;
   static sp<V1_0::ISecureElementHalCallback> mCallbackV1_0;
-  static sp<V1_1::ISecureElementHalCallback> mCallbackV1_1;
+
+  std::vector<sp<V1_1::ISecureElementHalCallback>> mCallbacks;
+  bool mHasPriorityAccess = false;
+
+  void notifyClients(bool connected, std::string reason);
+
+  void registerCallback(const sp<V1_1::ISecureElementHalCallback>& callback);
+  void unregisterCallback(const sp<IBase>& callback);
+
   Return<SecureElementStatus> seHalDeInit();
   ESESTATUS seHalInit();
   Return<SecureElementStatus> internalCloseChannel(uint8_t channelNumber);
+  uint8_t getReserveChannelCnt(const hidl_vec<uint8_t>& aid);
+  uint8_t getMaxChannelCnt();
 };
 
 }  // namespace implementation
diff --git a/snxxx/1.2/VirtualISO.cpp b/snxxx/1.2/VirtualISO.cpp
index 44ece57..857a254 100755
--- a/snxxx/1.2/VirtualISO.cpp
+++ b/snxxx/1.2/VirtualISO.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -23,6 +23,9 @@
 #include "eSEClient.h"
 #endif
 #include <android-base/logging.h>
+// Undefined LOG_TAG as it is also defined in log.h
+#undef LOG_TAG
+#include <memunreachable/memunreachable.h>
 
 #include "hal_nxpese.h"
 #include "phNxpEse_Apdu_Api.h"
@@ -105,7 +108,7 @@
     status = phNxpEse_close(deInitStatus);
   }
   if (status == ESESTATUS_SUCCESS && mIsInitDone) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mMaxChannelCount = (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
     mOpenedChannels.resize(mMaxChannelCount, false);
     clientCallback->onStateChange(true);
   } else {
@@ -162,7 +165,7 @@
     status = phNxpEse_close(deInitStatus);
   }
   if (status == ESESTATUS_SUCCESS && mIsInitDone) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mMaxChannelCount = (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
     mOpenedChannels.resize(mMaxChannelCount, false);
     clientCallback->onStateChange_1_1(true, "NXP VISIO HAL init ok");
   } else {
@@ -234,6 +237,18 @@
 
   LogicalChannelResponse resApduBuff;
 
+  if (GET_CHIP_OS_VERSION() <= OS_VERSION_6_2) {
+    uint8_t maxLogicalChannelSupported = mMaxChannelCount - 1;
+    uint8_t openedLogicalChannelCount = mOpenedchannelCount;
+    if (mOpenedChannels[0]) openedLogicalChannelCount--;
+
+    if (openedLogicalChannelCount >= maxLogicalChannelSupported) {
+      LOG(ERROR) << "%s: Reached Max supported Logical Channel" << __func__;
+      _hidl_cb(resApduBuff, SecureElementStatus::CHANNEL_NOT_AVAILABLE);
+      return Void();
+    }
+  }
+
   LOG(INFO) << "Acquired the lock in VISO openLogicalChannel";
 
   resApduBuff.channelNumber = 0xff;
@@ -248,7 +263,7 @@
   }
 
   if (mOpenedChannels.size() == 0x00) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mMaxChannelCount = (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
     mOpenedChannels.resize(mMaxChannelCount, false);
   }
 
@@ -309,7 +324,7 @@
         LOG(INFO) << "seDeInit Failed";
       }
     }
-    /*If manageChanle is failed in any of above cases
+    /*If manageChannel is failed in any of above cases
     send the callback and return*/
     status = phNxpEse_ResetEndPoint_Cntxt(1);
     if (status != ESESTATUS_SUCCESS) {
@@ -329,12 +344,12 @@
 
   if ((resApduBuff.channelNumber > 0x03) &&
       (resApduBuff.channelNumber < 0x14)) {
-    /* update CLA byte accoridng to GP spec Table 11-12*/
+    /* update CLA byte according to GP spec Table 11-12*/
     cpdu.cla =
         0x40 + (resApduBuff.channelNumber - 4); /* Class of instruction */
   } else if ((resApduBuff.channelNumber > 0x00) &&
              (resApduBuff.channelNumber < 0x04)) {
-    /* update CLA byte accoridng to GP spec Table 11-11*/
+    /* update CLA byte according to GP spec Table 11-11*/
     cpdu.cla = resApduBuff.channelNumber; /* Class of instruction */
   } else {
     LOG(ERROR) << StringPrintf("%s: Invalid Channel no: %02x", __func__,
@@ -427,7 +442,7 @@
   }
 
   if (mOpenedChannels.size() == 0x00) {
-    mMaxChannelCount = (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+    mMaxChannelCount = (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
     mOpenedChannels.resize(mMaxChannelCount, false);
   }
 
@@ -524,9 +539,9 @@
     phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
     phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
     cpdu.cla = channelNumber; /* Class of instruction */
-    // For Suplementary Channel update CLA byte according to GP
+    // For Supplementary Channel update CLA byte according to GP
     if ((channelNumber > 0x03) && (channelNumber < 0x14)) {
-      /* update CLA byte accoridng to GP spec Table 11-12*/
+      /* update CLA byte according to GP spec Table 11-12*/
       cpdu.cla = 0x40 + (channelNumber - 4); /* Class of instruction */
     }
     cpdu.ins = 0x70;          /* Instruction code */
@@ -658,7 +673,6 @@
   status = phNxpEse_close(deInitStatus);
   if (status == ESESTATUS_SUCCESS && mIsDeInitDone) {
     sestatus = SecureElementStatus::SUCCESS;
-    ;
   } else {
     LOG(ERROR) << "seHalDeInit: Failed";
   }
@@ -690,7 +704,7 @@
       sestatus = SecureElementStatus::SUCCESS;
       if (mOpenedChannels.size() == 0x00) {
         mMaxChannelCount =
-            (GET_CHIP_OS_VERSION() >= OS_VERSION_6_2) ? 0x0C : 0x04;
+            (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
         mOpenedChannels.resize(mMaxChannelCount, false);
       }
       for (uint8_t xx = 0; xx < mMaxChannelCount; xx++) {
@@ -704,6 +718,13 @@
   return sestatus;
 }
 
+Return<void> VirtualISO::debug(const hidl_handle& /* fd */,
+                               const hidl_vec<hidl_string>& /* options */) {
+  LOG(INFO) << "\n SecureElement-VirtualISO HAL MemoryLeak Info = \n"
+            << ::android::GetUnreachableMemoryString(true, 10000).c_str();
+  return Void();
+}
+
 }  // namespace implementation
 }  // namespace V1_0
 }  // namespace virtual_iso
diff --git a/snxxx/1.2/VirtualISO.h b/snxxx/1.2/VirtualISO.h
index af8b641..53419e1 100755
--- a/snxxx/1.2/VirtualISO.h
+++ b/snxxx/1.2/VirtualISO.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
 using android::base::StringPrintf;
 using ::android::hardware::hidl_array;
 using ::android::hardware::hidl_death_recipient;
+using ::android::hardware::hidl_handle;
 using ::android::hardware::hidl_memory;
 using ::android::hardware::hidl_string;
 using ::android::hardware::hidl_vec;
@@ -47,13 +48,16 @@
 using ::android::hardware::secure_element::V1_0::SecureElementStatus;
 using ::android::hardware::secure_element::V1_2::ISecureElement;
 using ::android::hidl::base::V1_0::IBase;
-
 #ifndef DEFAULT_BASIC_CHANNEL
 #define DEFAULT_BASIC_CHANNEL 0x00
 #endif
 
 struct VirtualISO : public ISecureElement, public hidl_death_recipient {
   VirtualISO();
+  // Methods from ::android::hidl::base::V1_0::IBase follow.
+  Return<void> debug(const hidl_handle& handle,
+                     const hidl_vec<hidl_string>& options) override;
+
   Return<void> init(
       const sp<
           ::android::hardware::secure_element::V1_0::ISecureElementHalCallback>&
diff --git a/snxxx/Android.bp b/snxxx/Android.bp
index 1713d67..17877d0 100755
--- a/snxxx/Android.bp
+++ b/snxxx/Android.bp
@@ -1,3 +1,17 @@
+//
+// Copyright 2023 NXP
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
 
 package {
     // See: http://go/android-license-faq
@@ -8,69 +22,16 @@
     default_applicable_licenses: ["hardware_nxp_secure_element_license"],
 }
 
-cc_binary {
-    relative_install_path: "hw",
-    name: "android.hardware.secure_element_snxxx@1.2-service",
-    init_rc: ["1.2/android.hardware.secure_element_snxxx@1.2-service.rc"],
-    proprietary: true,
-    defaults: ["hidl_defaults"],
-    srcs: [
-        "1.2/NxpEseService.cpp",
-        "1.2/SecureElement.cpp",
-        "1.2/VirtualISO.cpp",
-        "extns/impl/NxpEse.cpp",
-        "1.2/OsuHal/src/OsuHalExtn.cpp",
+subdirs = [
+    "aidl","1.2",
+]
+filegroup {
+    name: "OsuHalCommonFile",
+    srcs: ["OsuHal/src/OsuHalExtn.cpp"],
+}
+filegroup {
+    name: "ExtnsFile",
+     srcs: [
+         "extns/impl/NxpEse.cpp",
     ],
-
-    shared_libs: [
-        "android.hardware.secure_element@1.0",
-        "android.hardware.secure_element@1.1",
-        "android.hardware.secure_element@1.2",
-        "ese_spi_nxp_snxxx",
-        "libbase",
-        "libcutils",
-        "libdl",
-        "libhardware",
-        "libhidlbase",
-        "liblog",
-        "libutils",
-        "libchrome",
-        "vendor.nxp.nxpese@1.0",
-        "vendor.nxp.nxpnfc@2.0",
-        "android.hardware.nfc@1.0",
-        "android.hardware.nfc@1.1",
-        "android.hardware.nfc@1.2",
-    ],
-
-    local_include_dirs: [
-        "libese-spi/common/include",
-        "libese-spi/p73/common",
-        "libese-spi/p73/inc",
-        "libese-spi/p73/lib",
-        "libese-spi/p73/pal",
-        "libese-spi/p73/pal/spi",
-        "libese-spi/p73/utils",
-        "libese-spi/p73/spm",
-        "libese-spi/src/include",
-        "1.2/OsuHal/inc",
-    ],
-
-    include_dirs: [
-        "hardware/nxp/secure_element/snxxx/extns/impl",
-    ],
-    cflags: [
-        "-DANDROID",
-        "-DJCOP_VER_3_1=1",
-        "-DJCOP_VER_3_2=2",
-        "-DJCOP_VER_3_3=3",
-        "-DJCOP_VER_4_0=4",
-        "-DJCOP_VER_5_x=5",
-        "-DBUILDCFG=1",
-        "-DNXP_EXTNS=TRUE",
-        "-DNFC_NXP_ESE_VER=JCOP_VER_5_x",
-        "-Wall",
-        "-Werror",
-        "-fexceptions",
-    ],
-
 }
diff --git a/snxxx/1.2/OsuHal/inc/OsuHalExtn.h b/snxxx/OsuHal/inc/OsuHalExtn.h
similarity index 87%
rename from snxxx/1.2/OsuHal/inc/OsuHalExtn.h
rename to snxxx/OsuHal/inc/OsuHalExtn.h
index 3fb8a72..04e6877 100644
--- a/snxxx/1.2/OsuHal/inc/OsuHalExtn.h
+++ b/snxxx/OsuHal/inc/OsuHalExtn.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2020-2021 NXP
+ *  Copyright 2020-2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -19,13 +19,10 @@
 #pragma once
 #include <android-base/logging.h>
 #include <android-base/stringprintf.h>
-#include <hardware/hardware.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
 #include <string.h>
+
 #include "phNxpEse_Api.h"
 
-using ::android::hardware::hidl_vec;
 #define OSU_PROP_CLA 0x80
 #define OSU_PROP_INS 0xDF
 #define OSU_PROP_RST_P1 0xEF
@@ -63,7 +60,7 @@
 
   static OsuHalExtn& getInstance();
 
-  OsuApduMode isOsuMode(const hidl_vec<uint8_t>& evt, uint8_t type,
+  OsuApduMode isOsuMode(const std::vector<uint8_t>& evt, uint8_t type,
                         phNxpEse_data* pCmdData = nullptr);
   bool isOsuMode(uint8_t type, uint8_t channel = 0xFF);
   virtual ~OsuHalExtn();
@@ -74,8 +71,8 @@
  private:
   bool isAppOSUMode;
   bool isJcopOSUMode;
-  static const hidl_vec<uint8_t> osu_aid[10];
+  static const std::vector<uint8_t> osu_aid[10];
   OsuApduMode checkTransmit(uint8_t* input, uint32_t* outLength,
-                            const hidl_vec<uint8_t>& data);
+                            const std::vector<uint8_t>& data);
   bool isOsuMode();
 };
diff --git a/snxxx/1.2/OsuHal/src/OsuHalExtn.cpp b/snxxx/OsuHal/src/OsuHalExtn.cpp
similarity index 95%
rename from snxxx/1.2/OsuHal/src/OsuHalExtn.cpp
rename to snxxx/OsuHal/src/OsuHalExtn.cpp
index 0411c16..a530cfb 100644
--- a/snxxx/1.2/OsuHal/src/OsuHalExtn.cpp
+++ b/snxxx/OsuHal/src/OsuHalExtn.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2020-2021 NXP
+ *  Copyright 2020-2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
  *
  ******************************************************************************/
 #include "OsuHalExtn.h"
+
 #include <ese_config.h>
 
 #define LOG_TAG "OsuHalExtn"
@@ -23,8 +24,8 @@
 
 #define DEFAULT_MAX_WTX_COUNT 60
 
-const static hidl_vec<uint8_t> OSU_AID = {0x4F, 0x70, 0x80, 0x13, 0x04,
-                                          0xDE, 0xAD, 0xBE, 0xEF};
+const static std::vector<uint8_t> OSU_AID = {0x4F, 0x70, 0x80, 0x13, 0x04,
+                                             0xDE, 0xAD, 0xBE, 0xEF};
 const static uint8_t defaultSelectAid[] = {0x00, 0xA4, 0x04, 0x00, 0x00};
 
 /*******************************************************************************
@@ -38,7 +39,7 @@
 **              OSU_BLOCKED_MODE, OSU_GP_MODE)
 **
 *******************************************************************************/
-OsuHalExtn::OsuApduMode OsuHalExtn::isOsuMode(const hidl_vec<uint8_t>& evt,
+OsuHalExtn::OsuApduMode OsuHalExtn::isOsuMode(const std::vector<uint8_t>& evt,
                                               uint8_t type,
                                               phNxpEse_data* pCmdData) {
   OsuApduMode osuSubState = (isAppOSUMode ? OSU_PROP_MODE : NON_OSU_MODE);
@@ -49,7 +50,7 @@
        * update & return OSU_PROP_MODE if OpenBasicChannel AID request matches
        * OSU_AID
        */
-      if (!memcmp(&evt[0], &OSU_AID[0], OSU_AID.size())) {
+      if (evt.size() && !memcmp(&evt[0], &OSU_AID[0], OSU_AID.size())) {
         isAppOSUMode = true;
         osuSubState = OSU_PROP_MODE;
         ALOGD("Dedicated mode is set !!!!!!!!!!!!!!!!!");
@@ -197,7 +198,7 @@
 **
 *******************************************************************************/
 OsuHalExtn::OsuApduMode OsuHalExtn::checkTransmit(
-    uint8_t* input, uint32_t* outLength, const hidl_vec<uint8_t>& data) {
+    uint8_t* input, uint32_t* outLength, const std::vector<uint8_t>& data) {
   OsuHalExtn::OsuApduMode halMode = NON_OSU_MODE;
   size_t length = data.size();
 
diff --git a/snxxx/aidl/Android.bp b/snxxx/aidl/Android.bp
new file mode 100644
index 0000000..61eca51
--- /dev/null
+++ b/snxxx/aidl/Android.bp
@@ -0,0 +1,87 @@
+//
+// Copyright 2023 NXP
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "hardware_nxp_secure_element_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["hardware_nxp_secure_element_license"],
+}
+
+cc_binary {
+    name: "android.hardware.secure_element-service.nxp",
+    relative_install_path: "hw",
+    vendor: true,
+    init_rc: ["secure_element-service-nxp.rc"],
+    vintf_fragments: ["secure_element-service-nxp.xml"],
+    enabled: true,
+
+    srcs: [
+        "NxpEseService.cpp",
+        "SecureElement.cpp",
+        "VirtualISO.cpp",
+        ":OsuHalCommonFile",
+    ],
+
+    shared_libs: [
+        "libbase",
+        "libbinder_ndk",
+        "android.hardware.secure_element-V1-ndk",
+        "libhardware",
+        "liblog",
+        "libmemunreachable",
+        "libutils",
+        "ese_spi_nxp_snxxx",
+        "nfc_nci_nxp_snxxx",
+        "android.hardware.nfc@1.2",
+        "android.hardware.nfc-V1-ndk",
+        "vendor.nxp.nxpnfc_aidl-V1-ndk",
+    ],
+
+    include_dirs: [
+        "hardware/nxp/secure_element/snxxx/extns/impl",
+        "hardware/nxp/secure_element/snxxx/libese-spi/common/include",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/common",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/inc",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/lib",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/pal",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/pal/spi",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/utils",
+        "hardware/nxp/secure_element/snxxx/libese-spi/p73/spm",
+        "hardware/nxp/secure_element/snxxx/libese-spi/src/include",
+        "hardware/nxp/secure_element/snxxx/OsuHal/inc",
+        "hardware/nxp/secure_element/snxxx/ese-clients/inc",
+        "hardware/nxp/nfc/snxxx/halimpl/common",
+        "hardware/nxp/nfc/snxxx/halimpl/utils",
+    ],
+
+    cflags: [
+        "-DANDROID",
+        "-DJCOP_VER_3_1=1",
+        "-DJCOP_VER_3_2=2",
+        "-DJCOP_VER_3_3=3",
+        "-DJCOP_VER_4_0=4",
+        "-DJCOP_VER_5_x=5",
+        "-DBUILDCFG=1",
+        "-DNXP_EXTNS=TRUE",
+        "-DNFC_NXP_ESE_VER=JCOP_VER_5_x",
+        "-DNXP_VISO_ENABLE",
+        "-Wall",
+        "-Werror",
+        "-fexceptions",
+    ],
+}
diff --git a/snxxx/aidl/NxpEseService.cpp b/snxxx/aidl/NxpEseService.cpp
new file mode 100644
index 0000000..d8e868b
--- /dev/null
+++ b/snxxx/aidl/NxpEseService.cpp
@@ -0,0 +1,140 @@
+/******************************************************************************
+ *
+ *  Copyright 2023 NXP
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+#include <aidl/android/hardware/nfc/INfc.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <android/hardware/nfc/1.2/INfc.h>
+
+#include "SecureElement.h"
+#include "VirtualISO.h"
+#include "phNxpConfig.h"
+
+#define MAX_NFC_GET_RETRY 30
+#define NFC_GET_SERVICE_DELAY_MS 100
+#define TERMINAL_LEN 5
+#define NAME_NXP_SPI_SE_TERMINAL_NUM "NXP_SPI_SE_TERMINAL_NUM"
+#define NAME_NXP_VISO_SE_TERMINAL_NUM "NXP_VISO_SE_TERMINAL_NUM"
+
+using INfc = android::hardware::nfc::V1_2::INfc;
+using INfcAidl = ::aidl::android::hardware::nfc::INfc;
+using ::aidl::android::hardware::secure_element::SecureElement;
+using VirtualISO = aidl::vendor::nxp::virtual_iso::VirtualISO;
+
+using android::OK;
+using android::sp;
+using android::status_t;
+
+std::string NFC_AIDL_HAL_SERVICE_NAME = "android.hardware.nfc.INfc/default";
+
+static inline void waitForNFCHAL() {
+  int retry = 0;
+  android::sp<INfc> nfc_service = nullptr;
+  std::shared_ptr<INfcAidl> nfc_aidl_service = nullptr;
+
+  ALOGI("Waiting for NFC HAL .. ");
+  do {
+    ::ndk::SpAIBinder binder(
+        AServiceManager_checkService(NFC_AIDL_HAL_SERVICE_NAME.c_str()));
+    nfc_aidl_service = INfcAidl::fromBinder(binder);
+    if (nfc_aidl_service != nullptr) {
+      ALOGI("NFC HAL service is registered");
+      break;
+    }
+    /* Wait for 100 MS for HAL RETRY*/
+    usleep(NFC_GET_SERVICE_DELAY_MS * 1000);
+  } while (retry++ < MAX_NFC_GET_RETRY);
+
+  if (nfc_aidl_service == nullptr) {
+    ALOGE("Failed to get NFC AIDLHAL Service, trying to get HIDL service");
+    nfc_service = INfc::tryGetService();
+    if (nfc_service != nullptr) {
+      ALOGI("NFC HAL service is registered");
+    } else {
+      ALOGE("Failed to get NFC HAL Service");
+    }
+  }
+}
+
+int main() {
+  char terminalID[5] = "eSE1";
+  const char* SEterminal = "eSEx";
+  bool ret = false;
+
+  ALOGI("Secure Element AIDL HAL Service starting up");
+  if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) {
+    ALOGE("failed to set thread pool max thread count");
+    return EXIT_FAILURE;
+  }
+
+  waitForNFCHAL();
+  ALOGI("Secure Element AIDL HAL Service starting up");
+  std::shared_ptr<SecureElement> se_service =
+      ndk::SharedRefBase::make<SecureElement>();
+  std::shared_ptr<VirtualISO> virtual_iso_service = nullptr;
+
+  if (GetNxpStrValue(NAME_NXP_SPI_SE_TERMINAL_NUM, terminalID, TERMINAL_LEN)) {
+    LOG(ERROR) << "eSETerminalId found";
+    ALOGE("eSETerminalId found val = %s ", terminalID);
+
+    ret = true;
+  }
+  ALOGI("Terminal val = %s", terminalID);
+  if ((ret) && (strncmp(SEterminal, terminalID, 3) == 0)) {
+    ALOGI("Terminal ID found");
+    const std::string seInstName =
+        std::string() + SecureElement::descriptor + "/" + terminalID;
+    binder_status_t status = AServiceManager_addService(
+        se_service->asBinder().get(), seInstName.c_str());
+    if (status != OK) {
+      ALOGE("Could not register service for Secure Element HAL Iface (%d).",
+            status);
+      goto shutdown;
+    }
+    ALOGI("Secure Element Service is ready");
+  }
+#ifdef NXP_VISO_ENABLE
+  ALOGI("Virtual ISO HAL Service 1.0 is starting.");
+  virtual_iso_service = ndk::SharedRefBase::make<VirtualISO>();
+
+  ret = false;
+  if (GetNxpStrValue(NAME_NXP_VISO_SE_TERMINAL_NUM, terminalID, TERMINAL_LEN)) {
+    ALOGE("eUICCTerminalId found val = %s ", terminalID);
+    ret = true;
+  }
+  if ((ret) && (strncmp(SEterminal, terminalID, 3) == 0)) {
+    const std::string vISO_InstName =
+        std::string() + SecureElement::descriptor + "/" + terminalID;
+    binder_status_t status = AServiceManager_addService(
+        virtual_iso_service->asBinder().get(), vISO_InstName.c_str());
+
+    if (status != OK) {
+      ALOGE("Could not register service for Virtual ISO HAL Iface (%d).",
+            status);
+      goto shutdown;
+    }
+  }
+
+  ALOGI("Virtual ISO: Secure Element Service is ready");
+#endif
+  ABinderProcess_joinThreadPool();
+// Should not pass this line
+shutdown:
+  // In normal operation, we don't expect the thread pool to exit
+  ALOGE("Secure Element Service is shutting down");
+  return EXIT_FAILURE;
+}
\ No newline at end of file
diff --git a/snxxx/aidl/SecureElement.cpp b/snxxx/aidl/SecureElement.cpp
new file mode 100644
index 0000000..3790d04
--- /dev/null
+++ b/snxxx/aidl/SecureElement.cpp
@@ -0,0 +1,955 @@
+/******************************************************************************
+ *
+ *  Copyright 2023 NXP
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+#include "SecureElement.h"
+
+#include <log/log.h>
+
+#include "phNfcStatus.h"
+#include "phNxpEse_Apdu_Api.h"
+#include "phNxpEse_Api.h"
+/* Mutex to synchronize multiple transceive */
+#include <memunreachable/memunreachable.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace secure_element {
+
+#define DEFAULT_BASIC_CHANNEL 0x00
+#define INVALID_LEN_SW1 0x64
+#define INVALID_LEN_SW2 0xFF
+#define SW1_BYTES_REMAINING 0x61
+#define NUM_OF_CH4 0x04
+#define NUM_OF_CH5 0x05
+
+typedef struct gsTransceiveBuffer {
+  phNxpEse_data cmdData;
+  phNxpEse_data rspData;
+  std::vector<uint8_t>* pRspDataBuff;
+} sTransceiveBuffer_t;
+
+static int getResponseInternal(uint8_t cla, phNxpEse_7816_rpdu_t& rpdu,
+                               std::vector<uint8_t>& result);
+static sTransceiveBuffer_t gsTxRxBuffer;
+static std::vector<uint8_t> gsRspDataBuff(256);
+std::shared_ptr<ISecureElementCallback> SecureElement::mCb = nullptr;
+AIBinder_DeathRecipient* clientDeathRecipient = nullptr;
+std::vector<bool> SecureElement::mOpenedChannels;
+
+SecureElement::SecureElement()
+    : mMaxChannelCount(0), mOpenedchannelCount(0), mIsEseInitialized(false) {}
+
+void SecureElement::updateSeHalInitState(bool mstate) {
+  mIsEseInitialized = mstate;
+}
+void OnDeath(void* cookie) {
+  (void)cookie;
+  LOG(ERROR) << " SecureElement serviceDied!!!";
+  SecureElement* se = static_cast<SecureElement*>(cookie);
+  se->updateSeHalInitState(false);
+  if (se->seHalDeInit() != SESTATUS_SUCCESS) {
+    LOG(ERROR) << "SE Deinit not successful";
+  }
+}
+
+void SecureElement::NotifySeWaitExtension(phNxpEse_wtxState state) {
+  if (state == WTX_ONGOING) {
+    LOG(INFO) << "SecureElement::WTX ongoing";
+  } else if (state == WTX_END) {
+    LOG(INFO) << "SecureElement::WTX ended";
+  }
+}
+
+ScopedAStatus SecureElement::init(
+    const std::shared_ptr<ISecureElementCallback>& clientCallback) {
+  LOG(INFO) << __func__ << " callback: " << clientCallback.get();
+  if (!clientCallback) {
+    return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
+  }
+
+  mCb = clientCallback;
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  bool mIsInitDone = false;
+  phNxpEse_initParams initParams;
+  gsTxRxBuffer.pRspDataBuff = &gsRspDataBuff;
+  memset(&initParams, 0x00, sizeof(phNxpEse_initParams));
+  initParams.initMode = ESE_MODE_NORMAL;
+  initParams.mediaType = ESE_PROTOCOL_MEDIA_SPI_APDU_GATE;
+  initParams.fPtr_WtxNtf = SecureElement::NotifySeWaitExtension;
+
+  if (clientCallback == nullptr) {
+    return ScopedAStatus::ok();
+  } else {
+    clientDeathRecipient = AIBinder_DeathRecipient_new(OnDeath);
+    auto linkRet =
+        AIBinder_linkToDeath(clientCallback->asBinder().get(),
+                             clientDeathRecipient, this /* cookie */);
+    if (linkRet != STATUS_OK) {
+      LOG(ERROR) << __func__ << ": linkToDeath failed: " << linkRet;
+      // Just ignore the error.
+    }
+  }
+
+  LOG(INFO) << "SecureElement::init called here";
+  if (mIsEseInitialized) {
+    mCb->onStateChange(true, "NXP SE HAL init ok");
+    return ScopedAStatus::ok();
+  }
+
+  phNxpEse_setWtxCountLimit(OsuHalExtn::getInstance().getOSUMaxWtxCount());
+  status = phNxpEse_open(initParams);
+  if (status == ESESTATUS_SUCCESS || ESESTATUS_BUSY == status) {
+    ESESTATUS initStatus = ESESTATUS_SUCCESS;
+    ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0)) {
+      initStatus = phNxpEse_init(initParams);
+      if (initStatus == ESESTATUS_SUCCESS) {
+        /*update OS mode during first init*/
+        IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+
+        if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
+          LOG(INFO) << "ESE SPI init complete!!!";
+          mIsInitDone = true;
+        }
+        deInitStatus = phNxpEse_deInit();
+        if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
+      }
+    }
+    status = phNxpEse_close(deInitStatus);
+    /*Enable terminal post recovery(i.e. close success) from transmit failure */
+    if (status == ESESTATUS_SUCCESS &&
+        (initStatus == ESESTATUS_TRANSCEIVE_FAILED ||
+         initStatus == ESESTATUS_FAILED)) {
+      IS_OSU_MODE(OsuHalExtn::getInstance().INIT, 0);
+      mIsInitDone = true;
+    }
+  }
+  phNxpEse_setWtxCountLimit(RESET_APP_WTX_COUNT);
+  if (status == ESESTATUS_SUCCESS && mIsInitDone) {
+    mHasPriorityAccess = phNxpEse_isPriorityAccessEnabled();
+    mMaxChannelCount = getMaxChannelCnt();
+    mOpenedChannels.resize(mMaxChannelCount, false);
+    mCb->onStateChange(true, "NXP SE HAL init ok");
+  } else {
+    LOG(ERROR) << "eSE-Hal Init failed";
+    mCb->onStateChange(false, "NXP SE HAL init failed");
+  }
+  return ScopedAStatus::ok();
+}
+
+ScopedAStatus SecureElement::getAtr(std::vector<uint8_t>* _aidl_return) {
+  LOG(INFO) << __func__;
+
+  AutoMutex guard(seHalLock);
+  LOG(ERROR) << "Processing ATR.....";
+  phNxpEse_data atrData;
+  std::vector<uint8_t> response;
+  ESESTATUS status = ESESTATUS_FAILED;
+  bool mIsSeHalInitDone = false;
+
+  // In dedicated mode getATR not allowed
+  if (IS_OSU_MODE(OsuHalExtn::getInstance().GETATR)) {
+    LOG(ERROR) << "%s: Not allowed in dedicated mode!!!" << __func__;
+    *_aidl_return = response;
+    return ndk::ScopedAStatus::ok();
+  }
+
+  if (!mIsEseInitialized) {
+    ESESTATUS status = seHalInit();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+      *_aidl_return = response; /*Return with empty Vector*/
+      return ndk::ScopedAStatus::ok();
+    } else {
+      mIsSeHalInitDone = true;
+    }
+  }
+  status = phNxpEse_SetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "Endpoint set failed";
+  }
+  status = phNxpEse_getAtr(&atrData);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_getAtr failed";
+    *_aidl_return = response; /*Return with empty Vector*/
+    return ndk::ScopedAStatus::ok();
+  } else {
+    response.resize(atrData.len);
+    memcpy(&response[0], atrData.p_data, atrData.len);
+  }
+
+  status = phNxpEse_ResetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "Endpoint set failed";
+  }
+
+  if (status != ESESTATUS_SUCCESS) {
+    ALOGD("ATR Data[BytebyByte]=Look below for %d bytes", atrData.len);
+    for (auto i = response.begin(); i != response.end(); ++i)
+      ALOGI("0x%x\t", *i);
+  }
+
+  *_aidl_return = response;
+  if (atrData.p_data != NULL) {
+    phNxpEse_free(atrData.p_data);
+  }
+  if (mIsSeHalInitDone) {
+    if (SESTATUS_SUCCESS != seHalDeInit())
+      LOG(ERROR) << "phNxpEse_getAtr seHalDeInit failed";
+    mIsEseInitialized = false;
+    mIsSeHalInitDone = false;
+  }
+  return ndk::ScopedAStatus::ok();
+}
+
+ScopedAStatus SecureElement::isCardPresent(bool* _aidl_return) {
+  LOG(INFO) << __func__;
+  *_aidl_return = true;
+  return ScopedAStatus::ok();
+}
+
+ScopedAStatus SecureElement::transmit(const std::vector<uint8_t>& data,
+                                      std::vector<uint8_t>* _aidl_return) {
+  AutoMutex guard(seHalLock);
+  ESESTATUS status = ESESTATUS_FAILED;
+  std::vector<uint8_t> result;
+  phNxpEse_memset(&gsTxRxBuffer.cmdData, 0x00, sizeof(phNxpEse_data));
+  phNxpEse_memset(&gsTxRxBuffer.rspData, 0x00, sizeof(phNxpEse_data));
+  gsTxRxBuffer.cmdData.len = (uint32_t)data.size();
+  gsTxRxBuffer.cmdData.p_data =
+      (uint8_t*)phNxpEse_memalloc(data.size() * sizeof(uint8_t));
+  if (NULL == gsTxRxBuffer.cmdData.p_data) {
+    LOG(ERROR) << "transmit failed to allocate the Memory!!!";
+    /*Return empty vec*/
+    *_aidl_return = result;
+    return ScopedAStatus::ok();
+  }
+  OsuHalExtn::OsuApduMode mode = IS_OSU_MODE(
+      data, OsuHalExtn::getInstance().TRANSMIT, &gsTxRxBuffer.cmdData);
+  if (mode == OsuHalExtn::getInstance().OSU_BLOCKED_MODE) {
+    LOG(ERROR) << "Not allowed in dedicated mode!!!";
+    /*Return empty vec*/
+    *_aidl_return = result;
+    return ScopedAStatus::ok();
+  } else if (mode == OsuHalExtn::getInstance().OSU_RST_MODE) {
+    uint8_t sw[2] = {0x90, 0x00};
+    result.resize(sizeof(sw));
+    memcpy(&result[0], sw, sizeof(sw));
+    *_aidl_return = result;
+    return ScopedAStatus::ok();
+  } else {
+    // continue with normal processing
+  }
+  // memcpy(gsTxRxBuffer.cmdData.p_data, data.data(), gsTxRxBuffer.cmdData.len);
+  LOG(INFO) << "Acquired lock for SPI";
+  status = phNxpEse_SetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  status = phNxpEse_Transceive(&gsTxRxBuffer.cmdData, &gsTxRxBuffer.rspData);
+
+  if (status == ESESTATUS_SUCCESS) {
+    result.resize(gsTxRxBuffer.rspData.len);
+    memcpy(&result[0], gsTxRxBuffer.rspData.p_data, gsTxRxBuffer.rspData.len);
+  } else if (status == ESESTATUS_INVALID_RECEIVE_LENGTH) {
+    uint8_t respBuf[] = {INVALID_LEN_SW1, INVALID_LEN_SW2};
+    result.resize(sizeof(respBuf));
+    memcpy(&result[0], respBuf, sizeof(respBuf));
+  } else {
+    LOG(ERROR) << "transmit failed!!!";
+    if (!mOpenedchannelCount) {
+      // 0x69, 0x86 = COMMAND NOT ALLOWED
+      uint8_t sw[2] = {0x69, 0x86};
+      result.resize(sizeof(sw));
+      memcpy(&result[0], sw, sizeof(sw));
+    }
+  }
+  status = phNxpEse_ResetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+
+  *_aidl_return = result;
+  if (NULL != gsTxRxBuffer.cmdData.p_data) {
+    phNxpEse_free(gsTxRxBuffer.cmdData.p_data);
+    gsTxRxBuffer.cmdData.p_data = NULL;
+  }
+  if (NULL != gsTxRxBuffer.rspData.p_data) {
+    phNxpEse_free(gsTxRxBuffer.rspData.p_data);
+    gsTxRxBuffer.rspData.p_data = NULL;
+  }
+
+  return ScopedAStatus::ok();
+}
+
+ScopedAStatus SecureElement::openLogicalChannel(
+    const std::vector<uint8_t>& aid, int8_t p2,
+    ::aidl::android::hardware::secure_element::LogicalChannelResponse*
+        _aidl_return) {
+  AutoMutex guard(seHalLock);
+  std::vector<uint8_t> manageChannelCommand = {0x00, 0x70, 0x00, 0x00, 0x01};
+
+  LogicalChannelResponse resApduBuff;
+  resApduBuff.channelNumber = 0xff;
+  memset(&resApduBuff, 0x00, sizeof(resApduBuff));
+
+  /*
+   * Basic channel & reserved channel if any is removed
+   * from count
+   */
+  uint8_t maxLogicalChannelSupported =
+      mMaxChannelCount - getReserveChannelCnt(aid) - 1;
+
+  uint8_t openedLogicalChannelCount = mOpenedchannelCount;
+  if (mOpenedChannels[0]) openedLogicalChannelCount--;
+
+  if (openedLogicalChannelCount >= maxLogicalChannelSupported) {
+    ALOGE("%s: Reached Max supported(%d) Logical Channel", __func__,
+          openedLogicalChannelCount);
+    *_aidl_return = resApduBuff;
+    return ScopedAStatus::fromServiceSpecificError(CHANNEL_NOT_AVAILABLE);
+  }
+
+  LOG(INFO) << "Acquired the lock from SPI openLogicalChannel";
+
+  // In dedicated mode openLogical not allowed
+  if (IS_OSU_MODE(OsuHalExtn::getInstance().OPENLOGICAL)) {
+    LOG(ERROR) << "%s: Not allowed in dedicated mode!!!" << __func__;
+    *_aidl_return = resApduBuff;
+    return ScopedAStatus::fromServiceSpecificError(IOERROR);
+  }
+  if (!mIsEseInitialized) {
+    ESESTATUS status = seHalInit();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+      *_aidl_return = resApduBuff;
+      return ScopedAStatus::fromServiceSpecificError(IOERROR);
+    }
+  }
+
+  if (mOpenedChannels.size() == 0x00) {
+    mMaxChannelCount = getMaxChannelCnt();
+    mOpenedChannels.resize(mMaxChannelCount, false);
+  }
+
+  int sestatus = ISecureElement::IOERROR;
+  ESESTATUS status = ESESTATUS_FAILED;
+  phNxpEse_data cmdApdu;
+  phNxpEse_data rspApdu;
+
+  phNxpEse_memset(&cmdApdu, 0x00, sizeof(phNxpEse_data));
+
+  phNxpEse_memset(&rspApdu, 0x00, sizeof(phNxpEse_data));
+
+  cmdApdu.len = (uint32_t)manageChannelCommand.size();
+  cmdApdu.p_data = (uint8_t*)phNxpEse_memalloc(manageChannelCommand.size() *
+                                               sizeof(uint8_t));
+  memcpy(cmdApdu.p_data, manageChannelCommand.data(), cmdApdu.len);
+
+  status = phNxpEse_SetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  status = phNxpEse_Transceive(&cmdApdu, &rspApdu);
+  if (status != ESESTATUS_SUCCESS) {
+    resApduBuff.channelNumber = 0xff;
+  } else if (rspApdu.p_data[rspApdu.len - 2] == 0x6A &&
+             rspApdu.p_data[rspApdu.len - 1] == 0x81) {
+    resApduBuff.channelNumber = 0xff;
+    sestatus = ISecureElement::CHANNEL_NOT_AVAILABLE;
+  } else if (rspApdu.p_data[rspApdu.len - 2] == 0x90 &&
+             rspApdu.p_data[rspApdu.len - 1] == 0x00) {
+    resApduBuff.channelNumber = rspApdu.p_data[0];
+    mOpenedchannelCount++;
+    mOpenedChannels[resApduBuff.channelNumber] = true;
+    sestatus = SESTATUS_SUCCESS;
+  } else if (((rspApdu.p_data[rspApdu.len - 2] == 0x6E) ||
+              (rspApdu.p_data[rspApdu.len - 2] == 0x6D)) &&
+             rspApdu.p_data[rspApdu.len - 1] == 0x00) {
+    sestatus = ISecureElement::UNSUPPORTED_OPERATION;
+  }
+  /*Free the allocations*/
+  phNxpEse_free(cmdApdu.p_data);
+  phNxpEse_free(rspApdu.p_data);
+
+  if (sestatus != SESTATUS_SUCCESS) {
+    if (mOpenedchannelCount == 0) {
+      int deInitStatus = seHalDeInit();
+      if (deInitStatus != SESTATUS_SUCCESS) {
+        LOG(INFO) << "seDeInit Failed";
+      }
+    }
+    /*If manageChannel is failed in any of above cases
+    send the callback and return*/
+    status = phNxpEse_ResetEndPoint_Cntxt(0);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+    *_aidl_return = resApduBuff;
+    return ScopedAStatus::fromServiceSpecificError(sestatus);
+  }
+  LOG(INFO) << "openLogicalChannel Sending selectApdu";
+  sestatus = ISecureElement::IOERROR;
+  status = ESESTATUS_FAILED;
+
+  phNxpEse_7816_cpdu_t cpdu;
+  phNxpEse_7816_rpdu_t rpdu;
+  phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
+  phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
+
+  if ((resApduBuff.channelNumber > 0x03) &&
+      (resApduBuff.channelNumber < 0x14)) {
+    /* update CLA byte according to GP spec Table 11-12*/
+    cpdu.cla =
+        0x40 + (resApduBuff.channelNumber - 4); /* Class of instruction */
+  } else if ((resApduBuff.channelNumber > 0x00) &&
+             (resApduBuff.channelNumber < 0x04)) {
+    /* update CLA byte according to GP spec Table 11-11*/
+    cpdu.cla = resApduBuff.channelNumber; /* Class of instruction */
+  } else {
+    ALOGE("%s: Invalid Channel no: %02x", __func__, resApduBuff.channelNumber);
+    resApduBuff.channelNumber = 0xff;
+    *_aidl_return = resApduBuff;
+    return ScopedAStatus::fromServiceSpecificError(IOERROR);
+  }
+  cpdu.ins = 0xA4; /* Instruction code */
+  cpdu.p1 = 0x04;  /* Instruction parameter 1 */
+  cpdu.p2 = p2;    /* Instruction parameter 2 */
+  cpdu.lc = (uint16_t)aid.size();
+  cpdu.le_type = 0x01;
+  cpdu.pdata = (uint8_t*)phNxpEse_memalloc(aid.size() * sizeof(uint8_t));
+  memcpy(cpdu.pdata, aid.data(), cpdu.lc);
+  cpdu.le = 256;
+
+  rpdu.len = 0x02;
+  rpdu.pdata = (uint8_t*)phNxpEse_memalloc(cpdu.le * sizeof(uint8_t));
+
+  status = phNxpEse_7816_Transceive(&cpdu, &rpdu);
+
+  if (status != ESESTATUS_SUCCESS) {
+    /*Transceive failed*/
+    if (rpdu.len > 0 && (rpdu.sw1 == 0x64 && rpdu.sw2 == 0xFF)) {
+      sestatus = ISecureElement::IOERROR;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  } else {
+    /*Status word to be passed as part of response
+    So include additional length*/
+    uint16_t responseLen = rpdu.len + 2;
+    resApduBuff.selectResponse.resize(responseLen);
+    memcpy(&resApduBuff.selectResponse[0], rpdu.pdata, rpdu.len);
+    resApduBuff.selectResponse[responseLen - 1] = rpdu.sw2;
+    resApduBuff.selectResponse[responseLen - 2] = rpdu.sw1;
+
+    if (rpdu.sw1 == SW1_BYTES_REMAINING) {
+      sestatus =
+          getResponseInternal(cpdu.cla, rpdu, resApduBuff.selectResponse);
+      if (sestatus != SESTATUS_SUCCESS) {
+        LOG(ERROR) << "%s: getResponseInternal Failed" << __func__;
+      }
+    }
+
+    /*Status is success*/
+    if ((rpdu.sw1 == 0x90 && rpdu.sw2 == 0x00) || (rpdu.sw1 == 0x62) ||
+        (rpdu.sw1 == 0x63)) {
+      sestatus = SESTATUS_SUCCESS;
+    }
+    /*AID provided doesn't match any applet on the secure element*/
+    else if ((rpdu.sw1 == 0x6A && rpdu.sw2 == 0x82) ||
+             (rpdu.sw1 == 0x69 && (rpdu.sw2 == 0x99 || rpdu.sw2 == 0x85))) {
+      sestatus = ISecureElement::NO_SUCH_ELEMENT_ERROR;
+    }
+    /*Operation provided by the P2 parameter is not permitted by the applet.*/
+    else if (rpdu.sw1 == 0x6A && rpdu.sw2 == 0x86) {
+      sestatus = ISecureElement::UNSUPPORTED_OPERATION;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  }
+  if (sestatus != SESTATUS_SUCCESS) {
+    int closeChannelStatus = internalCloseChannel(resApduBuff.channelNumber);
+    if (closeChannelStatus != SESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: closeChannel Failed" << __func__;
+    } else {
+      resApduBuff.channelNumber = 0xff;
+    }
+  }
+  status = phNxpEse_ResetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  *_aidl_return = resApduBuff;
+  phNxpEse_free(cpdu.pdata);
+  phNxpEse_free(rpdu.pdata);
+
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+ScopedAStatus SecureElement::openBasicChannel(
+    const std::vector<uint8_t>& aid, int8_t p2,
+    std::vector<uint8_t>* _aidl_return) {
+  AutoMutex guard(seHalLock);
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  phNxpEse_7816_cpdu_t cpdu;
+  phNxpEse_7816_rpdu_t rpdu;
+  std::vector<uint8_t> result;
+
+  if (mOpenedChannels[0]) {
+    LOG(ERROR) << "openBasicChannel failed, channel already in use";
+    *_aidl_return = result;
+    return ScopedAStatus::fromServiceSpecificError(UNSUPPORTED_OPERATION);
+  }
+
+  LOG(ERROR) << "Acquired the lock in SPI openBasicChannel";
+  OsuHalExtn::OsuApduMode mode =
+      IS_OSU_MODE(aid, OsuHalExtn::getInstance().OPENBASIC);
+  if (mode == OsuHalExtn::OSU_PROP_MODE) {
+    uint8_t sw[2] = {0x90, 0x00};
+    result.resize(sizeof(sw));
+    memcpy(&result[0], sw, 2);
+    if (mIsEseInitialized) {
+      /* Close existing sessions if any to start dedicated OSU Mode
+       * with OSU specific settings in TZ/TEE */
+      if (seHalDeInit() != SESTATUS_SUCCESS) {
+        LOG(INFO) << "seDeInit Failed";
+        *_aidl_return = result;
+        return ScopedAStatus::fromServiceSpecificError(IOERROR);
+      }
+    }
+    phNxpEse_setWtxCountLimit(OsuHalExtn::getInstance().getOSUMaxWtxCount());
+    ESESTATUS status = ESESTATUS_FAILED;
+    uint8_t retry = 0;
+    do {
+      /*For Reset Recovery*/
+      status = seHalInit();
+    } while (status != ESESTATUS_SUCCESS && retry++ < 1);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+      phNxpEse_setWtxCountLimit(RESET_APP_WTX_COUNT);
+      *_aidl_return = result;
+      return ScopedAStatus::fromServiceSpecificError(IOERROR);
+    }
+    if (phNxpEse_doResetProtection(true) != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: Enable Reset Protection Failed!!!" << __func__;
+      *_aidl_return = result;
+      return ScopedAStatus::fromServiceSpecificError(FAILED);
+    } else {
+      *_aidl_return = result;
+      return ScopedAStatus::ok();
+    }
+  }
+
+  if (!mIsEseInitialized) {
+    ESESTATUS status = seHalInit();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+      *_aidl_return = result;
+      return ScopedAStatus::fromServiceSpecificError(IOERROR);
+    }
+  }
+
+  phNxpEse_data atrData;
+  if (phNxpEse_getAtr(&atrData) != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_getAtr failed";
+  }
+  if (atrData.p_data != NULL) {
+    phNxpEse_free(atrData.p_data);
+  }
+
+  if (phNxpEse_GetOsMode() == OSU_MODE) {
+    if (mOpenedchannelCount == 0) {
+      if (seHalDeInit() != SESTATUS_SUCCESS) {
+        LOG(INFO) << "seDeInit Failed";
+      }
+    }
+    *_aidl_return = result;
+    return ScopedAStatus::fromServiceSpecificError(IOERROR);
+  }
+
+  if (mOpenedChannels.size() == 0x00) {
+    mMaxChannelCount = getMaxChannelCnt();
+    mOpenedChannels.resize(mMaxChannelCount, false);
+  }
+  phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
+  phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
+
+  cpdu.cla = 0x00; /* Class of instruction */
+  cpdu.ins = 0xA4; /* Instruction code */
+  cpdu.p1 = 0x04;  /* Instruction parameter 1 */
+  cpdu.p2 = p2;    /* Instruction parameter 2 */
+  cpdu.lc = (uint16_t)aid.size();
+  cpdu.le_type = 0x01;
+  cpdu.pdata = (uint8_t*)phNxpEse_memalloc(aid.size() * sizeof(uint8_t));
+  memcpy(cpdu.pdata, aid.data(), cpdu.lc);
+  cpdu.le = 256;
+
+  rpdu.len = 0x02;
+  rpdu.pdata = (uint8_t*)phNxpEse_memalloc(cpdu.le * sizeof(uint8_t));
+
+  status = phNxpEse_SetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  status = phNxpEse_7816_Transceive(&cpdu, &rpdu);
+  int sestatus;
+  sestatus = SESTATUS_SUCCESS;
+
+  if (status != ESESTATUS_SUCCESS) {
+    /* Transceive failed */
+    if (rpdu.len > 0 && (rpdu.sw1 == 0x64 && rpdu.sw2 == 0xFF)) {
+      sestatus = ISecureElement::IOERROR;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  } else {
+    /*Status word to be passed as part of response
+    So include additional length*/
+    uint16_t responseLen = rpdu.len + 2;
+    result.resize(responseLen);
+    memcpy(&result[0], rpdu.pdata, rpdu.len);
+    result[responseLen - 1] = rpdu.sw2;
+    result[responseLen - 2] = rpdu.sw1;
+    if (rpdu.sw1 == SW1_BYTES_REMAINING) {
+      sestatus = getResponseInternal(cpdu.cla, rpdu, result);
+      if (sestatus != SESTATUS_SUCCESS) {
+        LOG(ERROR) << "%s: getResponseInternal Failed " << __func__;
+      }
+    }
+
+    /*Status is success*/
+    if (((rpdu.sw1 == 0x90) && (rpdu.sw2 == 0x00)) || (rpdu.sw1 == 0x62) ||
+        (rpdu.sw1 == 0x63)) {
+      /*Set basic channel reference if it is not set */
+      if (!mOpenedChannels[0]) {
+        mOpenedChannels[0] = true;
+        mOpenedchannelCount++;
+      }
+
+      sestatus = SESTATUS_SUCCESS;
+    }
+    /*AID provided doesn't match any applet on the secure element*/
+    else if ((rpdu.sw1 == 0x6A && rpdu.sw2 == 0x82) ||
+             (rpdu.sw1 == 0x69 && (rpdu.sw2 == 0x99 || rpdu.sw2 == 0x85))) {
+      sestatus = ISecureElement::NO_SUCH_ELEMENT_ERROR;
+    }
+    /*Operation provided by the P2 parameter is not permitted by the applet.*/
+    else if (rpdu.sw1 == 0x6A && rpdu.sw2 == 0x86) {
+      sestatus = ISecureElement::UNSUPPORTED_OPERATION;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  }
+  status = phNxpEse_ResetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  if (sestatus != SESTATUS_SUCCESS) {
+    int closeChannelStatus = internalCloseChannel(DEFAULT_BASIC_CHANNEL);
+    if (closeChannelStatus != SESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: closeChannel Failed" << __func__;
+    }
+  }
+  *_aidl_return = result;
+  phNxpEse_free(cpdu.pdata);
+  phNxpEse_free(rpdu.pdata);
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+int SecureElement::internalCloseChannel(uint8_t channelNumber) {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  int sestatus = ISecureElement::FAILED;
+  phNxpEse_7816_cpdu_t cpdu;
+  phNxpEse_7816_rpdu_t rpdu;
+
+  LOG(ERROR) << "Acquired the lock in SPI internalCloseChannel";
+  ALOGD("mMaxChannelCount = %d, Closing Channel = %d", mMaxChannelCount,
+        channelNumber);
+  if (channelNumber >= mMaxChannelCount) {
+    ALOGE("invalid channel!!! %d", channelNumber);
+  } else if (channelNumber > DEFAULT_BASIC_CHANNEL &&
+             mOpenedChannels[channelNumber]) {
+    phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
+    phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
+    cpdu.cla = channelNumber; /* Class of instruction */
+    // For Supplementary Channel update CLA byte according to GP
+    if ((channelNumber > 0x03) && (channelNumber < 0x14)) {
+      /* update CLA byte according to GP spec Table 11-12*/
+      cpdu.cla = 0x40 + (channelNumber - 4); /* Class of instruction */
+    }
+    cpdu.ins = 0x70;         /* Instruction code */
+    cpdu.p1 = 0x80;          /* Instruction parameter 1 */
+    cpdu.p2 = channelNumber; /* Instruction parameter 2 */
+    cpdu.lc = 0x00;
+    cpdu.le = 0x9000;
+    status = phNxpEse_SetEndPoint_Cntxt(0);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+    status = phNxpEse_7816_Transceive(&cpdu, &rpdu);
+    if (status == ESESTATUS_SUCCESS) {
+      if ((rpdu.sw1 == 0x90) && (rpdu.sw2 == 0x00)) {
+        sestatus = SESTATUS_SUCCESS;
+      }
+    }
+    status = phNxpEse_ResetEndPoint_Cntxt(0);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+  } else if (channelNumber == DEFAULT_BASIC_CHANNEL &&
+             mOpenedChannels[channelNumber]) {
+    sestatus = SESTATUS_SUCCESS;
+  }
+  if (channelNumber < mMaxChannelCount) {
+    if (mOpenedChannels[channelNumber]) {
+      mOpenedChannels[channelNumber] = false;
+      mOpenedchannelCount--;
+    }
+  }
+  /*If there are no channels remaining close secureElement*/
+  if (mOpenedchannelCount == 0) {
+    if (SESTATUS_SUCCESS != seHalDeInit()) {
+      LOG(ERROR) << "internalCloseChannel seHalDeInit failed";
+    }
+  } else {
+    sestatus = SESTATUS_SUCCESS;
+  }
+  return sestatus;
+}
+
+ScopedAStatus SecureElement::closeChannel(int8_t channelNumber) {
+  AutoMutex guard(seHalLock);
+  int sestatus;
+  // Close internal allowed when not in dedicated Mode
+  if (!IS_OSU_MODE(OsuHalExtn::getInstance().CLOSE, channelNumber)) {
+    sestatus = internalCloseChannel(channelNumber);
+  } else {
+    /*Decrement channel count opened to
+     * keep in sync with service */
+    if (channelNumber < mMaxChannelCount) {
+      if (mOpenedChannels[channelNumber]) {
+        mOpenedChannels[channelNumber] = false;
+        mOpenedchannelCount--;
+      }
+    }
+    sestatus = SESTATUS_SUCCESS;
+  }
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+ESESTATUS SecureElement::seHalInit() {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  phNxpEse_initParams initParams;
+  ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
+  memset(&initParams, 0x00, sizeof(phNxpEse_initParams));
+  initParams.initMode = ESE_MODE_NORMAL;
+  initParams.mediaType = ESE_PROTOCOL_MEDIA_SPI_APDU_GATE;
+  initParams.fPtr_WtxNtf = SecureElement::NotifySeWaitExtension;
+
+  status = phNxpEse_open(initParams);
+  if (ESESTATUS_SUCCESS == status || ESESTATUS_BUSY == status) {
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(0) &&
+        ESESTATUS_SUCCESS == (status = phNxpEse_init(initParams))) {
+      if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(0)) {
+        mIsEseInitialized = true;
+        LOG(INFO) << "ESE SPI init complete!!!";
+        return ESESTATUS_SUCCESS;
+      }
+    } else {
+      LOG(INFO) << "ESE SPI init NOT successful";
+      status = ESESTATUS_FAILED;
+    }
+    deInitStatus = phNxpEse_deInit();
+    if (phNxpEse_close(deInitStatus) != ESESTATUS_SUCCESS) {
+      LOG(INFO) << "ESE close not successful";
+      status = ESESTATUS_FAILED;
+    }
+    mIsEseInitialized = false;
+  }
+  return status;
+}
+
+int SecureElement::seHalDeInit() {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
+  bool mIsDeInitDone = true;
+  int sestatus = ISecureElement::FAILED;
+  status = phNxpEse_SetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    mIsDeInitDone = false;
+  }
+  deInitStatus = phNxpEse_deInit();
+  if (ESESTATUS_SUCCESS != deInitStatus) mIsDeInitDone = false;
+  status = phNxpEse_ResetEndPoint_Cntxt(0);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    mIsDeInitDone = false;
+  }
+  status = phNxpEse_close(deInitStatus);
+  if (status == ESESTATUS_SUCCESS && mIsDeInitDone) {
+    sestatus = SESTATUS_SUCCESS;
+  } else {
+    LOG(ERROR) << "seHalDeInit: Failed";
+  }
+  mIsEseInitialized = false;
+  for (uint8_t xx = 0; xx < mMaxChannelCount; xx++) {
+    mOpenedChannels[xx] = false;
+  }
+  mOpenedchannelCount = 0;
+
+  return sestatus;
+}
+
+ScopedAStatus SecureElement::reset() {
+  LOG(INFO) << __func__;
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  int sestatus = ISecureElement::FAILED;
+  LOG(INFO) << __func__ << " Enter";
+  if (!mIsEseInitialized) {
+    ESESTATUS status = seHalInit();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << __func__ << " seHalInit Failed!!!";
+    }
+  }
+  if (status == ESESTATUS_SUCCESS) {
+    mCb->onStateChange(false, "reset");
+    status = phNxpEse_reset();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << __func__ << " SecureElement reset failed!!";
+    } else {
+      sestatus = SESTATUS_SUCCESS;
+      if (mOpenedChannels.size() == 0x00) {
+        mMaxChannelCount = getMaxChannelCnt();
+        mOpenedChannels.resize(mMaxChannelCount, false);
+      }
+      for (uint8_t xx = 0; xx < mMaxChannelCount; xx++) {
+        mOpenedChannels[xx] = false;
+      }
+      mOpenedchannelCount = 0;
+      mCb->onStateChange(true, "reset");
+    }
+  }
+  LOG(ERROR) << __func__ << ": Exit";
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+static int getResponseInternal(uint8_t cla, phNxpEse_7816_rpdu_t& rpdu,
+                               std::vector<uint8_t>& result) {
+  int sestatus = SESTATUS_SUCCESS;
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  phNxpEse_data cmdApdu;
+  phNxpEse_data rspApdu;
+  uint16_t responseLen = rpdu.len;  // Response already copied
+  uint8_t getRespLe = rpdu.sw2;     // Response pending to receive
+  uint8_t getResponse[5] = {0x00, 0xC0, 0x00, 0x00, 0x00};
+
+  getResponse[0] = cla;
+
+  phNxpEse_memset(&cmdApdu, 0x00, sizeof(phNxpEse_data));
+
+  cmdApdu.len = (uint32_t)sizeof(getResponse);
+  cmdApdu.p_data = getResponse;
+
+  do {
+    // update GET response 61 xx(Le)
+    getResponse[4] = getRespLe;
+
+    phNxpEse_memset(&rspApdu, 0x00, sizeof(phNxpEse_data));
+
+    status = phNxpEse_Transceive(&cmdApdu, &rspApdu);
+    if (status != ESESTATUS_SUCCESS) {
+      /*Transceive failed*/
+      if (rspApdu.len > 0 && (rspApdu.p_data[rspApdu.len - 2] == 0x64 &&
+                              rspApdu.p_data[rspApdu.len - 1] == 0xFF)) {
+        sestatus = ISecureElement::IOERROR;
+      } else {
+        sestatus = ISecureElement::FAILED;
+      }
+      break;
+    } else {
+      uint32_t respLen = rspApdu.len;
+
+      // skip 2 bytes in case of 61xx SW again
+      if (rspApdu.p_data[respLen - 2] == SW1_BYTES_REMAINING) {
+        respLen -= 2;
+        getRespLe = rspApdu.p_data[respLen - 1];
+      }
+      // copy response chunk received
+      result.resize(responseLen + respLen);
+      memcpy(&result[responseLen], rspApdu.p_data, respLen);
+      responseLen += respLen;
+    }
+  } while (rspApdu.p_data[rspApdu.len - 2] == SW1_BYTES_REMAINING);
+
+  // Propagate SW as it is received from card
+  if (sestatus == SESTATUS_SUCCESS) {
+    rpdu.sw1 = rspApdu.p_data[rspApdu.len - 2];
+    rpdu.sw2 = rspApdu.p_data[rspApdu.len - 1];
+  } else {  // Other Failure cases update failure SW:64FF
+    rpdu.sw1 = INVALID_LEN_SW1;
+    rpdu.sw2 = INVALID_LEN_SW2;
+  }
+
+  return sestatus;
+}
+
+uint8_t SecureElement::getReserveChannelCnt(const std::vector<uint8_t>& aid) {
+  const std::vector<uint8_t> weaverAid = {0xA0, 0x00, 0x00, 0x03,
+                                          0x96, 0x10, 0x10};
+  const std::vector<uint8_t> araAid = {0xA0, 0x00, 0x00, 0x01, 0x51,
+                                       0x41, 0x43, 0x4C, 0x00};
+  uint8_t reserveChannel = 0;
+  // Check priority access enabled then only reserve channel
+  if (mHasPriorityAccess && aid != weaverAid && aid != araAid) {
+    // Exclude basic channel
+    reserveChannel = 1;
+  }
+  return reserveChannel;
+}
+
+uint8_t SecureElement::getMaxChannelCnt() {
+  /*
+   * 1) SN1xx max channel supported 4.
+   * 2) SN220 up to v2 max channel supported 5 (If priority access)
+   *    otherwise 4 channel.
+   * 3) SN220 v3 and higher shall be updated accordingly.
+   */
+  uint8_t cnt = 0;
+  if (GET_CHIP_OS_VERSION() < OS_VERSION_6_2)
+    cnt = NUM_OF_CH4;
+  else if (GET_CHIP_OS_VERSION() == OS_VERSION_6_2)
+    cnt = (mHasPriorityAccess ? NUM_OF_CH5 : NUM_OF_CH4);
+  else
+    cnt = NUM_OF_CH5;
+
+  return cnt;
+}
+
+}  // namespace secure_element
+}  // namespace hardware
+}  // namespace android
+}  // namespace aidl
diff --git a/snxxx/aidl/SecureElement.h b/snxxx/aidl/SecureElement.h
new file mode 100644
index 0000000..1309db0
--- /dev/null
+++ b/snxxx/aidl/SecureElement.h
@@ -0,0 +1,113 @@
+/******************************************************************************
+ *
+ *  Copyright 2023 NXP
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+#pragma once
+
+#include <SyncEvent.h>
+#include <aidl/android/hardware/secure_element/BnSecureElement.h>
+#include <aidl/android/hardware/secure_element/ISecureElementCallback.h>
+#include <android-base/logging.h>
+#include <log/log.h>
+
+#include "OsuHalExtn.h"
+#include "phNxpEse_Api.h"
+
+#define SESTATUS_SUCCESS 0
+
+class ThreadMutex {
+ public:
+  ThreadMutex();
+  virtual ~ThreadMutex();
+  void lock();
+  void unlock();
+  operator pthread_mutex_t*() { return &mMutex; }
+
+ private:
+  pthread_mutex_t mMutex;
+};
+
+class AutoThreadMutex {
+ public:
+  AutoThreadMutex(ThreadMutex& m);
+  virtual ~AutoThreadMutex();
+  operator ThreadMutex&() { return mm; }
+  operator pthread_mutex_t*() { return (pthread_mutex_t*)mm; }
+
+ private:
+  ThreadMutex& mm;
+};
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace secure_element {
+
+using ::ndk::ICInterface;
+using ndk::ScopedAStatus;
+
+#ifndef MIN_APDU_LENGTH
+#define MIN_APDU_LENGTH 0x04
+#endif
+#ifndef DEFAULT_BASIC_CHANNEL
+#define DEFAULT_BASIC_CHANNEL 0x00
+#endif
+
+struct SecureElement : public BnSecureElement {
+ public:
+  SecureElement();
+  ::ndk::ScopedAStatus closeChannel(int8_t in_channelNumber) override;
+  ::ndk::ScopedAStatus getAtr(std::vector<uint8_t>* _aidl_return) override;
+  ::ndk::ScopedAStatus init(
+      const std::shared_ptr<
+          ::aidl::android::hardware::secure_element::ISecureElementCallback>&
+          in_clientCallback) override;
+  ::ndk::ScopedAStatus isCardPresent(bool* _aidl_return) override;
+  ::ndk::ScopedAStatus openBasicChannel(
+      const std::vector<uint8_t>& in_aid, int8_t in_p2,
+      std::vector<uint8_t>* _aidl_return) override;
+  ::ndk::ScopedAStatus openLogicalChannel(
+      const std::vector<uint8_t>& in_aid, int8_t in_p2,
+      ::aidl::android::hardware::secure_element::LogicalChannelResponse*
+          _aidl_return) override;
+  ::ndk::ScopedAStatus reset() override;
+  ::ndk::ScopedAStatus transmit(const std::vector<uint8_t>& in_data,
+                                std::vector<uint8_t>* _aidl_return) override;
+
+  static void NotifySeWaitExtension(phNxpEse_wtxState state);
+  void updateSeHalInitState(bool);
+  int seHalDeInit();
+
+ private:
+  uint8_t mMaxChannelCount;
+  uint8_t mOpenedchannelCount = 0;
+  Mutex seHalLock;
+  bool mIsEseInitialized = false;
+  static std::vector<bool> mOpenedChannels;
+
+  static std::shared_ptr<ISecureElementCallback> mCb;
+  bool mHasPriorityAccess = false;
+
+  ESESTATUS seHalInit();
+  int internalCloseChannel(uint8_t channelNumber);
+  uint8_t getReserveChannelCnt(const std::vector<uint8_t>& aid);
+  uint8_t getMaxChannelCnt();
+};
+
+}  // namespace secure_element
+}  // namespace hardware
+}  // namespace android
+}  // namespace aidl
\ No newline at end of file
diff --git a/snxxx/aidl/VirtualISO.cpp b/snxxx/aidl/VirtualISO.cpp
new file mode 100644
index 0000000..571e365
--- /dev/null
+++ b/snxxx/aidl/VirtualISO.cpp
@@ -0,0 +1,669 @@
+/******************************************************************************
+ *
+ *  Copyright 2023 NXP
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+#include "VirtualISO.h"
+
+#include "SecureElement.h"
+// Undefined LOG_TAG as it is also defined in log.h
+#undef LOG_TAG
+#include <memunreachable/memunreachable.h>
+// #include "hal_nxpese.h"
+#include "phNxpEse_Apdu_Api.h"
+#include "phNxpEse_Api.h"
+
+namespace aidl {
+namespace vendor {
+namespace nxp {
+namespace virtual_iso {
+
+#define LOG_TAG "nxpVIsoese_aidl-service"
+
+#define DEFAULT_BASIC_CHANNEL 0x00
+
+typedef struct gsTransceiveBuffer {
+  phNxpEse_data cmdData;
+  phNxpEse_data rspData;
+  std::vector<uint8_t>* pRspDataBuff;
+} sTransceiveBuffer_t;
+static sTransceiveBuffer_t gsTxRxBuffer;
+static std::vector<uint8_t> gsRspDataBuff(256);
+
+std::shared_ptr<ISecureElementCallback> VirtualISO::mCallback = nullptr;
+AIBinder_DeathRecipient* clientDeathRecipient = nullptr;
+std::vector<bool> VirtualISO::mOpenedChannels;
+
+VirtualISO::VirtualISO()
+    : mMaxChannelCount(0), mOpenedchannelCount(0), mIsEseInitialized(false) {}
+
+void OnDeath(void* cookie) {
+  (void)cookie;
+  // TODO: Implement graceful closure, to close ongoing tx-rx and deinit
+  // T=1 stack
+  // close(0);
+}
+
+ScopedAStatus VirtualISO::init(
+    const std::shared_ptr<ISecureElementCallback>& clientCallback) {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
+  bool mIsInitDone = false;
+  phNxpEse_initParams initParams;
+  LOG(INFO) << "Virtual ISO::init Enter";
+  gsTxRxBuffer.pRspDataBuff = &gsRspDataBuff;
+  memset(&initParams, 0x00, sizeof(phNxpEse_initParams));
+  initParams.initMode = ESE_MODE_NORMAL;
+  initParams.mediaType = ESE_PROTOCOL_MEDIA_SPI_APDU_GATE;
+
+  if (clientCallback == nullptr) {
+    return ScopedAStatus::ok();
+  } else {
+    clientDeathRecipient = AIBinder_DeathRecipient_new(OnDeath);
+    auto linkRet =
+        AIBinder_linkToDeath(clientCallback->asBinder().get(),
+                             clientDeathRecipient, this /* cookie */);
+    if (linkRet != STATUS_OK) {
+      LOG(ERROR) << __func__ << ": linkToDeath failed: " << linkRet;
+      // Just ignore the error.
+    }
+  }
+
+  if (mIsEseInitialized) {
+    clientCallback->onStateChange(true, "NXP VISIO HAL init ok");
+    return ScopedAStatus::ok();
+  }
+  status = phNxpEse_open(initParams);
+  if (status == ESESTATUS_SUCCESS || ESESTATUS_BUSY == status) {
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(1) &&
+        ESESTATUS_SUCCESS == phNxpEse_init(initParams)) {
+      if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(1)) {
+        LOG(INFO) << "VISO init complete!!!";
+        mIsInitDone = true;
+      }
+      deInitStatus = phNxpEse_deInit();
+      if (ESESTATUS_SUCCESS != deInitStatus) mIsInitDone = false;
+    }
+    status = phNxpEse_close(deInitStatus);
+  }
+  if (status == ESESTATUS_SUCCESS && mIsInitDone) {
+    mMaxChannelCount = (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
+    mOpenedChannels.resize(mMaxChannelCount, false);
+    clientCallback->onStateChange(true, "NXP VISIO HAL init ok");
+  } else {
+    LOG(ERROR) << "VISO-Hal Init failed";
+    clientCallback->onStateChange(false, "NXP VISIO HAL init failed");
+  }
+  return ScopedAStatus::ok();
+}
+
+ScopedAStatus VirtualISO::getAtr(std::vector<uint8_t>* _aidl_return) {
+  std::vector<uint8_t> response;
+  *_aidl_return = response;
+  return ScopedAStatus::ok();
+}
+
+ScopedAStatus VirtualISO::isCardPresent(bool* _aidl_return) {
+  LOG(INFO) << __func__;
+  *_aidl_return = true;
+  return ScopedAStatus::ok();
+}
+
+ScopedAStatus VirtualISO::transmit(const std::vector<uint8_t>& data,
+                                   std::vector<uint8_t>* _aidl_return) {
+  ESESTATUS status = ESESTATUS_FAILED;
+  std::vector<uint8_t> result;
+  phNxpEse_memset(&gsTxRxBuffer.cmdData, 0x00, sizeof(phNxpEse_data));
+  phNxpEse_memset(&gsTxRxBuffer.rspData, 0x00, sizeof(phNxpEse_data));
+  gsTxRxBuffer.cmdData.len = data.size();
+  gsTxRxBuffer.cmdData.p_data =
+      (uint8_t*)phNxpEse_memalloc(data.size() * sizeof(uint8_t));
+  if (NULL == gsTxRxBuffer.cmdData.p_data) {
+    LOG(ERROR) << "transmit failed to allocate the Memory!!!";
+    /*Return empty vec*/
+    *_aidl_return = result;
+    return ScopedAStatus::ok();
+  }
+  memcpy(gsTxRxBuffer.cmdData.p_data, data.data(), gsTxRxBuffer.cmdData.len);
+  LOG(ERROR) << "Acquired the lock in VISO ";
+  status = phNxpEse_SetEndPoint_Cntxt(1);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  status = phNxpEse_Transceive(&gsTxRxBuffer.cmdData, &gsTxRxBuffer.rspData);
+
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "transmit failed!!!";
+  } else {
+    result.resize(gsTxRxBuffer.rspData.len);
+    memcpy(&result[0], gsTxRxBuffer.rspData.p_data, gsTxRxBuffer.rspData.len);
+  }
+  status = phNxpEse_ResetEndPoint_Cntxt(1);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+
+  *_aidl_return = result;
+
+  if (NULL != gsTxRxBuffer.cmdData.p_data) {
+    phNxpEse_free(gsTxRxBuffer.cmdData.p_data);
+    gsTxRxBuffer.cmdData.p_data = NULL;
+  }
+  if (NULL != gsTxRxBuffer.rspData.p_data) {
+    phNxpEse_free(gsTxRxBuffer.rspData.p_data);
+    gsTxRxBuffer.rspData.p_data = NULL;
+  }
+
+  return ScopedAStatus::ok();
+}
+
+ScopedAStatus VirtualISO::openLogicalChannel(
+    const std::vector<uint8_t>& aid, int8_t p2,
+    ::aidl::android::hardware::secure_element::LogicalChannelResponse*
+        _aidl_return) {
+  std::vector<uint8_t> manageChannelCommand = {0x00, 0x70, 0x00, 0x00, 0x01};
+
+  LogicalChannelResponse resApduBuff;
+
+  if (GET_CHIP_OS_VERSION() <= OS_VERSION_6_2) {
+    uint8_t maxLogicalChannelSupported = mMaxChannelCount - 1;
+    uint8_t openedLogicalChannelCount = mOpenedchannelCount;
+    if (mOpenedChannels[0]) openedLogicalChannelCount--;
+
+    if (openedLogicalChannelCount >= maxLogicalChannelSupported) {
+      LOG(ERROR) << "%s: Reached Max supported Logical Channel" << __func__;
+      *_aidl_return = resApduBuff;
+      return ScopedAStatus::fromServiceSpecificError(CHANNEL_NOT_AVAILABLE);
+    }
+  }
+
+  LOG(INFO) << "Acquired the lock in VISO openLogicalChannel";
+
+  resApduBuff.channelNumber = 0xff;
+  memset(&resApduBuff, 0x00, sizeof(resApduBuff));
+  if (!mIsEseInitialized) {
+    ESESTATUS status = seHalInit();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+      *_aidl_return = resApduBuff;
+      return ScopedAStatus::fromServiceSpecificError(IOERROR);
+    }
+  }
+
+  if (mOpenedChannels.size() == 0x00) {
+    mMaxChannelCount = (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
+    mOpenedChannels.resize(mMaxChannelCount, false);
+  }
+
+  int sestatus = ISecureElement::IOERROR;
+
+  ESESTATUS status = ESESTATUS_FAILED;
+  phNxpEse_data cmdApdu;
+  phNxpEse_data rspApdu;
+
+  phNxpEse_memset(&cmdApdu, 0x00, sizeof(phNxpEse_data));
+  phNxpEse_memset(&rspApdu, 0x00, sizeof(phNxpEse_data));
+
+  cmdApdu.len = manageChannelCommand.size();
+  cmdApdu.p_data = (uint8_t*)phNxpEse_memalloc(manageChannelCommand.size() *
+                                               sizeof(uint8_t));
+  memcpy(cmdApdu.p_data, manageChannelCommand.data(), cmdApdu.len);
+
+  sestatus = SESTATUS_SUCCESS;
+
+  status = phNxpEse_SetEndPoint_Cntxt(1);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  status = phNxpEse_Transceive(&cmdApdu, &rspApdu);
+  if (status != ESESTATUS_SUCCESS) {
+    resApduBuff.channelNumber = 0xff;
+    if (NULL != rspApdu.p_data && rspApdu.len > 0) {
+      if ((rspApdu.p_data[0] == 0x64 && rspApdu.p_data[1] == 0xFF)) {
+        sestatus = ISecureElement::IOERROR;
+      }
+    }
+    if (sestatus != ISecureElement::IOERROR) {
+      sestatus = ISecureElement::FAILED;
+    }
+  } else if (rspApdu.p_data[rspApdu.len - 2] == 0x6A &&
+             rspApdu.p_data[rspApdu.len - 1] == 0x81) {
+    resApduBuff.channelNumber = 0xff;
+    sestatus = ISecureElement::CHANNEL_NOT_AVAILABLE;
+  } else if (rspApdu.p_data[rspApdu.len - 2] == 0x90 &&
+             rspApdu.p_data[rspApdu.len - 1] == 0x00) {
+    resApduBuff.channelNumber = rspApdu.p_data[0];
+    mOpenedchannelCount++;
+    mOpenedChannels[resApduBuff.channelNumber] = true;
+    sestatus = SESTATUS_SUCCESS;
+  } else if (((rspApdu.p_data[rspApdu.len - 2] == 0x6E) ||
+              (rspApdu.p_data[rspApdu.len - 2] == 0x6D)) &&
+             rspApdu.p_data[rspApdu.len - 1] == 0x00) {
+    sestatus = ISecureElement::UNSUPPORTED_OPERATION;
+  }
+
+  /*Free the allocations*/
+  phNxpEse_free(cmdApdu.p_data);
+  phNxpEse_free(rspApdu.p_data);
+
+  if (sestatus != SESTATUS_SUCCESS) {
+    if (mOpenedchannelCount == 0) {
+      sestatus = seHalDeInit();
+      if (sestatus != SESTATUS_SUCCESS) {
+        LOG(INFO) << "seDeInit Failed";
+      }
+    }
+    /*If manageChannel is failed in any of above cases
+    send the callback and return*/
+    status = phNxpEse_ResetEndPoint_Cntxt(1);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+    *_aidl_return = resApduBuff;
+    return ScopedAStatus::fromServiceSpecificError(sestatus);
+  }
+  LOG(INFO) << "openLogicalChannel Sending selectApdu";
+  sestatus = ISecureElement::IOERROR;
+  status = ESESTATUS_FAILED;
+
+  phNxpEse_7816_cpdu_t cpdu;
+  phNxpEse_7816_rpdu_t rpdu;
+  phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
+  phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
+
+  if ((resApduBuff.channelNumber > 0x03) &&
+      (resApduBuff.channelNumber < 0x14)) {
+    /* update CLA byte according to GP spec Table 11-12*/
+    cpdu.cla =
+        0x40 + (resApduBuff.channelNumber - 4); /* Class of instruction */
+  } else if ((resApduBuff.channelNumber > 0x00) &&
+             (resApduBuff.channelNumber < 0x04)) {
+    /* update CLA byte according to GP spec Table 11-11*/
+    cpdu.cla = resApduBuff.channelNumber; /* Class of instruction */
+  } else {
+    ALOGE("%s: Invalid Channel no: %02x", __func__, resApduBuff.channelNumber);
+    resApduBuff.channelNumber = 0xff;
+    *_aidl_return = resApduBuff;
+    return ScopedAStatus::fromServiceSpecificError(IOERROR);
+  }
+  cpdu.ins = 0xA4; /* Instruction code */
+  cpdu.p1 = 0x04;  /* Instruction parameter 1 */
+  cpdu.p2 = p2;    /* Instruction parameter 2 */
+  cpdu.lc = aid.size();
+  cpdu.le_type = 0x01;
+  cpdu.pdata = (uint8_t*)phNxpEse_memalloc(aid.size() * sizeof(uint8_t));
+  memcpy(cpdu.pdata, aid.data(), cpdu.lc);
+  cpdu.le = 256;
+
+  rpdu.len = 0x02;
+  rpdu.pdata = (uint8_t*)phNxpEse_memalloc(cpdu.le * sizeof(uint8_t));
+
+  status = phNxpEse_7816_Transceive(&cpdu, &rpdu);
+  if (status != ESESTATUS_SUCCESS) {
+    /*Transceive failed*/
+    if (rpdu.len > 0 && (rpdu.sw1 == 0x64 && rpdu.sw2 == 0xFF)) {
+      sestatus = ISecureElement::IOERROR;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  } else {
+    /*Status word to be passed as part of response
+    So include additional length*/
+    uint16_t responseLen = rpdu.len + 2;
+    resApduBuff.selectResponse.resize(responseLen);
+    memcpy(&resApduBuff.selectResponse[0], rpdu.pdata, rpdu.len);
+    resApduBuff.selectResponse[responseLen - 1] = rpdu.sw2;
+    resApduBuff.selectResponse[responseLen - 2] = rpdu.sw1;
+
+    /*Status is success*/
+    if (rpdu.sw1 == 0x90 && rpdu.sw2 == 0x00) {
+      sestatus = SESTATUS_SUCCESS;
+    }
+    /*AID provided doesn't match any applet on the secure element*/
+    else if (rpdu.sw1 == 0x6A && rpdu.sw2 == 0x82) {
+      sestatus = ISecureElement::NO_SUCH_ELEMENT_ERROR;
+    }
+    /*Operation provided by the P2 parameter is not permitted by the applet.*/
+    else if (rpdu.sw1 == 0x6A && rpdu.sw2 == 0x86) {
+      sestatus = ISecureElement::UNSUPPORTED_OPERATION;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  }
+  if (sestatus != SESTATUS_SUCCESS) {
+    int closeChannelStatus = internalCloseChannel(resApduBuff.channelNumber);
+    if (closeChannelStatus != SESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: closeChannel Failed" << __func__;
+    } else {
+      resApduBuff.channelNumber = 0xff;
+    }
+  }
+  status = phNxpEse_ResetEndPoint_Cntxt(1);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  *_aidl_return = resApduBuff;
+  phNxpEse_free(cpdu.pdata);
+  phNxpEse_free(rpdu.pdata);
+
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+ScopedAStatus VirtualISO::openBasicChannel(const std::vector<uint8_t>& aid,
+                                           int8_t p2,
+                                           std::vector<uint8_t>* _aidl_return) {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  phNxpEse_7816_cpdu_t cpdu;
+  phNxpEse_7816_rpdu_t rpdu;
+  std::vector<uint8_t> result;
+
+  LOG(INFO) << "Acquired the lock in VISO openBasicChannel";
+
+  if (!mIsEseInitialized) {
+    ESESTATUS status = seHalInit();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+      *_aidl_return = result;
+      return ScopedAStatus::fromServiceSpecificError(IOERROR);
+    }
+  }
+
+  if (mOpenedChannels.size() == 0x00) {
+    mMaxChannelCount = (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
+    mOpenedChannels.resize(mMaxChannelCount, false);
+  }
+
+  phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
+  phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
+
+  cpdu.cla = 0x00; /* Class of instruction */
+  cpdu.ins = 0xA4; /* Instruction code */
+  cpdu.p1 = 0x04;  /* Instruction parameter 1 */
+  cpdu.p2 = p2;    /* Instruction parameter 2 */
+  cpdu.lc = aid.size();
+  cpdu.le_type = 0x01;
+  cpdu.pdata = (uint8_t*)phNxpEse_memalloc(aid.size() * sizeof(uint8_t));
+  memcpy(cpdu.pdata, aid.data(), cpdu.lc);
+  cpdu.le = 256;
+
+  rpdu.len = 0x02;
+  rpdu.pdata = (uint8_t*)phNxpEse_memalloc(cpdu.le * sizeof(uint8_t));
+
+  status = phNxpEse_SetEndPoint_Cntxt(1);
+  status = phNxpEse_7816_Transceive(&cpdu, &rpdu);
+
+  int sestatus;
+  sestatus = SESTATUS_SUCCESS;
+
+  if (status != ESESTATUS_SUCCESS) {
+    /* Transceive failed */
+    if (rpdu.len > 0 && (rpdu.sw1 == 0x64 && rpdu.sw2 == 0xFF)) {
+      sestatus = ISecureElement::IOERROR;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  } else {
+    /*Status word to be passed as part of response
+    So include additional length*/
+    uint16_t responseLen = rpdu.len + 2;
+    result.resize(responseLen);
+    memcpy(&result[0], rpdu.pdata, rpdu.len);
+    result[responseLen - 1] = rpdu.sw2;
+    result[responseLen - 2] = rpdu.sw1;
+
+    /*Status is success*/
+    if ((rpdu.sw1 == 0x90) && (rpdu.sw2 == 0x00)) {
+      /*Set basic channel reference if it is not set */
+      if (!mOpenedChannels[0]) {
+        mOpenedChannels[0] = true;
+        mOpenedchannelCount++;
+      }
+
+      sestatus = SESTATUS_SUCCESS;
+    }
+    /*AID provided doesn't match any applet on the secure element*/
+    else if (rpdu.sw1 == 0x6A && rpdu.sw2 == 0x82) {
+      sestatus = ISecureElement::NO_SUCH_ELEMENT_ERROR;
+    }
+    /*Operation provided by the P2 parameter is not permitted by the applet.*/
+    else if (rpdu.sw1 == 0x6A && rpdu.sw2 == 0x86) {
+      sestatus = ISecureElement::UNSUPPORTED_OPERATION;
+    } else {
+      sestatus = ISecureElement::FAILED;
+    }
+  }
+  status = phNxpEse_ResetEndPoint_Cntxt(1);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+  }
+  if (sestatus != SESTATUS_SUCCESS) {
+    int closeChannelStatus = internalCloseChannel(DEFAULT_BASIC_CHANNEL);
+    if (closeChannelStatus != SESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: closeChannel Failed" << __func__;
+    }
+  }
+  *_aidl_return = result;
+  phNxpEse_free(cpdu.pdata);
+  phNxpEse_free(rpdu.pdata);
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+int VirtualISO::internalCloseChannel(uint8_t channelNumber) {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  int sestatus = ISecureElement::FAILED;
+  phNxpEse_7816_cpdu_t cpdu;
+  phNxpEse_7816_rpdu_t rpdu;
+
+  ALOGE("internalCloseChannel Enter");
+  ALOGI("mMaxChannelCount = %d, Closing Channel = %d", mMaxChannelCount,
+        channelNumber);
+  if ((int8_t)channelNumber < DEFAULT_BASIC_CHANNEL ||
+      channelNumber >= mMaxChannelCount) {
+    ALOGE("invalid channel!!! %d", channelNumber);
+  } else if (channelNumber > DEFAULT_BASIC_CHANNEL) {
+    phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
+    phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
+    cpdu.cla = channelNumber; /* Class of instruction */
+    // For Supplementary Channel update CLA byte according to GP
+    if ((channelNumber > 0x03) && (channelNumber < 0x14)) {
+      /* update CLA byte according to GP spec Table 11-12*/
+      cpdu.cla = 0x40 + (channelNumber - 4); /* Class of instruction */
+    }
+    cpdu.ins = 0x70;         /* Instruction code */
+    cpdu.p1 = 0x80;          /* Instruction parameter 1 */
+    cpdu.p2 = channelNumber; /* Instruction parameter 2 */
+    cpdu.lc = 0x00;
+    cpdu.le = 0x9000;
+    status = phNxpEse_SetEndPoint_Cntxt(1);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+    status = phNxpEse_7816_Transceive(&cpdu, &rpdu);
+
+    if (status == ESESTATUS_SUCCESS) {
+      if ((rpdu.sw1 == 0x90) && (rpdu.sw2 == 0x00)) {
+        sestatus = SESTATUS_SUCCESS;
+      }
+    }
+    status = phNxpEse_ResetEndPoint_Cntxt(1);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+    if (mOpenedChannels[channelNumber]) {
+      mOpenedChannels[channelNumber] = false;
+      mOpenedchannelCount--;
+    }
+  }
+  /*If there are no channels remaining close secureElement*/
+  if (mOpenedchannelCount == 0) {
+    sestatus = seHalDeInit();
+  } else {
+    sestatus = SESTATUS_SUCCESS;
+  }
+  return sestatus;
+}
+
+ScopedAStatus VirtualISO::closeChannel(int8_t channelNumber) {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  int sestatus = ISecureElement::FAILED;
+  phNxpEse_7816_cpdu_t cpdu;
+  phNxpEse_7816_rpdu_t rpdu;
+
+  LOG(INFO) << "Acquired the lock in VISO closeChannel";
+  if ((int8_t)channelNumber < DEFAULT_BASIC_CHANNEL ||
+      channelNumber >= mMaxChannelCount) {
+    ALOGE("invalid channel!!! %d", channelNumber);
+  } else if (channelNumber > DEFAULT_BASIC_CHANNEL) {
+    phNxpEse_memset(&cpdu, 0x00, sizeof(phNxpEse_7816_cpdu_t));
+    phNxpEse_memset(&rpdu, 0x00, sizeof(phNxpEse_7816_rpdu_t));
+    cpdu.cla = channelNumber; /* Class of instruction */
+    cpdu.ins = 0x70;          /* Instruction code */
+    cpdu.p1 = 0x80;           /* Instruction parameter 1 */
+    cpdu.p2 = channelNumber;  /* Instruction parameter 2 */
+    cpdu.lc = 0x00;
+    cpdu.le = 0x9000;
+    status = phNxpEse_SetEndPoint_Cntxt(1);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+    status = phNxpEse_7816_Transceive(&cpdu, &rpdu);
+
+    if (status == ESESTATUS_SUCCESS) {
+      if ((rpdu.sw1 == 0x90) && (rpdu.sw2 == 0x00)) {
+        sestatus = SESTATUS_SUCCESS;
+      }
+    }
+    status = phNxpEse_ResetEndPoint_Cntxt(1);
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    }
+    if (mOpenedChannels[channelNumber]) {
+      mOpenedChannels[channelNumber] = false;
+      mOpenedchannelCount--;
+    }
+  }
+
+  /*If there are no channels remaining close secureElement*/
+  if (mOpenedchannelCount == 0) {
+    sestatus = seHalDeInit();
+  } else {
+    sestatus = SESTATUS_SUCCESS;
+  }
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+ESESTATUS VirtualISO::seHalInit() {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
+  phNxpEse_initParams initParams;
+  memset(&initParams, 0x00, sizeof(phNxpEse_initParams));
+  initParams.initMode = ESE_MODE_NORMAL;
+  initParams.mediaType = ESE_PROTOCOL_MEDIA_SPI_APDU_GATE;
+
+  status = phNxpEse_open(initParams);
+  if (ESESTATUS_SUCCESS == status || ESESTATUS_BUSY == status) {
+    if (ESESTATUS_SUCCESS == phNxpEse_SetEndPoint_Cntxt(1) &&
+        ESESTATUS_SUCCESS == phNxpEse_init(initParams)) {
+      if (ESESTATUS_SUCCESS == phNxpEse_ResetEndPoint_Cntxt(1)) {
+        mIsEseInitialized = true;
+        LOG(INFO) << "VISO init complete!!!";
+        return ESESTATUS_SUCCESS;
+      }
+      deInitStatus = phNxpEse_deInit();
+    }
+    if (phNxpEse_close(deInitStatus) != ESESTATUS_SUCCESS) {
+      LOG(INFO) << "VISO close is not successful";
+    }
+    mIsEseInitialized = false;
+  }
+  return status;
+}
+int VirtualISO::seHalDeInit() {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  ESESTATUS deInitStatus = ESESTATUS_SUCCESS;
+  bool mIsDeInitDone = true;
+  int sestatus = ISecureElement::FAILED;
+  status = phNxpEse_SetEndPoint_Cntxt(1);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    mIsDeInitDone = false;
+  }
+  deInitStatus = phNxpEse_deInit();
+  if (ESESTATUS_SUCCESS != deInitStatus) mIsDeInitDone = false;
+  status = phNxpEse_ResetEndPoint_Cntxt(1);
+  if (status != ESESTATUS_SUCCESS) {
+    LOG(ERROR) << "phNxpEse_SetEndPoint_Cntxt failed!!!";
+    mIsDeInitDone = false;
+  }
+  status = phNxpEse_close(deInitStatus);
+  if (status == ESESTATUS_SUCCESS && mIsDeInitDone) {
+    sestatus = SESTATUS_SUCCESS;
+  } else {
+    LOG(ERROR) << "seHalDeInit: Failed";
+  }
+  // Clear all the flags as SPI driver is closed.
+  mIsEseInitialized = false;
+  for (uint8_t xx = 0; xx < mMaxChannelCount; xx++) {
+    mOpenedChannels[xx] = false;
+  }
+  mOpenedchannelCount = 0;
+  return sestatus;
+}
+
+ScopedAStatus VirtualISO::reset() {
+  ESESTATUS status = ESESTATUS_SUCCESS;
+  int sestatus = ISecureElement::FAILED;
+  LOG(ERROR) << "%s: Enter" << __func__;
+  if (!mIsEseInitialized) {
+    ESESTATUS status = seHalInit();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: seHalInit Failed!!!" << __func__;
+    }
+  }
+  if (status == ESESTATUS_SUCCESS) {
+    mCallback->onStateChange(false, "reset the SE");
+    status = phNxpEse_reset();
+    if (status != ESESTATUS_SUCCESS) {
+      LOG(ERROR) << "%s: SecureElement reset failed!!" << __func__;
+    } else {
+      sestatus = SESTATUS_SUCCESS;
+      if (mOpenedChannels.size() == 0x00) {
+        mMaxChannelCount =
+            (GET_CHIP_OS_VERSION() > OS_VERSION_6_2) ? 0x0C : 0x04;
+        mOpenedChannels.resize(mMaxChannelCount, false);
+      }
+      for (uint8_t xx = 0; xx < mMaxChannelCount; xx++) {
+        mOpenedChannels[xx] = false;
+      }
+      mOpenedchannelCount = 0;
+      mCallback->onStateChange(true, "SE initialized");
+    }
+  }
+  LOG(ERROR) << "%s: Exit" << __func__;
+  return sestatus == SESTATUS_SUCCESS
+             ? ndk::ScopedAStatus::ok()
+             : ndk::ScopedAStatus::fromServiceSpecificError(sestatus);
+}
+
+}  // namespace virtual_iso
+}  // namespace nxp
+}  // namespace vendor
+}  // namespace aidl
diff --git a/snxxx/aidl/VirtualISO.h b/snxxx/aidl/VirtualISO.h
new file mode 100644
index 0000000..fc8140a
--- /dev/null
+++ b/snxxx/aidl/VirtualISO.h
@@ -0,0 +1,86 @@
+/******************************************************************************
+ *
+ *  Copyright 2023 NXP
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+#pragma once
+
+#include <aidl/android/hardware/secure_element/BnSecureElement.h>
+#include <aidl/android/hardware/secure_element/ISecureElement.h>
+#include <aidl/android/hardware/secure_element/ISecureElementCallback.h>
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <hardware/hardware.h>
+#include <log/log.h>
+
+#include "phNxpEse_Api.h"
+
+#define SESTATUS_SUCCESS 0
+
+namespace aidl {
+namespace vendor {
+namespace nxp {
+namespace virtual_iso {
+
+using ::aidl::android::hardware::secure_element::ISecureElementCallback;
+using ::aidl::android::hardware::secure_element::LogicalChannelResponse;
+using ::ndk::ICInterface;
+using ndk::ScopedAStatus;
+
+#ifndef DEFAULT_BASIC_CHANNEL
+#define DEFAULT_BASIC_CHANNEL 0x00
+#endif
+
+struct VirtualISO
+    : public ::aidl::android::hardware::secure_element::BnSecureElement {
+  VirtualISO();
+  ::ndk::ScopedAStatus closeChannel(int8_t in_channelNumber) override;
+  ::ndk::ScopedAStatus getAtr(std::vector<uint8_t>* _aidl_return) override;
+  ::ndk::ScopedAStatus init(
+      const std::shared_ptr<
+          ::aidl::android::hardware::secure_element::ISecureElementCallback>&
+          in_clientCallback) override;
+  ::ndk::ScopedAStatus isCardPresent(bool* _aidl_return) override;
+  ::ndk::ScopedAStatus openBasicChannel(
+      const std::vector<uint8_t>& in_aid, int8_t in_p2,
+      std::vector<uint8_t>* _aidl_return) override;
+  ::ndk::ScopedAStatus openLogicalChannel(
+      const std::vector<uint8_t>& in_aid, int8_t in_p2,
+      ::aidl::android::hardware::secure_element::LogicalChannelResponse*
+          _aidl_return) override;
+  ::ndk::ScopedAStatus reset() override;
+  ::ndk::ScopedAStatus transmit(const std::vector<uint8_t>& in_data,
+                                std::vector<uint8_t>* _aidl_return) override;
+
+  static void NotifySeWaitExtension(phNxpEse_wtxState state);
+
+ private:
+  uint8_t mMaxChannelCount;
+  uint8_t mOpenedchannelCount = 0;
+  bool mIsEseInitialized = false;
+  static std::vector<bool> mOpenedChannels;
+
+  static std::shared_ptr<ISecureElementCallback> mCallback;
+
+  int seHalDeInit();
+  ESESTATUS seHalInit();
+  int internalCloseChannel(uint8_t channelNumber);
+};
+
+}  // namespace virtual_iso
+}  // namespace nxp
+}  // namespace vendor
+}  // namespace aidl
\ No newline at end of file
diff --git a/snxxx/aidl/secure_element-service-nxp.rc b/snxxx/aidl/secure_element-service-nxp.rc
new file mode 100644
index 0000000..0a64d39
--- /dev/null
+++ b/snxxx/aidl/secure_element-service-nxp.rc
@@ -0,0 +1,4 @@
+service vendor.secure_element_hal_service /vendor/bin/hw/android.hardware.secure_element-service.nxp
+    class hal
+    user secure_element
+    group secure_element
diff --git a/snxxx/aidl/secure_element-service-nxp.xml b/snxxx/aidl/secure_element-service-nxp.xml
new file mode 100644
index 0000000..96ab2e7
--- /dev/null
+++ b/snxxx/aidl/secure_element-service-nxp.xml
@@ -0,0 +1,7 @@
+<manifest version="1.0" type="device">
+    <hal format="aidl">
+        <name>android.hardware.secure_element</name>
+        <version>1</version>
+        <fqname>ISecureElement/eSE1</fqname>
+    </hal>
+</manifest>
diff --git a/snxxx/ese-clients/inc/eSEClient.h b/snxxx/ese-clients/inc/eSEClient.h
index f8752f3..a017f60 100644
--- a/snxxx/ese-clients/inc/eSEClient.h
+++ b/snxxx/ese-clients/inc/eSEClient.h
@@ -1,6 +1,6 @@
 /*******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020, 2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,16 +16,13 @@
  *
  ******************************************************************************/
 
-#include <android/hardware/secure_element/1.0/ISecureElementHalCallback.h>
-
-#include "../../../secure_element_extns/inc/eSEClientIntf.h"
+#include "eSEClientIntf.h"
 #include "phNxpEse_Api.h"
 
 #ifndef ESE_UPDATE_2_H_
 #define ESE_UPDATE_2_H_
 
 extern ese_update_state_t ese_update;
-using ::android::hardware::secure_element::V1_0::ISecureElementHalCallback;
 
 void checkEseClientUpdate();
 
diff --git a/snxxx/ese-clients/src/eSEClient.cpp b/snxxx/ese-clients/src/eSEClient.cpp
index 1ee1e8c..2498027 100644
--- a/snxxx/ese-clients/src/eSEClient.cpp
+++ b/snxxx/ese-clients/src/eSEClient.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020, 2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 #include <IChannel.h>
 #include <JcDnld.h>
 #include <LsClient.h>
+#include <aidl/vendor/nxp/nxpnfc_aidl/INxpNfc.h>
 #include <dirent.h>
 #include <ese_config.h>
 #include <log/log.h>
@@ -41,8 +42,14 @@
 using android::hardware::hidl_vec;
 using android::hardware::Void;
 using vendor::nxp::nxpese::V1_0::implementation::NxpEse;
-using vendor::nxp::nxpnfc::V2_0::INxpNfc;
+using INxpNfc = vendor::nxp::nxpnfc::V2_0::INxpNfc;
+using INxpNfcAidl = ::aidl::vendor::nxp::nxpnfc_aidl::INxpNfc;
+
+std::string NXPNFC_AIDL_HAL_SERVICE_NAME =
+    "vendor.nxp.nxpnfc_aidl.INxpNfc/default";
+
 sp<INxpNfc> mHalNxpNfc = nullptr;
+std::shared_ptr<INxpNfcAidl> mAidlHalNxpNfc = nullptr;
 
 void seteSEClientState(uint8_t state);
 
@@ -102,7 +109,7 @@
 ** Function:        checkEseClientUpdate
 **
 ** Description:     Check the initial condition
-                    and interafce for eSE Client update for LS and JCOP download
+                    and interface for eSE Client update for LS and JCOP download
 **
 ** Returns:         SUCCESS of ok
 **
@@ -156,7 +163,6 @@
 **
 *******************************************************************************/
 void eSEClientUpdate_Thread() {
-  SESTATUS status = SESTATUS_FAILED;
   pthread_t thread;
   pthread_attr_t attr;
   pthread_attr_init(&attr);
@@ -164,9 +170,7 @@
   if (pthread_create(&thread, &attr, &eSEClientUpdate_ThreadHandler, NULL) !=
       0) {
     ALOGD("Thread creation failed");
-    status = SESTATUS_FAILED;
   } else {
-    status = SESTATUS_SUCCESS;
     ALOGD("Thread creation success");
   }
   pthread_attr_destroy(&attr);
@@ -181,16 +185,13 @@
 **
 *******************************************************************************/
 void eSEClientUpdate_SE_Thread() {
-  SESTATUS status = SESTATUS_FAILED;
   pthread_t thread;
   pthread_attr_t attr;
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
   if (pthread_create(&thread, &attr, &eSEUpdate_SE_SeqHandler, NULL) != 0) {
     ALOGD("Thread creation failed");
-    status = SESTATUS_FAILED;
   } else {
-    status = SESTATUS_SUCCESS;
     ALOGD("Thread creation success");
   }
   pthread_attr_destroy(&attr);
@@ -225,25 +226,41 @@
   int cnt = 0;
 
   ALOGD("%s Enter\n", __func__);
-  while (((mHalNxpNfc == nullptr) && (cnt < 3))) {
+  if (mAidlHalNxpNfc == nullptr) {
+    do {
+      ::ndk::SpAIBinder binder(
+          AServiceManager_checkService(NXPNFC_AIDL_HAL_SERVICE_NAME.c_str()));
+      mAidlHalNxpNfc = INxpNfcAidl::fromBinder(binder);
+      if (!mAidlHalNxpNfc) {
+        usleep(100 * 1000);
+        cnt++;
+      }
+    } while (((mAidlHalNxpNfc == nullptr) && (cnt < 3)));
+  }
+
+  if (mAidlHalNxpNfc) {
+    ALOGD("Boot Time Update not supported for mAidlHalNxpNfc.");
+    ALOGD("%s Exit\n", __func__);
+    pthread_exit(NULL);
+    return NULL;
+  } else {
     mHalNxpNfc = INxpNfc::tryGetService();
     if (mHalNxpNfc == nullptr) ALOGD(": Failed to retrieve the NXP NFC HAL!");
     if (mHalNxpNfc != nullptr) {
       ALOGD("INxpNfc::getService() returned %p (%s)", mHalNxpNfc.get(),
             (mHalNxpNfc->isRemote() ? "remote" : "local"));
     }
-    usleep(100 * 1000);
-    cnt++;
-  }
 
-  if (mHalNxpNfc != nullptr) {
-    if (!se_intf.isJcopUpdateRequired && mHalNxpNfc->isJcopUpdateRequired()) {
-      se_intf.isJcopUpdateRequired = true;
-      ALOGD(" se_intf.isJcopUpdateRequired = %d", se_intf.isJcopUpdateRequired);
-    }
-    if (!se_intf.isLSUpdateRequired && mHalNxpNfc->isLsUpdateRequired()) {
-      se_intf.isLSUpdateRequired = true;
-      ALOGD("se_intf.isLSUpdateRequired = %d", se_intf.isLSUpdateRequired);
+    if (mHalNxpNfc != nullptr) {
+      if (!se_intf.isJcopUpdateRequired && mHalNxpNfc->isJcopUpdateRequired()) {
+        se_intf.isJcopUpdateRequired = true;
+        ALOGD(" se_intf.isJcopUpdateRequired = %d",
+              se_intf.isJcopUpdateRequired);
+      }
+      if (!se_intf.isLSUpdateRequired && mHalNxpNfc->isLsUpdateRequired()) {
+        se_intf.isLSUpdateRequired = true;
+        ALOGD("se_intf.isLSUpdateRequired = %d", se_intf.isLSUpdateRequired);
+      }
     }
   }
 
diff --git a/snxxx/extns/impl/NxpEse.cpp b/snxxx/extns/impl/NxpEse.cpp
index 370ce51..9970db6 100755
--- a/snxxx/extns/impl/NxpEse.cpp
+++ b/snxxx/extns/impl/NxpEse.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright (C) 2018-2021 NXP Semiconductors
+ *  Copyright 2018-2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 #endif
 #include <android-base/logging.h>
 #include <android-base/stringprintf.h>
+#include <memunreachable/memunreachable.h>
 
 #include "phNxpEse_Api.h"
 
@@ -217,6 +218,12 @@
 }
 
 // Methods from ::android::hidl::base::V1_0::IBase follow.
+Return<void> NxpEse::debug(const hidl_handle& /* fd */,
+                           const hidl_vec<hidl_string>& /* options */) {
+  LOG(INFO) << "\n SecureElement-NxpEse HAL MemoryLeak Info = \n"
+            << ::android::GetUnreachableMemoryString(true, 10000).c_str();
+  return Void();
+}
 
 }  // namespace implementation
 }  // namespace V1_0
diff --git a/snxxx/extns/impl/NxpEse.h b/snxxx/extns/impl/NxpEse.h
index 8c4ec5f..02e2302 100755
--- a/snxxx/extns/impl/NxpEse.h
+++ b/snxxx/extns/impl/NxpEse.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright (C) 2018-2019 NXP Semiconductors
+ *  Copyright 2018-2019,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -18,13 +18,21 @@
 #ifndef VENDOR_NXP_NXPNFC_V1_0_NXPNFC_H
 #define VENDOR_NXP_NXPNFC_V1_0_NXPNFC_H
 
+#include <android/binder_auto_utils.h>
+#include <android/binder_enums.h>
+#include <android/binder_ibinder.h>
+#include <android/binder_interface_utils.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
 #include <android/hardware/secure_element/1.0/ISecureElementHalCallback.h>
 #include <android/hardware/secure_element/1.1/ISecureElement.h>
 #include <android/hardware/secure_element/1.1/ISecureElementHalCallback.h>
+#include <binder/IServiceManager.h>
 #include <hardware/hardware.h>
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
 #include <vendor/nxp/nxpese/1.0/INxpEse.h>
+
 #include "hal_nxpese.h"
 namespace vendor {
 namespace nxp {
@@ -34,6 +42,7 @@
 
 using ::android::sp;
 using ::android::hardware::hidl_array;
+using android::hardware::hidl_handle;
 using ::android::hardware::hidl_memory;
 using ::android::hardware::hidl_string;
 using ::android::hardware::hidl_vec;
@@ -44,6 +53,10 @@
 using ::android::hidl::base::V1_0::IBase;
 using ::vendor::nxp::nxpese::V1_0::INxpEse;
 struct NxpEse : public INxpEse {
+  // Methods from ::android::hidl::base::V1_0::IBase follow.
+  Return<void> debug(const hidl_handle& handle,
+                     const hidl_vec<hidl_string>& options) override;
+
   Return<void> ioctl(uint64_t ioctlType, const hidl_vec<uint8_t>& inOutData,
                      ioctl_cb _hidl_cb) override;
   static Return<void> setSeCallBack(
diff --git a/snxxx/libese-spi/Android.bp b/snxxx/libese-spi/Android.bp
index 4563037..c45dd01 100755
--- a/snxxx/libese-spi/Android.bp
+++ b/snxxx/libese-spi/Android.bp
@@ -21,6 +21,7 @@
         "p73/pal/phNxpEsePal.cpp",
         "p73/pal/EseTransportFactory.cpp",
         "p73/pal/spi/EseSpiTransport.cpp",
+        "p73/pal/NxpTimer.cpp",
         "p73/spm/phNxpEse_Spm.cpp",
         "p73/utils/ese_config.cpp",
         "p73/utils/config.cpp",
@@ -43,8 +44,10 @@
         "src/include",
     ],
     include_dirs: [
+        "hardware/nxp/nfc/snxxx/extns/impl/nxpnfc/aidl",
         "hardware/nxp/nfc/snxxx/extns/impl/nxpnfc/2.0",
         "hardware/nxp/secure_element/snxxx/extns/impl",
+        "hardware/nxp/secure_element/snxxx/ese-clients/inc"
 ],
 
     cflags: [
@@ -69,11 +72,14 @@
         "libhardware",
         "libhidlbase",
         "libutils",
+        "libbinder",
+        "libbinder_ndk",
         "liblog",
         "libbase",
         "libchrome",
         "vendor.nxp.nxpese@1.0",
         "vendor.nxp.nxpnfc@2.0",
+        "vendor.nxp.nxpnfc_aidl-V1-ndk",
     ],
 
     product_variables: {
diff --git a/snxxx/libese-spi/common/include/phNxpEseFeatures.h b/snxxx/libese-spi/common/include/phNxpEseFeatures.h
index f6fef6c..af8f491 100644
--- a/snxxx/libese-spi/common/include/phNxpEseFeatures.h
+++ b/snxxx/libese-spi/common/include/phNxpEseFeatures.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020, 2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -38,11 +38,12 @@
   OS_VERSION_5_2 = 3,
   OS_VERSION_5_2_2 = 4,
   OS_VERSION_6_2 = 5,
+  OS_VERSION_6_3 = 6,
   INVALID_OS_VERSION = 0xFF,
 } phNxpEse_OsVersion_t;
 
 extern phNxpEse_OsVersion_t phNxpEse_getOsVersion();
-extern bool ese_debug_enabled;
+
 #define GET_CHIP_OS_VERSION() phNxpEse_getOsVersion()
 
 #endif /* end of #ifndef NXP_ESE_FEATURES_H */
diff --git a/snxxx/libese-spi/p73/inc/phNxpEse_Api.h b/snxxx/libese-spi/p73/inc/phNxpEse_Api.h
index fc9655d..7d720db 100755
--- a/snxxx/libese-spi/p73/inc/phNxpEse_Api.h
+++ b/snxxx/libese-spi/p73/inc/phNxpEse_Api.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2021,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -99,11 +99,6 @@
  */
 #define ESELIB_MW_VERSION_MIN (0x04)
 
-/*!
- * \brief eSE debugging log Level
- */
-extern bool ese_debug_enabled;
-
 /**
  * \ingroup spi_libese
  *
@@ -455,5 +450,18 @@
  *
  */
 void phNxpEse_setWtxCountLimit(unsigned long int wtxCount);
+
+/**
+ * \ingroup spi_libese
+ * \brief This function returns whether priority channel enabled or
+ *  not
+ *
+ * \param[in] void
+ *
+ * \retval uint8_t - Priority Access enabled(1)/disabled(0).
+ *
+ */
+bool phNxpEse_isPriorityAccessEnabled(void);
+
 /** @} */
 #endif /* _PHNXPSPILIB_API_H_ */
diff --git a/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.cpp b/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.cpp
index 1267c07..87af666 100755
--- a/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.cpp
+++ b/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2019 NXP
+ *  Copyright 2018-2019,2022-2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
  *
  ******************************************************************************/
 #define LOG_TAG "NxpEseHal"
+#include <ese_logs.h>
 #include <log/log.h>
 #include <phNxpEseDataMgr.h>
 #include <phNxpEsePal.h>
@@ -53,28 +54,27 @@
           total_len = 0;
           status = ESESTATUS_SUCCESS;
         } else {
-          ALOGD_IF(ese_debug_enabled,
-                   "%s Mismatch of len total_data_len %d total_len %d",
-                   __FUNCTION__, total_data_len, total_len);
+          NXP_LOG_ESE_D("%s Mismatch of len total_data_len %d total_len %d",
+                        __FUNCTION__, total_data_len, total_len);
           phNxpEse_free(pbuff);
         }
       } else {
-        ALOGE("%s phNxpEse_GetDataFromList failed", __FUNCTION__);
+        NXP_LOG_ESE_E("%s phNxpEse_GetDataFromList failed", __FUNCTION__);
         phNxpEse_free(pbuff);
       }
     } else {
-      ALOGE("%s Error in malloc ", __FUNCTION__);
+      NXP_LOG_ESE_E("%s Error in malloc ", __FUNCTION__);
       status = ESESTATUS_NOT_ENOUGH_MEMORY;
     }
   } else {
-    ALOGD_IF(ese_debug_enabled, "%s total_len = %d", __FUNCTION__, total_len);
+    NXP_LOG_ESE_D("%s total_len = %d", __FUNCTION__, total_len);
   }
 
   if (ESESTATUS_SUCCESS != status) {
     *pbuffer = NULL;
     *data_len = 0;
   }
-  ALOGD_IF(ese_debug_enabled, "%s exit status = %d", __FUNCTION__, status);
+  NXP_LOG_ESE_D("%s exit status = %d", __FUNCTION__, status);
   return status;
 }
 
@@ -92,7 +92,8 @@
   newNode = (phNxpEse_sCoreRecvBuff_List_t*)phNxpEse_memalloc(
       sizeof(phNxpEse_sCoreRecvBuff_List_t));
   if (newNode == NULL) {
-    ALOGE("%s Error in malloc ", __FUNCTION__);
+    NXP_LOG_ESE_E("%s Error in malloc ", __FUNCTION__);
+    phNxpEse_FlushData();
     return ESESTATUS_NOT_ENOUGH_MEMORY;
   }
   newNode->pNext = NULL;
@@ -120,7 +121,7 @@
 static ESESTATUS phNxpEse_GetDataFromList(uint32_t* data_len, uint8_t* pbuff) {
   phNxpEse_sCoreRecvBuff_List_t* new_node;
   uint32_t offset = 0;
-  ALOGD_IF(ese_debug_enabled, "%s Enter ", __FUNCTION__);
+  NXP_LOG_ESE_D("%s Enter ", __FUNCTION__);
   if (head == NULL || pbuff == NULL) {
     return ESESTATUS_FAILED;
   }
@@ -133,7 +134,7 @@
     new_node = new_node->pNext;
   }
   *data_len = offset;
-  ALOGD_IF(ese_debug_enabled, "%s Exit ", __FUNCTION__);
+  NXP_LOG_ESE_D("%s Exit ", __FUNCTION__);
   return ESESTATUS_SUCCESS;
 }
 
@@ -163,3 +164,26 @@
   head = NULL;
   return status;
 }
+
+/******************************************************************************
+ * Function         phNxpEse_FlushData
+ *
+ * Description      This function flushes the data from the data list
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void phNxpEse_FlushData() {
+  phNxpEse_data pRes;
+  phNxpEse_memset(&pRes, 0x00, sizeof(phNxpEse_data));
+
+  /* read if any residual data is there */
+  if ((total_len > 0) &&
+      (ESESTATUS_SUCCESS == phNxpEse_GetData(&pRes.len, &pRes.p_data))) {
+    NXP_LOG_ESE_D("%s Flushed data DataLen = %d", __FUNCTION__, pRes.len);
+  }
+  if (pRes.p_data != NULL) {
+    phNxpEse_free(pRes.p_data);
+    pRes.p_data = NULL;
+  }
+}
diff --git a/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.h b/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.h
index 77fea80..281e4d1 100644
--- a/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.h
+++ b/snxxx/libese-spi/p73/lib/phNxpEseDataMgr.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2019 NXP
+ *  Copyright 2018-2019,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -44,5 +44,6 @@
 
 ESESTATUS phNxpEse_GetData(uint32_t* data_len, uint8_t** pbuff);
 ESESTATUS phNxpEse_StoreDatainList(uint32_t data_len, uint8_t* pbuff);
+void phNxpEse_FlushData();
 
 #endif /* PHNXPESE_RECVMGR_H */
diff --git a/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.cpp b/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.cpp
old mode 100755
new mode 100644
index d6df6da..5a3d01d
--- a/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.cpp
+++ b/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,9 +16,12 @@
  *
  ******************************************************************************/
 #define LOG_TAG "NxpEseHal"
+#include <ese_logs.h>
 #include <log/log.h>
 #include <phNxpEseProto7816_3.h>
 
+#include "phNxpEsePal.h"
+
 /**
  * \addtogroup ISO7816-3_protocol_lib
  *
@@ -120,8 +123,9 @@
 /**
  * \ingroup ISO7816-3_protocol_lib
  * \brief      This internal function is called to push I-frame data to internal
- *structure. \param[in]    p_data -raw data buffer \param[in]    data_len -data
- *length
+ *structure.
+ *\param[in]    p_data -raw data buffer
+ *\param[in]    data_len -data length
  *
  */
 static ESESTATUS phNxpEseProto7816_SaveIframeData(uint8_t* p_data,
@@ -130,7 +134,7 @@
 /**
  * \ingroup ISO7816-3_protocol_lib
  * \brief      This internal function is called to do reset the recovery
- *pareameters
+ *parameters
  *
  */
 static ESESTATUS phNxpEseProto7816_ResetRecovery(void);
@@ -188,7 +192,7 @@
 /**
  * \ingroup ISO7816-3_protocol_lib
  * \brief      This internal function is used to
- *                  1. Send propreitary S-Frame command for resynch
+ *                  1. Send proprietary S-Frame command for re-sync
  *T=1 sequence at worker
  *
  */
@@ -196,13 +200,6 @@
 
 /**
  * \ingroup ISO7816-3_protocol_lib
- * \brief       This function is used to reset the 7816 protocol stack
- *
- */
-static ESESTATUS phNxpEseProto7816_ResetProtoParams(void);
-
-/**
- * \ingroup ISO7816-3_protocol_lib
  * \brief       This function is used to send the spi hard reset command
  *
  */
@@ -271,6 +268,13 @@
  */
 static phNxpEseProto7816_t phNxpEseProto7816_ptr[MAX_END_POINTS];
 
+/*!
+ * \brief  Prints  time taken(in microseconds) in cmd transfer and response
+ *         receive
+ */
+static void printCmdRspTimeDuration(ESESTATUS status, uint32_t cmdLen,
+                                    uint32_t respLen);
+
 /******************************************************************************
  * Function         phNxpEseProto7816_SendRawFrame
  *
@@ -282,15 +286,14 @@
 static ESESTATUS phNxpEseProto7816_SendRawFrame(uint32_t data_len,
                                                 uint8_t* p_data) {
   ESESTATUS status = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   status = phNxpEse_WriteFrame(data_len, p_data);
   if (ESESTATUS_SUCCESS != status) {
-    ALOGE("%s Error phNxpEse_WriteFrame\n", __FUNCTION__);
+    NXP_LOG_ESE_E("%s Error phNxpEse_WriteFrame\n", __FUNCTION__);
   } else {
-    ALOGD_IF(ese_debug_enabled, "%s phNxpEse_WriteFrame Success \n",
-             __FUNCTION__);
+    NXP_LOG_ESE_D("%s phNxpEse_WriteFrame Success \n", __FUNCTION__);
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s with status %d", __FUNCTION__, status);
   return status;
 }
 
@@ -308,7 +311,8 @@
 
   status = phNxpEse_read(data_len, pp_data);
   if (ESESTATUS_SUCCESS != status) {
-    ALOGE("%s phNxpEse_read failed , status : 0x%x", __FUNCTION__, status);
+    NXP_LOG_ESE_E("%s phNxpEse_read failed , status : 0x%x", __FUNCTION__,
+                  status);
   }
   return status;
 }
@@ -324,11 +328,11 @@
 static uint8_t phNxpEseProto7816_ComputeLRC(unsigned char* p_buff,
                                             uint32_t offset, uint32_t length) {
   uint32_t LRC = 0, i = 0;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   for (i = offset; i < length; i++) {
     LRC = LRC ^ p_buff[i];
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return (uint8_t)LRC;
 }
 
@@ -346,23 +350,22 @@
   ESESTATUS status = ESESTATUS_SUCCESS;
   uint8_t calc_crc = 0;
   uint8_t recv_crc = 0;
-  ALOGD_IF(ese_debug_enabled, "Enter %s len %d", __FUNCTION__, data_len);
+  NXP_LOG_ESE_D("Enter %s len %d", __FUNCTION__, data_len);
   if (data_len > 0) {
     recv_crc = p_data[data_len - 1];
 
     /* calculate the CRC after excluding CRC  */
     calc_crc = phNxpEseProto7816_ComputeLRC(p_data, 1, (data_len - 1));
-    ALOGD_IF(ese_debug_enabled, "Received LRC:0x%x Calculated LRC:0x%x",
-             recv_crc, calc_crc);
+    NXP_LOG_ESE_D("Received LRC:0x%x Calculated LRC:0x%x", recv_crc, calc_crc);
     if (recv_crc != calc_crc) {
       status = ESESTATUS_FAILED;
-      ALOGE("%s LRC failed", __FUNCTION__);
+      NXP_LOG_ESE_E("%s LRC failed", __FUNCTION__);
     }
   } else {
     status = ESESTATUS_FAILED;
-    ALOGE("%s LRC failed length = 0", __FUNCTION__);
+    NXP_LOG_ESE_E("%s LRC failed length = 0", __FUNCTION__);
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -381,7 +384,7 @@
   uint8_t* p_framebuff = NULL;
   uint8_t pcb_byte = 0;
   uint8_t lenIFS = 0;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   sFrameInfo_t sframeData = sFrameData;
   /* This update is helpful in-case a R-NACK is transmitted from the MW */
   phNxpEseProto7816_3_Var.lastSentNonErrorframeType = SFRAME;
@@ -489,7 +492,7 @@
       pcb_byte |= ATR_REQ;
       break;
     default:
-      ALOGE("Invalid S-block");
+      NXP_LOG_ESE_E("Invalid S-block");
       break;
   }
   if (NULL != p_framebuff) {
@@ -499,7 +502,7 @@
 
     p_framebuff[frame_len - 1] =
         phNxpEseProto7816_ComputeLRC(p_framebuff, 0, (frame_len - 1));
-    ALOGD_IF(ese_debug_enabled, "S-Frame PCB: %x\n", p_framebuff[1]);
+    NXP_LOG_ESE_D("S-Frame PCB: %x\n", p_framebuff[1]);
     status = phNxpEseProto7816_SendRawFrame(frame_len, p_framebuff);
     phNxpEse_free(p_framebuff);
     /*After S-Frame Tx 1 ms sleep before Rx*/
@@ -508,9 +511,9 @@
       phNxpEse_Sleep(1 * 1000);
     }
   } else {
-    ALOGE("Invalid S-block or malloc for s-block failed");
+    NXP_LOG_ESE_E("Invalid S-block or malloc for s-block failed");
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -537,7 +540,7 @@
   recv_ack[1] |=
       ((phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdIframeInfo.seqNo ^ 1)
        << 4);
-  ALOGD_IF(ese_debug_enabled, "%s recv_ack[1]:0x%x", __FUNCTION__, recv_ack[1]);
+  NXP_LOG_ESE_D("%s recv_ack[1]:0x%x", __FUNCTION__, recv_ack[1]);
   recv_ack[3] =
       phNxpEseProto7816_ComputeLRC(recv_ack, 0x00, (sizeof(recv_ack) - 1));
   status = phNxpEseProto7816_SendRawFrame(sizeof(recv_ack), recv_ack);
@@ -558,9 +561,9 @@
   uint32_t frame_len = 0;
   uint8_t* p_framebuff = NULL;
   uint8_t pcb_byte = 0;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   if (0 == iFrameData.sendDataLen) {
-    ALOGE("I frame Len is 0, INVALID");
+    NXP_LOG_ESE_E("I frame Len is 0, INVALID");
     return ESESTATUS_FAILED;
   }
   /* This update is helpful in-case a R-NACK is transmitted from the MW */
@@ -570,7 +573,7 @@
 
   p_framebuff = (uint8_t*)phNxpEse_memalloc(frame_len * sizeof(uint8_t));
   if (NULL == p_framebuff) {
-    ALOGE("Heap allocation failed");
+    NXP_LOG_ESE_E("Heap allocation failed");
     return ESESTATUS_FAILED;
   }
 
@@ -613,9 +616,14 @@
       phNxpEseProto7816_ComputeLRC(p_framebuff, 0, (frame_len - 1));
 
   status = phNxpEseProto7816_SendRawFrame(frame_len, p_framebuff);
+  if (iFrameData.isChained == false) {
+    NXP_LOG_ESE_I("All Iframes are sent");
+    phPalEse_stopTimer(phPalEse_getTimer()->tx_timer);
 
+    phPalEse_startTimer(phPalEse_getTimer()->rx_timer);
+  }
   phNxpEse_free(p_framebuff);
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -630,7 +638,7 @@
  *
  ******************************************************************************/
 static ESESTATUS phNxpEseProto7816_SetFirstIframeContxt(void) {
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.dataOffset = 0;
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = IFRAME;
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.seqNo =
@@ -652,10 +660,11 @@
         phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.totalDataLen;
     phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.isChained = false;
   }
-  ALOGD_IF(ese_debug_enabled, "I-Frame Data Len: %d Seq. no:%d",
-           phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.sendDataLen,
-           phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.seqNo);
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D(
+      "I-Frame Data Len: %d Seq. no:%d",
+      phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.sendDataLen,
+      phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.seqNo);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return ESESTATUS_SUCCESS;
 }
 
@@ -670,7 +679,7 @@
  *
  ******************************************************************************/
 static ESESTATUS phNxpEseProto7816_SetNextIframeContxt(void) {
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   /* Expecting to reach here only after first of chained I-frame is sent and
    * before the last chained is sent */
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = IFRAME;
@@ -690,7 +699,7 @@
   if (phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo.totalDataLen >
       phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo
           .currentDataLenIFS) {
-    ALOGD_IF(ese_debug_enabled, "Process Chained Frame");
+    NXP_LOG_ESE_D("Process Chained Frame");
     phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.isChained = true;
     phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.sendDataLen =
         phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo
@@ -704,9 +713,10 @@
     phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.sendDataLen =
         phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo.totalDataLen;
   }
-  ALOGD_IF(ese_debug_enabled, "I-Frame Data Len: %d",
-           phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.sendDataLen);
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D(
+      "I-Frame Data Len: %d",
+      phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.sendDataLen);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return ESESTATUS_SUCCESS;
 }
 
@@ -714,23 +724,22 @@
  * Function         phNxpEseProto7816_ResetRecovery
  *
  * Description      This internal function is called to do reset the recovery
- *pareameters
+ *                  parameters
  *
  * Returns          On success return true or else false.
  *
  ******************************************************************************/
 static ESESTATUS phNxpEseProto7816_SaveIframeData(uint8_t* p_data,
                                                   uint32_t data_len) {
-  ESESTATUS status = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
-  ALOGD_IF(ese_debug_enabled, "Data[0]=0x%x len=%d Data[%d]=0x%x", p_data[0],
-           data_len, data_len - 1, p_data[data_len - 1]);
-  if (ESESTATUS_SUCCESS != phNxpEse_StoreDatainList(data_len, p_data)) {
-    ALOGE("%s - Error storing chained data in list", __FUNCTION__);
-  } else {
-    status = ESESTATUS_SUCCESS;
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Data[0]=0x%x len=%d Data[%d]=0x%x", p_data[0], data_len,
+                data_len - 1, p_data[data_len - 1]);
+  ESESTATUS status = phNxpEse_StoreDatainList(data_len, p_data);
+  if (ESESTATUS_SUCCESS != status) {
+    NXP_LOG_ESE_E("%s - Error storing chained data in list, status %d",
+                  __FUNCTION__, status);
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -738,7 +747,7 @@
  * Function         phNxpEseProto7816_ResetRecovery
  *
  * Description      This internal function is called to do reset the recovery
- *pareameters
+ *                  parameters
  *
  * Returns          On success return true or else false.
  *
@@ -768,9 +777,10 @@
         INTF_RESET_REQ;
     phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
         SEND_S_INTF_RST;
+    phNxpEseProto7816_3_Var.reset_type = RESET_TYPE_RECOVERY;
   } else { /* If recovery fails */
     phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState = IDLE_STATE;
-    ALOGE("%s Recovery failed", __FUNCTION__);
+    NXP_LOG_ESE_E("%s Recovery failed", __FUNCTION__);
   }
   return ESESTATUS_SUCCESS;
 }
@@ -821,14 +831,13 @@
   if (ifsd_data == phNxpEseProto7816_3_Var.currentIFSDSize) {
     phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.currentDataLenIFS =
         phNxpEseProto7816_3_Var.currentIFSDSize;
-    ALOGD_IF(ese_debug_enabled, "%s IFS adjustment: Max DataLen=%d \n",
-             __FUNCTION__,
-             phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo
-                 .currentDataLenIFS);
+    NXP_LOG_ESE_D("%s IFS adjustment: Max DataLen=%d \n", __FUNCTION__,
+                  phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo
+                      .currentDataLenIFS);
   } else {
-    ALOGE("%s ERROR IFS adjustment: Max DataLen=%d \n", __FUNCTION__,
-          phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo
-              .currentDataLenIFS);
+    NXP_LOG_ESE_E("%s ERROR IFS adjustment: Max DataLen=%d \n", __FUNCTION__,
+                  phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo
+                      .currentDataLenIFS);
   }
 }
 
@@ -858,60 +867,60 @@
                   &p_data[PH_PROPTO_7816_FRAME_LENGTH_OFFSET],
                   sizeof(phNxpEseProto7816_ATR_Info_t));
 
-  ALOGD_IF(
-      ese_debug_enabled,
+  NXP_LOG_ESE_D(
       "%s Max DataLen=%d Current DataLen=%d Default DataLen=%d \n",
       __FUNCTION__,
       phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.maxDataLenIFSC,
       phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.currentDataLenIFS,
       phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo
           .defaultDataLenIFSC);
-  ALOGD_IF(ese_debug_enabled, "ATR Data Follows");
-  ALOGD_IF(ese_debug_enabled, "======================");
-  ALOGD_IF(ese_debug_enabled, "ATR Length = %d",
-           phNxpEseProto7816_3_Var.atrInfo.len);
-  ALOGD_IF(ese_debug_enabled, "Vendor ID = 0x%.2x%.2x%.2x%.2x%.2x",
-           phNxpEseProto7816_3_Var.atrInfo.vendorID[0],
-           phNxpEseProto7816_3_Var.atrInfo.vendorID[1],
-           phNxpEseProto7816_3_Var.atrInfo.vendorID[2],
-           phNxpEseProto7816_3_Var.atrInfo.vendorID[3],
-           phNxpEseProto7816_3_Var.atrInfo.vendorID[4]);
-  ALOGD_IF(ese_debug_enabled, "DLL-IC = supports T%d",
-           phNxpEseProto7816_3_Var.atrInfo.dll_IC);
-  ALOGD_IF(ese_debug_enabled, "BGT = %d ms",
-           (phNxpEseProto7816_3_Var.atrInfo.bgt[0] << 8) |
-               (phNxpEseProto7816_3_Var.atrInfo.bgt[1]));
-  ALOGD_IF(ese_debug_enabled, "BWT = %d ms",
-           phNxpEseProto7816_3_Var.atrInfo.bwt[0] << 8 |
-               phNxpEseProto7816_3_Var.atrInfo.bwt[1]);
-  ALOGD_IF(ese_debug_enabled, "Max supported frequency = %d Hz",
-           phNxpEseProto7816_3_Var.atrInfo.maxFreq[0] << 8 |
-               phNxpEseProto7816_3_Var.atrInfo.maxFreq[1]);
-  ALOGD_IF(ese_debug_enabled, "Checksum LRC(0)/CRC(1) supports = 0x%x",
-           phNxpEseProto7816_3_Var.atrInfo.checksum);
-  ALOGD_IF(ese_debug_enabled, "DefaultIFSC = %d bytes",
-           phNxpEseProto7816_3_Var.atrInfo.defaultIFSC);
-  ALOGD_IF(ese_debug_enabled, "Max IFSC = %d bytes",
-           phNxpEseProto7816_3_Var.atrInfo.maxIFSC[0] << 8 |
-               phNxpEseProto7816_3_Var.atrInfo.maxIFSC[1]);
-  ALOGD_IF(ese_debug_enabled, "Capabilities = 0x%x",
-           phNxpEseProto7816_3_Var.atrInfo.capabilities[0] << 8 |
-               phNxpEseProto7816_3_Var.atrInfo.capabilities[1]);
+  NXP_LOG_ESE_D("ATR Data Follows");
+  NXP_LOG_ESE_D("======================");
+  NXP_LOG_ESE_D("ATR Length = %d", phNxpEseProto7816_3_Var.atrInfo.len);
+  NXP_LOG_ESE_D("Vendor ID = 0x%.2x%.2x%.2x%.2x%.2x",
+                phNxpEseProto7816_3_Var.atrInfo.vendorID[0],
+                phNxpEseProto7816_3_Var.atrInfo.vendorID[1],
+                phNxpEseProto7816_3_Var.atrInfo.vendorID[2],
+                phNxpEseProto7816_3_Var.atrInfo.vendorID[3],
+                phNxpEseProto7816_3_Var.atrInfo.vendorID[4]);
+  NXP_LOG_ESE_D("DLL-IC = supports T%d",
+                phNxpEseProto7816_3_Var.atrInfo.dll_IC);
+  NXP_LOG_ESE_D("BGT = %d ms", (phNxpEseProto7816_3_Var.atrInfo.bgt[0] << 8) |
+                                   (phNxpEseProto7816_3_Var.atrInfo.bgt[1]));
+  NXP_LOG_ESE_D("BWT = %d ms", phNxpEseProto7816_3_Var.atrInfo.bwt[0] << 8 |
+                                   phNxpEseProto7816_3_Var.atrInfo.bwt[1]);
+  NXP_LOG_ESE_D("Max supported frequency = %d Hz",
+                phNxpEseProto7816_3_Var.atrInfo.maxFreq[0] << 8 |
+                    phNxpEseProto7816_3_Var.atrInfo.maxFreq[1]);
+  NXP_LOG_ESE_D("Checksum LRC(0)/CRC(1) supports = 0x%x",
+                phNxpEseProto7816_3_Var.atrInfo.checksum);
+  NXP_LOG_ESE_D("DefaultIFSC = %d bytes",
+                phNxpEseProto7816_3_Var.atrInfo.defaultIFSC);
+  NXP_LOG_ESE_D("Max IFSC = %d bytes",
+                phNxpEseProto7816_3_Var.atrInfo.maxIFSC[0] << 8 |
+                    phNxpEseProto7816_3_Var.atrInfo.maxIFSC[1]);
+  NXP_LOG_ESE_D("Capabilities = 0x%x",
+                phNxpEseProto7816_3_Var.atrInfo.capabilities[0] << 8 |
+                    phNxpEseProto7816_3_Var.atrInfo.capabilities[1]);
 
   if (phNxpEseProto7816_3_Var.atrInfo.vendorID[4] >= PH_SE_OS_VERSION_11) {
     phNxpEse_memcpy(&phNxpEseProto7816_3_Var.extndAtrInfo.channelNo,
                     &p_data[PH_PROPTO_7816_FRAME_LENGTH_OFFSET] +
                         sizeof(phNxpEseProto7816_ATR_Info_t),
                     sizeof(phNxpEseProto7816_ATR_Info2_t));
-    ALOGD_IF(ese_debug_enabled, "Channel Number = 0x%x",
-             phNxpEseProto7816_3_Var.extndAtrInfo.channelNo);
-    ALOGD_IF(
-        ese_debug_enabled, "OS Type = %s",
+    NXP_LOG_ESE_D("Channel Number = 0x%x",
+                  phNxpEseProto7816_3_Var.extndAtrInfo.channelNo);
+    NXP_LOG_ESE_D(
+        "OS Type = %s",
         (phNxpEseProto7816_3_Var.extndAtrInfo.osType == 0x01 ? "JCOP Mode"
                                                              : "OSU Mode"));
   }
   if (phNxpEseProto7816_3_Var.atrInfo.vendorID[PH_PROTO_ATR_RSP_VENDOR_ID_LEN -
-                                               1] >= PH_SE_OS_VERSION_20) {
+                                               1] >= PH_SE_OS_VERSION_21) {
+    phNxpEse_setOsVersion(OS_VERSION_6_3);
+  } else if (phNxpEseProto7816_3_Var.atrInfo
+                 .vendorID[PH_PROTO_ATR_RSP_VENDOR_ID_LEN - 1] >=
+             PH_SE_OS_VERSION_20) {
     phNxpEse_setOsVersion(OS_VERSION_6_2);
   } else if (phNxpEseProto7816_3_Var.atrInfo
                  .vendorID[PH_PROTO_ATR_RSP_VENDOR_ID_LEN - 1] >=
@@ -927,7 +936,7 @@
     phNxpEse_setOsVersion(OS_VERSION_5_1);
   }
 
-  ALOGD_IF(ese_debug_enabled, "======================");
+  NXP_LOG_ESE_D("======================");
 }
 
 /******************************************************************************
@@ -948,8 +957,8 @@
   while (maxSframeLen > frameOffset) {
     frameOffset += 1; /* To get the Type (TLV) */
     dataType = p_data[frameOffset];
-    ALOGD_IF(ese_debug_enabled, "%s frameoffset=%d value=0x%x\n", __FUNCTION__,
-             frameOffset, p_data[frameOffset]);
+    NXP_LOG_ESE_D("%s frameoffset=%d value=0x%x\n", __FUNCTION__, frameOffset,
+                  p_data[frameOffset]);
     switch (dataType) /* Type (TLV) */
     {
       case PH_PROPTO_7816_SFRAME_TIMER1:
@@ -973,10 +982,10 @@
         break;
     }
   }
-  ALOGD_IF(ese_debug_enabled, "secure timer t1 = 0x%x t2 = 0x%x t3 = 0x%x",
-           phNxpEseProto7816_3_Var.secureTimerParams.secureTimer1,
-           phNxpEseProto7816_3_Var.secureTimerParams.secureTimer2,
-           phNxpEseProto7816_3_Var.secureTimerParams.secureTimer3);
+  NXP_LOG_ESE_D("secure timer t1 = 0x%x t2 = 0x%x t3 = 0x%x",
+                phNxpEseProto7816_3_Var.secureTimerParams.secureTimer1,
+                phNxpEseProto7816_3_Var.secureTimerParams.secureTimer2,
+                phNxpEseProto7816_3_Var.secureTimerParams.secureTimer3);
   return;
 }
 
@@ -990,7 +999,7 @@
                     3. If the received frame is R-frame,
                        3.1 R-ACK with expected seq. number: Send the next
  chained I-frame
-                       3.2 R-ACK with different sequence number: Sebd the R-Nack
+                       3.2 R-ACK with different sequence number: Send the R-Nack
                        3.3 R-NACK: Re-send the last frame
                     4. If the received frame is S-frame, send back the correct
  S-frame response.
@@ -1002,9 +1011,9 @@
   ESESTATUS status = ESESTATUS_SUCCESS;
   uint8_t pcb;
   phNxpEseProto7816_PCB_bits_t pcb_bits;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
-  ALOGD_IF(ese_debug_enabled, "Retry Counter = %d\n",
-           phNxpEseProto7816_3_Var.recoveryCounter);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Retry Counter = %d\n",
+                phNxpEseProto7816_3_Var.recoveryCounter);
   pcb = p_data[PH_PROPTO_7816_PCB_OFFSET];
   // memset(&phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.rcvPcbBits, 0x00,
   // sizeof(struct PCB_BITS));
@@ -1014,14 +1023,14 @@
   if (0x00 == pcb_bits.msb) /* I-FRAME decoded should come here */
   {
     if (!phNxpEseProto7816_ResendLastSFrameReq()) {
-      ALOGD_IF(ese_debug_enabled, "%s I-Frame Received", __FUNCTION__);
+      NXP_LOG_ESE_D("%s I-Frame Received", __FUNCTION__);
       phNxpEseProto7816_CheckAndNotifyWtx(WTX_END);
       phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdFrameType = IFRAME;
       if (phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdIframeInfo.seqNo !=
           pcb_bits.bit7)  //   != pcb_bits->bit7)
       {
-        ALOGD_IF(ese_debug_enabled, "%s I-Frame lastRcvdIframeInfo.seqNo:0x%x",
-                 __FUNCTION__, pcb_bits.bit7);
+        NXP_LOG_ESE_D("%s I-Frame lastRcvdIframeInfo.seqNo:0x%x", __FUNCTION__,
+                      pcb_bits.bit7);
         phNxpEseProto7816_ResetRecovery();
         phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdIframeInfo.seqNo = 0x00;
         phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdIframeInfo.seqNo |=
@@ -1044,7 +1053,7 @@
           } else {
             phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
                 SEND_R_NACK;
-            ALOGD_IF(ese_debug_enabled, "%s Invalid IframeData", __FUNCTION__);
+            NXP_LOG_ESE_I("%s Invalid IframeData", __FUNCTION__);
           }
         } else {
           phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdIframeInfo.isChained =
@@ -1061,7 +1070,7 @@
             phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = RFRAME;
             phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
                 SEND_R_NACK;
-            ALOGD_IF(ese_debug_enabled, "%s Invalid IframeData", __FUNCTION__);
+            NXP_LOG_ESE_I("%s Invalid IframeData", __FUNCTION__);
           }
         }
       } else {
@@ -1082,61 +1091,71 @@
   } else if ((0x01 == pcb_bits.msb) &&
              (0x00 == pcb_bits.bit7)) /* R-FRAME decoded should come here */
   {
-    ALOGD_IF(ese_debug_enabled, "%s R-Frame Received", __FUNCTION__);
-    phNxpEseProto7816_CheckAndNotifyWtx(WTX_END);
-    phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdFrameType = RFRAME;
-    phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.seqNo =
-        0;  // = 0;
-    phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.seqNo |=
-        pcb_bits.bit5;
+    NXP_LOG_ESE_D("%s R-Frame Received", __FUNCTION__);
+    if (data_len == (PH_PROTO_7816_HEADER_LEN + PH_PROTO_7816_CRC_LEN)) {
+      phNxpEseProto7816_CheckAndNotifyWtx(WTX_END);
+      phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdFrameType = RFRAME;
+      phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.seqNo =
+          0;  // = 0;
+      phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.seqNo |=
+          pcb_bits.bit5;
 
-    if ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x00)) {
-      if (!phNxpEseProto7816_ResendLastSFrameReq()) {
-        phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
-            NO_ERROR;
-        phNxpEseProto7816_ResetRecovery();
-        if (phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.seqNo !=
-            phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo.seqNo) {
-          status = phNxpEseProto7816_SetNextIframeContxt();
-          phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
-              SEND_IFRAME;
-        } else {
-          // error handling.
+      if ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x00)) {
+        if (!phNxpEseProto7816_ResendLastSFrameReq()) {
+          phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
+              NO_ERROR;
+          phNxpEseProto7816_ResetRecovery();
+          if (phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo
+                  .seqNo !=
+              phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo.seqNo) {
+            status = phNxpEseProto7816_SetNextIframeContxt();
+            phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+                SEND_IFRAME;
+          } else {
+            // error handling.
+          }
         }
-      }
-    } /* Error handling 1 : Parity error */
-    else if (((pcb_bits.lsb == 0x01) && (pcb_bits.bit2 == 0x00)) ||
-             /* Error handling 2: Other indicated error */
-             ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x01)) ||
-             /* Error handling 3 : Frame Missing error */
-             ((pcb_bits.lsb == 0x01) && (pcb_bits.bit2 == 0x01))) {
-      phNxpEse_Sleep(GET_DELAY_ERROR_RECOVERY());
-      if ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x01)) {
-        phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
-            OTHER_ERROR;
-      } else if ((pcb_bits.lsb == 0x01) && (pcb_bits.bit2 == 0x00)) {
-        phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
-            PARITY_ERROR;
-      } else {
-        phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
-            SOF_MISSED_ERROR;
-      }
-      if (phNxpEseProto7816_3_Var.recoveryCounter < GET_FRAME_RETRY_COUNT()) {
-        if (phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.FrameType == IFRAME) {
-          /*Only for R-NACK other issue re sync*/
-          if ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x01)) {
-            if (phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo
-                        .seqNo != phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx
-                                      .IframeInfo.seqNo &&
-                phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo
-                        .isChained == false) {
-              phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
-                  SEND_S_RSYNC;
-              phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = SFRAME;
-              phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.SframeInfo
-                  .sFrameType = RESYNCH_REQ;
+      } /* Error handling 1 : Parity error */
+      else if (((pcb_bits.lsb == 0x01) && (pcb_bits.bit2 == 0x00)) ||
+               /* Error handling 2: Other indicated error */
+               ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x01)) ||
+               /* Error handling 3 : Frame Missing error */
+               ((pcb_bits.lsb == 0x01) && (pcb_bits.bit2 == 0x01))) {
+        phNxpEse_Sleep(GET_DELAY_ERROR_RECOVERY());
+        if ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x01)) {
+          phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
+              OTHER_ERROR;
+        } else if ((pcb_bits.lsb == 0x01) && (pcb_bits.bit2 == 0x00)) {
+          phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
+              PARITY_ERROR;
+        } else {
+          phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
+              SOF_MISSED_ERROR;
+        }
+        if (phNxpEseProto7816_3_Var.recoveryCounter < GET_FRAME_RETRY_COUNT()) {
+          if (phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.FrameType == IFRAME) {
+            /*Only for R-NACK other issue re sync*/
+            if ((pcb_bits.lsb == 0x00) && (pcb_bits.bit2 == 0x01)) {
+              if (phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo
+                          .seqNo != phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx
+                                        .IframeInfo.seqNo &&
+                  phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo
+                          .isChained == false) {
+                phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+                    SEND_S_RSYNC;
+                phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = SFRAME;
+                phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.SframeInfo
+                    .sFrameType = RESYNCH_REQ;
+              } else {
+                /*If R-NACK with sequence no matching then also reissue frame*/
+                phNxpEse_memcpy(&phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
+                                &phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx,
+                                sizeof(phNxpEseProto7816_NextTx_Info_t));
+                phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+                    SEND_IFRAME;
+                phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = IFRAME;
+              }
             } else {
-              /*If R-NACK with sequence no matching then also reissue frame*/
               phNxpEse_memcpy(&phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
                               &phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx,
                               sizeof(phNxpEseProto7816_NextTx_Info_t));
@@ -1144,84 +1163,81 @@
                   SEND_IFRAME;
               phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = IFRAME;
             }
-          } else {
+          } else if (phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.FrameType ==
+                     RFRAME) {
+            /* Usecase to reach the below case:
+            I-frame sent first, followed by R-NACK and we receive a R-NACK with
+            last sent I-frame sequence number*/
+            if ((phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo
+                     .seqNo == phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx
+                                   .IframeInfo.seqNo) &&
+                (phNxpEseProto7816_3_Var.lastSentNonErrorframeType == IFRAME)) {
+              phNxpEse_memcpy(&phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
+                              &phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx,
+                              sizeof(phNxpEseProto7816_NextTx_Info_t));
+              phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+                  SEND_IFRAME;
+              phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = IFRAME;
+            }
+            /* Usecase to reach the below case:
+            R-frame sent first, followed by R-NACK and we receive a R-NACK with
+            next expected I-frame sequence number*/
+            else if ((phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo
+                          .seqNo != phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx
+                                        .IframeInfo.seqNo) &&
+                     (phNxpEseProto7816_3_Var.lastSentNonErrorframeType ==
+                      RFRAME)) {
+              phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = RFRAME;
+              phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.RframeInfo.errCode =
+                  NO_ERROR;
+              phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+                  SEND_R_ACK;
+            }
+            /* Usecase to reach the below case:
+            I-frame sent first, followed by R-NACK and we receive a R-NACK with
+            next expected I-frame sequence number + all the other unexpected
+            scenarios */
+            else {
+              phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = RFRAME;
+              phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.RframeInfo.errCode =
+                  OTHER_ERROR;
+              phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+                  SEND_R_NACK;
+            }
+          } else if (phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.FrameType ==
+                     SFRAME) {
+            /* Copy the last S frame sent */
             phNxpEse_memcpy(&phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
                             &phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx,
                             sizeof(phNxpEseProto7816_NextTx_Info_t));
-            phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
-                SEND_IFRAME;
-            phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = IFRAME;
           }
-        } else if (phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.FrameType ==
-                   RFRAME) {
-          /* Usecase to reach the below case:
-          I-frame sent first, followed by R-NACK and we receive a R-NACK with
-          last sent I-frame sequence number*/
-          if ((phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo
-                   .seqNo ==
-               phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.IframeInfo.seqNo) &&
-              (phNxpEseProto7816_3_Var.lastSentNonErrorframeType == IFRAME)) {
-            phNxpEse_memcpy(&phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
-                            &phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx,
-                            sizeof(phNxpEseProto7816_NextTx_Info_t));
-            phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
-                SEND_IFRAME;
-            phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = IFRAME;
-          }
-          /* Usecase to reach the below case:
-          R-frame sent first, followed by R-NACK and we receive a R-NACK with
-          next expected I-frame sequence number*/
-          else if ((phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo
-                        .seqNo != phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx
-                                      .IframeInfo.seqNo) &&
-                   (phNxpEseProto7816_3_Var.lastSentNonErrorframeType ==
-                    RFRAME)) {
-            phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = RFRAME;
-            phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.RframeInfo.errCode =
-                NO_ERROR;
-            phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
-                SEND_R_ACK;
-          }
-          /* Usecase to reach the below case:
-          I-frame sent first, followed by R-NACK and we receive a R-NACK with
-          next expected I-frame sequence number + all the other unexpected
-          scenarios */
-          else {
-            phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = RFRAME;
-            phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.RframeInfo.errCode =
-                OTHER_ERROR;
-            phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
-                SEND_R_NACK;
-          }
-        } else if (phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.FrameType ==
-                   SFRAME) {
-          /* Copy the last S frame sent */
-          phNxpEse_memcpy(&phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
-                          &phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx,
-                          sizeof(phNxpEseProto7816_NextTx_Info_t));
+          phNxpEseProto7816_3_Var.recoveryCounter++;
+        } else {
+          phNxpEseProto7816_RecoverySteps();
+          phNxpEseProto7816_3_Var.recoveryCounter++;
         }
-        phNxpEseProto7816_3_Var.recoveryCounter++;
-      } else {
-        phNxpEseProto7816_RecoverySteps();
-        phNxpEseProto7816_3_Var.recoveryCounter++;
+        // resend previously send I frame
+      } else /* Error handling 4 */
+      {
+        phNxpEse_Sleep(GET_DELAY_ERROR_RECOVERY());
+        if (phNxpEseProto7816_3_Var.recoveryCounter < GET_FRAME_RETRY_COUNT()) {
+          phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
+              UNDEFINED_ERROR;
+          phNxpEseProto7816_3_Var.recoveryCounter++;
+        } else {
+          phNxpEseProto7816_RecoverySteps();
+          phNxpEseProto7816_3_Var.recoveryCounter++;
+        }
       }
-      // resend previously send I frame
-    } else /* Error handling 4 */
-    {
-      phNxpEse_Sleep(GET_DELAY_ERROR_RECOVERY());
-      if (phNxpEseProto7816_3_Var.recoveryCounter < GET_FRAME_RETRY_COUNT()) {
-        phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdRframeInfo.errCode =
-            UNDEFINED_ERROR;
-        phNxpEseProto7816_3_Var.recoveryCounter++;
-      } else {
-        phNxpEseProto7816_RecoverySteps();
-        phNxpEseProto7816_3_Var.recoveryCounter++;
-      }
+    } else {
+      NXP_LOG_ESE_E("%s Payload data is not expected in R-Frame, data_len %d",
+                    __FUNCTION__, data_len);
+      status = ESESTATUS_INVALID_RECEIVE_LENGTH;
     }
   } else if ((0x01 == pcb_bits.msb) &&
              (0x01 == pcb_bits.bit7)) /* S-FRAME decoded should come here */
   {
-    ALOGD_IF(ese_debug_enabled, "%s S-Frame Received", __FUNCTION__);
+    NXP_LOG_ESE_D("%s S-Frame Received", __FUNCTION__);
     int32_t frameType = (int32_t)(pcb & 0x3F); /*discard upper 2 bits */
     phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdFrameType = SFRAME;
     if (frameType != WTX_REQ) {
@@ -1287,10 +1303,10 @@
         break;
       case WTX_REQ:
         phNxpEseProto7816_3_Var.wtx_counter++;
-        ALOGD_IF(ese_debug_enabled, "%s Wtx_counter value - %lu", __FUNCTION__,
-                 phNxpEseProto7816_3_Var.wtx_counter);
-        ALOGD_IF(ese_debug_enabled, "%s Wtx_counter wtx_counter_limit - %lu",
-                 __FUNCTION__, phNxpEseProto7816_3_Var.wtx_counter_limit);
+        NXP_LOG_ESE_D("%s Wtx_counter value - %lu", __FUNCTION__,
+                      phNxpEseProto7816_3_Var.wtx_counter);
+        NXP_LOG_ESE_D("%s Wtx_counter wtx_counter_limit - %lu", __FUNCTION__,
+                      phNxpEseProto7816_3_Var.wtx_counter_limit);
         /* Previous sent frame is some S-frame but not WTX response S-frame */
         if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0 &&
             phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.SframeInfo.sFrameType !=
@@ -1314,10 +1330,10 @@
               phNxpEseProto7816_3_Var.wtx_counter_limit) {
             phNxpEseProto7816_CheckAndNotifyWtx(WTX_END);
             if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
-              ALOGD_IF(ese_debug_enabled,
-                       "%s Power cycle to eSE  max "
-                       "WTX received",
-                       __FUNCTION__);
+              NXP_LOG_ESE_D(
+                  "%s Power cycle to eSE  max "
+                  "WTX received",
+                  __FUNCTION__);
               phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
                   IDLE_STATE;
               status = ESESTATUS_TRANSCEIVE_FAILED;
@@ -1329,10 +1345,10 @@
                   .sFrameType = INTF_RESET_REQ;
               phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
                   SEND_S_INTF_RST;
-              ALOGD_IF(ese_debug_enabled,
-                       "%s Interface Reset to eSE wtx"
-                       " count reached!!!",
-                       __FUNCTION__);
+              NXP_LOG_ESE_D(
+                  "%s Interface Reset to eSE wtx"
+                  " count reached!!!",
+                  __FUNCTION__);
             }
           } else {
             phNxpEse_Sleep(GET_DELAY_ERROR_RECOVERY());
@@ -1355,17 +1371,30 @@
             INTF_RESET_REQ;
         break;
       case INTF_RESET_RSP:
-        phNxpEseProto7816_ResetProtoParams();
-        phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdSframeInfo.sFrameType =
-            INTF_RESET_RSP;
+        if (phNxpEseProto7816_3_Var.reset_type == RESET_TYPE_RECOVERY) {
+          uint32_t tmpcurrentIFSDSize = phNxpEseProto7816_3_Var.currentIFSDSize;
+          phNxpEseProto7816_ResetProtoParams();
+          phNxpEseProto7816_3_Var.currentIFSDSize = tmpcurrentIFSDSize;
+          phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
+              PH_NXP_ESE_PROTO_7816_TRANSCEIVE;
+          phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = SFRAME;
+          phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.SframeInfo.sFrameType =
+              IFS_REQ;
+          phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+              SEND_S_IFS_ADJ;
+        } else {
+          phNxpEseProto7816_ResetProtoParams();
+          phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdSframeInfo
+              .sFrameType = INTF_RESET_RSP;
+          phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = UNKNOWN;
+          phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+              IDLE_STATE;
+        }
         if (p_data[PH_PROPTO_7816_FRAME_LENGTH_OFFSET] > 0) {
           phNxpEseProto7816_DecodeSFrameATRData(p_data);
         } else {
           phNxpEse_setOsVersion(OS_VERSION_4_0);
         }
-        phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = UNKNOWN;
-        phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
-            IDLE_STATE;
         break;
       case PROP_END_APDU_REQ:
         phNxpEseProto7816_3_Var.phNxpEseRx_Cntx.lastRcvdSframeInfo.sFrameType =
@@ -1406,7 +1435,7 @@
             ATR_RSP;
         if (p_data[PH_PROPTO_7816_FRAME_LENGTH_OFFSET] > 0) {
           phNxpEseProto7816_DecodeSFrameATRData(p_data);
-          phNxpEse_StoreDatainList(
+          status = phNxpEse_StoreDatainList(
               p_data[PH_PROPTO_7816_FRAME_LENGTH_OFFSET],
               &p_data[PH_PROPTO_7816_FRAME_LENGTH_OFFSET + 1]);
         } else {
@@ -1417,18 +1446,18 @@
             IDLE_STATE;
         break;
       default:
-        ALOGE("%s Wrong S-Frame Received", __FUNCTION__);
+        NXP_LOG_ESE_E("%s Wrong S-Frame Received", __FUNCTION__);
         break;
     }
-    /*After S-Frame Rx 1 msec delay before next Tx*/
+    /*After S-Frame Rx 1 microsecond delay before next Tx*/
     if ((GET_CHIP_OS_VERSION() != OS_VERSION_4_0) &&
         (frameType != PROP_END_APDU_RSP)) {
       phNxpEse_Sleep(1000);
     }
   } else {
-    ALOGD_IF(ese_debug_enabled, "%s Wrong-Frame Received", __FUNCTION__);
+    NXP_LOG_ESE_D("%s Wrong-Frame Received", __FUNCTION__);
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -1445,10 +1474,10 @@
   uint32_t data_len = 0;
   uint8_t* p_data = NULL;
   ESESTATUS status = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   status = phNxpEseProto7816_GetRawFrame(&data_len, &p_data);
-  ALOGD_IF(ese_debug_enabled, "%s p_data ----> %p len ----> 0x%x", __FUNCTION__,
-           p_data, data_len);
+  NXP_LOG_ESE_D("%s p_data ----> %p len ----> 0x%x", __FUNCTION__, p_data,
+                data_len);
   if (ESESTATUS_SUCCESS == status) {
     /* Resetting the timeout counter */
     phNxpEseProto7816_3_Var.timeoutCounter = PH_PROTO_7816_VALUE_ZERO;
@@ -1459,7 +1488,7 @@
       phNxpEseProto7816_3_Var.rnack_retry_counter = PH_PROTO_7816_VALUE_ZERO;
       status = phNxpEseProto7816_DecodeFrame(p_data, data_len);
     } else {
-      ALOGE("%s LRC Check failed", __FUNCTION__);
+      NXP_LOG_ESE_E("%s LRC Check failed", __FUNCTION__);
       if (phNxpEseProto7816_3_Var.rnack_retry_counter <
           phNxpEseProto7816_3_Var.rnack_retry_limit) {
         /*If Last sent Non-error frame is S-Frame*/
@@ -1488,8 +1517,7 @@
       }
     }
   } else {
-    ALOGD_IF(ese_debug_enabled, "%s phNxpEseProto7816_GetRawFrame failed",
-             __FUNCTION__);
+    NXP_LOG_ESE_I("%s phNxpEseProto7816_GetRawFrame failed", __FUNCTION__);
     if ((SFRAME == phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.FrameType) &&
         ((WTX_RSP ==
           phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.SframeInfo.sFrameType) ||
@@ -1520,8 +1548,7 @@
       if (phNxpEseProto7816_3_Var.timeoutCounter <
           PH_PROTO_7816_TIMEOUT_RETRY_COUNT) {
         phNxpEseProto7816_3_Var.timeoutCounter++;
-        ALOGD_IF(ese_debug_enabled, "%s re-transmitting the previous frame",
-                 __FUNCTION__);
+        NXP_LOG_ESE_D("%s re-transmitting the previous frame", __FUNCTION__);
         phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx =
             phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx;
       } else {
@@ -1532,13 +1559,17 @@
           status = ESESTATUS_FAILED;
         }
         phNxpEseProto7816_3_Var.timeoutCounter = PH_PROTO_7816_VALUE_ZERO;
-        ALOGD_IF(ese_debug_enabled, "%s calling phNxpEse_StoreDatainList",
-                 __FUNCTION__);
-        phNxpEse_StoreDatainList(data_len, p_data);
+        NXP_LOG_ESE_D("%s calling phNxpEse_StoreDatainList", __FUNCTION__);
+        ESESTATUS storeDataStatus = phNxpEse_StoreDatainList(data_len, p_data);
+        if (storeDataStatus != ESESTATUS_SUCCESS) {
+          NXP_LOG_ESE_D("%s :phNxpEse_StoreDatainList failed. status = %x",
+                        __FUNCTION__, storeDataStatus);
+          status = storeDataStatus;
+        }
       }
     }
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s Status 0x%x", __FUNCTION__, status);
+  NXP_LOG_ESE_D("Exit %s Status 0x%x", __FUNCTION__, status);
   return status;
 }
 
@@ -1559,11 +1590,13 @@
   sFrameInfo_t sFrameInfo;
   memset(&sFrameInfo, 0, sizeof(sFrameInfo_t));
 
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  phNxpEse_FlushData();
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   while (phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState !=
          IDLE_STATE) {
-    ALOGD_IF(ese_debug_enabled, "%s nextTransceiveState %x", __FUNCTION__,
-             phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState);
+    NXP_LOG_ESE_D(
+        "%s nextTransceiveState %x", __FUNCTION__,
+        phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState);
     switch (phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState) {
       case SEND_IFRAME:
         status = phNxpEseProto7816_SendIframe(
@@ -1621,16 +1654,25 @@
                       &phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
                       sizeof(phNxpEseProto7816_NextTx_Info_t));
       status = phNxpEseProto7816_ProcessResponse();
+      if (ESESTATUS_NOT_ENOUGH_MEMORY == status ||
+          ESESTATUS_INVALID_RECEIVE_LENGTH == status) {
+        NXP_LOG_ESE_E(
+            "%s Processing response failed, shall retry in new session",
+            __FUNCTION__);
+        phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
+            IDLE_STATE;
+      }
     } else {
-      ALOGE("%s Transceive send failed, going to recovery!", __FUNCTION__);
+      NXP_LOG_ESE_E("%s Transceive send failed, going to recovery!",
+                    __FUNCTION__);
       phNxpEseProto7816_3_Var.phNxpEseProto7816_nextTransceiveState =
           IDLE_STATE;
     }
-  };
+  }
   /*Timeout condition when previously WTX_ONGOING is notified
    *WTX_END shall be notified from here */
   phNxpEseProto7816_CheckAndNotifyWtx(WTX_END);
-  ALOGD_IF(ese_debug_enabled, "Exit %s Status 0x%x", __FUNCTION__, status);
+  NXP_LOG_ESE_D("Exit %s Status 0x%x", __FUNCTION__, status);
   return status;
 }
 
@@ -1683,7 +1725,7 @@
   ESESTATUS status = ESESTATUS_FAILED;
   ESESTATUS wStatus = ESESTATUS_FAILED;
   phNxpEse_data pRes;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   if ((NULL == pCmd) || (NULL == pRsp) ||
       (phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState !=
        PH_NXP_ESE_PROTO_7816_IDLE))
@@ -1695,32 +1737,37 @@
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.p_data = pCmd->p_data;
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.totalDataLen =
       pCmd->len;
-  ALOGD_IF(ese_debug_enabled, "Transceive data ptr 0x%p len:%d", pCmd->p_data,
-           pCmd->len);
+  NXP_LOG_ESE_D("Transceive data ptr 0x%p len:%d", pCmd->p_data, pCmd->len);
   status = phNxpEseProto7816_SetFirstIframeContxt();
+
+  phPalEse_startTimer(phPalEse_getTimer()->tx_timer);
+
   status = TransceiveProcess();
+
+  phPalEse_stopTimer(phPalEse_getTimer()->rx_timer);
+
   if (ESESTATUS_FAILED == status || ESESTATUS_TRANSCEIVE_FAILED == status) {
     /* ESE hard reset to be done */
-    ALOGE("Transceive failed, hard reset to proceed");
+    NXP_LOG_ESE_E("Transceive failed, hard reset to proceed");
     wStatus = phNxpEse_GetData(&pRes.len, &pRes.p_data);
     if (ESESTATUS_SUCCESS == wStatus) {
-      ALOGD_IF(ese_debug_enabled,
-               "%s Data successfully received at 7816, packaging to "
-               "send upper layers: DataLen = %d",
-               __FUNCTION__, pRes.len);
+      NXP_LOG_ESE_D(
+          "%s Data successfully received at 7816, packaging to "
+          "send upper layers: DataLen = %d",
+          __FUNCTION__, pRes.len);
     }
   } else {
     // fetch the data info and report to upper layer.
     wStatus = phNxpEse_GetData(&pRes.len, &pRes.p_data);
     if (ESESTATUS_SUCCESS == wStatus) {
-      ALOGD_IF(ese_debug_enabled,
-               "%s Data successfully received at 7816, packaging to "
-               "send upper layers: DataLen = %d",
-               __FUNCTION__, pRes.len);
+      NXP_LOG_ESE_D(
+          "%s Data successfully received at 7816, packaging to "
+          "send upper layers: DataLen = %d",
+          __FUNCTION__, pRes.len);
     } else
       status = ESESTATUS_FAILED;
   }
-
+  printCmdRspTimeDuration(status, pCmd->len, pRes.len);
   /* Copy the data to be read by the upper layer via transceive api */
   pRsp->len = pRes.len;
   pRsp->p_data = pRes.p_data;
@@ -1728,11 +1775,37 @@
   phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
       PH_NXP_ESE_PROTO_7816_IDLE;
   phNxpEseProto7816_3_Var.reset_type = RESET_TYPE_NONE;
-  ALOGD_IF(ese_debug_enabled, "Exit %s Status 0x%x", __FUNCTION__, status);
+  NXP_LOG_ESE_D("Exit %s Status 0x%x", __FUNCTION__, status);
   return status;
 }
 
 /******************************************************************************
+ * Function         printCmdRspTimeDuration
+ *
+ * Description      Prints time taken(usecs) in sending C-Apdu and receiving
+ *                  R-Apdu
+ *                  Applicable only when KPI measurement config is enabled
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+static void printCmdRspTimeDuration(ESESTATUS status, uint32_t cmdLen,
+                                    uint32_t respLen) {
+  if (!phPalEse_getTimer()->is_enabled) return;
+
+  if (status == ESESTATUS_SUCCESS) {
+    NXP_LOG_ESE_I(
+        "TX: Total time taken for sending C-Apdu of size: %d is %lu usecs",
+        cmdLen, phPalEse_timerDuration(phPalEse_getTimer()->tx_timer));
+    NXP_LOG_ESE_I(
+        "RX: Total time taken for receiving R-Apdu of size: %d is %lu usecs",
+        respLen, phPalEse_timerDuration(phPalEse_getTimer()->rx_timer));
+  } else {
+    phPalEse_resetTimer();
+  }
+}
+
+/******************************************************************************
  * Function         phNxpEseProto7816_RSync
  *
  * Description      This function is used to send the RSync command
@@ -1879,8 +1952,7 @@
 ESESTATUS phNxpEseProto7816_Open(phNxpEseProto7816InitParam_t initParam) {
   ESESTATUS status = ESESTATUS_FAILED;
   status = phNxpEseProto7816_ResetProtoParams();
-  ALOGD_IF(ese_debug_enabled, "%s: First open completed, Congratulations",
-           __FUNCTION__);
+  NXP_LOG_ESE_D("%s: First open completed, Congratulations", __FUNCTION__);
   /* Update WTX max. limit */
   phNxpEseProto7816_3_Var.wtx_counter_limit = initParam.wtx_counter_limit;
   phNxpEseProto7816_3_Var.rnack_retry_limit = initParam.rnack_retry_limit;
@@ -1939,13 +2011,13 @@
   status = TransceiveProcess();
   if (ESESTATUS_SUCCESS != status) {
     /* reset all the structures */
-    ALOGE("%s TransceiveProcess failed ", __FUNCTION__);
+    NXP_LOG_ESE_E("%s TransceiveProcess failed ", __FUNCTION__);
     if (status == ESESTATUS_TRANSCEIVE_FAILED &&
         phNxpEseProto7816_3_Var.atrInfo.len > PH_PROTO_7816_VALUE_ZERO) {
       if (phNxpEseProto7816_3_Var.atrInfo
               .vendorID[PH_PROTO_ATR_RSP_VENDOR_ID_LEN - 1] <
           PH_SE_OS_VERSION_10) {
-        ALOGD_IF(ese_debug_enabled, "%s shall trigger recovery", __FUNCTION__);
+        NXP_LOG_ESE_D("%s shall trigger recovery", __FUNCTION__);
         status = ESESTATUS_RESPONSE_TIMEOUT;
       }
     }
@@ -1991,14 +2063,14 @@
       status = TransceiveProcess();
       if (ESESTATUS_FAILED == status) {
         /* reset all the structures */
-        ALOGD_IF(ese_debug_enabled, "%s EndOfSession failed ", __FUNCTION__);
+        NXP_LOG_ESE_D("%s EndOfSession failed ", __FUNCTION__);
       }
       phNxpEse_free(buffer);
       phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
           PH_NXP_ESE_PROTO_7816_IDLE;
     }
   } else {
-    ALOGD_IF(ese_debug_enabled, "%s Function not supported ", __FUNCTION__);
+    NXP_LOG_ESE_D("%s Function not supported ", __FUNCTION__);
     status = ESESTATUS_SUCCESS;
   }
   return status;
@@ -2015,7 +2087,7 @@
 ESESTATUS phNxpEseProto7816_IntfReset(
     phNxpEseProto7816SecureTimer_t* pSecureTimerParam) {
   ESESTATUS status = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
       PH_NXP_ESE_PROTO_7816_TRANSCEIVE;
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = SFRAME;
@@ -2026,13 +2098,13 @@
   status = TransceiveProcess();
   if (ESESTATUS_FAILED == status) {
     /* reset all the structures */
-    ALOGE("%s TransceiveProcess failed ", __FUNCTION__);
+    NXP_LOG_ESE_E("%s TransceiveProcess failed ", __FUNCTION__);
   }
   phNxpEse_memcpy(pSecureTimerParam, &phNxpEseProto7816_3_Var.secureTimerParams,
                   sizeof(phNxpEseProto7816SecureTimer_t));
   phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
       PH_NXP_ESE_PROTO_7816_IDLE;
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -2048,16 +2120,15 @@
   // phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.maxDataLenIFSC =
   // IFSC_Size;
   ESESTATUS status = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   /* IFSD > IFSC not allowed, card will reject by R-NACK so not sending */
   if (IFS_Size >
       phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.maxDataLenIFSC) {
     phNxpEseProto7816_3_Var.currentIFSDSize =
         phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.maxDataLenIFSC;
     /* IFSD is greater than IFSC , set max IFSC as IFSD*/
-    ALOGD_IF(ese_debug_enabled,
-             "%s : IFSD greater than IFSC ,  set max IFSC as IFSD  ",
-             __FUNCTION__);
+    NXP_LOG_ESE_D("%s : IFSD greater than IFSC ,  set max IFSC as IFSD  ",
+                  __FUNCTION__);
   } else {
     phNxpEseProto7816_3_Var.currentIFSDSize = IFS_Size;
   }
@@ -2070,11 +2141,11 @@
   status = TransceiveProcess();
   if (ESESTATUS_FAILED == status) {
     /* reset all the structures */
-    ALOGE("%s TransceiveProcess failed ", __FUNCTION__);
+    NXP_LOG_ESE_E("%s TransceiveProcess failed ", __FUNCTION__);
   }
   phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
       PH_NXP_ESE_PROTO_7816_IDLE;
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -2088,8 +2159,8 @@
  *
  ******************************************************************************/
 uint16_t phNxpEseProto7816_GetIfs(void) {
-  ALOGD_IF(
-      ese_debug_enabled, "Enter %s current IFSC = %d", __FUNCTION__,
+  NXP_LOG_ESE_D(
+      "Enter %s current IFSC = %d", __FUNCTION__,
       phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo.currentDataLenIFS);
   return phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.IframeInfo
       .currentDataLenIFS;
@@ -2108,20 +2179,17 @@
   phNxpEseProto7816_OsType_t mode = UNKNOWN_MODE;
   if (GET_CHIP_OS_VERSION() >= OS_VERSION_5_2_2) {
     if (phNxpEseProto7816_3_Var.extndAtrInfo.osType == MODE_JCOP) {
-      ALOGD_IF(ese_debug_enabled, "Enter %s OS Mode = %s", __FUNCTION__,
-               "JCOP Mode");
+      NXP_LOG_ESE_D("Enter %s OS Mode = %s", __FUNCTION__, "JCOP Mode");
       mode = JCOP_MODE;
     } else if (phNxpEseProto7816_3_Var.extndAtrInfo.osType == MODE_OSU) {
-      ALOGD_IF(ese_debug_enabled, "Enter %s OS Mode = %s", __FUNCTION__,
-               "OSU Mode");
+      NXP_LOG_ESE_D("Enter %s OS Mode = %s", __FUNCTION__, "OSU Mode");
       mode = OSU_MODE;
     } else {
-      ALOGD_IF(ese_debug_enabled, "Enter %s OS Mode = %s", __FUNCTION__,
-               "UNKNOWN Mode");
+      NXP_LOG_ESE_D("Enter %s OS Mode = %s", __FUNCTION__, "UNKNOWN Mode");
       mode = UNKNOWN_MODE;
     }
   } else {
-    ALOGE("%s function not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s function not supported", __FUNCTION__);
   }
   return mode;
 }
@@ -2137,7 +2205,7 @@
 ESESTATUS phNxpEseProto7816_getAtr(phNxpEse_data* pATRRsp) {
   ESESTATUS status = ESESTATUS_FAILED;
 
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
       PH_NXP_ESE_PROTO_7816_TRANSCEIVE;
   phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx.FrameType = SFRAME;
@@ -2148,20 +2216,20 @@
   status = TransceiveProcess();
   if (ESESTATUS_FAILED == status) {
     /* reset all the structures */
-    ALOGD_IF(ese_debug_enabled, "%s TransceiveProcess failed ", __FUNCTION__);
+    NXP_LOG_ESE_D("%s TransceiveProcess failed ", __FUNCTION__);
   }
 
   status = phNxpEse_GetData(&(pATRRsp->len), &(pATRRsp->p_data));
   if (ESESTATUS_SUCCESS == status) {
-    ALOGD_IF(ese_debug_enabled,
-             "%s Data successfully received at 7816, packaging to "
-             "send upper layers: DataLen = %d",
-             __FUNCTION__, pATRRsp->len);
+    NXP_LOG_ESE_D(
+        "%s Data successfully received at 7816, packaging to "
+        "send upper layers: DataLen = %d",
+        __FUNCTION__, pATRRsp->len);
   } else
     status = ESESTATUS_FAILED;
   phNxpEseProto7816_3_Var.phNxpEseProto7816_CurrentState =
       PH_NXP_ESE_PROTO_7816_IDLE;
-  ALOGD_IF(ese_debug_enabled, "Exit %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Exit %s ", __FUNCTION__);
   return status;
 }
 
@@ -2218,9 +2286,8 @@
   if (phNxpEseProto7816_3_Var.lastSentNonErrorframeType == SFRAME &&
       WTX_RSP !=
           phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx.SframeInfo.sFrameType) {
-    ALOGD_IF(ese_debug_enabled,
-             "%s Unexpected Frame, re-transmitting the previous S-frame",
-             __FUNCTION__);
+    NXP_LOG_ESE_D("%s Unexpected Frame, re-transmitting the previous S-frame",
+                  __FUNCTION__);
     phNxpEse_memcpy(&phNxpEseProto7816_3_Var.phNxpEseNextTx_Cntx,
                     &phNxpEseProto7816_3_Var.phNxpEseLastTx_Cntx,
                     sizeof(phNxpEseProto7816_NextTx_Info_t));
diff --git a/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.h b/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.h
index 70f4617..f71d8fc 100755
--- a/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.h
+++ b/snxxx/libese-spi/p73/lib/phNxpEseProto7816_3.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -118,6 +118,14 @@
 } phNxpEseProto7816_TransceiveStates_t;
 
 /*!
+ * \brief reset type used in 7816-3 stack
+ */
+typedef enum phNxpEseProto7816_ResetType {
+  RESET_TYPE_NONE,
+  RESET_TYPE_RECOVERY
+} phNxpEseProto7816_ResetType_t;
+
+/*!
  * \brief I-frame information structure for ISO 7816-3
  *
  * This structure holds the  information of I-frame used for sending
@@ -232,7 +240,7 @@
 } phNxpEseProto7816_NextTx_Info_t;
 
 /*!
- * \brief Last sent Tx ransceive data
+ * \brief Last sent Tx transceive data
  *
  * This structure holds the information of the last sent
  * I-frame/R-frame/S-frame
@@ -256,7 +264,7 @@
 } phNxpEseRx_Cntx_t;
 
 /*!
- * \brief Proprietery: Secure timer value updates
+ * \brief Proprietary: Secure timer value updates
  *
  * This structure holds the secure timer value
  *
@@ -318,8 +326,8 @@
 /*!
  * \brief 7816-3 protocol stack init params
  *
- * This structure holds the parameters to be passed to open 7816-3 protocl stack
- *instance
+ * This structure holds the parameters to be passed to open 7816-3 protocol
+ *stack instance
  *
  */
 typedef struct phNxpEseProto7816InitParam {
@@ -465,10 +473,6 @@
 /*!
  * \brief APIs exposed from the 7816-3 protocol layer
  */
-#define RESET_TYPE_NONE 0x00
-/*!
- * \brief APIs exposed from the 7816-3 protocol layer
- */
 #define EXTENDED_FRAME_MARKER 0xFF
 /*!
  * \brief APIs exposed from the 7816-3 protocol layer
@@ -495,6 +499,10 @@
  */
 #define PH_SE_OS_VERSION_20 0x20
 /*!
+ * \brief OS version on SE for SN220
+ */
+#define PH_SE_OS_VERSION_21 0x21
+/*!
  * \brief Default wait extension notification interval
  */
 #define PH_DEFAULT_WTX_NTF_LIMIT 0x03
diff --git a/snxxx/libese-spi/p73/lib/phNxpEse_Apdu_Api.cpp b/snxxx/libese-spi/p73/lib/phNxpEse_Apdu_Api.cpp
index 9a01370..fc5d051 100755
--- a/snxxx/libese-spi/p73/lib/phNxpEse_Apdu_Api.cpp
+++ b/snxxx/libese-spi/p73/lib/phNxpEse_Apdu_Api.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2019,2021 NXP
+ *  Copyright 2018-2019,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
  *
  * @{ */
 #define LOG_TAG "NxpEseHal"
+#include <ese_logs.h>
 #include <log/log.h>
 #include <phNxpEse_Apdu_Api.h>
 #include <phNxpEse_Api.h>
@@ -40,7 +41,7 @@
 ESESTATUS phNxpEse_7816_Transceive(pphNxpEse_7816_cpdu_t pCmd,
                                    pphNxpEse_7816_rpdu_t pRsp) {
   ESESTATUS status = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, " %s Enter \n", __FUNCTION__);
+  NXP_LOG_ESE_D(" %s Enter \n", __FUNCTION__);
 
   uint32_t cmd_len = 0;
   uint8_t* pCmd_data = NULL;
@@ -50,15 +51,15 @@
   phNxpEse_memset(&pRspTrans, 0x00, sizeof(phNxpEse_data));
 
   if (NULL == pCmd || NULL == pRsp) {
-    ALOGE(" %s Invalid prameter \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s Invalid parameter \n", __FUNCTION__);
     status = ESESTATUS_INVALID_PARAMETER;
   } else if (pCmd->cpdu_type > 1) {
-    ALOGE(" %s Invalid cpdu type \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s Invalid cpdu type \n", __FUNCTION__);
     status = ESESTATUS_INVALID_CPDU_TYPE;
   } else if (0 < pCmd->le_type && NULL == pRsp->pdata) {
     /* if response is requested, but no valid res buffer
      * provided by application */
-    ALOGE(" %s Invalid response buffer \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s Invalid response buffer \n", __FUNCTION__);
     status = ESESTATUS_INVALID_BUFFER;
   } else {
     status = phNxpEse_7816_FrameCmd(pCmd, &pCmd_data, &cmd_len);
@@ -67,7 +68,7 @@
       pCmdTrans.p_data = pCmd_data;
       status = phNxpEse_Transceive(&pCmdTrans, &pRspTrans);
       if (ESESTATUS_SUCCESS != status) {
-        ALOGE(" %s phNxpEse_Transceive Failed \n", __FUNCTION__);
+        NXP_LOG_ESE_E(" %s phNxpEse_Transceive Failed \n", __FUNCTION__);
         if ((pRspTrans.len > 0) && (pRspTrans.p_data != NULL)) {
           pRsp->sw2 = *(pRspTrans.p_data + (pRspTrans.len - 1));
           pRspTrans.len--;
@@ -82,7 +83,7 @@
           pRsp->sw1 = *(pRspTrans.p_data + (pRspTrans.len - 1));
           pRspTrans.len--;
           pRsp->len = pRspTrans.len;
-          ALOGD_IF(ese_debug_enabled, "pRsp->len %d", pRsp->len);
+          NXP_LOG_ESE_D("pRsp->len %d", pRsp->len);
           if (pRspTrans.len > 0 && NULL != pRsp->pdata) {
             phNxpEse_memcpy(pRsp->pdata, pRspTrans.p_data, pRspTrans.len);
             status = ESESTATUS_SUCCESS;
@@ -90,25 +91,25 @@
             status = ESESTATUS_SUCCESS;
           } else {
             /* if application response buffer is null and data is present */
-            ALOGE("Invalid Res buffer");
+            NXP_LOG_ESE_E("Invalid Res buffer");
             status = ESESTATUS_FAILED;
           }
-          ALOGD_IF(ese_debug_enabled, "Freeing memory pRspTrans.p_data ");
+          NXP_LOG_ESE_D("Freeing memory pRspTrans.p_data ");
           phNxpEse_free(pRspTrans.p_data);
           pRspTrans.p_data = NULL;
           pRspTrans.len = 0;
         } else {
-          ALOGE("pRspTrans.len error = %d", pRspTrans.len);
+          NXP_LOG_ESE_E("pRspTrans.len error = %d", pRspTrans.len);
           status = ESESTATUS_FAILED;
         }
       }
       if (pCmd_data != NULL) {
-        ALOGD_IF(ese_debug_enabled, "Freeing memory pCmd_data");
+        NXP_LOG_ESE_D("Freeing memory pCmd_data");
         phNxpEse_free(pCmd_data);
       }
     }
   }
-  ALOGD_IF(ese_debug_enabled, " %s Exit status 0x%x \n", __FUNCTION__, status);
+  NXP_LOG_ESE_D(" %s Exit status 0x%x \n", __FUNCTION__, status);
   return status;
 }
 
@@ -138,8 +139,8 @@
   uint8_t lc_len = 0;
   uint8_t le_len = 0;
 
-  ALOGD_IF(ese_debug_enabled, "%s  pCmd->lc = %d, pCmd->le_type = %d",
-           __FUNCTION__, pCmd->lc, pCmd->le_type);
+  NXP_LOG_ESE_D("%s  pCmd->lc = %d, pCmd->le_type = %d", __FUNCTION__, pCmd->lc,
+                pCmd->le_type);
   /* calculate the total buffer length */
   if (pCmd->lc > 0) {
     if (pCmd->cpdu_type == 0) {
@@ -152,13 +153,13 @@
 
     cmd_total_len += pCmd->lc; /* add data length */
     if (pCmd->pdata == NULL) {
-      ALOGE("%s Invalide data buffer from application ", __FUNCTION__);
+      NXP_LOG_ESE_E("%s Invalid data buffer from application ", __FUNCTION__);
       return ESESTATUS_INVALID_BUFFER;
     }
   } else {
     lc_len = 0;
-    ALOGD_IF(ese_debug_enabled, "%s lc (data) field is not present %d",
-             __FUNCTION__, pCmd->lc);
+    NXP_LOG_ESE_D("%s lc (data) field is not present %d", __FUNCTION__,
+                  pCmd->lc);
   }
 
   if (pCmd->le_type > 0) {
@@ -176,24 +177,25 @@
         cmd_total_len += 2; /* 2 byte LE */
         le_len = 2;
       } else {
-        ALOGE("%s wrong LE type  %d", __FUNCTION__, pCmd->le_type);
+        NXP_LOG_ESE_E("%s wrong LE type  %d", __FUNCTION__, pCmd->le_type);
         cmd_total_len += pCmd->le_type;
         le_len = pCmd->le_type;
       }
     } else {
-      ALOGE("%s wrong cpdu_type value %d", __FUNCTION__, pCmd->cpdu_type);
+      NXP_LOG_ESE_E("%s wrong cpdu_type value %d", __FUNCTION__,
+                    pCmd->cpdu_type);
       return ESESTATUS_INVALID_CPDU_TYPE;
     }
   } else {
     le_len = 0;
-    ALOGD_IF(ese_debug_enabled, "%s le field is not present", __FUNCTION__);
+    NXP_LOG_ESE_D("%s le field is not present", __FUNCTION__);
   }
-  ALOGD_IF(ese_debug_enabled, "%s cmd_total_len = %d, le_len = %d, lc_len = %d",
-           __FUNCTION__, cmd_total_len, le_len, lc_len);
+  NXP_LOG_ESE_D("%s cmd_total_len = %d, le_len = %d, lc_len = %d", __FUNCTION__,
+                cmd_total_len, le_len, lc_len);
 
   pbuff = (uint8_t*)phNxpEse_calloc(cmd_total_len, sizeof(uint8_t));
   if (pbuff == NULL) {
-    ALOGE("%s Error allocating memory", __FUNCTION__);
+    NXP_LOG_ESE_E("%s Error allocating memory", __FUNCTION__);
     return ESESTATUS_INSUFFICIENT_RESOURCES;
   }
   *cmd_len = cmd_total_len;
@@ -263,8 +265,8 @@
       }
     }
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s cmd_total_len = %d, index = %d",
-           __FUNCTION__, index, cmd_total_len);
+  NXP_LOG_ESE_D("Exit %s cmd_total_len = %d, index = %d", __FUNCTION__, index,
+                cmd_total_len);
   return ESESTATUS_SUCCESS;
 }
 /** @} */
diff --git a/snxxx/libese-spi/p73/lib/phNxpEse_Api.cpp b/snxxx/libese-spi/p73/lib/phNxpEse_Api.cpp
old mode 100755
new mode 100644
index da6a0e1..5fc188e
--- a/snxxx/libese-spi/p73/lib/phNxpEse_Api.cpp
+++ b/snxxx/libese-spi/p73/lib/phNxpEse_Api.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
  *
  ******************************************************************************/
 #define LOG_TAG "NxpEseHal"
-#include <log/log.h>
-
 #include <EseTransport.h>
 #include <cutils/properties.h>
 #include <ese_config.h>
+#include <ese_logs.h>
+#include <log/log.h>
 #include <phNxpEseFeatures.h>
 #include <phNxpEsePal.h>
 #include <phNxpEseProto7816_3.h>
@@ -58,8 +58,8 @@
 
 /* ESE Context structure */
 phNxpEse_Context_t nxpese_ctxt;
-bool ese_debug_enabled = false;
 
+uint8_t ese_log_level = 0;
 /******************************************************************************
  * Function         phNxpEse_SetEndPoint_Cntxt
  *
@@ -78,9 +78,9 @@
       nxpese_ctxt.nadInfo.nadTx = nadInfoTx_ptr[uEndPoint];
       nxpese_ctxt.endPointInfo = uEndPoint;
     }
-    ALOGD_IF(ese_debug_enabled, "%s: Enpoint=%d", __FUNCTION__, uEndPoint);
+    NXP_LOG_ESE_D("%s: Endpoint=%d", __FUNCTION__, uEndPoint);
   } else {
-    ALOGE("%s- Function not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s- Function not supported", __FUNCTION__);
   }
   return status;
 }
@@ -98,7 +98,7 @@
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
     status = phNxpEseProto7816_ResetEndPoint(uEndPoint);
   } else {
-    ALOGE("%s- Function not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s- Function not supported", __FUNCTION__);
   }
   return status;
 }
@@ -113,8 +113,8 @@
  ******************************************************************************/
 
 void phNxpLog_InitializeLogLevel() {
-  ese_debug_enabled =
-      (EseConfig::getUnsigned(NAME_SE_DEBUG_ENABLED, 0) != 0) ? true : false;
+  ese_log_level = EseConfig::getUnsigned(
+      NAME_SE_LOG_LEVEL, NXPESE_LOGLEVEL_DEBUG /*default level*/);
 
   char valueStr[PROPERTY_VALUE_MAX] = {0};
   int len = property_get("vendor.ese.debug_enabled", valueStr, "");
@@ -122,10 +122,10 @@
     // let Android property override .conf variable
     unsigned debug_enabled = 0;
     sscanf(valueStr, "%u", &debug_enabled);
-    ese_debug_enabled = (debug_enabled == 0) ? false : true;
+    ese_log_level = debug_enabled;
   }
 
-  ALOGD_IF(ese_debug_enabled, "%s: level=%u", __func__, ese_debug_enabled);
+  NXP_LOG_ESE_I("%s: level=%u", __func__, ese_log_level);
 }
 
 /******************************************************************************
@@ -151,19 +151,18 @@
 
   if (app_wtx_cnt > RESET_APP_WTX_COUNT) {
     protoInitParam.wtx_counter_limit = app_wtx_cnt;
-    ALOGD_IF(ese_debug_enabled, "Wtx_counter limit from app setting - %lu",
-             protoInitParam.wtx_counter_limit);
+    NXP_LOG_ESE_D("Wtx_counter limit from app setting - %lu",
+                  protoInitParam.wtx_counter_limit);
   } else {
     protoInitParam.wtx_counter_limit = EseConfig::getUnsigned(
         NAME_NXP_WTX_COUNT_VALUE, PH_PROTO_WTX_DEFAULT_COUNT);
-    ALOGD_IF(ese_debug_enabled, "Wtx_counter read from config file - %lu",
-             protoInitParam.wtx_counter_limit);
+    NXP_LOG_ESE_D("Wtx_counter read from config file - %lu",
+                  protoInitParam.wtx_counter_limit);
   }
   if (EseConfig::hasKey(NAME_RNACK_RETRY_DELAY)) {
     num = EseConfig::getUnsigned(NAME_RNACK_RETRY_DELAY);
     nxpese_ctxt.invalidFrame_Rnack_Delay = num;
-    ALOGD_IF(ese_debug_enabled, "Rnack retry_delay read from config file - %lu",
-             num);
+    NXP_LOG_ESE_D("Rnack retry_delay read from config file - %lu", num);
   } else {
     nxpese_ctxt.invalidFrame_Rnack_Delay = 7000;
   }
@@ -186,7 +185,7 @@
   } else /* OSU mode, no interface reset is required */
   {
     if (phNxpEse_doResetProtection(true)) {
-      ALOGE("%s Reset Potection failed. returning...", __FUNCTION__);
+      NXP_LOG_ESE_E("%s Reset Protection failed. returning...", __FUNCTION__);
       return ESESTATUS_FAILED;
     }
     protoInitParam.interfaceReset = false;
@@ -194,8 +193,8 @@
   if (EseConfig::hasKey(NAME_NXP_WTX_NTF_COUNT)) {
     num = EseConfig::getUnsigned(NAME_NXP_WTX_NTF_COUNT);
     protoInitParam.wtx_ntf_limit = num;
-    ALOGD_IF(ese_debug_enabled, "Wtx_ntf limit from config file - %lu",
-             protoInitParam.wtx_ntf_limit);
+    NXP_LOG_ESE_D("Wtx_ntf limit from config file - %lu",
+                  protoInitParam.wtx_ntf_limit);
   } else {
     protoInitParam.wtx_ntf_limit = PH_DEFAULT_WTX_NTF_LIMIT;
   }
@@ -204,18 +203,17 @@
   protoInitParam.pSecureTimerParams =
       (phNxpEseProto7816SecureTimer_t*)&nxpese_ctxt.secureTimerParams;
 
-  ALOGD_IF(ese_debug_enabled,
-           "%s secureTimer1 0x%x secureTimer2 0x%x secureTimer3 0x%x",
-           __FUNCTION__, nxpese_ctxt.secureTimerParams.secureTimer1,
-           nxpese_ctxt.secureTimerParams.secureTimer2,
-           nxpese_ctxt.secureTimerParams.secureTimer3);
+  NXP_LOG_ESE_D("%s secureTimer1 0x%x secureTimer2 0x%x secureTimer3 0x%x",
+                __FUNCTION__, nxpese_ctxt.secureTimerParams.secureTimer1,
+                nxpese_ctxt.secureTimerParams.secureTimer2,
+                nxpese_ctxt.secureTimerParams.secureTimer3);
 
   phNxpEse_GetMaxTimer(&maxTimer);
 #ifdef SPM_INTEGRATED
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     wConfigStatus = phNxpEse_SPM_DisablePwrControl(maxTimer);
     if (wConfigStatus != ESESTATUS_SUCCESS) {
-      ALOGE("%s phNxpEse_SPM_DisablePwrControl: failed", __FUNCTION__);
+      NXP_LOG_ESE_E("%s phNxpEse_SPM_DisablePwrControl: failed", __FUNCTION__);
     }
   }
 #endif
@@ -234,36 +232,37 @@
   }
 
   if (ESESTATUS_SUCCESS == wConfigStatus) {
-    ALOGD_IF(ese_debug_enabled, "phNxpEseProto7816_Open completed >>>>>");
+    NXP_LOG_ESE_D("phNxpEseProto7816_Open completed >>>>>");
     /* Retrieving the IFS-D value configured in the config file and applying to
      * Card */
     if ((nxpese_ctxt.endPointInfo == END_POINT_ESE) &&
         (EseConfig::hasKey(NAME_NXP_ESE_IFSD_VALUE))) {
       ifsd_value = EseConfig::getUnsigned(NAME_NXP_ESE_IFSD_VALUE);
       if ((0xFFFF > ifsd_value) && (ifsd_value > 0)) {
-        ALOGD_IF(ese_debug_enabled,
-                 "phNxpEseProto7816_SetIFS IFS adjustment requested with %ld",
-                 ifsd_value);
+        NXP_LOG_ESE_D(
+            "phNxpEseProto7816_SetIFS IFS adjustment requested with %ld",
+            ifsd_value);
         phNxpEse_setIfs(ifsd_value);
       } else {
-        ALOGD_IF(ese_debug_enabled,
-                 "phNxpEseProto7816_SetIFS IFS adjustment argument invalid");
+        NXP_LOG_ESE_D(
+            "phNxpEseProto7816_SetIFS IFS adjustment argument invalid");
       }
     } else if ((nxpese_ctxt.endPointInfo == END_POINT_EUICC) &&
                (EseConfig::hasKey(NAME_NXP_EUICC_IFSD_VALUE))) {
       ifsd_value = EseConfig::getUnsigned(NAME_NXP_EUICC_IFSD_VALUE);
       if ((0xFFFF > ifsd_value) && (ifsd_value > 0)) {
-        ALOGD_IF(ese_debug_enabled,
-                 "phNxpEseProto7816_SetIFS IFS adjustment requested with %ld",
-                 ifsd_value);
+        NXP_LOG_ESE_D(
+            "phNxpEseProto7816_SetIFS IFS adjustment requested with %ld",
+            ifsd_value);
         phNxpEse_setIfs(ifsd_value);
       } else {
-        ALOGD_IF(ese_debug_enabled,
-                 "phNxpEseProto7816_SetIFS IFS adjustment argument invalid");
+        NXP_LOG_ESE_D(
+            "phNxpEseProto7816_SetIFS IFS adjustment argument invalid");
       }
     }
   } else {
-    ALOGE("phNxpEseProto7816_Open failed with status = %x", wConfigStatus);
+    NXP_LOG_ESE_E("phNxpEseProto7816_Open failed with status = %x",
+                  wConfigStatus);
   }
 
   return wConfigStatus;
@@ -274,8 +273,8 @@
  *
  * Description      This function is called by Jni during the
  *                  initialization of the ESE. It opens the physical connection
- *                  with ESE and creates required NAME_NXP_MAX_RNACK_RETRYclient
- *                  thread for operation.
+ *                  with ESE and creates required NAME_NXP_MAX_RNACK_RETRY
+ *                  client thread for operation.
  * Returns          This function return ESESTATUS_SUCCESS (0) in case of
  *                  success. In case of failure returns other failure values.
  *
@@ -293,51 +292,50 @@
   /* initialize trace level */
   phNxpLog_InitializeLogLevel();
 
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_open Enter");
+  phPalEse_initTimer();
+
+  NXP_LOG_ESE_D("phNxpEse_open Enter");
   /*When spi channel is already opened return status as FAILED*/
   if (nxpese_ctxt.EseLibStatus != ESE_STATUS_CLOSE) {
-    ALOGD_IF(ese_debug_enabled, "already opened\n");
+    NXP_LOG_ESE_D("already opened\n");
     return ESESTATUS_BUSY;
   }
 
   phNxpEse_memset(&nxpese_ctxt, 0x00, sizeof(nxpese_ctxt));
   phNxpEse_memset(&tPalConfig, 0x00, sizeof(tPalConfig));
 
-  ALOGD_IF(ese_debug_enabled, "MW SEAccessKit Version");
-  ALOGD_IF(ese_debug_enabled, "Android Version:0x%x", NXP_ANDROID_VER);
-  ALOGD_IF(ese_debug_enabled, "Major Version:0x%x", ESELIB_MW_VERSION_MAJ);
-  ALOGD_IF(ese_debug_enabled, "Minor Version:0x%x", ESELIB_MW_VERSION_MIN);
+  NXP_LOG_ESE_D("MW SEAccessKit Version");
+  NXP_LOG_ESE_D("Android Version:0x%x", NXP_ANDROID_VER);
+  NXP_LOG_ESE_D("Major Version:0x%x", ESELIB_MW_VERSION_MAJ);
+  NXP_LOG_ESE_D("Minor Version:0x%x", ESELIB_MW_VERSION_MIN);
 
   if (EseConfig::hasKey(NAME_NXP_OS_VERSION)) {
     num = EseConfig::getUnsigned(NAME_NXP_OS_VERSION);
-    ALOGD_IF(ese_debug_enabled, "Chip type read from config file - %lu", num);
+    NXP_LOG_ESE_D("Chip type read from config file - %lu", num);
     sOsVersion = (num == 1) ? OS_VERSION_4_0
                             : ((num == 2) ? OS_VERSION_5_1 : OS_VERSION_5_2);
   } else {
     sOsVersion = OS_VERSION_5_2;
-    ALOGD_IF(ese_debug_enabled,
-             "Chip type not defined in config file osVersion- %d", sOsVersion);
+    NXP_LOG_ESE_D("Chip type not defined in config file osVersion- %d",
+                  sOsVersion);
   }
   if (EseConfig::hasKey(NAME_NXP_TP_MEASUREMENT)) {
     tpm_enable = EseConfig::getUnsigned(NAME_NXP_TP_MEASUREMENT);
-    ALOGD_IF(
-        ese_debug_enabled,
+    NXP_LOG_ESE_D(
         "SPI Throughput measurement enable/disable read from config file - %lu",
         tpm_enable);
   } else {
-    ALOGD_IF(ese_debug_enabled,
-             "SPI Throughput not defined in config file - %lu", tpm_enable);
+    NXP_LOG_ESE_D("SPI Throughput not defined in config file - %lu",
+                  tpm_enable);
   }
 #if (NXP_POWER_SCHEME_SUPPORT == true)
   if (EseConfig::hasKey(NAME_NXP_POWER_SCHEME)) {
     num = EseConfig::getUnsigned(NAME_NXP_POWER_SCHEME);
     nxpese_ctxt.pwr_scheme = num;
-    ALOGD_IF(ese_debug_enabled, "Power scheme read from config file - %lu",
-             num);
+    NXP_LOG_ESE_D("Power scheme read from config file - %lu", num);
   } else {
     nxpese_ctxt.pwr_scheme = PN67T_POWER_SCHEME;
-    ALOGD_IF(ese_debug_enabled, "Power scheme not defined in config file - %lu",
-             num);
+    NXP_LOG_ESE_D("Power scheme not defined in config file - %lu", num);
   }
 #else
   nxpese_ctxt.pwr_scheme = PN67T_POWER_SCHEME;
@@ -351,9 +349,9 @@
     nxpese_ctxt.nadPollingRetryTime = 5;
   }
 
-  ALOGD_IF(ese_debug_enabled, "Nad poll retry time in us - %lu us",
-           nxpese_ctxt.nadPollingRetryTime * GET_WAKE_UP_DELAY() *
-               NAD_POLLING_SCALER);
+  NXP_LOG_ESE_D("Nad poll retry time in us - %lu us",
+                nxpese_ctxt.nadPollingRetryTime * GET_WAKE_UP_DELAY() *
+                    NAD_POLLING_SCALER);
 
   /*Read device node path*/
   ese_node = EseConfig::getString(NAME_NXP_ESE_DEV_NODE, "/dev/pn81a");
@@ -363,18 +361,17 @@
   /* Initialize PAL layer */
   wConfigStatus = phPalEse_open_and_configure(&tPalConfig);
   if (wConfigStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phPalEse_Init Failed");
+    NXP_LOG_ESE_E("phPalEse_Init Failed");
     if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
       if (ESESTATUS_DRIVER_BUSY == wConfigStatus)
-        ALOGE("Ese Driver is Busy!!!");
+        NXP_LOG_ESE_E("Ese Driver is Busy!!!");
     }
     goto clean_and_return;
   }
   /* Copying device handle to ESE Lib context*/
   nxpese_ctxt.pDevHandle = tPalConfig.pDevHandle;
   if (ESE_PROTOCOL_MEDIA_SPI == initParams.mediaType) {
-    ALOGD_IF(ese_debug_enabled,
-             "Inform eSE about the starting of trusted Mode");
+    NXP_LOG_ESE_D("Inform eSE about the starting of trusted Mode");
     wConfigStatus =
         phPalEse_ioctl(phPalEse_e_SetSecureMode, tPalConfig.pDevHandle, 0x01);
     if (ESESTATUS_SUCCESS != wConfigStatus) goto clean_and_return_2;
@@ -383,41 +380,42 @@
   /* Get the Access of ESE*/
   wSpmStatus = phNxpEse_SPM_Init(nxpese_ctxt.pDevHandle);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_Init Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_Init Failed");
     wConfigStatus = ESESTATUS_FAILED;
     goto clean_and_return_2;
   }
   wSpmStatus = phNxpEse_SPM_SetPwrScheme(nxpese_ctxt.pwr_scheme);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE(" %s : phNxpEse_SPM_SetPwrScheme Failed", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s : phNxpEse_SPM_SetPwrScheme Failed", __FUNCTION__);
     wConfigStatus = ESESTATUS_FAILED;
     goto clean_and_return_1;
   }
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     wConfigStatus = phNxpEse_checkFWDwnldStatus();
     if (wConfigStatus != ESESTATUS_SUCCESS) {
-      ALOGE("Failed to open SPI due to VEN pin used by FW download \n");
+      NXP_LOG_ESE_E("Failed to open SPI due to VEN pin used by FW download \n");
       wConfigStatus = ESESTATUS_FAILED;
       goto clean_and_return_1;
     }
   }
   wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
     wConfigStatus = ESESTATUS_FAILED;
     goto clean_and_return_1;
   } else {
     if (((current_spm_state & SPM_STATE_SPI) |
          (current_spm_state & SPM_STATE_SPI_PRIO)) &&
         !(current_spm_state & SPM_STATE_SPI_FAILED)) {
-      ALOGE(" %s : SPI is already opened...second instance not allowed",
-            __FUNCTION__);
+      NXP_LOG_ESE_E(" %s : SPI is already opened...second instance not allowed",
+                    __FUNCTION__);
       wConfigStatus = ESESTATUS_FAILED;
       goto clean_and_return_1;
     }
   }
   if (current_spm_state & SPM_STATE_JCOP_DWNLD) {
-    ALOGE(" %s : Denying to open JCOP Download in progress", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s : Denying to open JCOP Download in progress",
+                  __FUNCTION__);
     wConfigStatus = ESESTATUS_FAILED;
     goto clean_and_return_1;
   }
@@ -426,17 +424,17 @@
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     /* Updating ESE power state based on the init mode */
     if (ESE_MODE_OSU == nxpese_ctxt.initParams.initMode) {
-      ALOGD_IF(ese_debug_enabled, "%s Init mode ---->OSU", __FUNCTION__);
+      NXP_LOG_ESE_D("%s Init mode ---->OSU", __FUNCTION__);
       wConfigStatus = phNxpEse_checkJcopDwnldState();
       if (wConfigStatus != ESESTATUS_SUCCESS) {
-        ALOGE("phNxpEse_checkJcopDwnldState failed");
+        NXP_LOG_ESE_E("phNxpEse_checkJcopDwnldState failed");
         goto clean_and_return_1;
       }
     }
   }
   wSpmStatus = phNxpEse_SPM_ConfigPwr(SPM_POWER_ENABLE);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_ConfigPwr: enabling power Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_ConfigPwr: enabling power Failed");
     if (wSpmStatus == ESESTATUS_BUSY) {
       wConfigStatus = ESESTATUS_BUSY;
     } else if (wSpmStatus == ESESTATUS_DWNLD_BUSY) {
@@ -446,7 +444,7 @@
     }
     goto clean_and_return;
   } else {
-    ALOGD_IF(ese_debug_enabled, "nxpese_ctxt.spm_power_state true");
+    NXP_LOG_ESE_D("nxpese_ctxt.spm_power_state true");
     nxpese_ctxt.spm_power_state = true;
   }
 #endif
@@ -455,19 +453,19 @@
       wConfigStatus = phPalEse_ioctl(phPalEse_e_EnableThroughputMeasurement,
                                      nxpese_ctxt.pDevHandle, 0);
       if (wConfigStatus != ESESTATUS_SUCCESS) {
-        ALOGE("phPalEse_IoCtl Failed");
+        NXP_LOG_ESE_E("phPalEse_IoCtl Failed");
         goto clean_and_return;
       }
     }
   }
-  ALOGD_IF(ese_debug_enabled, "wConfigStatus %x", wConfigStatus);
+  NXP_LOG_ESE_D("wConfigStatus %x", wConfigStatus);
   return wConfigStatus;
 
 clean_and_return:
 #ifdef SPM_INTEGRATED
   wSpmStatus = phNxpEse_SPM_ConfigPwr(SPM_POWER_DISABLE);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_ConfigPwr: disabling power Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_ConfigPwr: disabling power Failed");
   }
 clean_and_return_1:
   phNxpEse_SPM_DeInit();
@@ -513,7 +511,7 @@
 
   /* initialize trace level */
   phNxpLog_InitializeLogLevel();
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_openPrioSession Enter");
+  NXP_LOG_ESE_D("phNxpEse_openPrioSession Enter");
 #ifdef SPM_INTEGRATED
   ESESTATUS wSpmStatus = ESESTATUS_SUCCESS;
   spm_state_t current_spm_state = SPM_STATE_INVALID;
@@ -521,33 +519,29 @@
   phNxpEse_memset(&nxpese_ctxt, 0x00, sizeof(nxpese_ctxt));
   phNxpEse_memset(&tPalConfig, 0x00, sizeof(tPalConfig));
 
-  ALOGD_IF(ese_debug_enabled, "MW SEAccessKit Version");
-  ALOGD_IF(ese_debug_enabled, "Android Version:0x%x", NXP_ANDROID_VER);
-  ALOGD_IF(ese_debug_enabled, "Major Version:0x%x", ESELIB_MW_VERSION_MAJ);
-  ALOGD_IF(ese_debug_enabled, "Minor Version:0x%x", ESELIB_MW_VERSION_MIN);
+  NXP_LOG_ESE_D("MW SEAccessKit Version");
+  NXP_LOG_ESE_D("Android Version:0x%x", NXP_ANDROID_VER);
+  NXP_LOG_ESE_D("Major Version:0x%x", ESELIB_MW_VERSION_MAJ);
+  NXP_LOG_ESE_D("Minor Version:0x%x", ESELIB_MW_VERSION_MIN);
 
 #if (NXP_POWER_SCHEME_SUPPORT == true)
   if (EseConfig::hasKey(NAME_NXP_POWER_SCHEME)) {
     num = EseConfig::getUnsigned(NAME_NXP_POWER_SCHEME);
     nxpese_ctxt.pwr_scheme = num;
-    ALOGD_IF(ese_debug_enabled, "Power scheme read from config file - %lu",
-             num);
+    NXP_LOG_ESE_D("Power scheme read from config file - %lu", num);
   } else
 #endif
   {
     nxpese_ctxt.pwr_scheme = PN67T_POWER_SCHEME;
-    ALOGD_IF(ese_debug_enabled, "Power scheme not defined in config file - %lu",
-             num);
+    NXP_LOG_ESE_D("Power scheme not defined in config file - %lu", num);
   }
   if (EseConfig::hasKey(NAME_NXP_TP_MEASUREMENT)) {
     tpm_enable = EseConfig::getUnsigned(NAME_NXP_TP_MEASUREMENT);
-    ALOGD_IF(
-        ese_debug_enabled,
+    NXP_LOG_ESE_D(
         "SPI Throughput measurement enable/disable read from config file - %lu",
         tpm_enable);
   } else {
-    ALOGD_IF(ese_debug_enabled,
-             "SPI Throughput not defined in config file - %lu", num);
+    NXP_LOG_ESE_D("SPI Throughput not defined in config file - %lu", num);
   }
 
   tPalConfig.pDevName = (int8_t*)"/dev/p73";
@@ -555,7 +549,7 @@
   /* Initialize PAL layer */
   wConfigStatus = phPalEse_open_and_configure(&tPalConfig);
   if (wConfigStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phPalEse_Init Failed");
+    NXP_LOG_ESE_E("phPalEse_Init Failed");
     goto clean_and_return;
   }
   /* Copying device handle to hal context*/
@@ -565,39 +559,40 @@
   /* Get the Access of ESE*/
   wSpmStatus = phNxpEse_SPM_Init(nxpese_ctxt.pDevHandle);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_Init Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_Init Failed");
     wConfigStatus = ESESTATUS_FAILED;
     goto clean_and_return_2;
   }
   wSpmStatus = phNxpEse_SPM_SetPwrScheme(nxpese_ctxt.pwr_scheme);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE(" %s : phNxpEse_SPM_SetPwrScheme Failed", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s : phNxpEse_SPM_SetPwrScheme Failed", __FUNCTION__);
     wConfigStatus = ESESTATUS_FAILED;
     goto clean_and_return_1;
   }
   wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
     wConfigStatus = ESESTATUS_FAILED;
     goto clean_and_return_1;
   } else {
     if ((current_spm_state & SPM_STATE_SPI) |
         (current_spm_state & SPM_STATE_SPI_PRIO)) {
-      ALOGE(" %s : SPI is already opened...second instance not allowed",
-            __FUNCTION__);
+      NXP_LOG_ESE_E(" %s : SPI is already opened...second instance not allowed",
+                    __FUNCTION__);
       wConfigStatus = ESESTATUS_FAILED;
       goto clean_and_return_1;
     }
     if (current_spm_state & SPM_STATE_JCOP_DWNLD) {
-      ALOGE(" %s : Denying to open JCOP Download in progress", __FUNCTION__);
+      NXP_LOG_ESE_E(" %s : Denying to open JCOP Download in progress",
+                    __FUNCTION__);
       wConfigStatus = ESESTATUS_FAILED;
       goto clean_and_return_1;
     }
     if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
       wConfigStatus = phNxpEse_checkFWDwnldStatus();
       if (wConfigStatus != ESESTATUS_SUCCESS) {
-        ALOGD_IF(ese_debug_enabled,
-                 "Failed to open SPI due to VEN pin used by FW download \n");
+        NXP_LOG_ESE_D(
+            "Failed to open SPI due to VEN pin used by FW download \n");
         wConfigStatus = ESESTATUS_FAILED;
         goto clean_and_return_1;
       }
@@ -610,14 +605,14 @@
     if (ESE_MODE_OSU == nxpese_ctxt.initParams.initMode) {
       wConfigStatus = phNxpEse_checkJcopDwnldState();
       if (wConfigStatus != ESESTATUS_SUCCESS) {
-        ALOGE("phNxpEse_checkJcopDwnldState failed");
+        NXP_LOG_ESE_E("phNxpEse_checkJcopDwnldState failed");
         goto clean_and_return_1;
       }
     }
   }
   wSpmStatus = phNxpEse_SPM_ConfigPwr(SPM_POWER_PRIO_ENABLE);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_ConfigPwr: enabling power for spi prio Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_ConfigPwr: enabling power for spi prio Failed");
     if (wSpmStatus == ESESTATUS_BUSY) {
       wConfigStatus = ESESTATUS_BUSY;
     } else if (wSpmStatus == ESESTATUS_DWNLD_BUSY) {
@@ -627,7 +622,7 @@
     }
     goto clean_and_return;
   } else {
-    ALOGE("nxpese_ctxt.spm_power_state true");
+    NXP_LOG_ESE_E("nxpese_ctxt.spm_power_state true");
     nxpese_ctxt.spm_power_state = true;
   }
 #endif
@@ -636,29 +631,29 @@
   wConfigStatus =
       phPalEse_ioctl(phPalEse_e_ResetDevice, nxpese_ctxt.pDevHandle, 2);
   if (wConfigStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phPalEse_IoCtl Failed");
+    NXP_LOG_ESE_E("phPalEse_IoCtl Failed");
     goto clean_and_return;
   }
 #endif
   wConfigStatus =
       phPalEse_ioctl(phPalEse_e_EnableLog, nxpese_ctxt.pDevHandle, 0);
   if (wConfigStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phPalEse_IoCtl Failed");
+    NXP_LOG_ESE_E("phPalEse_IoCtl Failed");
     goto clean_and_return;
   }
   wConfigStatus =
       phPalEse_ioctl(phPalEse_e_EnablePollMode, nxpese_ctxt.pDevHandle, 1);
   if (wConfigStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phPalEse_IoCtl Failed");
+    NXP_LOG_ESE_E("phPalEse_IoCtl Failed");
     goto clean_and_return;
   }
-  ALOGD_IF(ese_debug_enabled, "wConfigStatus %x", wConfigStatus);
+  NXP_LOG_ESE_D("wConfigStatus %x", wConfigStatus);
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     if (tpm_enable) {
       wConfigStatus = phPalEse_ioctl(phPalEse_e_EnableThroughputMeasurement,
                                      nxpese_ctxt.pDevHandle, 0);
       if (wConfigStatus != ESESTATUS_SUCCESS) {
-        ALOGE("phPalEse_IoCtl Failed");
+        NXP_LOG_ESE_E("phPalEse_IoCtl Failed");
         goto clean_and_return;
       }
     }
@@ -669,7 +664,7 @@
 #ifdef SPM_INTEGRATED
   wSpmStatus = phNxpEse_SPM_ConfigPwr(SPM_POWER_DISABLE);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_ConfigPwr: disabling power Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_ConfigPwr: disabling power Failed");
   }
 clean_and_return_1:
   phNxpEse_SPM_DeInit();
@@ -695,12 +690,12 @@
  ******************************************************************************/
 static ESESTATUS phNxpEse_setJcopDwnldState(phNxpEse_JcopDwnldState state) {
   ESESTATUS wConfigStatus = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_setJcopDwnldState Enter");
+  NXP_LOG_ESE_D("phNxpEse_setJcopDwnldState Enter");
 
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     wConfigStatus = phNxpEse_SPM_SetJcopDwnldState(state);
   } else {
-    ALOGE("%s function not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s function not supported", __FUNCTION__);
   }
   return wConfigStatus;
 }
@@ -715,7 +710,7 @@
  *
  ******************************************************************************/
 static ESESTATUS phNxpEse_checkJcopDwnldState(void) {
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_checkJcopDwnld Enter");
+  NXP_LOG_ESE_D("phNxpEse_checkJcopDwnld Enter");
   ESESTATUS wSpmStatus = ESESTATUS_SUCCESS;
   spm_state_t current_spm_state = SPM_STATE_INVALID;
   uint8_t ese_dwnld_retry = 0x00;
@@ -731,7 +726,7 @@
     status = phNxpEse_setJcopDwnldState(JCP_DWNLD_INIT);
     if (status == ESESTATUS_SUCCESS) {
       while (ese_dwnld_retry < ESE_JCOP_OS_DWNLD_RETRY_CNT) {
-        ALOGD_IF(ese_debug_enabled, "ESE_JCOP_OS_DWNLD_RETRY_CNT retry count");
+        NXP_LOG_ESE_D("ESE_JCOP_OS_DWNLD_RETRY_CNT retry count");
         wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
         if (wSpmStatus == ESESTATUS_SUCCESS) {
           if ((current_spm_state & SPM_STATE_JCOP_DWNLD)) {
@@ -749,7 +744,7 @@
     }
   }
 
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_checkJcopDwnldState status %x", status);
+  NXP_LOG_ESE_D("phNxpEse_checkJcopDwnldState status %x", status);
   return status;
 }
 
@@ -767,26 +762,27 @@
   if ((NULL == pCmd) || (NULL == pRsp)) return ESESTATUS_INVALID_PARAMETER;
 
   if ((pCmd->len == 0) || pCmd->p_data == NULL) {
-    ALOGE(" phNxpEse_Transceive - Invalid Parameter no data\n");
+    NXP_LOG_ESE_E(" phNxpEse_Transceive - Invalid Parameter no data\n");
     return ESESTATUS_INVALID_PARAMETER;
   } else if (pCmd->len > MAX_SUPPORTED_DATA_SIZE) {
-    ALOGE(" phNxpEse_Transceive - Invalid data size \n");
+    NXP_LOG_ESE_E(" phNxpEse_Transceive - Invalid data size \n");
     return ESESTATUS_INVALID_RECEIVE_LENGTH;
   } else if ((ESE_STATUS_CLOSE == nxpese_ctxt.EseLibStatus)) {
-    ALOGE(" %s ESE Not Initialized \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s ESE Not Initialized \n", __FUNCTION__);
     return ESESTATUS_NOT_INITIALISED;
   } else if ((ESE_STATUS_BUSY == nxpese_ctxt.EseLibStatus)) {
-    ALOGE(" %s ESE - BUSY \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s ESE - BUSY \n", __FUNCTION__);
     return ESESTATUS_BUSY;
   } else if ((ESE_STATUS_RECOVERY == nxpese_ctxt.EseLibStatus)) {
-    ALOGE(" %s ESE - RECOVERY \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s ESE - RECOVERY \n", __FUNCTION__);
     return ESESTATUS_RECOVERY_STARTED;
   } else {
     nxpese_ctxt.EseLibStatus = ESE_STATUS_BUSY;
     status = phNxpEseProto7816_Transceive((phNxpEse_data*)pCmd,
                                           (phNxpEse_data*)pRsp);
     if (ESESTATUS_SUCCESS != status) {
-      ALOGE(" %s phNxpEseProto7816_Transceive- Failed \n", __FUNCTION__);
+      NXP_LOG_ESE_E(" %s phNxpEseProto7816_Transceive- Failed \n",
+                    __FUNCTION__);
       if (ESESTATUS_TRANSCEIVE_FAILED == status) {
         /*MAX WTX reached*/
         nxpese_ctxt.EseLibStatus = ESE_STATUS_RECOVERY;
@@ -799,8 +795,7 @@
     }
     nxpese_ctxt.rnack_sent = false;
 
-    ALOGD_IF(ese_debug_enabled, " %s Exit status 0x%x \n", __FUNCTION__,
-             status);
+    NXP_LOG_ESE_D(" %s Exit status 0x%x \n", __FUNCTION__, status);
     return status;
   }
 }
@@ -821,15 +816,14 @@
  ******************************************************************************/
 ESESTATUS phNxpEse_coldReset(void) {
   ESESTATUS wSpmStatus = ESESTATUS_SUCCESS;
-  ALOGD_IF(ese_debug_enabled, " %s Enter \n", __FUNCTION__);
+  NXP_LOG_ESE_D(" %s Enter \n", __FUNCTION__);
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
     wSpmStatus = phNxpEse_SPM_ConfigPwr(SPM_RECOVERY_RESET);
   } else {
     wSpmStatus = ESESTATUS_FAILED;
-    ALOGE(" %s Function not supported \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s Function not supported \n", __FUNCTION__);
   }
-  ALOGD_IF(ese_debug_enabled, " %s Exit status 0x%x \n", __FUNCTION__,
-           wSpmStatus);
+  NXP_LOG_ESE_D(" %s Exit status 0x%x \n", __FUNCTION__, wSpmStatus);
   return wSpmStatus;
 }
 
@@ -850,33 +844,32 @@
 #endif
 
   /* TBD : Call the ioctl to reset the ESE */
-  ALOGD_IF(ese_debug_enabled, " %s Enter \n", __FUNCTION__);
+  NXP_LOG_ESE_D(" %s Enter \n", __FUNCTION__);
   /* Do an interface reset, don't wait to see if JCOP went through a full power
    * cycle or not */
   status = phNxpEseProto7816_IntfReset(
       (phNxpEseProto7816SecureTimer_t*)&nxpese_ctxt.secureTimerParams);
   if (status) {
-    ALOGE("%s Ese status Failed", __FUNCTION__);
+    NXP_LOG_ESE_E("%s Ese status Failed", __FUNCTION__);
   }
 
-  ALOGD_IF(ese_debug_enabled,
-           "%s secureTimer1 0x%x secureTimer2 0x%x secureTimer3 0x%x",
-           __FUNCTION__, nxpese_ctxt.secureTimerParams.secureTimer1,
-           nxpese_ctxt.secureTimerParams.secureTimer2,
-           nxpese_ctxt.secureTimerParams.secureTimer3);
+  NXP_LOG_ESE_D("%s secureTimer1 0x%x secureTimer2 0x%x secureTimer3 0x%x",
+                __FUNCTION__, nxpese_ctxt.secureTimerParams.secureTimer1,
+                nxpese_ctxt.secureTimerParams.secureTimer2,
+                nxpese_ctxt.secureTimerParams.secureTimer3);
   phNxpEse_GetMaxTimer(&maxTimer);
 #ifdef SPM_INTEGRATED
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     status = phNxpEse_SPM_DisablePwrControl(maxTimer);
     if (status != ESESTATUS_SUCCESS) {
-      ALOGE("%s phNxpEse_SPM_DisablePwrControl: failed", __FUNCTION__);
+      NXP_LOG_ESE_E("%s phNxpEse_SPM_DisablePwrControl: failed", __FUNCTION__);
     }
   }
   if ((nxpese_ctxt.pwr_scheme == PN67T_POWER_SCHEME) ||
       (nxpese_ctxt.pwr_scheme == PN80T_LEGACY_SCHEME)) {
     wSpmStatus = phNxpEse_SPM_ConfigPwr(SPM_POWER_RESET);
     if (wSpmStatus != ESESTATUS_SUCCESS) {
-      ALOGE("phNxpEse_SPM_ConfigPwr: reset Failed");
+      NXP_LOG_ESE_E("phNxpEse_SPM_ConfigPwr: reset Failed");
     }
   }
 #else
@@ -885,10 +878,10 @@
    */
   status = phPalEse_ioctl(phPalEse_e_ResetDevice, nxpese_ctxt.pDevHandle, 2);
   if (status != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_reset Failed");
+    NXP_LOG_ESE_E("phNxpEse_reset Failed");
   }
 #endif
-  ALOGD_IF(ese_debug_enabled, " %s Exit \n", __FUNCTION__);
+  NXP_LOG_ESE_D(" %s Exit \n", __FUNCTION__);
   return status;
 }
 
@@ -909,7 +902,7 @@
 #endif
 
   /* TBD : Call the ioctl to reset the  */
-  ALOGD_IF(ese_debug_enabled, " %s Enter \n", __FUNCTION__);
+  NXP_LOG_ESE_D(" %s Enter \n", __FUNCTION__);
 
   /* Reset interface after every reset irrespective of
   whether JCOP did a full power cycle or not. */
@@ -924,13 +917,12 @@
     unsigned long int ifsd_value = 0;
     ifsd_value = EseConfig::getUnsigned(NAME_NXP_ESE_IFSD_VALUE);
     if ((0xFFFF > ifsd_value) && (ifsd_value > 0)) {
-      ALOGD_IF(ese_debug_enabled,
-               "phNxpEseProto7816_SetIFS IFS adjustment requested with %ld",
-               ifsd_value);
+      NXP_LOG_ESE_D(
+          "phNxpEseProto7816_SetIFS IFS adjustment requested with %ld",
+          ifsd_value);
       phNxpEse_setIfs(ifsd_value);
     } else {
-      ALOGD_IF(ese_debug_enabled,
-               "phNxpEseProto7816_SetIFS IFS adjustment argument invalid");
+      NXP_LOG_ESE_D("phNxpEseProto7816_SetIFS IFS adjustment argument invalid");
     }
   }
 #ifdef SPM_INTEGRATED
@@ -938,28 +930,28 @@
   if (EseConfig::hasKey(NAME_NXP_POWER_SCHEME)) {
     num = EseConfig::getUnsigned(NAME_NXP_POWER_SCHEME);
     if ((num == 1) || (num == 2)) {
-      ALOGD_IF(ese_debug_enabled, " %s Call Config Pwr Reset \n", __FUNCTION__);
+      NXP_LOG_ESE_D(" %s Call Config Pwr Reset \n", __FUNCTION__);
       status = phNxpEse_SPM_ConfigPwr(SPM_POWER_RESET);
       if (status != ESESTATUS_SUCCESS) {
-        ALOGE("phNxpEse_resetJcopUpdate: reset Failed");
+        NXP_LOG_ESE_E("phNxpEse_resetJcopUpdate: reset Failed");
         status = ESESTATUS_FAILED;
       }
     } else if (num == 3) {
-      ALOGD_IF(ese_debug_enabled, " %s Call eSE Chip Reset \n", __FUNCTION__);
+      NXP_LOG_ESE_D(" %s Call eSE Chip Reset \n", __FUNCTION__);
       status = phNxpEse_chipReset();
       if (status != ESESTATUS_SUCCESS) {
-        ALOGE("phNxpEse_resetJcopUpdate: chip reset Failed");
+        NXP_LOG_ESE_E("phNxpEse_resetJcopUpdate: chip reset Failed");
         status = ESESTATUS_FAILED;
       }
     } else {
-      ALOGD_IF(ese_debug_enabled, " %s Invalid Power scheme \n", __FUNCTION__);
+      NXP_LOG_ESE_D(" %s Invalid Power scheme \n", __FUNCTION__);
     }
   }
 #else
   {
     status = phNxpEse_SPM_ConfigPwr(SPM_POWER_RESET);
     if (status != ESESTATUS_SUCCESS) {
-      ALOGE("phNxpEse_SPM_ConfigPwr: reset Failed");
+      NXP_LOG_ESE_E("phNxpEse_SPM_ConfigPwr: reset Failed");
       status = ESESTATUS_FAILED;
     }
   }
@@ -970,11 +962,11 @@
    */
   status = phPalEse_ioctl(phPalEse_e_ResetDevice, nxpese_ctxt.pDevHandle, 2);
   if (status != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_resetJcopUpdate Failed");
+    NXP_LOG_ESE_E("phNxpEse_resetJcopUpdate Failed");
   }
 #endif
 
-  ALOGD_IF(ese_debug_enabled, " %s Exit \n", __FUNCTION__);
+  NXP_LOG_ESE_D(" %s Exit \n", __FUNCTION__);
   return status;
 }
 /******************************************************************************
@@ -1011,15 +1003,15 @@
   if (nxpese_ctxt.pwr_scheme == PN80T_EXT_PMU_SCHEME) {
     bStatus = phNxpEseProto7816_Reset();
     if (!bStatus) {
-      ALOGE("Inside phNxpEse_chipReset, phNxpEseProto7816_Reset Failed");
+      NXP_LOG_ESE_E(
+          "Inside phNxpEse_chipReset, phNxpEseProto7816_Reset Failed");
     }
     status = phPalEse_ioctl(phPalEse_e_ChipRst, nxpese_ctxt.pDevHandle, 6);
     if (status != ESESTATUS_SUCCESS) {
-      ALOGE("phNxpEse_chipReset  Failed");
+      NXP_LOG_ESE_E("phNxpEse_chipReset  Failed");
     }
   } else {
-    ALOGD_IF(ese_debug_enabled,
-             "phNxpEse_chipReset is not supported in legacy power scheme");
+    NXP_LOG_ESE_D("phNxpEse_chipReset is not supported in legacy power scheme");
   }
   return status;
 }
@@ -1060,16 +1052,15 @@
  ******************************************************************************/
 ESESTATUS phNxpEse_doResetProtection(bool flag) {
   ESESTATUS wSpmStatus = ESESTATUS_SUCCESS;
-  ALOGD_IF(ese_debug_enabled, " %s Enter \n", __FUNCTION__);
+  NXP_LOG_ESE_D(" %s Enter \n", __FUNCTION__);
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
     wSpmStatus = phPalEse_ioctl(phPalEse_e_ResetProtection,
                                 nxpese_ctxt.pDevHandle, flag);
   } else {
     wSpmStatus = ESESTATUS_FAILED;
-    ALOGE(" %s Function not supported \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s Function not supported \n", __FUNCTION__);
   }
-  ALOGD_IF(ese_debug_enabled, " %s Exit status 0x%x \n", __FUNCTION__,
-           wSpmStatus);
+  NXP_LOG_ESE_D(" %s Exit status 0x%x \n", __FUNCTION__, wSpmStatus);
   return wSpmStatus;
 }
 
@@ -1103,24 +1094,23 @@
     status = phNxpEseProto7816_Close(
         (phNxpEseProto7816SecureTimer_t*)&nxpese_ctxt.secureTimerParams);
     if (status == ESESTATUS_SUCCESS) {
-      ALOGD_IF(ese_debug_enabled,
-               "%s secureTimer1 0x%x secureTimer2 0x%x secureTimer3 0x%x",
-               __FUNCTION__, nxpese_ctxt.secureTimerParams.secureTimer1,
-               nxpese_ctxt.secureTimerParams.secureTimer2,
-               nxpese_ctxt.secureTimerParams.secureTimer3);
+      NXP_LOG_ESE_D("%s secureTimer1 0x%x secureTimer2 0x%x secureTimer3 0x%x",
+                    __FUNCTION__, nxpese_ctxt.secureTimerParams.secureTimer1,
+                    nxpese_ctxt.secureTimerParams.secureTimer2,
+                    nxpese_ctxt.secureTimerParams.secureTimer3);
       phNxpEse_GetMaxTimer(&maxTimer);
 #ifdef SPM_INTEGRATED
       if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
         status = phNxpEse_SPM_DisablePwrControl(maxTimer);
         if (status != ESESTATUS_SUCCESS) {
-          ALOGE("%s phNxpEseP61_DisablePwrCntrl: failed", __FUNCTION__);
+          NXP_LOG_ESE_E("%s phNxpEseP61_DisablePwrCntrl: failed", __FUNCTION__);
         }
       } else {
-        ALOGD_IF(ese_debug_enabled, "Interface reset for DPD");
+        NXP_LOG_ESE_D("Interface reset for DPD");
         status = phNxpEseProto7816_IntfReset(
             (phNxpEseProto7816SecureTimer_t*)&nxpese_ctxt.secureTimerParams);
         if (status != ESESTATUS_SUCCESS) {
-          ALOGE("%s IntfReset Failed ", __FUNCTION__);
+          NXP_LOG_ESE_E("%s IntfReset Failed ", __FUNCTION__);
         }
       }
 #endif
@@ -1140,9 +1130,12 @@
  ******************************************************************************/
 ESESTATUS phNxpEse_close(ESESTATUS deInitStatus) {
   ESESTATUS status = ESESTATUS_SUCCESS;
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_close Enter");
+  NXP_LOG_ESE_D("phNxpEse_close Enter");
+
+  phPalEse_deInitTimer();
+
   if ((ESE_STATUS_CLOSE == nxpese_ctxt.EseLibStatus)) {
-    ALOGE(" %s ESE Not Initialized \n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s ESE Not Initialized \n", __FUNCTION__);
     return ESESTATUS_NOT_INITIALISED;
   }
 
@@ -1154,7 +1147,7 @@
   /* Release the Access of  */
   wSpmStatus = phNxpEse_SPM_ConfigPwr(SPM_POWER_DISABLE);
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_ConfigPwr: disabling power Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_ConfigPwr: disabling power Failed");
   } else {
     nxpese_ctxt.spm_power_state = false;
   }
@@ -1163,35 +1156,35 @@
     if (ESE_MODE_OSU == nxpese_ctxt.initParams.initMode) {
       status = phNxpEse_setJcopDwnldState(JCP_SPI_DWNLD_COMPLETE);
       if (status != ESESTATUS_SUCCESS) {
-        ALOGE("%s: phNxpEse_setJcopDwnldState failed", __FUNCTION__);
+        NXP_LOG_ESE_E("%s: phNxpEse_setJcopDwnldState failed", __FUNCTION__);
       }
     }
   } else {
     if (NULL != nxpese_ctxt.pDevHandle) {
       if (ESE_PROTOCOL_MEDIA_SPI == nxpese_ctxt.initParams.mediaType) {
-        ALOGD_IF(ese_debug_enabled, "Inform eSE that trusted Mode is over");
+        NXP_LOG_ESE_D("Inform eSE that trusted Mode is over");
         status = phPalEse_ioctl(phPalEse_e_SetSecureMode,
                                 nxpese_ctxt.pDevHandle, 0x00);
         if (status != ESESTATUS_SUCCESS) {
-          ALOGE("%s: phPalEse_e_SetSecureMode failed", __FUNCTION__);
+          NXP_LOG_ESE_E("%s: phPalEse_e_SetSecureMode failed", __FUNCTION__);
         }
         if (ESESTATUS_SUCCESS != phNxpEseProto7816_CloseAllSessions()) {
-          ALOGD_IF(ese_debug_enabled, "eSE not responding perform hard reset");
+          NXP_LOG_ESE_D("eSE not responding perform hard reset");
           phNxpEse_SPM_ConfigPwr(SPM_RECOVERY_RESET);
         }
       } else {
         if (nxpese_ctxt.EseLibStatus == ESE_STATUS_RECOVERY ||
             (deInitStatus == ESESTATUS_RESPONSE_TIMEOUT) ||
             ESESTATUS_SUCCESS != phNxpEseProto7816_CloseAllSessions()) {
-          ALOGD_IF(ese_debug_enabled, "eSE not responding perform hard reset");
+          NXP_LOG_ESE_D("eSE not responding perform hard reset");
           phNxpEse_SPM_ConfigPwr(SPM_RECOVERY_RESET);
         }
       }
-      ALOGD_IF(ese_debug_enabled, "Interface reset for DPD");
+      NXP_LOG_ESE_D("Interface reset for DPD");
       status = phNxpEseProto7816_IntfReset(
           (phNxpEseProto7816SecureTimer_t*)&nxpese_ctxt.secureTimerParams);
       if (status == ESESTATUS_TRANSCEIVE_FAILED || status == ESESTATUS_FAILED) {
-        ALOGE("%s IntfReset Failed, perform hard reset", __FUNCTION__);
+        NXP_LOG_ESE_E("%s IntfReset Failed, perform hard reset", __FUNCTION__);
         // max wtx or no response of interface reset after protocol recovery
         phNxpEse_SPM_ConfigPwr(SPM_RECOVERY_RESET);
       }
@@ -1200,14 +1193,13 @@
 
   wSpmStatus = phNxpEse_SPM_DeInit();
   if (wSpmStatus != ESESTATUS_SUCCESS) {
-    ALOGE("phNxpEse_SPM_DeInit Failed");
+    NXP_LOG_ESE_E("phNxpEse_SPM_DeInit Failed");
   }
 #endif
   if (NULL != nxpese_ctxt.pDevHandle) {
     phPalEse_close(nxpese_ctxt.pDevHandle);
     phNxpEse_memset(&nxpese_ctxt, 0x00, sizeof(nxpese_ctxt));
-    ALOGD_IF(ese_debug_enabled,
-             "phNxpEse_close - ESE Context deinit completed");
+    NXP_LOG_ESE_D("phNxpEse_close - ESE Context deinit completed");
   }
   /* Return success always */
   return status;
@@ -1230,23 +1222,31 @@
   ESESTATUS status = ESESTATUS_SUCCESS;
   int ret = -1;
 
-  ALOGD_IF(ese_debug_enabled, "%s Enter ..", __FUNCTION__);
+  NXP_LOG_ESE_D("%s Enter ..", __FUNCTION__);
 
   ret = phNxpEse_readPacket(nxpese_ctxt.pDevHandle, nxpese_ctxt.p_read_buff,
                             MAX_DATA_LEN);
   if (ret < 0) {
-    ALOGE("PAL Read status error status = %x", status);
+    NXP_LOG_ESE_E("PAL Read status error status = %x", status);
     *data_len = 2;
     *pp_data = nxpese_ctxt.p_read_buff;
     status = ESESTATUS_FAILED;
   } else {
-    PH_PAL_ESE_PRINT_PACKET_RX(nxpese_ctxt.p_read_buff, (uint16_t)ret);
+    if (ret > MAX_DATA_LEN) {
+      NXP_LOG_ESE_E(
+          "%s PAL Read buffer length(%x) is greater than MAX_DATA_LEN(%x) ",
+          __FUNCTION__, ret, MAX_DATA_LEN);
+      PH_PAL_ESE_PRINT_PACKET_RX(nxpese_ctxt.p_read_buff,
+                                 (uint16_t)MAX_DATA_LEN);
+    } else {
+      PH_PAL_ESE_PRINT_PACKET_RX(nxpese_ctxt.p_read_buff, (uint16_t)ret);
+    }
     *data_len = ret;
     *pp_data = nxpese_ctxt.p_read_buff;
     status = ESESTATUS_SUCCESS;
   }
 
-  ALOGD_IF(ese_debug_enabled, "%s Exit", __FUNCTION__);
+  NXP_LOG_ESE_D("%s Exit", __FUNCTION__);
   return status;
 }
 
@@ -1267,12 +1267,12 @@
   int sof_counter = 0; /* one read may take 1 ms*/
   int total_count = 0, numBytesToRead = 0, headerIndex = 0;
 
-  ALOGD_IF(ese_debug_enabled, "%s Enter", __FUNCTION__);
+  NXP_LOG_ESE_D("%s Enter", __FUNCTION__);
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
     int max_sof_counter = 0;
     /*Max retry to get SOF in case of chaining*/
     if (poll_sof_chained_delay == 1) {
-      /*Wait Max for 1.3 sec before retry/recvoery*/
+      /*Wait Max for 1.3 sec before retry/recovery*/
       /*(max_sof_counter(1300) * 10 us) = 1.3 sec */
       max_sof_counter = ESE_POLL_TIMEOUT * 10;
     }
@@ -1287,30 +1287,29 @@
     if (nxpese_ctxt.rnack_sent) {
       phPalEse_sleep(nxpese_ctxt.invalidFrame_Rnack_Delay);
     }
-    ALOGD_IF(ese_debug_enabled,
-             "read() max_sof_counter: "
-             "%X ESE_POLL_TIMEOUT %2X",
-             max_sof_counter, ESE_POLL_TIMEOUT);
+    NXP_LOG_ESE_D(
+        "read() max_sof_counter: "
+        "%X ESE_POLL_TIMEOUT %2X",
+        max_sof_counter, ESE_POLL_TIMEOUT);
     do {
       ret = -1;
       ret = phPalEse_read(pDevHandle, pBuffer, 2);
       if (ret < 0) {
         /*Polling for read on spi, hence Debug log*/
-        ALOGD_IF(ese_debug_enabled, "_spi_read() [HDR]errno : %x ret : %X",
-                 errno, ret);
+        NXP_LOG_ESE_D("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
       } else {
         if ((pBuffer[0] == nxpese_ctxt.nadInfo.nadRx) ||
             (pBuffer[0] == RECEIVE_PACKET_SOF)) {
-          /* Read the HEADR of one byte*/
-          ALOGD_IF(ese_debug_enabled, "%s Read HDR SOF + PCB", __FUNCTION__);
+          /* Read the HEADER of one byte*/
+          NXP_LOG_ESE_D("%s Read HDR SOF + PCB", __FUNCTION__);
           numBytesToRead = 1; /*Read only INF LEN*/
           headerIndex = 1;
           break;
         } else if (((pBuffer[0] == 0x00) || (pBuffer[0] == 0xFF)) &&
                    ((pBuffer[1] == nxpese_ctxt.nadInfo.nadRx) ||
                     (pBuffer[1] == RECEIVE_PACKET_SOF))) {
-          /* Read the HEADR of Two bytes*/
-          ALOGD_IF(ese_debug_enabled, "%s Read HDR only SOF", __FUNCTION__);
+          /* Read the HEADER of Two bytes*/
+          NXP_LOG_ESE_D("%s Read HDR only SOF", __FUNCTION__);
           pBuffer[0] = pBuffer[1];
           numBytesToRead = 2; /*Read PCB + INF LEN*/
           headerIndex = 0;
@@ -1321,22 +1320,22 @@
           // pBuffer[0], pBuffer[1]);
         } else if (ret >= 0) { /* Corruption happened during the receipt from
                                   Card, go flush out the data */
-          ALOGE("_spi_read() Corruption Buf[0]: %X Buf[1]: %X ..len=%d",
-                pBuffer[0], pBuffer[1], ret);
+          NXP_LOG_ESE_E("_spi_read() Corruption Buf[0]: %X Buf[1]: %X ..len=%d",
+                        pBuffer[0], pBuffer[1], ret);
           break;
         }
       }
       /*If it is Chained packet wait for 100 usec*/
       if (poll_sof_chained_delay == 1) {
-        ALOGD_IF(ese_debug_enabled, "%s Chained Pkt, delay read %dus",
-                 __FUNCTION__, GET_WAKE_UP_DELAY() * CHAINED_PKT_SCALER);
-        phPalEse_sleep(GET_WAKE_UP_DELAY() * CHAINED_PKT_SCALER);
+        NXP_LOG_ESE_D("%s Chained Pkt, delay read %dus", __FUNCTION__,
+                      GET_WAKE_UP_DELAY() * CHAINED_PKT_SCALER);
+        phPalEse_BusyWait(GET_WAKE_UP_DELAY() * CHAINED_PKT_SCALER);
       } else {
-        /*DLOG_IF(INFO, ese_debug_enabled)
+        /*DLOG_IF(INFO, ese_log_level)
          << StringPrintf("%s Normal Pkt, delay read %dus", __FUNCTION__,
          WAKE_UP_DELAY_SN1xx * NAD_POLLING_SCALER_SN1xx);*/
-        phPalEse_sleep(nxpese_ctxt.nadPollingRetryTime * GET_WAKE_UP_DELAY() *
-                       NAD_POLLING_SCALER);
+        phPalEse_BusyWait(nxpese_ctxt.nadPollingRetryTime *
+                          GET_WAKE_UP_DELAY() * NAD_POLLING_SCALER);
       }
       sof_counter++;
     } while (sof_counter < max_sof_counter);
@@ -1352,24 +1351,24 @@
       pBuffer[1] = 0xFF;
     } else if ((pBuffer[0] == nxpese_ctxt.nadInfo.nadRx) ||
                (pBuffer[0] == RECEIVE_PACKET_SOF)) {
-      ALOGD_IF(ese_debug_enabled, "%s SOF FOUND", __FUNCTION__);
-      /* Read the HEADR of one/Two bytes based on how two bytes read A5 PCB or
+      NXP_LOG_ESE_D("%s SOF FOUND", __FUNCTION__);
+      /* Read the HEADER of one/Two bytes based on how two bytes read A5 PCB or
        * 00 A5*/
       ret =
           phPalEse_read(pDevHandle, &pBuffer[1 + headerIndex], numBytesToRead);
       if (ret < 0) {
-        ALOGE("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
+        NXP_LOG_ESE_E("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
         flushData = true;
       } else {
         if ((pBuffer[1] == CHAINED_PACKET_WITHOUTSEQN) ||
             (pBuffer[1] == CHAINED_PACKET_WITHSEQN)) {
           poll_sof_chained_delay = 1;
-          ALOGD_IF(ese_debug_enabled, "poll_sof_chained_delay value is %d ",
-                   poll_sof_chained_delay);
+          NXP_LOG_ESE_D("poll_sof_chained_delay value is %d ",
+                        poll_sof_chained_delay);
         } else {
           poll_sof_chained_delay = 0;
-          ALOGD_IF(ese_debug_enabled, "poll_sof_chained_delay value is %d ",
-                   poll_sof_chained_delay);
+          NXP_LOG_ESE_D("poll_sof_chained_delay value is %d ",
+                        poll_sof_chained_delay);
         }
         total_count = 3;
         uint8_t pcb;
@@ -1387,7 +1386,7 @@
           } else {
             ret = phPalEse_read(pDevHandle, &pBuffer[3], 2);
             if (ret < 0) {
-              ALOGE("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
+              NXP_LOG_ESE_E("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
               flushData = true;
             } else {
               nNbBytesToRead = (pBuffer[3] << 8);
@@ -1395,11 +1394,11 @@
               /*If I-Frame received with invalid length respond with RNACK*/
               if ((nNbBytesToRead == 0) || (nNbBytesToRead > MAX_DATA_LEN) ||
                   (nNbBytesToRead > phNxpEseProto7816_GetIfs())) {
-                ALOGD_IF(ese_debug_enabled, "I-Frame with invalid len == %d",
-                         nNbBytesToRead);
+                NXP_LOG_ESE_D("I-Frame with invalid len == %d", nNbBytesToRead);
                 flushData = true;
               } else {
-                ALOGE("_spi_read() [HDR]EXTENDED_FRAME_MARKER, ret=%d", ret);
+                NXP_LOG_ESE_E("_spi_read() [HDR]EXTENDED_FRAME_MARKER, ret=%d",
+                              ret);
                 total_count += 2;
                 headerIndex = 5;
               }
@@ -1415,7 +1414,7 @@
           ret = phPalEse_read(pDevHandle, &pBuffer[headerIndex],
                               (nNbBytesToRead + 1));
           if (ret < 0) {
-            ALOGE("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
+            NXP_LOG_ESE_E("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
             ret = -1;
           } else {
             ret = (total_count + (nNbBytesToRead + 1));
@@ -1431,7 +1430,8 @@
          Flushing out data in the Rx buffer so that Card can switch the mode */
       uint16_t ifsd_size = phNxpEseProto7816_GetIfs();
       uint32_t total_frame_size = 0;
-      ALOGE("_spi_read() corrupted, IFSD size=%d flushing it out!!", ifsd_size);
+      NXP_LOG_ESE_E("_spi_read() corrupted, IFSD size=%d flushing it out!!",
+                    ifsd_size);
       /* If a non-zero byte is received while polling for NAD byte and the byte
          is not a valid NAD byte (0xA5 or 0xB4): 1)  Read & discard (without
          de-asserting SPI CS line) : a.  Max IFSD size + 5 (remaining four
@@ -1448,11 +1448,10 @@
       phPalEse_sleep(nxpese_ctxt.invalidFrame_Rnack_Delay);
       ret = phPalEse_read(pDevHandle, &pBuffer[2], total_frame_size);
       if (ret < 0) {
-        ALOGE("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
+        NXP_LOG_ESE_E("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
       } else { /* LRC fail expected for this frame to send R-NACK*/
-        ALOGD_IF(
-            ese_debug_enabled,
-            "_spi_read() SUCCESS  ret : %X LRC fail excpected for this frame",
+        NXP_LOG_ESE_D(
+            "_spi_read() SUCCESS  ret : %X LRC fail expected for this frame",
             ret);
         PH_PAL_ESE_PRINT_PACKET_RX(pBuffer, ret);
       }
@@ -1464,7 +1463,7 @@
   } else {
     ret = phNxpEse_readPacket_legacy(pDevHandle, pBuffer, nNbBytesToRead);
   }
-  ALOGD_IF(ese_debug_enabled, "%s Exit ret = %d", __FUNCTION__, ret);
+  NXP_LOG_ESE_D("%s Exit ret = %d", __FUNCTION__, ret);
   return ret;
 }
 
@@ -1489,18 +1488,17 @@
     ret = phPalEse_read(pDevHandle, pBuffer, 2);
     if (ret < 0) {
       /*Polling for read on spi, hence Debug log*/
-      ALOGD_IF(ese_debug_enabled, "_spi_read() [HDR]errno : %x ret : %X", errno,
-               ret);
+      NXP_LOG_ESE_D("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
     }
     if (pBuffer[0] == RECEIVE_PACKET_SOF) {
-      /* Read the HEADR of one byte*/
-      ALOGD_IF(ese_debug_enabled, "%s Read HDR", __FUNCTION__);
+      /* Read the HEADER of one byte*/
+      NXP_LOG_ESE_D("%s Read HDR", __FUNCTION__);
       numBytesToRead = 1;
       headerIndex = 1;
       break;
     } else if (pBuffer[1] == RECEIVE_PACKET_SOF) {
-      /* Read the HEADR of Two bytes*/
-      ALOGD_IF(ese_debug_enabled, "%s Read HDR", __FUNCTION__);
+      /* Read the HEADER of Two bytes*/
+      NXP_LOG_ESE_D("%s Read HDR", __FUNCTION__);
       pBuffer[0] = RECEIVE_PACKET_SOF;
       numBytesToRead = 2;
       headerIndex = 0;
@@ -1508,39 +1506,39 @@
     }
     /*If it is Chained packet wait for 100 usec*/
     if (poll_sof_chained_delay == 1) {
-      ALOGD_IF(ese_debug_enabled, "%s Chained Pkt, delay read %dus",
-               __FUNCTION__, GET_WAKE_UP_DELAY() * CHAINED_PKT_SCALER);
+      NXP_LOG_ESE_D("%s Chained Pkt, delay read %dus", __FUNCTION__,
+                    GET_WAKE_UP_DELAY() * CHAINED_PKT_SCALER);
       phPalEse_sleep(GET_WAKE_UP_DELAY() * CHAINED_PKT_SCALER);
     } else {
-      ALOGD_IF(ese_debug_enabled, "%s Normal Pkt, delay read %dus",
-               __FUNCTION__, GET_WAKE_UP_DELAY() * NAD_POLLING_SCALER);
+      NXP_LOG_ESE_D("%s Normal Pkt, delay read %dus", __FUNCTION__,
+                    GET_WAKE_UP_DELAY() * NAD_POLLING_SCALER);
       phPalEse_sleep(GET_WAKE_UP_DELAY() * NAD_POLLING_SCALER);
     }
   } while (sof_counter < ESE_NAD_POLLING_MAX);
   if (pBuffer[0] == RECEIVE_PACKET_SOF) {
-    ALOGD_IF(ese_debug_enabled, "%s SOF FOUND", __FUNCTION__);
-    /* Read the HEADR of one/Two bytes based on how two bytes read A5 PCB or
+    NXP_LOG_ESE_D("%s SOF FOUND", __FUNCTION__);
+    /* Read the HEADER of one/Two bytes based on how two bytes read A5 PCB or
      * 00 A5*/
     ret = phPalEse_read(pDevHandle, &pBuffer[1 + headerIndex], numBytesToRead);
     if (ret < 0) {
-      ALOGE("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
+      NXP_LOG_ESE_E("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
     }
     if ((pBuffer[1] == CHAINED_PACKET_WITHOUTSEQN) ||
         (pBuffer[1] == CHAINED_PACKET_WITHSEQN)) {
       poll_sof_chained_delay = 1;
-      ALOGD_IF(ese_debug_enabled, "poll_sof_chained_delay value is %d ",
-               poll_sof_chained_delay);
+      NXP_LOG_ESE_D("poll_sof_chained_delay value is %d ",
+                    poll_sof_chained_delay);
     } else {
       poll_sof_chained_delay = 0;
-      ALOGD_IF(ese_debug_enabled, "poll_sof_chained_delay value is %d ",
-               poll_sof_chained_delay);
+      NXP_LOG_ESE_D("poll_sof_chained_delay value is %d ",
+                    poll_sof_chained_delay);
     }
     total_count = 3;
     nNbBytesToRead = (pBuffer[2] & 0x000000FF);
     /* Read the Complete data + one byte CRC*/
     ret = phPalEse_read(pDevHandle, &pBuffer[3], (nNbBytesToRead + 1));
     if (ret < 0) {
-      ALOGE("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
+      NXP_LOG_ESE_E("_spi_read() [HDR]errno : %x ret : %X", errno, ret);
       ret = -1;
     } else {
       ret = (total_count + (nNbBytesToRead + 1));
@@ -1571,7 +1569,7 @@
 ESESTATUS phNxpEse_WriteFrame(uint32_t data_len, uint8_t* p_data) {
   ESESTATUS status = ESESTATUS_INVALID_PARAMETER;
   int32_t dwNoBytesWrRd = 0;
-  ALOGD_IF(ese_debug_enabled, "Enter %s ", __FUNCTION__);
+  NXP_LOG_ESE_D("Enter %s ", __FUNCTION__);
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
     /* TODO where to set the nad id */
     p_data[0] = nxpese_ctxt.nadInfo.nadTx;
@@ -1582,16 +1580,22 @@
   phNxpEse_memcpy(nxpese_ctxt.p_cmd_data, p_data, data_len);
   nxpese_ctxt.cmd_len = data_len;
 
+  // eSE requires around 200 usec to switch from tx to rx mode
+  // As per the observation, debug logs when enabled introduces around
+  // same amount of delay, therefore below explicit delay is required
+  // only if debug logs are disabled
+  if (ese_log_level < NXPESE_LOGLEVEL_DEBUG) phPalEse_BusyWait(200 /*usecs*/);
+
   dwNoBytesWrRd = phPalEse_write(nxpese_ctxt.pDevHandle, nxpese_ctxt.p_cmd_data,
                                  nxpese_ctxt.cmd_len);
   if (-1 == dwNoBytesWrRd) {
-    ALOGE(" - Error in SPI Write.....%d\n", errno);
+    NXP_LOG_ESE_E(" - Error in SPI Write.....%d\n", errno);
     status = ESESTATUS_FAILED;
   } else {
     status = ESESTATUS_SUCCESS;
     PH_PAL_ESE_PRINT_PACKET_TX(nxpese_ctxt.p_cmd_data, nxpese_ctxt.cmd_len);
   }
-  ALOGD_IF(ese_debug_enabled, "Exit %s status %x\n", __FUNCTION__, status);
+  NXP_LOG_ESE_I("Exit %s status %x\n", __FUNCTION__, status);
   return status;
 }
 
@@ -1610,7 +1614,7 @@
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
     status = phNxpEseProto7816_getAtr(pATR);
   } else {
-    ALOGE(" %s - Function not supported\n", __FUNCTION__);
+    NXP_LOG_ESE_E(" %s - Function not supported\n", __FUNCTION__);
   }
   return status;
 }
@@ -1727,8 +1731,7 @@
   /* Add extra 5% to the timer */
   *pMaxTimer +=
       CONVERT_TO_PERCENTAGE(*pMaxTimer, ADDITIONAL_SECURE_TIME_PERCENTAGE);
-  ALOGD_IF(ese_debug_enabled, "%s Max timer value = %lu", __FUNCTION__,
-           *pMaxTimer);
+  NXP_LOG_ESE_D("%s Max timer value = %lu", __FUNCTION__, *pMaxTimer);
   return;
 }
 
@@ -1744,15 +1747,16 @@
 ESESTATUS phNxpEse_DisablePwrCntrl(void) {
   ESESTATUS status = ESESTATUS_SUCCESS;
   unsigned long maxTimer = 0;
-  ALOGE("%s Enter", __FUNCTION__);
+  NXP_LOG_ESE_E("%s Enter", __FUNCTION__);
   phNxpEse_GetMaxTimer(&maxTimer);
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     status = phNxpEse_SPM_DisablePwrControl(maxTimer);
     if (status != ESESTATUS_SUCCESS) {
-      ALOGE("%s phNxpEseP61_DisablePwrCntrl: failed", __FUNCTION__);
+      NXP_LOG_ESE_E("%s phNxpEseP61_DisablePwrCntrl: failed", __FUNCTION__);
     }
   } else {
-    ALOGE("%s phNxpEseP61_DisablePwrCntrl: not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s phNxpEseP61_DisablePwrCntrl: not supported",
+                  __FUNCTION__);
     status = ESESTATUS_FAILED;
   }
   return status;
@@ -1791,7 +1795,7 @@
  *
  ******************************************************************************/
 static ESESTATUS phNxpEse_checkFWDwnldStatus(void) {
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_checkFWDwnldStatus Enter");
+  NXP_LOG_ESE_D("phNxpEse_checkFWDwnldStatus Enter");
   ESESTATUS wSpmStatus = ESESTATUS_SUCCESS;
   spm_state_t current_spm_state = SPM_STATE_INVALID;
   uint8_t ese_dwnld_retry = 0x00;
@@ -1801,13 +1805,13 @@
   if (wSpmStatus == ESESTATUS_SUCCESS) {
     /* Check current_spm_state and update config/Spm status*/
     while (ese_dwnld_retry < ESE_FW_DWNLD_RETRY_CNT) {
-      ALOGD_IF(ese_debug_enabled, "ESE_FW_DWNLD_RETRY_CNT retry count");
+      NXP_LOG_ESE_D("ESE_FW_DWNLD_RETRY_CNT retry count");
       wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
       if (wSpmStatus == ESESTATUS_SUCCESS) {
         if ((current_spm_state & SPM_STATE_DWNLD)) {
           status = ESESTATUS_FAILED;
         } else {
-          ALOGE("Exit polling no FW Download ..");
+          NXP_LOG_ESE_E("Exit polling no FW Download ..");
           status = ESESTATUS_SUCCESS;
           break;
         }
@@ -1820,7 +1824,7 @@
     }
   }
 
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_checkFWDwnldStatus status %x", status);
+  NXP_LOG_ESE_D("phNxpEse_checkFWDwnldStatus status %x", status);
   return status;
 }
 
@@ -1843,9 +1847,9 @@
 
   phNxpEse_SecureTimer_t secureTimerParams;
   uint8_t* temp_timer_buffer = NULL;
-  ALOGD_IF(ese_debug_enabled, "%s Enter", __FUNCTION__);
+  NXP_LOG_ESE_D("%s Enter", __FUNCTION__);
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
-    ALOGE("%s function not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s function not supported", __FUNCTION__);
     return status;
   }
   if (timer_buffer != NULL) {
@@ -1860,8 +1864,7 @@
     phNxpEse_memcpy(&secureTimerParams, &nxpese_ctxt.secureTimerParams,
                     sizeof(phNxpEse_SecureTimer_t));
 
-    ALOGD_IF(
-        ese_debug_enabled,
+    NXP_LOG_ESE_D(
         "%s secureTimer1 0x%x secureTimer2 0x%x secureTimer3 0x%x len = %d",
         __FUNCTION__, secureTimerParams.secureTimer1,
         secureTimerParams.secureTimer2, secureTimerParams.secureTimer3,
@@ -1891,10 +1894,10 @@
       }
     }
   } else {
-    ALOGE("%s Invalid timer buffer ", __FUNCTION__);
+    NXP_LOG_ESE_E("%s Invalid timer buffer ", __FUNCTION__);
   }
 
-  ALOGD_IF(ese_debug_enabled, "%s Exit status = 0x%x", __FUNCTION__, status);
+  NXP_LOG_ESE_D("%s Exit status = 0x%x", __FUNCTION__, status);
   return status;
 }
 
@@ -1903,14 +1906,13 @@
   short int count = 0, shift = 3;
   unsigned int mask = 0x000000FF;
   if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
-    ALOGE("%s function not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s function not supported", __FUNCTION__);
   } else {
-    ALOGD_IF(ese_debug_enabled, "value = %x \n", value);
+    NXP_LOG_ESE_D("value = %x \n", value);
     for (count = 0; count < 4; count++) {
       if (timer_buffer != NULL) {
         *timer_buffer = (value >> (shift * 8) & mask);
-        ALOGD_IF(ese_debug_enabled, "*timer_buffer=0x%x shift=0x%x",
-                 *timer_buffer, shift);
+        NXP_LOG_ESE_D("*timer_buffer=0x%x shift=0x%x", *timer_buffer, shift);
         timer_buffer++;
         shift--;
       } else {
@@ -1934,7 +1936,7 @@
   if (nxpese_ctxt.fPtr_WtxNtf) {
     (nxpese_ctxt.fPtr_WtxNtf)(state);
   } else {
-    ALOGE("%s function not supported", __FUNCTION__);
+    NXP_LOG_ESE_E("%s function not supported", __FUNCTION__);
   }
 }
 
@@ -1949,3 +1951,21 @@
 void phNxpEse_setWtxCountLimit(unsigned long int wtxCount) {
   app_wtx_cnt = wtxCount;
 }
+
+/******************************************************************************
+ * Function         phNxpEse_isPriorityAccessEnabled
+ *
+ * Description      This function returns whether priority channel enabled or
+ *                  not.
+ *
+ * Returns          Priority Access enabled(1)/disabled(0).
+ *
+ ******************************************************************************/
+bool phNxpEse_isPriorityAccessEnabled(void) {
+  uint8_t isPriorityAccess = 0;
+  if (EseConfig::hasKey(NAME_NXP_SE_PRIORITY_ACCESS)) {
+    isPriorityAccess = EseConfig::getUnsigned(NAME_NXP_SE_PRIORITY_ACCESS);
+  }
+  NXP_LOG_ESE_D("Reserve channel enabled = %d", isPriorityAccess);
+  return (isPriorityAccess != 0);
+}
diff --git a/snxxx/libese-spi/p73/pal/EseTransport.h b/snxxx/libese-spi/p73/pal/EseTransport.h
index 2929374..03d715d 100644
--- a/snxxx/libese-spi/p73/pal/EseTransport.h
+++ b/snxxx/libese-spi/p73/pal/EseTransport.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2020-2021 NXP
+ *  Copyright 2020-2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -62,69 +62,69 @@
 /*!
  * \brief IOCTL number to set ESE PWR
  */
-#define P61_SET_PWR _IOW(P61_MAGIC, 0x01, long)
+#define P61_SET_PWR _IOW(P61_MAGIC, 0x01, uint64_t)
 /*!
  * \brief IOCTL number to set debug state
  */
-#define P61_SET_DBG _IOW(P61_MAGIC, 0x02, long)
+#define P61_SET_DBG _IOW(P61_MAGIC, 0x02, uint64_t)
 /*!
  * \brief IOCTL number to enable poll mode
  */
-#define P61_SET_POLL _IOW(P61_MAGIC, 0x03, long)
+#define P61_SET_POLL _IOW(P61_MAGIC, 0x03, uint64_t)
 /*!
  * \brief SPI Request NFCC to enable p61 power, only in param
  *         Only for SPI
  *         level 1 = Enable power
  *         level 0 = Disable power
  */
-#define P61_SET_SPM_PWR _IOW(P61_MAGIC, 0x04, long)
+#define P61_SET_SPM_PWR _IOW(P61_MAGIC, 0x04, uint64_t)
 
 /*!
  * \brief SPI or DWP can call this ioctl to get the current
  *         power state of P61
  *
  */
-#define P61_GET_SPM_STATUS _IOR(P61_MAGIC, 0x05, long)
+#define P61_GET_SPM_STATUS _IOR(P61_MAGIC, 0x05, uint64_t)
 /*!
  * \brief IOCTL to add throughput measurement source code in device driver
  *
  */
-#define P61_SET_THROUGHPUT _IOW(P61_MAGIC, 0x06, long)
+#define P61_SET_THROUGHPUT _IOW(P61_MAGIC, 0x06, uint64_t)
 /*!
  * \brief IOCTL to get the ESE access
  *
  */
-#define P61_GET_ESE_ACCESS _IOW(P61_MAGIC, 0x07, long)
+#define P61_GET_ESE_ACCESS _IOW(P61_MAGIC, 0x07, uint64_t)
 /*!
  * \brief IOCTL to set the power scheme
  *
  */
-#define P61_SET_POWER_SCHEME _IOW(P61_MAGIC, 0x08, long)
+#define P61_SET_POWER_SCHEME _IOW(P61_MAGIC, 0x08, uint64_t)
 /*!
  * \brief This function is used to set the ESE jcop
  *  download state.
  */
-#define P61_SET_DWNLD_STATUS _IOW(P61_MAGIC, 0x09, long)
+#define P61_SET_DWNLD_STATUS _IOW(P61_MAGIC, 0x09, uint64_t)
 
 /*!
  * \brief This function is used to set disable ESE GPIO
  *  state On&Off
  */
-#define P61_INHIBIT_PWR_CNTRL _IOW(P61_MAGIC, 0x0A, long)
+#define P61_INHIBIT_PWR_CNTRL _IOW(P61_MAGIC, 0x0A, uint64_t)
 /*!
  * \brief IOCTL to set the GPIO for the eSE to distinguish
  *        the logical interface
  */
-#define ESE_SET_TRUSTED_ACCESS _IOW(P61_MAGIC, 0x0B, long)
+#define ESE_SET_TRUSTED_ACCESS _IOW(P61_MAGIC, 0x0B, uint64_t)
 
 /*!
  * \brief IOCTL to perform the eSE COLD_RESET  via NFC driver.
  */
-#define ESE_PERFORM_COLD_RESET _IOW(P61_MAGIC, 0x0C, long)
+#define ESE_PERFORM_COLD_RESET _IOW(P61_MAGIC, 0x0C, uint64_t)
 /*!
  * \brief IOCTL to enable/disable GPIO/COLD reset protection.
  */
-#define PERFORM_RESET_PROTECTION _IOW(P61_MAGIC, 0x0D, long)
+#define PERFORM_RESET_PROTECTION _IOW(P61_MAGIC, 0x0D, uint64_t)
 
 class EseTransport {
  public:
diff --git a/snxxx/libese-spi/p73/pal/NxpTimer.cpp b/snxxx/libese-spi/p73/pal/NxpTimer.cpp
new file mode 100644
index 0000000..17274e7
--- /dev/null
+++ b/snxxx/libese-spi/p73/pal/NxpTimer.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2022 NXP
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "NxpTimer.h"
+
+#include <android-base/logging.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+NxpTimer::NxpTimer(std::string tag) {
+  logtag = tag;
+  is_running = false;
+  start_ts = end_ts = 0;
+}
+NxpTimer::~NxpTimer() {}
+void NxpTimer::startTimer() {
+  is_running = true;
+
+  struct timespec tm;
+  clock_gettime(CLOCK_MONOTONIC, &tm);
+  start_ts = tm.tv_nsec * 1e-3 + tm.tv_sec * 1e+6;
+
+  LOG(INFO) << logtag << " Timer started";
+}
+void NxpTimer::stopTimer() {
+  is_running = false;
+
+  struct timespec tm;
+  clock_gettime(CLOCK_MONOTONIC, &tm);
+  end_ts = tm.tv_nsec * 1e-3 + tm.tv_sec * 1e+6;
+
+  LOG(INFO) << logtag << " Timer stopped";
+}
+unsigned long NxpTimer::totalDuration() {
+  unsigned long duration = end_ts - start_ts;
+
+  resetTimer();
+
+  return duration;
+}
+void NxpTimer::resetTimer() {
+  is_running = false;
+  start_ts = end_ts = 0;
+}
+bool NxpTimer::isRunning() { return is_running; }
diff --git a/snxxx/libese-spi/p73/pal/NxpTimer.h b/snxxx/libese-spi/p73/pal/NxpTimer.h
new file mode 100644
index 0000000..e312a3d
--- /dev/null
+++ b/snxxx/libese-spi/p73/pal/NxpTimer.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2022 NXP
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+#include <string>
+
+class NxpTimer {
+ public:
+  /*
+  ** Constructor
+  */
+  NxpTimer(std::string tag);
+
+  /*
+  ** Function         startTimer
+  **
+  ** Description      captures starting timestamp
+  **
+  ** Return           void
+  */
+  void startTimer();
+
+  /*
+  ** Function         stopTimer
+  **
+  ** Description       Captures end timestamp
+  **
+  ** Return           void
+  */
+  void stopTimer();
+
+  /*
+  ** Function         resetTimer
+  **
+  ** Description       Invalidates the timer state
+  **
+  ** Return           void
+  */
+  void resetTimer();
+
+  /*
+  ** Function         stopTimer
+  **
+  ** Description       Captures end timestamp
+  **
+  ** Return           void
+  */
+  unsigned long totalDuration();
+
+  /*
+  ** Function         isRunning
+  **
+  ** Description       Returns true if the timer is running else false
+  **
+  ** Return           bool
+  */
+  bool isRunning();
+
+  /*
+  ** Destructor
+  */
+  ~NxpTimer();
+
+ private:
+  unsigned long long start_ts, end_ts;
+  std::string logtag;
+  bool is_running;
+};
diff --git a/snxxx/libese-spi/p73/pal/phNxpEsePal.cpp b/snxxx/libese-spi/p73/pal/phNxpEsePal.cpp
index 7e23305..1cf8927 100755
--- a/snxxx/libese-spi/p73/pal/phNxpEsePal.cpp
+++ b/snxxx/libese-spi/p73/pal/phNxpEsePal.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -23,19 +23,19 @@
  *
  */
 #define LOG_TAG "NxpEseHal"
-#include <log/log.h>
-
+#include <EseTransportFactory.h>
+#include <NxpTimer.h>
 #include <errno.h>
+#include <ese_config.h>
+#include <ese_logs.h>
 #include <fcntl.h>
+#include <log/log.h>
+#include <phEseStatus.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
-#include <EseTransportFactory.h>
-#include <ese_config.h>
-#include <phEseStatus.h>
-#include <string.h>
-
 /*!
  * \brief Normal mode header length
  */
@@ -55,6 +55,8 @@
 
 spTransport gpTransportObj;
 
+static phPalEse_NxpTimer_t gNxpTimer;
+
 /*******************************************************************************
 **
 ** Function         phPalEse_close
@@ -180,8 +182,8 @@
 ESESTATUS phPalEse_ioctl(phPalEse_ControlCode_t eControlCode, void* pDevHandle,
                          long level) {
   ESESTATUS ret = ESESTATUS_FAILED;
-  ALOGD_IF(ese_debug_enabled, "phPalEse_spi_ioctl(), ioctl %x , level %lx",
-           eControlCode, level);
+  NXP_LOG_ESE_D("phPalEse_spi_ioctl(), ioctl %x , level %lx", eControlCode,
+                level);
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
     if (NULL == pDevHandle) {
       return ESESTATUS_IOCTL_FAILED;
@@ -197,6 +199,28 @@
 
   return ret;
 }
+/*******************************************************************************
+**
+** Function         phPalEse_BusyWait
+**
+** Description      This function  suspends execution of the calling thread for
+**                  total_time usecs(max extra delay 1 usecs) with busy wait.
+**                  Use this only for short delays (less than 500 microseconds)
+**
+** Returns          None
+**
+*******************************************************************************/
+
+void phPalEse_BusyWait(long total_time /* usecs*/) {
+  struct timespec ts1, ts2;
+  clock_gettime(CLOCK_MONOTONIC, &ts1);
+  long elapsed_time = 0;  // microseconds
+  do {
+    clock_gettime(CLOCK_MONOTONIC, &ts2);
+    elapsed_time = 1e+6 * ts2.tv_sec + 1e-3 * ts2.tv_nsec -
+                   (1e+6 * ts1.tv_sec + 1e-3 * ts1.tv_nsec);
+  } while (elapsed_time < total_time);
+}
 
 /*******************************************************************************
 **
@@ -209,6 +233,8 @@
 *******************************************************************************/
 void phPalEse_print_packet(const char* pString, const uint8_t* p_data,
                            uint16_t len) {
+  if (ese_log_level < NXPESE_LOGLEVEL_DEBUG) return;  // debug logs disabled
+
   uint32_t i;
   char print_buffer[len * 3 + 1];
 
@@ -217,13 +243,10 @@
     snprintf(&print_buffer[i * 2], 3, "%02X", p_data[i]);
   }
   if (0 == memcmp(pString, "SEND", 0x04)) {
-    ALOGD_IF(ese_debug_enabled, "NxpEseDataX len = %3d > %s", len,
-             print_buffer);
+    NXP_LOG_ESE_D("NxpEseDataX len = %3d > %s", len, print_buffer);
   } else if (0 == memcmp(pString, "RECV", 0x04)) {
-    ALOGD_IF(ese_debug_enabled, "NxpEseDataR len = %3d > %s", len,
-             print_buffer);
+    NXP_LOG_ESE_D("NxpEseDataR len = %3d > %s", len, print_buffer);
   }
-
   return;
 }
 
@@ -312,3 +335,117 @@
   }
   return;
 }
+/*******************************************************************************
+**
+** Function         phPalEse_initTimer
+**
+** Description      Initializes phPalEse_NxpTimer_t global struct
+**
+** Returns          None
+**
+*******************************************************************************/
+
+void phPalEse_initTimer() {
+  bool is_kpi_enabled =
+      EseConfig::getUnsigned(NAME_SE_KPI_MEASUREMENT_ENABLED, 0);
+  gNxpTimer.is_enabled = (is_kpi_enabled != 0) ? true : false;
+  if (!gNxpTimer.is_enabled) return;
+
+  gNxpTimer.tx_timer = new NxpTimer("TX");
+  gNxpTimer.rx_timer = new NxpTimer("RX");
+}
+/*******************************************************************************
+**
+** Function         phPalEse_getTimer
+**
+** Description      Get handle to phPalEse_NxpTimer_t global struct variable
+**
+** Returns          pointer to phPalEse_NxpTimer_t struct variable
+**
+*******************************************************************************/
+
+const phPalEse_NxpTimer_t* phPalEse_getTimer() { return &gNxpTimer; }
+/*******************************************************************************
+**
+** Function         phPalEse_startTimer
+**
+** Description      Wrapper function to start the given timer
+**
+** Returns          None
+**
+*******************************************************************************/
+
+void phPalEse_startTimer(NxpTimer* timer) {
+  if (!gNxpTimer.is_enabled) return;
+
+  timer->startTimer();
+}
+/*******************************************************************************
+**
+** Function         phPalEse_stopTimer
+**
+** Description      Wrapper function to stop the given timer
+**
+** Returns          None
+**
+*******************************************************************************/
+
+void phPalEse_stopTimer(NxpTimer* timer) {
+  if (!gNxpTimer.is_enabled) return;
+
+  timer->stopTimer();
+}
+/*******************************************************************************
+**
+** Function         phPalEse_timerDuration
+**
+** Description      Wrapper function to get total time (usecs) recorded by the
+**                  given timer
+**
+** Returns          total time (in usecs) recorded by the timer
+**
+*******************************************************************************/
+
+unsigned long phPalEse_timerDuration(NxpTimer* timer) {
+  if (!gNxpTimer.is_enabled) return 0;
+
+  return timer->totalDuration();
+}
+/*******************************************************************************
+**
+** Function         phPalEse_resetTimer
+**
+** Description      Function to reset both timers in gNxpTimer object
+**
+** Returns          None
+**
+*******************************************************************************/
+
+void phPalEse_resetTimer() {
+  if (!gNxpTimer.is_enabled) return;
+
+  gNxpTimer.tx_timer->resetTimer();
+  gNxpTimer.rx_timer->resetTimer();
+}
+
+/*******************************************************************************
+**
+** Function         phPalEse_deInitTimer
+**
+** Description      Wrapper function to de-construct the timer objects
+**
+** Returns          None
+**
+*******************************************************************************/
+
+void phPalEse_deInitTimer() {
+  if (!gNxpTimer.is_enabled) return;
+
+  delete gNxpTimer.tx_timer;
+  gNxpTimer.tx_timer = nullptr;
+
+  delete gNxpTimer.rx_timer;
+  gNxpTimer.rx_timer = nullptr;
+
+  gNxpTimer.is_enabled = false;
+}
diff --git a/snxxx/libese-spi/p73/pal/phNxpEsePal.h b/snxxx/libese-spi/p73/pal/phNxpEsePal.h
index d6d06cf..3c6d5e8 100644
--- a/snxxx/libese-spi/p73/pal/phNxpEsePal.h
+++ b/snxxx/libese-spi/p73/pal/phNxpEsePal.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2021 NXP
+ *  Copyright 2018-2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 #define _PHNXPESE_PAL_H
 
 /* Basic type definitions */
+#include <NxpTimer.h>
 #include <errno.h>
 #include <phEseStatus.h>
 #include <phNxpEseFeatures.h>
@@ -82,6 +83,26 @@
   /*!< Device handle output */
 } phPalEse_Config_t, *pphPalEse_Config_t; /* pointer to phPalEse_Config_t */
 
+/*!
+ * \ingroup eSe_PAL
+ *
+ * \brief NxpTimer struct to measure cmd TX and response RX time.
+ */
+typedef struct phPalEse_NxpTimer {
+  NxpTimer* tx_timer;
+  /*!< timer to capture time taken for cmd transfer
+   */
+
+  NxpTimer* rx_timer;
+  /*!< timer to capture time taken for response receival
+   */
+
+  bool is_enabled;
+  /*!< TRUE if KPI measurement is enabled else FALSE
+   */
+
+} phPalEse_NxpTimer_t;
+
 /* Function declarations */
 /**
  * \ingroup eSe_PAL
@@ -184,6 +205,19 @@
 
 /**
  * \ingroup eSe_PAL
+ * \brief This function  suspends execution of the calling thread for
+ *        total_time usecs(max extra delay 1 usecs) with busy loop wait.
+ *        Use this only for short delays (less than 500 microseconds)
+ *
+ * \param[in]    usec                - number of micro seconds to sleep
+ *
+ * \retval   void
+ *
+ */
+void phPalEse_BusyWait(long total_time /* usecs*/);
+
+/**
+ * \ingroup eSe_PAL
  * \brief This function updates destination buffer with val
  *                 data in len size
  *
@@ -234,7 +268,7 @@
 
 /**
  * \ingroup eSe_PAL
- * \brief This is utility function for freeeing heap memory allocated
+ * \brief This is utility function for freeing heap memory allocated
  *
  * \param[in]    ptr                 - Address pointer to previous allocation
  *
@@ -243,5 +277,90 @@
  */
 void phPalEse_free(void* ptr);
 
+/**
+ * \ingroup eSe_PAL
+ * \brief This is wrapper function for constructing timer objects.
+ *  Timer is used for cmd TX and response RX time measurement.
+ *  Applicable only for KPI measurement
+ *
+ * \param[in]    void
+ *
+ * \retval   void
+ *
+ */
+void phPalEse_initTimer();
+
+/**
+ * \ingroup eSe_PAL
+ * \brief Function for getting handle to initialized timers.
+ *  Applicable only for KPI measurement
+ *
+ * \param[in]    void
+ *
+ * \retval   pointer to global phPalEse_NxpTimer_t struct or null
+ *
+ */
+const phPalEse_NxpTimer_t* phPalEse_getTimer();
+
+/**
+ * \ingroup eSe_PAL
+ * \brief Wrapper function to start timer.
+ *  Applicable only for KPI measurement
+ *
+ * \param[in]    pointer to NxpTimer object
+ *
+ * \retval   void
+ *
+ */
+void phPalEse_startTimer(NxpTimer* timer);
+
+/**
+ * \ingroup eSe_PAL
+ * \brief Wrapper function to stop timer.
+ *  Applicable only for KPI measurement
+ *
+ * \param[in]    pointer to NxpTimer object
+ *
+ * \retval   void
+ *
+ */
+void phPalEse_stopTimer(NxpTimer* timer);
+
+/**
+ * \ingroup eSe_PAL
+ * \brief Wrapper function to get total time recorded by given timer.
+ *  Applicable only for KPI measurement
+ *
+ * \param[in]    pointer to NxpTimer object
+ *
+ * \retval   total time recorded by this timer
+ *
+ */
+unsigned long phPalEse_timerDuration(NxpTimer* timer);
+
+/**
+ * \ingroup eSe_PAL
+ * \brief Wrapper function to reset the both timer state.
+ *  Applicable only for KPI measurement
+ *
+ * \param[in]    void
+ *
+ * \retval   void
+ *
+ */
+void phPalEse_resetTimer();
+
+/**
+ * \ingroup eSe_PAL
+ * \brief Wrapper function to delete the objects created by initTimer.
+ *  Applicable only for KPI measurement
+ *
+ * \param[in]    void
+ *
+ * \retval   void
+ *
+ */
+void phPalEse_deInitTimer();
+
 /** @} */
 #endif /*  _PHNXPESE_PAL_H    */
diff --git a/snxxx/libese-spi/p73/pal/spi/EseSpiTransport.cpp b/snxxx/libese-spi/p73/pal/spi/EseSpiTransport.cpp
index 859298e..08ddda1 100644
--- a/snxxx/libese-spi/p73/pal/spi/EseSpiTransport.cpp
+++ b/snxxx/libese-spi/p73/pal/spi/EseSpiTransport.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020, 2023 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -26,19 +26,19 @@
 #include "EseSpiTransport.h"
 
 #define LOG_TAG "NxpEseHal"
-#include <log/log.h>
-
 #include <errno.h>
+#include <ese_config.h>
+#include <ese_logs.h>
 #include <fcntl.h>
+#include <hardware/nfc.h>
+#include <log/log.h>
+#include <phEseStatus.h>
+#include <phNxpEsePal.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 
-#include <ese_config.h>
-#include <hardware/nfc.h>
-#include <phEseStatus.h>
-#include <phNxpEsePal.h>
-#include <string.h>
 #include "NfcAdaptation.h"
 #include "hal_nxpese.h"
 #include "phNxpEse_Api.h"
@@ -90,8 +90,8 @@
 ESESTATUS phNxpEse_spiIoctl(uint64_t ioctlType, void* p_data) {
   ESESTATUS status = ESESTATUS_SUCCESS;
   if (!p_data) {
-    ALOGE("halimpl phNxpEse_spiIoctl p_data is null ioctltyp: %ld",
-          (long)ioctlType);
+    NXP_LOG_ESE_E("halimpl phNxpEse_spiIoctl p_data is null ioctltyp: %ld",
+                  (long)ioctlType);
     return ESESTATUS_FAILED;
   }
 #if (NFC_NXP_ESE_VER == JCOP_VER_5_x)
@@ -100,31 +100,15 @@
     case HAL_ESE_IOCTL_RF_STATUS_UPDATE:
       rf_status = inpOutData->inp.data.nxpCmd.p_cmd[0];
       if (rf_status == 1) {
-        ALOGD_IF(
-            ese_debug_enabled,
+        NXP_LOG_ESE_D(
             "******************RF IS ON*************************************");
       } else {
-        ALOGD_IF(
-            ese_debug_enabled,
+        NXP_LOG_ESE_D(
             "******************RF IS OFF*************************************");
       }
       break;
-    case HAL_ESE_IOCTL_NFC_JCOP_DWNLD:
-
-      eseioctldata.nfc_jcop_download_state =
-          inpOutData->inp.data.nxpCmd.p_cmd[0];
-      if (eseioctldata.nfc_jcop_download_state == 1) {
-        ALOGD_IF(ese_debug_enabled,
-                 "******************JCOP Download "
-                 "started*************************************");
-      } else {
-        ALOGD_IF(ese_debug_enabled,
-                 "******************JCOP Download "
-                 "stopped*************************************");
-      }
-      break;
     default:
-      ALOGD_IF(ese_debug_enabled, "Invalid IOCTL type");
+      NXP_LOG_ESE_D("Invalid IOCTL type");
       break;
   }
 #endif
@@ -152,17 +136,15 @@
 
       rf_status = inpOutData->inp.data.nxpCmd.p_cmd[0];
       if (rf_status == 1) {
-        ALOGD_IF(
-            ese_debug_enabled,
+        NXP_LOG_ESE_D(
             "******************RF IS ON*************************************");
       } else {
-        ALOGD_IF(
-            ese_debug_enabled,
+        NXP_LOG_ESE_D(
             "******************RF IS OFF*************************************");
       }
       break;
     default:
-      ALOGD_IF(ese_debug_enabled, "Invalid IOCTL type");
+      NXP_LOG_ESE_D("Invalid IOCTL type");
       break;
   }
   return ESESTATUS_SUCCESS;
@@ -190,32 +172,31 @@
   ALOGD("NxpEse EseSpiTransport::OpenAndConfigure 1");
   if (EseConfig::hasKey(NAME_NXP_SOF_WRITE)) {
     mConfigSofWrite = EseConfig::getUnsigned(NAME_NXP_SOF_WRITE);
-    ALOGD_IF(ese_debug_enabled, "NXP_SOF_WRITE value from config file = %ld",
-             mConfigSofWrite);
+    NXP_LOG_ESE_D("NXP_SOF_WRITE value from config file = %ld",
+                  mConfigSofWrite);
   }
   if (EseConfig::hasKey(NAME_NXP_SPI_WRITE_TIMEOUT)) {
     mConfigSpiWriteTimeout = EseConfig::getUnsigned(NAME_NXP_SPI_WRITE_TIMEOUT);
-    ALOGD_IF(ese_debug_enabled,
-             "NXP_SPI_WRITE_TIMEOUT value from config file = %ld",
-             mConfigSpiWriteTimeout);
+    NXP_LOG_ESE_D("NXP_SPI_WRITE_TIMEOUT value from config file = %ld",
+                  mConfigSpiWriteTimeout);
   }
   /* Read eSE cold reset interface from ese config file */
   if (EseConfig::hasKey(NAME_NXP_P61_COLD_RESET_INTERFACE)) {
     mConfigColdResetIntf =
         EseConfig::getUnsigned(NAME_NXP_P61_COLD_RESET_INTERFACE);
-    ALOGD_IF(ese_debug_enabled,
-             "mConfigColdResetIntf value from config file = %ld",
-             mConfigColdResetIntf);
+    NXP_LOG_ESE_D("mConfigColdResetIntf value from config file = %ld",
+                  mConfigColdResetIntf);
   } else {
     mConfigColdResetIntf = 0x01; /* Default interface is NFC HAL */
-    ALOGD_IF(ese_debug_enabled, "mConfigColdResetIntf: Default value ");
+    NXP_LOG_ESE_D("mConfigColdResetIntf: Default value ");
   }
-  ALOGD_IF(ese_debug_enabled, "Opening port=%s\n", pConfig->pDevName);
+  NXP_LOG_ESE_D("Opening port=%s\n", pConfig->pDevName);
 /* open port */
 retry:
   nHandle = open((char const*)pConfig->pDevName, O_RDWR);
   if (nHandle < 0) {
-    ALOGE("%s : failed errno = 0x%x, retval %x", __FUNCTION__, errno, nHandle);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x, retval %x", __FUNCTION__, errno,
+                  nHandle);
 
     if ((errno == -EBUSY) || (errno == EBUSY)) {
       if (GET_CHIP_OS_VERSION() != OS_VERSION_4_0) {
@@ -223,18 +204,18 @@
         return ESESTATUS_DRIVER_BUSY;
       } else {
         retryCnt++;
-        ALOGE("Retry open eSE driver, retry cnt : %d", retryCnt);
+        NXP_LOG_ESE_E("Retry open eSE driver, retry cnt : %d", retryCnt);
         if (retryCnt < MAX_RETRY_CNT) {
           phPalEse_sleep(1000000);
           goto retry;
         }
       }
     }
-    ALOGE("_spi_open() Failed: retval %x", nHandle);
+    NXP_LOG_ESE_E("_spi_open() Failed: retval %x", nHandle);
     pConfig->pDevHandle = NULL;
     return ESESTATUS_INVALID_DEVICE;
   }
-  ALOGD_IF(ese_debug_enabled, "eSE driver opened :: fd = [%d]", nHandle);
+  NXP_LOG_ESE_D("eSE driver opened :: fd = [%d]", nHandle);
   pConfig->pDevHandle = (void*)((intptr_t)nHandle);
   return ESESTATUS_SUCCESS;
 }
@@ -282,7 +263,7 @@
   int numWrote = 0;
   unsigned long int retryCount = 0;
   if (NULL == pDevHandle) {
-    ALOGE("phPalEse_spi_write: received pDevHandle=NULL");
+    NXP_LOG_ESE_E("phPalEse_spi_write: received pDevHandle=NULL");
     return -1;
   }
   if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
@@ -293,10 +274,10 @@
       /* Do Nothing */
     }
   }
-  ALOGE("NXP_SPI_WRITE_TIMEOUT value is... : %ld secs", mConfigSpiWriteTimeout);
+  NXP_LOG_ESE_D("NXP_SPI_WRITE_TIMEOUT value is... : %ld secs",
+                mConfigSpiWriteTimeout);
   if (mConfigSpiWriteTimeout > 0) {
     gsMaxSpiWriteRetryCnt = mConfigSpiWriteTimeout;
-    ALOGE(" spi_write_timeout Wait time ... : %ld", gsMaxSpiWriteRetryCnt);
   } else {
     /* Do Nothing */
   }
@@ -312,11 +293,11 @@
     if (ret > 0) {
       numWrote += ret;
     } else if (ret == 0) {
-      ALOGE("_spi_write() EOF");
+      NXP_LOG_ESE_E("_spi_write() EOF");
       return -1;
     } else {
-      ALOGE("_spi_write() errno : %x", errno);
-      ALOGD_IF(ese_debug_enabled, "rf_status value is %d", rf_status);
+      NXP_LOG_ESE_E("_spi_write() errno : %x", errno);
+      NXP_LOG_ESE_D("rf_status value is %d", rf_status);
       if ((errno == EINTR || errno == EAGAIN || rf_status == 1) &&
           (retryCount < gsMaxSpiWriteRetryCnt)) {
         /*Configure retry count or timeout here,now its configured for 2*10
@@ -329,7 +310,8 @@
         retryCount++;
         /* 5ms delay to give ESE wake up delay */
         phPalEse_sleep(1000 * (GET_WAKE_UP_DELAY()));
-        ALOGE("_spi_write() failed. Going to retry, counter:%ld !", retryCount);
+        NXP_LOG_ESE_E("_spi_write() failed. Going to retry, counter:%ld !",
+                      retryCount);
         continue;
       }
       return -1;
@@ -360,8 +342,8 @@
   inpOutData.inp.level = level;
   NfcAdaptation& pNfcAdapt = NfcAdaptation::GetInstance();
 #endif
-  ALOGD_IF(ese_debug_enabled, "phPalEse_spi_ioctl(), ioctl %x , level %lx",
-           eControlCode, level);
+  NXP_LOG_ESE_D("phPalEse_spi_ioctl(), ioctl %x , level %lx", eControlCode,
+                level);
   if (NULL == pDevHandle) {
     if (GET_CHIP_OS_VERSION() == OS_VERSION_4_0) {
       return ESESTATUS_IOCTL_FAILED;
@@ -410,6 +392,7 @@
           } else {
 #if (NFC_NXP_ESE_VER == JCOP_VER_5_x)
             // Nfc Driver communication part
+            pNfcAdapt.Initialize();
             ret = pNfcAdapt.resetEse(level);
 #else
             ret = ESESTATUS_SUCCESS;
@@ -428,8 +411,8 @@
         if (0x00 <= retioctl) {
           ret = ESESTATUS_SUCCESS;
         } else {
-          ALOGE("phPalEse_e_ResetProtection ioctl failed status :%x !",
-                retioctl);
+          NXP_LOG_ESE_E("phPalEse_e_ResetProtection ioctl failed status :%x !",
+                        retioctl);
         }
       }
       break;
@@ -473,23 +456,6 @@
             (ESESTATUS)ioctl((intptr_t)pDevHandle, P61_SET_DWNLD_STATUS, level);
       }
       break;
-#if (NFC_NXP_ESE_VER == JCOP_VER_5_x)
-    case phPalEse_e_SetClientUpdateState: {
-      pNfcAdapt.Initialize();
-      ALOGD_IF(ese_debug_enabled,
-               "phPalEse_spi_ioctl state = phPalEse_e_SetJcopDwnldState");
-      ese_nxp_IoctlInOutData_t inpOutData;
-      memset(&inpOutData, 0x00, sizeof(ese_nxp_IoctlInOutData_t));
-      inpOutData.inp.data.nxpCmd.cmd_len = 1;
-      inpOutData.inp.data_source = 1;
-      uint8_t data = (uint8_t)level;
-      memcpy(inpOutData.inp.data.nxpCmd.p_cmd, &data, sizeof(data));
-      ALOGD_IF(ese_debug_enabled, "Before phPalEse_e_SetClientUpdateState");
-
-      ret = pNfcAdapt.setEseUpdateState(&inpOutData);
-      ALOGD_IF(ese_debug_enabled, "After phPalEse_e_SetClientUpdateState");
-    } break;
-#endif
     case phPalEse_e_DisablePwrCntrl:
       ret = ESESTATUS_SUCCESS;
       break;
@@ -497,7 +463,6 @@
       ret = ESESTATUS_IOCTL_FAILED;
       break;
   }
-  ALOGD_IF(ese_debug_enabled, "Exit  phPalEse_spi_ioctl : ret = %d errno = %d",
-           ret, errno);
+  NXP_LOG_ESE_D("Exit  phPalEse_spi_ioctl : ret = %d errno = %d", ret, errno);
   return (ESESTATUS)ret;
 }
diff --git a/snxxx/libese-spi/p73/spm/phNxpEse_Spm.cpp b/snxxx/libese-spi/p73/spm/phNxpEse_Spm.cpp
index 836c24b..b2c5558 100755
--- a/snxxx/libese-spi/p73/spm/phNxpEse_Spm.cpp
+++ b/snxxx/libese-spi/p73/spm/phNxpEse_Spm.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2019 NXP
+ *  Copyright 2018-2019,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,18 +16,20 @@
  *
  ******************************************************************************/
 #define LOG_TAG "NxpEseHal"
-#include <log/log.h>
+#include "phNxpEse_Spm.h"
 
 #include <errno.h>
+#include <ese_logs.h>
 #include <fcntl.h>
+#include <log/log.h>
 #include <phNxpEsePal.h>
 #include <phNxpEse_Internal.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+
 #include "phNxpEseFeatures.h"
-#include "phNxpEse_Spm.h"
 
 /*********************** Global Variables *************************************/
 
@@ -41,7 +43,7 @@
 /******************************************************************************
 \section Introduction Introduction
 
- * This module provide power request to Pn54x nfc-i2c driver, it cheks if
+ * This module provide power request to Pn54x nfc-i2c driver, it checks if
  * wired access is already granted. It should have access to pn54x drive.
  * Below are the apis provided by the SPM module.
  ******************************************************************************/
@@ -58,10 +60,10 @@
   ESESTATUS status = ESESTATUS_SUCCESS;
   pEseDeviceHandle = pDevHandle;
   if (NULL == pEseDeviceHandle) {
-    ALOGE("%s : failed, device handle is null", __FUNCTION__);
+    NXP_LOG_ESE_E("%s : failed, device handle is null", __FUNCTION__);
     status = ESESTATUS_FAILED;
   }
-  ALOGD_IF(ese_debug_enabled, "%s : exit status = %d", __FUNCTION__, status);
+  NXP_LOG_ESE_D("%s : exit status = %d", __FUNCTION__, status);
 
   return status;
 }
@@ -104,23 +106,25 @@
   switch (arg) {
     case SPM_POWER_DISABLE: {
       if (ret < 0) {
-        ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+        NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
         wSpmStatus = ESESTATUS_FAILED;
       } else {
         if (phNxpEse_SPM_RelAccess() != ESESTATUS_SUCCESS) {
-          ALOGE(" %s phNxpEse_SPM_RelAccess : failed \n", __FUNCTION__);
+          NXP_LOG_ESE_E(" %s phNxpEse_SPM_RelAccess : failed \n", __FUNCTION__);
         }
       }
     } break;
     case SPM_POWER_ENABLE: {
       if (ret < 0) {
-        ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+        NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
         if (errno == -EBUSY) {
           wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
           if (wSpmStatus != ESESTATUS_SUCCESS) {
-            ALOGE(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
+            NXP_LOG_ESE_E(" %s : phNxpEse_SPM_GetPwrState Failed",
+                          __FUNCTION__);
             if (phNxpEse_SPM_RelAccess() != ESESTATUS_SUCCESS) {
-              ALOGE(" %s phNxpEse_SPM_RelAccess : failed \n", __FUNCTION__);
+              NXP_LOG_ESE_E(" %s phNxpEse_SPM_RelAccess : failed \n",
+                            __FUNCTION__);
             }
             return wSpmStatus;
           } else {
@@ -135,18 +139,20 @@
         }
         if (wSpmStatus != ESESTATUS_SUCCESS) {
           if (phNxpEse_SPM_RelAccess() != ESESTATUS_SUCCESS) {
-            ALOGE(" %s phNxpEse_SPM_RelAccess : failed \n", __FUNCTION__);
+            NXP_LOG_ESE_E(" %s phNxpEse_SPM_RelAccess : failed \n",
+                          __FUNCTION__);
           }
         }
       }
     } break;
     case SPM_POWER_RESET: {
       if (ret < 0) {
-        ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+        NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
         if (errno == -EBUSY) {
           wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
           if (wSpmStatus != ESESTATUS_SUCCESS) {
-            ALOGE(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
+            NXP_LOG_ESE_E(" %s : phNxpEse_SPM_GetPwrState Failed",
+                          __FUNCTION__);
             return wSpmStatus;
           } else {
             if (current_spm_state & SPM_STATE_DWNLD) {
@@ -162,11 +168,12 @@
     } break;
     case SPM_POWER_PRIO_ENABLE: {
       if (ret < 0) {
-        ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+        NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
         if (errno == -EBUSY) {
           wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
           if (wSpmStatus != ESESTATUS_SUCCESS) {
-            ALOGE(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
+            NXP_LOG_ESE_E(" %s : phNxpEse_SPM_GetPwrState Failed",
+                          __FUNCTION__);
             return wSpmStatus;
           } else {
             if (current_spm_state & SPM_STATE_DWNLD) {
@@ -183,7 +190,7 @@
     } break;
     case SPM_POWER_PRIO_DISABLE: {
       if (ret < 0) {
-        ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+        NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
         wSpmStatus = ESESTATUS_FAILED;
       }
     } break;
@@ -207,15 +214,15 @@
   int32_t ret = -1;
   ESESTATUS wSpmStatus = ESESTATUS_SUCCESS;
   spm_state_t current_spm_state = SPM_STATE_INVALID;
-  ALOGD_IF(ese_debug_enabled, "%s : phNxpEse_SPM_EnablePwr is set to  = 0x%d",
-           __FUNCTION__, 0);
+  NXP_LOG_ESE_D("%s : phNxpEse_SPM_EnablePwr is set to  = 0x%d", __FUNCTION__,
+                0);
   ret = phPalEse_ioctl(phPalEse_e_ChipRst, pEseDeviceHandle, 0);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     if (errno == -EBUSY) {
       wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
       if (wSpmStatus != ESESTATUS_SUCCESS) {
-        ALOGE(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
+        NXP_LOG_ESE_E(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
         return wSpmStatus;
       } else {
         if (current_spm_state == SPM_STATE_DWNLD) {
@@ -246,11 +253,11 @@
 ESESTATUS phNxpEse_SPM_DisablePwr(void) {
   int32_t ret = -1;
   ESESTATUS status = ESESTATUS_SUCCESS;
-  ALOGD_IF(ese_debug_enabled, "%s : phNxpEse_SPM_DisablePwr is set to  = 0x%d",
-           __FUNCTION__, 1);
+  NXP_LOG_ESE_D("%s : phNxpEse_SPM_DisablePwr is set to  = 0x%d", __FUNCTION__,
+                1);
   ret = phPalEse_ioctl(phPalEse_e_ChipRst, pEseDeviceHandle, 1);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     status = ESESTATUS_FAILED;
   }
 
@@ -269,11 +276,10 @@
   int32_t ret = -1;
   ESESTATUS status = ESESTATUS_SUCCESS;
 
-  ALOGD_IF(ese_debug_enabled, "%s : Power scheme is set to  = 0x%ld",
-           __FUNCTION__, arg);
+  NXP_LOG_ESE_D("%s : Power scheme is set to  = 0x%ld", __FUNCTION__, arg);
   ret = phPalEse_ioctl(phPalEse_e_SetPowerScheme, pEseDeviceHandle, arg);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     status = ESESTATUS_FAILED;
   }
 
@@ -293,11 +299,11 @@
   int32_t ret = -1;
   ESESTATUS status = ESESTATUS_SUCCESS;
 
-  ALOGD_IF(ese_debug_enabled, "%s : Inhibit power control is set to  = 0x%ld",
-           __FUNCTION__, arg);
+  NXP_LOG_ESE_D("%s : Inhibit power control is set to  = 0x%ld", __FUNCTION__,
+                arg);
   ret = phPalEse_ioctl(phPalEse_e_DisablePwrCntrl, pEseDeviceHandle, arg);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     status = ESESTATUS_FAILED;
   }
 
@@ -318,13 +324,13 @@
   spm_state_t ese_current_state = SPM_STATE_INVALID;
 
   if (current_state == NULL) {
-    ALOGE("%s : failed Invalid argument", __FUNCTION__);
+    NXP_LOG_ESE_E("%s : failed Invalid argument", __FUNCTION__);
     return ESESTATUS_FAILED;
   }
   ret = phPalEse_ioctl(phPalEse_e_GetSPMStatus, pEseDeviceHandle,
                        (unsigned long)&ese_current_state);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     status = ESESTATUS_FAILED;
   } else {
     *current_state = ese_current_state; /* Current ESE state */
@@ -345,11 +351,11 @@
   int ret = -1;
   ESESTATUS status = ESESTATUS_SUCCESS;
 
-  ALOGD_IF(ese_debug_enabled, "%s :phNxpEse_SPM_SetJcopDwnldState  = 0x%ld",
-           __FUNCTION__, arg);
+  NXP_LOG_ESE_D("%s :phNxpEse_SPM_SetJcopDwnldState  = 0x%ld", __FUNCTION__,
+                arg);
   ret = phPalEse_ioctl(phPalEse_e_SetJcopDwnldState, pEseDeviceHandle, arg);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     status = ESESTATUS_FAILED;
   }
 
@@ -368,12 +374,11 @@
   int ret = -1;
   ESESTATUS status = ESESTATUS_SUCCESS;
 
-  ALOGD_IF(ese_debug_enabled,
-           "%s :phNxpEse_SPM_SetEseClientUpdateState  = 0x%ld", __FUNCTION__,
-           arg);
+  NXP_LOG_ESE_D("%s :phNxpEse_SPM_SetEseClientUpdateState  = 0x%ld",
+                __FUNCTION__, arg);
   ret = phPalEse_ioctl(phPalEse_e_SetClientUpdateState, pEseDeviceHandle, arg);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     status = ESESTATUS_FAILED;
   }
 
@@ -397,11 +402,11 @@
   /* reset the ese */
   ret = phPalEse_ioctl(phPalEse_e_ChipRst, pEseDeviceHandle, 2);
   if (ret < 0) {
-    ALOGE("%s : failed errno = 0x%x", __FUNCTION__, errno);
+    NXP_LOG_ESE_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
     if (errno == -EBUSY || errno == EBUSY) {
       wSpmStatus = phNxpEse_SPM_GetState(&current_spm_state);
       if (wSpmStatus != ESESTATUS_SUCCESS) {
-        ALOGE(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
+        NXP_LOG_ESE_E(" %s : phNxpEse_SPM_GetPwrState Failed", __FUNCTION__);
         return wSpmStatus;
       } else {
         if (current_spm_state == SPM_STATE_DWNLD) {
@@ -432,8 +437,7 @@
 *******************************************************************************/
 ESESTATUS phNxpEse_SPM_GetAccess(long timeout) {
   ESESTATUS status = ESESTATUS_SUCCESS;
-  ALOGD_IF(ese_debug_enabled, "phTmlEse_get_ese_access(), timeout  %ld",
-           timeout);
+  NXP_LOG_ESE_D("phTmlEse_get_ese_access(), timeout  %ld", timeout);
 #if ((NFC_NXP_ESE_VER == JCOP_VER_3_1) || (NFC_NXP_ESE_VER == JCOP_VER_3_2))
   int ret = -1;
 
@@ -444,7 +448,7 @@
     else
       status = ESESTATUS_FAILED;
   }
-  ALOGD_IF(ese_debug_enabled, "phTmlEse_get_ese_access(), exit  %d", status);
+  NXP_LOG_ESE_D("phTmlEse_get_ese_access(), exit  %d", status);
 #endif
   return status;
 }
@@ -463,13 +467,13 @@
   ESESTATUS status = ESESTATUS_SUCCESS;
 #if ((NFC_NXP_ESE_VER == JCOP_VER_3_1) || (NFC_NXP_ESE_VER == JCOP_VER_3_2))
   int ret = -1;
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_SPM_RelAccess(): enter");
+  NXP_LOG_ESE_D("phNxpEse_SPM_RelAccess(): enter");
 
   ret = phPalEse_ioctl(phPalEse_e_ChipRst, pEseDeviceHandle, 5);
   if (ret < 0) {
     status = ESESTATUS_FAILED;
   }
-  ALOGD_IF(ese_debug_enabled, "phNxpEse_SPM_RelAccess(): exit  %d", status);
+  NXP_LOG_ESE_D("phNxpEse_SPM_RelAccess(): exit  %d", status);
 #endif
   return status;
 }
diff --git a/snxxx/libese-spi/p73/utils/ese_config.h b/snxxx/libese-spi/p73/utils/ese_config.h
index bba26c8..d5da308 100755
--- a/snxxx/libese-spi/p73/utils/ese_config.h
+++ b/snxxx/libese-spi/p73/utils/ese_config.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -26,7 +26,8 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-#define NAME_SE_DEBUG_ENABLED "SE_DEBUG_ENABLED"
+#define NAME_SE_LOG_LEVEL "SE_LOG_LEVEL"
+#define NAME_SE_KPI_MEASUREMENT_ENABLED "SE_KPI_MEASUREMENT_ENABLED"
 #define NAME_NXP_JCOPDL_AT_BOOT_ENABLE "NXP_JCOPDL_AT_BOOT_ENABLE"
 #define NAME_NXP_WTX_COUNT_VALUE "NXP_WTX_COUNT_VALUE"
 #define NAME_NXP_MAX_RSP_TIMEOUT "NXP_MAX_RSP_TIMEOUT"
@@ -48,6 +49,7 @@
 #define NAME_NXP_WTX_NTF_COUNT "NXP_WTX_NTF_COUNT"
 #define NAME_NXP_OSU_MAX_WTX_COUNT "NXP_OSU_MAX_WTX_COUNT"
 #define NAME_NXP_TRANSPORT "NXP_TRANSPORT"
+#define NAME_NXP_SE_PRIORITY_ACCESS "NXP_SE_PRIORITY_ACCESS"
 #endif
 
 class EseConfig {
diff --git a/snxxx/libese-spi/p73/utils/ese_logs.h b/snxxx/libese-spi/p73/utils/ese_logs.h
new file mode 100644
index 0000000..a8a52b0
--- /dev/null
+++ b/snxxx/libese-spi/p73/utils/ese_logs.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2022 NXP
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(NXPESELOG__H_INCLUDED)
+#define NXPESELOG__H_INCLUDED
+#include <stdint.h>
+
+extern uint8_t ese_log_level;
+
+/* ####################### LOG LEVELS ################### */
+
+#define NXPESE_LOGLEVEL_SILENT 0x00
+#define NXPESE_LOGLEVEL_ERROR 0x01
+#define NXPESE_LOGLEVEL_WARN 0x02
+#define NXPESE_LOGLEVEL_INFO 0x03
+#define NXPESE_LOGLEVEL_DEBUG 0x04
+
+/* ########################################################
+ */
+/* Macros  */
+
+#define NXP_LOG_ESE_D(...) \
+  { ALOGD_IF(ese_log_level >= NXPESE_LOGLEVEL_DEBUG, __VA_ARGS__); }
+
+#define NXP_LOG_ESE_I(...) \
+  { ALOGI_IF(ese_log_level >= NXPESE_LOGLEVEL_INFO, __VA_ARGS__); }
+
+#define NXP_LOG_ESE_W(...) \
+  { ALOGW_IF(ese_log_level >= NXPESE_LOGLEVEL_WARN, __VA_ARGS__); }
+
+#define NXP_LOG_ESE_E(...) \
+  { ALOGE_IF(ese_log_level >= NXPESE_LOGLEVEL_ERROR, __VA_ARGS__); }
+
+#endif /* NXPESELOG__H_INCLUDED */
diff --git a/snxxx/libese-spi/src/adaptation/NfcAdaptation.cpp b/snxxx/libese-spi/src/adaptation/NfcAdaptation.cpp
index d746a0c..474fa10 100644
--- a/snxxx/libese-spi/src/adaptation/NfcAdaptation.cpp
+++ b/snxxx/libese-spi/src/adaptation/NfcAdaptation.cpp
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2018-2020 NXP
+ *  Copyright 2018-2020,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -17,7 +17,17 @@
  ******************************************************************************/
 #define LOG_TAG "NxpEseHal-NfcAdaptation"
 #include "NfcAdaptation.h"
+
+#include <aidl/vendor/nxp/nxpnfc_aidl/INxpNfc.h>
+#include <android/binder_auto_utils.h>
+#include <android/binder_enums.h>
+#include <android/binder_ibinder.h>
+#include <android/binder_interface_utils.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
 #include <android/hardware/nfc/1.0/types.h>
+#include <binder/IServiceManager.h>
+#include <ese_logs.h>
 #include <hwbinder/ProcessState.h>
 #include <log/log.h>
 #include <pthread.h>
@@ -33,9 +43,16 @@
 using android::hardware::ProcessState;
 using android::hardware::Return;
 using android::hardware::Void;
-using vendor::nxp::nxpnfc::V2_0::INxpNfc;
+using INxpNfc = vendor::nxp::nxpnfc::V2_0::INxpNfc;
+using INxpNfcAidl = ::aidl::vendor::nxp::nxpnfc_aidl::INxpNfc;
+
+#define MAX_NFC_GET_RETRY 30
+#define NFC_GET_SERVICE_DELAY_MS 100
+std::string NXPNFC_AIDL_HAL_SERVICE_NAME =
+    "vendor.nxp.nxpnfc_aidl.INxpNfc/default";
 
 sp<INxpNfc> NfcAdaptation::mHalNxpNfc = nullptr;
+std::shared_ptr<INxpNfcAidl> NfcAdaptation::mAidlHalNxpNfc = nullptr;
 ThreadMutex NfcAdaptation::sIoctlLock;
 NfcAdaptation* NfcAdaptation::mpInstance = NULL;
 ThreadMutex NfcAdaptation::sLock;
@@ -43,15 +60,30 @@
 int omapi_status;
 
 void NfcAdaptation::Initialize() {
+  int retry = 0;
   const char* func = "NfcAdaptation::Initialize";
-  ALOGD_IF(ese_debug_enabled, "%s", func);
-  if (mHalNxpNfc != nullptr) return;
-  mHalNxpNfc = INxpNfc::tryGetService();
-  if (mHalNxpNfc != nullptr) {
-    ALOGE("%s: INxpNfc::getService() returned %p (%s)", func, mHalNxpNfc.get(),
-          (mHalNxpNfc->isRemote() ? "remote" : "local"));
+  NXP_LOG_ESE_D("%s", func);
+  // Try get AIDL
+  do {
+    ::ndk::SpAIBinder binder(
+        AServiceManager_checkService(NXPNFC_AIDL_HAL_SERVICE_NAME.c_str()));
+    mAidlHalNxpNfc = INxpNfcAidl::fromBinder(binder);
+    if (mAidlHalNxpNfc != nullptr) {
+      NXP_LOG_ESE_E("%s: INxpNfcAidl::fromBinder returned", func);
+      break;
+    }
+    usleep(NFC_GET_SERVICE_DELAY_MS * 1000);
+  } while (retry++ < MAX_NFC_GET_RETRY);
+  if (mAidlHalNxpNfc == nullptr) {
+    ALOGE("Failed to get NXP NFC AIDLHAL .. Try for HIDL HAL");
+    mHalNxpNfc = INxpNfc::tryGetService();
+    if (mHalNxpNfc != nullptr) {
+      ALOGI("NXP NFC HAL service is available");
+    } else {
+      ALOGE("Failed to get INxpNfc::tryGetService");
+    }
   }
-  ALOGD_IF(ese_debug_enabled, "%s: exit", func);
+  NXP_LOG_ESE_D("%s: exit", func);
 }
 /*******************************************************************************
 **
@@ -121,7 +153,7 @@
 **
 ** Function:    ThreadMutex::lock()
 **
-** Description: lock kthe mutex
+** Description: lock the mutex
 **
 ** Returns:     none
 **
@@ -177,15 +209,23 @@
   ESESTATUS result = ESESTATUS_FAILED;
   bool ret = 0;
 
-  ALOGD_IF(ese_debug_enabled, "%s : Enter", func);
+  NXP_LOG_ESE_D("%s : Enter", func);
 
-  if (mHalNxpNfc != nullptr) {
-    ret = mHalNxpNfc->resetEse(level);
+  if (mAidlHalNxpNfc != nullptr) {
+    mAidlHalNxpNfc->resetEse(level, &ret);
     if (ret) {
-      ALOGE("NfcAdaptation::resetEse mHalNxpNfc completed");
+      NXP_LOG_ESE_E("NfcAdaptation::resetEse mAidlHalNxpNfc completed");
       result = ESESTATUS_SUCCESS;
     } else {
-      ALOGE("NfcAdaptation::resetEse mHalNxpNfc failed");
+      NXP_LOG_ESE_E("NfcAdaptation::resetEse mAidlHalNxpNfc failed");
+    }
+  } else if (mHalNxpNfc != nullptr) {
+    ret = mHalNxpNfc->resetEse(level);
+    if (ret) {
+      NXP_LOG_ESE_E("NfcAdaptation::resetEse mHalNxpNfc completed");
+      result = ESESTATUS_SUCCESS;
+    } else {
+      NXP_LOG_ESE_E("NfcAdaptation::resetEse mHalNxpNfc failed");
     }
   }
 
@@ -197,8 +237,8 @@
 ** Function:    NfcAdaptation::setEseUpdateState
 **
 ** Description:  This is a wrapper functions notifies upper layer about
-** the jcob download comple
-** tion.
+** the jcob download completion.
+**
 ** Returns:     -1 or 0.
 **
 *******************************************************************************/
@@ -208,20 +248,23 @@
   ESESTATUS result = ESESTATUS_FAILED;
   bool ret = 0;
 
-  ALOGD_IF(ese_debug_enabled, "%s : Enter", func);
+  NXP_LOG_ESE_D("%s : Enter", func);
 
   ese_nxp_IoctlInOutData_t* pInpOutData = (ese_nxp_IoctlInOutData_t*)p_data;
   data.setToExternal((uint8_t*)pInpOutData, sizeof(ese_nxp_IoctlInOutData_t));
 
-  if (mHalNxpNfc != nullptr) {
+  if (mAidlHalNxpNfc != nullptr) {
+    NXP_LOG_ESE_D(
+        "NfcAdaptation::setEseUpdateState not supported for mAidlHalNxpNfc");
+  } else if (mHalNxpNfc != nullptr) {
     ret = mHalNxpNfc->setEseUpdateState(
         (::vendor::nxp::nxpnfc::V2_0::NxpNfcHalEseState)
             pInpOutData->inp.data.nxpCmd.p_cmd[0]);
     if (ret) {
-      ALOGE("NfcAdaptation::setEseUpdateState completed");
+      NXP_LOG_ESE_E("NfcAdaptation::setEseUpdateState mHalNxpNfc completed");
       result = ESESTATUS_SUCCESS;
     } else {
-      ALOGE("NfcAdaptation::setEseUpdateState failed");
+      NXP_LOG_ESE_E("NfcAdaptation::setEseUpdateState mHalNxpNfc failed");
     }
   }
 
diff --git a/snxxx/libese-spi/src/include/NfcAdaptation.h b/snxxx/libese-spi/src/include/NfcAdaptation.h
index 10c0545..a87fa98 100644
--- a/snxxx/libese-spi/src/include/NfcAdaptation.h
+++ b/snxxx/libese-spi/src/include/NfcAdaptation.h
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- *  Copyright 2020 NXP
+ *  Copyright 2020,2022 NXP
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
  *
  ******************************************************************************/
 #pragma once
+#include <aidl/vendor/nxp/nxpnfc_aidl/INxpNfc.h>
 #include <android/hardware/nfc/1.0/types.h>
 #include <phEseStatus.h>
 #include <phNxpEseFeatures.h>
@@ -24,7 +25,8 @@
 #include <vendor/nxp/nxpnfc/2.0/INxpNfc.h>
 
 #include "hal_nxpese.h"
-using vendor::nxp::nxpnfc::V2_0::INxpNfc;
+using INxpNfc = vendor::nxp::nxpnfc::V2_0::INxpNfc;
+using INxpNfcAidl = ::aidl::vendor::nxp::nxpnfc_aidl::INxpNfc;
 
 class ThreadMutex {
  public:
@@ -81,4 +83,5 @@
   ThreadCondVar mCondVar;
   static ThreadCondVar mHalIoctlEvent;
   static android::sp<INxpNfc> mHalNxpNfc;
+  static std::shared_ptr<INxpNfcAidl> mAidlHalNxpNfc;
 };