Snap for 5490587 from f384f95bfe983c90d6d549388bbc903ac8f50c3b to qt-release

Change-Id: I6ebf1d2b6f98c0b1184b68018fda15084b209af7
diff --git a/1.2/Nfc.cpp b/1.2/Nfc.cpp
new file mode 100755
index 0000000..540f982
--- /dev/null
+++ b/1.2/Nfc.cpp
@@ -0,0 +1,152 @@
+/******************************************************************************
+ *
+ *  Copyright 2018-2019 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.
+ *
+ ******************************************************************************/
+#define LOG_TAG "android.hardware.nfc@1.2-impl"
+#include <log/log.h>
+#include "Nfc.h"
+#include "halimpl/inc/phNxpNciHal_Adaptation.h"
+#include "phNfcStatus.h"
+
+#define CHK_STATUS(x) ((x) == NFCSTATUS_SUCCESS) \
+      ? (V1_0::NfcStatus::OK) : (V1_0::NfcStatus::FAILED)
+
+extern bool nfc_debug_enabled;
+
+namespace android {
+namespace hardware {
+namespace nfc {
+namespace V1_2 {
+namespace implementation {
+
+sp<V1_1::INfcClientCallback> Nfc::mCallbackV1_1 = nullptr;
+sp<V1_0::INfcClientCallback> Nfc::mCallbackV1_0 = nullptr;
+
+Return<V1_0::NfcStatus> Nfc::open_1_1(
+    const sp<V1_1::INfcClientCallback>& clientCallback) {
+  if (clientCallback == nullptr) {
+    ALOGD_IF(nfc_debug_enabled, "Nfc::open null callback");
+    return V1_0::NfcStatus::FAILED;
+  } else {
+    mCallbackV1_1 = clientCallback;
+    mCallbackV1_1->linkToDeath(this, 0 /*cookie*/);
+  }
+  return open(clientCallback);
+}
+
+// Methods from ::android::hardware::nfc::V1_0::INfc follow.
+Return<V1_0::NfcStatus> Nfc::open(
+    const sp<V1_0::INfcClientCallback>& clientCallback) {
+  ALOGD_IF(nfc_debug_enabled, "Nfc::open Enter");
+  if (clientCallback == nullptr) {
+    ALOGD_IF(nfc_debug_enabled, "Nfc::open null callback");
+    return V1_0::NfcStatus::FAILED;
+  } else {
+    mCallbackV1_0 = clientCallback;
+    mCallbackV1_0->linkToDeath(this, 0 /*cookie*/);
+  }
+
+  NFCSTATUS status = phNxpNciHal_open(eventCallback, dataCallback);
+  ALOGD_IF(nfc_debug_enabled, "Nfc::open Exit");
+  return CHK_STATUS(status);
+}
+
+Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data) {
+  hidl_vec<uint8_t> copy = data;
+  return phNxpNciHal_write(copy.size(), &copy[0]);
+}
+
+Return<V1_0::NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data) {
+  hidl_vec<uint8_t> copy = data;
+  NFCSTATUS status = phNxpNciHal_core_initialized(&copy[0]);
+  return CHK_STATUS(status);
+}
+
+Return<V1_0::NfcStatus> Nfc::prediscover() {
+  NFCSTATUS status = phNxpNciHal_pre_discover();
+  return CHK_STATUS(status);
+}
+
+Return<V1_0::NfcStatus> Nfc::close() {
+  if (mCallbackV1_1 == nullptr && mCallbackV1_0 == nullptr) {
+    return V1_0::NfcStatus::FAILED;
+  }
+  NFCSTATUS status = phNxpNciHal_close(false);
+
+  if (mCallbackV1_1 != nullptr) {
+    mCallbackV1_1->unlinkToDeath(this);
+    mCallbackV1_1 = nullptr;
+  }
+  if (mCallbackV1_0 != nullptr) {
+    mCallbackV1_0->unlinkToDeath(this);
+    mCallbackV1_0 = nullptr;
+  }
+  return CHK_STATUS(status);
+}
+
+Return<V1_0::NfcStatus> Nfc::controlGranted() {
+  NFCSTATUS status = phNxpNciHal_control_granted();
+  return CHK_STATUS(status);
+}
+
+Return<V1_0::NfcStatus> Nfc::powerCycle() {
+  NFCSTATUS status = phNxpNciHal_power_cycle();
+  return CHK_STATUS(status);
+}
+
+// Methods from ::android::hardware::nfc::V1_1::INfc follow.
+Return<void> Nfc::factoryReset() {
+  phNxpNciHal_do_factory_reset();
+  return Void();
+}
+
+Return<V1_0::NfcStatus> Nfc::closeForPowerOffCase() {
+  if (mCallbackV1_1 == nullptr && mCallbackV1_0 == nullptr) {
+    return V1_0::NfcStatus::FAILED;
+  }
+  NFCSTATUS status = phNxpNciHal_configDiscShutdown();
+
+  if (mCallbackV1_1 != nullptr) {
+    mCallbackV1_1->unlinkToDeath(this);
+    mCallbackV1_1 = nullptr;
+  }
+  if (mCallbackV1_0 != nullptr) {
+    mCallbackV1_0->unlinkToDeath(this);
+    mCallbackV1_0 = nullptr;
+  }
+  return CHK_STATUS(status);
+}
+
+Return<void> Nfc::getConfig(getConfig_cb hidl_cb) {
+  android::hardware::nfc::V1_1::NfcConfig nfcVendorConfig;
+  phNxpNciHal_getVendorConfig(nfcVendorConfig);
+  hidl_cb(nfcVendorConfig);
+  return Void();
+}
+
+// Methods from ::android::hardware::nfc::V1_2::INfc follow.
+Return<void> Nfc::getConfig_1_2(getConfig_1_2_cb hidl_cb) {
+  NfcConfig nfcVendorConfig;
+  phNxpNciHal_getVendorConfig_1_2(nfcVendorConfig);
+  hidl_cb(nfcVendorConfig);
+  return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_2
+}  // namespace nfc
+}  // namespace hardware
+}  // namespace android
diff --git a/1.2/Nfc.h b/1.2/Nfc.h
new file mode 100755
index 0000000..3a5d76a
--- /dev/null
+++ b/1.2/Nfc.h
@@ -0,0 +1,114 @@
+/******************************************************************************
+ *
+ *  Copyright 2018-2019 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.
+ *
+ ******************************************************************************/
+
+#ifndef ANDROID_HARDWARE_NFC_V1_2_NFC_H
+#define ANDROID_HARDWARE_NFC_V1_2_NFC_H
+
+#include <android/hardware/nfc/1.2/INfc.h>
+#include <android/hardware/nfc/1.2/types.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <log/log.h>
+
+namespace android {
+namespace hardware {
+namespace nfc {
+namespace V1_2 {
+namespace implementation {
+
+using ::android::hidl::base::V1_0::IBase;
+using ::android::hardware::nfc::V1_2::INfc;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+struct Nfc : public V1_2::INfc, public hidl_death_recipient {
+ public:
+  // Methods from ::android::hardware::nfc::V1_0::INfc follow.
+  Return<V1_0::NfcStatus> open(
+      const sp<V1_0::INfcClientCallback>& clientCallback) override;
+  Return<V1_0::NfcStatus> open_1_1(
+      const sp<V1_1::INfcClientCallback>& clientCallback) override;
+  Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
+  Return<V1_0::NfcStatus> coreInitialized(
+      const hidl_vec<uint8_t>& data) override;
+  Return<V1_0::NfcStatus> prediscover() override;
+  Return<V1_0::NfcStatus> close() override;
+  Return<V1_0::NfcStatus> controlGranted() override;
+  Return<V1_0::NfcStatus> powerCycle() override;
+
+  // Methods from ::android::hardware::nfc::V1_1::INfc follow.
+  Return<void> factoryReset();
+  Return<V1_0::NfcStatus> closeForPowerOffCase();
+  Return<void> getConfig(getConfig_cb config);
+
+  // Methods from ::android::hardware::nfc::V1_2::INfc follow.
+  Return<void> getConfig_1_2(getConfig_1_2_cb config);
+
+  // Methods from ::android::hidl::base::V1_0::IBase follow.
+  static void eventCallback(uint8_t event, uint8_t status) {
+    if (mCallbackV1_1 != nullptr) {
+      auto ret = mCallbackV1_1->sendEvent_1_1((V1_1::NfcEvent)event,
+                                              (V1_0::NfcStatus)status);
+      if (!ret.isOk()) {
+        ALOGW("failed to send event!!!");
+      }
+    } else if (mCallbackV1_0 != nullptr) {
+      auto ret = mCallbackV1_0->sendEvent((V1_0::NfcEvent)event,
+                                          (V1_0::NfcStatus)status);
+      if (!ret.isOk()) {
+        ALOGE("failed to send event!!!");
+      }
+    }
+  }
+
+  static void dataCallback(uint16_t data_len, uint8_t* p_data) {
+    hidl_vec<uint8_t> data;
+    data.setToExternal(p_data, data_len);
+    if (mCallbackV1_1 != nullptr) {
+      auto ret = mCallbackV1_1->sendData(data);
+      if (!ret.isOk()) {
+        ALOGW("failed to send data!!!");
+      }
+    } else if (mCallbackV1_0 != nullptr) {
+      auto ret = mCallbackV1_0->sendData(data);
+      if (!ret.isOk()) {
+        ALOGE("failed to send data!!!");
+      }
+    }
+  }
+
+  virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) {
+    close();
+  }
+
+ private:
+  static sp<V1_1::INfcClientCallback> mCallbackV1_1;
+  static sp<V1_0::INfcClientCallback> mCallbackV1_0;
+};
+
+}  // namespace implementation
+}  // namespace V1_2
+}  // namespace nfc
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_NFC_V1_2_NFC_H
diff --git a/1.2/NxpNfcService.cpp b/1.2/NxpNfcService.cpp
new file mode 100755
index 0000000..7d9e76a
--- /dev/null
+++ b/1.2/NxpNfcService.cpp
@@ -0,0 +1,56 @@
+/******************************************************************************
+ *
+ *  Copyright 2018-2019 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.
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "nxpnfc@1.2-service"
+#include <android/hardware/nfc/1.2/INfc.h>
+#include <vendor/nxp/nxpnfc/1.0/INxpNfc.h>
+
+#include <hidl/LegacySupport.h>
+#include "Nfc.h"
+#include "NxpNfc.h"
+
+// Generated HIDL files
+using android::hardware::nfc::V1_2::INfc;
+using android::hardware::nfc::V1_2::implementation::Nfc;
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
+using android::sp;
+using android::status_t;
+using android::OK;
+using vendor::nxp::nxpnfc::V1_0::INxpNfc;
+using vendor::nxp::nxpnfc::V1_0::implementation::NxpNfc;
+
+int main() {
+    ALOGD("NFC HAL Service 1.2 is starting.");
+    sp<INfc> nfc_service = new Nfc();
+
+    configureRpcThreadpool(1, true /*callerWillJoin*/);
+    status_t status = nfc_service->registerAsService();
+    if (status != OK) {
+        LOG_ALWAYS_FATAL("Could not register service for NFC HAL Iface (%d).", status);
+        return -1;
+    }
+    sp<INxpNfc> nxp_nfc_service = new NxpNfc();
+    status = nxp_nfc_service->registerAsService();
+    if (status != OK) {
+        ALOGD("Could not register service for NXP NFC Extn Iface (%d).", status);
+    }
+    ALOGD("NFC service is ready");
+    joinRpcThreadpool();
+    return 1;
+}
diff --git a/1.2/android.hardware.nfc@1.2-service.rc b/1.2/android.hardware.nfc@1.2-service.rc
new file mode 100755
index 0000000..7017c0e
--- /dev/null
+++ b/1.2/android.hardware.nfc@1.2-service.rc
@@ -0,0 +1,4 @@
+service vendor.nfc_hal_service /vendor/bin/hw/android.hardware.nfc@1.2-service
+    class hal
+    user nfc
+    group nfc
diff --git a/Android.bp b/Android.bp
index 9b018fe..7d5d199 100755
--- a/Android.bp
+++ b/Android.bp
@@ -46,6 +46,7 @@
         "halimpl/utils/phNxpConfig.cpp",
         "halimpl/utils/phNxpNciHal_utils.cc",
         "halimpl/utils/sparse_crc32.cc",
+        "halimpl/utils/NfccPowerTracker.cpp",
     ],
 
     local_include_dirs: [
@@ -67,6 +68,7 @@
     shared_libs: [
         "android.hardware.nfc@1.0",
         "android.hardware.nfc@1.1",
+        "android.hardware.nfc@1.2",
         "android.hardware.secure_element@1.0",
         "libbase",
         "libcutils",
@@ -81,15 +83,12 @@
     ],
 }
 
-cc_binary {
-    name: "android.hardware.nfc@1.1-service",
-    defaults: ["hidl_defaults"],
-    proprietary: true,
-    init_rc: ["1.1/android.hardware.nfc@1.1-service.rc"],
+cc_defaults {
+    name: "nxp_nfc_defaults",
     relative_install_path: "hw",
+    proprietary: true,
+    defaults: ["hidl_defaults"],
     srcs: [
-        "1.1/NxpNfcService.cpp",
-        "1.1/Nfc.cpp",
         "extns/impl/NxpNfc.cpp",
     ],
 
@@ -102,6 +101,7 @@
         "libutils",
         "android.hardware.nfc@1.0",
         "android.hardware.nfc@1.1",
+        "android.hardware.nfc@1.2",
         "libhidlbase",
         "libhidltransport",
         "libhwbinder",
@@ -110,3 +110,23 @@
         "vendor.nxp.nxpnfc@1.0",
     ],
 }
+
+cc_binary {
+    name: "android.hardware.nfc@1.1-service",
+    init_rc: ["1.1/android.hardware.nfc@1.1-service.rc"],
+    defaults: ["nxp_nfc_defaults"],
+    srcs: [
+        "1.1/NxpNfcService.cpp",
+        "1.1/Nfc.cpp",
+    ],
+}
+
+cc_binary {
+    name: "android.hardware.nfc@1.2-service",
+    init_rc: ["1.2/android.hardware.nfc@1.2-service.rc"],
+    defaults: ["nxp_nfc_defaults"],
+    srcs: [
+        "1.2/NxpNfcService.cpp",
+        "1.2/Nfc.cpp",
+    ],
+}
diff --git a/halimpl/hal/phNxpNciHal.cc b/halimpl/hal/phNxpNciHal.cc
index 15ebac9..7d3264d 100755
--- a/halimpl/hal/phNxpNciHal.cc
+++ b/halimpl/hal/phNxpNciHal.cc
@@ -13,13 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
+#include "NfccPowerTracker.h"
+#include "hal_nxpese.h"
+#include "hal_nxpnfc.h"
+#include "spi_spm.h"
+#include <EseAdaptation.h>
+#include <cutils/properties.h>
 #include <log/log.h>
 #include <phDal4Nfc_messageQueueLib.h>
 #include <phDnldNfc.h>
 #include <phNxpConfig.h>
 #include <phNxpLog.h>
-#include <cutils/properties.h>
 #include <phNxpNciHal.h>
 #include <phNxpNciHal_Adaptation.h>
 #include <phNxpNciHal_Dnld.h>
@@ -27,12 +31,9 @@
 #include <phNxpNciHal_ext.h>
 #include <phTmlNfc.h>
 #include <sys/stat.h>
-#include <EseAdaptation.h>
-#include "hal_nxpnfc.h"
-#include "hal_nxpese.h"
-#include "spi_spm.h"
 
 using namespace android::hardware::nfc::V1_1;
+using namespace android::hardware::nfc::V1_2;
 using android::hardware::nfc::V1_1::NfcEvent;
 
 /*********************** Global Variables *************************************/
@@ -728,7 +729,7 @@
       NXPLOG_NCIHAL_D("FW download Success");
     }
   }
-
+  NfccPowerTracker::getInstance().Initialize();
   /* Call open complete */
   phNxpNciHal_MinOpen_complete(wConfigStatus);
   NXPLOG_NCIHAL_D("phNxpNciHal_MinOpen(): exit");
@@ -974,6 +975,9 @@
     goto clean_and_return;
   }
 
+  NfccPowerTracker::getInstance().ProcessCmd(
+      (uint8_t *)nxpncihal_ctrl.p_cmd_data, (uint16_t)nxpncihal_ctrl.cmd_len);
+
 retry:
 
   data_len = nxpncihal_ctrl.cmd_len;
@@ -1107,6 +1111,10 @@
 
     phNxpNciHal_print_res_status(pInfo->pBuff, &pInfo->wLength);
 
+    if ((nxpncihal_ctrl.p_rx_data[0x00] & NCI_MT_MASK) == NCI_MT_NTF) {
+      NfccPowerTracker::getInstance().ProcessNtf(nxpncihal_ctrl.p_rx_data,
+                                                 nxpncihal_ctrl.rx_data_len);
+    }
     /* Check if response should go to hal module only */
     if (nxpncihal_ctrl.hal_ext_enabled == TRUE &&
         (nxpncihal_ctrl.p_rx_data[0x00] & NCI_MT_MASK) == NCI_MT_RSP) {
@@ -2153,7 +2161,7 @@
 
     NXPLOG_NCIHAL_D("phNxpNciHal_close - phOsalNfc_DeInit completed");
   }
-
+  NfccPowerTracker::getInstance().Pause();
   CONCURRENCY_UNLOCK();
 
   phNxpNciHal_cleanup_monitor();
@@ -2197,6 +2205,7 @@
  ******************************************************************************/
 int phNxpNciHal_configDiscShutdown(void) {
   NFCSTATUS status;
+  NfccPowerTracker::getInstance().Reset();
 
   status = phNxpNciHal_close(true);
   if(status != NFCSTATUS_SUCCESS) {
@@ -2217,12 +2226,12 @@
  *
  ******************************************************************************/
 
-void phNxpNciHal_getVendorConfig(NfcConfig& config) {
+void phNxpNciHal_getVendorConfig(android::hardware::nfc::V1_1::NfcConfig& config) {
   unsigned long num = 0;
   std::array<uint8_t, NXP_MAX_CONFIG_STRING_LEN> buffer;
   buffer.fill(0);
   long retlen = 0;
-  memset(&config, 0x00, sizeof(NfcConfig));
+  memset(&config, 0x00, sizeof(android::hardware::nfc::V1_1::NfcConfig));
 
   phNxpNciHal_getPersistUiccSetting();
 
@@ -2280,6 +2289,42 @@
 }
 
 /******************************************************************************
+ * Function         phNxpNciHal_getVendorConfig_1_2
+ *
+ * Description      This function can be used by HAL to inform
+ *                 to update vendor configuration parametres
+ *
+ * Returns          void.
+ *
+ ******************************************************************************/
+
+void phNxpNciHal_getVendorConfig_1_2(android::hardware::nfc::V1_2::NfcConfig& config) {
+  unsigned long num = 0;
+  std::array<uint8_t, NXP_MAX_CONFIG_STRING_LEN> buffer;
+  buffer.fill(0);
+  long retlen = 0;
+  memset(&config, 0x00, sizeof(android::hardware::nfc::V1_2::NfcConfig));
+  phNxpNciHal_getVendorConfig(config.v1_1);
+
+  if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_UICC, (char*)buffer.data(), buffer.size(), &retlen)) {
+    config.offHostRouteUicc.resize(retlen);
+    for(int i=0; i<retlen; i++)
+      config.offHostRouteUicc[i] = buffer[i];
+  }
+
+  if (GetNxpByteArrayValue(NAME_OFFHOST_ROUTE_ESE, (char*)buffer.data(), buffer.size(), &retlen)) {
+    config.offHostRouteEse.resize(retlen);
+    for(int i=0; i<retlen; i++)
+      config.offHostRouteEse[i] = buffer[i];
+  }
+
+  if (GetNxpNumValue(NAME_DEFAULT_ISODEP_ROUTE, &num, sizeof(num))) {
+      config.defaultIsoDepRoute = num;
+  }
+
+}
+
+/******************************************************************************
  * Function         phNxpNciHal_notify_i2c_fragmentation
  *
  * Description      This function can be used by HAL to inform
diff --git a/halimpl/inc/phNxpNciHal_Adaptation.h b/halimpl/inc/phNxpNciHal_Adaptation.h
index c2a02cc..7da4fd5 100755
--- a/halimpl/inc/phNxpNciHal_Adaptation.h
+++ b/halimpl/inc/phNxpNciHal_Adaptation.h
@@ -18,10 +18,10 @@
 #define _PHNXPNCIHAL_ADAPTATION_H_
 
 #include <hardware/nfc.h>
-#include <android/hardware/nfc/1.1/INfc.h>
-#include <android/hardware/nfc/1.1/types.h>
+#include <android/hardware/nfc/1.2/INfc.h>
+#include <android/hardware/nfc/1.2/types.h>
 
-using ::android::hardware::nfc::V1_1::NfcConfig;
+using ::android::hardware::nfc::V1_2::NfcConfig;
 
 typedef struct {
   struct nfc_nci_device nci_device;
@@ -42,5 +42,6 @@
 int phNxpNciHal_power_cycle(void);
 int phNxpNciHal_ioctl(long arg, void* p_data);
 void phNxpNciHal_do_factory_reset(void);
-void phNxpNciHal_getVendorConfig(NfcConfig& config);
+void phNxpNciHal_getVendorConfig(android::hardware::nfc::V1_1::NfcConfig& config);
+void phNxpNciHal_getVendorConfig_1_2(NfcConfig& config);
 #endif /* _PHNXPNCIHAL_ADAPTATION_H_ */
diff --git a/halimpl/libnfc-nxp-PN81B_example_NCI2_0.conf b/halimpl/libnfc-nxp-PN81B_example_NCI2_0.conf
index 03bcb20..d3fbec9 100755
--- a/halimpl/libnfc-nxp-PN81B_example_NCI2_0.conf
+++ b/halimpl/libnfc-nxp-PN81B_example_NCI2_0.conf
@@ -127,7 +127,8 @@
 # DWP intf behavior config, SVDD Load activated by default if set to 0x31 A037
 # SPI CL Sync enable  A098
 # EVT END OF Operation delay A0B2
-NXP_CORE_CONF_EXTN={20, 02, 31, 0C,
+# Power tracker command  A091
+NXP_CORE_CONF_EXTN={20, 02, 35, 0D,
     A0, EC, 01, 01,
     A0, ED, 01, 01,
     A0, 5E, 01, 01,
@@ -139,7 +140,8 @@
     A0, D8, 01, 02,
     A0, D5, 01, 0A,
     A0, 98, 01, 03,
-    A0, B2, 01, 19
+    A0, B2, 01, 19,
+    A0, 91, 01, 01
 }
 
 ###############################################################################
diff --git a/halimpl/libnfc-nxp-PN81T_example_NCI2_0.conf b/halimpl/libnfc-nxp-PN81T_example_NCI2_0.conf
index c6d81f9..1286368 100755
--- a/halimpl/libnfc-nxp-PN81T_example_NCI2_0.conf
+++ b/halimpl/libnfc-nxp-PN81T_example_NCI2_0.conf
@@ -127,7 +127,7 @@
 # DWP intf behavior config, SVDD Load activated by default if set to 0x31 A037
 # SPI CL Sync enable  A098
 # EVT END OF Operation delay A0B2
-NXP_CORE_CONF_EXTN={20, 02, 31, 0C,
+NXP_CORE_CONF_EXTN={20, 02, 35, 0D,
     A0, EC, 01, 01,
     A0, ED, 01, 01,
     A0, 5E, 01, 01,
@@ -139,7 +139,8 @@
     A0, D8, 01, 02,
     A0, D5, 01, 0A,
     A0, 98, 01, 03,
-    A0, B2, 01, 19
+    A0, B2, 01, 19,
+    A0, 91, 01, 01
 }
 
 ###############################################################################
diff --git a/halimpl/utils/NfccPowerTracker.cpp b/halimpl/utils/NfccPowerTracker.cpp
new file mode 100644
index 0000000..99f2b8a
--- /dev/null
+++ b/halimpl/utils/NfccPowerTracker.cpp
@@ -0,0 +1,438 @@
+/******************************************************************************
+ *
+ *  Copyright 2018 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.
+ *
+ ******************************************************************************/
+#define LOG_TAG "NfccPowerTracker"
+#include "NfccPowerTracker.h"
+#include "phNxpNciHal_ext.h"
+#include <assert.h>
+#include <fstream>
+#include <iostream>
+#include <log/log.h>
+#include <sstream>
+#include <stdio.h>
+#include <sys/file.h>
+#include <sys/time.h>
+using namespace std;
+
+extern bool nfc_debug_enabled;
+extern phNxpNciHal_Control_t nxpncihal_ctrl;
+static const uint64_t PWR_TRK_ERROR_MARGIN_IN_MILLISEC = 60000;
+static const std::string POWER_TRACKER_LOG_FILE =
+    "/data/vendor/nfc/nfc_power_state.txt";
+static const uint16_t TIMER_COUNT_MASK = 0x7FFF;
+
+NfccPowerTracker::NfccPowerTracker() {
+  mIsFirstPwrTrkNtfRecvd = false;
+  mLastPowerTrackAborted = false;
+  /*Default standby time*/
+  mStandbyTimePerDiscLoopInMillisec = 1000;
+}
+NfccPowerTracker::~NfccPowerTracker() {}
+
+/*******************************************************************************
+**
+** Function         NfccPowerTracker::getInstance
+**
+** Description      access class singleton
+**
+** Returns          pointer to the singleton object
+**
+*******************************************************************************/
+NfccPowerTracker &NfccPowerTracker::getInstance() {
+  static NfccPowerTracker sPwrInstance;
+  return sPwrInstance;
+}
+/*******************************************************************************
+**
+** Function         Initialize
+**
+** Description      get all prerequisite information from NFCC needed for
+**                  Power tracker calculations.
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::Initialize() {
+  /*get total duration of discovery loop from NFCC using GET CONFIG command*/
+  uint8_t cmdGetConfigDiscLoopDuration[] = {0x20, 0x03, 0x02, 0x01, 0x00};
+  int status = phNxpNciHal_send_ext_cmd(sizeof(cmdGetConfigDiscLoopDuration),
+                                        cmdGetConfigDiscLoopDuration);
+  if (status != 0) {
+    ALOGD_IF(nfc_debug_enabled, "NfccPowerTracker::Initialize: failed");
+    return;
+  }
+  /*Check for valid get config response and update stanby time*/
+  if (nxpncihal_ctrl.p_rx_data[0] == 0x40 &&
+      nxpncihal_ctrl.p_rx_data[1] == 0x03 &&
+      nxpncihal_ctrl.p_rx_data[2] == 0x06 &&
+      nxpncihal_ctrl.p_rx_data[3] == 0x00 &&
+      nxpncihal_ctrl.p_rx_data[4] == 0x01 &&
+      nxpncihal_ctrl.p_rx_data[5] == 0x00 &&
+      nxpncihal_ctrl.p_rx_data[6] == 0x02) {
+    mStandbyTimePerDiscLoopInMillisec = (uint32_t)(
+        (nxpncihal_ctrl.p_rx_data[8] << 8) | nxpncihal_ctrl.p_rx_data[7]);
+    ALOGD_IF(nfc_debug_enabled, "mStandbyTimePerDiscLoopInMillisec value : %d",
+             mStandbyTimePerDiscLoopInMillisec);
+  }
+}
+
+/*******************************************************************************
+**
+** Function         TimeDiff
+**
+** Description      Computes time difference in milliseconds.
+**
+** Returns          Time difference in milliseconds
+**
+*******************************************************************************/
+uint64_t NfccPowerTracker::TimeDiff(struct timespec start,
+                                    struct timespec end) {
+  uint64_t startTimeInMillisec =
+      start.tv_sec * 1000 + (start.tv_nsec / 1000000);
+  uint64_t endTimeInMillisec = end.tv_sec * 1000 + (end.tv_nsec / 1000000);
+
+  assert(startTimeInMillisec > endTimeInMillisec);
+  return (endTimeInMillisec - startTimeInMillisec);
+}
+
+/*******************************************************************************
+**
+** Function         NfccPowerTracker::ProcessCmd
+**
+** Description      Parse the commands going to NFCC,
+**                  get the time at which power relevant commands are sent
+**                  (ex:Screen state/OMAPI session)is sent and
+**                  log/cache the timestamp to file
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::ProcessCmd(uint8_t *cmd, uint16_t len) {
+  ALOGD_IF(nfc_debug_enabled,
+           "NfccPowerTracker::ProcessCmd: Enter,Recieved len :%d", len);
+  bool screenStateCommand;
+  if (cmd[0] == 0x20 && cmd[1] == 0x09) {
+    screenStateCommand = true;
+  } else {
+    screenStateCommand = false;
+  }
+
+  if (screenStateCommand && (cmd[3] == 0x00 || cmd[3] == 0x02)) {
+    /* Command for Screen State On-Locked or Unlocked */
+    clock_gettime(CLOCK_BOOTTIME, &mLastScreenOnTimeStamp);
+    mIsLastUpdateScreenOn = true;
+  } else if (screenStateCommand && (cmd[3] == 0x01 || cmd[3] == 0x03)) {
+    /* Command for Screen State OFF-locked or Unlocked */
+    clock_gettime(CLOCK_BOOTTIME, &mLastScreenOffTimeStamp);
+    mIsLastUpdateScreenOn = false;
+  } else if (cmd[0] == 0x20 && cmd[1] == 0x02 && cmd[2] == 0x05 &&
+             cmd[3] == 0x01 && cmd[4] == 0x00 && cmd[5] == 0x02) {
+    /* Command to update duration of discovery loop */
+    mStandbyTimePerDiscLoopInMillisec = (cmd[7] << 8 | cmd[6]);
+    ALOGD_IF(nfc_debug_enabled, "mStandbyTimePerDiscLoopInMillisec value : %d",
+             mStandbyTimePerDiscLoopInMillisec);
+  }
+}
+
+/*******************************************************************************
+**
+** Function         NfccPowerTracker::ProcessNtf
+**
+** Description      Parse the Notifications coming from NFCC,
+**                  get the time at which power relevant notifications are
+**                  received
+**                  (ex:RF ON-OFF/ACTIVATE-DEACTIVATE NTF/PROP_PWR_TRACKINFO)
+**                  calculate error in standby time by comparing the
+**                  expectated value from NFC HAL and received value from NFCC.
+**                  Cache relevant info (timestamps) to file
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::ProcessNtf(uint8_t *rsp, uint16_t rsp_len) {
+  ALOGD_IF(nfc_debug_enabled, "NfccPowerTracker::ProcessNtf: Enter");
+
+  /* Screen State Notification recieved */
+  if ((rsp[0] == 0x6F && rsp[1] == 0x05)) {
+    ProcessPowerTrackNtf(rsp, rsp_len);
+  } else if (rsp[0] == 0x61 && rsp[1] == 0x05) {
+    /*Activation notification received. Calculate the time NFCC is
+    active in Reader/P2P/CE duration */
+    clock_gettime(CLOCK_BOOTTIME, &mActiveTimeStart);
+    if (!mIsLastUpdateScreenOn) {
+      mActiveInfo.totalTransitions++;
+    }
+  } else if (rsp[0] == 0x61 && rsp[1] == 0x06) {
+    /* Deactivation notification received Calculate the time NFCC is
+    active in Reader/P2P/CE duration.Time between Activation and
+    Deacivation gives the active time*/
+    clock_gettime(CLOCK_BOOTTIME, &mActiveTimeEnd);
+    mActiveDurationFromLastScreenUpdate +=
+        TimeDiff(mActiveTimeStart, mActiveTimeEnd);
+    if (!mIsLastUpdateScreenOn) {
+      mStandbyInfo.totalTransitions++;
+    }
+    ALOGD_IF(nfc_debug_enabled, "mActiveDurationFromLastScreenUpdate: %llu",
+             (unsigned long long)mActiveDurationFromLastScreenUpdate);
+  }
+}
+
+/*******************************************************************************
+**
+** Function         ProcessPowerTrackNtf
+**
+** Description      Process Power Tracker notification and update timingInfo to
+**                  Log File.
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::ProcessPowerTrackNtf(uint8_t *rsp, uint16_t rsp_len) {
+  /* Enable Power Tracking computations after 1st Power tracker notification
+   * is received. */
+  if (!mIsFirstPwrTrkNtfRecvd) {
+    mIsFirstPwrTrkNtfRecvd = true;
+    ifstream ifile(POWER_TRACKER_LOG_FILE.c_str());
+    if ((bool)ifile == true) {
+      mLastPowerTrackAborted = true;
+    }
+    return;
+  }
+
+  /*Duration between screen state change is taken as reference for calculating
+  active and standby time*/
+  uint64_t totalDuration = 0;
+  totalDuration =
+      mIsLastUpdateScreenOn
+          ? TimeDiff(mLastScreenOffTimeStamp, mLastScreenOnTimeStamp)
+          : TimeDiff(mLastScreenOnTimeStamp, mLastScreenOffTimeStamp);
+  if (totalDuration == 0)
+    return;
+
+  /*Calculate Active and Standby time based on the pollCount provided in the
+  Power tracker Notification from NFCC*/
+  uint16_t sPollCount = (TIMER_COUNT_MASK & ((rsp[5] << 8) | rsp[4]));
+  ALOGD_IF(nfc_debug_enabled,
+           "Poll/Timer count recived from FW is %d and rsp_len :%d", sPollCount,
+           rsp_len);
+  uint64_t standbyTime = 0, activeTime = 0;
+  if (mIsLastUpdateScreenOn) {
+    activeTime = sPollCount * ACTIVE_TIME_PER_TIMER_COUNT_IN_MILLISEC;
+    /*Check for errors in count provided by NFCC*/
+    uint64_t error = (activeTime > mActiveDurationFromLastScreenUpdate)
+                         ? (activeTime - mActiveDurationFromLastScreenUpdate)
+                         : (mActiveDurationFromLastScreenUpdate - activeTime);
+    if (error > PWR_TRK_ERROR_MARGIN_IN_MILLISEC) {
+      ALOGD_IF(nfc_debug_enabled,
+               "Active Time Error observed with value is %llu",
+               (unsigned long long)error);
+      mErrorInStandbyInfo.residencyInMsecSinceBoot += error;
+    }
+    standbyTime = (totalDuration > activeTime) ? (totalDuration - activeTime)
+                                               : (activeTime - totalDuration);
+    if (rsp[3]) {
+      /*If notification trigger is counter overflow, update the screen on
+      timestamp as there is no screen state change*/
+      clock_gettime(CLOCK_BOOTTIME, &mLastScreenOnTimeStamp);
+    }
+    mActiveInfo.totalTransitions++;
+  } else {
+    standbyTime = (sPollCount * mStandbyTimePerDiscLoopInMillisec);
+    activeTime = totalDuration > standbyTime ? (totalDuration - standbyTime)
+                                             : (standbyTime - totalDuration);
+    if (rsp[3]) {
+      /*If notification trigger is counter overflow, update the screen off
+      timestamp as there is no screen state change*/
+      clock_gettime(CLOCK_BOOTTIME, &mLastScreenOffTimeStamp);
+    }
+    /*Total transitions in screen on -> Screen Off window is same as poll count
+    provided by NFCC, as, there is transition in each discovery loop*/
+    mActiveInfo.totalTransitions += sPollCount;
+    /*1 additional transition for screen state update*/
+    mStandbyInfo.totalTransitions += (sPollCount + 1);
+  }
+
+  ALOGD_IF(nfc_debug_enabled,
+           "activeTime: %llu, standbyTime: %llu, totalDuration :%llu",
+           (unsigned long long)activeTime, (unsigned long long)standbyTime,
+           (unsigned long long)totalDuration);
+  if (mLastPowerTrackAborted) {
+    ALOGD_IF(nfc_debug_enabled,
+             "Last Hal service aborted,so retrive the power info data and "
+             "continue\n");
+    /*Read the file content and store in mActiveInfo.residencyInMsecSinceBoot
+    and mStandbyInfo.residencyInMsecSinceBoot*/
+    if (ReadPowerStateLog()) {
+      mLastPowerTrackAborted = false;
+    }
+  }
+  mStandbyInfo.residencyInMsecSinceBoot += standbyTime;
+  mActiveInfo.residencyInMsecSinceBoot += activeTime;
+  UpdatePowerStateLog(mStandbyInfo, mActiveInfo);
+  mActiveDurationFromLastScreenUpdate = 0;
+}
+/*******************************************************************************
+**
+** Function         NfccPowerTracker::UpdatePowerStateLog
+**
+** Description      update the powerstate related information in log file
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::UpdatePowerStateLog(NfccPowerStateInfo_t mStandbyInfo,
+                                           NfccPowerStateInfo_t mActiveInfo) {
+  FILE *fp;
+  const string PWR_TRK_LOG_FILE_VERSION = "1.0";
+  /*Write the Active and standby timestamp into the file*/
+  fp = fopen(POWER_TRACKER_LOG_FILE.c_str(), "w");
+  if (fp == NULL) {
+    ALOGD_IF(nfc_debug_enabled, "Failed to Open Pwr Tracker Info File\n");
+    return;
+  }
+  ostringstream PwrTrackerInfo;
+  PwrTrackerInfo << "Version: " << PWR_TRK_LOG_FILE_VERSION.c_str() << endl;
+  PwrTrackerInfo << "NFC {" << endl;
+  PwrTrackerInfo << " { " << STR_ACTIVE
+                 << std::to_string(mActiveInfo.residencyInMsecSinceBoot) << " }"
+                 << endl;
+  PwrTrackerInfo << " { " << STR_STANDBY
+                 << std::to_string(mStandbyInfo.residencyInMsecSinceBoot)
+                 << " }" << endl;
+  PwrTrackerInfo << "}";
+  ALOGD_IF(nfc_debug_enabled,
+           "mActiveInfo.residencyInMsecSinceBoot: %llu, "
+           "mActiveInfo.totalTransitions: %llu,"
+           "mStandbyInfo.residencyInMsecSinceBoot "
+           ":%llu,mStandbyInfo.totalTransitions: %llu"
+           "mErrorInStandbyInfo.residencyInMsecSinceBoot: %llu",
+           (unsigned long long)mActiveInfo.residencyInMsecSinceBoot,
+           (unsigned long long)mActiveInfo.totalTransitions,
+           (unsigned long long)mStandbyInfo.residencyInMsecSinceBoot,
+           (unsigned long long)mStandbyInfo.totalTransitions,
+           (unsigned long long)mErrorInStandbyInfo.residencyInMsecSinceBoot);
+  string PwrInfo = PwrTrackerInfo.str();
+  if (!TryLockFile(fp)) {
+    ALOGD_IF(nfc_debug_enabled,
+             "Failed to Lock PwrTracker File.Skipping update\n");
+    fclose(fp);
+    return;
+  }
+  fwrite(PwrInfo.c_str(), sizeof(char), PwrInfo.length(), fp);
+  fflush(fp);
+  UnlockFile(fp);
+  fclose(fp);
+}
+/*******************************************************************************
+ **
+ ** Function         ReadPowerStateLog
+ **
+ ** Description      Retrieve powerstate related information from log file.
+ **
+ ** Returns          true if read successful, false otherwise.
+ **
+ *******************************************************************************/
+bool NfccPowerTracker::ReadPowerStateLog() {
+  ifstream pwrStateFileStream;
+  string itemName;
+  ALOGD_IF(nfc_debug_enabled, "NfccPowerTracker::ReadPowerStateLog: Enter \n");
+  pwrStateFileStream.open(POWER_TRACKER_LOG_FILE.c_str());
+  if (pwrStateFileStream.fail()) {
+    ALOGE("Error: %s", strerror(errno));
+    return false;
+  }
+
+  /*Check for required string(time in millisec) in the log file and convert it
+    to integer*/
+  while (pwrStateFileStream >> itemName) {
+    if (STR_ACTIVE.compare(itemName) == 0) {
+      pwrStateFileStream >> itemName;
+      mActiveInfo.residencyInMsecSinceBoot = stoull(itemName.c_str(), nullptr);
+    } else if (STR_STANDBY.compare(itemName) == 0) {
+      pwrStateFileStream >> itemName;
+      mStandbyInfo.residencyInMsecSinceBoot = stoull(itemName.c_str(), nullptr);
+    }
+  }
+
+  ALOGD_IF(nfc_debug_enabled,
+           "Value retrieved from Powertracker file is"
+           "activeTime: %llu and standbyTime: %llu\n",
+           (unsigned long long)mActiveInfo.residencyInMsecSinceBoot,
+           (unsigned long long)mStandbyInfo.residencyInMsecSinceBoot);
+  pwrStateFileStream.close();
+  return true;
+}
+/*******************************************************************************
+**
+** Function         Pause
+**
+** Description      Pause Power state Information Tracking,Tracking will resume
+**                  once next power tracker notification is recieved as part of
+**                  ProcessNtf.
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::Pause() { mIsFirstPwrTrkNtfRecvd = false; }
+
+/*******************************************************************************
+**
+** Function         Reset
+**
+** Description      Stop power track information processing and delete
+**                  power tracker log file.
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::Reset() {
+  ALOGD_IF(nfc_debug_enabled, "NfccPowerTracker::Reset enter");
+  if (remove(POWER_TRACKER_LOG_FILE.c_str()) != 0) {
+    ALOGD_IF(nfc_debug_enabled, "Error deleting Power tracker file");
+  }
+}
+/*******************************************************************************
+**
+** Function         TryLockFile
+**
+** Description      Lock PowerTracker log file. Any application trying to read
+**                  from PowerTracker log file shall acquire lock before reading
+**                  to avoid inconsistent data.
+**
+** Returns          true if locking was successful
+**                  false if there was a failure to lock PowerTracker log file.
+*******************************************************************************/
+bool NfccPowerTracker::TryLockFile(FILE *fp) {
+  uint8_t retryCount = 5;
+  do {
+    if (!flock(fileno(fp), LOCK_EX | LOCK_NB))
+      return true;
+    usleep(10000); /*10 millisec*/
+  } while (retryCount--);
+
+  return false;
+}
+/*******************************************************************************
+**
+** Function         UnlockFile
+**
+** Description      Unlock previously locked PowerTracker log file.
+**
+** Returns          void
+**
+*******************************************************************************/
+void NfccPowerTracker::UnlockFile(FILE *fp) { flock(fileno(fp), LOCK_UN); }
diff --git a/halimpl/utils/NfccPowerTracker.h b/halimpl/utils/NfccPowerTracker.h
new file mode 100644
index 0000000..3b3e8c0
--- /dev/null
+++ b/halimpl/utils/NfccPowerTracker.h
@@ -0,0 +1,195 @@
+/******************************************************************************
+ *
+ *  Copyright 2018 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>
+#include <time.h>
+#include <vector>
+
+/*Time spent in Active mode per count provided by NFCC*/
+static const uint32_t ACTIVE_TIME_PER_TIMER_COUNT_IN_MILLISEC = 20;
+/*Types of  Power states supported by NFCC */
+typedef struct NfccPowerStateInfo {
+  /* state name: Active/Standby */
+  std::string name;
+  /* Time spent in msec at this  power state since boot */
+  uint64_t residencyInMsecSinceBoot;
+  /* Total number of times Nfcc entered this state */
+  uint64_t totalTransitions;
+} NfccPowerStateInfo_t;
+
+/*Class to track the time spent in Standby mode by NFCC*/
+class NfccPowerTracker {
+public:
+  static NfccPowerTracker &getInstance();
+
+  /*******************************************************************************
+  **
+  ** Function         Initialize
+  **
+  ** Description      get all prerequisite information from NFCC needed for
+  **                  Power tracker calculations.
+  **
+  ** Returns          void
+  **
+  *******************************************************************************/
+  void Initialize();
+
+  /*******************************************************************************
+  **
+  ** Function         ProcessCmd
+  **
+  ** Description      Parse the commands going to NFCC,
+  **                  get the time at which power relevant commands are sent
+  **                  (ex:Screen state/OMAPI session)is sent and
+  **                  log/cache the timestamp to file.
+  **
+  ** Returns          void
+  **
+  *******************************************************************************/
+  void ProcessCmd(uint8_t *, uint16_t len);
+
+  /*******************************************************************************
+  **
+  ** Function         ProcessNtf
+  **
+  ** Description      Parse the Notifications coming from NFCC,
+  **                  get the time at which power relevant notifications are
+  **                  received (ex:RF ON-OFF/ACTIVATE-DEACTIVATE NTF/
+  **                  PROP_PWR_TRACKINFO). Calculate error in standby time by
+  **                  comparing the expectated value from NFC HAL and received
+  **                  value from NFCC. Update power state duration info
+  **                  to file.
+  **
+  ** Returns          void
+  **
+  *******************************************************************************/
+  void ProcessNtf(uint8_t *cmd, uint16_t len);
+
+  /*******************************************************************************
+  **
+  ** Function         Pause
+  **
+  ** Description      Pause Power state Information Tracking,Tracking will
+  **                  resume once next power tracker notification is recieved as
+  **                  part of ProcessNtf.
+  **
+  ** Returns          void
+  **
+  *******************************************************************************/
+  void Pause();
+
+  /*******************************************************************************
+  **
+  ** Function         Reset
+  **
+  ** Description      Stop power tracker information processing and delete
+  **                  power track log file.
+  **
+  ** Returns          void
+  **
+  *******************************************************************************/
+  void Reset();
+
+private:
+  NfccPowerTracker();
+  ~NfccPowerTracker();
+
+  /*******************************************************************************
+  **
+  ** Function         UpdatePowerStateLog
+  **
+  ** Description      update the powerstate related information in log file
+  **
+  ** Returns          void
+  **
+  *******************************************************************************/
+  void UpdatePowerStateLog(NfccPowerStateInfo_t standbyTime,
+                           NfccPowerStateInfo_t activeTime);
+
+  /*******************************************************************************
+   **
+   ** Function         ReadPowerStateLog
+   **
+   ** Description      Retrieve powerstate related information from log file.
+   **
+   ** Returns          true if read successful, false otherwise.
+   **
+   *******************************************************************************/
+  bool ReadPowerStateLog();
+
+  /*******************************************************************************
+   **
+   ** Function         ProcessPowerTrackNtf
+   **
+   ** Description      Process Power Tracker notification.
+   **
+   ** Returns          void
+   **
+   *******************************************************************************/
+  void ProcessPowerTrackNtf(uint8_t *rsp, uint16_t rsp_len);
+
+  /*******************************************************************************
+  **
+  ** Function         TimeDiff
+  **
+  ** Description      Computes time difference in milliseconds.
+  **
+  ** Returns          Time difference in milliseconds
+  **
+  *******************************************************************************/
+  uint64_t TimeDiff(timespec start, timespec end);
+  /*******************************************************************************
+  **
+  ** Function         TryLockFile
+  **
+  ** Description      Lock PowerTracker log file. Any application trying to read
+  **                  from PowerTracker log file shall acquire lock before
+  **                  reading to avoid inconsistent data.
+  **
+  ** Returns          true if locking was successful
+  **                  false if there was a failure to lock file.
+  *******************************************************************************/
+  bool TryLockFile(FILE *fp);
+  /*******************************************************************************
+  **
+  ** Function         UnlockFile
+  **
+  ** Description      Unlock previously locked PowerTracker log file.
+  **
+  ** Returns          void
+  *******************************************************************************/
+  void UnlockFile(FILE *fp);
+  struct timespec mLastScreenOffTimeStamp = {0, 0},
+                  mLastScreenOnTimeStamp = {0, 0};
+  /*Used to calculate time NFCC is active during Card emulation/P2P/Reader
+   * modes*/
+  struct timespec mActiveTimeStart = {0, 0}, mActiveTimeEnd = {0, 0};
+
+  bool mIsLastUpdateScreenOn;
+  bool mIsFirstPwrTrkNtfRecvd;
+
+  uint64_t mActiveDurationFromLastScreenUpdate = 0;
+  NfccPowerStateInfo_t mActiveInfo, mStandbyInfo, mErrorInStandbyInfo;
+
+  /*Last powertracker processing aborted due to NFC HAL Service abort*/
+  bool mLastPowerTrackAborted = false;
+  /* Time spent in standby mode in one discovery loop containing poll */
+  uint32_t mStandbyTimePerDiscLoopInMillisec;
+  const std::string STR_ACTIVE = "Active: ", STR_STANDBY = "StandBy: ";
+};
diff --git a/halimpl/utils/phNxpConfig.h b/halimpl/utils/phNxpConfig.h
index e6931e2..3901c1d 100755
--- a/halimpl/utils/phNxpConfig.h
+++ b/halimpl/utils/phNxpConfig.h
@@ -104,6 +104,9 @@
 #define NAME_NFA_PROPRIETARY_CFG "NFA_PROPRIETARY_CFG"
 #define NAME_PRESENCE_CHECK_ALGORITHM "PRESENCE_CHECK_ALGORITHM"
 #define NAME_NXP_PHASE_TIRM_OFFSET_SIGN_UPDATE "NXP_PHASE_TIRM_OFFSET_SIGN_UPDATE"
+#define NAME_OFFHOST_ROUTE_ESE "OFFHOST_ROUTE_ESE"
+#define NAME_OFFHOST_ROUTE_UICC "OFFHOST_ROUTE_UICC"
+#define NAME_DEFAULT_ISODEP_ROUTE "DEFAULT_ISODEP_ROUTE"
 
 /* default configuration */
 #define default_storage_location "/data/vendor/nfc"