NFC: Import baseline of third party libnfc-nci

Import baseline of third party libnfc-nci and hal.

(merged from branch "nxpnfc-project/br_android_ncihalx_m")

Change-Id: I258c2c854d4ffee4605041af3d2132540fd67d59
diff --git a/Android.mk b/Android.mk
index eb36bb6..aa04ff6 100644
--- a/Android.mk
+++ b/Android.mk
@@ -8,26 +8,70 @@
 
 
 LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
 NFA := src/nfa
 NFC := src/nfc
 HAL := src/hal
 UDRV := src/udrv
-HALIMPL := halimpl/bcm2079x
+
 D_CFLAGS := -DANDROID -DBUILDCFG=1
 
+#NXP PN547 Enable
+D_CFLAGS += -DNXP_EXTNS=TRUE
+#variables for NFC_NXP_CHIP_TYPE
+PN547C2 := 1
+PN548C2 := 2
+PN551C2 := 3
+NQ110 := $PN547C2
+NQ120 := $PN547C2
+NQ210 := $PN548C2
+NQ220 := $PN548C2
 
+ifeq ($(PN547C2),1)
+D_CFLAGS += -DPN547C2=1
+endif
+ifeq ($(PN548C2),2)
+D_CFLAGS += -DPN548C2=2
+endif
+ifeq ($(PN551C2),3)
+D_CFLAGS += -DPN551C2=3
+endif
+
+#### Select the JCOP OS Version ####
+JCOP_VER_3_0 := 1
+JCOP_VER_3_1_1 := 2
+JCOP_VER_3_1_2 := 3
+JCOP_VER_3_2 := 4
+
+LOCAL_CFLAGS += -DJCOP_VER_3_0=$(JCOP_VER_3_0)
+LOCAL_CFLAGS += -DJCOP_VER_3_1_1=$(JCOP_VER_3_1_1)
+LOCAL_CFLAGS += -DJCOP_VER_3_1_2=$(JCOP_VER_3_1_2)
+LOCAL_CFLAGS += -DJCOP_VER_3_2=$(JCOP_VER_3_2)
+
+NFC_NXP_ESE:= FALSE
+ifeq ($(NFC_NXP_ESE),TRUE)
+LOCAL_CFLAGS += -DNFC_NXP_ESE=TRUE
+LOCAL_CFLAGS += -DNFC_NXP_ESE_VER=$(JCOP_VER_3_1_2)
+else
+LOCAL_CFLAGS += -DNFC_NXP_ESE=FALSE
+endif
+
+#### Select the CHIP ####
+D_CFLAGS += -DNFC_NXP_CHIP_TYPE=PN548C2
+
+#Gemalto SE support
+D_CFLAGS += -DGEMALTO_SE_SUPPORT
+D_CFLAGS += -DNXP_UICC_ENABLE
+D_CFLAGS += -DNFC_POWER_MANAGEMENT=FALSE
 ######################################
 # Build shared library system/lib/libnfc-nci.so for stack code.
 
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_ARM_MODE := arm
 LOCAL_MODULE := libnfc-nci
 LOCAL_MODULE_TAGS := optional
 LOCAL_SHARED_LIBRARIES := libhardware_legacy libcutils liblog libdl libhardware
-LOCAL_CFLAGS := $(D_CFLAGS)
-LOCAL_C_INCLUDES := \
-    $(LOCAL_PATH)/src/include \
+LOCAL_CFLAGS += $(D_CFLAGS)
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src/include \
     $(LOCAL_PATH)/src/gki/ulinux \
     $(LOCAL_PATH)/src/gki/common \
     $(LOCAL_PATH)/$(NFA)/include \
@@ -44,39 +88,9 @@
     $(call all-c-files-under, src/adaptation) \
     $(call all-cpp-files-under, src/adaptation) \
     $(call all-c-files-under, src/gki) \
-    $(HALIMPL)/adaptation/android_logmsg.cpp \
     src/nfca_version.c
 include $(BUILD_SHARED_LIBRARY)
 
 
 ######################################
-# Build shared library system/lib/hw/nfc_nci.*.so for Hardware Abstraction Layer.
-# Android's generic HAL (libhardware.so) dynamically loads this shared library.
-
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_MODULE := nfc_nci.bcm2079x.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := $(call all-c-files-under, $(HALIMPL)) \
-    $(call all-cpp-files-under, $(HALIMPL)) \
-    src/adaptation/CrcChecksum.cpp \
-    src//nfca_version.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils libhardware_legacy
-LOCAL_MODULE_TAGS := optional
-LOCAL_C_INCLUDES := \
-    $(LOCAL_PATH)/$(HALIMPL)/include \
-    $(LOCAL_PATH)/$(HALIMPL)/gki/ulinux \
-    $(LOCAL_PATH)/$(HALIMPL)/gki/common \
-    $(LOCAL_PATH)/$(HAL)/include \
-    $(LOCAL_PATH)/$(HAL)/int \
-    $(LOCAL_PATH)/src/include \
-    $(LOCAL_PATH)/$(NFC)/include \
-    $(LOCAL_PATH)/$(NFA)/include \
-    $(LOCAL_PATH)/$(UDRV)/include
-LOCAL_CFLAGS := $(D_CFLAGS) -DNFC_HAL_TARGET=TRUE -DNFC_RW_ONLY=TRUE
-LOCAL_CPPFLAGS := $(LOCAL_CFLAGS)
-include $(BUILD_SHARED_LIBRARY)
-
-
-######################################
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b616c15
--- /dev/null
+++ b/README.md
@@ -0,0 +1,21 @@
+#NFC_NCIHAL_libnfc-nci
+
+####Git Repository
+
+| DESCRIPTION        | CHECKOUT COMMAND          |
+|:-------------:|:-------------:| 
+| NFC_NCIHAL_libnfc-nci     |  git clone https://github.com/NXPNFCProject/NFC_NCIHAL_libnfc-nci.git |
+
+####Supported Versions on "master" Branch
+
+| Android Version        | NXP Release          | NXP Tag  |
+| :-------------: |:-------------:| :-----:|
+| android-5.0.0_r1/android5.1.0_r1     |  3.5.0_L (PN547C2/PN548C2) |  NFC_NCIHALx_AR0F.3.5.0_L_OpnSrc |
+
+####Supported Versions on "br_android_ncihalx_m" Branch
+
+| Android Version        | NXP Release          | NXP Tag  |
+| :-------------: |:-------------:| :-----:|
+| android-6.0.0_r1                     |  4.2.0_M (PN547C2/PN548C2) |  NFC_NCIHALx_AR0F.4.2.0_M_OpnSrc |
+
+
diff --git a/halimpl/pn54x/Android.mk b/halimpl/pn54x/Android.mk
index c923a46..2bd1269 100644
--- a/halimpl/pn54x/Android.mk
+++ b/halimpl/pn54x/Android.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2014 NXP Semiconductors
+# Copyright (C) 2011 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -21,30 +21,42 @@
  )
 endef
 
+
+HAL_SUFFIX := $(TARGET_DEVICE)
+ifeq ($(TARGET_DEVICE),crespo)
+	HAL_SUFFIX := herring
+endif
+
 LOCAL_PRELINK_MODULE := false
 LOCAL_ARM_MODE := arm
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
-LOCAL_MODULE := nfc_nci.$(TARGET_DEVICE)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
+LOCAL_MODULE := nfc_nci.pn54x.default
 LOCAL_MODULE_RELATIVE_PATH := hw
 LOCAL_SRC_FILES := $(call all-c-files-under, .)  $(call all-cpp-files-under, .)
-LOCAL_SHARED_LIBRARIES := liblog libcutils libhardware_legacy libdl libhardware
+LOCAL_SHARED_LIBRARIES := libhardware_legacy libcutils liblog libdl
 LOCAL_MODULE_TAGS := optional
 
 LOCAL_C_INCLUDES += \
-    $(LOCAL_PATH)/utils \
-    $(LOCAL_PATH)/inc \
-    $(LOCAL_PATH)/common \
-    $(LOCAL_PATH)/dnld \
-    $(LOCAL_PATH)/hal \
-    $(LOCAL_PATH)/log \
-    $(LOCAL_PATH)/tml \
-    $(LOCAL_PATH)/self-test
+	$(LOCAL_PATH)/utils \
+	$(LOCAL_PATH)/inc \
+	$(LOCAL_PATH)/common \
+	$(LOCAL_PATH)/dnld \
+	$(LOCAL_PATH)/hal \
+	$(LOCAL_PATH)/log \
+	$(LOCAL_PATH)/tml \
+	$(LOCAL_PATH)/self-test
+
 
 #variables for NFC_NXP_CHIP_TYPE
 PN547C2 := 1
 PN548C2 := 2
-
+NQ110 := $PN547C2
+NQ120 := $PN547C2
+NQ210 := $PN548C2
+NQ220 := $PN548C2
+#NXP PN547 Enable
 ifeq ($(PN547C2),1)
 LOCAL_CFLAGS += -DPN547C2=1
 endif
@@ -58,6 +70,8 @@
 LOCAL_CFLAGS += -DANDROID \
         -DNXP_UICC_ENABLE -DNXP_HW_SELF_TEST
 LOCAL_CFLAGS += -DNFC_NXP_HFO_SETTINGS=FALSE
+D_CFLAGS += -DNFC_POWER_MANAGEMENT=FALSE
+LOCAL_CFLAGS += $(D_CFLAGS)
 #LOCAL_CFLAGS += -DFELICA_CLT_ENABLE
-
+#-DNXP_PN547C1_DOWNLOAD
 include $(BUILD_SHARED_LIBRARY)
diff --git a/halimpl/pn54x/common/phNfcCommon.h b/halimpl/pn54x/common/phNfcCommon.h
index 8e040d4..fe69688 100644
--- a/halimpl/pn54x/common/phNfcCommon.h
+++ b/halimpl/pn54x/common/phNfcCommon.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@
 
 /* HAL Version number (Updated as per release) */
 #define NXP_MW_VERSION_MAJ  (1U)
-#define NXP_MW_VERSION_MIN  (0U)
+#define NXP_MW_VERSION_MIN  (1U)
 
 /*
  *****************************************************************
diff --git a/halimpl/pn54x/common/phNfcCompId.h b/halimpl/pn54x/common/phNfcCompId.h
index f88fbb4..2d94e67 100644
--- a/halimpl/pn54x/common/phNfcCompId.h
+++ b/halimpl/pn54x/common/phNfcCompId.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/common/phNfcStatus.h b/halimpl/pn54x/common/phNfcStatus.h
index fb1d818..59dbda1 100644
--- a/halimpl/pn54x/common/phNfcStatus.h
+++ b/halimpl/pn54x/common/phNfcStatus.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -183,6 +183,14 @@
 #define NFCSTATUS_NOT_ALLOWED                                 (0x003A)
 
 /*
+ * FW version error while performing FW download,
+ * FW major version mismatch (cannot downgrade FW major version) or FW version already upto date
+ * User may be trying to flash Mobile FW on top of Infra FW, which is not allowed
+ * Download appropriate version of FW
+ */
+#define NFCSTATUS_FW_VERSION_ERROR                            (0x003C)
+
+/*
  *  The system is busy with the previous operation.
  */
 #define NFCSTATUS_BUSY                                        (0x006F)
@@ -292,9 +300,24 @@
 /* No registry node matches the specified input data. */
 #define NFCSTATUS_NODE_NOT_FOUND                              (0x0017)
 
+#if(NFC_POWER_MANAGEMENT == TRUE)
+
+#define NFCSTATUS_SMX_SPI_STATE                               (0x00F0)
+
+/* The current module is free ; one might use it */
+#define NFCSTATUS_SMX_IDLE_STATE                              (0x00F1)
+
+/* The current module is busy with wired; one might use it */
+#define NFCSTATUS_SMX_WIRED_STATE                             (0x00F3)
+
+/* The current module is free ; one might use it */
+#define NFCSTATUS_NFCC_DWNLD_STATE                            (0x00F4)
+
+#else
 /* The current module is busy ; one might retry later */
 #define NFCSTATUS_SMX_BAD_STATE                               (0x00F0)
 
+#endif
 
 /* The Abort mechanism has failed for unexpected reason: user can try again*/
 #define NFCSTATUS_ABORT_FAILED                                (0x00F2)
diff --git a/halimpl/pn54x/common/phNfcTypes.h b/halimpl/pn54x/common/phNfcTypes.h
index 1e2fe9f..3c8883b 100644
--- a/halimpl/pn54x/common/phNfcTypes.h
+++ b/halimpl/pn54x/common/phNfcTypes.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -296,7 +296,17 @@
                                                  */
     uint8_t                        bWordCount;   /* Number of words to be read or written */
 }phNfc_sTransceiveInfo_t;
-
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+typedef enum p61_access_state{
+    P61_STATE_INVALID = 0x0000,
+    P61_STATE_IDLE = 0x0100, /* p61 is free to use */
+    P61_STATE_WIRED = 0x0200,  /* p61 is being accessed by DWP (NFCC)*/
+    P61_STATE_SPI = 0x0400, /* P61 is being accessed by SPI */
+    P61_STATE_DWNLD = 0x0800, /* NFCC fw download is in progress */
+    P61_STATE_SPI_PRIO = 0x1000, /*Start of p61 access by SPI on priority*/
+    P61_STATE_SPI_PRIO_END = 0x2000, /*End of p61 access by SPI on priority*/
+}p61_access_state_t;
+#endif
 #define UNUSED(X) (void)X;
 
 #endif /* PHNFCTYPES_H */
diff --git a/halimpl/pn54x/dnld/phDnldNfc.c b/halimpl/pn54x/dnld/phDnldNfc.c
index 512b186..13aaab5 100644
--- a/halimpl/pn54x/dnld/phDnldNfc.c
+++ b/halimpl/pn54x/dnld/phDnldNfc.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,10 +24,14 @@
 #include <phTmlNfc.h>
 #include <phNxpLog.h>
 #include <dlfcn.h>
+#include <phNxpConfig.h>
 
 static void *pFwLibHandle; /* Global firmware lib handle used in this file only */
 uint16_t wMwVer = 0; /* Middleware version no */
 uint16_t wFwVer = 0; /* Firmware version no */
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+uint8_t gRecFWDwnld; // flag  set to true to  indicate dummy FW download
+#endif
 static pphDnldNfc_DlContext_t gpphDnldContext = NULL; /* Download contex */
 static pphDnldNfc_RspCb_t      UserCb; /* Upper layer call back function */
 static void*                   UserCtxt; /* Pointer to upper layer context */
@@ -864,12 +868,28 @@
     NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
     uint8_t *pImageInfo =  NULL;
     uint16_t ImageInfoLen = 0;
+    char fwFileName[256];
+    char fwpathName[256];
+    char *pathName = NULL;
 
-    /* if memory is not allocated then allocate memory for donwload context structure */
+    /* if memory is not allocated then allocate memory for download context structure */
     phDnldNfc_SetHwDevHandle();
 
+    /*Read Firmware file name from config file*/
+    if(GetNxpStrValue(NAME_NXP_FW_NAME, fwFileName, sizeof(fwFileName)) == TRUE)
+    {
+        strcpy(fwpathName, FW_DLL_ROOT_DIR);
+        strncat(fwpathName, fwFileName, strlen(fwFileName));
+        pathName = fwpathName;
+    }
+
     /* load the library and get the image info pointer */
-    wStatus = phDnldNfc_LoadFW(FW_LIB_PATH, &pImageInfo, &ImageInfoLen);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+    if(gRecFWDwnld == TRUE)
+        wStatus = phDnldNfc_LoadRecoveryFW(pathName, &pImageInfo, &ImageInfoLen);
+    else
+#endif
+        wStatus = phDnldNfc_LoadFW(pathName, &pImageInfo, &ImageInfoLen);
 
     NXPLOG_FWDNLD_D("FW Image Length - ImageInfoLen %d",ImageInfoLen);
     NXPLOG_FWDNLD_D("FW Image Info Pointer - pImageInfo %x",(uintptr_t)pImageInfo);
@@ -939,9 +959,12 @@
 
     /* if memory is not allocated then allocate memory for donwload context structure */
     phDnldNfc_SetHwDevHandle();
-
-    wStatus = phDnldNfc_LoadFW(PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen);
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+    if(gRecFWDwnld == TRUE)
+        wStatus = phDnldNfc_LoadRecoveryFW(PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen);
+    else
+#endif
+        wStatus = phDnldNfc_LoadFW(PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen);
     if((pImageInfo == NULL) || (ImageInfoLen == 0))
     {
         NXPLOG_FWDNLD_E("Image extraction Failed - invalid imginfo or imginfolen!!");
@@ -997,8 +1020,12 @@
     phDnldNfc_SetHwDevHandle();
 
     /* load the PKU image library */
-    wStatus = phDnldNfc_LoadFW(PKU_LIB_PATH, &pImageInfo, &ImageInfoLen);
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+    if(gRecFWDwnld == TRUE)
+        wStatus = phDnldNfc_LoadRecoveryFW(PKU_LIB_PATH, &pImageInfo, &ImageInfoLen);
+    else
+#endif
+        wStatus = phDnldNfc_LoadFW(PKU_LIB_PATH, &pImageInfo, &ImageInfoLen);
     if((pImageInfo == NULL) || (ImageInfoLen == 0))
     {
         NXPLOG_FWDNLD_E("Image extraction Failed - invalid imginfo or imginfolen!!");
@@ -1132,8 +1159,80 @@
 
     return NFCSTATUS_SUCCESS;
 }
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+/*******************************************************************************
+**
+** Function         phDnldNfc_LoadRecoveryFW
+**
+** Description      Load the dummy firmware version form firmware lib for recovery
+**                  This will change the FW version of the NFCC firmware
+**                  and enable flashing of firmware of same version.
+**
+** Parameters       pathName    - Firmware image path
+**                  pImgInfo    - Firmware image handle
+**                  pImgInfoLen - Firmware image length
+**
+** Returns          NFC
+**
+*******************************************************************************/
+NFCSTATUS phDnldNfc_LoadRecoveryFW(const char* pathName, uint8_t **pImgInfo, uint16_t* pImgInfoLen)
+{
+    void* pImageInfo = NULL;
+    void* pImageInfoLen = NULL;
 
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+    /* check for path name */
+    if(pathName == NULL)
+    {
+        pathName = "/system/vendor/firmware/libpn548ad_fw.so";
+    }
+#else
+    if(pathName == NULL)
+       {
+           pathName = "/system/vendor/firmware/libpn547_fw.so";
+       }
+#endif
+    /* check if the handle is not NULL then free the library */
+    if(pFwLibHandle != NULL)
+    {
+        phDnldNfc_UnloadFW();
+        pFwLibHandle = NULL;
+    }
+    /* load the DLL file */
+    pFwLibHandle = dlopen(pathName, RTLD_LAZY);
+    NXPLOG_FWDNLD_D ("phDnldNfc_LoadRecoveryFW %s ", pathName);
 
+    /* if library load failed then handle will be NULL */
+    if(pFwLibHandle == NULL)
+    {
+        NXPLOG_FWDNLD_E("NULL handler : unable to load the library file, specify correct path");
+        return NFCSTATUS_FAILED;
+    }
+
+    dlerror();    /* Clear any existing error */
+
+    /* load the address of download image pointer and image size */
+   pImageInfo     =  (void*)dlsym(pFwLibHandle,"gphDnldNfc_DummyDlSeq");
+
+   if(dlerror()|| (NULL == pImageInfo))
+   {
+       NXPLOG_FWDNLD_E("Problem loading symbol : gphDnldNfc_DummyDlSeq");
+       return NFCSTATUS_FAILED;
+   }
+   (*pImgInfo) = (*(uint8_t**)pImageInfo);
+
+   pImageInfoLen  = (void*)dlsym(pFwLibHandle,"gphDnldNfc_DlSeqDummyFwSz");
+   if(dlerror() || (NULL == pImageInfoLen))
+   {
+       NXPLOG_FWDNLD_E("Problem loading symbol : gphDnldNfc_DlSeqDummyFwSz");
+       return NFCSTATUS_FAILED;
+   }
+
+   (*pImgInfoLen) = (uint16_t)(*((uint16_t*)pImageInfoLen));
+
+    return NFCSTATUS_SUCCESS;
+}
+#endif
 /*******************************************************************************
 **
 ** Function         phDnldNfc_UnloadFW
diff --git a/halimpl/pn54x/dnld/phDnldNfc.h b/halimpl/pn54x/dnld/phDnldNfc.h
index df95c93..10aeed1 100644
--- a/halimpl/pn54x/dnld/phDnldNfc.h
+++ b/halimpl/pn54x/dnld/phDnldNfc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -104,5 +104,8 @@
 extern NFCSTATUS phDnldNfc_LoadPKInfo(void);
 extern void phDnldNfc_CloseFwLibHandle(void);
 extern NFCSTATUS phDnldNfc_LoadFW(const char* pathName, uint8_t **pImgInfo, uint16_t* pImgInfoLen);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+extern NFCSTATUS phDnldNfc_LoadRecoveryFW(const char* pathName, uint8_t **pImgInfo, uint16_t* pImgInfoLen);
+#endif
 extern NFCSTATUS phDnldNfc_UnloadFW(void);
 #endif /* PHDNLDNFC_H */
diff --git a/halimpl/pn54x/dnld/phDnldNfc_Cmd.h b/halimpl/pn54x/dnld/phDnldNfc_Cmd.h
index 91ef3f0..b489f06 100644
--- a/halimpl/pn54x/dnld/phDnldNfc_Cmd.h
+++ b/halimpl/pn54x/dnld/phDnldNfc_Cmd.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/dnld/phDnldNfc_Internal.c b/halimpl/pn54x/dnld/phDnldNfc_Internal.c
index 628e582..3b18ad3 100644
--- a/halimpl/pn54x/dnld/phDnldNfc_Internal.c
+++ b/halimpl/pn54x/dnld/phDnldNfc_Internal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -275,6 +275,8 @@
                         (pphTmlNfc_TransactCompletionCb_t)&phDnldNfc_ProcessSeqState,
                         (void *)pDlCtxt);
 
+                    /* set read status to pDlCtxt->wCmdSendStatus to enable callback */
+                    pDlCtxt->wCmdSendStatus = wStatus;
                     break;
                 }
                 else
@@ -454,6 +456,8 @@
                         (pphTmlNfc_TransactCompletionCb_t)&phDnldNfc_ProcessRWSeqState,
                         (void *)pDlCtxt);
 
+                    /* set read status to pDlCtxt->wCmdSendStatus to enable callback */
+                    pDlCtxt->wCmdSendStatus = wStatus;
                     break;
                 }
                 else
@@ -1232,12 +1236,12 @@
             }
             else if(PH_DL_STATUS_FIRMWARE_VERSION_ERROR == (pInfo->pBuff[PHDNLDNFC_FRAMESTATUS_OFFSET]))
             {
-                NXPLOG_FWDNLD_E("Firmware Already Up To Date!!");
+                NXPLOG_FWDNLD_E("FW version Error !!!could be either due to FW major version mismatch or Firmware Already Up To Date !!");
                 (pDlContext->tRWInfo.bFirstWrReq) = FALSE;
                 /* resetting wRemBytes to 0 to avoid any further write frames send */
                 (pDlContext->tRWInfo.wRemBytes) = 0;
                 (pDlContext->tRWInfo.wOffset) = 0;
-                wStatus = NFCSTATUS_SUCCESS;
+                wStatus = NFCSTATUS_FW_VERSION_ERROR;
             }
             else if(PH_DL_STATUS_PLL_ERROR == (pInfo->pBuff[PHDNLDNFC_FRAMESTATUS_OFFSET]))
             {
diff --git a/halimpl/pn54x/dnld/phDnldNfc_Internal.h b/halimpl/pn54x/dnld/phDnldNfc_Internal.h
index c6d7834..4a3facd 100644
--- a/halimpl/pn54x/dnld/phDnldNfc_Internal.h
+++ b/halimpl/pn54x/dnld/phDnldNfc_Internal.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/dnld/phDnldNfc_Status.h b/halimpl/pn54x/dnld/phDnldNfc_Status.h
index 59747d9..035f7a9 100644
--- a/halimpl/pn54x/dnld/phDnldNfc_Status.h
+++ b/halimpl/pn54x/dnld/phDnldNfc_Status.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/dnld/phDnldNfc_Utils.c b/halimpl/pn54x/dnld/phDnldNfc_Utils.c
index d1c84ff..f264865 100644
--- a/halimpl/pn54x/dnld/phDnldNfc_Utils.c
+++ b/halimpl/pn54x/dnld/phDnldNfc_Utils.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/dnld/phDnldNfc_Utils.h b/halimpl/pn54x/dnld/phDnldNfc_Utils.h
index 4b4e2af..3c8e955 100644
--- a/halimpl/pn54x/dnld/phDnldNfc_Utils.h
+++ b/halimpl/pn54x/dnld/phDnldNfc_Utils.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c b/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c
index c8acb13..95ff877 100644
--- a/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c
+++ b/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,7 +35,9 @@
 /* External global variable to get FW version */
 extern uint16_t wFwVer;
 extern uint16_t wMwVer;
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+extern uint8_t gRecFWDwnld; // flag  set to true to  indicate dummy FW download
+#endif
 /* RF Configuration structure */
 typedef struct phLibNfc_IoctlSetRfConfig
 {
@@ -178,7 +180,19 @@
     phNxpNciHal_fw_dnld_chk_integrity,
     NULL
 };
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+/* Array of pointers to start dummy fw download seq */
+static NFCSTATUS (*phNxpNciHal_dummy_rec_dwnld_seqhandler[])(
+        void* pContext, NFCSTATUS status, void* pInfo) = {
+    phNxpNciHal_fw_dnld_normal,
+    phNxpNciHal_fw_dnld_normal,
+    phNxpNciHal_fw_dnld_get_sessn_state,
+    phNxpNciHal_fw_dnld_get_version,
+    phNxpNciHal_fw_dnld_log_read,
+    phNxpNciHal_fw_dnld_write,
+    NULL
+};
+#endif
 /* Download Recovery Sequence */
 static NFCSTATUS (*phNxpNciHal_dwnld_rec_seqhandler[])(
         void* pContext, NFCSTATUS status, void* pInfo) = {
@@ -1671,6 +1685,12 @@
         (gphNxpNciHal_fw_IoctlCtx.bDnldInitiated) = FALSE;
         /* Perform the Logging sequence */
         wStatus = phNxpNciHal_fw_seq_handler(phNxpNciHal_dwnld_log_seqhandler);
+        if(NFCSTATUS_SUCCESS != gphNxpNciHal_fw_IoctlCtx.bLastStatus)
+        {
+            /* update the previous Download Write status to upper layer and not the status of Log command */
+            wStatus = gphNxpNciHal_fw_IoctlCtx.bLastStatus;
+            NXPLOG_FWDNLD_E("phNxpNciHal_fw_dnld_complete: Last Download Write Status before Log command bLastStatus = 0x%x", gphNxpNciHal_fw_IoctlCtx.bLastStatus);
+        }
         status = phNxpNciHal_fw_dnld_complete(pContext, wStatus, &pInfo);
         if (NFCSTATUS_SUCCESS == status)
         {
@@ -1680,7 +1700,6 @@
         {
             NXPLOG_FWDNLD_E(" phNxpNciHal_fw_dnld_complete : FAILED");
         }
-
     }
     else if(TRUE == (gphNxpNciHal_fw_IoctlCtx.bDnldRecovery))
     {
@@ -1727,6 +1746,7 @@
     }
     else
     {
+        NXPLOG_FWDNLD_D("phNxpNciHal_fw_dnld_complete: Download Status = 0x%x", status);
         if(FALSE == (gphNxpNciHal_fw_IoctlCtx.bSkipSeq))
         {
             if(NFCSTATUS_SUCCESS == status)
@@ -1854,7 +1874,15 @@
     if (NFCSTATUS_SUCCESS == phDnldNfc_InitImgInfo())
     {
         NXPLOG_FWDNLD_D("phDnldNfc_InitImgInfo:SUCCESS");
-        status = phNxpNciHal_fw_seq_handler(phNxpNciHal_dwnld_seqhandler);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+        if(gRecFWDwnld == TRUE)
+        {
+            status = phNxpNciHal_fw_seq_handler(phNxpNciHal_dummy_rec_dwnld_seqhandler);
+        }else
+#endif
+        {
+            status = phNxpNciHal_fw_seq_handler(phNxpNciHal_dwnld_seqhandler);
+        }
     }
     else
     {
diff --git a/halimpl/pn54x/dnld/phNxpNciHal_Dnld.h b/halimpl/pn54x/dnld/phNxpNciHal_Dnld.h
index fb448ab..59e8ad9 100644
--- a/halimpl/pn54x/dnld/phNxpNciHal_Dnld.h
+++ b/halimpl/pn54x/dnld/phNxpNciHal_Dnld.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/hal/phNxpNciHal.c b/halimpl/pn54x/hal/phNxpNciHal.c
index aa70d79..5c5bea4 100644
--- a/halimpl/pn54x/hal/phNxpNciHal.c
+++ b/halimpl/pn54x/hal/phNxpNciHal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -54,6 +54,11 @@
 extern int send_to_upper_kovio;
 extern int kovio_detected;
 extern int disable_kovio;
+extern bool_t rf_deactive_cmd;
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+extern uint8_t gRecFWDwnld;// flag  set to true to  indicate dummy FW download
+static uint8_t gRecFwRetryCount; //variable to hold dummy FW recovery count
+#endif
 static uint8_t Rx_data[NCI_MAX_DATA_LEN];
 
 uint32_t timeoutTimerId = 0;
@@ -82,7 +87,12 @@
 static void phNxpNciHal_enable_i2c_fragmentation();
 NFCSTATUS phNxpNciHal_check_clock_config(void);
 NFCSTATUS phNxpNciHal_china_tianjin_rf_setting(void);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+static NFCSTATUS phNxpNciHalRFConfigCmdRecSequence();
+static NFCSTATUS phNxpNciHal_CheckRFCmdRespStatus();
+#endif
 int  check_config_parameter();
+static NFCSTATUS phNxpNciHal_uicc_baud_rate();
 /******************************************************************************
  * Function         phNxpNciHal_client_thread
  *
@@ -323,6 +333,12 @@
             NXPLOG_NCIHAL_D("Firmware download not allowed (NXP_FW_PROTECION_OVERRIDE not defiend)");
         }
     }
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+    else if(gRecFWDwnld == TRUE)
+    {
+        status = NFCSTATUS_SUCCESS;
+    }
+#endif
     else if (wFwVerRsp == 0)
     {
         NXPLOG_NCIHAL_E("FW Version not received by NCI command >>> Force Firmware download");
@@ -409,6 +425,8 @@
 {
     phOsalNfc_Config_t tOsalConfig;
     phTmlNfc_Config_t tTmlConfig;
+    uint8_t *nfc_dev_node = NULL;
+    const uint16_t max_len = 260; /* device node name is max of 255 bytes + 5 bytes (/dev/) */
     NFCSTATUS wConfigStatus = NFCSTATUS_SUCCESS;
     NFCSTATUS status = NFCSTATUS_SUCCESS;
     /*NCI_INIT_CMD*/
@@ -419,7 +437,7 @@
     resetNxpConfig();
 
     int init_retry_cnt=0;
-
+    int8_t ret_val = 0x00;
     /* initialize trace level */
     phNxpLog_InitializeLogLevel();
 
@@ -445,10 +463,23 @@
     nxpncihal_ctrl.p_nfc_stack_cback = p_cback;
     nxpncihal_ctrl.p_nfc_stack_data_cback = p_data_cback;
 
+    /* Read the nfc device node name */
+    nfc_dev_node = (uint8_t*) malloc(max_len*sizeof(uint8_t));
+    if(nfc_dev_node == NULL)
+    {
+        NXPLOG_NCIHAL_E("malloc of nfc_dev_node failed ");
+        goto clean_and_return;
+    }
+    else if (!GetNxpStrValue (NAME_NXP_NFC_DEV_NODE, nfc_dev_node, sizeof (nfc_dev_node)))
+    {
+        NXPLOG_NCIHAL_E("Invalid nfc device node name keeping the default device node /dev/pn544");
+        strcpy (nfc_dev_node, "/dev/pn544");
+    }
+
     /* Configure hardware link */
     nxpncihal_ctrl.gDrvCfg.nClientId = phDal4Nfc_msgget(0, 0600);
     nxpncihal_ctrl.gDrvCfg.nLinkType = ENUM_LINK_TYPE_I2C;/* For PN54X */
-    tTmlConfig.pDevName = (int8_t *) "/dev/pn54x";
+    tTmlConfig.pDevName = (uint8_t *) nfc_dev_node;
     tOsalConfig.dwCallbackThreadId
     = (uintptr_t) nxpncihal_ctrl.gDrvCfg.nClientId;
     tOsalConfig.pLogFile = NULL;
@@ -461,13 +492,23 @@
         NXPLOG_NCIHAL_E("phTmlNfc_Init Failed");
         goto clean_and_return;
     }
+    else
+    {
+        if(nfc_dev_node != NULL)
+        {
+            free(nfc_dev_node);
+            nfc_dev_node = NULL;
+        }
+    }
 
     /* Create the client thread */
     pthread_attr_t attr;
     pthread_attr_init(&attr);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-    if (pthread_create(&nxpncihal_ctrl.client_thread, &attr,
-            phNxpNciHal_client_thread, &nxpncihal_ctrl) != 0)
+    ret_val = pthread_create(&nxpncihal_ctrl.client_thread, &attr,
+            phNxpNciHal_client_thread, &nxpncihal_ctrl);
+    pthread_attr_destroy(&attr);
+    if (ret_val != 0)
     {
         NXPLOG_NCIHAL_E("pthread_create failed");
         wConfigStatus = phTmlNfc_Shutdown();
@@ -587,6 +628,11 @@
 
     clean_and_return:
     CONCURRENCY_UNLOCK();
+    if(nfc_dev_node != NULL)
+    {
+        free(nfc_dev_node);
+        nfc_dev_node = NULL;
+    }
     /* Report error status */
     (*nxpncihal_ctrl.p_nfc_stack_cback)(HAL_NFC_OPEN_CPLT_EVT,
             HAL_NFC_STATUS_FAILED);
@@ -665,11 +711,14 @@
     /* Specific logic to block RF disable when Kovio detection logic is active */
     if (p_data[0] == 0x21&&
         p_data[1] == 0x06 &&
-        p_data[2] == 0x01 &&
-        kovio_detected == TRUE)
+        p_data[2] == 0x01)
     {
-        NXPLOG_NCIHAL_D ("Kovio detection logic is active: Set Flag to disable it.");
-        disable_kovio=0x01;
+        rf_deactive_cmd = TRUE;
+        if(kovio_detected == TRUE)
+        {
+            NXPLOG_NCIHAL_D ("Kovio detection logic is active: Set Flag to disable it.");
+            disable_kovio=0x01;
+        }
     }
 
     /* Check for NXP ext before sending write */
@@ -864,7 +913,7 @@
         phNxpNciHal_print_res_status(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 == 1
-                && (nxpncihal_ctrl.p_rx_data[0x00] & 0x40) == 0x40)
+                && (nxpncihal_ctrl.p_rx_data[0x00] & 0xF0) == 0x40)
         {
             if(status == NFCSTATUS_FAILED)
             {
@@ -951,6 +1000,9 @@
      int temp_fix = 1;
 #if(NFC_NXP_CHIP_TYPE == PN548C2)
     unsigned long num = 0;
+    //initialize dummy FW recovery variables
+    gRecFwRetryCount = 0;
+    gRecFWDwnld = 0;
 #endif
     // recovery --start
     /*NCI_INIT_CMD*/
@@ -965,7 +1017,10 @@
 retry_core_init:
         config_access = FALSE;
         if(buffer != NULL)
+        {
             free(buffer);
+            buffer = NULL;
+        }
         if(retry_core_init_cnt > 3)
         {
             return NFCSTATUS_FAILED;
@@ -1147,11 +1202,27 @@
         }
 #endif
         retlen = 0;
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+        config_access = FALSE;
+#endif
         NXPLOG_NCIHAL_D ("Performing RF Settings BLK 1");
         isfound = GetNxpByteArrayValue(NAME_NXP_RF_CONF_BLK_1, (char *) buffer,
                 bufflen, &retlen);
         if (retlen > 0) {
             status = phNxpNciHal_send_ext_cmd(retlen, buffer);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                status = phNxpNciHal_CheckRFCmdRespStatus();
+                /*STATUS INVALID PARAM 0x09*/
+                if(status == 0x09)
+                {
+                    phNxpNciHalRFConfigCmdRecSequence();
+                    retry_core_init_cnt++;
+                    goto retry_core_init;
+                }
+            }else
+#endif
             if (status != NFCSTATUS_SUCCESS) {
                 NXPLOG_NCIHAL_E("RF Settings BLK 1 failed");
                 retry_core_init_cnt++;
@@ -1165,6 +1236,19 @@
                 bufflen, &retlen);
         if (retlen > 0) {
             status = phNxpNciHal_send_ext_cmd(retlen, buffer);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                status = phNxpNciHal_CheckRFCmdRespStatus();
+                /*STATUS INVALID PARAM 0x09*/
+                if(status == 0x09)
+                {
+                    phNxpNciHalRFConfigCmdRecSequence();
+                    retry_core_init_cnt++;
+                    goto retry_core_init;
+                }
+            }else
+#endif
             if (status != NFCSTATUS_SUCCESS) {
                 NXPLOG_NCIHAL_E("RF Settings BLK 2 failed");
                 retry_core_init_cnt++;
@@ -1178,6 +1262,19 @@
                 bufflen, &retlen);
         if (retlen > 0) {
             status = phNxpNciHal_send_ext_cmd(retlen, buffer);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                status = phNxpNciHal_CheckRFCmdRespStatus();
+                /*STATUS INVALID PARAM 0x09*/
+                if(status == 0x09)
+                {
+                    phNxpNciHalRFConfigCmdRecSequence();
+                    retry_core_init_cnt++;
+                    goto retry_core_init;
+                }
+            }else
+#endif
             if (status != NFCSTATUS_SUCCESS) {
                 NXPLOG_NCIHAL_E("RF Settings BLK 3 failed");
                 retry_core_init_cnt++;
@@ -1191,6 +1288,19 @@
                 bufflen, &retlen);
         if (retlen > 0) {
             status = phNxpNciHal_send_ext_cmd(retlen, buffer);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                status = phNxpNciHal_CheckRFCmdRespStatus();
+                /*STATUS INVALID PARAM 0x09*/
+                if(status == 0x09)
+                {
+                    phNxpNciHalRFConfigCmdRecSequence();
+                    retry_core_init_cnt++;
+                    goto retry_core_init;
+                }
+            }else
+#endif
             if (status != NFCSTATUS_SUCCESS) {
                 NXPLOG_NCIHAL_E("RF Settings BLK 4 failed");
                 retry_core_init_cnt++;
@@ -1204,6 +1314,19 @@
                 bufflen, &retlen);
         if (retlen > 0) {
             status = phNxpNciHal_send_ext_cmd(retlen, buffer);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                status = phNxpNciHal_CheckRFCmdRespStatus();
+                /*STATUS INVALID PARAM 0x09*/
+                if(status == 0x09)
+                {
+                    phNxpNciHalRFConfigCmdRecSequence();
+                    retry_core_init_cnt++;
+                    goto retry_core_init;
+                }
+            }else
+#endif
             if (status != NFCSTATUS_SUCCESS) {
                 NXPLOG_NCIHAL_E("RF Settings BLK 5 failed");
                 retry_core_init_cnt++;
@@ -1217,6 +1340,19 @@
                 bufflen, &retlen);
         if (retlen > 0) {
             status = phNxpNciHal_send_ext_cmd(retlen, buffer);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                status = phNxpNciHal_CheckRFCmdRespStatus();
+                /*STATUS INVALID PARAM 0x09*/
+                if(status == 0x09)
+                {
+                    phNxpNciHalRFConfigCmdRecSequence();
+                    retry_core_init_cnt++;
+                    goto retry_core_init;
+                }
+            }else
+#endif
             if (status != NFCSTATUS_SUCCESS) {
                 NXPLOG_NCIHAL_E("RF Settings BLK 6 failed");
                 retry_core_init_cnt++;
@@ -1224,7 +1360,9 @@
             }
         }
         retlen = 0;
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+        config_access = TRUE;
+#endif
         NXPLOG_NCIHAL_D ("Performing NAME_NXP_CORE_CONF_EXTN Settings");
         isfound = GetNxpByteArrayValue(NAME_NXP_CORE_CONF_EXTN,
                 (char *) buffer, bufflen, &retlen);
@@ -1253,18 +1391,36 @@
         }
 
         retlen = 0;
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+        config_access = FALSE;
+#endif
         isfound = GetNxpByteArrayValue(NAME_NXP_CORE_RF_FIELD,
                 (char *) buffer, bufflen, &retlen);
         if (retlen > 0) {
             /* NXP ACT Proprietary Ext */
             status = phNxpNciHal_send_ext_cmd(retlen, buffer);
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                status = phNxpNciHal_CheckRFCmdRespStatus();
+                /*STATUS INVALID PARAM 0x09*/
+                if(status == 0x09)
+                {
+                    phNxpNciHalRFConfigCmdRecSequence();
+                    retry_core_init_cnt++;
+                    goto retry_core_init;
+                }
+            }else
+#endif
             if (status != NFCSTATUS_SUCCESS) {
                 NXPLOG_NCIHAL_E("Setting NXP_CORE_RF_FIELD status failed");
                 retry_core_init_cnt++;
                 goto retry_core_init;
             }
         }
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+        config_access = TRUE;
+#endif
 #if(NFC_NXP_CHIP_TYPE != PN547C2)
         retlen = 0;
 
@@ -1279,9 +1435,9 @@
                     uint16_t timeout = retlen * 1000;
                     uint16_t timeoutHx = 0x0000;
 
-                    uint8_t buffer[10];
-                    snprintf ( buffer, 10, "%04x", timeout );
-                    sscanf (buffer,"%x",&timeoutHx);
+                    uint8_t tmpbuffer[10];
+                    snprintf ( tmpbuffer, 10, "%04x", timeout );
+                    sscanf (tmpbuffer,"%x",&timeoutHx);
 
                     swp_switch_timeout_cmd[7]= (timeoutHx & 0xFF);
                     swp_switch_timeout_cmd[8]=  ((timeoutHx & 0xFF00) >> 8);
@@ -1307,7 +1463,16 @@
         if (status != NFCSTATUS_SUCCESS)
         {
             NXPLOG_NCIHAL_E("phNxpNciHal_china_tianjin_rf_setting failed");
-            return NFCSTATUS_FAILED;
+            retry_core_init_cnt++;
+            goto retry_core_init;
+        }
+#endif
+#if(NFC_NXP_CHIP_TYPE == PN547C2)
+        status = phNxpNciHal_uicc_baud_rate();
+        if (status != NFCSTATUS_SUCCESS) {
+            NXPLOG_NCIHAL_E("Setting NXP_CORE_RF_FIELD status failed");
+            retry_core_init_cnt++;
+            goto retry_core_init;
         }
 #endif
     }
@@ -1471,7 +1636,6 @@
                 retry_core_init_cnt++;
                 goto retry_core_init;
             }
-
         }
         else
         {
@@ -1487,14 +1651,22 @@
             }
 
         }
+
+        if (nxpprofile_ctrl.profile_type == EMV_CO_PROFILE)
+        {
+            NXPLOG_NCIHAL_E("Current Profile : EMV_CO_PROFILE. Resetting to NFC_FORUM_PROFILE...");
+            nxpprofile_ctrl.profile_type = NFC_FORUM_PROFILE;
+        }
+
         NXPLOG_NCIHAL_E("Sending last command for Recovery ");
 
         if(p_core_init_rsp_params[35] > 0)
         {  //if length of last command is 0 then it doesn't need to send last command.
             if( !(((p_core_init_rsp_params[36] == 0x21) && (p_core_init_rsp_params[37] == 0x03))
-                && (*(p_core_init_rsp_params + 1) == 1))&&
-                    !((p_core_init_rsp_params[36] == 0x21) && (p_core_init_rsp_params[37] == 0x06)))
-                //if last command is discovery and RF staus is also discovery state, then it doesn't need to execute.
+                && (*(p_core_init_rsp_params + 1) == 1)) &&
+                    !((p_core_init_rsp_params[36] == 0x21) && (p_core_init_rsp_params[37] == 0x06) && (p_core_init_rsp_params[39] == 0x00) &&(*(p_core_init_rsp_params + 1) == 0x00)))
+                //if last command is discovery and RF status is also discovery state, then it doesn't need to execute or similarly
+                // if the last command is deactivate to idle and RF status is also idle , no need to execute the command .
             {
                 tmp_len = p_core_init_rsp_params[35];
 
@@ -1504,6 +1676,11 @@
                         nxpncihal_ctrl.p_rsp_data);
                 if (status != NFCSTATUS_SUCCESS)
                 {
+                    if(buffer)
+                    {
+                        free(buffer);
+                        buffer = NULL;
+                    }
                     /* Do not send packet to PN54X, send response directly */
                     msg.eMsgType = NCI_HAL_RX_MSG;
                     msg.pMsgData = NULL;
@@ -1533,8 +1710,13 @@
     if(buffer)
     {
         free(buffer);
+        buffer = NULL;
     }
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+    //initialize dummy FW recovery variables
+    gRecFWDwnld = 0;
+    gRecFwRetryCount = 0;
+#endif
     if(!((*p_core_init_rsp_params > 0) && (*p_core_init_rsp_params < 4)))
         phNxpNciHal_core_initialized_complete(status);
     else
@@ -1549,16 +1731,213 @@
                     nxpncihal_ctrl.rx_data_len, nxpncihal_ctrl.p_rx_data);
         }
     }
-
+/* This code is moved to JNI
 #ifdef PN547C2_CLOCK_SETTING
     if (isNxpConfigModified())
     {
         updateNxpConfigTimestamp();
     }
-#endif
+#endif*/
     return NFCSTATUS_SUCCESS;
 }
-
+#if(NFC_NXP_CHIP_TYPE == PN548C2)
+/******************************************************************************
+ * Function         phNxpNciHal_CheckRFCmdRespStatus
+ *
+ * Description      This function is called to check the resp status of
+ *                  RF update commands.
+ *
+ * Returns          NFCSTATUS_SUCCESS           if successful,
+ *                  NFCSTATUS_INVALID_PARAMETER if parameter is inavlid
+ *                  NFCSTATUS_FAILED            if failed response
+ *
+ ******************************************************************************/
+NFCSTATUS phNxpNciHal_CheckRFCmdRespStatus()
+{
+    NFCSTATUS status = NFCSTATUS_SUCCESS;
+    static uint16_t INVALID_PARAM = 0x09;
+    if(nxpncihal_ctrl.rx_data_len > 0  && nxpncihal_ctrl.p_rx_data[2] > 0)
+    {
+        if(nxpncihal_ctrl.p_rx_data[3] == 0x09)
+        {
+            status = INVALID_PARAM;
+        }
+        else if(nxpncihal_ctrl.p_rx_data[3] != NFCSTATUS_SUCCESS)
+        {
+            status = NFCSTATUS_FAILED;
+        }
+    }
+    return status;
+}
+/******************************************************************************
+ * Function         phNxpNciHalRFConfigCmdRecSequence
+ *
+ * Description      This function is called to handle dummy FW recovery sequence
+ *                  Whenever RF settings are failed to apply with invalid param
+ *                  response , recovery mechanism  includes dummy firmware download
+ *                  followed by irmware downlaod and then config settings. The dummy
+ *                  firmware changes the major number of the firmware inside NFCC.
+ *                  Then actual firmware dowenload will be successful.This can be
+ *                  retried maximum three times.
+ *
+ * Returns          Always returns NFCSTATUS_SUCCESS
+ *
+ ******************************************************************************/
+NFCSTATUS phNxpNciHalRFConfigCmdRecSequence()
+{
+    NFCSTATUS status = NFCSTATUS_SUCCESS;
+    uint16_t recFWState = 1;
+    gRecFWDwnld = TRUE;
+    gRecFwRetryCount++;
+    if(gRecFwRetryCount > 0x03)
+    {
+        NXPLOG_NCIHAL_D ("Max retry count for RF config FW recovery exceeded ");
+        gRecFWDwnld = FALSE;
+        return NFCSTATUS_FAILED;
+    }
+    do{
+        status = phTmlNfc_IoCtl(phTmlNfc_e_ResetDevice);
+        phDnldNfc_InitImgInfo();
+        if (NFCSTATUS_SUCCESS == phNxpNciHal_CheckValidFwVersion())
+        {
+            fw_download_success = 0;
+            status = phNxpNciHal_fw_download();
+            if(status == NFCSTATUS_SUCCESS)
+            {
+                fw_download_success = 1;
+                status = phTmlNfc_Read(
+                nxpncihal_ctrl.p_cmd_data,
+                NCI_MAX_DATA_LEN,(pphTmlNfc_TransactCompletionCb_t) &phNxpNciHal_read_complete,
+                NULL);
+                if (status != NFCSTATUS_PENDING)
+                {
+                    NXPLOG_NCIHAL_E("TML Read status error status = %x", status);
+                    status = phTmlNfc_Shutdown();
+                    status = NFCSTATUS_FAILED;
+                    break;
+                }
+            }
+            else
+            {
+                status = NFCSTATUS_FAILED;
+                break;
+            }
+        }
+        gRecFWDwnld = FALSE;
+    }while(recFWState--);
+    gRecFWDwnld = FALSE;
+    return status;
+}
+#endif
+#if(NFC_NXP_CHIP_TYPE == PN547C2)
+/******************************************************************************
+ * Function         phNxpNciHal_uicc_baud_rate
+ *
+ * Description      This function is used to restrict the UICC baud
+ *                  rate for type A and type B UICC.
+ *
+ * Returns          Status.
+ *
+ ******************************************************************************/
+static NFCSTATUS phNxpNciHal_uicc_baud_rate()
+{
+    uint32_t configValue = 0x00;
+    uint16_t bitRateCmdLen = 0x04; // HDR + LEN + PARAMS   2 + 1 + 1
+    uint8_t  uiccTypeAValue = 0x00; // read uicc type A value
+    uint8_t  uiccTypeBValue = 0x00; // read uicc type B value
+    uint8_t  setUiccBitRateBuf[] = {0x20, 0x02, 0x01, 0x00, 0xA0, 0x86, 0x01, 0x91, 0xA0, 0x87, 0x01, 0x91};
+    uint8_t  getUiccBitRateBuf[] = {0x20, 0x03, 0x05, 0x02, 0xA0 ,0x86 ,0xA0 , 0x87};
+    NFCSTATUS status = NFCSTATUS_SUCCESS;
+    status = phNxpNciHal_send_ext_cmd (sizeof(getUiccBitRateBuf), getUiccBitRateBuf);
+    if(status == NFCSTATUS_SUCCESS && nxpncihal_ctrl.rx_data_len >= 0x0D)
+    {
+        if(nxpncihal_ctrl.p_rx_data[0] == 0x40 && nxpncihal_ctrl.p_rx_data[1] == 0x03 &&
+                nxpncihal_ctrl.p_rx_data[2] > 0x00 && nxpncihal_ctrl.p_rx_data[3] == 0x00)
+        {
+            uiccTypeAValue = nxpncihal_ctrl.p_rx_data[8];
+            uiccTypeBValue = nxpncihal_ctrl.p_rx_data[12];
+        }
+    }
+    /* NXP Restrict Type A UICC baud rate */
+    if(GetNxpNumValue(NAME_NXP_TYPEA_UICC_BAUD_RATE, (void *)&configValue, sizeof(configValue)))
+    {
+        if(configValue == 0x00)
+        {
+            NXPLOG_NCIHAL_D("Default UICC TypeA Baud Rate supported");
+        }
+        else
+        {
+            setUiccBitRateBuf[2] += 0x04; // length byte
+            setUiccBitRateBuf[3] = 0x01;  // param byte
+            bitRateCmdLen += 0x04;
+            if(configValue == 0x01 && uiccTypeAValue != 0x91)
+            {
+                NXPLOG_NCIHAL_D("UICC TypeA Baud Rate 212kbps supported");
+                setUiccBitRateBuf[7] = 0x91; //set config value for 212
+            }
+            else if(configValue == 0x02 && uiccTypeAValue != 0xB3)
+            {
+                NXPLOG_NCIHAL_D("UICC TypeA Baud Rate 424kbps supported");
+                setUiccBitRateBuf[7] = 0xB3; //set config value for 424
+            }
+            else if(configValue == 0x03 && uiccTypeAValue != 0xF7)
+            {
+                NXPLOG_NCIHAL_D("UICC TypeA Baud Rate 848kbps supported");
+                setUiccBitRateBuf[7] = 0xF7;// set config value for 848
+            }
+            else
+            {
+                setUiccBitRateBuf[3] = 0x00;
+                setUiccBitRateBuf[2] -= 0x04;
+                bitRateCmdLen -= 0x04;
+            }
+        }
+    }
+    configValue = 0;
+    /* NXP Restrict Type B UICC baud rate*/
+    if(GetNxpNumValue(NAME_NXP_TYPEB_UICC_BAUD_RATE, (void *)&configValue, sizeof(configValue)))
+    {
+        if(configValue == 0x00)
+        {
+            NXPLOG_NCIHAL_D("Default UICC TypeB Baud Rate supported");
+        }
+        else
+        {
+            setUiccBitRateBuf[2] += 0x04;
+            setUiccBitRateBuf[3] += 0x01;
+            setUiccBitRateBuf[bitRateCmdLen++] = 0xA0;
+            setUiccBitRateBuf[bitRateCmdLen++] = 0x87;
+            setUiccBitRateBuf[bitRateCmdLen++] = 0x01;
+            if(configValue == 0x01 && uiccTypeBValue != 0x91)
+            {
+                NXPLOG_NCIHAL_D("UICC TypeB Baud Rate 212kbps supported");
+                setUiccBitRateBuf[bitRateCmdLen++] = 0x91; //set config value for 212
+            }
+            else if(configValue == 0x02 && uiccTypeBValue != 0xB3)
+            {
+                NXPLOG_NCIHAL_D("UICC TypeB Baud Rate 424kbps supported");
+                setUiccBitRateBuf[bitRateCmdLen++] = 0xB3;//set config value for 424
+            }
+            else if(configValue == 0x03 && uiccTypeBValue != 0xF7)
+            {
+                NXPLOG_NCIHAL_D("UICC TypeB Baud Rate 848kbps supported");
+                setUiccBitRateBuf[bitRateCmdLen++] = 0xF7;//set config value for 848
+            }
+            else
+            {
+                setUiccBitRateBuf[2] -= 0x04;
+                setUiccBitRateBuf[3] -= 0x01;
+                bitRateCmdLen -= 0x04;
+            }
+        }
+    }
+    if(bitRateCmdLen > 0x04)
+    {
+        status = phNxpNciHal_send_ext_cmd (bitRateCmdLen, setUiccBitRateBuf);
+    }
+    return status;
+}
+#endif
 /******************************************************************************
  * Function         phNxpNciHal_core_initialized_complete
  *
@@ -1876,6 +2255,50 @@
     return;
 }
 
+
+/******************************************************************************
+ * Function         phNxpNciHal_ioctl
+ *
+ * Description      This function is called by jni when wired mode is
+ *                  performed.First Pn54x driver will give the access
+ *                  permission whether wired mode is allowed or not
+ *                  arg (0):
+ * Returns          return 0 on success and -1 on fail, On success
+ *                  update the acutual state of operation in arg pointer
+ *
+ ******************************************************************************/
+int phNxpNciHal_ioctl(long arg, void *p_data)
+{
+    NXPLOG_NCIHAL_D("%s : enter - arg = %ld", __FUNCTION__, arg);
+
+    int ret = -1;
+    NFCSTATUS status = NFCSTATUS_FAILED;
+#if(NFC_POWER_MANAGEMENT == TRUE)
+    switch(arg)
+    {
+    case 0:
+        status = phTmlNfc_IoCtl(phTmlNfc_e_SetP61IdleMode);
+        break;
+    case 1:
+        status = phTmlNfc_IoCtl(phTmlNfc_e_SetP61WiredMode);
+        break;
+    case 2:
+        status = phTmlNfc_IoCtl(phTmlNfc_e_GetP61PwrMode);
+        break;
+    default:
+        NXPLOG_NCIHAL_E("%s : Wrong arg = %ld", __FUNCTION__, arg);
+        break;
+    }
+#endif
+    if(NFCSTATUS_FAILED != status)
+    {
+        *(uint16_t*)p_data = (uint16_t)status;
+        ret = 0;
+    }
+    NXPLOG_NCIHAL_D("%s : exit - ret = %d", __FUNCTION__, ret);
+    return ret;
+}
+
 /******************************************************************************
  * Function         phNxpNciHal_set_clock
  *
diff --git a/halimpl/pn54x/hal/phNxpNciHal.h b/halimpl/pn54x/hal/phNxpNciHal.h
index fa7b637..0ded653 100644
--- a/halimpl/pn54x/hal/phNxpNciHal.h
+++ b/halimpl/pn54x/hal/phNxpNciHal.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/hal/phNxpNciHal_Kovio.c b/halimpl/pn54x/hal/phNxpNciHal_Kovio.c
index 3489b8f..99ca605 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_Kovio.c
+++ b/halimpl/pn54x/hal/phNxpNciHal_Kovio.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
 int kovio_detected = 0x00;
 int send_to_upper_kovio = 0x01;
 int disable_kovio=0x00;
+bool_t rf_deactive_cmd = FALSE;
 static uint8_t rf_deactivate_cmd[]   = { 0x21, 0x06, 0x01, 0x03 }; /* discovery */
 static uint8_t rf_deactivated_ntf[]  = { 0x61, 0x06, 0x02, 0x03, 0x01 };
 static uint8_t reset_ntf[] = {0x60, 0x00, 0x06, 0xA0, 0x00, 0xC7, 0xD4, 0x00, 0x00};
@@ -121,7 +122,7 @@
             //Send the Core Reset NTF to upper layer, which will trigger the recovery.
             nxpncihal_ctrl.rx_data_len = sizeof(reset_ntf);
             memcpy(nxpncihal_ctrl.p_rx_data, reset_ntf, sizeof(reset_ntf));
-            (*nxpncihal_ctrl.p_nfc_stack_data_cback)(nxpncihal_ctrl.rx_data_len, nxpncihal_ctrl.p_rx_data);
+            //(*nxpncihal_ctrl.p_nfc_stack_data_cback)(nxpncihal_ctrl.rx_data_len, nxpncihal_ctrl.p_rx_data);
         }
     }
 
@@ -179,8 +180,18 @@
             {
                 send_to_upper_kovio = 0;
             }
-            NXPLOG_NCIHAL_D("Send RF deactivate command to NFCC");
-            status = phNxpNciHal_rf_deactivate();
+
+            if(!rf_deactive_cmd)
+            {
+                NXPLOG_NCIHAL_D("Send RF deactivate command to NFCC");
+                status = phNxpNciHal_rf_deactivate();
+            }
+            else
+            {
+                NXPLOG_NCIHAL_D("RF deactivate command is already sent to NFCC");
+                disable_kovio = TRUE;
+                send_to_upper_kovio = 0;
+            }
             status = phOsalNfc_Timer_Start(kovio_timer,
                     KOVIO_TIMEOUT,
                     &kovio_timer_handler,
@@ -206,6 +217,7 @@
     }
     else if((p_ntf[0]==0x41)&&(p_ntf[1]==0x06)&&(p_ntf[2]==0x01)&&(p_ntf[3]==0x00))
     {
+        rf_deactive_cmd = FALSE;
         if(kovio_detected == 1)
             send_to_upper_kovio = 0;
         if((kovio_detected == 1)&&(disable_kovio==0x01))
diff --git a/halimpl/pn54x/hal/phNxpNciHal_Kovio.h b/halimpl/pn54x/hal/phNxpNciHal_Kovio.h
index d630e37..5262d86 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_Kovio.h
+++ b/halimpl/pn54x/hal/phNxpNciHal_Kovio.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.c b/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.c
index a2f51be..b1fcdc1 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.c
+++ b/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -135,6 +135,7 @@
     {
         NXPLOG_NCIHAL_E("phNxpNciHal_resume_polling_loop");
     }
+    pthread_attr_destroy(&attr);
     return status;
 }
 
@@ -161,6 +162,7 @@
     {
         NXPLOG_NCIHAL_E("phNxpNciHal_resume_polling_loop");
     }
+    pthread_attr_destroy(&attr);
     return status;
 }
 
@@ -187,6 +189,7 @@
     {
         NXPLOG_NCIHAL_E("phNxpNciHal_resume_polling_loop");
     }
+    pthread_attr_destroy(&attr);
     return status;
 }
 
@@ -584,7 +587,7 @@
     {
         NXPLOG_NCIHAL_E("phNxpNciHal_resume_polling_loop");
     }
-
+    pthread_attr_destroy(&attr);
     return status;
 }
 /*******************************************************************************
diff --git a/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.h b/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.h
index 4e56084..15c72a3 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.h
+++ b/halimpl/pn54x/hal/phNxpNciHal_NfcDepSWPrio.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/hal/phNxpNciHal_dta.c b/halimpl/pn54x/hal/phNxpNciHal_dta.c
index 46b7604..0155c09 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_dta.c
+++ b/halimpl/pn54x/hal/phNxpNciHal_dta.c
@@ -1,5 +1,5 @@
- /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+/*
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@
 
     if (nxpdta_ctrl.dta_ctrl_flag == TRUE)
     {
-        // Workaround for DTA, block the set config command with general bytes */
+        // DTA: Block the set config command with general bytes */
         if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 &&
              p_cmd_data[2] == 0x17 && p_cmd_data[3] == 0x01 &&
              p_cmd_data[4] == 0x29 && p_cmd_data[5] == 0x14 )
@@ -112,7 +112,7 @@
             phNxpNciHal_print_packet("DTARECV", p_rsp_data, 5);
 
             status = NFCSTATUS_FAILED;
-            NXPLOG_NCIHAL_D("Going through DTA workaround - Block set config command END");
+            NXPLOG_NCIHAL_D("DTA - Block set config command END");
 
         }
         else if (p_cmd_data[0] == 0x21 && p_cmd_data[1] == 0x08 && p_cmd_data[2] == 0x04
diff --git a/halimpl/pn54x/hal/phNxpNciHal_dta.h b/halimpl/pn54x/hal/phNxpNciHal_dta.h
index 7a649a1..a8efd2d 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_dta.h
+++ b/halimpl/pn54x/hal/phNxpNciHal_dta.h
@@ -1,5 +1,5 @@
- /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+/*
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/hal/phNxpNciHal_ext.c b/halimpl/pn54x/hal/phNxpNciHal_ext.c
index d8f5bf6..ce360c5 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_ext.c
+++ b/halimpl/pn54x/hal/phNxpNciHal_ext.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -52,7 +52,6 @@
 /* local buffer to store CORE_INIT response */
 static uint32_t bCoreInitRsp[40];
 static uint32_t iCoreInitRspLen;
-
 extern uint32_t timeoutTimerId;
 
 extern NFCSTATUS read_retry();
@@ -128,6 +127,7 @@
         NXPLOG_NCIHAL_D("FelicaReaderMode:Activity 1.1");
     }
 
+
 #ifdef P2P_PRIO_LOGIC_HAL_IMP
     if(p_ntf[0] == 0x61 &&
        p_ntf[1] == 0x05 &&
@@ -277,7 +277,7 @@
             p_ntf[5] == 0x06 &&
             p_ntf[6] == 0x06)
     {
-        NXPLOG_NCIHAL_D ("> Going through workaround - notification of ISO 15693");
+        NXPLOG_NCIHAL_D ("> Notification for ISO-15693");
         icode_detected = 0x01;
         p_ntf[21] = 0x01;
         p_ntf[22] = 0x01;
@@ -299,7 +299,7 @@
         }
         if (p_ntf[p_ntf[2]+ 2] == 0x00)
         {
-            NXPLOG_NCIHAL_D ("> Going through workaround - data of ISO 15693");
+            NXPLOG_NCIHAL_D ("> Data of ISO-15693");
             p_ntf[2]--;
             (*p_len)--;
         }
@@ -322,7 +322,7 @@
                 p_ntf[2] == 0x01 &&
                 p_ntf[3] == 0x06 )
     {
-        NXPLOG_NCIHAL_D ("> Deinit workaround for LLCP set_config 0x%x 0x%x 0x%x", p_ntf[21], p_ntf[22], p_ntf[23]);
+        NXPLOG_NCIHAL_D ("> Deinit for LLCP set_config 0x%x 0x%x 0x%x", p_ntf[21], p_ntf[22], p_ntf[23]);
         p_ntf[0] = 0x40;
         p_ntf[1] = 0x02;
         p_ntf[2] = 0x02;
@@ -339,19 +339,76 @@
         iCoreInitRspLen = *p_len;
         memcpy(bCoreInitRsp, p_ntf, *p_len);
         NXPLOG_NCIHAL_D ("NxpNci> FW Version: %x.%x.%x", p_ntf[len-2], p_ntf[len-1], p_ntf[len]);
+        NXPLOG_NCIHAL_D ("NxpNci> Model id: %x", p_ntf[len-3]>>4);
+        /* Before FW version: 10.01.12, products are PN548c2(for model id = 0) and PN66T(for model id = 1)*/
+        if(p_ntf[len-2] == 0x10 )
+        {
+            if((p_ntf[len-1] < 0x01) |
+                (( p_ntf[len-1] == 0x01) && (p_ntf[len] <= 0x11)))
+            {
+                if(0x01 == (p_ntf[len-3]>>4))
+                {
+                    NXPLOG_NCIHAL_D ("NxpNci> Product: PN66T");
+                }
+                else
+                {
+                    NXPLOG_NCIHAL_D ("NxpNci> Product: PN548c2");
+                }
+            }
+            else
+            {   /* From FW version: 10.01.12, product names based on Hardware Version number */
+                switch(p_ntf[len-3])
+                {
+                    case 0x08:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: PN546");
+                        break;
+                    case 0x18:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: PN66T");
+                        break;
+                    case 0x28:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: PN548C2");
+                        break;
+                    case 0x38:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: PN66U");
+                        break;
+                    case 0x48:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: NQ210");
+                        break;
+                    case 0x58:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: NQ220");
+                        break;
+                    case 0x68:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: NPC300");
+                        break;
+                    case 0x78:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: NPC320");
+                        break;
+                    case 0x88:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: PN7150");
+                        break;
+                    case 0x98:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: PN548C3");
+                        break;
+                    default:
+                        NXPLOG_NCIHAL_D ("NxpNci> Product: Invalid");
+                }
+            }
+        }
+        else
+        {
+            /* Do Nothing */
+        }
     }
     //4200 02 00 01
     else if(p_ntf[0] == 0x42 && p_ntf[1] == 0x00 && ee_disc_done == 0x01)
     {
-        NXPLOG_NCIHAL_D("Going through workaround - NFCEE_DISCOVER_RSP");
+        NXPLOG_NCIHAL_D("As done with the NFCEE discovery so setting it to zero  - NFCEE_DISCOVER_RSP");
         if(p_ntf[4] == 0x01)
         {
             p_ntf[4] = 0x00;
 
             ee_disc_done = 0x00;
         }
-        NXPLOG_NCIHAL_D("Going through workaround - NFCEE_DISCOVER_RSP - END");
-
     }
     else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x03 /*&& cleanup_timer!=0*/)
     {
@@ -390,7 +447,7 @@
             && p_ntf[4] == 0x02 && p_ntf[5] == 0x80
             && p_ntf[6] == 0x00 )
     {
-        NXPLOG_NCIHAL_D("Going through workaround - iso-dep  interface  mifare protocol with sak value not equal to 0x20");
+        NXPLOG_NCIHAL_D("Going through the iso-dep interface mifare protocol with sak value not equal to 0x20");
         rf_technology_length_param = p_ntf[9];
         if((p_ntf[ 9 + rf_technology_length_param] & 0x20) != 0x20)
         {
@@ -619,8 +676,7 @@
             p_cmd_data[4] == 0x01 &&
             p_cmd_data[5] == 0x03)
     {
-        NXPLOG_NCIHAL_D("> Going through workaround - set host list");
-
+        NXPLOG_NCIHAL_D("> Going through the set host list");
 #if(NFC_NXP_CHIP_TYPE != PN547C2)
         *cmd_len = 8;
 
@@ -633,8 +689,6 @@
         p_cmd_data[2] = 0x04;
         p_cmd_data[6] = 0xC0;
 #endif
-
-        NXPLOG_NCIHAL_D("> Going through workaround - set host list - END");
         status = NFCSTATUS_SUCCESS;
     }
     else if(icode_detected)
@@ -697,9 +751,8 @@
         p_cmd_data[11] = 0x50;
         p_cmd_data[12] = 0x00;
 
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
+        NXPLOG_NCIHAL_D ("> Dirty Set Config ");
 //        phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
     }
 //    20020703300031003200
 //    2002 0301 3200
@@ -710,7 +763,7 @@
             )
     )
     {
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
+        NXPLOG_NCIHAL_D ("> Dirty Set Config ");
         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
         *rsp_len = 5;
         p_rsp_data[0] = 0x40;
@@ -721,7 +774,6 @@
 
         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
         status = NFCSTATUS_FAILED;
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
     }
 
     //2002 0D04 300104 310100 320100 500100
@@ -735,13 +787,12 @@
     {
 //        p_cmd_data[12] = 0x40;
 
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
+        NXPLOG_NCIHAL_D ("> Dirty Set Config ");
         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
         p_cmd_data[6] = 0x60;
 
         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
 //        status = NFCSTATUS_FAILED;
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
     }
 
 #if 0
@@ -754,7 +805,7 @@
                      (p_cmd_data[2] == 0x05 && p_cmd_data[3] == 0x02))
              )
     {
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
+        NXPLOG_NCIHAL_D ("> Dirty Set Config ");
         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
         *rsp_len = 5;
         p_rsp_data[0] = 0x40;
@@ -765,14 +816,13 @@
 
         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
         status = NFCSTATUS_FAILED;
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
     }
 
     else if((p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) &&
            ((p_cmd_data[3] == 0x00) ||
            ((*cmd_len >= 0x06) && (p_cmd_data[5] == 0x00)))) /*If the length of the first param id is zero don't allow*/
     {
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
+        NXPLOG_NCIHAL_D ("> Dirty Set Config ");
         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
         *rsp_len = 5;
         p_rsp_data[0] = 0x40;
@@ -783,7 +833,6 @@
 
         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
         status = NFCSTATUS_FAILED;
-        NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
     }
 #endif
     else if ((wFwVerRsp & 0x0000FFFF) == wFwVer)
diff --git a/halimpl/pn54x/hal/phNxpNciHal_ext.h b/halimpl/pn54x/hal/phNxpNciHal_ext.h
index b2d7a17..9f8ec5e 100644
--- a/halimpl/pn54x/hal/phNxpNciHal_ext.h
+++ b/halimpl/pn54x/hal/phNxpNciHal_ext.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/inc/phNxpNciHal_Adaptation.h b/halimpl/pn54x/inc/phNxpNciHal_Adaptation.h
index ba5f8f5..a8dfc61 100644
--- a/halimpl/pn54x/inc/phNxpNciHal_Adaptation.h
+++ b/halimpl/pn54x/inc/phNxpNciHal_Adaptation.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
 int phNxpNciHal_open(nfc_stack_callback_t *p_cback,
         nfc_stack_data_callback_t *p_data_cback);
 int phNxpNciHal_write(uint16_t data_len, const uint8_t *p_data);
+int phNxpNciHal_ioctl(long arg, void *p_data);
 int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params);
 int phNxpNciHal_pre_discover(void);
 int phNxpNciHal_close(void);
diff --git a/halimpl/pn54x/inc/phNxpNciHal_Api.h b/halimpl/pn54x/inc/phNxpNciHal_Api.h
index 8497e05..d8d48de 100644
--- a/halimpl/pn54x/inc/phNxpNciHal_Api.h
+++ b/halimpl/pn54x/inc/phNxpNciHal_Api.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/inc/phNxpNciHal_SelfTest.h b/halimpl/pn54x/inc/phNxpNciHal_SelfTest.h
index 711e505..88f9cda 100644
--- a/halimpl/pn54x/inc/phNxpNciHal_SelfTest.h
+++ b/halimpl/pn54x/inc/phNxpNciHal_SelfTest.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/libnfc-brcm.conf b/halimpl/pn54x/libnfc-brcm.conf
index 22dffb5..c98668a 100644
--- a/halimpl/pn54x/libnfc-brcm.conf
+++ b/halimpl/pn54x/libnfc-brcm.conf
@@ -1,4 +1,4 @@
-###################### Start of libnfc-brcm.conf #######################
+###################### Start of libnfc-common.conf #######################
 
 ###############################################################################
 # Application options
@@ -363,7 +363,7 @@
 
 ###############################################################################
 # NCI Hal Module name
-NCI_HAL_MODULE="nfc_nci"
+NCI_HAL_MODULE="nfc_nci.pn54x"
 
 ##############################################################################
 # Deactivate notification wait time out in seconds used in ETSI Reader mode
diff --git a/halimpl/pn54x/libnfc-nxp-PN547C2_example.conf b/halimpl/pn54x/libnfc-nxp-PN547C2_example.conf
index b160b11..1333636 100644
--- a/halimpl/pn54x/libnfc-nxp-PN547C2_example.conf
+++ b/halimpl/pn54x/libnfc-nxp-PN547C2_example.conf
@@ -1,13 +1,13 @@
-## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn54x)
-## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn54x)
+## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547)
+## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547)
 
 ###############################################################################
-# Application options
+# Application options 
 # Logging Levels
-# NXPLOG_DEFAULT_LOGLEVEL    0x01
-# ANDROID_LOG_DEBUG          0x03
-# ANDROID_LOG_WARN           0x02
-# ANDROID_LOG_ERROR          0x01
+# NXPLOG_DEFAULT_LOGLEVEL    0x01  
+# ANDROID_LOG_DEBUG          0x03 
+# ANDROID_LOG_WARN           0x02 
+# ANDROID_LOG_ERROR          0x01 
 # ANDROID_LOG_SILENT         0x00
 #
 NXPLOG_EXTNS_LOGLEVEL=0x03
@@ -18,6 +18,10 @@
 NXPLOG_TML_LOGLEVEL=0x03
 
 ###############################################################################
+# Nfc Device Node name
+NXP_NFC_DEV_NODE="/dev/pn544"
+
+###############################################################################
 # Extension for Mifare reader enable
 MIFARE_READER_ENABLE=0x01
 
@@ -25,9 +29,8 @@
 # Vzw Feature enable
 VZW_FEATURE_ENABLE=0x01
 ###############################################################################
-
-# File location for Firmware
-#FW_STORAGE="/vendor/firmware/libpn547_fw.so"
+# File name for Firmware
+NXP_FW_NAME="libpn547_fw.so"
 
 ###############################################################################
 # System clock source selection configuration
@@ -48,7 +51,7 @@
 NXP_SYS_CLK_FREQ_SEL=0x00
 
 ###############################################################################
-# The timeout value to be used for clock request acknowledgment
+# The timeout value to be used for clock request acknowledgment 
 # min value = 0x01 to max = 0x19
 
 NXP_SYS_CLOCK_TO_CFG=0x01
@@ -63,7 +66,7 @@
 
 ###############################################################################
 # Standby enable settings
-#NXP_CORE_STANDBY={2F, 00, 01, 01}
+NXP_CORE_STANDBY={2F, 00, 01, 01}
 
 ###############################################################################
 #Atonomous Mode
@@ -116,23 +119,29 @@
 # Clock settings A002, A003
 # PbF settings A008
 NXP_CORE_CONF_EXTN={20, 02, 16, 04,
-    A0, EC, 01, 01,
+    A0, EC, 01, 01,  
     A0, ED, 01, 01,
     A0, 5E, 01, 01,
     A0, 0D, 06, 3E, 2D, 15, 88, 15, 00
     }
+#       A0, 40, 01, 01, 
+#       A0, 41, 01, 02, 
+#       A0, 43, 01, 04,
+#       A0, 02, 01, 01, 
+#       A0, 03, 01, 11,
+#       A0, 07, 01, 03,
+#       A0, 08, 01, 01
+#       }
 
 ###############################################################################
-# Core configuration rf field filter settings to enable set 01 ,to disable set to 00 last bit
+# Core configuration rf field filter settings to enable set to 01 to disable set to 00 last bit
 NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01
         }
-
 ###############################################################################
 # To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00
 NXP_I2C_FRAGMENTATION_ENABLED=0x00
-
 ###############################################################################
-# Core configuration settings
+# Core configuration settings 
 NXP_CORE_CONF={ 20, 02, 2B, 0D,
         28, 01, 00,
         21, 01, 00,
@@ -146,12 +155,12 @@
         80, 01, 01,
         81, 01, 01,
         82, 01, 0E,
-        18, 01, 01
+        18, 01, 01 
         }
-
+ 
 ###############################################################################
-# Mifare Classic Key settings
-#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5,
+# Mifare Classic Key settings 
+#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5, 
 #                                     A0, 52, 06, D3, F7, D3, F7, D3, F7,
 #                                     A0, 53, 06, FF, FF, FF, FF, FF, FF,
 #                                     A0, 54, 06, 00, 00, 00, 00, 00, 00}
@@ -161,11 +170,10 @@
 # No secure element 0x00
 # eSE               0x01
 # UICC              0x02
-
+ 
 NXP_DEFAULT_SE=0x02
 
 NXP_DEFAULT_NFCEE_TIMEOUT=0x06
-
 ###############################################################################
 #Enable SWP full power mode when phone is power off
 NXP_SWP_FULL_PWR_ON=0x01
@@ -194,10 +202,12 @@
 # UICC 0x02
 DEFAULT_MIFARE_CLT_ROUTE=0x02
 
-###############################################################################
-#Chip type
+##############################################################################
+#### Select the CHIP ####
 #PN547C2            0x01
 #PN65T              0x02
+#PN548AD            0x03
+#PN66T              0x04
 
 NXP_NFC_CHIP=0x01
 
@@ -205,15 +215,41 @@
 NXP_SWP_RD_START_TIMEOUT=0x0A
 #Timeout in secs
 NXP_SWP_RD_TAG_OP_TIMEOUT=0x01
-
 ###############################################################################
 # CE when Screen state is locked
 # Disable           0x00
 # Enable            0x01
 NXP_CE_ROUTE_STRICT_DISABLE=0x01
 
+
 ###############################################################################
+
 # AID Matching platform options
 # AID_MATCHING_L 0x01
 # AID_MATCHING_K 0x02
 AID_MATCHING_PLATFORM=0x01
+################################################################################
+#Used to Restrict Type A UICC baud rate
+#0 = default supported
+#1 = 212 maximum supported
+#2 = 424 maximum supported
+#3 = 848 maximum supported
+
+NXP_TYPEA_UICC_BAUD_RATE=0x00
+
+################################################################################
+#Used to Restrict Type B UICC baud rate
+#0 = default supported
+#1 = 212 maximum supported
+#2 = 424 maximum supported
+#3 = 848 maximum supported
+
+NXP_TYPEB_UICC_BAUD_RATE=0x00
+################################################################################
+
+#Config to allow adding aids
+#NFC on/off is required after this config
+#1 = enabling adding aid  to NFCC routing table.
+#0 = disabling adding aid to NFCC routing table.
+NXP_ENABLE_ADD_AID=0x01
+##################################################################################
diff --git a/halimpl/pn54x/libnfc-nxp-PN548C2_example.conf b/halimpl/pn54x/libnfc-nxp-PN548C2_example.conf
new file mode 100644
index 0000000..ea3231e
--- /dev/null
+++ b/halimpl/pn54x/libnfc-nxp-PN548C2_example.conf
@@ -0,0 +1,281 @@
+## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547)
+## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547)
+
+###############################################################################
+# Application options
+# Logging Levels
+# NXPLOG_DEFAULT_LOGLEVEL    0x01
+# ANDROID_LOG_DEBUG          0x03
+# ANDROID_LOG_WARN           0x02
+# ANDROID_LOG_ERROR          0x01
+# ANDROID_LOG_SILENT         0x00
+#
+NXPLOG_EXTNS_LOGLEVEL=0x03
+NXPLOG_NCIHAL_LOGLEVEL=0x03
+NXPLOG_NCIX_LOGLEVEL=0x03
+NXPLOG_NCIR_LOGLEVEL=0x03
+NXPLOG_FWDNLD_LOGLEVEL=0x03
+NXPLOG_TML_LOGLEVEL=0x03
+
+###############################################################################
+# Nfc Device Node name
+NXP_NFC_DEV_NODE="/dev/pn544"
+
+###############################################################################
+# Extension for Mifare reader enable
+MIFARE_READER_ENABLE=0x01
+
+###############################################################################
+# Vzw Feature enable
+VZW_FEATURE_ENABLE=0x01
+
+###############################################################################
+# File name for Firmware
+NXP_FW_NAME="libpn548ad_fw.so"
+
+###############################################################################
+# System clock source selection configuration
+#define CLK_SRC_XTAL       1
+#define CLK_SRC_PLL        2
+
+NXP_SYS_CLK_SRC_SEL=0x02
+
+###############################################################################
+# System clock frequency selection configuration
+#define CLK_FREQ_13MHZ         1
+#define CLK_FREQ_19_2MHZ       2
+#define CLK_FREQ_24MHZ         3
+#define CLK_FREQ_26MHZ         4
+#define CLK_FREQ_38_4MHZ       5
+#define CLK_FREQ_52MHZ         6
+
+NXP_SYS_CLK_FREQ_SEL=0x02
+
+###############################################################################
+# The timeout value to be used for clock request acknowledgment
+# min value = 0x01 to max = 0x1A
+
+NXP_SYS_CLOCK_TO_CFG=0x1A
+
+###############################################################################
+# NXP proprietary settings
+NXP_ACT_PROP_EXTN={2F, 02, 00}
+
+###############################################################################
+# NFC forum profile settings
+NXP_NFC_PROFILE_EXTN={20, 02, 05, 01, A0, 44, 01, 00}
+
+###############################################################################
+# NFCC Configuration Control
+# Allow NFCC to manage RF Config       0x01
+# Don't allow NFCC to manage RF Config 0x00
+NXP_NFC_MERGE_RF_PARAMS={20, 02, 04, 01, 85, 01, 01}
+
+###############################################################################
+# Standby enable settings
+NXP_CORE_STANDBY={2F, 00, 01, 01}
+
+###############################################################################
+# NXP TVDD configurations settings
+# Allow NFCC to configure External TVDD, There are currently three
+#configurations (1, 2 and 3) are supported, out of them only one can be
+#supported.
+
+NXP_EXT_TVDD_CFG=0x01
+
+#config1:SLALM, 3.3V for both RM and CM
+NXP_EXT_TVDD_CFG_1={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 02, 09, 00}
+
+#config2: use DCDC in CE, use Tx_Pwr_Req, set CFG2 mode, SLALM,
+#monitoring 5V from DCDC, 4.7V for both RM and CM, DCDCWaitTime=4.2ms
+NXP_EXT_TVDD_CFG_2={20, 02, 0B, 02, A0, 66, 01, 00, A0, 0E, 03, 56, 64, 0A}
+
+#config3: use DCDC in CE, use Tx_Pwr_Req, SLALM, monitoring 5V from DCDC,
+#DCDCWaitTime=4.2ms
+NXP_EXT_TVDD_CFG_3={20, 02, 0B, 02, A0, 66, 01, 01, A0, 0E, 03, 52, 64, 0A}
+
+###############################################################################
+# NXP RF configuration ALM/PLM settings
+# This section needs to be updated with the correct values based on the platform
+#NXP_RF_CONF_BLK_1={
+#}
+
+###############################################################################
+# NXP RF configuration ALM/PLM settings
+# This section needs to be updated with the correct values based on the platform
+#NXP_RF_CONF_BLK_2={
+#}
+
+###############################################################################
+# NXP RF configuration ALM/PLM settings
+# This section needs to be updated with the correct values based on the platform
+#NXP_RF_CONF_BLK_3={
+#}
+
+###############################################################################
+# NXP RF configuration ALM/PLM settings
+# This section needs to be updated with the correct values based on the platform
+#NXP_RF_CONF_BLK_4={
+#}
+
+###############################################################################
+# NXP RF configuration ALM/PLM settings
+# This section needs to be updated with the correct values based on the platform
+#NXP_RF_CONF_BLK_5={
+#}
+
+###############################################################################
+# NXP RF configuration ALM/PLM settings
+# This section needs to be updated with the correct values based on the platform
+#NXP_RF_CONF_BLK_6={
+#}
+
+
+###############################################################################
+# Core configuration extensions
+# It includes
+# Wired mode settings A0ED, A0EE
+# Tag Detector A040, A041, A043
+# Low Power mode A007
+# Clock settings A002, A003
+# PbF settings A008
+NXP_CORE_CONF_EXTN={20, 02, 19, 06,
+    A0, EC, 01, 01,
+    A0, ED, 01, 00,
+    A0, 5E, 01, 01,
+    A0, 40, 01, 01,
+    A0, DD, 01, 2D,
+    A0, 96, 01, 01
+    }
+#       A0, 41, 01, 02,
+#       A0, 43, 01, 04,
+#       A0, 02, 01, 01,
+#       A0, 03, 01, 11,
+#       A0, 07, 01, 03,
+#       A0, 08, 01, 01
+#       }
+
+###############################################################################
+# Core configuration rf field filter settings to enable set to 01 to disable set to 00 last bit
+NXP_CORE_RF_FIELD={ 20, 02, 05, 01, A0, 62, 01, 01
+        }
+###############################################################################
+# To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00
+NXP_I2C_FRAGMENTATION_ENABLED=0x00
+
+###############################################################################
+# Core configuration settings
+NXP_CORE_CONF={ 20, 02, 2B, 0D,
+        28, 01, 00,
+        21, 01, 00,
+        30, 01, 08,
+        31, 01, 03,
+        33, 04, 01, 02, 03, 04,
+        54, 01, 06,
+        50, 01, 02,
+        5B, 01, 00,
+        60, 01, 0E,
+        80, 01, 01,
+        81, 01, 01,
+        82, 01, 0E,
+        18, 01, 01
+        }
+
+###############################################################################
+# Mifare Classic Key settings
+#NXP_CORE_MFCKEY_SETTING={20, 02, 25,04, A0, 51, 06, A0, A1, A2, A3, A4, A5,
+#                                     A0, 52, 06, D3, F7, D3, F7, D3, F7,
+#                                     A0, 53, 06, FF, FF, FF, FF, FF, FF,
+#                                     A0, 54, 06, 00, 00, 00, 00, 00, 00}
+
+###############################################################################
+# Default SE Options
+# No secure element 0x00
+# eSE               0x01
+# UICC              0x02
+
+NXP_DEFAULT_SE=0x03
+
+###############################################################################
+#Enable SWP full power mode when phone is power off
+NXP_SWP_FULL_PWR_ON=0x00
+
+###############################################################################
+#### Select the CHIP ####
+#PN547C2            0x01
+#PN65T              0x02
+#PN548AD            0x03
+#PN66T              0x04
+
+NXP_NFC_CHIP=0x03
+
+###############################################################################
+# CE when Screen state is locked
+# Disable           0x00
+# Enable            0x01
+NXP_CE_ROUTE_STRICT_DISABLE=0x01
+
+#Timeout in secs to get NFCEE Discover notification
+NXP_DEFAULT_NFCEE_DISC_TIMEOUT=20
+
+NXP_DEFAULT_NFCEE_TIMEOUT=0x06
+
+#Timeout in secs
+NXP_SWP_RD_START_TIMEOUT=0x0A
+
+#Timeout in secs
+NXP_SWP_RD_TAG_OP_TIMEOUT=0x01
+
+###############################################################################
+#Set the default AID route Location :
+#This settings will be used when application does not set this parameter
+# host 0x00
+# eSE  0x01
+# UICC 0x02
+DEFAULT_AID_ROUTE=0x00
+
+###############################################################################
+#Set the Mifare Desfire route Location :
+#This settings will be used when application does not set this parameter
+# host 0x00
+# eSE  0x01
+# UICC 0x02
+DEFAULT_DESFIRE_ROUTE=0x02
+
+###############################################################################
+#Set the Mifare CLT route Location :
+#This settings will be used when application does not set this parameter
+# host 0x00
+# eSE  0x01
+# UICC 0x02
+DEFAULT_MIFARE_CLT_ROUTE=0x02
+###############################################################################
+# AID Matching platform options
+# AID_MATCHING_L 0x01
+# AID_MATCHING_K 0x02
+AID_MATCHING_PLATFORM=0x01
+###############################################################################
+#CHINA_TIANJIN_RF_SETTING
+#Enable  0x01
+#Disable 0x00
+NXP_CHINA_TIANJIN_RF_ENABLED=0x01
+###############################################################################
+#SWP_SWITCH_TIMEOUT_SETTING
+# Allowed range of swp timeout setting is 0x00 to 0x3C [0 - 60].
+# Timeout in milliseconds, for example
+# No Timeout  0x00
+# 10 millisecond timeout 0x0A
+NXP_SWP_SWITCH_TIMEOUT=0x0A
+###############################################################################
+#Dynamic RSSI feature enable
+# Disable 0x00
+# Enable  0x01
+NXP_AGC_DEBUG_ENABLE=0x00
+
+###############################################################################
+#Config to allow adding aids
+#NFC on/off is required after this config
+#1 = enabling adding aid  to NFCC routing table.
+#0 = disabling adding aid to NFCC routing table.
+NXP_ENABLE_ADD_AID=0x01
+################################################################################
\ No newline at end of file
diff --git a/halimpl/pn54x/log/phNxpLog.c b/halimpl/pn54x/log/phNxpLog.c
index ad8886c..726ef26 100644
--- a/halimpl/pn54x/log/phNxpLog.c
+++ b/halimpl/pn54x/log/phNxpLog.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include <string.h>
+/* ############################################### Header Includes ################################################ */
 #if ! defined (NXPLOG__H_INCLUDED)
 #    include "phNxpLog.h"
 #    include "phNxpConfig.h"
diff --git a/halimpl/pn54x/log/phNxpLog.h b/halimpl/pn54x/log/phNxpLog.h
index 22ce7b4..c1fea49 100644
--- a/halimpl/pn54x/log/phNxpLog.h
+++ b/halimpl/pn54x/log/phNxpLog.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 #define NXPLOG__H_INCLUDED
 
 #include <cutils/log.h>
+#include <string.h>
 
 typedef struct nci_log_level
 {
diff --git a/halimpl/pn54x/nfc_nci.c b/halimpl/pn54x/nfc_nci.c
index 4ae45ec..4c984e7 100644
--- a/halimpl/pn54x/nfc_nci.c
+++ b/halimpl/pn54x/nfc_nci.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,14 +16,13 @@
 
 #define LOG_TAG "NxpNfcNciHal"
 
-#include <string.h>
-#include <stdlib.h>
 #include <utils/Log.h>
 #include <errno.h>
 #include <hardware/hardware.h>
 #include <hardware/nfc.h>
 #include <phNxpNciHal_Adaptation.h>
-
+#include <string.h>
+#include <stdlib.h>
 /*****************************************************************************
  * NXP NCI HAL Function implementations.
  *****************************************************************************/
@@ -70,6 +69,24 @@
 
 /*******************************************************************************
 **
+** Function         hal_ioctl
+**
+** Description      Invoke ioctl to  to NFCC driver.
+**
+** Returns          status code of ioctl.
+**
+*******************************************************************************/
+static int hal_ioctl(const struct nfc_nci_device *p_dev, long arg, void *p_data)
+{
+    int retval = 0;
+    pn547_dev_t* dev = (pn547_dev_t*) p_dev;
+
+    retval = phNxpNciHal_ioctl(arg, p_data);
+    return retval;
+}
+
+/*******************************************************************************
+**
 ** Function         hal_core_initialized
 **
 ** Description      Notify NFCC after successful initialization of NFCC.
@@ -208,6 +225,7 @@
         /* NCI HAL method pointers */
         dev->nci_device.open = hal_open;
         dev->nci_device.write = hal_write;
+        dev->nci_device.ioctl = hal_ioctl;
         dev->nci_device.core_initialized = hal_core_initialized;
         dev->nci_device.pre_discover = hal_pre_discover;
         dev->nci_device.close = hal_close;
@@ -239,7 +257,7 @@
         .tag = HARDWARE_MODULE_TAG,
         .module_api_version = 0x0100, /* [15:8] major, [7:0] minor (1.0) */
         .hal_api_version = 0x00, /* 0 is only valid value */
-        .id = NFC_NCI_HARDWARE_MODULE_ID,
+        .id = NFC_NCI_NXP_PN54X_HARDWARE_MODULE_ID,
         .name = "NXP PN54X NFC NCI HW HAL",
         .author = "NXP Semiconductors",
         .methods = &nfc_module_methods,
diff --git a/halimpl/pn54x/self-test/phNxpNciHal_SelfTest.c b/halimpl/pn54x/self-test/phNxpNciHal_SelfTest.c
index c45099f..e6998d7 100644
--- a/halimpl/pn54x/self-test/phNxpNciHal_SelfTest.c
+++ b/halimpl/pn54x/self-test/phNxpNciHal_SelfTest.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * 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 <phNxpLog.h>
 #include <pthread.h>
 #include <phOsalNfc_Timer.h>
+#include <phNxpConfig.h>
 
 #define HAL_WRITE_RSP_TIMEOUT   (2000)   /* Timeout value to wait for response from PN54X */
 #define HAL_WRITE_MAX_RETRY     (10)
@@ -1384,9 +1385,11 @@
 
     phOsalNfc_Config_t tOsalConfig;
     phTmlNfc_Config_t tTmlConfig;
+    uint8_t *nfc_dev_node = NULL;
+    const uint16_t max_len = 260; /* device node name is max of 255 bytes + 5 bytes (/dev/) */
     NFCSTATUS status = NFCSTATUS_SUCCESS;
     uint16_t read_len = 255;
-
+    int8_t ret_val = 0x00;
     /* initialize trace level */
     phNxpLog_InitializeLogLevel();
 
@@ -1401,9 +1404,22 @@
     memset(&tOsalConfig, 0x00, sizeof(tOsalConfig));
     memset(&tTmlConfig, 0x00, sizeof(tTmlConfig));
 
+    /* Read the nfc device node name */
+    nfc_dev_node = (uint8_t*) malloc(max_len*sizeof(uint8_t));
+    if(nfc_dev_node == NULL)
+    {
+        NXPLOG_NCIHAL_E("malloc of nfc_dev_node failed ");
+        goto clean_and_return;
+    }
+    else if (!GetNxpStrValue (NAME_NXP_NFC_DEV_NODE, nfc_dev_node, sizeof (nfc_dev_node)))
+    {
+        NXPLOG_NCIHAL_E("Invalid nfc device node name keeping the default device node /dev/pn544");
+        strcpy (nfc_dev_node, "/dev/pn544");
+    }
+
     gDrvCfg.nClientId = phDal4Nfc_msgget(0, 0600);
     gDrvCfg.nLinkType = ENUM_LINK_TYPE_I2C;/* For PN54X */
-    tTmlConfig.pDevName = (int8_t *) "/dev/pn54x";
+    tTmlConfig.pDevName = (uint8_t *) nfc_dev_node;
     tOsalConfig.dwCallbackThreadId = (uintptr_t) gDrvCfg.nClientId;
     tOsalConfig.pLogFile = NULL;
     tTmlConfig.dwGetMsgThreadId = (uintptr_t) gDrvCfg.nClientId;
@@ -1416,12 +1432,22 @@
         NXPLOG_NCIHAL_E("phTmlNfc_Init Failed");
         goto clean_and_return;
     }
+    else
+    {
+        if(nfc_dev_node != NULL)
+        {
+            free(nfc_dev_node);
+            nfc_dev_node = NULL;
+        }
+    }
 
     pthread_attr_t attr;
     pthread_attr_init(&attr);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-    if (pthread_create(&test_rx_thread, &attr,
-            phNxpNciHal_test_rx_thread, NULL) != 0)
+    ret_val = pthread_create(&test_rx_thread, &attr,
+            phNxpNciHal_test_rx_thread, NULL);
+    pthread_attr_destroy(&attr);
+    if (ret_val != 0)
     {
         NXPLOG_NCIHAL_E("pthread_create failed");
         phTmlNfc_Shutdown();
@@ -1444,6 +1470,11 @@
 
 clean_and_return:
     CONCURRENCY_UNLOCK();
+    if(nfc_dev_node != NULL)
+    {
+        free(nfc_dev_node);
+        nfc_dev_node = NULL;
+    }
     phNxpNciHal_cleanup_monitor();
     return NFCSTATUS_FAILED;
 }
diff --git a/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.c b/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.c
index e19eaca..d2ac339 100644
--- a/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.c
+++ b/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.h b/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.h
index e121223..6ebbc38 100644
--- a/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.h
+++ b/halimpl/pn54x/tml/phDal4Nfc_messageQueueLib.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/tml/phOsalNfc_Timer.c b/halimpl/pn54x/tml/phOsalNfc_Timer.c
index bdd4cba..26db61a 100644
--- a/halimpl/pn54x/tml/phOsalNfc_Timer.c
+++ b/halimpl/pn54x/tml/phOsalNfc_Timer.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/tml/phOsalNfc_Timer.h b/halimpl/pn54x/tml/phOsalNfc_Timer.h
index 6749785..63312e5 100644
--- a/halimpl/pn54x/tml/phOsalNfc_Timer.h
+++ b/halimpl/pn54x/tml/phOsalNfc_Timer.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/tml/phTmlNfc.c b/halimpl/pn54x/tml/phTmlNfc.c
index e2ee759..53d1bd8 100644
--- a/halimpl/pn54x/tml/phTmlNfc.c
+++ b/halimpl/pn54x/tml/phTmlNfc.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,7 +24,10 @@
 #include <phDal4Nfc_messageQueueLib.h>
 #include <phTmlNfc_i2c.h>
 #include <phNxpNciHal_utils.h>
-
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+#include <sys/types.h>
+long nfc_service_pid;
+#endif
 /*
  * Duration of Timer to wait after sending an Nci packet
  */
@@ -76,6 +79,7 @@
 NFCSTATUS phTmlNfc_Init(pphTmlNfc_Config_t pConfig)
 {
     NFCSTATUS wInitStatus = NFCSTATUS_SUCCESS;
+    NFCSTATUS setPidStatus = NFCSTATUS_SUCCESS;
 
     /* Check if TML layer is already Initialized */
     if (NULL != gpphTmlNfc_Context)
@@ -170,6 +174,21 @@
         /* Clear all handles and memory locations initialized during init */
         phTmlNfc_CleanUp();
     }
+#if(NFC_POWER_MANAGEMENT == TRUE)
+    else
+    {
+        nfc_service_pid = getpid();
+        setPidStatus = phTmlNfc_IoCtl(phTmlNfc_e_SetNfcServicePid);
+        if(setPidStatus == NFCSTATUS_SUCCESS)
+       {
+           NXPLOG_TML_D("nfc service set pid done");
+       }
+       else
+       {
+           NXPLOG_TML_D("nfc service set pid failed");
+       }
+    }
+#endif
 
     return wInitStatus;
 }
@@ -922,6 +941,28 @@
                     usleep(100 * 1000);
                     break;
                 }
+#if(NFC_POWER_MANAGEMENT == TRUE)
+            case phTmlNfc_e_SetNfcServicePid:
+            {
+                wStatus = phTmlNfc_set_pid(gpphTmlNfc_Context->pDevHandle, nfc_service_pid);
+                break;
+            }
+            case phTmlNfc_e_GetP61PwrMode:
+            {
+                wStatus = phTmlNfc_i2c_get_p61_power_state(gpphTmlNfc_Context->pDevHandle);
+                break;
+            }
+            case phTmlNfc_e_SetP61WiredMode:
+            {
+                wStatus = phTmlNfc_i2c_set_p61_power_state(gpphTmlNfc_Context->pDevHandle, 1);
+                break;
+            }
+            case phTmlNfc_e_SetP61IdleMode:
+            {
+                wStatus = phTmlNfc_i2c_set_p61_power_state(gpphTmlNfc_Context->pDevHandle, 0);
+                break;
+            }
+#endif
             default:
                 {
                     wStatus = NFCSTATUS_INVALID_PARAMETER;
diff --git a/halimpl/pn54x/tml/phTmlNfc.h b/halimpl/pn54x/tml/phTmlNfc.h
index 8a1641b..1c28ef6 100644
--- a/halimpl/pn54x/tml/phTmlNfc.h
+++ b/halimpl/pn54x/tml/phTmlNfc.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -99,7 +99,13 @@
     phTmlNfc_e_Invalid = 0,
     phTmlNfc_e_ResetDevice = PH_TMLNFC_RESETDEVICE, /* Reset the device */
     phTmlNfc_e_EnableDownloadMode, /* Do the hardware setting to enter into download mode */
-    phTmlNfc_e_EnableNormalMode /* Hardware setting for normal mode of operation */
+    phTmlNfc_e_EnableNormalMode/* Hardware setting for normal mode of operation */
+#if(NFC_POWER_MANAGEMENT == TRUE)
+    ,phTmlNfc_e_SetNfcServicePid, /* Register the Nfc service PID with the driver */
+    phTmlNfc_e_GetP61PwrMode, /* Get the current P61 mode of operation */
+    phTmlNfc_e_SetP61WiredMode, /* Set the current P61 mode of operation to Wired*/
+    phTmlNfc_e_SetP61IdleMode /* Set the current P61 mode of operation to Idle*/
+#endif
 } phTmlNfc_ControlCode_t ;  /* Control code for IOCTL call */
 
 /*
diff --git a/halimpl/pn54x/tml/phTmlNfc_i2c.c b/halimpl/pn54x/tml/phTmlNfc_i2c.c
index 7add07f..ed3fe4f 100644
--- a/halimpl/pn54x/tml/phTmlNfc_i2c.c
+++ b/halimpl/pn54x/tml/phTmlNfc_i2c.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
 #include <phTmlNfc_i2c.h>
 #include <phNfcStatus.h>
 #include <string.h>
-#include "phNxpNciHal_utils.h"
+#include <phNxpNciHal_utils.h>
 
 #define CRC_LEN                     2
 #define NORMAL_MODE_HEADER_LEN      3
@@ -318,7 +318,6 @@
 **                  -1   - reset operation failure
 **
 *******************************************************************************/
-#define PN544_SET_PWR _IOW(0xe9, 0x01, unsigned int)
 int phTmlNfc_i2c_reset(void *pDevHandle, long level)
 {
     int ret;
@@ -339,6 +338,119 @@
     return ret;
 }
 
+#if(NFC_POWER_MANAGEMENT == TRUE)
+/*******************************************************************************
+**
+** Function         phTmlNfc_set_pid
+**
+** Description
+**
+** Parameters       pDevHandle     - valid device handle
+**                        pid - nfc service pid
+**
+** Returns          p61_access_state_t  - get_p61_power operation success
+**                  P61_STATE_INVALID   - get_p61_power operation failure
+**
+*******************************************************************************/
+NFCSTATUS phTmlNfc_set_pid(void *pDevHandle, long pid)
+{
+    int ret;
+    NXPLOG_TML_D("phTmlNfc_set_pid(), pid  %ld", pid);
+
+    if (NULL == pDevHandle)
+    {
+        return NFCSTATUS_FAILED;
+    }
+
+    ret = ioctl((int32_t)pDevHandle, P544_SET_NFC_SERVICE_PID, pid);
+    return ret;
+}
+
+/*******************************************************************************
+**
+** Function         phTmlNfc_i2c_set_p61_power_state
+**
+** Description
+**
+** Parameters       pDevHandle     - valid device handle
+**
+** Returns          p61_access_state_t  - get_p61_power operation success
+**                  P61_STATE_INVALID   - get_p61_power operation failure
+**
+*******************************************************************************/
+NFCSTATUS phTmlNfc_i2c_set_p61_power_state(void *pDevHandle, long level)
+{
+    int ret = -1;
+    NFCSTATUS wStatus = NFCSTATUS_FAILED;
+
+    NXPLOG_TML_D("phTmlNfc_i2c_set_p61_power_state(), level %ld", level);
+
+    if (NULL == pDevHandle)
+    {
+        return -1;
+    }
+    ret = ioctl((intptr_t)pDevHandle, P61_SET_WIRED_ACCESS, (unsigned long) level);
+    if(ret < 0)
+    {
+        NXPLOG_TML_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
+        if(errno == -EBUSY)
+        {
+            wStatus = NFCSTATUS_BUSY;
+        }
+        else if(errno == -EPERM)
+        {
+            wStatus = NFCSTATUS_NOT_ALLOWED;
+        }
+        else if(errno == -EBADRQC)
+        {
+            wStatus = NFCSTATUS_INVALID_PARAMETER;
+        }
+        else
+        {
+            wStatus = NFCSTATUS_FAILED;
+        }
+    }
+    else
+    {
+        wStatus = NFCSTATUS_SUCCESS;
+    }
+
+    return wStatus;
+}
+
+/*******************************************************************************
+**
+** Function         phTmlNfc_i2c_get_p61_power_state
+**
+** Description
+**
+** Parameters       pDevHandle     - valid device handle
+**
+** Returns          get_p61_power operation success
+**                  NFCSTATUS_FAILED   - get_p61_power operation failure
+**
+*******************************************************************************/
+NFCSTATUS phTmlNfc_i2c_get_p61_power_state(void *pDevHandle)
+{
+    int ret;
+    NFCSTATUS wStatus = NFCSTATUS_FAILED;
+    p61_access_state_t p61_current_state = P61_STATE_INVALID;
+    NXPLOG_TML_D("phTmlNfc_i2c_get_p61_power_mode()");
+
+    if (NULL == pDevHandle)
+    {
+        return -1;
+    }
+    ret = ioctl((intptr_t)pDevHandle, P61_GET_PWR_STATUS, (unsigned long )&p61_current_state);
+    if(ret < 0)
+    {
+        NXPLOG_TML_E("%s : failed errno = 0x%x", __FUNCTION__, errno);
+        p61_current_state = P61_STATE_INVALID;
+    }
+    wStatus = p61_current_state;
+    return wStatus;
+}
+#endif
 /*******************************************************************************
 **
 ** Function         getDownloadFlag
diff --git a/halimpl/pn54x/tml/phTmlNfc_i2c.h b/halimpl/pn54x/tml/phTmlNfc_i2c.h
index 724a2bd..f8331ce 100644
--- a/halimpl/pn54x/tml/phTmlNfc_i2c.h
+++ b/halimpl/pn54x/tml/phTmlNfc_i2c.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 NXP Semiconductors
+ * Copyright (C) 2015 NXP Semiconductors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,3 +30,44 @@
 int phTmlNfc_i2c_reset(void *pDevHandle,long level);
 bool_t getDownloadFlag(void);
 phTmlNfc_i2cfragmentation_t fragmentation_enabled;
+#define PN544_MAGIC 0xE9
+
+/*
+ * PN544 power control via ioctl
+ * PN544_SET_PWR(0): power off
+ * PN544_SET_PWR(1): power on
+ * PN544_SET_PWR(2): reset and power on with firmware download enabled
+ */
+#define PN544_SET_PWR    _IOW(PN544_MAGIC, 0x01, unsigned int)
+
+#if(NFC_POWER_MANAGEMENT == TRUE)
+NFCSTATUS phTmlNfc_i2c_get_p61_power_state(void *pDevHandle);
+NFCSTATUS phTmlNfc_i2c_set_p61_power_state(void *pDevHandle, long arg);
+NFCSTATUS phTmlNfc_set_pid(void *pDevHandle, long pid);
+
+/*
+ * SPI Request NFCC to enable p61 power, only in param
+ * Only for SPI
+ * level 1 = Enable power
+ * level 0 = Disable power
+ */
+#define P61_SET_SPI_PWR    _IOW(PN544_MAGIC, 0x02, unsigned int)
+
+/* SPI or DWP can call this ioctl to get the current
+ * power state of P61
+ *
+*/
+#define P61_GET_PWR_STATUS    _IOR(PN544_MAGIC, 0x03, unsigned int)
+
+/* DWP side this ioctl will be called
+ * level 1 = Wired access is enabled/ongoing
+ * level 0 = Wired access is disalbed/stopped
+*/
+#define P61_SET_WIRED_ACCESS _IOW(PN544_MAGIC, 0x04, unsigned int)
+
+/*
+  NFC Init will call the ioctl to register the PID with the i2c driver
+*/
+#define P544_SET_NFC_SERVICE_PID _IOW(PN544_MAGIC, 0x05, long)
+
+#endif
diff --git a/halimpl/pn54x/utils/phNxpConfig.cpp b/halimpl/pn54x/utils/phNxpConfig.cpp
index b44d018..0dd7bc0 100644
--- a/halimpl/pn54x/utils/phNxpConfig.cpp
+++ b/halimpl/pn54x/utils/phNxpConfig.cpp
@@ -20,7 +20,7 @@
  *
  *  The original Work has been changed by NXP Semiconductors.
  *
- *  Copyright (C) 2013-2014 NXP Semiconductors
+ *  Copyright (C) 2015 NXP Semiconductors
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -36,13 +36,13 @@
  *
  ******************************************************************************/
 
+#include <phNxpConfig.h>
+#include <stdio.h>
 #include <string>
 #include <vector>
 #include <list>
-#include <stdio.h>
 #include <sys/stat.h>
 
-#include <phNxpConfig.h>
 #include <phNxpLog.h>
 
 #if GENERIC_TARGET
@@ -66,6 +66,8 @@
 
 using namespace::std;
 
+namespace nxp {
+
 class CNfcParam : public string
 {
 public:
@@ -871,6 +873,29 @@
 
 /*******************************************************************************
 **
+** Function:    readOptionalConfig()
+**
+** Description: read Config settings from an optional conf file
+**
+** Returns:     none
+**
+*******************************************************************************/
+void readOptionalConfig(const char* extra)
+{
+    string strPath;
+    strPath.assign(transport_config_path);
+    if (alternative_config_path[0] != '\0')
+        strPath.assign(alternative_config_path);
+
+    strPath += extra_config_base;
+    strPath += extra;
+    strPath += extra_config_ext;
+    CNfcConfig::GetInstance().readConfig(strPath.c_str(), false);
+}
+
+} // namespace nxp
+/*******************************************************************************
+**
 ** Function:    GetStrValue
 **
 ** Description: API function for getting a string value of a setting
@@ -880,7 +905,7 @@
 *******************************************************************************/
 extern "C" int GetNxpStrValue(const char* name, char* pValue, unsigned long len)
 {
-    CNfcConfig& rConfig = CNfcConfig::GetInstance();
+    nxp::CNfcConfig& rConfig = nxp::CNfcConfig::GetInstance();
 
     return rConfig.getValue(name, pValue, len);
 }
@@ -903,7 +928,7 @@
 *******************************************************************************/
 extern "C" int GetNxpByteArrayValue(const char* name, char* pValue,long bufflen, long *len)
 {
-    CNfcConfig& rConfig = CNfcConfig::GetInstance();
+    nxp::CNfcConfig& rConfig = nxp::CNfcConfig::GetInstance();
 
     return rConfig.getValue(name, pValue, bufflen,len);
 }
@@ -922,8 +947,8 @@
     if (!pValue)
         return false;
 
-    CNfcConfig& rConfig = CNfcConfig::GetInstance();
-    const CNfcParam* pParam = rConfig.find(name);
+    nxp::CNfcConfig& rConfig = nxp::CNfcConfig::GetInstance();
+    const nxp::CNfcParam* pParam = rConfig.find(name);
 
     if (pParam == NULL)
         return false;
@@ -966,35 +991,13 @@
 extern "C" void resetNxpConfig()
 
 {
-    CNfcConfig& rConfig = CNfcConfig::GetInstance();
+    nxp::CNfcConfig& rConfig = nxp::CNfcConfig::GetInstance();
 
     rConfig.clean();
 }
 
 /*******************************************************************************
 **
-** Function:    readOptionalConfig()
-**
-** Description: read Config settings from an optional conf file
-**
-** Returns:     none
-**
-*******************************************************************************/
-void readOptionalConfig(const char* extra)
-{
-    string strPath;
-    strPath.assign(transport_config_path);
-    if (alternative_config_path[0] != '\0')
-        strPath.assign(alternative_config_path);
-
-    strPath += extra_config_base;
-    strPath += extra;
-    strPath += extra_config_ext;
-    CNfcConfig::GetInstance().readConfig(strPath.c_str(), false);
-}
-
-/*******************************************************************************
-**
 ** Function:    isNxpConfigModified()
 **
 ** Description: check if config file has modified
@@ -1004,7 +1007,7 @@
 *******************************************************************************/
 extern "C" int isNxpConfigModified()
 {
-    CNfcConfig& rConfig = CNfcConfig::GetInstance();
+    nxp::CNfcConfig& rConfig = nxp::CNfcConfig::GetInstance();
     return rConfig.checkTimestamp();
 }
 
@@ -1019,6 +1022,6 @@
 *******************************************************************************/
 extern "C" int updateNxpConfigTimestamp()
 {
-    CNfcConfig& rConfig = CNfcConfig::GetInstance();
+    nxp::CNfcConfig& rConfig = nxp::CNfcConfig::GetInstance();
     return rConfig.updateTimestamp();
 }
diff --git a/halimpl/pn54x/utils/phNxpConfig.h b/halimpl/pn54x/utils/phNxpConfig.h
index 45c1ecd..ebde1c4 100644
--- a/halimpl/pn54x/utils/phNxpConfig.h
+++ b/halimpl/pn54x/utils/phNxpConfig.h
@@ -20,7 +20,7 @@
  *
  *  The original Work has been changed by NXP Semiconductors.
  *
- *  Copyright (C) 2013-2014 NXP Semiconductors
+ *  Copyright (C) 2015 NXP Semiconductors
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -64,6 +64,8 @@
 
 #define NAME_MIFARE_READER_ENABLE    "MIFARE_READER_ENABLE"
 #define NAME_FW_STORAGE              "FW_STORAGE"
+#define NAME_NXP_NFC_DEV_NODE        "NXP_NFC_DEV_NODE"
+#define NAME_NXP_FW_NAME             "NXP_FW_NAME"
 #define NAME_NXP_FW_PROTECION_OVERRIDE "NXP_FW_PROTECION_OVERRIDE"
 #define NAME_NXP_SYS_CLK_SRC_SEL     "NXP_SYS_CLK_SRC_SEL"
 #define NAME_NXP_SYS_CLK_FREQ_SEL    "NXP_SYS_CLK_FREQ_SEL"
@@ -91,7 +93,8 @@
 #define NAME_NXP_NFC_MERGE_RF_PARAMS "NXP_NFC_MERGE_RF_PARAMS"
 #define NAME_NXP_I2C_FRAGMENTATION_ENABLED "NXP_I2C_FRAGMENTATION_ENABLED"
 #define NAME_AID_MATCHING_PLATFORM "AID_MATCHING_PLATFORM"
-
+#define NAME_NXP_TYPEA_UICC_BAUD_RATE "NXP_TYPEA_UICC_BAUD_RATE"
+#define NAME_NXP_TYPEB_UICC_BAUD_RATE "NXP_TYPEB_UICC_BAUD_RATE"
 
 /* default configuration */
 #define default_storage_location "/data/nfc"
diff --git a/halimpl/pn54x/utils/phNxpNciHal_utils.c b/halimpl/pn54x/utils/phNxpNciHal_utils.c
index 65ec89d..6363745 100644
--- a/halimpl/pn54x/utils/phNxpNciHal_utils.c
+++ b/halimpl/pn54x/utils/phNxpNciHal_utils.c
@@ -1,6 +1,24 @@
 /*
+ * Copyright (C) 2010 The Android Open Source Project
  *
- *  Copyright (C) 2013-2014 NXP Semiconductors
+ * 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.
+ */
+
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
diff --git a/halimpl/pn54x/utils/phNxpNciHal_utils.h b/halimpl/pn54x/utils/phNxpNciHal_utils.h
index f7bdfa2..26f6629 100644
--- a/halimpl/pn54x/utils/phNxpNciHal_utils.h
+++ b/halimpl/pn54x/utils/phNxpNciHal_utils.h
@@ -1,6 +1,24 @@
 /*
+ * Copyright (C) 2010 The Android Open Source Project
  *
- *  Copyright (C) 2013-2014 NXP Semiconductors
+ * 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.
+ */
+
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
diff --git a/src/adaptation/CrcChecksum.cpp b/src/adaptation/CrcChecksum.cpp
index 691e8ef..e487bf0 100644
--- a/src/adaptation/CrcChecksum.cpp
+++ b/src/adaptation/CrcChecksum.cpp
@@ -15,6 +15,26 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 "OverrideLog.h"
 #include "CrcChecksum.h"
 #include <sys/types.h>
@@ -22,7 +42,9 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <string>
+#ifndef LOG_TAG
 #define LOG_TAG "NfcNciHal"
+#endif
 
 
 static const unsigned short crctab [256] =
diff --git a/src/adaptation/NfcAdaptation.cpp b/src/adaptation/NfcAdaptation.cpp
index 1a9e191..210bd9d 100644
--- a/src/adaptation/NfcAdaptation.cpp
+++ b/src/adaptation/NfcAdaptation.cpp
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 "OverrideLog.h"
 #include "NfcAdaptation.h"
 extern "C"
@@ -40,9 +59,17 @@
 tHAL_NFC_DATA_CBACK* NfcAdaptation::mHalDataCallback = NULL;
 ThreadCondVar NfcAdaptation::mHalOpenCompletedEvent;
 ThreadCondVar NfcAdaptation::mHalCloseCompletedEvent;
+#if (NXP_EXTNS == TRUE)
+ThreadCondVar NfcAdaptation::mHalCoreResetCompletedEvent;
+ThreadCondVar NfcAdaptation::mHalCoreInitCompletedEvent;
+ThreadCondVar NfcAdaptation::mHalInitCompletedEvent;
+#endif
 
 UINT32 ScrProtocolTraceFlag = SCR_PROTO_TRACE_ALL; //0x017F00;
 UINT8 appl_trace_level = 0xff;
+#if (NXP_EXTNS == TRUE)
+UINT8 appl_dta_mode_flag = 0x00;
+#endif
 char bcm_nfc_location[120];
 char nci_hal_module[64];
 
@@ -309,6 +336,9 @@
     mHalEntryFuncs.close = HalClose;
     mHalEntryFuncs.core_initialized = HalCoreInitialized;
     mHalEntryFuncs.write = HalWrite;
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+    mHalEntryFuncs.ioctl = HalIoctl;
+#endif
     mHalEntryFuncs.prediscover = HalPrediscover;
     mHalEntryFuncs.control_granted = HalControlGranted;
     mHalEntryFuncs.power_cycle = HalPowerCycle;
@@ -453,6 +483,36 @@
     }
 }
 
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+/*******************************************************************************
+**
+** Function:    NfcAdaptation::HalIoctl
+**
+** Description: Calls ioctl to the Nfc driver.
+**              If called with a arg value of 0x01 than wired access requested,
+**              status of the requst would be updated to p_data.
+**              If called with a arg value of 0x00 than wired access will be
+**              released, status of the requst would be updated to p_data.
+**              If called with a arg value of 0x02 than current p61 state would be
+**              updated to p_data.
+**
+** Returns:     -1 or 0.
+**
+*******************************************************************************/
+int NfcAdaptation::HalIoctl (long arg, void* p_data)
+{
+    const char* func = "NfcAdaptation::HalIoctl";
+    ALOGD ("%s", func);
+    if (mHalDeviceContext)
+    {
+        return (mHalDeviceContext->ioctl (mHalDeviceContext, arg, p_data));
+    }
+    return -1;
+}
+
+#endif
+
+
 /*******************************************************************************
 **
 ** Function:    NfcAdaptation::HalCoreInitialized
@@ -579,12 +639,37 @@
 {
     const char* func = "NfcAdaptation::DownloadFirmware";
     ALOGD ("%s: enter", func);
+#if (NXP_EXTNS == TRUE)
+    static UINT8 cmd_reset_nci[] = {0x20,0x00,0x01,0x01};
+    static UINT8 cmd_init_nci[]  = {0x20,0x01,0x00};
+    static UINT8 cmd_reset_nci_size = sizeof(cmd_reset_nci) / sizeof(UINT8);
+    static UINT8 cmd_init_nci_size  = sizeof(cmd_init_nci)  / sizeof(UINT8);
+    UINT8 p_core_init_rsp_params;
+#endif
     HalInitialize ();
 
     mHalOpenCompletedEvent.lock ();
     ALOGD ("%s: try open HAL", func);
     HalOpen (HalDownloadFirmwareCallback, HalDownloadFirmwareDataCallback);
     mHalOpenCompletedEvent.wait ();
+#if (NXP_EXTNS == TRUE)
+    /* Send a CORE_RESET and CORE_INIT to the NFCC. This is required because when calling
+     * HalCoreInitialized, the HAL is going to parse the conf file and send NCI commands
+     * to the NFCC. Hence CORE-RESET and CORE-INIT have to be sent prior to this.
+     */
+    mHalCoreResetCompletedEvent.lock();
+    ALOGD("%s: send CORE_RESET", func);
+    HalWrite(cmd_reset_nci_size , cmd_reset_nci);
+    mHalCoreResetCompletedEvent.wait();
+    mHalCoreInitCompletedEvent.lock();
+    ALOGD("%s: send CORE_INIT", func);
+    HalWrite(cmd_init_nci_size , cmd_init_nci);
+    mHalCoreInitCompletedEvent.wait();
+    mHalInitCompletedEvent.lock ();
+    ALOGD ("%s: try init HAL", func);
+    HalCoreInitialized (&p_core_init_rsp_params);
+    mHalInitCompletedEvent.wait ();
+#endif
 
     mHalCloseCompletedEvent.lock ();
     ALOGD ("%s: try close HAL", func);
@@ -616,6 +701,12 @@
             mHalOpenCompletedEvent.signal ();
             break;
         }
+    case HAL_NFC_POST_INIT_CPLT_EVT:
+        {
+            ALOGD ("%s: HAL_NFC_POST_INIT_CPLT_EVT", func);
+            mHalInitCompletedEvent.signal ();
+            break;
+        }
     case HAL_NFC_CLOSE_CPLT_EVT:
         {
             ALOGD ("%s: HAL_NFC_CLOSE_CPLT_EVT", func);
@@ -636,6 +727,19 @@
 *******************************************************************************/
 void NfcAdaptation::HalDownloadFirmwareDataCallback (uint16_t data_len, uint8_t* p_data)
 {
+#if (NXP_EXTNS == TRUE)
+    if (data_len > 3)
+    {
+        if (p_data[0] == 0x40 && p_data[1] == 0x00)
+        {
+            mHalCoreResetCompletedEvent.signal();
+        }
+        else if (p_data[0] == 0x40 && p_data[1] == 0x01)
+        {
+            mHalCoreInitCompletedEvent.signal();
+        }
+    }
+#endif
 }
 
 
diff --git a/src/adaptation/OverrideLog.cpp b/src/adaptation/OverrideLog.cpp
index d0fda56..49daa4d 100644
--- a/src/adaptation/OverrideLog.cpp
+++ b/src/adaptation/OverrideLog.cpp
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  Override the ALOGD(), ALOGE(), and other logging macros from
@@ -55,7 +73,6 @@
     num = 1;
     if (GetNumValue (NAME_APPL_TRACE_LEVEL, &num, sizeof(num)))
         appl_trace_level = (unsigned char) num;
-
     int len = property_get ("nfc.app_log_level", valueStr, "");
     if (len > 0)
     {
@@ -99,3 +116,20 @@
     return ScrProtocolTraceFlag;
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function:        initializeGlobalDtaMode
+**
+** Description:     Initialize and get global DTA mode from .conf
+**
+** Returns:         none:
+**
+*******************************************************************************/
+void initializeGlobalAppDtaMode ()
+{
+    appl_dta_mode_flag = 0x01;
+    ALOGD("%s: DTA Enabled", __FUNCTION__);
+
+}
+#endif
diff --git a/src/adaptation/android_logmsg.cpp b/src/adaptation/android_logmsg.cpp
new file mode 100644
index 0000000..56c4e1b
--- /dev/null
+++ b/src/adaptation/android_logmsg.cpp
@@ -0,0 +1,417 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 1999-2012 Broadcom Corporation
+ *
+ *  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.
+ *
+ ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 "OverrideLog.h"
+#include "android_logmsg.h"
+#include "nfc_target.h"
+#include "buildcfg.h"
+#include <cutils/log.h>
+
+
+extern UINT32 ScrProtocolTraceFlag;
+#define MAX_NCI_PACKET_SIZE 259
+#define BTE_LOG_BUF_SIZE 1024
+#define BTE_LOG_MAX_SIZE (BTE_LOG_BUF_SIZE - 12)
+#define MAX_LOGCAT_LINE 4096
+#define PRINT(s) __android_log_write (ANDROID_LOG_DEBUG, "BrcmNci", s)
+#define UNUSED(X) (void)X
+static char log_line [MAX_LOGCAT_LINE];
+static const char* sTable = "0123456789abcdef";
+static BOOLEAN sIsUseRaw = FALSE;
+static void ToHex (const UINT8* data, UINT16 len, char* hexString, UINT16 hexStringSize);
+static void dumpbin (const char* data, int size, UINT32 trace_layer, UINT32 trace_type);
+static inline void word2hex (const char* data, char** hex);
+static inline void byte2char (const char* data, char** str);
+static inline void byte2hex (const char* data, char** str);
+
+
+void BTDISP_LOCK_LOG()
+{
+}
+
+
+void BTDISP_UNLOCK_LOG()
+{
+}
+
+
+void BTDISP_INIT_LOCK()
+{
+}
+
+
+void BTDISP_UNINIT_LOCK()
+{
+}
+
+
+void ProtoDispAdapterUseRawOutput (BOOLEAN isUseRaw)
+{
+    sIsUseRaw = isUseRaw;
+}
+
+
+void ProtoDispAdapterDisplayNciPacket (UINT8 *nciPacket, UINT16 nciPacketLen, BOOLEAN is_recv)
+{
+    //Protocol decoder is not available, so decode NCI packet into hex numbers.
+    if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_NCI))
+        return;
+    char line_buf [(MAX_NCI_PACKET_SIZE*2)+1];
+    ToHex (nciPacket, nciPacketLen, line_buf, sizeof(line_buf));
+    __android_log_write (ANDROID_LOG_DEBUG, (is_recv) ? "BrcmNciR": "BrcmNciX", line_buf);
+}
+
+
+void ToHex (const UINT8* data, UINT16 len, char* hexString, UINT16 hexStringSize)
+{
+    int i=0, j=0;
+    for(i = 0, j = 0; i < len && j < hexStringSize-3; i++)
+    {
+        hexString [j++] = sTable [(*data >> 4) & 0xf];
+        hexString [j++] = sTable [*data & 0xf];
+        data++;
+    }
+    hexString [j] = '\0';
+}
+
+
+//Protodisp code calls ScrLog() to print decoded texts.
+void ScrLog (UINT32 trace_set_mask, const char *fmt_str, ...)
+{
+    static char buffer [BTE_LOG_BUF_SIZE];
+    va_list ap;
+    UNUSED(trace_set_mask);
+    va_start (ap, fmt_str);
+    vsnprintf (buffer, BTE_LOG_MAX_SIZE, fmt_str, ap);
+    va_end (ap);
+    __android_log_write(ANDROID_LOG_INFO, "BrcmNci", buffer);
+}
+
+
+UINT8 *scru_dump_hex (UINT8 *p, char *pTitle, UINT32 len, UINT32 layer, UINT32 type)
+{
+    if(pTitle && *pTitle)
+        PRINT(pTitle);
+    dumpbin((char*) p, len, layer, type);
+    return p;
+}
+
+
+void dumpbin(const char* data, int size, UINT32 trace_layer, UINT32 trace_type)
+{
+    char line_buff[256];
+    char *line;
+    int i, j, addr;
+    const int width = 16;
+    UNUSED(trace_layer);
+    UNUSED(trace_type);
+    if(size <= 0)
+        return;
+    for(i = 0; i < size / width; i++)
+    {
+        line = line_buff;
+        //write address:
+        addr = i*width;
+        word2hex((const char*)&addr, &line);
+        *line++ = ':'; *line++ = ' ';
+        //write hex of data
+        for(j = 0; j < width; j++)
+        {
+            byte2hex(&data[j], &line);
+            *line++ = ' ';
+        }
+        //write char of data
+        for(j = 0; j < width; j++)
+            byte2char(data++, &line);
+        //wirte the end of line
+        *line = 0;
+        //output the line
+        PRINT(line_buff);
+    }
+    //last line of left over if any
+    int leftover = size % width;
+    if(leftover > 0)
+    {
+        line = line_buff;
+        //write address:
+        addr = i*width;
+        word2hex((const char*)&addr, &line);
+        *line++ = ':'; *line++ = ' ';
+        //write hex of data
+        for(j = 0; j < leftover; j++)
+        {
+            byte2hex(&data[j], &line);
+            *line++ = ' ';
+        }
+        //write hex padding
+        for(; j < width; j++)
+        {
+            *line++ = ' ';
+            *line++ = ' ';
+            *line++ = ' ';
+        }
+        //write char of data
+        for(j = 0; j < leftover; j++)
+            byte2char(data++, &line);
+        //write the end of line
+        *line = 0;
+        //output the line
+        PRINT(line_buff);
+    }
+}
+
+
+inline void word2hex (const char* data, char** hex)
+{
+    byte2hex(&data[1], hex);
+    byte2hex(&data[0], hex);
+}
+
+
+inline void byte2char (const char* data, char** str)
+{
+    **str = *data < ' ' ? '.' : *data > '~' ? '.' : *data;
+    ++(*str);
+}
+
+
+inline void byte2hex (const char* data, char** str)
+{
+    **str = sTable[(*data >> 4) & 0xf];
+    ++*str;
+    **str = sTable[*data & 0xf];
+    ++*str;
+}
+
+
+    //Decode a few Bluetooth HCI packets into hex numbers.
+    void DispHciCmd (BT_HDR *p_buf)
+    {
+        UINT32 nBytes = ((BT_HDR_SIZE + p_buf->offset + p_buf->len)*2)+1;
+        UINT8* data = (UINT8*) p_buf;
+        int data_len = BT_HDR_SIZE + p_buf->offset + p_buf->len;
+
+        if (appl_trace_level < BT_TRACE_LEVEL_DEBUG)
+            return;
+
+        if (nBytes > sizeof(log_line))
+            return;
+
+        ToHex (data, data_len, log_line, sizeof(log_line));
+        __android_log_write (ANDROID_LOG_DEBUG, "BrcmHciX", log_line);
+    }
+
+
+    //Decode a few Bluetooth HCI packets into hex numbers.
+    void DispHciEvt (BT_HDR *p_buf)
+    {
+        UINT32 nBytes = ((BT_HDR_SIZE + p_buf->offset + p_buf->len)*2)+1;
+        UINT8* data = (UINT8*) p_buf;
+        int data_len = BT_HDR_SIZE + p_buf->offset + p_buf->len;
+
+        if (appl_trace_level < BT_TRACE_LEVEL_DEBUG)
+            return;
+
+        if (nBytes > sizeof(log_line))
+            return;
+
+        ToHex (data, data_len, log_line, sizeof(log_line));
+        __android_log_write (ANDROID_LOG_DEBUG, "BrcmHciR", log_line);
+    }
+
+
+    /*******************************************************************************
+    **
+    ** Function         DispLLCP
+    **
+    ** Description      Log LLCP packet as hex-ascii bytes.
+    **
+    ** Returns          None.
+    **
+    *******************************************************************************/
+    void DispLLCP (BT_HDR *p_buf, BOOLEAN is_recv)
+    {
+        UINT32 nBytes = ((BT_HDR_SIZE + p_buf->offset + p_buf->len)*2)+1;
+        UINT8 * data = (UINT8*) p_buf;
+        int data_len = BT_HDR_SIZE + p_buf->offset + p_buf->len;
+
+        if (appl_trace_level < BT_TRACE_LEVEL_DEBUG)
+            return;
+
+        if (nBytes > sizeof(log_line))
+            return;
+
+        ToHex (data, data_len, log_line, sizeof(log_line));
+        __android_log_write (ANDROID_LOG_DEBUG, (is_recv) ? "BrcmLlcpR": "BrcmLlcpX", log_line);
+    }
+
+
+    /*******************************************************************************
+    **
+    ** Function         DispHcp
+    **
+    ** Description      Log raw HCP packet as hex-ascii bytes
+    **
+    ** Returns          None.
+    **
+    *******************************************************************************/
+    void DispHcp (UINT8 *data, UINT16 len, BOOLEAN is_recv)
+    {
+        UINT32 nBytes = (len*2)+1;
+
+        if (appl_trace_level < BT_TRACE_LEVEL_DEBUG)
+            return;
+
+        // Only trace HCP if we're tracing HCI as well
+        if (!(ScrProtocolTraceFlag & SCR_PROTO_TRACE_HCI_SUMMARY))
+            return;
+
+        if (nBytes > sizeof(log_line))
+            return;
+
+        ToHex (data, len, log_line, sizeof(log_line));
+        __android_log_write (ANDROID_LOG_DEBUG, (is_recv) ? "BrcmHcpR": "BrcmHcpX", log_line);
+    }
+
+
+    void DispSNEP (UINT8 local_sap, UINT8 remote_sap, BT_HDR *p_buf, BOOLEAN is_first, BOOLEAN is_rx)
+    {
+       UNUSED(local_sap);
+       UNUSED(remote_sap);
+       UNUSED(p_buf);
+       UNUSED(is_first);
+       UNUSED(is_rx);
+    }
+    void DispCHO (UINT8 *pMsg, UINT32 MsgLen, BOOLEAN is_rx)
+    {
+       UNUSED(pMsg);
+       UNUSED(MsgLen);
+       UNUSED(is_rx);
+    }
+    void DispT3TagMessage(BT_HDR *p_msg, BOOLEAN is_rx)
+    {
+       UNUSED(p_msg);
+       UNUSED(is_rx);
+    }
+    void DispRWT4Tags (BT_HDR *p_buf, BOOLEAN is_rx)
+    {
+       UNUSED(p_buf);
+       UNUSED(is_rx);
+    }
+    void DispCET4Tags (BT_HDR *p_buf, BOOLEAN is_rx)
+    {
+       UNUSED(p_buf);
+       UNUSED(is_rx);
+    }
+    void DispRWI93Tag (BT_HDR *p_buf, BOOLEAN is_rx, UINT8 command_to_respond)
+    {
+       UNUSED(p_buf);
+       UNUSED(is_rx);
+       UNUSED(command_to_respond);
+    }
+    void DispNDEFMsg (UINT8 *pMsg, UINT32 MsgLen, BOOLEAN is_recv)
+    {
+       UNUSED(pMsg);
+       UNUSED(MsgLen);
+       UNUSED(is_recv);
+    }
+
+
+/*******************************************************************************
+**
+** Function:        LogMsg
+**
+** Description:     Print messages from NFC stack.
+**
+** Returns:         None.
+**
+*******************************************************************************/
+void LogMsg (UINT32 trace_set_mask, const char *fmt_str, ...)
+{
+    static char buffer [BTE_LOG_BUF_SIZE];
+    va_list ap;
+    UINT32 trace_type = trace_set_mask & 0x07; //lower 3 bits contain trace type
+    int android_log_type = ANDROID_LOG_INFO;
+
+    va_start (ap, fmt_str);
+    vsnprintf (buffer, BTE_LOG_MAX_SIZE, fmt_str, ap);
+    va_end (ap);
+    if (trace_type == TRACE_TYPE_ERROR)
+        android_log_type = ANDROID_LOG_ERROR;
+    __android_log_write (android_log_type, LOGMSG_TAG_NAME, buffer);
+}
+
+
+void LogMsg_0 (UINT32 maskTraceSet, const char *p_str)
+{
+    LogMsg (maskTraceSet, p_str);
+}
+
+
+void LogMsg_1 (UINT32 maskTraceSet, const char *fmt_str, UINT32 p1)
+{
+    LogMsg (maskTraceSet, fmt_str, p1);
+}
+
+
+void LogMsg_2 (UINT32 maskTraceSet, const char *fmt_str, UINT32 p1, UINT32 p2)
+{
+    LogMsg (maskTraceSet, fmt_str, p1, p2);
+}
+
+
+void LogMsg_3 (UINT32 maskTraceSet, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3)
+{
+    LogMsg (maskTraceSet, fmt_str, p1, p2, p3);
+}
+
+
+void LogMsg_4 (UINT32 maskTraceSet, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3, UINT32 p4)
+{
+    LogMsg (maskTraceSet, fmt_str, p1, p2, p3, p4);
+}
+
+void LogMsg_5 (UINT32 maskTraceSet, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3, UINT32 p4, UINT32 p5)
+{
+    LogMsg (maskTraceSet, fmt_str, p1, p2, p3, p4, p5);
+}
+
+
+void LogMsg_6 (UINT32 maskTraceSet, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3, UINT32 p4, UINT32 p5, UINT32 p6)
+{
+    LogMsg (maskTraceSet, fmt_str, p1, p2, p3, p4, p5, p6);
+}
diff --git a/src/adaptation/config.cpp b/src/adaptation/config.cpp
index b6cf681..7e96e82 100644
--- a/src/adaptation/config.cpp
+++ b/src/adaptation/config.cpp
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2013-2014 NXP Semiconductors
+ *
+ *  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 "OverrideLog.h"
 #include "config.h"
 #include <stdio.h>
@@ -748,4 +767,3 @@
     strPath += extra_config_ext;
     CNfcConfig::GetInstance().readConfig(strPath.c_str(), false);
 }
-
diff --git a/src/adaptation/libmain.c b/src/adaptation/libmain.c
index 92b24be..93b4942 100644
--- a/src/adaptation/libmain.c
+++ b/src/adaptation/libmain.c
@@ -16,9 +16,9 @@
  *
  ******************************************************************************/
 #include "OverrideLog.h"
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <malloc.h>
 #include <fcntl.h>
 #include <errno.h>
 #include "buildcfg.h"
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "nfc_hal_target.h"
 #include "nfc_hal_nv_co.h"
-#include "nfa_nv_ci.h"
 #include "CrcChecksum.h"
 extern char bcm_nfc_location[];
 static const char* sNfaStorageBin = "/nfaStorage.bin";
@@ -279,4 +278,3 @@
     if (isValid == FALSE)
         delete_stack_non_volatile_store (TRUE);
 }
-
diff --git a/src/gki/common/gki.h b/src/gki/common/gki.h
index f1539f1..bff6d95 100644
--- a/src/gki/common/gki.h
+++ b/src/gki/common/gki.h
@@ -516,4 +516,3 @@
 
 
 #endif
-
diff --git a/src/gki/common/gki_buffer.c b/src/gki/common/gki_buffer.c
index 555bc4b..edf353f 100644
--- a/src/gki/common/gki_buffer.c
+++ b/src/gki/common/gki_buffer.c
@@ -1556,4 +1556,3 @@
 
     return ((Q->cur_cnt * 100) / Q->total);
 }
-
diff --git a/src/gki/common/gki_common.h b/src/gki/common/gki_common.h
index 2bd9f8f..afb27d4 100644
--- a/src/gki/common/gki_common.h
+++ b/src/gki/common/gki_common.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 GKI_COMMON_H
 #define GKI_COMMON_H
 
@@ -22,7 +41,7 @@
 #include "dyn_mem.h"
 
 #ifndef GKI_DEBUG
-#define GKI_DEBUG	FALSE
+#define GKI_DEBUG   FALSE
 #endif
 
 /* Task States: (For OSRdyTbl) */
@@ -90,7 +109,11 @@
 
 /* Buffer related defines
 */
+#if(NXP_EXTNS == TRUE)
+#define ALIGN_POOL(pl_size)  ( (((pl_size) + (sizeof(UINT32)-1)) / sizeof(UINT32)) * sizeof(UINT32))
+#else
 #define ALIGN_POOL(pl_size)  ( (((pl_size) + 3) / sizeof(UINT32)) * sizeof(UINT32))
+#endif
 #define BUFFER_HDR_SIZE     (sizeof(BUFFER_HDR_T))                  /* Offset past header */
 #define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(UINT32)) /* Header + Magic Number */
 #define MAX_USER_BUF_SIZE   ((UINT16)0xffff - BUFFER_PADDING_SIZE)  /* pool size must allow for header */
@@ -359,8 +382,8 @@
 extern void      gki_adjust_timer_count (INT32);
 
 extern void    OSStartRdy(void);
-extern void	   OSCtxSw(void);
-extern void	   OSIntCtxSw(void);
+extern void    OSCtxSw(void);
+extern void    OSIntCtxSw(void);
 extern void    OSSched(void);
 extern void    OSIntEnter(void);
 extern void    OSIntExit(void);
diff --git a/src/gki/common/gki_debug.c b/src/gki/common/gki_debug.c
index 481ba16..5e95314 100644
--- a/src/gki/common/gki_debug.c
+++ b/src/gki/common/gki_debug.c
@@ -135,7 +135,7 @@
 void GKI_print_task(void)
 {
 #ifdef _BT_WIN32
-	GKI_TRACE_0("Service not available under insight");
+    GKI_TRACE_0("Service not available under insight");
 #else
     UINT8 TaskId;
 
diff --git a/src/gki/common/gki_inet.h b/src/gki/common/gki_inet.h
index 569c4fd..e99b38c 100644
--- a/src/gki/common/gki_inet.h
+++ b/src/gki/common/gki_inet.h
@@ -23,8 +23,8 @@
 #define htons   ntohs
 #define htonl   ntohl
 
-#define htonets	nettohs
-#define htonetl	nettohl
+#define htonets nettohs
+#define htonetl nettohl
 
 #if BIG_ENDIAN == TRUE
 #define ntohs(n) (n)
@@ -44,4 +44,3 @@
 #endif
 
 #endif /* GKI_INET_H */
-
diff --git a/src/gki/ulinux/data_types.h b/src/gki/ulinux/data_types.h
index 27ae561..e230a47 100644
--- a/src/gki/ulinux/data_types.h
+++ b/src/gki/ulinux/data_types.h
@@ -68,4 +68,3 @@
 #define BCM_VSPRINTF_S(x1,x2,x3,x4) vsprintf((x1),(x3),(x4))
 
 #endif
-
diff --git a/src/gki/ulinux/gki_int.h b/src/gki/ulinux/gki_int.h
index c59ac32..6d419a2 100644
--- a/src/gki/ulinux/gki_int.h
+++ b/src/gki/ulinux/gki_int.h
@@ -19,6 +19,7 @@
 #define GKI_INT_H
 
 #include "gki_common.h"
+#include <stdlib.h>
 #include <pthread.h>
 
 /**********************************************************************
@@ -76,4 +77,3 @@
 #endif
 
 #endif
-
diff --git a/src/gki/ulinux/gki_ulinux.c b/src/gki/ulinux/gki_ulinux.c
index 3a377bf..e1a7a37 100644
--- a/src/gki/ulinux/gki_ulinux.c
+++ b/src/gki/ulinux/gki_ulinux.c
@@ -15,7 +15,6 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-#include <malloc.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <errno.h>
@@ -84,7 +83,7 @@
     UINT8 task_id;          /* GKI task id */
     TASKPTR task_entry;     /* Task entry function*/
     UINT32 params;          /* Extra params to pass to task entry function */
-    pthread_cond_t* pCond;	/* for android*/
+    pthread_cond_t* pCond;  /* for android*/
     pthread_mutex_t* pMutex;  /* for android*/
 } gki_pthread_info_t;
 gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS];
@@ -173,6 +172,9 @@
     p_os->no_timer_suspend = GKI_TIMER_TICK_RUN_COND;
     pthread_mutex_init(&p_os->gki_timer_mutex, NULL);
     pthread_cond_init(&p_os->gki_timer_cond, NULL);
+#if (NXP_EXTNS == TRUE)
+    pthread_mutexattr_destroy(&attr);
+#endif
 }
 
 
@@ -265,7 +267,10 @@
               &attr1,
               (void *)gki_task_entry,
               &gki_pthread_info[task_id]);
-
+#if (NXP_EXTNS == TRUE)
+    pthread_attr_destroy(&attr1);
+    pthread_condattr_destroy(&attr);
+#endif
     if (ret != 0)
     {
          GKI_TRACE_2("pthread_create failed(%d), %s!", ret, taskname);
@@ -493,7 +498,9 @@
     struct timespec delay;
     int err = 0;
     volatile int * p_run_cond = &gki_cb.os.no_timer_suspend;
-
+#if (NXP_EXTNS == TRUE)
+    int ret = 0;
+#endif
 #ifndef GKI_NO_TICK_STOP
     /* register start stop function which disable timer loop in GKI_run() when no timers are
      * in any GKI/BTA/BTU this should save power when BTLD is idle! */
@@ -509,10 +516,19 @@
 
     pthread_attr_init(&timer_attr);
     pthread_attr_setdetachstate(&timer_attr, PTHREAD_CREATE_DETACHED);
+#if (NXP_EXTNS == TRUE)
+    ret = pthread_create( &timer_thread_id,
+            &timer_attr,
+            timer_thread,
+            NULL);
+    pthread_attr_destroy(&timer_attr);
+    if (ret != 0)
+#else
     if (pthread_create( &timer_thread_id,
               &timer_attr,
               timer_thread,
               NULL) != 0 )
+#endif
     {
         GKI_TRACE_0("GKI_run: pthread_create failed to create timer_thread!");
         return GKI_FAILURE;
@@ -927,7 +943,7 @@
 {
     GKI_TRACE_0("GKI_enable");
     pthread_mutex_unlock(&gki_cb.os.GKI_mutex);
-/* 	pthread_mutex_xx is nesting save, no need for this: already_disabled = 0; */
+/*  pthread_mutex_xx is nesting save, no need for this: already_disabled = 0; */
     GKI_TRACE_0("Leaving GKI_enable");
     return;
 }
@@ -947,9 +963,9 @@
 {
     //GKI_TRACE_0("GKI_disable");
 
-/*	pthread_mutex_xx is nesting save, no need for this: if (!already_disabled) {
+/*  pthread_mutex_xx is nesting save, no need for this: if (!already_disabled) {
     already_disabled = 1; */
-    		pthread_mutex_lock(&gki_cb.os.GKI_mutex);
+            pthread_mutex_lock(&gki_cb.os.GKI_mutex);
 /*  } */
     //GKI_TRACE_0("Leaving GKI_disable");
     return;
@@ -1124,7 +1140,7 @@
 void GKI_os_free (void *p_mem)
 {
     if(p_mem != NULL)
-		free(p_mem);
+        free(p_mem);
     return;
 }
 
@@ -1209,7 +1225,7 @@
 
     GKI_enable();
 
-	//GKI_send_event(task_id, EVENT_MASK(GKI_SHUTDOWN_EVT));
+    //GKI_send_event(task_id, EVENT_MASK(GKI_SHUTDOWN_EVT));
 
     GKI_TRACE_1("GKI_exit_task %d done", task_id);
     return;
@@ -1290,5 +1306,3 @@
     for (xx = 0; xx < len; xx++)
         *pd++ = *ps++;
 }
-
-
diff --git a/src/hal/include/nci_defs.h b/src/hal/include/nci_defs.h
index 2ff50a7..e8c09a0 100644
--- a/src/hal/include/nci_defs.h
+++ b/src/hal/include/nci_defs.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -223,7 +241,6 @@
 #define NCI_MSG_RF_EE_ACTION            9
 #define NCI_MSG_RF_EE_DISCOVERY_REQ     10
 #define NCI_MSG_RF_PARAMETER_UPDATE     11
-
 /**********************************************
  * NFCEE MANAGEMENT Group Opcode - 2
  **********************************************/
@@ -240,8 +257,7 @@
 #define NCI_CORE_PARAM_SIZE_RESET       0x01
 #define NCI_CORE_PARAM_SIZE_RESET_RSP   0x03
 #define NCI_CORE_PARAM_SIZE_RESET_NTF   0x02
-
-#define NCI_CORE_PARAM_SIZE_INIT        0x00 /* no payload */
+#define NCI_CORE_PARAM_SIZE_INIT        0x00
 #define NCI_CORE_PARAM_SIZE_INIT_RSP    0x11
 #define NCI_CORE_INIT_RSP_OFFSET_NUM_INTF   0x05
 
@@ -351,8 +367,20 @@
 #define NCI_INTERFACE_FRAME             1
 #define NCI_INTERFACE_ISO_DEP           2
 #define NCI_INTERFACE_NFC_DEP           3
+
 #define NCI_INTERFACE_MAX               NCI_INTERFACE_NFC_DEP
+
 #define NCI_INTERFACE_FIRST_VS          0x80
+#if (NXP_EXTNS == TRUE)
+#define NCI_INTERFACE_MIFARE            0x80
+#if (NFC_NXP_CHIP_TYPE != PN547C2)
+#define NCI_INTERFACE_UICC_DIRECT       0x82
+#define NCI_INTERFACE_ESE_DIRECT        0x83
+#else
+#define NCI_INTERFACE_UICC_DIRECT       0x81
+#define NCI_INTERFACE_ESE_DIRECT        0x82
+#endif
+#endif
 typedef UINT8 tNCI_INTF_TYPE;
 
 /**********************************************
@@ -377,23 +405,63 @@
 #define NCI_PROTOCOL_T3T                0x03
 #define NCI_PROTOCOL_ISO_DEP            0x04
 #define NCI_PROTOCOL_NFC_DEP            0x05
+#if (NXP_EXTNS == TRUE)
+#define NCI_PROTOCOL_ISO7816            0xA0
+#endif
 /**********************************************
  * Proprietary Protocols
  **********************************************/
+#if (NXP_EXTNS == TRUE)
+#ifndef NCI_PROTOCOL_ISO7816
+#define NCI_PROTOCOL_ISO7816             0xA0
+#endif
+#ifndef NCI_PROTOCOL_MIFARE
+#define NCI_PROTOCOL_MIFARE             0x80
+#endif
+#ifndef NCI_PROTOCOL_18092_ACTIVE
+#define NCI_PROTOCOL_18092_ACTIVE       0x05
+#endif
+#else
+#ifndef NCI_PROTOCOL_MIFARE
+#define NCI_PROTOCOL_MIFARE             0xFF
+#endif
 #ifndef NCI_PROTOCOL_18092_ACTIVE
 #define NCI_PROTOCOL_18092_ACTIVE       0x80
 #endif
+#endif
+
 #ifndef NCI_PROTOCOL_B_PRIME
 #define NCI_PROTOCOL_B_PRIME            0x81
 #endif
 #ifndef NCI_PROTOCOL_DUAL
 #define NCI_PROTOCOL_DUAL               0x82
 #endif
+#if (NXP_EXTNS == TRUE)
+#ifndef NCI_PROTOCOL_15693
+#define NCI_PROTOCOL_15693              0x06
+#endif
+#else
 #ifndef NCI_PROTOCOL_15693
 #define NCI_PROTOCOL_15693              0x83
 #endif
+#endif
+
+
 #ifndef NCI_PROTOCOL_KOVIO
-#define NCI_PROTOCOL_KOVIO              0x8a
+#if (NXP_EXTNS == TRUE)
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+#define NCI_PROTOCOL_KOVIO              0x81
+#else
+#define NCI_PROTOCOL_KOVIO              0x8A
+#endif
+#else
+#define NCI_PROTOCOL_KOVIO              0x8A
+#endif
+#endif
+#if(NXP_EXTNS == TRUE)
+#ifndef NCI_PROTOCOL_T3BT
+#define NCI_PROTOCOL_T3BT               0x8b
+#endif
 #endif
 
 
@@ -404,7 +472,15 @@
 #define NCI_DISCOVERY_TYPE_POLL_A_ACTIVE        0x03
 #define NCI_DISCOVERY_TYPE_POLL_F_ACTIVE        0x05
 #define NCI_DISCOVERY_TYPE_POLL_B_PRIME         0x74
+#if (NXP_EXTNS == TRUE)
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+#define NCI_DISCOVERY_TYPE_POLL_KOVIO           0x70
+#else
 #define NCI_DISCOVERY_TYPE_POLL_KOVIO           0x77
+#endif
+#else
+#define NCI_DISCOVERY_TYPE_POLL_KOVIO           0x77
+#endif
 #define NCI_DISCOVERY_TYPE_LISTEN_A             0x80
 #define NCI_DISCOVERY_TYPE_LISTEN_B             0x81
 #define NCI_DISCOVERY_TYPE_LISTEN_F             0x82
@@ -435,6 +511,10 @@
 #define NCI_ROUTE_PWR_STATE_ON          0x01        /* The device is on */
 #define NCI_ROUTE_PWR_STATE_SWITCH_OFF  0x02        /* The device is switched off */
 #define NCI_ROUTE_PWR_STATE_BATT_OFF    0x04        /* The device's battery is removed */
+#if(NXP_EXTNS == TRUE)
+#define NCI_ROUTE_PWR_STATE_SCREEN_LOCK 0x40        /* The device is screen lock mode */
+#define NCI_ROUTE_PWR_STATE_SCREEN_OFF  0x80        /* The device is screen off mode */
+#endif
 
 #define NCI_NFCEE_TAG_HW_ID             0x00       /* Hardware / Registration Identification  */
 #define NCI_NFCEE_TAG_ATR_BYTES         0x01       /* ATR Bytes  */
@@ -448,6 +528,9 @@
 
 /* NCI RF Management Group Params */
 #define NCI_RF_PARAM_SIZE_T3T_POLLING   0x04        /* System Code, RC, TSN */
+#if(NXP_EXTNS == TRUE)
+#define NCI_MSG_RF_WTX                  0x17
+#endif
 
 /**********************************************
  * NCI Parameter IDs
@@ -499,6 +582,7 @@
 #define NCI_PARAM_ID_LF_T3T_MAX         0x52    /* max num of LF_T3T_ID supported by NFCC (1 for now) */
 #define NCI_PARAM_ID_LF_T3T_FLAGS2      0x53
 #define NCI_PARAM_ID_LF_CON_BITR_F      0x54
+#define NCI_PARAM_ID_LF_CON_ADV_FEAT    0x55 //FelicaOnHost
 #define NCI_PARAM_ID_FWI                0x58
 #define NCI_PARAM_ID_LA_HIST_BY         0x59
 #define NCI_PARAM_ID_LB_H_INFO_RSP      0x5A
@@ -547,6 +631,8 @@
 #define NCI_PARAM_LEN_LF_T3T_FLAGS2         2
 #define NCI_PARAM_LEN_LF_T3T_PMM            8
 #define NCI_PARAM_LEN_LF_T3T_ID            10
+#define NCI_PARAM_LEN_LF_CON_ADV_FEAT       1 //FelicaOnHost
+
 
 #define NCI_PARAM_LEN_FWI                   1
 #define NCI_PARAM_LEN_WT                    1
@@ -646,6 +732,9 @@
 } tNCI_RF_PB_PARAMS;
 
 #define NCI_MAX_SENSF_RES_LEN       18
+#if(NXP_EXTNS == TRUE)
+#define NCI_SENSF_RES_OFFSET_NFCID2 1
+#endif
 #define NCI_SENSF_RES_OFFSET_PAD0   8
 #define NCI_SENSF_RES_OFFSET_RD     16
 #define NCI_NFCID2_LEN              8
diff --git a/src/hal/include/nfc_hal_api.h b/src/hal/include/nfc_hal_api.h
index ebd385d..8135a11 100644
--- a/src/hal/include/nfc_hal_api.h
+++ b/src/hal/include/nfc_hal_api.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -57,7 +75,7 @@
 #define HAL_NFC_HCI_UICC0_HOST      0x01
 #define HAL_NFC_HCI_UICC1_HOST      0x02
 #define HAL_NFC_HCI_UICC2_HOST      0x04
-
+#define HAL_NFC_ENABLE_I2C_FRAGMENTATION_EVT        0x07
 /*******************************************************************************
 ** tHAL_NFC_CBACK Definitions
 *******************************************************************************/
@@ -86,6 +104,9 @@
 typedef void (tHAL_API_CLOSE) (void);
 typedef void (tHAL_API_CORE_INITIALIZED) (UINT8 *p_core_init_rsp_params);
 typedef void (tHAL_API_WRITE) (UINT16 data_len, UINT8 *p_data);
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+typedef int (tHAL_API_IOCTL) (long arg, void *p_data);
+#endif
 typedef BOOLEAN (tHAL_API_PREDISCOVER) (void);
 typedef void (tHAL_API_CONTROL_GRANTED) (void);
 typedef void (tHAL_API_POWER_CYCLE) (void);
@@ -119,6 +140,9 @@
     tHAL_API_CLOSE *close;
     tHAL_API_CORE_INITIALIZED *core_initialized;
     tHAL_API_WRITE *write;
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+    tHAL_API_IOCTL *ioctl;
+#endif
     tHAL_API_PREDISCOVER *prediscover;
     tHAL_API_CONTROL_GRANTED *control_granted;
     tHAL_API_POWER_CYCLE *power_cycle;
diff --git a/src/hal/include/nfc_types.h b/src/hal/include/nfc_types.h
index 740544f..02018f6 100644
--- a/src/hal/include/nfc_types.h
+++ b/src/hal/include/nfc_types.h
@@ -144,4 +144,3 @@
 #define TRACE_TYPE_GENERIC          0x00000008
 
 #endif /* NFC_TYPES_H */
-
diff --git a/src/hal/int/nfc_hal_int.h b/src/hal/int/nfc_hal_int.h
index fbde0f9..8269e14 100644
--- a/src/hal/int/nfc_hal_int.h
+++ b/src/hal/int/nfc_hal_int.h
@@ -404,7 +404,6 @@
     BOOLEAN                 b_wait_hcp_conn_create_rsp; /* Waiting for hcp connection create response */
     BOOLEAN                 clear_all_pipes_to_uicc1; /* UICC1 was restarted for patch download */
     BOOLEAN                 update_session_id;        /* Next response from NFCC is to Get Session id cmd */
-    BOOLEAN                 hci_fw_workaround;        /* HAL HCI Workaround need */
     BOOLEAN                 hci_fw_validate_netwk_cmd;/* Flag to indicate if hci network ntf to validate */
     UINT8                   hcp_conn_id;              /* NCI Connection id for HCP */
     UINT8                   dh_session_id[1];         /* Byte 0 of DH Session ID */
diff --git a/src/hal/int/nfc_hal_int_api.h b/src/hal/int/nfc_hal_int_api.h
index 894a2ff..dc694d9 100644
--- a/src/hal/int/nfc_hal_int_api.h
+++ b/src/hal/int/nfc_hal_int_api.h
@@ -296,4 +296,3 @@
 #endif
 
 #endif /* NFC_HAL_INT_API_H */
-
diff --git a/src/hal/int/nfc_hal_nv_ci.h b/src/hal/int/nfc_hal_nv_ci.h
index 1a36b57..d6877f0 100644
--- a/src/hal/int/nfc_hal_nv_ci.h
+++ b/src/hal/int/nfc_hal_nv_ci.h
@@ -90,4 +90,3 @@
 #endif /* NFC_HAL_HCI_INCLUDED */
 
 #endif /* NFC_HAL_NV_CI_H */
-
diff --git a/src/hal/int/nfc_hal_nv_co.h b/src/hal/int/nfc_hal_nv_co.h
index 7ddf46f..8f143fa 100644
--- a/src/hal/int/nfc_hal_nv_co.h
+++ b/src/hal/int/nfc_hal_nv_co.h
@@ -108,5 +108,8 @@
 *******************************************************************************/
 void nfc_hal_nv_co_write (const UINT8 *p_buf, UINT16 nbytes, UINT8 block);
 
+extern void nfa_nv_ci_read (UINT16 num_bytes_read, tNFA_NV_CO_STATUS status, UINT8 block);
+extern void nfa_nv_ci_write (tNFA_NV_CO_STATUS status);
+
 #endif /* NFC_HAL_HCI_INCLUDED */
 #endif /* NFC_HAL_NV_CO_H */
diff --git a/src/include/NfcAdaptation.h b/src/include/NfcAdaptation.h
index bd9afcc..6559f19 100644
--- a/src/include/NfcAdaptation.h
+++ b/src/include/NfcAdaptation.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 <pthread.h>
 #ifndef UINT32
@@ -83,7 +102,12 @@
     static tHAL_NFC_DATA_CBACK* mHalDataCallback;
     static ThreadCondVar mHalOpenCompletedEvent;
     static ThreadCondVar mHalCloseCompletedEvent;
-
+#if(NXP_EXTNS == TRUE)
+    pthread_t mThreadId;
+    static ThreadCondVar mHalCoreResetCompletedEvent;
+    static ThreadCondVar mHalCoreInitCompletedEvent;
+    static ThreadCondVar mHalInitCompletedEvent;
+#endif
     static UINT32 NFCA_TASK (UINT32 arg);
     static UINT32 Thread (UINT32 arg);
     void InitializeHalDeviceContext ();
@@ -96,6 +120,9 @@
     static void HalClose ();
     static void HalCoreInitialized (UINT8* p_core_init_rsp_params);
     static void HalWrite (UINT16 data_len, UINT8* p_data);
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+    static int HalIoctl (long arg, void* p_data);
+#endif
     static BOOLEAN HalPrediscover ();
     static void HalControlGranted ();
     static void HalPowerCycle ();
@@ -103,4 +130,3 @@
     static void HalDownloadFirmwareCallback (nfc_event_t event, nfc_status_t event_status);
     static void HalDownloadFirmwareDataCallback (uint16_t data_len, uint8_t* p_data);
 };
-
diff --git a/src/include/OverrideLog.h b/src/include/OverrideLog.h
index 42905ce..b698c59 100644
--- a/src/include/OverrideLog.h
+++ b/src/include/OverrideLog.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  Override the Android logging macro(s) from
@@ -43,6 +61,10 @@
 extern unsigned char appl_trace_level;
 extern UINT32 ScrProtocolTraceFlag;
 
+#if(NXP_EXTNS == TRUE)
+extern unsigned char appl_dta_mode_flag; //defined for run time DTA mode selection
+#endif
+
 
 /*******************************************************************************
 **
@@ -64,7 +86,18 @@
 unsigned char initializeGlobalAppLogLevel ();
 UINT32 initializeProtocolLogLevel ();
 
-
+#if (NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function:        initializeGlobalDtaMode
+**
+** Description:     Initialize and get global DTA mode from .conf
+**
+** Returns:         none:
+**
+*******************************************************************************/
+void initializeGlobalAppDtaMode ();
+#endif
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/include/android_logmsg.h b/src/include/android_logmsg.h
new file mode 100644
index 0000000..c18b4ad
--- /dev/null
+++ b/src/include/android_logmsg.h
@@ -0,0 +1,83 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2011-2012 Broadcom Corporation
+ *
+ *  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.
+ *
+ ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
+ /* Decode NFC packets and print them to ADB log.
+ * If protocol decoder is not present, then decode packets into hex numbers.
+ ******************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#include "data_types.h"
+
+
+#define DISP_NCI    ProtoDispAdapterDisplayNciPacket
+void ProtoDispAdapterDisplayNciPacket (UINT8* nciPacket, UINT16 nciPacketLen, BOOLEAN is_recv);
+void ProtoDispAdapterUseRawOutput (BOOLEAN isUseRaw);
+void ScrLog (UINT32 trace_set_mask, const char* fmt_str, ...);
+void LogMsg (UINT32 trace_set_mask, const char *fmt_str, ...);
+void LogMsg_0 (UINT32 trace_set_mask, const char *p_str);
+void LogMsg_1 (UINT32 trace_set_mask, const char *fmt_str, UINT32 p1);
+void LogMsg_2 (UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2);
+void LogMsg_3 (UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3);
+void LogMsg_4 (UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3, UINT32 p4);
+void LogMsg_5 (UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3, UINT32 p4, UINT32 p5);
+void LogMsg_6 (UINT32 trace_set_mask, const char *fmt_str, UINT32 p1, UINT32 p2, UINT32 p3, UINT32 p4, UINT32 p5, UINT32 p6);
+UINT8* scru_dump_hex (UINT8* p, char* pTitle, UINT32 len, UINT32 layer, UINT32 type);
+void BTDISP_LOCK_LOG();
+void BTDISP_UNLOCK_LOG();
+void BTDISP_INIT_LOCK();
+void BTDISP_UNINIT_LOCK();
+void DispHciCmd (BT_HDR* p_buf);
+void DispHciEvt (BT_HDR* p_buf);
+void DispLLCP (BT_HDR *p_buf, BOOLEAN is_recv);
+void DispHcp (UINT8 *data, UINT16 len, BOOLEAN is_recv);
+void DispSNEP (UINT8 local_sap, UINT8 remote_sap, BT_HDR *p_buf, BOOLEAN is_first, BOOLEAN is_rx);
+void DispCHO (UINT8 *pMsg, UINT32 MsgLen, BOOLEAN is_rx);
+void DispT3TagMessage(BT_HDR *p_msg, BOOLEAN is_rx);
+void DispRWT4Tags (BT_HDR *p_buf, BOOLEAN is_rx);
+void DispCET4Tags (BT_HDR *p_buf, BOOLEAN is_rx);
+void DispRWI93Tag (BT_HDR *p_buf, BOOLEAN is_rx, UINT8 command_to_respond);
+void DispNDEFMsg (UINT8 *pMsg, UINT32 MsgLen, BOOLEAN is_recv);
+
+
+
+#ifdef __cplusplus
+};
+#endif
diff --git a/src/include/bt_target.h b/src/include/bt_target.h
index f751548..769bcee 100644
--- a/src/include/bt_target.h
+++ b/src/include/bt_target.h
@@ -3979,4 +3979,3 @@
 #include "bt_trace.h"
 
 #endif /* BT_TARGET_H */
-
diff --git a/src/include/bt_trace.h b/src/include/bt_trace.h
index d9c58dd..1584983 100644
--- a/src/include/bt_trace.h
+++ b/src/include/bt_trace.h
@@ -132,7 +132,7 @@
 #define BTTRC_TYPE_DBG                     0xA0
 #else
 #define BTTRC_TYPE_ERROR                   0x01       /* Traces for error situation */
-#define BTTRC_TYPE_WARNING	               0x02       /* Traces for warning situation */
+#define BTTRC_TYPE_WARNING                 0x02       /* Traces for warning situation */
 #define BTTRC_TYPE_API                     0x04       /* Traces for API */
 #define BTTRC_TYPE_EVENT                   0x08       /* Traces for EVENT */
 #define BTTRC_TYPE_ACTION                  0x10       /* Traces for Action functions */
@@ -4833,5 +4833,3 @@
 
 
 #endif /* BT_TRACE_H */
-
-
diff --git a/src/include/bt_types.h b/src/include/bt_types.h
index 0a42c77..ec12331 100644
--- a/src/include/bt_types.h
+++ b/src/include/bt_types.h
@@ -443,8 +443,8 @@
 
 /* We will not allocate a PSM in the reserved range to 3rd party apps
 */
-#define BRCM_RESERVED_PSM_START	    0x5AE1
-#define BRCM_RESERVED_PSM_END	    0x5AFF
+#define BRCM_RESERVED_PSM_START     0x5AE1
+#define BRCM_RESERVED_PSM_END       0x5AFF
 
 #define BRCM_UTILITY_SERVICE_PSM    0x5AE1
 #define BRCM_MATCHER_PSM            0x5AE3
@@ -485,7 +485,7 @@
 #define AMP_USE_AMP_ONLY                       6   /* Only use AMP, never use BR/EDR                               */
 #define AMP_USE_AMP_MAX_DEF            AMP_USE_AMP_ONLY /* Maximum enum defined for AMP Criteria                        */
 
-#define	AMP_AUTOSWITCH_ALLOWED 		           0x80000000  /* flag to indicate that this connection is auto-switch ready */
+#define AMP_AUTOSWITCH_ALLOWED                 0x80000000  /* flag to indicate that this connection is auto-switch ready */
 #define AMP_USE_CURRENT_CRITERIA               0xFFFFFFFF  /* Flag if previous criteria was to be still used        */
 
 typedef UINT32 tAMP_CRITERIA;
@@ -613,7 +613,7 @@
 #define TRACE_ORG_USER_SCR          0x00000800
 #define TRACE_ORG_TESTER            0x00000900
 #define TRACE_ORG_MAX_NUM           10          /* 32-bit mask; must be < 32 */
-#define TRACE_LITE_ORG_MAX_NUM		6
+#define TRACE_LITE_ORG_MAX_NUM      6
 #define TRACE_ORG_ALL               0x03ff
 #define TRACE_ORG_RPC_TRANS         0x04
 
@@ -707,4 +707,3 @@
 typedef void (BT_LOG_FUNC) (int trace_type, const char *fmt_str, ...);
 
 #endif
-
diff --git a/src/include/buildcfg.h b/src/include/buildcfg.h
index fcd2396..2687449 100644
--- a/src/include/buildcfg.h
+++ b/src/include/buildcfg.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 __BUILDCFG_H
 #define __BUILDCFG_H
 #include <string.h>
@@ -37,7 +56,11 @@
 
 #define GKI_BUF1_MAX            0
 // 2 is in use
+#if (NXP_EXTNS == TRUE)
+#define GKI_BUF3_MAX            70
+#else
 #define GKI_BUF3_MAX            30
+#endif
 #define GKI_BUF4_SIZE           2400
 #define GKI_BUF4_MAX            30
 #define GKI_BUF5_MAX            0
@@ -46,15 +69,23 @@
 #define GKI_BUF8_MAX            0
 
 #define GKI_BUF2_SIZE           660
+#if (NXP_EXTNS == TRUE)
+#define GKI_BUF2_MAX            70
+#else
 #define GKI_BUF2_MAX            50
+#endif
 
 #define GKI_BUF0_SIZE           268
 #define GKI_BUF0_MAX            40
 
 #define NCI_BUF_POOL_ID         GKI_POOL_ID_0
+#if (NXP_EXTNS == TRUE)
+#define GKI_NUM_FIXED_BUF_POOLS 9
+#else
 #define GKI_NUM_FIXED_BUF_POOLS 4
+#endif
 
-#ifdef	__cplusplus
+#ifdef  __cplusplus
 extern "C" {
 #endif
 // +++from bte.h...
@@ -64,7 +95,7 @@
                             /* J3   J4              SW3-3   SW3-2   SW3-1   */
                             /* -------------------------------------------- */
     BTE_MODE_SERIAL_APP,    /* OUT  OUT             OFF     OFF     OFF     Sample serial port application      */
-    BTE_MODE_APPL,    	    /* IN   OUT             OFF     OFF     ON      Target used with Tester through RPC */
+    BTE_MODE_APPL,          /* IN   OUT             OFF     OFF     ON      Target used with Tester through RPC */
     BTE_MODE_RESERVED,      /* OUT  IN              OFF     ON      OFF     Reserved                            */
     BTE_MODE_SAMPLE_APPS,   /* IN   IN              OFF     ON      ON      Sample applications (ICP/HSP)       */
     BTE_MODE_DONGLE,        /* not yet supported    ON      OFF     OFF     Dongle mode                         */
@@ -100,7 +131,7 @@
 
 #endif
 
-#ifdef	__cplusplus
+#ifdef  __cplusplus
 };
 #endif
 #endif
diff --git a/src/include/buildcfg_hal.h b/src/include/buildcfg_hal.h
index a491bac..d43fb0c 100644
--- a/src/include/buildcfg_hal.h
+++ b/src/include/buildcfg_hal.h
@@ -22,4 +22,3 @@
  *
  ******************************************************************************/
 #pragma once
-
diff --git a/src/include/config.h b/src/include/config.h
index 7f978aa..1b12ddb 100644
--- a/src/include/config.h
+++ b/src/include/config.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 __CONFIG_H
 #define __CONFIG_H
 
@@ -35,12 +54,17 @@
 #define NAME_APPL_TRACE_LEVEL           "APPL_TRACE_LEVEL"
 #define NAME_USE_RAW_NCI_TRACE          "USE_RAW_NCI_TRACE"
 #define NAME_LOGCAT_FILTER              "LOGCAT_FILTER"
+#if(NXP_EXTNS == TRUE)
+#define NAME_APPL_DTA_MODE              "APPL_DTA_MODE"
+#endif
 #define NAME_LPTD_CFG                   "LPTD_CFG"
 #define NAME_SCREEN_OFF_POWER_STATE     "SCREEN_OFF_POWER_STATE"
 #define NAME_PREINIT_DSP_CFG            "PREINIT_DSP_CFG"
 #define NAME_DTA_START_CFG              "DTA_START_CFG"
+#if(NXP_EXTNS != TRUE)
 #define NAME_TRANSPORT_DRIVER           "TRANSPORT_DRIVER"
 #define NAME_POWER_CONTROL_DRIVER       "POWER_CONTROL_DRIVER"
+#endif
 #define NAME_PROTOCOL_TRACE_LEVEL       "PROTOCOL_TRACE_LEVEL"
 #define NAME_UART_PORT                  "UART_PORT"
 #define NAME_UART_BAUD                  "UART_BAUD"
@@ -65,6 +89,17 @@
 #define NAME_NFA_DTA_START_UP_VSC_CFG   "NFA_DTA_START_UP_VSC_CFG"
 #define NAME_UICC_LISTEN_TECH_MASK      "UICC_LISTEN_TECH_MASK"
 #define NAME_UICC_LISTEN_TECH_EX_MASK   "UICC_LISTEN_TECH_EXCLUDE_MASK"
+#define NAME_HOST_LISTEN_ENABLE         "HOST_LISTEN_ENABLE"
+#if (NXP_EXTNS == TRUE)
+#define NAME_DEFAULT_AID_ROUTE          "DEFAULT_AID_ROUTE"
+#define NAME_DEFAULT_DESFIRE_ROUTE      "DEFAULT_DESFIRE_ROUTE"
+#define NAME_DEFAULT_MIFARE_CLT_ROUTE   "DEFAULT_MIFARE_CLT_ROUTE"
+#define NAME_NFA_DM_DISC_NTF_TIMEOUT    "NFA_DM_DISC_NTF_TIMEOUT"
+#define NAME_NXP_FWD_FUNCTIONALITY_ENABLE   "NXP_FWD_FUNCTIONALITY_ENABLE"
+#endif
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+#define NAME_NXP_PRFD_TECH_SE            "NXP_PRFD_TECH_SE"
+#endif
 #define NAME_SNOOZE_MODE_CFG            "SNOOZE_MODE_CFG"
 #define NAME_NFA_DM_DISC_DURATION_POLL  "NFA_DM_DISC_DURATION_POLL"
 #define NAME_SPD_DEBUG                  "SPD_DEBUG"
@@ -88,6 +123,11 @@
 #define NAME_POWER_OFF_MODE             "POWER_OFF_MODE"
 #define NAME_GLOBAL_RESET               "DO_GLOBAL_RESET"
 #define NAME_NCI_HAL_MODULE             "NCI_HAL_MODULE"
+#define NAME_NXP_NFCC_STANDBY_TIMEOUT   "NXP_NFCC_STANDBY_TIMEOUT"
+#define NAME_NXP_CP_TIMEOUT             "NXP_CP_TIMEOUT"
+#if(NFC_NXP_CHIP_TYPE == PN547C2)
+#define NAME_NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE   "NXP_CORE_SCRN_OFF_AUTONOMOUS_ENABLE"
+#endif
 
 #define                     LPTD_PARAM_LEN (40)
 
diff --git a/src/include/dyn_mem.h b/src/include/dyn_mem.h
index 2a478b2..9e605d5 100644
--- a/src/include/dyn_mem.h
+++ b/src/include/dyn_mem.h
@@ -192,4 +192,3 @@
 #endif
 
 #endif  /* #ifdef DYN_MEM_H */
-
diff --git a/src/include/gki_target.h b/src/include/gki_target.h
index 602f37a..4cc3742 100644
--- a/src/include/gki_target.h
+++ b/src/include/gki_target.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 GKI_TARGET_H
 #define GKI_TARGET_H
 
@@ -195,8 +214,12 @@
 
 /* The size of the buffers in pool 3. */
 #ifndef GKI_BUF3_SIZE
+#if(NXP_EXTNS == TRUE)
+#define GKI_BUF3_SIZE               (0xFFB0)
+#else
 #define GKI_BUF3_SIZE               2500
 #endif
+#endif
 
 /* The number of buffers in buffer pool 3. */
 #ifndef GKI_BUF3_MAX
diff --git a/src/include/hcidefs.h b/src/include/hcidefs.h
index 163d25e..1cb8e49 100644
--- a/src/include/hcidefs.h
+++ b/src/include/hcidefs.h
@@ -2604,4 +2604,3 @@
 #endif
 
 #endif
-
diff --git a/src/include/nfc_target.h b/src/include/nfc_target.h
index dc7dd70..49790fd 100644
--- a/src/include/nfc_target.h
+++ b/src/include/nfc_target.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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 NFC_TARGET_H
 #define NFC_TARGET_H
 
@@ -285,7 +303,7 @@
 
 /* RW Type 3 Tag timeout for each API call, in ms */
 #ifndef RW_T3T_TOUT_RESP
-#define RW_T3T_TOUT_RESP            100         /* NFC-Android will use 100 instead of 75 for T3t presence-check */
+#define RW_T3T_TOUT_RESP            500         /* increased T3t presence-check time from 100 to 500, as Felica Secure mode commands require longer time to process */
 #endif
 
 /* CE Type 3 Tag maximum response timeout index (for check and update, used in SENSF_RES) */
@@ -542,7 +560,14 @@
 
 /* Timeout for waiting for the response to HCP Command packet */
 #ifndef NFA_HCI_RESPONSE_TIMEOUT
-#define NFA_HCI_RESPONSE_TIMEOUT    1000
+#if(NXP_EXTNS == TRUE)
+/*
+ * NOTE : HCI Response will be received only after Credit Ntf is received.
+ *        If credit Ntf timeout is triggered then response timer will also be stopped.
+ *        So NFA_HCI_RESPONSE_TIMEOUT should always NFC_NCI_WAIT_DATA_NTF_TOUT + 1s
+ * */
+#define NFA_HCI_RESPONSE_TIMEOUT    3000
+#endif
 #endif
 
 /* Default poll duration (may be over-ridden using NFA_SetRfDiscoveryDuration) */
@@ -574,6 +599,9 @@
 #ifndef NFA_DM_MAX_PRESENCE_CHECK_TIMEOUT
 #define NFA_DM_MAX_PRESENCE_CHECK_TIMEOUT           500
 #endif
+#if(NXP_EXTNS == TRUE)
+#define NFA_DM_ISO_15693_MAX_PRESENCE_CHECK_TIMEOUT           500
+#endif
 
 /* Default delay to auto presence check after sending raw frame */
 #ifndef NFA_DM_DEFAULT_PRESENCE_CHECK_START_DELAY
@@ -593,8 +621,12 @@
 /* Maximum number of listen entries configured/registered with NFA_CeConfigureUiccListenTech, */
 /* NFA_CeRegisterFelicaSystemCodeOnDH, or NFA_CeRegisterT4tAidOnDH                            */
 #ifndef NFA_CE_LISTEN_INFO_MAX
+#if(NXP_EXTNS == TRUE)
+#define NFA_CE_LISTEN_INFO_MAX        10
+#else
 #define NFA_CE_LISTEN_INFO_MAX        5
 #endif
+#endif
 
 #ifndef NFA_CHO_INCLUDED
 #define NFA_CHO_INCLUDED            FALSE /* Anddroid must use FALSE to exclude CHO */
@@ -660,12 +692,24 @@
 
 /* Max number of NFCEE supported */
 #ifndef NFA_EE_MAX_EE_SUPPORTED
+#if(NXP_EXTNS == TRUE)
+#define NFA_EE_MAX_EE_SUPPORTED         3 //Wait for UICC Init complete.
+#else
 #define NFA_EE_MAX_EE_SUPPORTED         4           /* Modified for NFC-A until we add dynamic support */
 #endif
+#endif
 
 /* Maximum number of AID entries per target_handle  */
 #ifndef NFA_EE_MAX_AID_ENTRIES
-#define NFA_EE_MAX_AID_ENTRIES      (32)
+#if(NXP_EXTNS == TRUE)
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+#define NFA_EE_MAX_AID_ENTRIES      (50)
+#else
+#define NFA_EE_MAX_AID_ENTRIES      (20)
+#endif
+#else
+#define NFA_EE_MAX_AID_ENTRIES      (10)
+#endif
 #endif
 
 /* Maximum number of callback functions can be registered through NFA_EeRegister() */
@@ -708,6 +752,3 @@
 
 
 #endif /* NFC_TARGET_H */
-
-
-
diff --git a/src/nfa/ce/nfa_ce_act.c b/src/nfa/ce/nfa_ce_act.c
index 2e8ca56..d5941eb 100644
--- a/src/nfa/ce/nfa_ce_act.c
+++ b/src/nfa/ce/nfa_ce_act.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -254,6 +272,13 @@
         break;
 
     case NFA_DM_RF_DISC_ACTIVATED_EVT:
+#if (NXP_EXTNS == TRUE)
+        /*
+         *TODO: Handle the Reader over SWP.
+         * Pass this info to JNI as START_READER_EVT.
+         * Handle in nfa_ce_activate_ntf.
+         */
+#endif
         ce_msg.activate_ntf.hdr.event = NFA_CE_ACTIVATE_NTF_EVT;
         ce_msg.activate_ntf.p_activation_params = &p_data->activate;
         nfa_ce_hdl_event ((BT_HDR *) &ce_msg);
@@ -292,7 +317,7 @@
     UINT8 tlv_size;
     UINT16 t3t_flags2_mask = 0xFFFF;        /* Mask of which T3T_IDs are disabled */
     UINT8 t3t_idx = 0;
-
+    UINT8 adv_Feat = 1;
     /* Point to start of tlv buffer */
     p_params = tlv;
 
@@ -319,8 +344,18 @@
 
     UINT8_TO_STREAM (p_params, NFC_PMID_LF_T3T_FLAGS2);      /* type */
     UINT8_TO_STREAM (p_params, NCI_PARAM_LEN_LF_T3T_FLAGS2); /* length */
-    UINT16_TO_STREAM (p_params, t3t_flags2_mask);            /* Mask of IDs to disable listening */
+#if (NXP_EXTNS == TRUE)
 
+
+//FelicaOnHost
+    UINT16_TO_BE_STREAM (p_params, t3t_flags2_mask);
+    UINT8_TO_STREAM (p_params, NCI_PARAM_ID_LF_CON_ADV_FEAT);      /* type */
+    UINT8_TO_STREAM (p_params, NCI_PARAM_LEN_LF_CON_ADV_FEAT); /* length */
+    UINT8_TO_STREAM (p_params, adv_Feat);            /* Mask of IDs to disable listening */
+
+#else
+    UINT16_TO_STREAM (p_params, t3t_flags2_mask);            /* Mask of IDs to disable listening */
+#endif
     tlv_size = (UINT8) (p_params-tlv);
     nfa_dm_check_set_config (tlv_size, (UINT8 *)tlv, FALSE);
 }
@@ -432,7 +467,13 @@
                     p_cb->listen_info[listen_info_idx].rf_disc_handle = disc_handle;
             }
 #if (NFC_NFCEE_INCLUDED == TRUE)
-            else if (p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_UICC)
+            else if (p_cb->listen_info[listen_info_idx].flags &
+#if(NXP_EXTNS == TRUE)
+                    (NFA_CE_LISTEN_INFO_UICC | NFA_CE_LISTEN_INFO_ESE)
+#else
+                    NFA_CE_LISTEN_INFO_UICC
+#endif
+                    )
             {
                 listen_mask = 0;
                 if (nfa_ee_is_active (p_cb->listen_info[listen_info_idx].ee_handle))
@@ -453,6 +494,16 @@
                     {
                         listen_mask |= NFA_DM_DISC_MASK_L_B_PRIME;
                     }
+#if(NXP_EXTNS == TRUE)
+                    if (p_cb->listen_info[listen_info_idx].tech_mask & NFA_TECHNOLOGY_MASK_A_ACTIVE)
+                    {
+                        listen_mask |= NFA_DM_DISC_MASK_LAA_NFC_DEP;
+                    }
+                    if (p_cb->listen_info[listen_info_idx].tech_mask & NFA_TECHNOLOGY_MASK_F_ACTIVE)
+                    {
+                        listen_mask |= NFA_DM_DISC_MASK_LFA_NFC_DEP;
+                    }
+#endif
                 }
 
                 if (listen_mask)
@@ -473,8 +524,13 @@
                 }
                 else
                 {
+#if(NXP_EXTNS == TRUE)
+                    NFA_TRACE_ERROR1 ("UICC/ESE[0x%x] is not activated",
+                                       p_cb->listen_info[listen_info_idx].ee_handle);
+#else
                     NFA_TRACE_ERROR1 ("UICC[0x%x] is not activated",
                                        p_cb->listen_info[listen_info_idx].ee_handle);
+#endif
                 }
             }
 #endif
@@ -553,6 +609,14 @@
             conn_evt.status = NFA_STATUS_OK;
             (*p_cb->listen_info[listen_info_idx].p_conn_cback) (NFA_CE_UICC_LISTEN_CONFIGURED_EVT, &conn_evt);
         }
+#if(NXP_EXTNS == TRUE)
+        else if (p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_ESE)
+        {
+            conn_evt.status = NFA_STATUS_OK;
+            (*p_cb->listen_info[listen_info_idx].p_conn_cback) (NFA_CE_ESE_LISTEN_CONFIGURED_EVT, &conn_evt);
+        }
+#endif
+
 #endif
         else
         {
@@ -766,8 +830,30 @@
     /* Store activation parameters */
     memcpy (&p_cb->activation_params, p_activation_params, sizeof (tNFC_ACTIVATE_DEVT));
 
+#if(NXP_EXTNS == TRUE)
+    if (p_cb->activation_params.intf_param.type == NCI_INTERFACE_UICC_DIRECT || p_cb->activation_params.intf_param.type == NCI_INTERFACE_ESE_DIRECT )
+    {
+        memcpy (&(conn_evt.activated.activate_ntf), &p_cb->activation_params, sizeof (tNFC_ACTIVATE_DEVT));
+        for (i=0; i<NFA_CE_LISTEN_INFO_IDX_INVALID; i++)
+        {
+            if (p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_UICC)
+            {
+                listen_info_idx = i;
+                NFA_TRACE_DEBUG1 ("listen_info found for this activation. listen_info_idx=%d", listen_info_idx);
+                /* Get CONN_CBACK for this activation */
+                p_cb->p_active_conn_cback = p_cb->listen_info[listen_info_idx].p_conn_cback;
+                break;
+            }
+        }
+
+        (*p_cb->p_active_conn_cback) (NFA_ACTIVATED_EVT, &conn_evt);
+    }
+    /* Find the listen_info entry corresponding to this activation */
+    else if (p_cb->activation_params.protocol == NFA_PROTOCOL_T3T)
+#else
     /* Find the listen_info entry corresponding to this activation */
     if (p_cb->activation_params.protocol == NFA_PROTOCOL_T3T)
+#endif
     {
         /* Look for T3T entries in listen_info table that match activated system code and NFCID2 */
         for (listen_info_idx=0; listen_info_idx<NFA_CE_LISTEN_INFO_IDX_INVALID; listen_info_idx++)
@@ -790,12 +876,14 @@
                     }
                 }
 
+#if (NXP_EXTNS == FALSE)
                 /* Check if entry is for T3T UICC */
                 if ((p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_UICC) &&
                     (p_cb->listen_info[listen_info_idx].tech_mask & NFA_TECHNOLOGY_MASK_F))
                 {
                     break;
                 }
+#endif
             }
         }
 
@@ -829,7 +917,13 @@
 
 #if (NFC_NFCEE_INCLUDED == TRUE)
                 /* Check if entry is for ISO_DEP UICC */
-                if (p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_UICC)
+                if (p_cb->listen_info[i].flags &
+#if(NXP_EXTNS == TRUE)
+                      (NFA_CE_LISTEN_INFO_UICC | NFA_CE_LISTEN_INFO_ESE)
+#else
+                      NFA_CE_LISTEN_INFO_UICC
+#endif
+                )
                 {
                     if (  (  (p_cb->activation_params.rf_tech_param.mode == NFC_DISCOVERY_TYPE_LISTEN_A)
                            &&(p_cb->listen_info[i].tech_proto_mask & NFA_DM_DISC_MASK_LA_ISO_DEP)  )
@@ -857,7 +951,13 @@
         for (i=0; i<NFA_CE_LISTEN_INFO_IDX_INVALID; i++)
         {
             if (  (p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_IN_USE)
-                &&(p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_UICC))
+                &&(p_cb->listen_info[i].flags &
+#if(NXP_EXTNS == TRUE)
+                        (NFA_CE_LISTEN_INFO_UICC | NFA_CE_LISTEN_INFO_ESE)
+#else
+                        NFA_CE_LISTEN_INFO_UICC
+#endif
+                ))
             {
                 listen_info_idx = i;
                 break;
@@ -865,6 +965,26 @@
         }
     }
 
+#if (NXP_EXTNS == TRUE)
+//FelicaOnHost
+         if ((listen_info_idx == NFA_CE_LISTEN_INFO_IDX_INVALID) && (p_cb->activation_params.protocol == NFA_PROTOCOL_T3T))
+         {
+             for (listen_info_idx=0; listen_info_idx<NFA_CE_LISTEN_INFO_IDX_INVALID; listen_info_idx++)
+             {
+                 /* Look for entries with NFA_PROTOCOL_MASK_T3T */
+                if (p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_IN_USE)
+                    {
+                          if ((p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_UICC) &&
+                             (p_cb->listen_info[listen_info_idx].tech_mask & NFA_TECHNOLOGY_MASK_F))
+                             {
+                                 break;
+                             }
+
+                   }
+             }
+
+         }
+#endif
     /* Check if valid listen_info entry was found */
     if (  (listen_info_idx == NFA_CE_LISTEN_INFO_IDX_INVALID)
         ||((listen_info_idx == NFA_CE_LISTEN_INFO_IDX_NDEF) && !(p_cb->listen_info[NFA_CE_LISTEN_INFO_IDX_NDEF].flags & NFA_CE_LISTEN_INFO_IN_USE)))
@@ -880,7 +1000,13 @@
     p_cb->idx_cur_active = listen_info_idx;
 
     if (  (p_cb->idx_cur_active == NFA_CE_LISTEN_INFO_IDX_NDEF)
-        ||(p_cb->listen_info[p_cb->idx_cur_active].flags & NFA_CE_LISTEN_INFO_UICC))
+        ||(p_cb->listen_info[p_cb->idx_cur_active].flags &
+#if(NXP_EXTNS == TRUE)
+                        (NFA_CE_LISTEN_INFO_UICC | NFA_CE_LISTEN_INFO_ESE)
+#else
+                        NFA_CE_LISTEN_INFO_UICC
+#endif
+        ))
     {
         memcpy (&(conn_evt.activated.activate_ntf), &p_cb->activation_params, sizeof (tNFC_ACTIVATE_DEVT));
 
@@ -966,7 +1092,13 @@
     {
         if (p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_IN_USE)
         {
-            if (  (p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_UICC)
+            if (  (p_cb->listen_info[i].flags &
+#if(NXP_EXTNS == TRUE)
+                        (NFA_CE_LISTEN_INFO_UICC | NFA_CE_LISTEN_INFO_ESE)
+#else
+                        NFA_CE_LISTEN_INFO_UICC
+#endif
+            )
                 &&(i == p_cb->idx_cur_active)  )
             {
                 conn_evt.deactivated.type =  deact_type;
@@ -1169,7 +1301,11 @@
     UINT8 i;
     UINT8 listen_info_idx = NFA_CE_LISTEN_INFO_IDX_INVALID;
 
+#if(NXP_EXTNS == TRUE)
+    NFA_TRACE_DEBUG1 ("Registering UICC/ESE/Felica/Type-4 tag listener. Type=%i", p_ce_msg->reg_listen.listen_type);
+#else
     NFA_TRACE_DEBUG1 ("Registering UICC/Felica/Type-4 tag listener. Type=%i", p_ce_msg->reg_listen.listen_type);
+#endif
 
     /* Look for available entry in listen_info table                                        */
     /* - If registering UICC listen, make sure there isn't another entry for the ee_handle  */
@@ -1187,6 +1323,19 @@
             nfa_dm_conn_cback_event_notify (NFA_CE_UICC_LISTEN_CONFIGURED_EVT, &conn_evt);
             return TRUE;
         }
+#if(NXP_EXTNS == TRUE)
+        else if (  (p_ce_msg->reg_listen.listen_type == NFA_CE_REG_TYPE_ESE)
+            &&(p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_IN_USE)
+            &&(p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_ESE)
+            &&(p_cb->listen_info[i].ee_handle == p_ce_msg->reg_listen.ee_handle)  )
+        {
+
+            NFA_TRACE_ERROR1 ("ESE (0x%x) listening already specified", p_ce_msg->reg_listen.ee_handle);
+            conn_evt.status = NFA_STATUS_FAILED;
+            nfa_dm_conn_cback_event_notify (NFA_CE_ESE_LISTEN_CONFIGURED_EVT, &conn_evt);
+            return TRUE;
+        }
+#endif
         /* If this is a free entry, and we haven't found one yet, remember it */
         else if (  (!(p_cb->listen_info[i].flags & NFA_CE_LISTEN_INFO_IN_USE))
                  &&(listen_info_idx == NFA_CE_LISTEN_INFO_IDX_INVALID)  )
@@ -1205,6 +1354,13 @@
             conn_evt.status = NFA_STATUS_FAILED;
             nfa_dm_conn_cback_event_notify (NFA_CE_UICC_LISTEN_CONFIGURED_EVT, &conn_evt);
         }
+#if(NXP_EXTNS == TRUE)
+        else if (p_ce_msg->reg_listen.listen_type == NFA_CE_REG_TYPE_ESE)
+        {
+            conn_evt.status = NFA_STATUS_FAILED;
+            nfa_dm_conn_cback_event_notify (NFA_CE_ESE_LISTEN_CONFIGURED_EVT, &conn_evt);
+        }
+#endif
         else
         {
             /* Notify application */
@@ -1264,6 +1420,24 @@
 
 #if (NFC_NFCEE_INCLUDED == TRUE)
         case NFA_CE_REG_TYPE_UICC:
+
+#if(NXP_EXTNS == TRUE)
+
+            for (i=1; i<NFA_CE_LISTEN_INFO_MAX; i++)
+            {
+                UINT8 tech = p_cb->listen_info[listen_info_idx].tech_mask &
+                        p_ce_msg->reg_listen.tech_mask;
+                if( (p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_ESE) &&
+                        (tech)
+                       )
+                {
+                    NFA_TRACE_ERROR1 ("NFA_CE: Technology %0x listening already specified for ESE", tech);
+                    conn_evt.status = NFA_STATUS_FAILED;
+                    nfa_dm_conn_cback_event_notify (NFA_CE_UICC_LISTEN_CONFIGURED_EVT, &conn_evt);
+                    return TRUE;
+                }
+            }
+#endif
             p_cb->listen_info[listen_info_idx].flags |= NFA_CE_LISTEN_INFO_UICC;
             p_cb->listen_info[listen_info_idx].p_conn_cback = &nfa_dm_conn_cback_event_notify;
 
@@ -1271,6 +1445,34 @@
             p_cb->listen_info[listen_info_idx].ee_handle = p_ce_msg->reg_listen.ee_handle;
             p_cb->listen_info[listen_info_idx].tech_mask = p_ce_msg->reg_listen.tech_mask;
             break;
+
+#if(NXP_EXTNS == TRUE)
+        case NFA_CE_REG_TYPE_ESE:
+
+            for (i=1; i<NFA_CE_LISTEN_INFO_MAX; i++)
+            {
+                UINT8 tech = p_cb->listen_info[listen_info_idx].tech_mask &
+                        p_ce_msg->reg_listen.tech_mask;
+                if( (p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_UICC) &&
+                        (tech)
+                       )
+                {
+                    NFA_TRACE_ERROR1 ("NFA_CE: Technology %0x listening already specified for UICC", tech);
+                    conn_evt.status = NFA_STATUS_FAILED;
+                    nfa_dm_conn_cback_event_notify (NFA_CE_ESE_LISTEN_CONFIGURED_EVT, &conn_evt);
+                    return TRUE;
+                }
+            }
+
+            p_cb->listen_info[listen_info_idx].flags |= NFA_CE_LISTEN_INFO_ESE;
+            p_cb->listen_info[listen_info_idx].p_conn_cback = &nfa_dm_conn_cback_event_notify;
+
+            /* Store EE handle and Tech */
+            p_cb->listen_info[listen_info_idx].ee_handle = p_ce_msg->reg_listen.ee_handle;
+            p_cb->listen_info[listen_info_idx].tech_mask = p_ce_msg->reg_listen.tech_mask;
+            break;
+#endif
+
 #endif
         }
     }
@@ -1287,6 +1489,12 @@
     {
         (*p_cb->listen_info[listen_info_idx].p_conn_cback) (NFA_CE_UICC_LISTEN_CONFIGURED_EVT, &conn_evt);
     }
+#if(NXP_EXTNS == TRUE)
+    else if (p_ce_msg->reg_listen.listen_type == NFA_CE_REG_TYPE_ESE)
+    {
+        (*p_cb->listen_info[listen_info_idx].p_conn_cback) (NFA_CE_ESE_LISTEN_CONFIGURED_EVT, &conn_evt);
+    }
+#endif
     else
     {
         conn_evt.ce_registered.handle = NFA_HANDLE_GROUP_CE | listen_info_idx;
@@ -1313,14 +1521,26 @@
     tNFA_CONN_EVT_DATA conn_evt;
 
 #if (NFC_NFCEE_INCLUDED == TRUE)
-    /* Check if deregistering UICC , or virtual secure element listen */
-    if (p_ce_msg->dereg_listen.listen_info == NFA_CE_LISTEN_INFO_UICC)
+    /* Check if deregistering UICC/ESE , or virtual secure element listen */
+    if (p_ce_msg->dereg_listen.listen_info
+#if(NXP_EXTNS == TRUE)
+                        & (NFA_CE_LISTEN_INFO_UICC | NFA_CE_LISTEN_INFO_ESE)
+#else
+                        == NFA_CE_LISTEN_INFO_UICC
+#endif
+    )
     {
         /* Deregistering UICC listen. Look for listen_info for this UICC ee handle */
         for (listen_info_idx = 0; listen_info_idx < NFA_CE_LISTEN_INFO_MAX; listen_info_idx++)
         {
             if (  (p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_IN_USE)
-                &&(p_cb->listen_info[listen_info_idx].flags & NFA_CE_LISTEN_INFO_UICC)
+                &&(p_cb->listen_info[listen_info_idx].flags &
+#if(NXP_EXTNS == TRUE)
+                        (NFA_CE_LISTEN_INFO_UICC | NFA_CE_LISTEN_INFO_ESE)
+#else
+                        NFA_CE_LISTEN_INFO_UICC
+#endif
+                )
                 &&(p_cb->listen_info[listen_info_idx].ee_handle == p_ce_msg->dereg_listen.handle)  )
             {
                 /* UICC is in not idle state */
@@ -1349,9 +1569,24 @@
 
         if (listen_info_idx == NFA_CE_LISTEN_INFO_MAX)
         {
+#if(NXP_EXTNS == TRUE)
+            NFA_TRACE_ERROR0 ("nfa_ce_api_dereg_listen (): cannot find listen_info for UICC/ESE");
+#else
             NFA_TRACE_ERROR0 ("nfa_ce_api_dereg_listen (): cannot find listen_info for UICC");
+#endif
             conn_evt.status = NFA_STATUS_INVALID_PARAM;
+#if(NXP_EXTNS == TRUE)
+            if(p_ce_msg->dereg_listen.listen_info & NFA_CE_LISTEN_INFO_UICC )
+            {
+                nfa_dm_conn_cback_event_notify (NFA_CE_UICC_LISTEN_CONFIGURED_EVT, &conn_evt);
+            }
+            else if(p_ce_msg->dereg_listen.listen_info & NFA_CE_LISTEN_INFO_ESE)
+            {
+                nfa_dm_conn_cback_event_notify (NFA_CE_ESE_LISTEN_CONFIGURED_EVT, &conn_evt);
+            }
+#else
             nfa_dm_conn_cback_event_notify (NFA_CE_UICC_LISTEN_CONFIGURED_EVT, &conn_evt);
+#endif
         }
     }
     else
diff --git a/src/nfa/ce/nfa_ce_api.c b/src/nfa/ce/nfa_ce_api.c
index 91a7958..af23208 100644
--- a/src/nfa/ce/nfa_ce_api.c
+++ b/src/nfa/ce/nfa_ce_api.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -47,7 +65,11 @@
     tNFA_CE_MSG      *p_ce_msg;
 
     /* Validate handle */
-    if (  (listen_info != NFA_CE_LISTEN_INFO_UICC)
+    if (  (listen_info != NFA_CE_LISTEN_INFO_UICC
+#if(NXP_EXTNS == TRUE)
+            && listen_info != NFA_CE_LISTEN_INFO_ESE
+#endif
+            )
         &&((handle & NFA_HANDLE_GROUP_MASK) != NFA_HANDLE_GROUP_CE)  )
     {
         NFA_TRACE_ERROR0 ("nfa_ce_api_reregister_listen: Invalid handle");
@@ -229,6 +251,65 @@
     return (NFA_STATUS_FAILED);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_CeConfigureEseListenTech
+**
+** Description      Configure listening for the Ese, using the specified
+**                  technologies.
+**
+**                  Events will be notifed using the tNFA_CONN_CBACK
+**                  (registered during NFA_Enable)
+**
+**                  The NFA_CE_ESE_LISTEN_CONFIGURED_EVT reports the status of the
+**                  operation.
+**
+**                  Activation and deactivation are reported using the
+**                  NFA_ACTIVATED_EVT and NFA_DEACTIVATED_EVT events
+**
+** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
+**                  should happen before calling this function
+**
+** Returns:
+**                  NFA_STATUS_OK, if command accepted
+**                  NFA_STATUS_FAILED: otherwise
+**
+*******************************************************************************/
+tNFA_STATUS NFA_CeConfigureEseListenTech (tNFA_HANDLE ee_handle,
+                                           tNFA_TECHNOLOGY_MASK tech_mask)
+{
+#if (NFC_NFCEE_INCLUDED == TRUE)
+    tNFA_CE_MSG *p_msg;
+
+    NFA_TRACE_API1 ("NFA_CeConfigureEseListenTech () ee_handle = 0x%x", ee_handle);
+
+    /* If tech_mask is zero, then app is disabling listening for specified uicc */
+    if (tech_mask == 0)
+    {
+        return (nfa_ce_api_deregister_listen (ee_handle, NFA_CE_LISTEN_INFO_ESE));
+    }
+
+    /* Otherwise then app is configuring ese listen for the specificed technologies */
+    if ((p_msg = (tNFA_CE_MSG *) GKI_getbuf ((UINT16) sizeof(tNFA_CE_MSG))) != NULL)
+    {
+        p_msg->reg_listen.hdr.event   = NFA_CE_API_REG_LISTEN_EVT;
+        p_msg->reg_listen.listen_type = NFA_CE_REG_TYPE_ESE;
+
+        p_msg->reg_listen.ee_handle   = ee_handle;
+        p_msg->reg_listen.tech_mask   = tech_mask;
+
+        nfa_sys_sendmsg (p_msg);
+
+        return (NFA_STATUS_OK);
+    }
+#else
+    NFA_TRACE_ERROR0 ("NFA_CeConfigureEseListenTech () NFCEE related functions are not enabled!");
+#endif
+    return (NFA_STATUS_FAILED);
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         NFA_CeRegisterFelicaSystemCodeOnDH
@@ -330,7 +411,11 @@
     NFA_TRACE_API0 ("NFA_CeRegisterAidOnDH ()");
 
     /* Validate parameters */
+#if (NXP_EXTNS == TRUE)
+    if ((p_conn_cback==NULL) || (aid_len > NFC_MAX_AID_LEN))
+#else
     if (p_conn_cback==NULL)
+#endif
         return (NFA_STATUS_INVALID_PARAM);
 
     if ((p_msg = (tNFA_CE_MSG *) GKI_getbuf ((UINT16) sizeof(tNFA_CE_MSG))) != NULL)
@@ -423,4 +508,3 @@
 
     return (NFA_STATUS_FAILED);
 }
-
diff --git a/src/nfa/dm/nfa_dm_act.c b/src/nfa/dm/nfa_dm_act.c
index 242963f..645e5de 100644
--- a/src/nfa/dm/nfa_dm_act.c
+++ b/src/nfa/dm/nfa_dm_act.c
@@ -15,8 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  This file contains the action functions for device manager state
@@ -58,7 +75,9 @@
 static BOOLEAN nfa_dm_deactivate_polling (void);
 static void nfa_dm_excl_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
 static void nfa_dm_poll_disc_cback (tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
-
+#if(NXP_EXTNS == TRUE)
+extern BOOLEAN gFelicaReaderMode;
+#endif
 
 /*******************************************************************************
 **
@@ -167,11 +186,14 @@
     /* WT */
     nfa_dm_cb.params.wt[0] = 14;
 
+    // LF_T3T_PMM is not supported.
     /* Set CE default configuration */
+#if (NXP_EXTNS != TRUE)
     if (p_nfa_dm_ce_cfg[0])
     {
         nfa_dm_check_set_config (p_nfa_dm_ce_cfg[0], &p_nfa_dm_ce_cfg[1], FALSE);
     }
+#endif
 
     /* Set optional general default configuration */
     if (p_nfa_dm_gen_cfg && p_nfa_dm_gen_cfg[0])
@@ -253,6 +275,9 @@
 {
     tNFA_DM_CBACK_DATA dm_cback_data;
     tNFA_GET_CONFIG   *p_nfa_get_confg;
+#if(NXP_EXTNS == TRUE)
+    tNFA_GET_ROUTING   *p_nfa_get_routing;
+#endif
     tNFA_CONN_EVT_DATA conn_evt;
     UINT8 dm_cback_evt;
     UINT8 max_ee = 0;
@@ -354,16 +379,14 @@
         break;
 
     case NFC_EE_DISCOVER_REQ_REVT:               /* EE Discover Req notification */
-        if (nfa_dm_is_active() &&
-            (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_DISCOVERY) )
-        {
-            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
-        }
+//        if (nfa_dm_is_active() &&
+//            (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_DISCOVERY) )
+//        {
+//            nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_IDLE);
+//        }
         nfa_ee_proc_evt (event, p_data);
         break;
 
-    case NFC_GET_ROUTING_REVT:                   /* Retrieve Routing response */
-        break;
 #endif
 
     case NFC_RF_FIELD_REVT:                      /* RF Field information            */
@@ -373,8 +396,32 @@
         break;
 
 
+    case NFC_GET_ROUTING_REVT:                   /* Retrieve Routing response */
+#if(NXP_EXTNS == TRUE)
+        if ((p_nfa_get_routing = (tNFA_GET_ROUTING *) GKI_getbuf ((UINT16) (sizeof (tNFA_GET_ROUTING)))) != NULL)
+        {
+            p_nfa_get_routing->status          = p_data->get_routing.status;
+            p_nfa_get_routing->num_tlvs        = p_data->get_routing.num_tlvs;
+            p_nfa_get_routing->tlv_size        = p_data->get_routing.tlv_size;
+            memcpy(p_nfa_get_routing->param_tlvs,p_data->get_routing.param_tlvs,p_data->get_routing.tlv_size);
+            (*nfa_dm_cb.p_dm_cback) (NFA_DM_GET_ROUTE_CONFIG_REVT, (tNFA_DM_CBACK_DATA *) p_nfa_get_routing);
+            GKI_freebuf (p_nfa_get_routing);
+        }
+        else
+        {
+            NFA_TRACE_DEBUG0 ("nfa_dm_nfc_response_cback unable to allocate buffer");
+        }
+#endif
+        break;
 
     case NFC_GEN_ERROR_REVT:                     /* generic error command or notification */
+#if(NXP_EXTNS == TRUE)
+        if (p_data->status == 0xE4) //STATUS_EMVCO_PCD_COLLISION
+        {
+            dm_cback_data.status = p_data->status;
+            (*nfa_dm_cb.p_dm_cback) (NFA_DM_EMVCO_PCD_COLLISION_EVT, &dm_cback_data);
+        }
+#endif
         break;
 
     case NFC_NFCC_RESTART_REVT:                  /* NFCC has been re-initialized */
@@ -399,6 +446,12 @@
         break;
 
     case NFC_NFCC_TIMEOUT_REVT:
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+        conn_evt.status = p_data->status;
+        nfa_dm_conn_cback_event_notify (NFA_RECOVERY_EVT, &conn_evt);
+#endif
+        break;
+
     case NFC_NFCC_TRANSPORT_ERR_REVT:
         NFA_TRACE_DEBUG1 ("flags:0x%08x", nfa_dm_cb.flags);
         dm_cback_evt = (event == NFC_NFCC_TIMEOUT_REVT) ? NFA_DM_NFCC_TIMEOUT_EVT : NFA_DM_NFCC_TRANSPORT_ERR_EVT;
@@ -750,9 +803,15 @@
     NFA_TRACE_DEBUG0 ("nfa_dm_act_deactivate ()");
 
     if (  (p_data->deactivate.sleep_mode == FALSE)                 /* Always allow deactivate to IDLE */
-        ||(  (nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_T1T)      /* Do not allow deactivate to SLEEP for T1T,NFCDEP, ISO15693 */
-           &&(nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_NFC_DEP)
-           &&(nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_ISO15693)
+        ||(  (nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_T1T)      /* Do not allow deactivate to SLEEP for T1T,NFCDEP */
+           &&
+#if(NXP_EXTNS == TRUE)
+             (
+#endif
+             (nfa_dm_cb.disc_cb.activated_protocol != NFA_PROTOCOL_NFC_DEP)
+#if(NXP_EXTNS == TRUE)
+            || gFelicaReaderMode || appl_dta_mode_flag)
+#endif
            &&(nfa_dm_cb.disc_cb.activated_protocol != NFC_PROTOCOL_KOVIO)  )  )
     {
         deact_type  = NFA_DEACTIVATE_TYPE_DISCOVERY;
@@ -763,19 +822,33 @@
                 /* Deactivate to sleep mode not allowed in this state. */
                 deact_type = NFA_DEACTIVATE_TYPE_IDLE;
             }
+#if(NXP_EXTNS == TRUE)
+            else if(appl_dta_mode_flag==TRUE && (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_LISTEN_SLEEP || nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_POLL_ACTIVE))
+            {
+                deact_type = NFA_DEACTIVATE_TYPE_SLEEP;
+            }
+#endif
             else if (nfa_dm_cb.disc_cb.disc_state != NFA_DM_RFST_LISTEN_SLEEP)
             {
                 deact_type = NFA_DEACTIVATE_TYPE_SLEEP;
             }
         }
-        if (nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
+        if ((nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_W4_ALL_DISCOVERIES)
+#if(NXP_EXTNS == TRUE)
+            ||(nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_T3BT)
+#endif
+           )
         {
             /* Only deactivate to IDLE is allowed in this state. */
             deact_type = NFA_DEACTIVATE_TYPE_IDLE;
         }
 
         if (  (nfa_dm_cb.disc_cb.activated_protocol == NFA_PROTOCOL_NFC_DEP)
-            &&((nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE) == 0x00)  )
+            &&((nfa_dm_cb.flags & NFA_DM_FLAGS_EXCL_RF_ACTIVE) == 0x00)
+#if(NXP_EXTNS == TRUE)
+            && appl_dta_mode_flag != TRUE
+#endif
+            )
         {
             /* Exclusive RF control doesn't use NFA P2P */
             /* NFA P2P will deactivate NFC link after deactivating LLCP link */
@@ -869,6 +942,29 @@
     return (FALSE);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfa_dm_act_send_nxp
+**
+** Description      Send the NXP NCI command to the NCI command queue
+**
+** Returns          FALSE (message buffer is NOT freed by caller)
+**
+*******************************************************************************/
+BOOLEAN nfa_dm_act_send_nxp(tNFA_DM_MSG *p_data)
+{
+    BT_HDR  *p_cmd = (BT_HDR *)p_data;
+
+    p_cmd->offset   = sizeof (tNFA_DM_API_SEND_VSC) - BT_HDR_SIZE;
+    p_cmd->len      = p_data->send_vsc.cmd_params_len;
+    NFC_SendNxpNciCommand (p_cmd, p_data->send_vsc.p_cback);
+
+    /* Most dm action functions return TRUE, so nfa-sys frees the GKI buffer carrying the message,
+     * This action function re-use the GKI buffer to send the VSC, so the GKI buffer can not be freed by nfa-sys */
+    return (FALSE);
+}
+#endif
 /*******************************************************************************
 **
 ** Function         nfa_dm_start_polling
@@ -1326,7 +1422,21 @@
     nfa_dm_cb.disc_cb.disc_duration = p_data->disc_duration.rf_disc_dur_ms;
     return (TRUE);
 }
-
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfa_dm_act_get_rf_disc_duration
+**
+** Description      Get duration for RF discovery
+**
+** Returns          UINT16
+**
+*******************************************************************************/
+UINT16 nfa_dm_act_get_rf_disc_duration ( )
+{
+    return (nfa_dm_cb.disc_cb.disc_duration);
+}
+#endif
 /*******************************************************************************
 **
 ** Function         nfa_dm_act_select
@@ -1623,26 +1733,50 @@
                     &(p_data->activate),
                     sizeof (tNFC_ACTIVATE_DEVT));
 
-            if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
-                &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
+            if ((nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
+                &&((nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)))
             {
-                if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_P2P_PAUSED))
+#if(NXP_EXTNS == TRUE)
+                /*For P2P mode(Default DTA mode) open Raw channel to bypass LLCP layer. For LLCP DTA mode activate LLCP*/
+                if ((appl_dta_mode_flag == 1) && (nfa_dm_cb.eDtaMode == NFA_DTA_DEFAULT_MODE))
                 {
-                    /* activate LLCP */
-                    nfa_p2p_activate_llcp (p_data);
+                    /* Open raw channel in case of p2p for DTA testing */
+                    NFC_SetStaticRfCback (nfa_dm_act_data_cback);
+                    nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
+
                 }
                 else
                 {
-                    NFA_TRACE_DEBUG0 ("P2P is paused");
-                    nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
+#endif
+                    if (!(nfa_dm_cb.flags & NFA_DM_FLAGS_P2P_PAUSED))
+                    {
+                        /* activate LLCP */
+                        nfa_p2p_activate_llcp (p_data);
+#if(NXP_EXTNS == TRUE)
+                        GKI_freebuf (nfa_dm_cb.p_activate_ntf);
+                        nfa_dm_cb.p_activate_ntf = NULL;
+#endif
+                    }
+                    else
+                    {
+                        NFA_TRACE_DEBUG0 ("P2P is paused");
+                        nfa_dm_notify_activation_status (NFA_STATUS_OK, NULL);
+                    }
+#if(NXP_EXTNS == TRUE)
                 }
+#endif
             }
             else if (  (nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T1T)
                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T2T)
                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3T)
                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_ISO_DEP)
                      ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_15693)
-                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_KOVIO)  )
+                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_KOVIO)
+#if(NXP_EXTNS == TRUE)
+                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_MIFARE)
+                     ||(nfa_dm_cb.disc_cb.activated_protocol  == NFC_PROTOCOL_T3BT)
+#endif
+                    )
             {
                 /* Notify NFA tag sub-system */
                 nfa_rw_proc_disc_evt (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data, TRUE);
@@ -1672,7 +1806,7 @@
         }
 
         if (  (nfa_dm_cb.disc_cb.activated_protocol     == NFC_PROTOCOL_NFC_DEP)
-            &&(nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)  )
+            && ((nfa_dm_cb.disc_cb.activated_rf_interface == NFC_INTERFACE_NFC_DEP)))
         {
             /*
             ** If LLCP link is not deactivated yet,
@@ -1728,6 +1862,21 @@
 }
 
 /*******************************************************************************
+** Function         nfa_dm_poll_disc_cback_dta_wrapper
+**
+** Description      Accessing the nfa_dm_poll_disc_cback for DTA wrapper
+**
+** Returns          None
+**
+*******************************************************************************/
+#if(NXP_EXTNS == TRUE)
+void nfa_dm_poll_disc_cback_dta_wrapper(tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data)
+{
+    nfa_dm_poll_disc_cback(event, p_data);
+}
+#endif
+
+/*******************************************************************************
 **
 ** Function         nfa_dm_notify_activation_status
 **
@@ -1770,13 +1919,43 @@
         /* get length of NFCID and location */
         if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_A)
         {
-            nfcid_len = p_tech_params->param.pa.nfcid1_len;
-            p_nfcid   = p_tech_params->param.pa.nfcid1;
+#if(NXP_EXTNS == TRUE)
+            if((p_tech_params->param.pa.nfcid1_len == 0) && (p_params != NULL))
+            {
+                nfcid_len = sizeof(p_params->t1t.uid);
+                p_nfcid   = p_params->t1t.uid;
+                evt_data.activated.activate_ntf.rf_tech_param.param.pa.nfcid1_len = nfcid_len;
+                if(nfcid_len > 0 && p_nfcid != NULL)
+                {
+                    memcpy (evt_data.activated.activate_ntf.rf_tech_param.param.pa.nfcid1,p_nfcid,nfcid_len);
+                }
+            }
+            else
+            {
+#endif
+                nfcid_len = p_tech_params->param.pa.nfcid1_len;
+                p_nfcid   = p_tech_params->param.pa.nfcid1;
+#if(NXP_EXTNS == TRUE)
+            }
+#endif
         }
         else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_B)
         {
             nfcid_len = NFC_NFCID0_MAX_LEN;
             p_nfcid   = p_tech_params->param.pb.nfcid0;
+#if(NXP_EXTNS == TRUE)
+            if(nfa_dm_cb.disc_cb.activated_protocol == NFC_PROTOCOL_T3BT)
+            {
+                if(p_tech_params->param.pb.pupiid_len != 0)
+                {
+                    tNFC_ACTIVATE_DEVT *activate_ntf = (tNFC_ACTIVATE_DEVT*)nfa_dm_cb.p_activate_ntf;
+                    p_nfcid = activate_ntf->rf_tech_param.param.pb.pupiid;
+                    nfcid_len = activate_ntf->rf_tech_param.param.pb.pupiid_len;
+                    NFA_TRACE_DEBUG1 ("nfa_dm_notify_activation_status (): update pupi_len=%x", nfcid_len);
+                    memcpy (evt_data.activated.activate_ntf.rf_tech_param.param.pb.pupiid, p_nfcid, nfcid_len);
+                }
+            }
+#endif
         }
         else if (p_tech_params->mode == NFC_DISCOVERY_TYPE_POLL_F)
         {
diff --git a/src/nfa/dm/nfa_dm_api.c b/src/nfa/dm/nfa_dm_api.c
index 89f667f..7178c12 100644
--- a/src/nfa/dm/nfa_dm_api.c
+++ b/src/nfa/dm/nfa_dm_api.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -29,6 +47,9 @@
 #include "nfa_ce_int.h"
 #include "nfa_sys_int.h"
 #include "ndef_utils.h"
+#if(NXP_EXTNS == TRUE)
+UINT32 gFelicaReaderMode;
+#endif
 
 /*****************************************************************************
 **  Constants
@@ -221,11 +242,33 @@
                            tNFA_PMID *p_param_ids)
 {
     tNFA_DM_API_GET_CONFIG *p_msg;
+#if(NXP_EXTNS == TRUE)
+    UINT8 bytes;
+    UINT8 propConfigCnt;
 
     NFA_TRACE_API1 ("NFA_GetConfig (): num_ids: %i", num_ids);
+    //NXP_EXTN code added to handle propritory config IDs
+    UINT32 idx = 0;
+    UINT8 *params =  p_param_ids;
+    propConfigCnt=0;
 
+    for(idx=0; idx<num_ids; idx++)
+    {
+        if(*params == 0xA0)
+        {
+            params++;
+            propConfigCnt++;
+        }
+        params++;
+    }
 
+    bytes = (num_ids - propConfigCnt) + (propConfigCnt<<1);
+
+    if ((p_msg = (tNFA_DM_API_GET_CONFIG *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_GET_CONFIG) + bytes))) != NULL)
+#else
+    NFA_TRACE_API1 ("NFA_GetConfig (): num_ids: %i", num_ids);
     if ((p_msg = (tNFA_DM_API_GET_CONFIG *) GKI_getbuf ((UINT16) (sizeof (tNFA_DM_API_GET_CONFIG) + num_ids))) != NULL)
+#endif
     {
         p_msg->hdr.event = NFA_DM_API_GET_CONFIG_EVT;
 
@@ -233,7 +276,11 @@
         p_msg->p_pmids = (tNFA_PMID *) (p_msg+1);
 
         /* Copy the param IDs */
+#if(NXP_EXTNS == TRUE)
+        memcpy (p_msg->p_pmids, p_param_ids, bytes);
+#else
         memcpy (p_msg->p_pmids, p_param_ids, num_ids);
+#endif
 
         nfa_sys_sendmsg (p_msg);
 
@@ -1185,6 +1232,54 @@
     return (NFA_STATUS_FAILED);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_SendNxpNciCommand
+**
+** Description      This function is called to send an NXP NCI Vendor Specific
+**                  command to NFCC.
+**
+**                  cmd_params_len  - The command parameter len
+**                  p_cmd_params    - The command parameter
+**                  p_cback         - The callback function to receive the command
+**
+** Returns          NFA_STATUS_OK if successfully initiated
+**                  NFA_STATUS_FAILED otherwise
+**
+*******************************************************************************/
+tNFA_STATUS NFA_SendNxpNciCommand (UINT8            cmd_params_len,
+                                   UINT8            *p_cmd_params,
+                                   tNFA_VSC_CBACK    *p_cback)
+{
+    tNFA_DM_API_SEND_VSC *p_msg;
+    UINT16  size = sizeof(tNFA_DM_API_SEND_VSC) + cmd_params_len;
+
+    if ((p_msg = (tNFA_DM_API_SEND_VSC *) GKI_getbuf (size)) != NULL)
+    {
+        p_msg->hdr.event        = NFA_DM_API_SEND_NXP_EVT;
+        p_msg->p_cback          = p_cback;
+        if (cmd_params_len && p_cmd_params)
+        {
+            p_msg->cmd_params_len   = cmd_params_len;
+            p_msg->p_cmd_params     = (UINT8 *)(p_msg + 1);
+            memcpy (p_msg->p_cmd_params, p_cmd_params, cmd_params_len);
+        }
+        else
+        {
+            p_msg->cmd_params_len   = 0;
+            p_msg->p_cmd_params     = NULL;
+        }
+
+        nfa_sys_sendmsg (p_msg);
+
+        return (NFA_STATUS_OK);
+    }
+
+    return (NFA_STATUS_FAILED);
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         NFA_SetTraceLevel
@@ -1202,4 +1297,55 @@
 
     return (nfa_sys_cb.trace_level);
 }
-
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function       NFA_SetReaderMode
+**
+** Description:
+**    This function enable/disable  reader mode. In reader mode, even though if
+**    P2P & CE from UICC is detected, Priority will be given to TypeF UICC read.
+**    Its currently implemented for TypeF
+**
+**    ReaderModeFlag   Enable/Disable Reader Mode
+**    Technologies     Type of technologies to be set for Reader mode
+**                     Currently not used and reader mode is enabled for TypeF Only
+**
+** Returns:
+**    void
+*******************************************************************************/
+void NFA_SetReaderMode (BOOLEAN ReaderModeFlag, UINT32 Technologies)
+{
+    NFA_TRACE_API1 ("NFA_SetReaderMode =0x%x", ReaderModeFlag);
+    gFelicaReaderMode = ReaderModeFlag;
+    return;
+}
+/*******************************************************************************
+**
+** Function:        NFA_EnableDtamode
+**
+** Description:     Enable DTA Mode
+**
+** Returns:         none:
+**
+*******************************************************************************/
+void  NFA_EnableDtamode (tNFA_eDtaModes eDtaMode)
+{
+    NFA_TRACE_API1("0x%x: DTA Enabled", eDtaMode);
+    appl_dta_mode_flag = 0x01;
+    nfa_dm_cb.eDtaMode = eDtaMode;
+}
+tNFA_MW_VERSION NFA_GetMwVersion ()
+{
+    tNFA_MW_VERSION mwVer;
+    mwVer.validation = ( NXP_EN_PN547C2 | (NXP_EN_PN65T << 1) | (NXP_EN_PN548AD << 2) |
+                        (NXP_EN_PN66T << 3));
+    mwVer.android_version = NXP_ANDROID_VER;
+    NFA_TRACE_API1("0x%x:NFC MW Major Version:", NFC_NXP_MW_VERSION_MAJ);
+    NFA_TRACE_API1("0x%x:NFC MW Minor Version:", NFC_NXP_MW_VERSION_MIN);
+    mwVer.major_version = NFC_NXP_MW_VERSION_MAJ;
+    mwVer.minor_version = NFC_NXP_MW_VERSION_MIN;
+    NFA_TRACE_API2("mwVer:Major=0x%x,Minor=0x%x", mwVer.major_version,mwVer.minor_version);
+    return mwVer;
+}
+#endif
diff --git a/src/nfa/dm/nfa_dm_discover.c b/src/nfa/dm/nfa_dm_discover.c
index f9e179f..93ab82e 100644
--- a/src/nfa/dm/nfa_dm_discover.c
+++ b/src/nfa/dm/nfa_dm_discover.c
@@ -15,8 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  This file contains the action functions for device manager discovery
@@ -35,9 +52,18 @@
 #endif
 #include "nfa_rw_int.h"
 
+#if(NXP_EXTNS == TRUE)
+#include "nfc_int.h"
+#include "nci_hmsgs.h"
+#include<config.h>
+#endif
 /*
 **  static functions
 */
+#if(NXP_EXTNS == TRUE)
+static BOOLEAN reconnect_in_progress;
+static BOOLEAN is_emvco_active;
+#endif
 
 static UINT8 nfa_dm_get_rf_discover_config (tNFA_DM_DISC_TECH_PROTO_MASK dm_disc_mask,
                                             tNFC_DISCOVER_PARAMS disc_params[],
@@ -58,7 +84,25 @@
 static char *nfa_dm_disc_event_2_str (UINT8 event);
 #endif
 
+#if(NXP_EXTNS == TRUE)
+typedef struct nfa_dm_p2p_prio_logic
+{
+    UINT8            isodep_detected; /*flag to check if ISO-DEP is detected */
+    UINT8            timer_expired;   /*flag to check whether timer is expired  */
+    TIMER_LIST_ENT   timer_list; /*timer structure pointer */
+    UINT8            first_tech_mode;
+}nfa_dm_p2p_prio_logic_t;
 
+static nfa_dm_p2p_prio_logic_t p2p_prio_logic_data;
+
+int getListenTechValue(int listenTechMask);
+#define P2P_RESUME_POLL_TIMEOUT 16 /*mili second timeout value*/
+static UINT16 P2P_PRIO_LOGIC_CLEANUP_TIMEOUT = 50; /*timeout value 500 ms for p2p_prio_logic_cleanup*/
+#endif
+
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+BOOLEAN etsi_reader_in_progress = FALSE;
+#endif
 /*******************************************************************************
 **
 ** Function         nfa_dm_get_rf_discover_config
@@ -261,6 +305,69 @@
     return num_params;
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfa_dm_get_sak
+**
+** Description      provides the proper sak value based on nfcee id present and
+**                  HOST configuration.
+**
+** Returns          NFA_STATUS_OK if success
+**
+*******************************************************************************/
+static UINT8 nfa_dm_get_sak(tNFA_DM_DISC_TECH_PROTO_MASK tech_proto_mask)
+{
+    UINT8 sak = 0;
+    UINT8 tech_list = 0;
+    unsigned long hostEnable = TRUE, fwdEnable = TRUE;
+#if(NXP_EXTNS == TRUE)
+    if ((GetNumValue(NAME_HOST_LISTEN_ENABLE, &hostEnable, sizeof(hostEnable))))
+    {
+        NFA_TRACE_DEBUG2 ("%s:HOST_LISTEN_ENABLE=0x0%lu;", __FUNCTION__, hostEnable);
+    }
+    if((GetNumValue(NAME_NXP_FWD_FUNCTIONALITY_ENABLE, &fwdEnable, sizeof(fwdEnable))))
+    {
+        NFA_TRACE_DEBUG2 ("%s:NXP_FWD_FUNCTIONALITY_ENABLE=0x0%lu;", __FUNCTION__, fwdEnable);
+    }
+#endif
+
+    tech_list = nfa_ee_get_supported_tech_list(0x02);
+    if(hostEnable)
+    {
+        if(!fwdEnable && (tech_list == NFA_TECHNOLOGY_MASK_B))
+        {
+            sak = 0x00;
+        }
+        else
+        {
+            if (tech_proto_mask & NFA_DM_DISC_MASK_LA_ISO_DEP)
+            {
+                sak |= NCI_PARAM_SEL_INFO_ISODEP;
+            }
+            if (tech_proto_mask & NFA_DM_DISC_MASK_LA_NFC_DEP)
+            {
+                sak |= NCI_PARAM_SEL_INFO_NFCDEP;
+            }
+        }
+    }
+    else
+    {
+        if(tech_list == NFA_TECHNOLOGY_MASK_B)
+        {
+            sak = 0x00;
+        }
+        else if (tech_proto_mask & NFA_DM_DISC_MASK_LA_NFC_DEP)
+        {
+            sak |= NCI_PARAM_SEL_INFO_ISODEP;
+            sak |= NCI_PARAM_SEL_INFO_NFCDEP;
+        }
+    }
+
+    return sak;
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         nfa_dm_set_rf_listen_mode_config
@@ -286,7 +393,7 @@
     ** ISO-DEP listen LA_PROT 0x01, LB_PROT 0x01
     ** NFC-DEP listen LA_PROT 0x02, LF_PROT 0x02
     */
-
+    p = params;
     if (tech_proto_mask & NFA_DM_DISC_MASK_LA_T1T)
     {
         platform = NCI_PARAM_PLATFORM_T1T;
@@ -297,6 +404,7 @@
     }
     else
     {
+#if(NXP_EXTNS == FALSE)
         if (tech_proto_mask & NFA_DM_DISC_MASK_LA_ISO_DEP)
         {
             sens_info |= NCI_PARAM_SEL_INFO_ISODEP;
@@ -306,9 +414,20 @@
         {
             sens_info |= NCI_PARAM_SEL_INFO_NFCDEP;
         }
+#else
+        sens_info = nfa_dm_get_sak(tech_proto_mask);
+        NFA_TRACE_DEBUG2 ("%s: sens_info=0x0%x;", __FUNCTION__, sens_info);
+#endif
     }
-
-    p = params;
+#if (NXP_EXTNS == TRUE)
+    /*
+     * SEL_INFO will be updated irrespective of UICC/eSE is selected or not
+     * This is required for P2P to work if UICC/ESE selected
+     * */
+    UINT8_TO_STREAM (p, NFC_PMID_LA_SEL_INFO);
+    UINT8_TO_STREAM (p, NCI_PARAM_LEN_LA_SEL_INFO);
+    UINT8_TO_STREAM (p, sens_info);
+#endif
 
     /*
     ** for Listen A
@@ -325,9 +444,11 @@
         UINT8_TO_STREAM (p, NFC_PMID_LA_PLATFORM_CONFIG);
         UINT8_TO_STREAM (p, NCI_PARAM_LEN_LA_PLATFORM_CONFIG);
         UINT8_TO_STREAM (p, platform);
+#if (NXP_EXTNS != TRUE)
         UINT8_TO_STREAM (p, NFC_PMID_LA_SEL_INFO);
         UINT8_TO_STREAM (p, NCI_PARAM_LEN_LA_SEL_INFO);
         UINT8_TO_STREAM (p, sens_info);
+#endif
     }
     else /* Let NFCC use UICC configuration by configuring with length = 0 */
     {
@@ -335,8 +456,10 @@
         UINT8_TO_STREAM (p, 0);
         UINT8_TO_STREAM (p, NFC_PMID_LA_PLATFORM_CONFIG);
         UINT8_TO_STREAM (p, 0);
+#if (NXP_EXTNS != TRUE)
         UINT8_TO_STREAM (p, NFC_PMID_LA_SEL_INFO);
         UINT8_TO_STREAM (p, 0);
+#endif
         UINT8_TO_STREAM (p, NFC_PMID_LA_NFCID1);
         UINT8_TO_STREAM (p, 0);
         UINT8_TO_STREAM (p, NFC_PMID_LA_HIST_BY);
@@ -371,19 +494,53 @@
         UINT8_TO_STREAM (p, 0);
     }
 
+#if (NXP_EXTNS == TRUE)
+    /** SEL_INFO will be updated irrespective of UICC/eSE is selected or not
+     *  This is required for P2P to work if UICC/ESE selected
+    **/
+        UINT8_TO_STREAM (p, NFC_PMID_LF_PROTOCOL);
+        UINT8_TO_STREAM (p, NCI_PARAM_LEN_LF_PROTOCOL);
+        if (tech_proto_mask & NFA_DM_DISC_MASK_LF_NFC_DEP)
+        {
+            UINT8_TO_STREAM (p, NCI_LISTEN_PROTOCOL_NFC_DEP);
+        }
+        else
+        {
+            UINT8_TO_STREAM (p, 0x00);
+        }
+#endif
+
     /* for Listen F */
-    /* NFCC can support NFC-DEP and T3T listening based on NFCID routing regardless of NFC-F tech routing */
-    UINT8_TO_STREAM (p, NFC_PMID_LF_PROTOCOL);
-    UINT8_TO_STREAM (p, NCI_PARAM_LEN_LF_PROTOCOL);
-    if ((tech_proto_mask & NFA_DM_DISC_MASK_LF_NFC_DEP) &&
-        !nfa_dm_is_p2p_paused() )
+#if(NXP_EXTNS == TRUE)
+    if (nfa_dm_cb.disc_cb.listen_RT[NFA_DM_DISC_LRT_NFC_F] == NFA_DM_DISC_HOST_ID_DH)
     {
-        UINT8_TO_STREAM (p, NCI_LISTEN_PROTOCOL_NFC_DEP);
+#endif
+        /* NFCC can support NFC-DEP and T3T listening based on NFCID routing regardless of NFC-F tech routing */
+        UINT8_TO_STREAM (p, NFC_PMID_LF_PROTOCOL);
+        UINT8_TO_STREAM (p, NCI_PARAM_LEN_LF_PROTOCOL);
+        if ((tech_proto_mask & NFA_DM_DISC_MASK_LF_NFC_DEP) &&
+            !nfa_dm_is_p2p_paused() )
+        {
+            UINT8_TO_STREAM (p, NCI_LISTEN_PROTOCOL_NFC_DEP);
+        }
+        else
+        {
+            UINT8_TO_STREAM (p, 0x00);
+        }
+#if(NXP_EXTNS == TRUE)
     }
     else
     {
-        UINT8_TO_STREAM (p, 0x00);
+        /* If DH is not listening on T3T, let NFCC use UICC configuration by configuring with length = 0 */
+        if ((tech_proto_mask & NFA_DM_DISC_MASK_LF_T3T) == 0)
+        {
+            UINT8_TO_STREAM (p, NFC_PMID_LF_PROTOCOL);
+            UINT8_TO_STREAM (p, 0);
+            UINT8_TO_STREAM (p, NFC_PMID_LF_T3T_FLAGS2);
+            UINT8_TO_STREAM (p, 0);
+        }
     }
+#endif
 
     if (p > params)
     {
@@ -556,9 +713,11 @@
             }
         }
 
+#if (NXP_EXTNS != TRUE)
         UINT8_TO_STREAM (p,  NFC_PMID_LF_T3T_PMM);
         UINT8_TO_STREAM (p,  NCI_PARAM_LEN_LF_T3T_PMM);
         ARRAY_TO_STREAM (p,  p_cfg->lf_t3t_pmm, NCI_PARAM_LEN_LF_T3T_PMM);
+#endif
 
         nfa_dm_check_set_config ((UINT8) (p - params), params, FALSE);
 
@@ -882,8 +1041,20 @@
 static void nfa_dm_disc_deact_ntf_timeout_cback (TIMER_LIST_ENT *p_tle)
 {
     NFA_TRACE_ERROR0 ("nfa_dm_disc_deact_ntf_timeout_cback()");
-
-    nfa_dm_disc_force_to_idle();
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+    if (nfc_cb.num_disc_maps == 1)
+    {
+    NFC_TRACE_ERROR0 ("reset Nfc..!!");
+    etsi_reader_in_progress = TRUE;
+    nfc_ncif_cmd_timeout();
+    }
+    else
+    {
+#endif
+        nfa_dm_disc_force_to_idle();
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+    }
+#endif
 }
 
 /*******************************************************************************
@@ -902,6 +1073,9 @@
 {
     tNFC_STATUS status = NFC_STATUS_SEMANTIC_ERROR;
     tNFA_DM_DISC_FLAGS w4_flags = nfa_dm_cb.disc_cb.disc_flags & (NFA_DM_DISC_FLAGS_W4_RSP|NFA_DM_DISC_FLAGS_W4_NTF);
+#if (NXP_EXTNS == TRUE)
+    unsigned long num = 0;
+#endif
 
     if (!w4_flags)
     {
@@ -913,7 +1087,30 @@
         if (!nfa_dm_cb.disc_cb.tle.in_use)
         {
             nfa_dm_cb.disc_cb.tle.p_cback = (TIMER_CBACK *)nfa_dm_disc_deact_ntf_timeout_cback;
+#if (NXP_EXTNS == TRUE)
+            num = NFA_DM_DISC_TIMEOUT_W4_DEACT_NTF;
+            NFA_TRACE_DEBUG1("num_disc_maps=%d",nfc_cb.num_disc_maps);
+            if (nfc_cb.num_disc_maps == 1)
+            {
+                NFA_TRACE_DEBUG1("Reading NAME_NFA_DM_DISC_NTF_TIMEOUT val   "
+                        "nfc_cb.num_disc_maps = %d", nfc_cb.num_disc_maps);
+                if ( GetNumValue ( NAME_NFA_DM_DISC_NTF_TIMEOUT, &num, sizeof ( num ) ) )
+                {
+                    num *= 1000;
+                }
+                else
+                {
+                    num = NFA_DM_DISC_TIMEOUT_W4_DEACT_NTF;
+                    NFA_TRACE_DEBUG1("Overriding NFA_DM_DISC_NTF_TIMEOUT to use %d", num);
+                }
+            }
+            NFA_TRACE_DEBUG1("Starting timer value %d", num);
+            /*wait infinite time for deactivate NTF, if the timeout is configured to 0*/
+            if(num != 0)
+                nfa_sys_start_timer (&nfa_dm_cb.disc_cb.tle, 0, num);
+#else
             nfa_sys_start_timer (&nfa_dm_cb.disc_cb.tle, 0, NFA_DM_DISC_TIMEOUT_W4_DEACT_NTF);
+#endif
         }
     }
     else
@@ -949,6 +1146,8 @@
     tNFC_DISCOVER_PARAMS    disc_params[NFA_DM_MAX_DISC_PARAMS];
     tNFA_DM_DISC_TECH_PROTO_MASK dm_disc_mask = 0, poll_mask, listen_mask;
     UINT8                   num_params, xx;
+    unsigned long           fwdEnable = FALSE, hostEnable =FALSE;
+    UINT8                   tech_list = 0;
 
     NFA_TRACE_DEBUG0 ("nfa_dm_start_rf_discover ()");
     /* Make sure that RF discovery was enabled, or some app has exclusive control */
@@ -975,7 +1174,7 @@
             if (nfa_dm_cb.disc_cb.entry[xx].in_use)
             {
                 poll_mask = (nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask & NFA_DM_DISC_MASK_POLL);
-
+                NFA_TRACE_DEBUG2 ("requested_disc_mask = 0x%x, xx=%d", nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask, xx);
                 /* clear poll mode technolgies and protocols which are already used by others */
                 poll_mask &= ~(dm_disc_mask & NFA_DM_DISC_MASK_POLL);
 
@@ -1004,18 +1203,20 @@
                     listen_mask |= (nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask  & NFA_DM_DISC_MASK_LA_NFC_DEP);
                     listen_mask |= (nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask  & NFA_DM_DISC_MASK_LAA_NFC_DEP);
                 }
+                NFA_TRACE_DEBUG1 ("listen_mask value after NFC-A = 0x%x", listen_mask);
 
                 /* NFC-B */
                 /* multiple hosts can listen ISO-DEP based on AID routing */
                 listen_mask |= nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask
                                & NFA_DM_DISC_MASK_LB_ISO_DEP;
+                NFA_TRACE_DEBUG1 ("listen_mask value after NFC-B = 0x%x", listen_mask);
 
                 /* NFC-F */
-                /* NFCC can support NFC-DEP and T3T listening based on NFCID routing regardless of NFC-F tech routing */
                 listen_mask |= nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask
                                & ( NFA_DM_DISC_MASK_LF_T3T
                                   |NFA_DM_DISC_MASK_LF_NFC_DEP
                                   |NFA_DM_DISC_MASK_LFA_NFC_DEP );
+                NFA_TRACE_DEBUG1 ("listen_mask value after NFC-F = 0x%x", listen_mask);
 
                 /* NFC-B Prime */
                 if (nfa_dm_cb.disc_cb.entry[xx].host_id == nfa_dm_cb.disc_cb.listen_RT[NFA_DM_DISC_LRT_NFC_BP])
@@ -1023,12 +1224,13 @@
                     listen_mask |= nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask
                                    & NFA_DM_DISC_MASK_L_B_PRIME;
                 }
-
+                NFA_TRACE_DEBUG1 ("listen_mask value after NFC-B Prime = 0x%x", listen_mask);
                 /*
                 ** clear listen mode technolgies and protocols which are already used by others
                 */
 
                 /* Check if other modules are listening T1T or T2T */
+                NFA_TRACE_DEBUG1 ("dm_disc_mask = 0x%x", dm_disc_mask);
                 if (dm_disc_mask & (NFA_DM_DISC_MASK_LA_T1T|NFA_DM_DISC_MASK_LA_T2T))
                 {
                     listen_mask &= ~( NFA_DM_DISC_MASK_LA_T1T
@@ -1036,6 +1238,7 @@
                                      |NFA_DM_DISC_MASK_LA_ISO_DEP
                                      |NFA_DM_DISC_MASK_LA_NFC_DEP );
                 }
+                NFA_TRACE_DEBUG1 ("listen_mask value after T1T and T2T = 0x%x", listen_mask);
 
                 /* T1T/T2T has priority on NFC-A */
                 if (  (dm_disc_mask & (NFA_DM_DISC_MASK_LA_ISO_DEP|NFA_DM_DISC_MASK_LA_NFC_DEP))
@@ -1054,6 +1257,8 @@
                                      |NFA_DM_DISC_MASK_LAA_NFC_DEP );
                 }
 
+                NFA_TRACE_DEBUG1 ("listen_mask value after NFC-DEP = 0x%x", listen_mask);
+
                 nfa_dm_cb.disc_cb.entry[xx].selected_disc_mask = poll_mask | listen_mask;
 
                 NFA_TRACE_DEBUG2 ("nfa_dm_cb.disc_cb.entry[%d].selected_disc_mask = 0x%x",
@@ -1063,6 +1268,33 @@
             }
         }
 
+#if(NXP_EXTNS == TRUE)
+        if((GetNumValue(NAME_NXP_FWD_FUNCTIONALITY_ENABLE, &fwdEnable, sizeof(fwdEnable))) == FALSE)
+        {
+            fwdEnable = TRUE; //default value
+        }
+        if ((GetNumValue(NAME_HOST_LISTEN_ENABLE, &hostEnable, sizeof(hostEnable))) == FALSE)
+        {
+            hostEnable = TRUE;
+            NFA_TRACE_DEBUG2 ("%s:HOST_LISTEN_ENABLE=0x0%lu;", __FUNCTION__, hostEnable);
+        }
+
+        tech_list = nfa_ee_get_supported_tech_list(0x02);
+        if((fwdEnable == FALSE) || (hostEnable == FALSE))
+        {
+            if(tech_list == NFA_TECHNOLOGY_MASK_B)
+            {
+                NFA_TRACE_DEBUG0 ("TypeB only sim handling in case of no FWD functionality");
+                dm_disc_mask &= ~(NFA_DM_DISC_MASK_LA_ISO_DEP | NFA_DM_DISC_MASK_LA_NFC_DEP);
+            }
+            else if(tech_list == NFA_TECHNOLOGY_MASK_A)
+            {
+                NFA_TRACE_DEBUG0 ("TypeA only sim handling in case of no FWD functionality");
+                dm_disc_mask &= ~(NFA_DM_DISC_MASK_LB_ISO_DEP);
+            }
+        }
+#endif
+
         /* Let P2P set GEN bytes for LLCP to NFCC */
         if (dm_disc_mask & NFA_DM_DISC_MASK_NFC_DEP)
         {
@@ -1267,6 +1499,41 @@
         return (NFA_STATUS_FAILED);
     }
 
+#if(NXP_EXTNS == TRUE)
+    /*
+     * if this is Proprietary RF interface, notify activation as START_READER_EVT.
+     *
+     * Code to handle the Reader over SWP.
+     * 1. Pass this info to JNI as START_READER_EVT.
+     * return (NFA_STATUS_OK)
+     */
+    if (p_data->activate.intf_param.type  == NCI_INTERFACE_UICC_DIRECT || p_data->activate.intf_param.type == NCI_INTERFACE_ESE_DIRECT)
+    {
+        for (xx = 0; xx < NFA_DM_DISC_NUM_ENTRIES; xx++)
+        {
+            if ((nfa_dm_cb.disc_cb.entry[xx].in_use)
+#if (NXP_EXTNS != TRUE)
+                &&(nfa_dm_cb.disc_cb.entry[xx].host_id != NFA_DM_DISC_HOST_ID_DH)
+#endif
+               )
+            {
+                nfa_dm_cb.disc_cb.activated_rf_interface = p_data->activate.intf_param.type;
+                nfa_dm_cb.disc_cb.activated_handle       = xx;
+
+                NFA_TRACE_DEBUG2 ("activated_rf_uicc-ese_interface:0x%x, activated_handle: 0x%x",
+                                   nfa_dm_cb.disc_cb.activated_rf_interface,
+                                   nfa_dm_cb.disc_cb.activated_handle);
+
+                if (nfa_dm_cb.disc_cb.entry[xx].p_disc_cback)
+                    (*(nfa_dm_cb.disc_cb.entry[xx].p_disc_cback)) (NFA_DM_RF_DISC_ACTIVATED_EVT, p_data);
+
+                return (NFA_STATUS_OK);
+            }
+        }
+        return (NFA_STATUS_FAILED);
+    }
+#endif
+
     /* get bit mask of technolgies/mode and protocol */
     activated_disc_mask = nfa_dm_disc_get_disc_mask (tech_n_mode, protocol);
 
@@ -1306,7 +1573,9 @@
             if (nfa_dm_cb.disc_cb.entry[xx].host_id == host_id_in_LRT)
             {
                 if (nfa_dm_cb.disc_cb.entry[xx].selected_disc_mask & activated_disc_mask)
+                {
                     break;
+                }
             }
             else
             {
@@ -1343,6 +1612,28 @@
         xx = iso_dep_t3t__listen;
     }
 
+#if(NXP_EXTNS == TRUE)
+    if(protocol == NFC_PROTOCOL_NFC_DEP &&
+            (tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_F_ACTIVE ||
+                    tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_A_ACTIVE ||
+                    tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_A
+                    )
+      )
+    {
+        if(appl_dta_mode_flag == 1 &&
+          (tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_A))
+        {
+            NFA_TRACE_DEBUG0("DTA Mode Enabled : NFC-A Passive Listen Mode");
+        }
+        else
+        {
+            extern tNFA_P2P_CB nfa_p2p_cb;
+            xx = nfa_p2p_cb.dm_disc_handle;
+        }
+    }
+
+#endif
+
     if (xx < NFA_DM_DISC_NUM_ENTRIES)
     {
         nfa_dm_cb.disc_cb.activated_tech_mode    = tech_n_mode;
@@ -1886,6 +2177,15 @@
             }
             /* Otherwise, deactivating when getting unexpected activation */
         }
+#if(NXP_EXTNS == TRUE)
+        else if (p_data->nfc_discover.status == NCI_STATUS_SEMANTIC_ERROR)
+        {
+            /* check any pending flags like NFA_DM_DISC_FLAGS_STOPPING or NFA_DM_DISC_FLAGS_DISABLING */
+            nfa_dm_disc_new_state (NFA_DM_RFST_IDLE);
+            /* check if need to restart discovery after resync discovery state with NFCC */
+            nfa_dm_start_rf_discover ();
+        }
+#endif
         /* Otherwise, wait for deactivation NTF */
         break;
 
@@ -1966,7 +2266,21 @@
         }
         break;
     case NFA_DM_RF_DISCOVER_NTF:
-        nfa_dm_disc_new_state (NFA_DM_RFST_W4_ALL_DISCOVERIES);
+#if(NXP_EXTNS == TRUE)
+        /* Notification Type = NCI_DISCOVER_NTF_LAST_ABORT */
+        if (p_data->nfc_discover.result.more == NCI_DISCOVER_NTF_LAST_ABORT)
+        {
+            /* Fix for multiple tags: After receiving deactivate event, restart discovery */
+            NFA_TRACE_DEBUG0 ("Received NCI_DISCOVER_NTF_LAST_ABORT, sending deactivate command");
+            NFC_Deactivate (NFA_DEACTIVATE_TYPE_IDLE);
+        }
+        else
+        {
+#endif
+            nfa_dm_disc_new_state (NFA_DM_RFST_W4_ALL_DISCOVERIES);
+#if(NXP_EXTNS == TRUE)
+        }
+#endif
         nfa_dm_notify_discovery (p_data);
         break;
     case NFA_DM_RF_INTF_ACTIVATED_NTF:
@@ -1982,6 +2296,18 @@
             {
                 nfa_dm_disc_new_state (NFA_DM_RFST_LISTEN_ACTIVE);
             }
+#if(NXP_EXTNS == TRUE)
+            /*
+             * Handle the Reader over SWP.
+             * Add condition UICC_DIRECT_INTF/ESE_DIRECT_INTF
+             * set new state NFA_DM_RFST_POLL_ACTIVE
+             * */
+            else if (p_data->nfc_discover.activate.intf_param.type == NCI_INTERFACE_UICC_DIRECT ||
+                    p_data->nfc_discover.activate.intf_param.type == NCI_INTERFACE_ESE_DIRECT )
+            {
+                nfa_dm_disc_new_state (NFA_DM_RFST_POLL_ACTIVE);
+            }
+#endif
             else if (p_data->nfc_discover.activate.rf_tech_param.mode & 0x80)
             {
                 /* Listen mode */
@@ -2064,6 +2390,16 @@
         nfa_dm_start_rf_discover ();
         break;
     case NFA_DM_RF_DISCOVER_NTF:
+#if(NXP_EXTNS == TRUE)
+        if(p_data->nfc_discover.result.protocol == NCI_PROTOCOL_UNKNOWN)
+        {
+            /* fix for p2p interop with Nexus5 */
+            NFA_TRACE_DEBUG0("Unknown protocol - Restart Discovery");
+            /* after receiving unknown protocol, restart discovery */
+            NFC_Deactivate (NFA_DEACTIVATE_TYPE_IDLE);
+            return;
+        }
+#endif
         /* if deactivate CMD is already sent then ignore discover NTF */
         if (!(nfa_dm_cb.disc_cb.disc_flags & NFA_DM_DISC_FLAGS_W4_RSP))
         {
@@ -2156,6 +2492,7 @@
         {
             /* Handle sleep wakeup success: notify RW module of sleep wakeup of tag; if deactivation is pending then deactivate  */
             nfa_dm_disc_end_sleep_wakeup (NFC_STATUS_OK);
+            nfa_rw_set_cback(&(p_data->nfc_discover));
         }
         else if (status == NFA_STATUS_FAILED)
         {
@@ -2199,6 +2536,10 @@
         break;
     default:
         NFA_TRACE_ERROR0 ("nfa_dm_disc_sm_w4_host_select (): Unexpected discovery event");
+#if(NXP_EXTNS == TRUE)
+        NFA_TRACE_ERROR0 ("nfa_dm_disc_sm_w4_host_select (): Restarted discovery");
+        NFC_Deactivate (NFA_DEACTIVATE_TYPE_IDLE);
+#endif
         break;
     }
 
@@ -2231,6 +2572,15 @@
     switch (event)
     {
     case NFA_DM_RF_DEACTIVATE_CMD:
+#if(NXP_EXTNS == TRUE)
+        if (nfa_dm_cb.disc_cb.activated_protocol == NCI_PROTOCOL_MIFARE)
+        {
+            nfa_dm_cb.disc_cb.deact_pending = TRUE;
+            nfa_dm_cb.disc_cb.pending_deact_type    = p_data->deactivate_type;
+            status = nfa_dm_send_deactivate_cmd(p_data->deactivate_type);
+            break;
+        }
+#endif
         if (old_sleep_wakeup_flag)
         {
             /* sleep wakeup is already enabled when deactivate cmd is requested,
@@ -2325,12 +2675,14 @@
         break;
 
     case NFA_DM_CORE_INTF_ERROR_NTF:
+#if(NXP_EXTNS != TRUE)
         sleep_wakeup_event    = TRUE;
         if (  (!old_sleep_wakeup_flag)
             ||(!nfa_dm_cb.disc_cb.deact_pending)  )
         {
             nfa_dm_send_deactivate_cmd (NFA_DEACTIVATE_TYPE_DISCOVERY);
         }
+#endif
         break;
 
     default:
@@ -2653,6 +3005,7 @@
     {
         if (!nfa_dm_cb.disc_cb.entry[xx].in_use)
         {
+            NFA_TRACE_DEBUG2 ("nfa_dm_add_rf_discover () disc_mask=0x%x, xx=%d", disc_mask, xx);
             nfa_dm_cb.disc_cb.entry[xx].in_use              = TRUE;
             nfa_dm_cb.disc_cb.entry[xx].requested_disc_mask = disc_mask;
             nfa_dm_cb.disc_cb.entry[xx].host_id             = host_id;
@@ -2962,3 +3315,214 @@
     return "Unknown";
 }
 #endif /* BT_TRACE_VERBOSE */
+
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         P2P_Prio_Logic
+**
+** Description      Implements algorithm for NFC-DEP protocol priority over
+**                  ISO-DEP protocol.
+**
+** Returns          True if success
+**
+*******************************************************************************/
+BOOLEAN nfa_dm_p2p_prio_logic(UINT8 event, UINT8 *p, UINT8 ntf_rsp)
+{
+
+    if((nfa_dm_cb.flags & NFA_DM_FLAGS_P2P_PAUSED) &&
+       (nfa_dm_cb.flags & NFA_DM_FLAGS_LISTEN_DISABLED))
+    {
+        NFA_TRACE_DEBUG0("returning from nfa_dm_p2p_prio_logic  Disable p2p_prio_logic");
+        return TRUE;
+    }
+    if (TRUE == reconnect_in_progress ||
+            TRUE == is_emvco_active)
+    {
+        NFA_TRACE_DEBUG0("returning from nfa_dm_p2p_prio_logic  reconnect_in_progress || is_emvco_active");
+        return TRUE;
+    }
+    if(0x01 == appl_dta_mode_flag)
+    {
+        /*Disable the P2P Prio Logic when DTA is running*/
+        return TRUE;
+    }
+    if(event == NCI_MSG_RF_DISCOVER && p2p_prio_logic_data.timer_expired == 1 && ntf_rsp == 1)
+    {
+        NFA_TRACE_DEBUG0("nfa_dm_p2p_prio_logic starting a timer for next rf intf activated ntf");
+        P2P_PRIO_LOGIC_CLEANUP_TIMEOUT = (nfa_dm_act_get_rf_disc_duration()/10); /*timeout value 50 ms multiplied by 10 for p2p_prio_logic_cleanup*/
+
+        nfc_start_quick_timer (&p2p_prio_logic_data.timer_list,
+                        NFC_TTYPE_P2P_PRIO_LOGIC_CLEANUP, P2P_PRIO_LOGIC_CLEANUP_TIMEOUT);
+        return TRUE;
+    }
+    if(event == NCI_MSG_RF_INTF_ACTIVATED && p2p_prio_logic_data.timer_expired == 1)
+    {
+        NFA_TRACE_DEBUG0("nfa_dm_p2p_prio_logic stopping a timer for next rf intf activated ntf");
+        nfc_stop_quick_timer (&p2p_prio_logic_data.timer_list);
+    }
+
+    if(nfa_dm_cb.disc_cb.disc_state == NFA_DM_RFST_DISCOVERY)
+    {
+        UINT8 rf_disc_id = 0xFF;
+        UINT8 type = 0xFF;
+        UINT8 protocol = 0xFF;
+        UINT8 tech_mode = 0xFF;
+
+        NFA_TRACE_DEBUG0 ("P2P_Prio_Logic");
+
+        if (event == NCI_MSG_RF_INTF_ACTIVATED )
+        {
+            rf_disc_id    = *p++;
+            type          = *p++;
+            protocol      = *p++;
+            tech_mode     = *p++;
+        }
+        NFA_TRACE_DEBUG1("nfa_dm_p2p_prio_logic type = 0x%x", type);
+
+
+        if(type == NCI_INTERFACE_UICC_DIRECT || type == NCI_INTERFACE_ESE_DIRECT )
+        {
+             NFA_TRACE_DEBUG0 ("Disable the p2p prio logic RDR_SWP");
+             return TRUE;
+        }
+
+        if(event == NCI_MSG_RF_INTF_ACTIVATED && tech_mode >= 0x80)
+        {
+            NFA_TRACE_DEBUG0 ("nfa_dm_p2p_prio_logic listen mode activated reset all the nfa_dm_p2p_prio_logic variables ");
+            memset(&p2p_prio_logic_data, 0x00, sizeof(nfa_dm_p2p_prio_logic_t));
+        }
+
+        if ((tech_mode < 0x80) &&
+            event == NCI_MSG_RF_INTF_ACTIVATED &&
+            protocol == NCI_PROTOCOL_ISO_DEP &&
+            p2p_prio_logic_data.isodep_detected == 0)
+        {
+            memset(&p2p_prio_logic_data, 0x00, sizeof(nfa_dm_p2p_prio_logic_t));
+            p2p_prio_logic_data.isodep_detected = 1;
+            p2p_prio_logic_data.first_tech_mode = tech_mode;
+            NFA_TRACE_DEBUG0 ("ISO-DEP Detected First Time  Resume the Polling Loop");
+            nci_snd_deactivate_cmd(NFA_DEACTIVATE_TYPE_DISCOVERY);
+            return FALSE;
+        }
+
+        else if(event == NCI_MSG_RF_INTF_ACTIVATED &&
+                protocol == NCI_PROTOCOL_ISO_DEP &&
+                p2p_prio_logic_data.isodep_detected == 1 &&
+                p2p_prio_logic_data.first_tech_mode != tech_mode)
+        {
+            p2p_prio_logic_data.isodep_detected = 1;
+            p2p_prio_logic_data.timer_expired = 0;
+            NFA_TRACE_DEBUG0 ("ISO-DEP Detected Second Time Other Techmode  Resume the Polling Loop");
+            nfc_stop_quick_timer (&p2p_prio_logic_data.timer_list);
+            nci_snd_deactivate_cmd(NFA_DEACTIVATE_TYPE_DISCOVERY);
+            return FALSE;
+        }
+
+        else if (event == NCI_MSG_RF_INTF_ACTIVATED &&
+                 protocol == NCI_PROTOCOL_ISO_DEP &&
+                 p2p_prio_logic_data.isodep_detected == 1 &&
+                 p2p_prio_logic_data.timer_expired == 1)
+        {
+            NFA_TRACE_DEBUG0 ("ISO-DEP Detected TimerExpired, Final Notifying the Event");
+            nfc_stop_quick_timer (&p2p_prio_logic_data.timer_list);
+            memset(&p2p_prio_logic_data, 0x00, sizeof(nfa_dm_p2p_prio_logic_t));
+        }
+
+        else if (event == NCI_MSG_RF_INTF_ACTIVATED &&
+                 protocol == NCI_PROTOCOL_ISO_DEP &&
+                 p2p_prio_logic_data.isodep_detected == 1 &&
+                 p2p_prio_logic_data.first_tech_mode == tech_mode)
+        {
+            NFA_TRACE_DEBUG0 ("ISO-DEP Detected Same Techmode, Final Notifying the Event");
+            nfc_stop_quick_timer (&p2p_prio_logic_data.timer_list);
+            NFA_TRACE_DEBUG0 ("P2P_Stop_Timer");
+            memset(&p2p_prio_logic_data, 0x00, sizeof(nfa_dm_p2p_prio_logic_t));
+        }
+
+        else if (event == NCI_MSG_RF_INTF_ACTIVATED &&
+                 protocol != NCI_PROTOCOL_ISO_DEP &&
+                 p2p_prio_logic_data.isodep_detected == 1)
+        {
+            NFA_TRACE_DEBUG0 ("ISO-DEP Not Detected  Giving Priority for other Technology");
+            nfc_stop_quick_timer (&p2p_prio_logic_data.timer_list);
+            NFA_TRACE_DEBUG0 ("P2P_Stop_Timer");
+            memset(&p2p_prio_logic_data, 0x00, sizeof(nfa_dm_p2p_prio_logic_t));
+        }
+
+        else if (event == NCI_MSG_RF_DEACTIVATE &&
+                 p2p_prio_logic_data.isodep_detected == 1 &&
+                 p2p_prio_logic_data.timer_expired == 0 &&
+                 ntf_rsp == 1)
+        {
+            NFA_TRACE_DEBUG0 ("NFA_DM_RF_DEACTIVATE_RSP");
+            return FALSE;
+        }
+
+        else if (event == NCI_MSG_RF_DEACTIVATE &&
+                 p2p_prio_logic_data.isodep_detected == 1 &&
+                 p2p_prio_logic_data.timer_expired == 0 && ntf_rsp == 2)
+        {
+            NFA_TRACE_DEBUG0 ("NFA_DM_RF_DEACTIVATE_NTF");
+
+            nfc_start_quick_timer (&p2p_prio_logic_data.timer_list,
+                                   NFC_TTYPE_P2P_PRIO_RESPONSE, P2P_RESUME_POLL_TIMEOUT);
+
+            NFA_TRACE_DEBUG0 ("P2P_Start_Timer");
+
+            return FALSE;
+        }
+    }
+
+    NFA_TRACE_DEBUG0("returning TRUE");
+    return TRUE;
+}
+void NFA_SetReconnectState (BOOLEAN flag)
+{
+    reconnect_in_progress = flag;
+    NFA_TRACE_DEBUG1("NFA_SetReconnectState = 0x%x", reconnect_in_progress);
+}
+
+void NFA_SetEmvCoState (BOOLEAN flag)
+{
+    is_emvco_active = flag;
+    NFA_TRACE_DEBUG1("NFA_SetEmvCoState = 0x%x", is_emvco_active);
+}
+
+/*******************************************************************************
+**
+** Function         p2p_prio_logic_timeout
+**
+** Description      Callback function for p2p timer
+**
+** Returns          void
+**
+*******************************************************************************/
+void nfa_dm_p2p_timer_event ()
+{
+    NFA_TRACE_DEBUG0 ("P2P_Timer_timeout NFC-DEP Not Discovered!!");
+
+    p2p_prio_logic_data.timer_expired = 1;
+
+    if(p2p_prio_logic_data.isodep_detected == 1)
+    {
+        NFA_TRACE_DEBUG0 ("Deactivate and Restart RF discovery");
+        nci_snd_deactivate_cmd(NFC_DEACTIVATE_TYPE_IDLE);
+    }
+}
+
+/*******************************************************************************
+**
+** Function         nfa_dm_p2p_prio_logic_cleanup
+**
+** Description      Callback function for p2p prio logic cleanup timer
+**
+** Returns          void
+**
+*******************************************************************************/
+void nfa_dm_p2p_prio_logic_cleanup()
+{
+    NFA_TRACE_DEBUG0 (" p2p_prio_logic_cleanup timeout no activated intf notification received ");
+    memset(&p2p_prio_logic_data, 0x00, sizeof(nfa_dm_p2p_prio_logic_t));
+}
+#endif
diff --git a/src/nfa/dm/nfa_dm_main.c b/src/nfa/dm/nfa_dm_main.c
index 466eff0..b11bc0e 100644
--- a/src/nfa/dm/nfa_dm_main.c
+++ b/src/nfa/dm/nfa_dm_main.c
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -42,7 +61,11 @@
 };
 
 
+#if(NXP_EXTNS == TRUE)
+tNFA_DM_CB  nfa_dm_cb;
+#else
 tNFA_DM_CB  nfa_dm_cb = {FALSE};
+#endif
 
 
 #define NFA_DM_NUM_ACTIONS  (NFA_DM_MAX_EVT & 0x00ff)
@@ -80,6 +103,9 @@
     nfa_dm_act_reg_vsc,                 /* NFA_DM_API_REG_VSC_EVT               */
     nfa_dm_act_send_vsc,                /* NFA_DM_API_SEND_VSC_EVT              */
     nfa_dm_act_disable_timeout          /* NFA_DM_TIMEOUT_DISABLE_EVT           */
+#if (NXP_EXTNS == TRUE)
+    , nfa_dm_act_send_nxp                 /* NFA_DM_API_SEND_NXP_EVT              */
+#endif
 };
 
 /*****************************************************************************
@@ -190,7 +216,11 @@
             ||(protocol == NFC_PROTOCOL_T3T)
             ||(protocol == NFC_PROTOCOL_ISO_DEP)
             ||(protocol == NFC_PROTOCOL_NFC_DEP)
-            ||(protocol == NFC_PROTOCOL_15693)  );
+            ||(protocol == NFC_PROTOCOL_15693)
+#if(NXP_EXTNS == TRUE)
+            ||(protocol == NFC_PROTOCOL_T3BT)
+#endif
+            );
 }
 /*******************************************************************************
 **
@@ -225,7 +255,11 @@
 *******************************************************************************/
 tNFA_STATUS nfa_dm_check_set_config (UINT8 tlv_list_len, UINT8 *p_tlv_list, BOOLEAN app_init)
 {
+#if (NXP_EXTNS == TRUE)
+    UINT8 type, len, *p_value, *p_stored = NULL, max_len = 0;
+#else
     UINT8 type, len, *p_value, *p_stored, max_len;
+#endif
     UINT8 xx = 0, updated_len = 0, *p_cur_len;
     BOOLEAN update;
     tNFC_STATUS nfc_status;
@@ -288,9 +322,20 @@
         **  Listen B Configuration
         */
         case NFC_PMID_LB_SENSB_INFO:
-            p_stored  = nfa_dm_cb.params.lb_sensb_info;
-            max_len   = NCI_PARAM_LEN_LB_SENSB_INFO;
-            p_cur_len = &nfa_dm_cb.params.lb_sensb_info_len;
+#if(NXP_EXTNS == TRUE)
+            if(app_init == TRUE)
+            {
+#endif
+                p_stored  = nfa_dm_cb.params.lb_sensb_info;
+                max_len   = NCI_PARAM_LEN_LB_SENSB_INFO;
+                p_cur_len = &nfa_dm_cb.params.lb_sensb_info_len;
+#if(NXP_EXTNS == TRUE)
+            }
+            else
+            {
+                update = FALSE;
+            }
+#endif
             break;
         case NFC_PMID_LB_NFCID0:
             p_stored  = nfa_dm_cb.params.lb_nfcid0;
@@ -326,18 +371,21 @@
             max_len   = NCI_PARAM_LEN_LF_T3T_FLAGS2;
             p_cur_len = &nfa_dm_cb.params.lf_t3t_flags2_len;
             break;
+#if(NXP_EXTNS != TRUE)
         case NFC_PMID_LF_T3T_PMM:
             p_stored = nfa_dm_cb.params.lf_t3t_pmm;
             max_len  = NCI_PARAM_LEN_LF_T3T_PMM;
             break;
-
+#endif
         /*
         **  ISO-DEP and NFC-DEP Configuration
         */
+#if(NXP_EXTNS != TRUE)
         case NFC_PMID_FWI:
             p_stored = nfa_dm_cb.params.fwi;
             max_len  = NCI_PARAM_LEN_FWI;
             break;
+#endif
         case NFC_PMID_WT:
             p_stored = nfa_dm_cb.params.wt;
             max_len  = NCI_PARAM_LEN_WT;
@@ -383,6 +431,13 @@
                 {
                     update = TRUE;
                 }
+#if(NXP_EXTNS == TRUE)
+                else if(appl_dta_mode_flag && app_init)
+                {/*In DTA mode, config update is forced so that length of config params
+                  (i.e update_len) is updated accordingly even for setconfig have only one tlv*/
+                    update = TRUE;
+                }
+#endif
             }
             else if (len == max_len)  /* fixed length */
             {
@@ -390,6 +445,13 @@
                 {
                     update = TRUE;
                 }
+#if(NXP_EXTNS == TRUE)
+                else if(appl_dta_mode_flag && app_init)
+                {/*In DTA mode, config update is forced so that length of config params
+                  (i.e update_len) is updated accordingly even for setconfig have only one tlv*/
+                    update = TRUE;
+                }
+#endif
             }
         }
 
@@ -412,7 +474,17 @@
     }
 
     /* If any TVLs to update, or if the SetConfig was initiated by the application, then send the SET_CONFIG command */
-    if (updated_len || app_init)
+    /*if (updated_len || app_init) app_init is TRUE when setconfig is invoked from application. For extra setconfigs from internal to
+    stack, updated_len will be true. To avoid extra setconfigs from stack which is NOT required by DTA, condition is modified*/
+    if
+#if(NXP_EXTNS == TRUE)
+    ((
+#endif
+       (updated_len || app_init)
+#if(NXP_EXTNS == TRUE)
+       && (appl_dta_mode_flag == 0x00 ))
+       || ((appl_dta_mode_flag) && (app_init)))
+#endif
     {
         if ((nfc_status = NFC_SetConfig (updated_len, p_tlv_list)) == NFC_STATUS_OK)
         {
diff --git a/src/nfa/ee/nfa_ee_act.c b/src/nfa/ee/nfa_ee_act.c
index 8858e7b..a52130a 100644
--- a/src/nfa/ee/nfa_ee_act.c
+++ b/src/nfa/ee/nfa_ee_act.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -29,6 +47,9 @@
 #include "nfa_sys_int.h"
 #include "nfc_api.h"
 #include "nfa_ee_int.h"
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+#include <config.h>
+#endif
 
 
 /* the de-bounce timer:
@@ -39,7 +60,11 @@
 #define NFA_EE_ROUT_TIMEOUT_VAL         1000
 #endif
 
-#define NFA_EE_ROUT_BUF_SIZE            540
+#if(NFC_NXP_CHIP_PN548AD == TRUE)
+#define NFA_EE_ROUT_BUF_SIZE            720
+#else
+#define NFA_EE_ROUT_BUF_SIZE            200
+#endif
 #define NFA_EE_ROUT_MAX_TLV_SIZE        0xFD
 
 
@@ -60,7 +85,11 @@
 };
 
 /* the following 2 tables convert the protocol mask in API and control block to the command for NFCC */
+#if(NXP_EXTNS == TRUE)
+#define NFA_EE_NUM_PROTO     6
+#else
 #define NFA_EE_NUM_PROTO     5
+#endif
 const UINT8 nfa_ee_proto_mask_list[NFA_EE_NUM_PROTO] =
 {
     NFA_PROTOCOL_MASK_T1T,
@@ -68,6 +97,9 @@
     NFA_PROTOCOL_MASK_T3T,
     NFA_PROTOCOL_MASK_ISO_DEP,
     NFA_PROTOCOL_MASK_NFC_DEP
+#if(NXP_EXTNS == TRUE)
+    ,NFC_PROTOCOL_MASK_ISO7816
+#endif
 };
 
 const UINT8 nfa_ee_proto_list[NFA_EE_NUM_PROTO] =
@@ -77,8 +109,26 @@
     NFC_PROTOCOL_T3T,
     NFC_PROTOCOL_ISO_DEP,
     NFC_PROTOCOL_NFC_DEP
+#if(NXP_EXTNS == TRUE)
+    ,NFC_PROTOCOL_ISO7816
+#endif
 };
 
+static UINT8 *proto_route_buff;
+static UINT8 *tech_route_buff;
+static UINT8 *proto_pp;
+static UINT8 *tech_pp;
+static UINT8  proto_tlv_ctr;
+static UINT8  tech_tlv_ctr;
+#define NFA_EE_PROTO_BUFF_SIZE  120 /* num of proto= 6, proto_mask =5 and num of EEs 4, total  size = (6x5x4) */
+#define NFA_EE_TECH_BUFF_SIZE  60 /* num of tech =3 , tech_mask =5 and num of EEs 4, total  size = (3x5x4) */
+
+#if(NXP_EXTNS == TRUE)
+UINT8 NFA_REMOVE_ALL_AID[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
+UINT8 nfa_ee_ce_route_strict_disable = 0x01;
+BOOLEAN  gNfaProvisionMode = FALSE; /* to know if device is set to provision mode or not */
+#endif
+
 static void nfa_ee_report_discover_req_evt(void);
 static void nfa_ee_build_discover_req_evt (tNFA_EE_DISCOVER_REQ *p_evt_data);
 /*******************************************************************************
@@ -286,8 +336,35 @@
     return len;
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfa_all_ee_find_total_aid_len
+**
+** Description      Find the total len in aid_cfg from start_entry to the last
+**                  for all EE and DH.
+**
+** Returns          total length
+**
+*******************************************************************************/
+int nfa_all_ee_find_total_aid_len()
+{
+    UINT32  xx;
+    int total_len = 0;
+    tNFA_EE_ECB *p_cb = nfa_ee_cb.ecb;
+    for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
+    {
+        total_len += nfa_ee_find_total_aid_len(p_cb, 0);
+        total_len += (p_cb->aid_entries * 2);/*Adding tag/len */
+    }
 
+    tNFA_EE_ECB *p_ecb = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
+    total_len += nfa_ee_find_total_aid_len(p_ecb, 0);
+    total_len += (p_ecb->aid_entries * 2);/*Adding tag/len */
 
+    return total_len;
+}
+#endif
 
 /*******************************************************************************
 **
@@ -535,11 +612,19 @@
     tNFA_TECHNOLOGY_MASK    old_tech_switch_on   = p_cb->tech_switch_on;
     tNFA_TECHNOLOGY_MASK    old_tech_switch_off  = p_cb->tech_switch_off;
     tNFA_TECHNOLOGY_MASK    old_tech_battery_off = p_cb->tech_battery_off;
+#if(NXP_EXTNS == TRUE)
+    tNFA_TECHNOLOGY_MASK    old_tech_screen_lock = p_cb->tech_screen_lock;
+    tNFA_TECHNOLOGY_MASK    old_tech_screen_off = p_cb->tech_screen_off;
+#endif
     UINT8                   old_size_mask        = p_cb->size_mask;
 
     p_cb->tech_switch_on   = p_data->set_tech.technologies_switch_on;
     p_cb->tech_switch_off  = p_data->set_tech.technologies_switch_off;
     p_cb->tech_battery_off = p_data->set_tech.technologies_battery_off;
+#if(NXP_EXTNS == TRUE)
+    p_cb->tech_screen_lock = p_data->set_tech.technologies_screen_lock;
+    p_cb->tech_screen_off  = p_data->set_tech.technologies_screen_off;
+#endif
     nfa_ee_update_route_size(p_cb);
     if (nfa_ee_total_lmrt_size() > NFC_GetLmrtSize())
     {
@@ -548,12 +633,20 @@
         p_cb->tech_switch_on   = old_tech_switch_on;
         p_cb->tech_switch_off  = old_tech_switch_off;
         p_cb->tech_battery_off = old_tech_battery_off;
+#if(NXP_EXTNS == TRUE)
+        p_cb->tech_screen_lock = old_tech_screen_lock;
+        p_cb->tech_screen_off  = old_tech_screen_off;
+#endif
         p_cb->size_mask        = old_size_mask;
     }
     else
     {
         p_cb->ecb_flags       |= NFA_EE_ECB_FLAGS_TECH;
-        if (p_cb->tech_switch_on | p_cb->tech_switch_off | p_cb->tech_battery_off)
+        if (p_cb->tech_switch_on | p_cb->tech_switch_off | p_cb->tech_battery_off
+#if(NXP_EXTNS == TRUE)
+            | p_cb->tech_screen_lock | p_cb->tech_screen_off
+#endif
+            )
         {
             /* if any technology in any power mode is configured, mark this entry as configured */
             nfa_ee_cb.ee_cfged    |= nfa_ee_ecb_to_mask(p_cb);
@@ -581,11 +674,19 @@
     tNFA_PROTOCOL_MASK    old_proto_switch_on   = p_cb->proto_switch_on;
     tNFA_PROTOCOL_MASK    old_proto_switch_off  = p_cb->proto_switch_off;
     tNFA_PROTOCOL_MASK    old_proto_battery_off = p_cb->proto_battery_off;
+#if(NXP_EXTNS == TRUE)
+    tNFA_PROTOCOL_MASK    old_proto_screen_lock = p_cb->proto_screen_lock;
+    tNFA_PROTOCOL_MASK    old_proto_screen_off = p_cb->proto_screen_off;
+#endif
     UINT8                   old_size_mask        = p_cb->size_mask;
 
     p_cb->proto_switch_on       = p_data->set_proto.protocols_switch_on;
     p_cb->proto_switch_off      = p_data->set_proto.protocols_switch_off;
     p_cb->proto_battery_off     = p_data->set_proto.protocols_battery_off;
+#if(NXP_EXTNS == TRUE)
+    p_cb->proto_screen_lock     = p_data->set_proto.protocols_screen_lock;
+    p_cb->proto_screen_off     = p_data->set_proto.protocols_screen_off;
+#endif
     nfa_ee_update_route_size(p_cb);
     if (nfa_ee_total_lmrt_size() > NFC_GetLmrtSize())
     {
@@ -594,12 +695,20 @@
         p_cb->proto_switch_on   = old_proto_switch_on;
         p_cb->proto_switch_off  = old_proto_switch_off;
         p_cb->proto_battery_off = old_proto_battery_off;
+#if(NXP_EXTNS == TRUE)
+        p_cb->proto_screen_lock = old_proto_screen_lock;
+        p_cb->proto_screen_off = old_proto_screen_off;
+#endif
         p_cb->size_mask         = old_size_mask;
     }
     else
     {
         p_cb->ecb_flags            |= NFA_EE_ECB_FLAGS_PROTO;
-        if (p_cb->proto_switch_on | p_cb->proto_switch_off | p_cb->proto_battery_off)
+        if (p_cb->proto_switch_on | p_cb->proto_switch_off | p_cb->proto_battery_off
+#if(NXP_EXTNS == TRUE)
+            | p_cb->proto_screen_lock | p_cb->proto_screen_off
+#endif
+            )
         {
             /* if any protocol in any power mode is configured, mark this entry as configured */
             nfa_ee_cb.ee_cfged         |= nfa_ee_ecb_to_mask(p_cb);
@@ -624,6 +733,11 @@
 {
     tNFA_EE_API_ADD_AID *p_add = &p_data->add_aid;
     tNFA_EE_ECB *p_cb = p_data->cfg_hdr.p_cb;
+
+#if(NXP_EXTNS == TRUE)
+    tNFA_EE_ECB *dh_ecb = NULL;
+    UINT8 vs_info = p_add->vs_info;
+#endif
     tNFA_EE_ECB *p_chk_cb;
     UINT8   *p, *p_start;
     int     len, len_needed;
@@ -660,7 +774,12 @@
     else
     {
         /* Find the total length so far */
+#if(NXP_EXTNS == TRUE)
+        len = nfa_all_ee_find_total_aid_len();
+#else
         len = nfa_ee_find_total_aid_len(p_cb, 0);
+#endif
+
 
         /* make sure the control block has enough room to hold this entry */
         len_needed  = p_add->aid_len + 2; /* tag/len */
@@ -680,17 +799,36 @@
             }
             else
             {
+#if(NXP_EXTNS == TRUE)
+//                len = nfa_ee_find_total_aid_len(p_cb, 0);
+                dh_ecb = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
+                len = nfa_ee_find_total_aid_len(dh_ecb, 0);
+
+#endif
                 /* add AID */
+#if(NXP_EXTNS == TRUE)
+                //Always use single aid_cfg buffer to keep the aid order intact.
+                dh_ecb->aid_pwr_cfg[dh_ecb->aid_entries]    = p_add->power_state;
+                dh_ecb->aid_rt_info[dh_ecb->aid_entries]    = NFA_EE_AE_ROUTE | ((NFA_EE_AE_NXP_PREFIX_MATCH & vs_info)?NFA_EE_AE_NXP_PREFIX_MATCH:0x00);
+                dh_ecb->aid_rt_loc[dh_ecb->aid_entries]     = p_cb->nfcee_id;
+                p       = dh_ecb->aid_cfg + len;
+#else
                 p_cb->aid_pwr_cfg[p_cb->aid_entries]    = p_add->power_state;
                 p_cb->aid_rt_info[p_cb->aid_entries]    = NFA_EE_AE_ROUTE;
                 p       = p_cb->aid_cfg + len;
+#endif
+
                 p_start = p;
                 *p++    = NFA_EE_AID_CFG_TAG_NAME;
                 *p++    = p_add->aid_len;
                 memcpy(p, p_add->p_aid, p_add->aid_len);
                 p      += p_add->aid_len;
 
+#if(NXP_EXTNS == TRUE)
+            dh_ecb->aid_len[dh_ecb->aid_entries++]     = (UINT8)(p - p_start);
+#else
                 p_cb->aid_len[p_cb->aid_entries++]     = (UINT8)(p - p_start);
+#endif
             }
         }
         else
@@ -758,6 +896,9 @@
             GKI_shiftup (&p_cb->aid_len[entry], &p_cb->aid_len[entry + 1], rest_len);
             GKI_shiftup (&p_cb->aid_pwr_cfg[entry], &p_cb->aid_pwr_cfg[entry + 1], rest_len);
             GKI_shiftup (&p_cb->aid_rt_info[entry], &p_cb->aid_rt_info[entry + 1], rest_len);
+#if(NXP_EXTNS == TRUE)
+            GKI_shiftup (&p_cb->aid_rt_loc[entry], &p_cb->aid_rt_loc[entry + 1], rest_len);
+#endif
         }
         /* else the last entry, just reduce the aid_entries by 1 */
         p_cb->aid_entries--;
@@ -767,6 +908,33 @@
         /* report NFA_EE_REMOVE_AID_EVT to the callback associated the NFCEE */
         p_cback = p_cb->p_ee_cback;
     }
+#if(NXP_EXTNS == TRUE)
+    /*Clear All AIDs*/
+    else if(0 == memcmp(NFA_REMOVE_ALL_AID,p_data->rm_aid.p_aid,p_data->rm_aid.aid_len))
+    {
+        UINT32  xx;
+        tNFA_EE_ECB *p_cb = nfa_ee_cb.ecb;
+        for (xx = 0; xx < NFA_EE_MAX_EE_SUPPORTED; xx++, p_cb++)
+        {
+            memset(&p_cb->aid_cfg[0],0x00, sizeof(p_cb->aid_cfg));
+            memset(&p_cb->aid_len[0], 0x00, sizeof(p_cb->aid_len));
+            memset(&p_cb->aid_pwr_cfg[0], 0x00, sizeof(p_cb->aid_pwr_cfg));
+            memset(&p_cb->aid_rt_info[0], 0x00, sizeof(p_cb->aid_rt_info));
+            p_cb->aid_entries = 0;
+            nfa_ee_cb.ee_cfged      |= nfa_ee_ecb_to_mask(p_cb);
+        }
+
+        tNFA_EE_ECB *p_ecb = &nfa_ee_cb.ecb[NFA_EE_CB_4_DH];
+
+        memset(&p_ecb->aid_cfg[0],0x00, sizeof(p_ecb->aid_cfg));
+        memset(&p_ecb->aid_len[0], 0x00, sizeof(p_ecb->aid_len));
+        memset(&p_ecb->aid_pwr_cfg[0], 0x00, sizeof(p_ecb->aid_pwr_cfg));
+        memset(&p_ecb->aid_rt_info[0], 0x00, sizeof(p_ecb->aid_rt_info));
+        p_ecb->aid_entries = 0;
+        p_cb->ecb_flags         |= NFA_EE_ECB_FLAGS_AID;
+        nfa_ee_cb.ee_cfged      |= nfa_ee_ecb_to_mask(p_ecb);
+    }
+#endif
     else
     {
         NFA_TRACE_ERROR0 ("nfa_ee_api_remove_aid The AID entry is not in the database");
@@ -957,7 +1125,6 @@
             }
         }
 
-
         if (nfa_ee_cb.p_ee_disc_cback)
         {
             /* notify API callback */
@@ -968,6 +1135,15 @@
             NFA_EeGetInfo(&evt_data.ee_discover.num_ee, evt_data.ee_discover.ee_info);
             nfa_ee_report_event (p_cback, NFA_EE_DISCOVER_EVT, &evt_data);
         }
+#if(NXP_EXTNS == TRUE)
+        else
+        {
+            evt_data.status                         = NFA_STATUS_OK;
+            evt_data.ee_discover.num_ee             = NFA_EE_MAX_EE_SUPPORTED;
+            NFA_AllEeGetInfo(&evt_data.ee_discover.num_ee, evt_data.ee_discover.ee_info);
+            nfa_ee_report_event (NULL, NFA_EE_DISCOVER_EVT, &evt_data);
+        }
+#endif
     }
 }
 
@@ -1376,6 +1552,13 @@
         p_info->lb_protocol     = p_cb->lb_protocol;
         p_info->lf_protocol     = p_cb->lf_protocol;
         p_info->lbp_protocol    = p_cb->lbp_protocol;
+#if(NXP_EXTNS == TRUE)
+        // code to handle and store Reader type(A/B) requested for Reader over SWP.
+        /*Reader over SWP*/
+        p_info->pa_protocol    = p_cb->pa_protocol;
+        p_info->pb_protocol    = p_cb->pb_protocol;
+        p_info->ee_req_op      = p_cb->ee_req_op;
+#endif
         p_evt_data->num_ee++;
         p_info++;
 
@@ -1437,10 +1620,12 @@
         NFA_TRACE_ERROR1 ("nfa_ee_nci_mode_set_rsp() Can not find cb for handle:0x%02x", p_rsp->nfcee_id);
         return;
     }
-
+#if(NXP_EXTNS == TRUE)
+    /* Do not update routing table on secure element enable/disable. */
+#else
     /* update routing table and vs on mode change */
     nfa_ee_start_timer();
-
+#endif
     if (p_rsp->status == NFA_STATUS_OK)
     {
 
@@ -1450,6 +1635,9 @@
         }
         else
         {
+#if(NXP_EXTNS == TRUE)
+    /* Do not update routing table on secure element enable/disable. */
+#else
             if (p_cb->tech_switch_on | p_cb->tech_switch_off | p_cb->tech_battery_off |
                 p_cb->proto_switch_on| p_cb->proto_switch_off| p_cb->proto_battery_off |
                 p_cb->aid_entries)
@@ -1462,6 +1650,7 @@
             p_cb->tech_switch_on    = p_cb->tech_switch_off = p_cb->tech_battery_off    = 0;
             p_cb->proto_switch_on   = p_cb->proto_switch_off= p_cb->proto_battery_off   = 0;
             p_cb->aid_entries       = 0;
+#endif
             p_cb->ee_status = NFC_NFCEE_STATUS_INACTIVE;
         }
     }
@@ -1675,6 +1864,40 @@
     nfa_ee_report_event(NULL, NFA_EE_ACTION_EVT, (tNFA_EE_CBACK_DATA *)&evt_data);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfa_ee_get_supported_tech_list
+**
+** Description      provides the supported technology list of given nfcee id
+**
+** Returns          UINT8
+**
+*******************************************************************************/
+UINT8 nfa_ee_get_supported_tech_list(UINT8 nfcee_id)
+{
+    UINT8 tech_list = 0;
+    tNFA_EE_ECB         *p_cb = NULL;
+
+    p_cb = nfa_ee_find_ecb (nfcee_id);
+    if(p_cb)
+    {
+        if(p_cb->la_protocol)
+            tech_list |= NFA_TECHNOLOGY_MASK_A;
+        if(p_cb->lb_protocol)
+            tech_list |= NFA_TECHNOLOGY_MASK_B;
+        if(p_cb->lf_protocol)
+            tech_list |= NFA_TECHNOLOGY_MASK_F;
+    }
+    else
+    {
+        NFA_TRACE_DEBUG1 ("Cannot find cb for given nfcee_id: 0x%x", nfcee_id);
+    }
+    NFA_TRACE_DEBUG2 ("supported tech list is 0x0%x for given nfcee_id: 0x%x ",tech_list, nfcee_id);
+    return tech_list;
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         nfa_ee_nci_disc_req_ntf
@@ -1720,6 +1943,9 @@
         }
 
         p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_DISC_REQ;
+#if(NXP_EXTNS == TRUE)
+        p_cb->ee_req_op = p_cbk->info[xx].op;
+#endif
         if (p_cbk->info[xx].op == NFC_EE_DISC_OP_ADD)
         {
             if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_LISTEN_A)
@@ -1738,7 +1964,19 @@
             {
                 p_cb->lbp_protocol = p_cbk->info[xx].protocol;
             }
-            NFA_TRACE_DEBUG6 ("nfcee_id=0x%x ee_status=0x%x ecb_flags=0x%x la_protocol=0x%x la_protocol=0x%x la_protocol=0x%x",
+#if(NXP_EXTNS == TRUE)
+            //code to handle and store Reader type(A/B) requested for Reader over SWP.
+            /*Reader over SWP*/
+            else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_POLL_A)
+            {
+                p_cb->pa_protocol = p_cbk->info[xx].protocol;
+            }
+            else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_POLL_B)
+            {
+                p_cb->pb_protocol = p_cbk->info[xx].protocol;
+            }
+#endif
+            NFA_TRACE_DEBUG6 ("nfcee_id=0x%x ee_status=0x%x ecb_flags=0x%x la_protocol=0x%x lb_protocol=0x%x lf_protocol=0x%x",
                 p_cb->nfcee_id, p_cb->ee_status, p_cb->ecb_flags,
                 p_cb->la_protocol, p_cb->lb_protocol, p_cb->lf_protocol);
         }
@@ -1760,6 +1998,18 @@
             {
                 p_cb->lbp_protocol = 0;
             }
+#if(NXP_EXTNS == TRUE)
+            //code to handle and store Reader type(A/B) requested for Reader over SWP.
+            /*Reader over SWP*/
+            else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_POLL_A)
+            {
+                p_cb->pa_protocol = 0xFF;
+            }
+            else if (p_cbk->info[xx].tech_n_mode == NFC_DISCOVERY_TYPE_POLL_B)
+            {
+                p_cb->pb_protocol= 0xFF;
+            }
+#endif
         }
     }
 
@@ -1785,6 +2035,14 @@
     int     xx;
     tNFA_EE_ECB  *p_cb = nfa_ee_cb.ecb;
 
+#if(NXP_EXTNS == TRUE)
+    //Added case for NFCEE_DH.
+    if(nfcee_id == NFA_EE_HANDLE_DH)
+    {
+        is_active = TRUE;
+        goto TheEnd;
+    }
+#endif
     if ((NFA_HANDLE_GROUP_MASK & nfcee_id) == NFA_HANDLE_GROUP_EE)
         nfcee_id    &= NFA_HANDLE_MASK;
 
@@ -1800,6 +2058,9 @@
             break;
         }
     }
+#if(NXP_EXTNS == TRUE)
+TheEnd:
+#endif
     return is_active;
 }
 
@@ -1922,30 +2183,78 @@
     pp       = ps + 1 + *p_cur_offset;
     p        = pp;
     tlv_size = (UINT8)*p_cur_offset;
-    /* add the Technology based routing */
-    for (xx = 0; xx < NFA_EE_NUM_TECH; xx++)
+   /* Routing entries in the order of AID entries,protocol entries  and technology entries*/
+    /* add the AID routing */
+#if(NXP_EXTNS == TRUE)
+    if (p_cb->nfcee_id == NFC_DH_ID && p_cb->aid_entries)
+#else
+    if (p_cb->aid_entries)
+#endif
     {
-        power_cfg = 0;
-        if (p_cb->tech_switch_on & nfa_ee_tech_mask_list[xx])
-            power_cfg |= NCI_ROUTE_PWR_STATE_ON;
-        if (p_cb->tech_switch_off & nfa_ee_tech_mask_list[xx])
-            power_cfg |= NCI_ROUTE_PWR_STATE_SWITCH_OFF;
-        if (p_cb->tech_battery_off & nfa_ee_tech_mask_list[xx])
-            power_cfg |= NCI_ROUTE_PWR_STATE_BATT_OFF;
-        if (power_cfg)
+        start_offset = 0;
+        for (xx = 0; xx < p_cb->aid_entries; xx++)
         {
-            *pp++   = NFC_ROUTE_TAG_TECH;
-            *pp++   = 3;
-            *pp++   = p_cb->nfcee_id;
-            *pp++   = power_cfg;
-            *pp++   = nfa_ee_tech_list[xx];
-            num_tlv++;
-            if (power_cfg != NCI_ROUTE_PWR_STATE_ON)
-                nfa_ee_cb.ee_cfged  |= NFA_EE_CFGED_OFF_ROUTING;
+            p_start     = pp; /* rememebr the beginning of this AID routing entry, just in case we need to put it in next command */
+            /* add one AID entry */
+#if(NXP_EXTNS == TRUE)
+            if ((p_cb->aid_rt_info[xx] & NFA_EE_AE_ROUTE) &&
+                    ((nfa_ee_nfeeid_active(p_cb->aid_rt_loc[xx]) == TRUE) || (p_cb->aid_rt_loc[xx] == NFC_DH_ID)))
+#else
+            if (p_cb->aid_rt_info[xx] & NFA_EE_AE_ROUTE)
+#endif
+            {
+                num_tlv++;
+                pa      = &p_cb->aid_cfg[start_offset];
+                pa ++; /* EMV tag */
+                len     = *pa++; /* aid_len */
+#if(NXP_EXTNS == TRUE)
+                if(p_cb->aid_rt_info[xx] & NFA_EE_AE_NXP_PREFIX_MATCH) {
+                 //This aid is for prefix match.
+                 *pp++   = NFC_ROUTE_TAG_AID|NFA_EE_AE_NXP_PREFIX_MATCH;
+                } else {
+                  //This aid is for exact match.
+                  *pp++   = NFC_ROUTE_TAG_AID;
+                }
+#else
+                *pp++   = NFC_ROUTE_TAG_AID;
+#endif
+                *pp++   = len + 2;
+#if(NXP_EXTNS == TRUE)
+                *pp++   = p_cb->aid_rt_loc[xx];
+#else
+                *pp++   = p_cb->nfcee_id;
+#endif
+                *pp++   = p_cb->aid_pwr_cfg[xx];
+                /* copy the AID */
+                memcpy(pp, pa, len);
+                pp     += len;
+            }
+                start_offset += p_cb->aid_len[xx];
+                new_size        = (UINT8)(pp - p_start);
+                nfa_ee_check_set_routing(new_size, p_max_len, ps, p_cur_offset);
+                if (*ps == 0 && num_tlv > 0x00)
+                {
+                    /* just sent routing command, update local */
+                    *ps      = 1;
+                    num_tlv  = *ps;
+                    *p_cur_offset = new_size;
+                    pp       = ps + 1;
+                    p        = pp;
+                    tlv_size = (UINT8)*p_cur_offset;
+                    max_tlv  = (UINT8)((*p_max_len > NFA_EE_ROUT_MAX_TLV_SIZE)?NFA_EE_ROUT_MAX_TLV_SIZE:*p_max_len);
+                    memcpy (p, p_start, new_size);
+                    pp      += new_size;
+                }
+                else
+                {
+                    /* add the new entry */
+                    *ps              = num_tlv;
+                    *p_cur_offset   += new_size;
+                }
         }
     }
 
-    /* add the Protocol based routing */
+    /* Store the Protocol based routing in temporary buffer */
     for (xx = 0; xx < NFA_EE_NUM_PROTO; xx++)
     {
         power_cfg = 0;
@@ -1955,80 +2264,92 @@
             power_cfg |= NCI_ROUTE_PWR_STATE_SWITCH_OFF;
         if (p_cb->proto_battery_off & nfa_ee_proto_mask_list[xx])
             power_cfg |= NCI_ROUTE_PWR_STATE_BATT_OFF;
+#if(NXP_EXTNS == TRUE)
+
+        if(power_cfg != 0x00)
+        {
+            if (p_cb->nfcee_id == NFC_DH_ID)
+                power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_LOCK;
+            else
+
+            {
+                    if (p_cb->proto_screen_lock & nfa_ee_proto_mask_list[xx])
+                        power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_LOCK;
+                    if (p_cb->proto_screen_off & nfa_ee_proto_mask_list[xx])
+                        power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF;
+            }
+        }
+#endif
         if (power_cfg)
         {
-            *pp++   = NFC_ROUTE_TAG_PROTO;
-            *pp++   = 3;
-            *pp++   = p_cb->nfcee_id;
-            *pp++   = power_cfg;
-            *pp++   = nfa_ee_proto_list[xx];
-            num_tlv++;
+            *proto_pp++   = NFC_ROUTE_TAG_PROTO;
+            *proto_pp++   = 3;
+            *proto_pp++   = p_cb->nfcee_id;
+            *proto_pp++   = power_cfg;
+            *proto_pp++   = nfa_ee_proto_list[xx];
+            proto_tlv_ctr++;
             if (power_cfg != NCI_ROUTE_PWR_STATE_ON)
                 nfa_ee_cb.ee_cfged  |= NFA_EE_CFGED_OFF_ROUTING;
         }
     }
 
-    /* add NFC-DEP routing to HOST */
-    if (p_cb->nfcee_id == NFC_DH_ID)
+/* add NFC-DEP routing to HOST */
+    if((p_cb->nfcee_id == NFC_DH_ID)
+#if(NXP_EXTNS == TRUE)
+            && !(nfa_ee_cb.ee_flags & NFA_EE_FLAG_CFG_NFC_DEP)
+#endif
+    )
     {
-        *pp++   = NFC_ROUTE_TAG_PROTO;
-        *pp++   = 3;
-        *pp++   = NFC_DH_ID;
-        *pp++   = NCI_ROUTE_PWR_STATE_ON;
-        *pp++   = NFC_PROTOCOL_NFC_DEP;
-        num_tlv++;
-    }
-
-    /* update the num_tlv and current offset */
-    entry_size       = (UINT8)(pp - p);
-    *p_cur_offset   += entry_size;
-    *ps              = num_tlv;
-    /* add the AID routing */
-    if (p_cb->aid_entries)
-    {
-        start_offset = 0;
-        for (xx = 0; xx < p_cb->aid_entries; xx++)
+#if(NXP_EXTNS == TRUE)
+        nfa_ee_cb.ee_flags  |= NFA_EE_FLAG_CFG_NFC_DEP;
+#endif
+        *proto_pp++   = NFC_ROUTE_TAG_PROTO;
+        *proto_pp++   = 3;
+        *proto_pp++   = NFC_DH_ID;
+        if(gNfaProvisionMode)
         {
-            p_start     = pp; /* rememebr the beginning of this AID routing entry, just in case we need to put it in next command */
-            /* add one AID entry */
-            if (p_cb->aid_rt_info[xx] & NFA_EE_AE_ROUTE)
-            {
-                num_tlv++;
-                pa      = &p_cb->aid_cfg[start_offset];
-                pa ++; /* EMV tag */
-                len     = *pa++; /* aid_len */
-                *pp++   = NFC_ROUTE_TAG_AID;
-                *pp++   = len + 2;
-                *pp++   = p_cb->nfcee_id;
-                *pp++   = p_cb->aid_pwr_cfg[xx];
-                /* copy the AID */
-                memcpy(pp, pa, len);
-                pp     += len;
-            }
-            start_offset += p_cb->aid_len[xx];
-            new_size        = (UINT8)(pp - p_start);
-            nfa_ee_check_set_routing(new_size, p_max_len, ps, p_cur_offset);
-            if (*ps == 0)
-            {
-                /* just sent routing command, update local */
-                *ps      = 1;
-                num_tlv  = *ps;
-                *p_cur_offset = new_size;
-                pp       = ps + 1;
-                p        = pp;
-                tlv_size = (UINT8)*p_cur_offset;
-                max_tlv  = (UINT8)((*p_max_len > NFA_EE_ROUT_MAX_TLV_SIZE)?NFA_EE_ROUT_MAX_TLV_SIZE:*p_max_len);
-                memcpy (p, p_start, new_size);
-                pp      += new_size;
-            }
-            else
-            {
-                /* add the new entry */
-                *ps              = num_tlv;
-                *p_cur_offset   += new_size;
-            }
+            /* only if device is in provision mode, set power state to screen locked */
+            *proto_pp++   = 0x41;
         }
+        else
+        {
+            *proto_pp++   = 1;
+        }
+        *proto_pp++   = NFC_PROTOCOL_NFC_DEP;
+        proto_tlv_ctr++;
     }
+/* store  the Technology based routing entries in temporary buffer */
+for (xx = 0; xx < NFA_EE_NUM_TECH; xx++)
+{
+    power_cfg = 0;
+    if (p_cb->tech_switch_on & nfa_ee_tech_mask_list[xx])
+        power_cfg |= NCI_ROUTE_PWR_STATE_ON;
+    if (p_cb->tech_switch_off & nfa_ee_tech_mask_list[xx])
+        power_cfg |= NCI_ROUTE_PWR_STATE_SWITCH_OFF;
+    if (p_cb->tech_battery_off & nfa_ee_tech_mask_list[xx])
+        power_cfg |= NCI_ROUTE_PWR_STATE_BATT_OFF;
+#if(NXP_EXTNS == TRUE)
+
+        if(power_cfg & NCI_ROUTE_PWR_STATE_ON)
+        {
+            if (p_cb->tech_screen_lock & nfa_ee_tech_mask_list[xx])
+                power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_LOCK;
+            if (p_cb->tech_screen_off & nfa_ee_tech_mask_list[xx])
+                power_cfg |= NCI_ROUTE_PWR_STATE_SCREEN_OFF;
+        }
+#endif
+    if (power_cfg)
+    {
+        *tech_pp++   = NFC_ROUTE_TAG_TECH;
+        *tech_pp++   = 3;
+        *tech_pp++   = p_cb->nfcee_id;
+        *tech_pp++   = power_cfg;
+        *tech_pp++   = nfa_ee_tech_list[xx];
+        tech_tlv_ctr++;
+        if (power_cfg != NCI_ROUTE_PWR_STATE_ON)
+            nfa_ee_cb.ee_cfged  |= NFA_EE_CFGED_OFF_ROUTING;
+    }
+}
 
     tlv_size   = nfa_ee_total_lmrt_size();
     if (tlv_size)
@@ -2043,6 +2364,35 @@
 
     if (more == FALSE)
     {
+/* add the protocol entries and technology entries  after AID entries*/
+        new_size       = (UINT8)(proto_pp - proto_route_buff);
+        new_size       += (UINT8)(tech_pp - tech_route_buff);
+        nfa_ee_check_set_routing (new_size, p_max_len, ps, p_cur_offset);
+        if(*ps == 0)
+        {
+            p = ps +1;
+            num_tlv = (proto_tlv_ctr + tech_tlv_ctr);
+        }
+        else
+        {
+            num_tlv += proto_tlv_ctr;
+            num_tlv += tech_tlv_ctr;
+            p = ps + 1+ *p_cur_offset;
+        }
+        if(proto_tlv_ctr != 0)
+        {
+            new_size = (UINT8)(proto_pp - proto_route_buff);
+            memcpy (p,proto_route_buff,new_size);
+            *p_cur_offset += new_size;
+            p = p + new_size;
+        }
+        if(tech_tlv_ctr != 0)
+        {
+            new_size = (UINT8)(tech_pp - tech_route_buff);
+            memcpy (p,tech_route_buff,new_size);
+            *p_cur_offset += new_size;
+        }
+
         /* last entry. update routing table now */
         if (nfa_ee_cb.ee_cfg_sts & NFA_EE_STS_CHANGED_ROUTING)
         {
@@ -2217,16 +2567,43 @@
     tNFA_STATUS status = NFA_STATUS_FAILED;
     int     cur_offset;
     UINT8   max_tlv;
+#if(NXP_EXTNS == TRUE)
+    tNFA_EE_CBACK_DATA  evt_data = {0};
+#endif
 
     /* update routing table: DH and the activated NFCEEs */
     p = (UINT8 *)GKI_getbuf(NFA_EE_ROUT_BUF_SIZE);
     if (p == NULL)
     {
         NFA_TRACE_ERROR0 ("nfa_ee_lmrt_to_nfcc() no buffer to send routing info.");
+#if(NXP_EXTNS == TRUE)
+        evt_data.status = status;
+        nfa_ee_report_event( NULL, NFA_EE_NO_MEM_ERR_EVT, (tNFA_EE_CBACK_DATA *)&evt_data);
+#else
         nfa_ee_report_event( NULL, NFA_EE_NO_MEM_ERR_EVT, (tNFA_EE_CBACK_DATA *)&status);
+#endif
         return;
     }
 
+    proto_route_buff = (UINT8 *)GKI_getbuf(NFA_EE_PROTO_BUFF_SIZE);  /* Temporary buffer to store proto route entries */
+    tech_route_buff = (UINT8 *)GKI_getbuf(NFA_EE_TECH_BUFF_SIZE);  /* Temporary buffer to store tech route entries */
+
+    if(proto_route_buff == NULL ||tech_route_buff == NULL)
+    {
+        NFA_TRACE_ERROR0("nfa_ee_lmrt_to_nfcc() no temp buffer to send routing info.");
+#if(NXP_EXTNS == TRUE)
+        evt_data.status = status;
+        nfa_ee_report_event( NULL, NFA_EE_NO_MEM_ERR_EVT, (tNFA_EE_CBACK_DATA *)&evt_data);
+#else
+        nfa_ee_report_event( NULL, NFA_EE_NO_MEM_ERR_EVT, (tNFA_EE_CBACK_DATA *)&status);
+#endif
+        return;
+    }
+    proto_tlv_ctr = 0;
+    tech_tlv_ctr = 0;
+    proto_pp = proto_route_buff;
+    tech_pp = tech_route_buff;
+
     /* find the last active NFCEE. */
     p_cb = &nfa_ee_cb.ecb[nfa_ee_cb.cur_ee - 1];
     for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb--)
@@ -2244,7 +2621,9 @@
     {
         more = FALSE;
     }
-
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+    find_and_resolve_tech_conflict();
+#endif
     /* add the routing for DH first */
     status  = NFA_STATUS_OK;
     max_len = NFC_GetLmrtSize();
@@ -2275,13 +2654,150 @@
             }
         }
     }
+#if(NXP_EXTNS == TRUE)
+    nfa_ee_cb.ee_flags &= ~NFA_EE_FLAG_CFG_NFC_DEP;
+    evt_data.status = status;
+#endif
     if (status != NFA_STATUS_OK)
     {
+#if(NXP_EXTNS == TRUE)
+        nfa_ee_report_event( NULL, NFA_EE_ROUT_ERR_EVT, (tNFA_EE_CBACK_DATA *)&evt_data);
+#else
         nfa_ee_report_event( NULL, NFA_EE_ROUT_ERR_EVT, (tNFA_EE_CBACK_DATA *)&status);
+#endif
     }
     GKI_freebuf(p);
+    GKI_freebuf(proto_route_buff);
+    GKI_freebuf(tech_route_buff);
+    proto_tlv_ctr = 0;
+    tech_tlv_ctr = 0;
+    proto_pp = 0;
+    tech_pp = 0;
 }
 
+
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+/*******************************************************************************
+**
+** Function         find_and_resolve_tech_conflict
+**
+** Description      This function prefer the SE to resolve the technology conflict.
+**
+** Returns          void
+**
+*******************************************************************************/
+
+void find_and_resolve_tech_conflict()
+{
+    int yy,xx;
+    tNFA_EE_ECB *p_cb = nfa_ee_cb.ecb;
+    UINT8   techA_found=0, techF_found=0;
+    UINT8   techA_ee, techF_ee;
+    unsigned long preferred_se = 0x01;
+    BOOLEAN conflict = FALSE;
+    UINT8 tech_to_rm, ee_from_rm;
+
+    NFA_TRACE_DEBUG1 ("%s:Enter",__FUNCTION__);
+
+    //Finding the Technology and nfcee_id supported
+    for (yy = 0; yy < NFA_EE_MAX_EE_SUPPORTED; yy++, p_cb++)
+    {
+        for (xx = 0; xx < 3; xx++)
+        {
+            if((p_cb->tech_switch_on & nfa_ee_tech_mask_list[xx])== NFA_TECHNOLOGY_MASK_A)
+            {
+                techA_found |= NFA_TECHNOLOGY_MASK_A;
+                techA_ee     = p_cb->nfcee_id;
+            }
+            if((p_cb->tech_switch_off & nfa_ee_tech_mask_list[xx])==NFA_TECHNOLOGY_MASK_A)
+            {
+                techA_found |= NFA_TECHNOLOGY_MASK_A;
+                techA_ee     = p_cb->nfcee_id;
+            }
+            if((p_cb->tech_battery_off & nfa_ee_tech_mask_list[xx])==NFA_TECHNOLOGY_MASK_A)
+            {
+                techA_found |= NFA_TECHNOLOGY_MASK_A;
+                techA_ee     = p_cb->nfcee_id;
+            }
+            if((p_cb->tech_switch_on & nfa_ee_tech_mask_list[xx])==NFA_TECHNOLOGY_MASK_F)
+            {
+                techF_found |= NFA_TECHNOLOGY_MASK_F;
+                techF_ee     = p_cb->nfcee_id;
+            }
+            if((p_cb->tech_switch_off & nfa_ee_tech_mask_list[xx])==NFA_TECHNOLOGY_MASK_F)
+            {
+                techF_found |= NFA_TECHNOLOGY_MASK_F;
+                techF_ee     = p_cb->nfcee_id;
+            }
+            if((p_cb->tech_battery_off & nfa_ee_tech_mask_list[xx])==NFA_TECHNOLOGY_MASK_F)
+            {
+                techF_found |= NFA_TECHNOLOGY_MASK_F;
+                techF_ee     = p_cb->nfcee_id;
+            }
+        }
+    }
+
+    NFA_TRACE_DEBUG5 ("%s:p_cb->nfcee_id=0x%x,p_cb->tech_switch_on= 0x%x,p_cb->tech_switch_off= 0x%x,p_cb->tech_battery_off= 0x%x", __FUNCTION__, p_cb->nfcee_id,p_cb->tech_switch_on,p_cb->tech_switch_off,p_cb->tech_battery_off);
+
+    //Preferred SE Selected.
+    if((GetNumValue(NAME_NXP_PRFD_TECH_SE, &preferred_se, sizeof(preferred_se))))
+    {
+        NFA_TRACE_DEBUG2 ("%s:NXP_PRFD_TECH_SE=0x0%lu;", __FUNCTION__, preferred_se);
+        if(preferred_se==0x01)
+            preferred_se=0xc0; //Ese
+        else if(preferred_se==0x02)
+            preferred_se=0x02; //UICC
+    }
+    NFA_TRACE_DEBUG3 ("%s:techF_found=0x%x,techF_ee= 0x%x;", __FUNCTION__, techF_found,techF_ee);
+    NFA_TRACE_DEBUG3 ("%s:techA_found=0x%x,techA_ee= 0x%x;", __FUNCTION__, techA_found,techA_ee);
+
+    if(techA_found == NFA_TECHNOLOGY_MASK_A && techF_found == NFA_TECHNOLOGY_MASK_F)
+    {
+        if(techA_ee != 0x00 && techF_ee != 0x00)
+        {
+            //Conflict occurs when techF and techA on Different SE.
+            if(techA_ee != techF_ee)
+                conflict = TRUE;
+        }
+    }
+
+
+    if(conflict == TRUE)
+    {
+        NFA_TRACE_DEBUG0 ("Conflict true");
+
+        if(techF_ee == preferred_se)
+        {
+            tech_to_rm = NFA_TECHNOLOGY_MASK_A;
+            ee_from_rm = techA_ee;
+        }
+        else
+        {
+            tech_to_rm = NFA_TECHNOLOGY_MASK_F;
+            ee_from_rm = techF_ee;
+        }
+
+        p_cb = nfa_ee_cb.ecb;
+        for (yy = 0; yy < NFA_EE_MAX_EE_SUPPORTED; yy++, p_cb++)
+        {
+            if(p_cb->nfcee_id == ee_from_rm)
+            {
+                for (xx = 0; xx < 3; xx++)
+                {
+                    if(((p_cb->tech_switch_on & nfa_ee_tech_mask_list[xx])==tech_to_rm))
+                        p_cb->tech_switch_on &= ~tech_to_rm;
+                    if((p_cb->tech_switch_off & nfa_ee_tech_mask_list[xx])==tech_to_rm)
+                        p_cb->tech_switch_off &= ~tech_to_rm;
+                    if((p_cb->tech_battery_off & nfa_ee_tech_mask_list[xx])==tech_to_rm)
+                        p_cb->tech_battery_off &= ~tech_to_rm;
+                }
+            }
+        }
+        NFA_TRACE_DEBUG1 ("%s:Exit",__FUNCTION__);
+    }
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         nfa_ee_update_rout
@@ -2324,4 +2840,39 @@
     NFA_TRACE_DEBUG2 ("nfa_ee_update_rout ee_cfg_sts:0x%02x ee_cfged:0x%02x", nfa_ee_cb.ee_cfg_sts, nfa_ee_cb.ee_cfged);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfa_ee_lmrt_size
+**
+** Description      This function is called to get the AID routing table size.
+**
+** Returns          AID routing table currently used size.
+**
+*******************************************************************************/
+UINT16 nfa_ee_lmrt_size()
+{
+    NFA_TRACE_DEBUG0 ("nfa_ee_lmrt_size");
+    int     len;
+    len = nfa_all_ee_find_total_aid_len() + 2 /* tag/len */ + 2 /*route/power state*/;
 
+    return len < NFA_EE_MAX_AID_CFG_LEN?len:NFA_EE_MAX_AID_CFG_LEN;
+}
+
+BOOLEAN nfa_ee_nfeeid_active(UINT8 nfee_id)
+{
+    int xx;
+    tNFA_EE_ECB    *p_cb;
+    BOOLEAN status = FALSE;
+    p_cb = &nfa_ee_cb.ecb[0];
+    for (xx = 0; xx < nfa_ee_cb.cur_ee; xx++, p_cb++)
+    {
+        if ((p_cb->nfcee_id == nfee_id) && (p_cb->ee_status == NFC_NFCEE_STATUS_ACTIVE))
+        {
+            status = TRUE;
+            break;
+        }
+    }
+    return status;
+}
+#endif
diff --git a/src/nfa/ee/nfa_ee_api.c b/src/nfa/ee/nfa_ee_api.c
index 506db27..a4a837f 100644
--- a/src/nfa/ee/nfa_ee_api.c
+++ b/src/nfa/ee/nfa_ee_api.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -124,6 +142,13 @@
         p_info->ee_status       = p_cb->ee_status;
         p_info->num_interface   = p_cb->num_interface;
         p_info->num_tlvs        = p_cb->num_tlvs;
+
+#if(NXP_EXTNS == TRUE)
+        p_info->la_protocol =  p_cb->la_protocol;
+        p_info->lb_protocol =  p_cb->lb_protocol;
+        p_info->lf_protocol =  p_cb->lf_protocol;
+        p_info->lbp_protocol =  p_cb->lbp_protocol;
+#endif
         memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
         memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
         p_info++;
@@ -134,6 +159,89 @@
     return (NFA_STATUS_OK);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_AllEeGetInfo
+**
+** Description      This function retrieves the NFCEE information from NFA.
+**                  The actual number of NFCEE independent of their status
+**                  is returned in p_num_nfcee and NFCEE information is returned
+**                  in p_info
+**
+** Returns          NFA_STATUS_OK if information is retrieved successfully
+**                  NFA_STATUS_FAILED If wrong state (retry later)
+**                  NFA_STATUS_INVALID_PARAM If bad parameter
+**
+*******************************************************************************/
+tNFA_STATUS NFA_AllEeGetInfo(UINT8        *p_num_nfcee,
+                             tNFA_EE_INFO *p_info)
+{
+    int   xx, ret = nfa_ee_cb.cur_ee;
+    tNFA_EE_ECB  *p_cb = nfa_ee_cb.ecb;
+    UINT8   max_ret;
+    UINT8   num_ret  = 0;
+
+    NFA_TRACE_DEBUG2 ("NFA_AllEeGetInfo em_state:%d cur_ee:%d", nfa_ee_cb.em_state, nfa_ee_cb.cur_ee);
+    /* validate parameters */
+    if (p_info == NULL || p_num_nfcee == NULL)
+    {
+        NFA_TRACE_ERROR0 ("NFA_AllEeGetInfo bad parameter");
+        return (NFA_STATUS_INVALID_PARAM);
+    }
+    max_ret         = *p_num_nfcee;
+    *p_num_nfcee = 0;
+    if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_INIT)
+    {
+        NFA_TRACE_ERROR1 ("NFA_AllEeGetInfo bad em state: %d", nfa_ee_cb.em_state);
+        return (NFA_STATUS_FAILED);
+    }
+
+    /* compose output */
+    for (xx = 0; (xx < ret) && (num_ret < max_ret); xx++, p_cb++)
+    {
+        NFA_TRACE_DEBUG4 ("xx:%d max_ret:%d, num_ret:%d ee_status:0x%x", xx, max_ret, num_ret, p_cb->ee_status);
+        if (p_cb->ee_status & NFA_EE_STATUS_INT_MASK)
+        {
+            continue;
+        }
+        p_info->ee_handle       = NFA_HANDLE_GROUP_EE | (tNFA_HANDLE)p_cb->nfcee_id;
+        p_info->ee_status       = p_cb->ee_status;
+        p_info->num_interface   = p_cb->num_interface;
+        p_info->num_tlvs        = p_cb->num_tlvs;
+
+#if(NXP_EXTNS == TRUE)
+        p_info->la_protocol =  p_cb->la_protocol;
+        p_info->lb_protocol =  p_cb->lb_protocol;
+        p_info->lf_protocol =  p_cb->lf_protocol;
+        p_info->lbp_protocol =  p_cb->lbp_protocol;
+#endif
+        memcpy(p_info->ee_interface, p_cb->ee_interface, p_cb->num_interface);
+        memcpy(p_info->ee_tlv, p_cb->ee_tlv, p_cb->num_tlvs * sizeof(tNFA_EE_TLV));
+        p_info++;
+        num_ret++;
+    }
+    NFA_TRACE_DEBUG1 ("num_ret:%d", num_ret);
+    *p_num_nfcee = num_ret;
+    return (NFA_STATUS_OK);
+}
+
+/*******************************************************************************
+**
+** Function         NFA_setProvisionMode
+**
+** Description      This function is used to set/reset the provision mode info
+**
+** Returns          None
+**
+*******************************************************************************/
+void NFA_setProvisionMode(BOOLEAN provisionMode)
+{
+    NFA_TRACE_API1 ("NFA_setProvisionMode(), provisionMode:%d", provisionMode);
+    gNfaProvisionMode = provisionMode;
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         NFA_EeRegister
@@ -293,15 +401,20 @@
 tNFA_STATUS NFA_EeSetDefaultTechRouting(tNFA_HANDLE          ee_handle,
                                         tNFA_TECHNOLOGY_MASK technologies_switch_on,
                                         tNFA_TECHNOLOGY_MASK technologies_switch_off,
-                                        tNFA_TECHNOLOGY_MASK technologies_battery_off)
+                                        tNFA_TECHNOLOGY_MASK technologies_battery_off
+#if(NXP_EXTNS == TRUE)
+                                       ,tNFA_TECHNOLOGY_MASK technologies_screen_lock,
+                                        tNFA_TECHNOLOGY_MASK technologies_screen_off
+#endif
+)
 {
     tNFA_EE_API_SET_TECH_CFG *p_msg;
     tNFA_STATUS status = NFA_STATUS_FAILED;
     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
     tNFA_EE_ECB *p_cb;
 
-    NFA_TRACE_API4 ("NFA_EeSetDefaultTechRouting(): handle:<0x%x>technology_mask:<0x%x>/<0x%x>/<0x%x>",
-        ee_handle, technologies_switch_on, technologies_switch_off, technologies_battery_off);
+    NFA_TRACE_API6 ("NFA_EeSetDefaultTechRouting(): handle:<0x%x>technology_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x>",
+        ee_handle, technologies_switch_on, technologies_switch_off, technologies_battery_off, technologies_screen_lock, technologies_screen_off );
     p_cb = nfa_ee_find_ecb (nfcee_id);
 
     if (p_cb == NULL)
@@ -317,7 +430,10 @@
         p_msg->technologies_switch_on   = technologies_switch_on;
         p_msg->technologies_switch_off  = technologies_switch_off;
         p_msg->technologies_battery_off = technologies_battery_off;
-
+#if(NXP_EXTNS == TRUE)
+        p_msg->technologies_screen_lock = technologies_screen_lock;
+        p_msg->technologies_screen_off  = technologies_screen_off;
+#endif
         nfa_sys_sendmsg (p_msg);
 
         status = NFA_STATUS_OK;
@@ -349,15 +465,20 @@
 tNFA_STATUS NFA_EeSetDefaultProtoRouting(tNFA_HANDLE         ee_handle,
                                          tNFA_PROTOCOL_MASK  protocols_switch_on,
                                          tNFA_PROTOCOL_MASK  protocols_switch_off,
-                                         tNFA_PROTOCOL_MASK  protocols_battery_off)
+                                         tNFA_PROTOCOL_MASK  protocols_battery_off
+#if(NXP_EXTNS == TRUE)
+                                        ,tNFA_PROTOCOL_MASK  protocols_screen_lock,
+                                         tNFA_PROTOCOL_MASK  protocols_screen_off
+#endif
+)
 {
     tNFA_EE_API_SET_PROTO_CFG *p_msg;
     tNFA_STATUS status = NFA_STATUS_FAILED;
     UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
     tNFA_EE_ECB *p_cb;
 
-    NFA_TRACE_API4 ("NFA_EeSetDefaultProtoRouting(): handle:<0x%x>protocol_mask:<0x%x>/<0x%x>/<0x%x>",
-        ee_handle, protocols_switch_on, protocols_switch_off, protocols_battery_off);
+    NFA_TRACE_API6 ("NFA_EeSetDefaultProtoRouting(): handle:<0x%x>protocol_mask:<0x%x>/<0x%x>/<0x%x><0x%x><0x%x>",
+        ee_handle, protocols_switch_on, protocols_switch_off, protocols_battery_off, protocols_screen_lock, protocols_screen_off);
     p_cb = nfa_ee_find_ecb (nfcee_id);
 
     if (p_cb == NULL)
@@ -373,7 +494,10 @@
         p_msg->protocols_switch_on      = protocols_switch_on;
         p_msg->protocols_switch_off     = protocols_switch_off;
         p_msg->protocols_battery_off    = protocols_battery_off;
-
+#if(NXP_EXTNS == TRUE)
+        p_msg->protocols_screen_lock     = protocols_screen_lock;
+        p_msg->protocols_screen_off    = protocols_screen_off;
+#endif
         nfa_sys_sendmsg (p_msg);
 
         status = NFA_STATUS_OK;
@@ -404,7 +528,12 @@
 tNFA_STATUS NFA_EeAddAidRouting(tNFA_HANDLE          ee_handle,
                                 UINT8                aid_len,
                                 UINT8               *p_aid,
-                                tNFA_EE_PWR_STATE    power_state)
+                                tNFA_EE_PWR_STATE    power_state
+#if(NXP_EXTNS == TRUE)
+                                , UINT8              vs_info)
+#else
+)
+#endif
 {
     tNFA_EE_API_ADD_AID *p_msg;
     tNFA_STATUS status = NFA_STATUS_FAILED;
@@ -430,6 +559,9 @@
         p_msg->aid_len          = aid_len;
         p_msg->power_state      = power_state;
         p_msg->p_aid            = (UINT8 *)(p_msg + 1);
+#if(NXP_EXTNS == TRUE)
+        p_msg->vs_info          = vs_info;
+#endif
         memcpy(p_msg->p_aid, p_aid, aid_len);
 
         nfa_sys_sendmsg (p_msg);
@@ -440,6 +572,118 @@
     return status;
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_AddEePowerState
+**
+** Description      This function is called to add power state in the
+**                  listen mode routing table in NFCC.
+**
+** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
+**                  should happen before calling this function
+**
+** Note:            NFA_EeUpdateNow() should be called after last NFA-EE function
+**                  to change the listen mode routing is called.
+**
+** Returns          NFA_STATUS_OK if successfully initiated
+**                  NFA_STATUS_FAILED otherwise
+**                  NFA_STATUS_INVALID_PARAM If bad parameter
+**
+*******************************************************************************/
+tNFA_STATUS NFA_AddEePowerState(tNFA_HANDLE          ee_handle,
+                                tNFA_EE_PWR_STATE    power_state_mask)
+{
+    tNFA_STATUS status = NFA_STATUS_FAILED;
+    UINT8       nfcee_id = (UINT8)(ee_handle & 0xFF);
+    tNFA_EE_ECB *p_cb;
+    UINT8 xx  = 0 ;
+
+    NFA_TRACE_API1 ("NFA_AddEePowerState(): handle:<0x%x>", ee_handle);
+    p_cb = nfa_ee_find_ecb (nfcee_id);
+
+    /* validate parameters */
+    if ((p_cb == NULL))
+    {
+        status = NFA_STATUS_INVALID_PARAM;
+        return status;
+    }
+
+    if((power_state_mask & NFA_EE_PWR_STATE_SWITCH_OFF) != 0x00)
+    {
+        for(xx=0; xx < p_cb->aid_entries; xx++)
+        {
+            p_cb->aid_pwr_cfg[xx] |= power_state_mask;
+            p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_AID;
+        }
+
+        /* For tech and proto only enable power off mode*/
+        p_cb->proto_switch_off |= p_cb->proto_switch_on;
+        p_cb->tech_switch_off |= p_cb->tech_switch_on;
+    }
+    else
+    {
+        for(xx=0; xx < p_cb->aid_entries; xx++)
+        {
+            p_cb->aid_pwr_cfg[xx] &= power_state_mask;
+            p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_AID;
+        }
+
+        p_cb->proto_switch_off &= 0x00;
+        p_cb->tech_switch_off &= 0x00;
+    }
+
+    p_cb->ecb_flags |= NFA_EE_ECB_FLAGS_TECH|NFA_EE_ECB_FLAGS_PROTO;
+
+    return status;
+}
+
+/*******************************************************************************
+**
+** Function         NFA_GetAidTableSize
+**
+** Description      This function is called to get the Maximum AID routing table size.
+**
+** Returns          AID routing table maximum size
+**
+*******************************************************************************/
+UINT16 NFA_GetAidTableSize()
+{
+    return NFA_EE_MAX_AID_CFG_LEN;
+}
+
+/*******************************************************************************
+**
+** Function         NFA_GetRemainingAidTableSize
+**
+** Description      This function is called to get the remaining AID routing
+**                  table size.
+**
+** Returns          Remaining AID routing table size.
+**
+*******************************************************************************/
+UINT16 NFA_GetRemainingAidTableSize()
+{
+    UINT16 size = 0;
+
+    size = NFA_EE_MAX_AID_CFG_LEN - nfa_ee_lmrt_size();
+
+    return size ;
+}
+/*******************************************************************************
+**
+** Function         NFA_SetCEStrictDisable
+**
+** Description      This function is called to set the flag for Strict CE.
+**
+** Returns          None.
+**
+*******************************************************************************/
+void NFA_SetCEStrictDisable(UINT32 state)
+{
+    nfa_ee_ce_route_strict_disable = (UINT8)state;
+}
+#endif
 
 /*******************************************************************************
 **
diff --git a/src/nfa/ee/nfa_ee_main.c b/src/nfa/ee/nfa_ee_main.c
index 70b87d4..0597b62 100644
--- a/src/nfa/ee/nfa_ee_main.c
+++ b/src/nfa/ee/nfa_ee_main.c
@@ -15,8 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  This is the main implementation file for the NFA EE.
@@ -39,6 +56,12 @@
 tNFA_EE_CB nfa_ee_cb;
 #endif
 
+#if(NXP_EXTNS == TRUE)
+#ifndef NFA_EE_DISCV_TIMEOUT_VAL
+#define NFA_EE_DISCV_TIMEOUT_VAL    4000 //Wait for UICC Init complete.
+#endif
+#endif
+
 /*****************************************************************************
 **  Constants
 *****************************************************************************/
@@ -673,6 +696,15 @@
     NFA_TRACE_DEBUG2 ("nfa_ee_evt_hdlr (): Event 0x%02x, State: %d", p_evt_data->hdr.event, nfa_ee_cb.em_state);
 #endif
 
+#if(NXP_EXTNS == TRUE)
+    /*This is required to receive Reader Over SWP event*/
+    if(p_evt_data->hdr.event == NFA_EE_NCI_DISC_NTF_EVT)
+    {
+        NFA_TRACE_DEBUG0("recived dis_ntf; stopping timer");
+        nfa_sys_stop_timer(&nfa_ee_cb.discv_timer);
+    }
+#endif
+
     switch (nfa_ee_cb.em_state)
     {
     case NFA_EE_EM_STATE_INIT_DONE:
@@ -704,5 +736,3 @@
 
     return TRUE;
 }
-
-
diff --git a/src/nfa/hci/nfa_hci_act.c b/src/nfa/hci/nfa_hci_act.c
index 77218c3..f77c48b 100644
--- a/src/nfa/hci/nfa_hci_act.c
+++ b/src/nfa/hci/nfa_hci_act.c
@@ -15,8 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  This file contains the action functions for the NFA HCI.
@@ -1049,6 +1066,7 @@
                         {
                             nfa_hci_cb.w4_rsp_evt   = TRUE;
                             nfa_hci_cb.hci_state    = NFA_HCI_STATE_WAIT_RSP;
+
                             nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, p_evt_data->send_evt.rsp_timeout);
                         }
                         else if (p_pipe->local_gate == NFA_HCI_LOOP_BACK_GATE)
@@ -1283,7 +1301,14 @@
         STREAM_TO_UINT8 (pipe,        p_data);
 
         if (  (dest_gate == NFA_HCI_IDENTITY_MANAGEMENT_GATE)
-            ||(dest_gate == NFA_HCI_LOOP_BACK_GATE) )
+            ||(dest_gate == NFA_HCI_LOOP_BACK_GATE)
+#if(NXP_EXTNS == TRUE)
+#ifdef GEMALTO_SE_SUPPORT
+            ||(dest_gate == NFC_HCI_DEFAULT_DEST_GATE)
+            ||(dest_gate == NFA_HCI_CONNECTIVITY_GATE)
+#endif
+#endif
+        )
         {
             response = nfa_hciu_add_pipe_to_static_gate (dest_gate, pipe, source_host, source_gate);
         }
@@ -1413,6 +1438,7 @@
         switch (nfa_hci_cb.cmd_sent)
         {
         case NFA_HCI_ANY_SET_PARAMETER:
+#if(NXP_EXTNS != TRUE)
             if (nfa_hci_cb.param_in_use == NFA_HCI_SESSION_IDENTITY_INDEX)
             {
                 /* Set WHITELIST */
@@ -1424,6 +1450,32 @@
                     ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE)  )
                     nfa_hci_dh_startup_complete ();
             }
+#else
+            if (nfa_hci_cb.param_in_use == NFA_HCI_WHITELIST_INDEX)
+            {
+                if (nfa_hci_cb.b_hci_netwk_reset)
+                {
+                    nfa_hci_cb.b_hci_netwk_reset = FALSE;
+                   /* Session ID is reset, Set New session id */
+                    memcpy (&nfa_hci_cb.cfg.admin_gate.session_id[NFA_HCI_SESSION_ID_LEN / 2], nfa_hci_cb.cfg.admin_gate.session_id, (NFA_HCI_SESSION_ID_LEN / 2));
+                    os_tick = GKI_get_os_tick_count ();
+                    memcpy (nfa_hci_cb.cfg.admin_gate.session_id, (UINT8 *)&os_tick, (NFA_HCI_SESSION_ID_LEN / 2));
+                    nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX, NFA_HCI_SESSION_ID_LEN, (UINT8 *) nfa_hci_cb.cfg.admin_gate.session_id);
+                }
+                else
+                {
+                    /* First thing is to get the session ID */
+                    nfa_hciu_send_get_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX);
+                }
+            }
+            else if (nfa_hci_cb.param_in_use == NFA_HCI_SESSION_IDENTITY_INDEX)
+            {
+                nfa_hci_network_enable();
+                if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP)
+                    ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE)  )
+                    nfa_hci_dh_startup_complete ();
+            }
+#endif
             break;
 
         case NFA_HCI_ANY_GET_PARAMETER:
@@ -1458,14 +1510,29 @@
                 /* The only parameter we get when initializing is the session ID. Check for match. */
                 if (!memcmp ((UINT8 *) nfa_hci_cb.cfg.admin_gate.session_id, p_data, NFA_HCI_SESSION_ID_LEN) )
                 {
+#if(NXP_EXTNS == TRUE)
+                    nfa_hci_network_enable();
+                    if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP)
+                        ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE)  )
+                        nfa_hci_dh_startup_complete ();
+#else
                     /* Session has not changed, Set WHITELIST */
                     nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_WHITELIST_INDEX, p_nfa_hci_cfg->num_whitelist_host, p_nfa_hci_cfg->p_whitelist);
+#endif
                 }
                 else
                 {
+#if(NXP_EXTNS == TRUE)
+                    /* Session ID is reset, Set New session id */
+                    memcpy (&nfa_hci_cb.cfg.admin_gate.session_id[NFA_HCI_SESSION_ID_LEN / 2], nfa_hci_cb.cfg.admin_gate.session_id, (NFA_HCI_SESSION_ID_LEN / 2));
+                    os_tick = GKI_get_os_tick_count ();
+                    memcpy (nfa_hci_cb.cfg.admin_gate.session_id, (UINT8 *)&os_tick, (NFA_HCI_SESSION_ID_LEN / 2));
+                    nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX, NFA_HCI_SESSION_ID_LEN, (UINT8 *) nfa_hci_cb.cfg.admin_gate.session_id);
+#else
                     /* Something wrong, NVRAM data could be corrupt or first start with default session id */
                     nfa_hciu_send_clear_all_pipe_cmd ();
                     nfa_hci_cb.b_hci_netwk_reset = TRUE;
+#endif
                 }
             }
             break;
@@ -1473,6 +1540,7 @@
         case NFA_HCI_ANY_OPEN_PIPE:
             nfa_hci_cb.cfg.admin_gate.pipe01_state = NFA_HCI_PIPE_OPENED;
 
+#if(NXP_EXTNS != TRUE)
             if (nfa_hci_cb.b_hci_netwk_reset)
             {
                 nfa_hci_cb.b_hci_netwk_reset = FALSE;
@@ -1487,6 +1555,9 @@
                 /* First thing is to get the session ID */
                 nfa_hciu_send_get_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX);
             }
+#else
+            nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_WHITELIST_INDEX, p_nfa_hci_cfg->num_whitelist_host, p_nfa_hci_cfg->p_whitelist);
+#endif
             break;
 
         case NFA_HCI_ADM_CLEAR_ALL_PIPE:
@@ -1763,6 +1834,31 @@
     {
         nfa_hci_handle_connectivity_gate_pkt (p_data, data_len, p_pipe);
     }
+#if(NXP_EXTNS == TRUE)
+#ifdef GEMALTO_SE_SUPPORT
+    else if (p_pipe->local_gate == NFC_HCI_DEFAULT_DEST_GATE)
+    {
+        /* Check if data packet is a command, response or event */
+        p_gate = nfa_hci_cb.cfg.dyn_gates;
+        p_gate->gate_owner = 0x0800;
+
+        switch (nfa_hci_cb.type)
+        {
+        case NFA_HCI_COMMAND_TYPE:
+            nfa_hci_handle_generic_gate_cmd (p_data, (UINT8) data_len, p_gate, p_pipe);
+            break;
+
+        case NFA_HCI_RESPONSE_TYPE:
+            nfa_hci_handle_generic_gate_rsp (p_data, (UINT8) data_len, p_gate, p_pipe);
+            break;
+
+        case NFA_HCI_EVENT_TYPE:
+            nfa_hci_handle_generic_gate_evt (p_data, data_len, p_gate, p_pipe);
+            break;
+        }
+    }
+#endif
+#endif
     else
     {
         p_gate = nfa_hciu_find_gate_by_gid (p_pipe->local_gate);
@@ -2196,10 +2292,16 @@
         evt_data.rcvd_evt.status    = NFA_STATUS_OK;
 
     evt_data.rcvd_evt.p_evt_buf = p_data;
-    nfa_hci_cb.rsp_buf_size     = 0;
-    nfa_hci_cb.p_rsp_buf        = NULL;
+#if(NXP_EXTNS == TRUE)
+    if(nfa_hci_cb.inst != NFA_HCI_EVT_WTX)
+    {
+#endif
+        nfa_hci_cb.rsp_buf_size     = 0;
+        nfa_hci_cb.p_rsp_buf        = NULL;
+#if(NXP_EXTNS == TRUE)
+    }
+#endif
 
     /* notify NFA_HCI_EVENT_RCVD_EVT to the application */
     nfa_hciu_send_to_app (NFA_HCI_EVENT_RCVD_EVT, &evt_data, p_gate->gate_owner);
 }
-
diff --git a/src/nfa/hci/nfa_hci_api.c b/src/nfa/hci/nfa_hci_api.c
index 8fb268f..4667f13 100644
--- a/src/nfa/hci/nfa_hci_api.c
+++ b/src/nfa/hci/nfa_hci_api.c
@@ -15,14 +15,32 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  NFA interface to HCI
  *
  ******************************************************************************/
 #include <string.h>
+#include <unistd.h>
 #include "nfc_api.h"
 #include "nfa_sys.h"
 #include "nfa_sys_int.h"
@@ -911,13 +929,13 @@
         NFA_TRACE_API1 ("NFA_HciAddStaticPipe (): Invalid Gate:0x%02x", gate);
         return (NFA_STATUS_FAILED);
     }
-
+#if(NXP_EXTNS != TRUE)
     if (pipe <= NFA_HCI_LAST_DYNAMIC_PIPE)
     {
         NFA_TRACE_API1 ("NFA_HciAddStaticPipe (): Invalid Pipe:0x%02x", pipe);
         return (NFA_STATUS_FAILED);
     }
-
+#endif
     NFA_TRACE_API2 ("NFA_HciAddStaticPipe (): hci_handle:0x%04x, pipe:0x%02X", hci_handle, pipe);
 
     /* Request HCI to delete a pipe created by the application identified by hci handle */
@@ -1011,3 +1029,39 @@
         break;
     }
 }
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_HciW4eSETransaction_Complete
+**
+** Description      This function is called to wait for eSE transaction
+**                  to complete before NFCC shutdown or NFC service turn OFF
+**
+** Returns          None
+**
+*******************************************************************************/
+void NFA_HciW4eSETransaction_Complete(tNFA_HCI_TRANSCV_STATE type)
+{
+    NFA_TRACE_API1 ("NFA_HciW4eSETransaction_Complete; type=%u", type);
+    UINT8 retry_cnt = 0;
+    UINT8 max_time =NFA_HCI_MAX_RSP_WAIT_TIME;
+
+    if(type == Release)
+    {
+        nfa_hci_release_transcieve();
+    }
+    else
+    {
+        do
+        {
+            if(nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_RSP)
+            {
+                sleep(1);
+            }
+            else
+                break;
+        }while(retry_cnt++ < max_time);
+    }
+    NFA_TRACE_API0 ("NFA_HciW4eSETransaction_Complete; End");
+}
+#endif
diff --git a/src/nfa/hci/nfa_hci_ci.c b/src/nfa/hci/nfa_hci_ci.c
index 73f2bdb..808dff0 100644
--- a/src/nfa/hci/nfa_hci_ci.c
+++ b/src/nfa/hci/nfa_hci_ci.c
@@ -78,4 +78,3 @@
         nfa_sys_sendmsg (p_msg);
     }
 }
-
diff --git a/src/nfa/hci/nfa_hci_main.c b/src/nfa/hci/nfa_hci_main.c
index 7558919..6f8f787 100644
--- a/src/nfa/hci/nfa_hci_main.c
+++ b/src/nfa/hci/nfa_hci_main.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -60,10 +78,14 @@
 
 static void nfa_hci_sys_enable (void);
 static void nfa_hci_sys_disable (void);
-static void nfa_hci_rsp_timeout (tNFA_HCI_EVENT_DATA *p_evt_data);
 static void nfa_hci_conn_cback (UINT8 conn_id, tNFC_CONN_EVT event, tNFC_CONN *p_data);
 static void nfa_hci_set_receive_buf (UINT8 pipe);
+#if (NXP_EXTNS == TRUE)
+void nfa_hci_rsp_timeout (tNFA_HCI_EVENT_DATA *p_evt_data);
+static void nfa_hci_assemble_msg (UINT8 *p_data, UINT16 data_len, UINT8 pipe);
+#else
 static void nfa_hci_assemble_msg (UINT8 *p_data, UINT16 data_len);
+#endif
 static void nfa_hci_handle_nv_read (UINT8 block, tNFA_STATUS status);
 
 /*****************************************************************************
@@ -99,12 +121,12 @@
         if (  (!nfa_hci_cb.ee_disc_cmplt)
             &&((nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP) || (nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE))  )
         {
-        /* NFCEE Discovery is in progress */
-        nfa_hci_cb.ee_disc_cmplt      = TRUE;
-        nfa_hci_cb.num_ee_dis_req_ntf = 0;
-        nfa_hci_cb.num_hot_plug_evts  = 0;
-        nfa_hci_cb.conn_id            = 0;
-        nfa_hci_startup ();
+            /* NFCEE Discovery is in progress */
+            nfa_hci_cb.ee_disc_cmplt      = TRUE;
+            nfa_hci_cb.num_ee_dis_req_ntf = 0;
+            nfa_hci_cb.num_hot_plug_evts  = 0;
+            nfa_hci_cb.conn_id            = 0;
+            nfa_hci_startup ();
         }
         break;
 
@@ -150,6 +172,14 @@
     case NFA_EE_DISC_STS_REQ:
         nfa_hci_cb.num_ee_dis_req_ntf++;
 
+#if(NXP_EXTNS == TRUE)
+        if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_NETWK_ENABLE)
+            ||(nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE_NETWK_ENABLE)  )
+        {
+            nfa_sys_stop_timer (&nfa_hci_cb.timer);
+            nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, 150);
+        }
+#endif
         if (nfa_hci_cb.ee_disable_disc)
         {
             /* Already received Discovery Ntf */
@@ -216,9 +246,10 @@
     UINT8       xx,yy,zz;
     tNFA_HANDLE reg_app[NFA_HCI_MAX_APP_CB];
     UINT8       valid_gate[NFA_HCI_MAX_GATE_CB];
-    UINT8       app_count       = 0;
-    UINT8       gate_count      = 0;
-    UINT32      pipe_inx_mask   = 0;
+    UINT8       app_count             = 0;
+    UINT8       gate_count            = 0;
+    UINT32      pipe_inx_mask         = 0;
+    UINT8       validated_gate_count  = 0;
 
     /* First, see if valid values are stored in app names, send connectivity events flag */
     for (xx = 0; xx < NFA_HCI_MAX_APP_CB; xx++)
@@ -339,16 +370,20 @@
                 ||(nfa_hci_cb.cfg.dyn_pipes[xx].dest_gate > NFA_HCI_LAST_PROP_GATE))
                 return FALSE;
 
-            /* Check if the same pipe is present more than once in the control block */
-            for (yy = xx + 1; yy < NFA_HCI_MAX_PIPE_CB; yy++)
+            if((xx + 1) < NFA_HCI_MAX_PIPE_CB)
             {
-                if (  (nfa_hci_cb.cfg.dyn_pipes[yy].pipe_id != 0)
-                    &&(nfa_hci_cb.cfg.dyn_pipes[xx].pipe_id == nfa_hci_cb.cfg.dyn_pipes[yy].pipe_id) )
+                /* Check if the same pipe is present more than once in the control block */
+                for (yy = xx + 1; yy < NFA_HCI_MAX_PIPE_CB; yy++)
                 {
-                    NFA_TRACE_EVENT1 ("nfa_hci_is_valid_cfg  Reusing: %u", nfa_hci_cb.cfg.dyn_pipes[xx].pipe_id);
-                    return FALSE;
+                    if (  (nfa_hci_cb.cfg.dyn_pipes[yy].pipe_id != 0)
+                        &&(nfa_hci_cb.cfg.dyn_pipes[xx].pipe_id == nfa_hci_cb.cfg.dyn_pipes[yy].pipe_id) )
+                    {
+                        NFA_TRACE_EVENT1 ("nfa_hci_is_valid_cfg  Reusing: %u", nfa_hci_cb.cfg.dyn_pipes[xx].pipe_id);
+                        return FALSE;
+                    }
                 }
             }
+#if(NXP_EXTNS == FALSE)
             /* The local gate should be one of the element in gate control block */
             for (zz = 0; zz < gate_count; zz++)
             {
@@ -360,8 +395,27 @@
                 NFA_TRACE_EVENT1 ("nfa_hci_is_valid_cfg  Invalid Gate: %u", nfa_hci_cb.cfg.dyn_pipes[xx].local_gate);
                 return FALSE;
             }
+#else
+            /* The local gate should be one of the element in gate control block */
+            for (zz = 0; zz < gate_count; zz++)
+            {
+                if (nfa_hci_cb.cfg.dyn_pipes[xx].local_gate == valid_gate[zz])
+                {
+                    validated_gate_count ++;
+                    break;
+                }
+            }
+
+#endif
         }
     }
+#if(NXP_EXTNS == TRUE)
+    if (validated_gate_count != gate_count && xx < NFA_HCI_MAX_PIPE_CB)
+    {
+        NFA_TRACE_EVENT1 ("nfa_hci_is_valid_cfg  Invalid Gate: %u", nfa_hci_cb.cfg.dyn_pipes[xx].local_gate);
+        return FALSE;
+    }
+#endif
 
     /* Check if admin pipe state is valid */
     if (  (nfa_hci_cb.cfg.admin_gate.pipe01_state != NFA_HCI_PIPE_OPENED)
@@ -468,6 +522,22 @@
 *******************************************************************************/
 void nfa_hci_dh_startup_complete (void)
 {
+//NFC-INIT MACH
+#if(NXP_EXTNS == TRUE)
+    if(nfa_hci_cb.ee_disable_disc)
+    {
+        if(nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP &&
+                nfa_hci_cb.num_nfcee >= 1)
+        {
+            NFA_TRACE_DEBUG0 ("nfa_hci_dh_startup_complete");
+            nfa_hci_cb.w4_hci_netwk_init = FALSE;
+            /* Received EE DISC REQ Ntf(s) */
+            nfa_hciu_send_get_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_HOST_LIST_INDEX);
+        }
+    }
+#endif
+//NFC_INIT MACH
+
     if (nfa_hci_cb.w4_hci_netwk_init)
     {
         if (nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP)
@@ -573,11 +643,12 @@
             if(ee_info[count].ee_interface[0] == NFA_EE_INTERFACE_HCI_ACCESS)
             {
                 found = TRUE;
-
+#if(NXP_EXTNS != TRUE)
                 if (ee_info[count].ee_status == NFA_EE_STATUS_INACTIVE)
                 {
                     NFC_NfceeModeSet (target_handle, NFC_MODE_ACTIVATE);
                 }
+#endif
                 if ((status = NFC_ConnCreate (NCI_DEST_TYPE_NFCEE, target_handle, NFA_EE_INTERFACE_HCI_ACCESS, nfa_hci_conn_cback)) == NFA_STATUS_OK)
                     nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, NFA_HCI_CON_CREATE_TIMEOUT_VAL);
                 else
@@ -586,6 +657,12 @@
                     NFA_TRACE_ERROR0 ("nfa_hci_startup - Failed to Create Logical connection. HCI Initialization/Restore failed");
                     nfa_hci_startup_complete (NFA_STATUS_FAILED);
                 }
+#if(NXP_EXTNS == TRUE)
+                /*if (ee_info[count].ee_status == NFA_EE_STATUS_INACTIVE)
+                {
+                    NFC_NfceeModeSet (target_handle, NFC_MODE_ACTIVATE);
+                }*/
+#endif
             }
             count++;
         }
@@ -597,6 +674,32 @@
     }
 }
 
+#if (NXP_EXTNS == TRUE)
+void nfa_hci_network_enable()
+{
+    tNFA_EE_INFO    ee_info[2];
+    UINT8           num_nfcee = 2;
+    UINT8           target_handle;
+    BOOLEAN         found = FALSE;
+    UINT8           count = 0;
+
+    NFA_EeGetInfo (&num_nfcee, ee_info);
+    while ((count < num_nfcee) && (!found))
+    {
+        target_handle = (UINT8) ee_info[count].ee_handle;
+
+        if(ee_info[count].ee_interface[0] == NFA_EE_INTERFACE_HCI_ACCESS)
+        {
+            found = TRUE;
+            if (ee_info[count].ee_status == NFA_EE_STATUS_INACTIVE)
+            {
+                NFC_NfceeModeSet (target_handle, NFC_MODE_ACTIVATE);
+            }
+        }
+        count++;
+    }
+}
+#endif
 /*******************************************************************************
 **
 ** Function         nfa_hci_sys_enable
@@ -665,6 +768,7 @@
     UINT16  pkt_len;
 #if (BT_TRACE_VERBOSE == TRUE)
     char    buff[100];
+    static  BOOLEAN is_first_chain_pkt = TRUE;
 #endif
 
     if (event == NFC_CONN_CREATE_CEVT)
@@ -685,8 +789,12 @@
         }
         else
         {
+#if (NXP_EXTNS == TRUE)
+            nfa_hciu_send_set_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_WHITELIST_INDEX, p_nfa_hci_cfg->num_whitelist_host, p_nfa_hci_cfg->p_whitelist);
+#else
             /* Read session id, to know DH session id is correct */
             nfa_hciu_send_get_param_cmd (NFA_HCI_ADMIN_PIPE, NFA_HCI_SESSION_IDENTITY_INDEX);
+#endif
         }
     }
     else if (event == NFC_CONN_CLOSE_CEVT)
@@ -721,54 +829,180 @@
     if (pkt_len != 0)
         pkt_len--;
 
+#if (NXP_EXTNS == TRUE)
+    UINT8 is_assembling_on_current_pipe = 0;
+
+    if(nfa_hci_cb.assembling_flags & NFA_HCI_FL_CONN_PIPE)
+    {
+        if(pipe == NFA_HCI_CONN_ESE_PIPE ||
+                (pipe == NFA_HCI_CONN_UICC_PIPE))
+        {
+            is_assembling_on_current_pipe = 1;
+        }
+    }
+    else if(nfa_hci_cb.assembling_flags & NFA_HCI_FL_APDU_PIPE)
+    {
+        if(pipe == NFA_HCI_APDU_PIPE)
+        {
+            is_assembling_on_current_pipe = 1;
+        }
+    }
+
+    if (is_assembling_on_current_pipe == 0)
+#else
     if (nfa_hci_cb.assembling == FALSE)
+#endif
     {
         /* First Segment of a packet */
         nfa_hci_cb.type            = ((*p) >> 0x06) & 0x03;
         nfa_hci_cb.inst            = (*p++ & 0x3F);
+
+#if (NXP_EXTNS == TRUE)
+        if(pipe == NFA_HCI_CONN_ESE_PIPE ||
+                (pipe == NFA_HCI_CONN_UICC_PIPE))
+        {
+            nfa_hci_cb.type_evt = nfa_hci_cb.type;
+            nfa_hci_cb.inst_evt = nfa_hci_cb.inst;
+        }
+        else if(pipe == NFA_HCI_APDU_PIPE)
+        {
+            nfa_hci_cb.type_msg = nfa_hci_cb.type;
+            nfa_hci_cb.inst_msg = nfa_hci_cb.inst;
+        }
+#endif
         if (pkt_len != 0)
             pkt_len--;
         nfa_hci_cb.assembly_failed = FALSE;
         nfa_hci_cb.msg_len         = 0;
-
+#if (NXP_EXTNS == TRUE)
+        nfa_hci_cb.evt_len = 0;
+#endif
         if (chaining_bit == NFA_HCI_MESSAGE_FRAGMENTATION)
         {
             nfa_hci_cb.assembling = TRUE;
             nfa_hci_set_receive_buf (pipe);
+#if (NXP_EXTNS == TRUE)
+            is_assembling_on_current_pipe = 1;
+            nfa_hci_assemble_msg (p, pkt_len, pipe);
+#else
             nfa_hci_assemble_msg (p, pkt_len);
+#endif
         }
         else
         {
-            if ((pipe >= NFA_HCI_FIRST_DYNAMIC_PIPE) && (nfa_hci_cb.type == NFA_HCI_EVENT_TYPE))
+            if ((pipe >= NFA_HCI_FIRST_DYNAMIC_PIPE) && (nfa_hci_cb.type == NFA_HCI_EVENT_TYPE)
+#if (NXP_EXTNS == TRUE)
+                 && (nfa_hci_cb.inst != NFA_HCI_EVT_WTX)
+#endif
+               )
             {
                 nfa_hci_set_receive_buf (pipe);
+#if (NXP_EXTNS == TRUE)
+                nfa_hci_assemble_msg (p, pkt_len, pipe);
+                if(pipe == NFA_HCI_APDU_PIPE)
+                {
+                    nfa_hci_cb.assembling_flags &= ~NFA_HCI_FL_APDU_PIPE;
+                    nfa_hci_cb.assembly_failed_flags &= ~NFA_HCI_FL_APDU_PIPE;
+
+                    p = nfa_hci_cb.p_msg_data;
+                }
+                else if( (pipe == NFA_HCI_CONN_UICC_PIPE) ||
+                        (pipe == NFA_HCI_CONN_ESE_PIPE))
+                {
+                    nfa_hci_cb.assembling_flags &= ~NFA_HCI_FL_CONN_PIPE;
+                    nfa_hci_cb.assembly_failed_flags &= ~NFA_HCI_FL_CONN_PIPE;
+
+                    p = nfa_hci_cb.p_evt_data;
+                }
+#else
                 nfa_hci_assemble_msg (p, pkt_len);
                 p = nfa_hci_cb.p_msg_data;
+#endif
             }
         }
     }
     else
     {
+#if (NXP_EXTNS == TRUE)
+        UINT8 is_assembly_failed_on_current_pipe = 0;
+        if(nfa_hci_cb.assembly_failed_flags & NFA_HCI_FL_CONN_PIPE)
+        {
+            if(pipe == NFA_HCI_CONN_ESE_PIPE ||
+                    (pipe == NFA_HCI_CONN_UICC_PIPE))
+            {
+                is_assembly_failed_on_current_pipe = 1;
+            }
+        }
+        else if(nfa_hci_cb.assembly_failed_flags & NFA_HCI_FL_APDU_PIPE)
+        {
+            if(pipe == NFA_HCI_APDU_PIPE)
+            {
+                is_assembly_failed_on_current_pipe = 1;
+            }
+        }
+
+        if (is_assembly_failed_on_current_pipe == 1)
+#else
         if (nfa_hci_cb.assembly_failed)
+#endif
         {
             /* If Reassembly failed because of insufficient buffer, just drop the new segmented packets */
             NFA_TRACE_ERROR1 ("nfa_hci_conn_cback (): Insufficient buffer to Reassemble HCP packet! Dropping :%u bytes", pkt_len);
         }
         else
         {
+#if (NXP_EXTNS == TRUE)
+            nfa_hci_assemble_msg (p, pkt_len, pipe);
+#else
             /* Reassemble the packet */
             nfa_hci_assemble_msg (p, pkt_len);
+#endif
         }
 
         if (chaining_bit == NFA_HCI_NO_MESSAGE_FRAGMENTATION)
         {
             /* Just added the last segment in the chain. Reset pointers */
             nfa_hci_cb.assembling = FALSE;
+#if (NXP_EXTNS == TRUE)
+            is_assembling_on_current_pipe = 0;
+            if(pipe == NFA_HCI_APDU_PIPE)
+            {
+                nfa_hci_cb.assembling_flags &= ~NFA_HCI_FL_APDU_PIPE;
+                nfa_hci_cb.assembly_failed_flags &= ~NFA_HCI_FL_APDU_PIPE;
+
+                p                     = nfa_hci_cb.p_msg_data;
+                pkt_len               = nfa_hci_cb.msg_len;
+            }
+            else if( (pipe == NFA_HCI_CONN_UICC_PIPE) ||
+                    (pipe == NFA_HCI_CONN_ESE_PIPE))
+            {
+                nfa_hci_cb.assembling_flags &= ~NFA_HCI_FL_CONN_PIPE;
+                nfa_hci_cb.assembly_failed_flags &= ~NFA_HCI_FL_CONN_PIPE;
+
+                p                     = nfa_hci_cb.p_evt_data;
+                pkt_len               = nfa_hci_cb.evt_len;
+            }
+#else
             p                     = nfa_hci_cb.p_msg_data;
             pkt_len               = nfa_hci_cb.msg_len;
+#endif
         }
     }
 
+#if (NXP_EXTNS == TRUE)
+    if(pipe == NFA_HCI_CONN_ESE_PIPE ||
+            (pipe == NFA_HCI_CONN_UICC_PIPE))
+    {
+        nfa_hci_cb.type = nfa_hci_cb.type_evt;
+        nfa_hci_cb.inst = nfa_hci_cb.inst_evt;
+    }
+    else if(pipe == NFA_HCI_APDU_PIPE)
+    {
+        nfa_hci_cb.type = nfa_hci_cb.type_msg;
+        nfa_hci_cb.inst = nfa_hci_cb.inst_msg;
+    }
+#endif
+
 #if (BT_TRACE_VERBOSE == TRUE)
     NFA_TRACE_EVENT5 ("nfa_hci_conn_cback Recvd data pipe:%d  %s  chain:%d  assmbl:%d  len:%d",
                       (UINT8)pipe, nfa_hciu_get_type_inst_names (pipe, nfa_hci_cb.type, nfa_hci_cb.inst, buff),
@@ -778,9 +1012,24 @@
                       pipe, nfa_hci_cb.type, nfa_hci_cb.inst, chaining_bit, nfa_hci_cb.assembling, p_pkt->len);
 #endif
 
+#if (NXP_EXTNS == TRUE)
+    /*After the reception of WTX, if the next response is chained
+     * the timer value should be big enough to hold the complete packet*/
+    if((nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_RSP) &&
+       (nfa_hci_cb.assembling && is_first_chain_pkt))
+    {
+        is_first_chain_pkt = FALSE;
+        nfa_sys_stop_timer (&nfa_hci_cb.timer);
+        nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, NFA_HCI_CHAIN_PKT_RSP_TIMEOUT);
+    }
+#endif
 
-    /* If still reassembling fragments, just return */
-    if (nfa_hci_cb.assembling)
+#if (NXP_EXTNS == TRUE)
+    if (is_assembling_on_current_pipe == 1)
+#else
+        /* If still reassembling fragments, just return */
+        if (nfa_hci_cb.assembling)
+#endif
     {
         /* if not last packet, release GKI buffer */
         GKI_freebuf (p_pkt);
@@ -789,11 +1038,32 @@
 
     /* If we got a response, cancel the response timer. Also, if waiting for */
     /* a single response, we can go back to idle state                       */
-    if (  (nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_RSP)
-        &&((nfa_hci_cb.type == NFA_HCI_RESPONSE_TYPE) || (nfa_hci_cb.w4_rsp_evt && (nfa_hci_cb.type == NFA_HCI_EVENT_TYPE)))  )
+    if (
+#if (NXP_EXTNS == TRUE)
+            (pipe == NFA_HCI_APDU_PIPE) &&(
+#endif
+                    (nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_RSP)
+                    &&((nfa_hci_cb.type == NFA_HCI_RESPONSE_TYPE) || (nfa_hci_cb.w4_rsp_evt && (nfa_hci_cb.type == NFA_HCI_EVENT_TYPE)
+                    ))
+#if (NXP_EXTNS == TRUE)
+            )
+#endif
+    )
     {
         nfa_sys_stop_timer (&nfa_hci_cb.timer);
-        nfa_hci_cb.hci_state  = NFA_HCI_STATE_IDLE;
+#if (NXP_EXTNS == TRUE)
+        is_first_chain_pkt = TRUE;
+        if(nfa_hci_cb.inst == NFA_HCI_EVT_WTX)
+        {
+            if(nfa_hci_cb.w4_rsp_evt == TRUE)
+            {
+                const INT32 rsp_timeout = 3000; //3-sec
+                nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, rsp_timeout);
+            }
+        }
+        else
+#endif
+            nfa_hci_cb.hci_state  = NFA_HCI_STATE_IDLE;
     }
 
     switch (pipe)
@@ -826,7 +1096,19 @@
         break;
     }
 
-    if ((nfa_hci_cb.type == NFA_HCI_RESPONSE_TYPE) || (nfa_hci_cb.w4_rsp_evt && (nfa_hci_cb.type == NFA_HCI_EVENT_TYPE)))
+    if (
+#if (NXP_EXTNS == TRUE)
+            (pipe == NFA_HCI_APDU_PIPE) && (
+#endif
+                    (nfa_hci_cb.type == NFA_HCI_RESPONSE_TYPE) || (nfa_hci_cb.w4_rsp_evt && (nfa_hci_cb.type == NFA_HCI_EVENT_TYPE)
+#if (NXP_EXTNS == TRUE)
+                            && (nfa_hci_cb.inst != NFA_HCI_EVT_WTX)
+#endif
+                    )
+#if (NXP_EXTNS == TRUE)
+            )
+#endif
+    )
     {
         nfa_hci_cb.w4_rsp_evt = FALSE;
     }
@@ -983,6 +1265,9 @@
             evt_data.registry.pipe     = nfa_hci_cb.pipe_in_use;
             evt_data.registry.data_len = 0;
             evt_data.registry.index    = nfa_hci_cb.param_in_use;
+#if (NXP_EXTNS == TRUE)
+            evt_data.registry.status   = NFA_HCI_ANY_E_TIMEOUT;
+#endif
             evt                        = NFA_HCI_GET_REG_RSP_EVT;
             break;
 
@@ -1033,11 +1318,13 @@
             delete_pipe                = nfa_hci_cb.pipe_in_use;
             break;
         }
+#if (NXP_EXTNS != TRUE)
         if (delete_pipe && (delete_pipe <= NFA_HCI_LAST_DYNAMIC_PIPE))
         {
             nfa_hciu_send_delete_pipe_cmd (delete_pipe);
             nfa_hciu_release_pipe (delete_pipe);
         }
+#endif
         break;
     case NFA_HCI_STATE_DISABLED:
     default:
@@ -1062,6 +1349,43 @@
     if (  (pipe >= NFA_HCI_FIRST_DYNAMIC_PIPE)
         &&(nfa_hci_cb.type == NFA_HCI_EVENT_TYPE)  )
     {
+#if (NXP_EXTNS == TRUE)
+        if(pipe == NFA_HCI_CONN_ESE_PIPE || pipe == NFA_HCI_CONN_UICC_PIPE)
+        {
+            /* Connectivity or transaction events are received
+             * from SE. will be assembled and sent to application.
+             * */
+            nfa_hci_cb.assembling_flags |= NFA_HCI_FL_CONN_PIPE;
+            nfa_hci_cb.p_evt_data  = nfa_hci_cb.evt_data;
+            nfa_hci_cb.max_evt_len = NFA_MAX_HCI_EVENT_LEN;
+            return;
+        }
+        else if(pipe == NFA_HCI_APDU_PIPE)
+        {
+            /* Here APDU response is received, for the APDU
+             * sent from JNI layer using transceive.
+             * */
+            nfa_hci_cb.assembling_flags |= NFA_HCI_FL_APDU_PIPE;
+            if (  (nfa_hci_cb.rsp_buf_size)
+                &&(nfa_hci_cb.p_rsp_buf != NULL)  )
+            {
+                nfa_hci_cb.p_msg_data  = nfa_hci_cb.p_rsp_buf;
+                nfa_hci_cb.max_msg_len = nfa_hci_cb.rsp_buf_size;
+                return;
+            }
+        }
+        else
+        {
+            nfa_hci_cb.assembling_flags |= NFA_HCI_FL_OTHER_PIPE;
+            if (  (nfa_hci_cb.rsp_buf_size)
+                &&(nfa_hci_cb.p_rsp_buf != NULL)  )
+            {
+                nfa_hci_cb.p_msg_data  = nfa_hci_cb.p_rsp_buf;
+                nfa_hci_cb.max_msg_len = nfa_hci_cb.rsp_buf_size;
+                return;
+            }
+        }
+#else
         if (  (nfa_hci_cb.rsp_buf_size)
             &&(nfa_hci_cb.p_rsp_buf != NULL)  )
         {
@@ -1069,6 +1393,7 @@
             nfa_hci_cb.max_msg_len = nfa_hci_cb.rsp_buf_size;
             return;
         }
+#endif
     }
     nfa_hci_cb.p_msg_data  = nfa_hci_cb.msg_data;
     nfa_hci_cb.max_msg_len = NFA_MAX_HCI_EVENT_LEN;
@@ -1083,8 +1408,51 @@
 ** Returns          None
 **
 *******************************************************************************/
+#if (NXP_EXTNS == TRUE)
+static void nfa_hci_assemble_msg (UINT8 *p_data, UINT16 data_len, UINT8 pipe)
+#else
 static void nfa_hci_assemble_msg (UINT8 *p_data, UINT16 data_len)
+#endif
 {
+#if (NXP_EXTNS == TRUE)
+    if(pipe == NFA_HCI_APDU_PIPE)
+    {
+        if ((nfa_hci_cb.msg_len + data_len) > nfa_hci_cb.max_msg_len)
+        {
+            /* Fill the buffer as much it can hold */
+            memcpy (&nfa_hci_cb.p_msg_data[nfa_hci_cb.msg_len], p_data, (nfa_hci_cb.max_msg_len - nfa_hci_cb.msg_len));
+            nfa_hci_cb.msg_len         = nfa_hci_cb.max_msg_len;
+            /* Set Reassembly failed */
+            nfa_hci_cb.assembly_failed = TRUE;
+            nfa_hci_cb.assembly_failed_flags |= NFA_HCI_FL_APDU_PIPE;
+            NFA_TRACE_ERROR1 ("nfa_hci_assemble_msg (): Insufficient buffer to Reassemble APDU HCP packet! Dropping :%u bytes", ((nfa_hci_cb.msg_len + data_len) - nfa_hci_cb.max_msg_len));
+        }
+        else
+        {
+            memcpy (&nfa_hci_cb.p_msg_data[nfa_hci_cb.msg_len], p_data, data_len);
+            nfa_hci_cb.msg_len += data_len;
+        }
+    }
+    else if( (pipe == NFA_HCI_CONN_ESE_PIPE) ||
+            (pipe == NFA_HCI_CONN_UICC_PIPE))
+    {
+        if ((nfa_hci_cb.evt_len + data_len) > nfa_hci_cb.max_evt_len)
+        {
+            /* Fill the buffer as much it can hold */
+            memcpy (&nfa_hci_cb.p_evt_data[nfa_hci_cb.evt_len], p_data, (nfa_hci_cb.max_evt_len - nfa_hci_cb.evt_len));
+            nfa_hci_cb.evt_len         = nfa_hci_cb.max_evt_len;
+            /* Set Reassembly failed */
+            nfa_hci_cb.assembly_failed = TRUE;
+            nfa_hci_cb.assembly_failed_flags |= NFA_HCI_FL_CONN_PIPE;
+            NFA_TRACE_ERROR1 ("nfa_hci_assemble_msg (): Insufficient buffer to Reassemble Event HCP packet! Dropping :%u bytes", ((nfa_hci_cb.msg_len + data_len) - nfa_hci_cb.max_msg_len));
+        }
+        else
+        {
+            memcpy (&nfa_hci_cb.p_evt_data[nfa_hci_cb.evt_len], p_data, data_len);
+            nfa_hci_cb.evt_len += data_len;
+        }
+    }
+#else
     if ((nfa_hci_cb.msg_len + data_len) > nfa_hci_cb.max_msg_len)
     {
         /* Fill the buffer as much it can hold */
@@ -1099,6 +1467,7 @@
         memcpy (&nfa_hci_cb.p_msg_data[nfa_hci_cb.msg_len], p_data, data_len);
         nfa_hci_cb.msg_len += data_len;
     }
+#endif
 }
 
 /*******************************************************************************
@@ -1175,3 +1544,14 @@
     return FALSE;
 }
 
+#if (NXP_EXTNS == TRUE)
+void nfa_hci_release_transcieve()
+{
+    NFA_TRACE_DEBUG0 ("nfa_hci_release_transcieve (); Release ongoing transcieve");
+    if(nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_RSP)
+    {
+        nfa_sys_stop_timer(&nfa_hci_cb.timer);
+        nfa_hci_rsp_timeout(NULL);
+    }
+}
+#endif
diff --git a/src/nfa/hci/nfa_hci_utils.c b/src/nfa/hci/nfa_hci_utils.c
index 3ee8bdf..37906ff 100644
--- a/src/nfa/hci/nfa_hci_utils.c
+++ b/src/nfa/hci/nfa_hci_utils.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -320,7 +338,7 @@
     BOOLEAN          first_pkt = TRUE;
     UINT16          data_len;
     tNFA_STATUS     status = NFA_STATUS_OK;
-    UINT16          max_seg_hcp_pkt_size = nfa_hci_cb.buff_size - NCI_DATA_HDR_SIZE;
+    UINT16          max_seg_hcp_pkt_size = nfa_hci_cb.buff_size;
 
 #if (BT_TRACE_VERBOSE == TRUE)
     char    buff[100];
@@ -401,7 +419,6 @@
 
         if (nfa_hci_cb.hci_state == NFA_HCI_STATE_IDLE)
             nfa_hci_cb.hci_state = NFA_HCI_STATE_WAIT_RSP;
-
         nfa_sys_start_timer (&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT, p_nfa_hci_cfg->hcp_response_timeout);
     }
 
@@ -1454,4 +1471,3 @@
     p_buf->event = NFA_HCI_CHECK_QUEUE_EVT;
     nfa_sys_sendmsg (p_buf);
 }
-
diff --git a/src/nfa/include/nfa_api.h b/src/nfa/include/nfa_api.h
index 0443275..0ea5cb2 100644
--- a/src/nfa/include/nfa_api.h
+++ b/src/nfa/include/nfa_api.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -104,12 +122,12 @@
 typedef UINT8 tNFA_PMID;
 
 /* Definitions for tNFA_TECHNOLOGY_MASK */
-#define NFA_TECHNOLOGY_MASK_A	        0x01    /* NFC Technology A             */
-#define NFA_TECHNOLOGY_MASK_B	        0x02    /* NFC Technology B             */
-#define NFA_TECHNOLOGY_MASK_F	        0x04    /* NFC Technology F             */
-#define NFA_TECHNOLOGY_MASK_ISO15693	0x08    /* Proprietary Technology       */
-#define NFA_TECHNOLOGY_MASK_B_PRIME	    0x10    /* Proprietary Technology       */
-#define NFA_TECHNOLOGY_MASK_KOVIO	    0x20    /* Proprietary Technology       */
+#define NFA_TECHNOLOGY_MASK_A           0x01    /* NFC Technology A             */
+#define NFA_TECHNOLOGY_MASK_B           0x02    /* NFC Technology B             */
+#define NFA_TECHNOLOGY_MASK_F           0x04    /* NFC Technology F             */
+#define NFA_TECHNOLOGY_MASK_ISO15693    0x08    /* Proprietary Technology       */
+#define NFA_TECHNOLOGY_MASK_B_PRIME     0x10    /* Proprietary Technology       */
+#define NFA_TECHNOLOGY_MASK_KOVIO       0x20    /* Proprietary Technology       */
 #define NFA_TECHNOLOGY_MASK_A_ACTIVE    0x40    /* NFC Technology A active mode */
 #define NFA_TECHNOLOGY_MASK_F_ACTIVE    0x80    /* NFC Technology F active mode */
 #define NFA_TECHNOLOGY_MASK_ALL         0xFF    /* All supported technologies   */
@@ -124,6 +142,10 @@
 #define NFA_PROTOCOL_ISO15693   NFC_PROTOCOL_15693
 #define NFA_PROTOCOL_B_PRIME    NFC_PROTOCOL_B_PRIME
 #define NFA_PROTOCOL_KOVIO      NFC_PROTOCOL_KOVIO
+#if (NXP_EXTNS == TRUE)
+#define NFA_PROTOCOL_MIFARE     NFC_PROTOCOL_MIFARE
+#define NFA_PROTOCOL_T3BT       NFC_PROTOCOL_T3BT
+#endif
 #define NFA_PROTOCOL_INVALID    0xFF
 #define NFA_MAX_NUM_PROTOCOLS   8
 typedef UINT8 tNFA_NFC_PROTOCOL;
@@ -134,6 +156,9 @@
 #define NFA_PROTOCOL_MASK_T3T       0x04    /* FeliCa / Type 3 tag */
 #define NFA_PROTOCOL_MASK_ISO_DEP   0x08    /* ISODEP/4A,4B        */
 #define NFA_PROTOCOL_MASK_NFC_DEP   0x10    /* NFCDEP/LLCP         */
+#if(NXP_EXTNS == TRUE)
+#define NFC_PROTOCOL_MASK_ISO7816   0x20    /*ISO 7816 - Aid Default Route */
+#endif
 typedef UINT8 tNFA_PROTOCOL_MASK;
 
 
@@ -143,9 +168,19 @@
 #define NFA_DM_SET_CONFIG_EVT           2   /* Result of NFA_SetConfig          */
 #define NFA_DM_GET_CONFIG_EVT           3   /* Result of NFA_GetConfig          */
 #define NFA_DM_PWR_MODE_CHANGE_EVT      4   /* Result of NFA_PowerOffSleepMode  */
-#define NFA_DM_RF_FIELD_EVT	            5   /* Status of RF Field               */
+#define NFA_DM_RF_FIELD_EVT             5   /* Status of RF Field               */
 #define NFA_DM_NFCC_TIMEOUT_EVT         6   /* NFCC is not responding           */
 #define NFA_DM_NFCC_TRANSPORT_ERR_EVT   7   /* NCI Tranport error               */
+#if(NXP_EXTNS == TRUE)
+#define NFA_DM_EMVCO_PCD_COLLISION_EVT  8   /* Collision event in case of EMV-CO Profile (Nxp)*/
+#define NFA_DM_SET_ROUTE_CONFIG_REVT    9   /* Status of EE Route config CMD (Nxp)*/
+#define NFA_DM_GET_ROUTE_CONFIG_REVT    10  /* Result of NFA_GetRouting         */
+/* Reader over SWP Events*/
+#define NFA_RD_SWP_READER_REQUESTED     0
+#define NFA_RD_SWP_READER_START         1
+#define NFA_RD_SWP_READER_STOP          2
+#define NFA_RD_SWP_READER_START_FAIL    3
+#endif
 
 #define NFA_T1T_HR_LEN              T1T_HR_LEN      /* T1T HR length            */
 #define NFA_MAX_UID_LEN             TAG_MAX_UID_LEN /* Max UID length of T1/T2  */
@@ -180,6 +215,17 @@
     UINT8 param_tlvs[1];    /* TLV (Parameter ID-Len-Value byte stream) */
 } tNFA_GET_CONFIG;
 
+#if(NXP_EXTNS == TRUE)
+/* Data for NFA_DM_GET_ROUTING_EVT */
+typedef struct
+{
+    tNFA_STATUS status;     /* NFA_STATUS_OK if successful              */
+    UINT8   num_tlvs;       /* number of TLVs                           */
+    UINT8   tlv_size;       /* the total len of all TLVs                */
+    UINT8 param_tlvs[150];  /* TLV (Parameter ID-Len-Value byte stream) */
+} tNFA_GET_ROUTING;
+#endif
+
 #define NFA_DM_PWR_MODE_FULL        0x04
 #define NFA_DM_PWR_MODE_OFF_SLEEP   0x00
 
@@ -208,6 +254,9 @@
     tNFA_STATUS             status;         /* NFA_DM_ENABLE_EVT        */
     tNFA_SET_CONFIG         set_config;     /* NFA_DM_SET_CONFIG_EVT    */
     tNFA_GET_CONFIG         get_config;     /* NFA_DM_GET_CONFIG_EVT    */
+#if(NXP_EXTNS == TRUE)
+    tNFA_GET_ROUTING        get_routing;    /* NFA_DM_GET_ROUTING_EVT    */
+#endif
     tNFA_DM_PWR_MODE_CHANGE power_mode;     /* NFA_DM_PWR_MODE_CHANGE_EVT   */
     tNFA_DM_RF_FIELD        rf_field;       /* NFA_DM_RF_FIELD_EVT      */
     void                    *p_vs_evt_data; /* Vendor-specific evt data */
@@ -216,6 +265,22 @@
 /* NFA_DM callback */
 typedef void (tNFA_DM_CBACK) (UINT8 event, tNFA_DM_CBACK_DATA *p_data);
 
+#if(NXP_EXTNS == TRUE)
+/* NFA Enable DTA Type Mode */
+typedef enum
+{
+    NFA_DTA_DEFAULT_MODE=0,
+    NFA_DTA_LLCP_MODE,
+    NFA_DTA_SNEP_MODE
+}tNFA_eDtaModes;
+typedef struct
+{
+    UINT8 validation; /* indicates on which platform validation is done like pn547, pn548, pn65T, pn66T */
+    UINT8 android_version; /* Nxp's android version */
+    UINT8 major_version; /* Major Version of MW*/
+    UINT8 minor_version; /* Minor Version of Mw */
+}tNFA_MW_VERSION;
+#endif
 
 /* NFA Connection Callback Events */
 #define NFA_POLL_ENABLED_EVT                    0   /* Polling enabled event                        */
@@ -258,6 +323,11 @@
 #define NFA_LISTEN_DISABLED_EVT                 37  /* Listening disabled event                     */
 #define NFA_P2P_PAUSED_EVT                      38  /* P2P services paused event                    */
 #define NFA_P2P_RESUMED_EVT                     39  /* P2P services resumed event                   */
+#if(NXP_EXTNS == TRUE)
+#define NFA_CE_ESE_LISTEN_CONFIGURED_EVT        40  /* ESE Listen configured                        */
+#define NFA_ACTIVATED_UPDATE_EVT                41  /* Activated intf for updating the   tech variables */
+#define NFA_RECOVERY_EVT                        42  /*Recovery*/
+#endif
 
 /* NFC deactivation type */
 #define NFA_DEACTIVATE_TYPE_IDLE        NFC_DEACTIVATE_TYPE_IDLE
@@ -269,7 +339,7 @@
 /* Data for NFA_DISC_RESULT_EVT */
 typedef struct
 {
-    tNFA_STATUS	        status;         /* NFA_STATUS_OK if successful       */
+    tNFA_STATUS         status;         /* NFA_STATUS_OK if successful       */
     tNFC_RESULT_DEVT    discovery_ntf;  /* RF discovery notification details */
 } tNFA_DISC_RESULT;
 
@@ -595,6 +665,9 @@
 #define NFA_INTERFACE_FRAME         NFC_INTERFACE_FRAME
 #define NFA_INTERFACE_ISO_DEP       NFC_INTERFACE_ISO_DEP
 #define NFA_INTERFACE_NFC_DEP       NFC_INTERFACE_NFC_DEP
+#if (NXP_EXTNS == TRUE)
+#define NFA_INTERFACE_MIFARE        NFC_INTERFACE_MIFARE
+#endif
 typedef tNFC_INTF_TYPE tNFA_INTF_TYPE;
 
 /*******************************************************************************
@@ -607,10 +680,10 @@
 #define NFA_TNF_RFC2046_MEDIA   NDEF_TNF_MEDIA      /* Media-type as defined in RFC 2046 [RFC 2046]     */
 #define NFA_TNF_RFC3986_URI     NDEF_TNF_URI        /* Absolute URI as defined in RFC 3986 [RFC 3986]   */
 #define NFA_TNF_EXTERNAL        NDEF_TNF_EXT        /* NFC Forum external type [NFC RTD]                */
-#define NFA_TNF_UNKNOWN	        NDEF_TNF_UNKNOWN    /* Unknown                                          */
+#define NFA_TNF_UNKNOWN         NDEF_TNF_UNKNOWN    /* Unknown                                          */
 #define NFA_TNF_UNCHANGED       NDEF_TNF_UNCHANGED  /* Unchanged                                        */
 #define NFA_TNF_RESERVED        NDEF_TNF_RESERVED   /* Reserved                                         */
-#define NFA_TNF_DEFAULT	        0xFF                /* Used to register default NDEF type handler       */
+#define NFA_TNF_DEFAULT         0xFF                /* Used to register default NDEF type handler       */
 typedef UINT8 tNFA_TNF;
 
 /* Definitions for tNFA_NDEF_URI_ID (Frequently used prefixes. For additional values, see [NFC RTD URI] */
@@ -626,7 +699,7 @@
 
 /* Events for tNFA_NDEF_CBACK */
 #define NFA_NDEF_REGISTER_EVT   0   /* NDEF record type registered. (In response to NFA_RegisterNDefTypeHandler)    */
-#define NFA_NDEF_DATA_EVT	    1   /* Received an NDEF message with the registered type. See [tNFA_NDEF_DATA]       */
+#define NFA_NDEF_DATA_EVT       1   /* Received an NDEF message with the registered type. See [tNFA_NDEF_DATA]       */
 typedef UINT8 tNFA_NDEF_EVT;
 
 /* Structure for NFA_NDEF_REGISTER_EVT event data */
@@ -1231,6 +1304,29 @@
                                               UINT8            *p_cmd_params,
                                               tNFA_VSC_CBACK   *p_cback);
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_SendNxpNciCommand
+**
+** Description      This function is called to send NXP NCI Vendor Specific
+**                  command to NFCC.
+**
+**                  cmd_params_len  - The command parameter len
+**                  p_cmd_params    - The command parameter
+**                  p_cback         - The callback function to receive the command
+**
+** Returns          NFA_STATUS_OK if successfully initiated
+**                  NFA_STATUS_FAILED otherwise
+**
+*******************************************************************************/
+
+NFC_API extern tNFA_STATUS NFA_SendNxpNciCommand (UINT8            cmd_params_len,
+                                                  UINT8            *p_cmd_params,
+                                                  tNFA_VSC_CBACK   *p_cback);
+
+#endif
+
 /*******************************************************************************
 **
 ** Function         NFA_SetTraceLevel
@@ -1243,10 +1339,50 @@
 *******************************************************************************/
 NFC_API extern UINT8 NFA_SetTraceLevel (UINT8 new_level);
 
+/*******************************************************************************
+**
+** Function:        NFA_EnableDTA_TypeMode
+**
+** Description:     Initialize and get global DTA type mode from .conf
+**
+** Returns:         none:
+**
+*******************************************************************************/
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_SetReaderMode
+**
+** Description:
+**      This function enable/disable  reader mode. In reader mode, even though if
+**      P2P & CE from UICC is detected, Priority will be given to TypeF UICC read.
+**      Its currently implemented for TypeF
+**
+**      ReaderModeFlag - Enable/Disable Reader Mode
+**      Technologies   - Type of technologies to be set for Reader mode
+**                       Currently not used and reader mode is enabled for TypeF Only
+**
+** Returns:
+**      void
+*******************************************************************************/
+NFC_API extern void NFA_SetReaderMode (BOOLEAN ReaderModeFlag, UINT32 Technologies);
 
+NFC_API extern void  NFA_EnableDtamode (tNFA_eDtaModes eDtaMode);
+
+/*******************************************************************************
+**
+** Function:        NFA_GetMwVersion
+**
+** Description:     This function gets the Middleware Version
+**
+** Returns:         First 8 bit Major Version
+**                  Last 8 bit Minor Version
+**
+*******************************************************************************/
+NFC_API extern tNFA_MW_VERSION NFA_GetMwVersion ();
+#endif
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* NFA_API_H */
-
diff --git a/src/nfa/include/nfa_ce_api.h b/src/nfa/include/nfa_ce_api.h
index ccb4115..95584db 100644
--- a/src/nfa/include/nfa_ce_api.h
+++ b/src/nfa/include/nfa_ce_api.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -114,6 +132,34 @@
 NFC_API extern tNFA_STATUS NFA_CeConfigureUiccListenTech (tNFA_HANDLE          ee_handle,
                                                           tNFA_TECHNOLOGY_MASK tech_mask);
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_CeConfigureEseListenTech
+**
+** Description      Configure listening for the Ese, using the specified
+**                  technologies.
+**
+**                  Events will be notifed using the tNFA_CONN_CBACK
+**                  (registered during NFA_Enable)
+**
+**                  The NFA_CE_ESE_LISTEN_CONFIGURED_EVT reports the status of the
+**                  operation.
+**
+**                  Activation and deactivation are reported using the
+**                  NFA_ACTIVATED_EVT and NFA_DEACTIVATED_EVT events
+**
+** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
+**                  should happen before calling this function
+**
+** Returns:
+**                  NFA_STATUS_OK, if command accepted
+**                  NFA_STATUS_FAILED: otherwise
+**
+*******************************************************************************/
+NFC_API extern tNFA_STATUS NFA_CeConfigureEseListenTech (tNFA_HANDLE ee_handle,
+                                           tNFA_TECHNOLOGY_MASK tech_mask);
+#endif
 /*******************************************************************************
 **
 ** Function         NFA_CeRegisterFelicaSystemCodeOnDH
diff --git a/src/nfa/include/nfa_cho_api.h b/src/nfa/include/nfa_cho_api.h
index f9bf093..3722adc 100644
--- a/src/nfa/include/nfa_cho_api.h
+++ b/src/nfa/include/nfa_cho_api.h
@@ -370,4 +370,3 @@
 #endif
 
 #endif /* NFA_CHO_API_H */
-
diff --git a/src/nfa/include/nfa_ee_api.h b/src/nfa/include/nfa_ee_api.h
index 8cefe9b..bd0ecaa 100644
--- a/src/nfa/include/nfa_ee_api.h
+++ b/src/nfa/include/nfa_ee_api.h
@@ -15,8 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  NFA interface to NFCEE
@@ -34,6 +51,12 @@
 *****************************************************************************/
 #define NFA_MAX_AID_LEN             NFC_MAX_AID_LEN /* 16 per ISO 7816 specification    */
 #define NFA_EE_HANDLE_DH            (NFA_HANDLE_GROUP_EE|NFC_DH_ID)
+#if(NXP_EXTNS == TRUE)
+extern  UINT8 NFA_REMOVE_ALL_AID[];
+#define NFA_REMOVE_ALL_AID_LEN      (0x08)
+extern  UINT8 nfa_ee_ce_route_strict_disable;
+#define NFA_EE_AE_NXP_PREFIX_MATCH      (0x10)
+#endif
 
 /* NFA EE callback events */
 enum
@@ -72,7 +95,11 @@
 #define NFA_EE_TAG_ATR_BYTES         NFC_NFCEE_TAG_ATR_BYTES            /* ATR Bytes            */
 #define NFA_EE_TAG_T3T_INFO          NFC_NFCEE_TAG_T3T_INFO             /* T3T Supplement. Info */
 #define NFA_EE_TAG_HCI_HOST_ID       NFC_NFCEE_TAG_HCI_HOST_ID          /* Broadcom Proprietary */
+#if(NXP_EXTNS == TRUE)
+typedef UINT16 tNFA_EE_TAG;
+#else
 typedef UINT8 tNFA_EE_TAG;
+#endif
 
 /* for NFA_EeModeSet () */
 #define NFA_EE_MD_ACTIVATE          NFC_MODE_ACTIVATE
@@ -112,6 +139,12 @@
     tNFA_EE_INTERFACE   ee_interface[NFC_MAX_EE_INTERFACE];/* NFCEE supported interface */
     UINT8               num_tlvs;               /* number of TLVs           */
     tNFA_EE_TLV         ee_tlv[NFC_MAX_EE_TLVS];/* the TLV                  */
+#if(NXP_EXTNS == TRUE)
+    tNFA_NFC_PROTOCOL       la_protocol;        /* Listen A protocol    */
+    tNFA_NFC_PROTOCOL       lb_protocol;        /* Listen B protocol    */
+    tNFA_NFC_PROTOCOL       lf_protocol;        /* Listen F protocol    */
+    tNFA_NFC_PROTOCOL       lbp_protocol;       /* Listen B' protocol   */
+#endif
 } tNFA_EE_INFO;
 
 
@@ -166,6 +199,11 @@
     tNFA_NFC_PROTOCOL   lb_protocol;        /* Listen B protocol    */
     tNFA_NFC_PROTOCOL   lf_protocol;        /* Listen F protocol    */
     tNFA_NFC_PROTOCOL   lbp_protocol;       /* Listen B' protocol   */
+#if(NXP_EXTNS == TRUE)
+    tNFA_NFC_PROTOCOL   pa_protocol;        /* Passive poll A SWP Reader   */
+    tNFA_NFC_PROTOCOL   pb_protocol;        /* Passive poll B SWP Reader   */
+    UINT8               ee_req_op;          /* add or remove req ntf*/
+#endif
 } tNFA_EE_DISCOVER_INFO;
 
 /* Data for NFA_EE_DISCOVER_REQ_EVT */
@@ -250,6 +288,25 @@
 NFC_API extern tNFA_STATUS NFA_EeGetInfo (UINT8        *p_num_nfcee,
                                           tNFA_EE_INFO *p_info);
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_AllEeGetInfo
+**
+** Description      This function retrieves the All NFCEE's independent of
+**                  their status information from NFA.
+**                  The actual number of NFCEE is returned in p_num_nfcee
+**                  and NFCEE information is returned in p_info
+**
+** Returns          NFA_STATUS_OK if information is retrieved successfully
+**                  NFA_STATUS_FAILED If wrong state (retry later)
+**                  NFA_STATUS_INVALID_PARAM If bad parameter
+**
+*******************************************************************************/
+NFC_API extern tNFA_STATUS NFA_AllEeGetInfo (UINT8        *p_num_nfcee,
+                                             tNFA_EE_INFO *p_info);
+#endif
+
 /*******************************************************************************
 **
 ** Function         NFA_EeRegister
@@ -318,7 +375,13 @@
 NFC_API extern tNFA_STATUS NFA_EeSetDefaultTechRouting (tNFA_HANDLE          ee_handle,
                                                         tNFA_TECHNOLOGY_MASK technologies_switch_on,
                                                         tNFA_TECHNOLOGY_MASK technologies_switch_off,
-                                                        tNFA_TECHNOLOGY_MASK technologies_battery_off);
+                                                        tNFA_TECHNOLOGY_MASK technologies_battery_off
+#if(NXP_EXTNS == TRUE)
+                                                       ,tNFA_TECHNOLOGY_MASK technologies_screen_lock,
+                                                        tNFA_TECHNOLOGY_MASK technologies_screen_off
+#endif
+
+);
 
 /*******************************************************************************
 **
@@ -343,7 +406,12 @@
 NFC_API extern tNFA_STATUS NFA_EeSetDefaultProtoRouting (tNFA_HANDLE         ee_handle,
                                                          tNFA_PROTOCOL_MASK  protocols_switch_on,
                                                          tNFA_PROTOCOL_MASK  protocols_switch_off,
-                                                         tNFA_PROTOCOL_MASK  protocols_battery_off);
+                                                         tNFA_PROTOCOL_MASK  protocols_battery_off
+#if(NXP_EXTNS == TRUE)
+                                                        ,tNFA_PROTOCOL_MASK  protocols_screen_lock,
+                                                         tNFA_PROTOCOL_MASK  protocols_screen_off
+#endif
+);
 
 /*******************************************************************************
 **
@@ -367,7 +435,11 @@
 NFC_API extern tNFA_STATUS NFA_EeAddAidRouting (tNFA_HANDLE          ee_handle,
                                                 UINT8                aid_len,
                                                 UINT8               *p_aid,
-                                                tNFA_EE_PWR_STATE    power_state);
+                                                tNFA_EE_PWR_STATE     power_state
+#if(NXP_EXTNS == TRUE)
+                                                , UINT8              vs_info
+#endif
+);
 
 /*******************************************************************************
 **
@@ -474,10 +546,77 @@
 *******************************************************************************/
 NFC_API extern tNFA_STATUS NFA_EeDisconnect (tNFA_HANDLE ee_handle);
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_AddEePowerState
+**
+** Description      This function is called to add power state in the
+**                  listen mode routing table in NFCC.
+**
+** Note:            If RF discovery is started, NFA_StopRfDiscovery()/NFA_RF_DISCOVERY_STOPPED_EVT
+**                  should happen before calling this function
+**
+** Note:            NFA_EeUpdateNow() should be called after last NFA-EE function
+**                  to change the listen mode routing is called.
+**
+** Returns          NFA_STATUS_OK if successfully initiated
+**                  NFA_STATUS_FAILED otherwise
+**                  NFA_STATUS_INVALID_PARAM If bad parameter
+**
+*******************************************************************************/
+NFC_API extern tNFA_STATUS NFA_AddEePowerState(tNFA_HANDLE          ee_handle,
+                                tNFA_EE_PWR_STATE    power_state_mask);
+
+/*******************************************************************************
+**
+** Function         NFA_GetAidTableSize
+**
+** Description      This function is called to get the AID routing table size.
+**
+** Returns          Maximum AID routing table size.
+**
+*******************************************************************************/
+NFC_API extern UINT16 NFA_GetAidTableSize();
+
+/*******************************************************************************
+**
+** Function         NFA_GetRemainingAidTableSize
+**
+** Description      This function is called to get the remaining AID routing
+**                  table size.
+**
+** Returns          Remaining AID routing table size.
+**
+*******************************************************************************/
+NFC_API extern UINT16 NFA_GetRemainingAidTableSize();
+
+/*******************************************************************************
+**
+** Function         NFA_SetCEStrictDisable
+**
+** Description      This function is called to set the flag for Strict CE.
+**
+** Returns          None.
+**
+*******************************************************************************/
+NFC_API extern void NFA_SetCEStrictDisable(UINT32 state);
+
+/*******************************************************************************
+**
+** Function         NFA_setProvisionMode
+**
+** Description      This function is called to set/reset the provision mode info.
+**
+** Returns          None.
+**
+*******************************************************************************/
+NFC_API extern void NFA_setProvisionMode(BOOLEAN provisionMode);
+
+#endif
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* NFA_EE_API_H */
-
diff --git a/src/nfa/include/nfa_hci_api.h b/src/nfa/include/nfa_hci_api.h
index 0d8ab18..dd7c641 100644
--- a/src/nfa/include/nfa_hci_api.h
+++ b/src/nfa/include/nfa_hci_api.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -39,16 +57,16 @@
 #define NFA_HCI_DEBUG_DISABLE_LOOPBACK          102
 
 /* NFA HCI callback events */
-#define NFA_HCI_REGISTER_EVT	                0x00    /* Application registered                       */
+#define NFA_HCI_REGISTER_EVT                    0x00    /* Application registered                       */
 #define NFA_HCI_DEREGISTER_EVT                  0x01    /* Application deregistered                     */
 #define NFA_HCI_GET_GATE_PIPE_LIST_EVT          0x02    /* Retrieved gates,pipes assoc. to application  */
-#define NFA_HCI_ALLOCATE_GATE_EVT	            0x03    /* A generic gate allocated to the application  */
-#define NFA_HCI_DEALLOCATE_GATE_EVT	            0x04    /* A generic gate is released                   */
-#define NFA_HCI_CREATE_PIPE_EVT         	    0x05    /* Pipe is created                              */
-#define NFA_HCI_OPEN_PIPE_EVT         	        0x06    /* Pipe is opened / could not open              */
-#define NFA_HCI_CLOSE_PIPE_EVT         	        0x07    /* Pipe is closed / could not close             */
-#define NFA_HCI_DELETE_PIPE_EVT         	    0x08    /* Pipe is deleted                              */
-#define NFA_HCI_HOST_LIST_EVT       	        0x09    /* Received list of Host from Host controller   */
+#define NFA_HCI_ALLOCATE_GATE_EVT               0x03    /* A generic gate allocated to the application  */
+#define NFA_HCI_DEALLOCATE_GATE_EVT             0x04    /* A generic gate is released                   */
+#define NFA_HCI_CREATE_PIPE_EVT                 0x05    /* Pipe is created                              */
+#define NFA_HCI_OPEN_PIPE_EVT                   0x06    /* Pipe is opened / could not open              */
+#define NFA_HCI_CLOSE_PIPE_EVT                  0x07    /* Pipe is closed / could not close             */
+#define NFA_HCI_DELETE_PIPE_EVT                 0x08    /* Pipe is deleted                              */
+#define NFA_HCI_HOST_LIST_EVT                   0x09    /* Received list of Host from Host controller   */
 #define NFA_HCI_INIT_EVT                        0x0A    /* HCI subsytem initialized                     */
 #define NFA_HCI_EXIT_EVT                        0x0B    /* HCI subsytem exited                          */
 #define NFA_HCI_RSP_RCVD_EVT                    0x0C    /* Response recvd to cmd sent on app owned pipe */
@@ -68,7 +86,15 @@
 #define NFA_MAX_HCI_APP_NAME_LEN                0x10    /* Max application name length */
 #define NFA_MAX_HCI_CMD_LEN                     255     /* Max HCI command length */
 #define NFA_MAX_HCI_RSP_LEN                     255     /* Max HCI event length */
+#if (NXP_EXTNS == TRUE)
+/*
+ * increased the the buffer size, since as per HCI specification connectivity event may
+ * take up 271 bytes. (MAX AID length:16, MAX PARAMETERS length:255)
+ * */
+#define NFA_MAX_HCI_EVENT_LEN                   300     /* Max HCI event length */
+#else
 #define NFA_MAX_HCI_EVENT_LEN                   260     /* Max HCI event length */
+#endif
 #define NFA_MAX_HCI_DATA_LEN                    260     /* Max HCI data length */
 
 /* NFA HCI PIPE states */
@@ -269,6 +295,14 @@
     tNFA_HCI_ADD_STATIC_PIPE_EVT    pipe_added;     /* NFA_HCI_ADD_STATIC_PIPE_EVT    */
 } tNFA_HCI_EVT_DATA;
 
+#if(NXP_EXTNS == TRUE)
+typedef enum
+{
+    Wait = 0,
+    Release
+}tNFA_HCI_TRANSCV_STATE;
+#endif
+
 /* NFA HCI callback */
 typedef void (tNFA_HCI_CBACK) (tNFA_HCI_EVT event, tNFA_HCI_EVT_DATA *p_data);
 
@@ -603,9 +637,22 @@
 *******************************************************************************/
 NFC_API extern void NFA_HciDebug (UINT8 action, UINT8 size, UINT8 *p_data);
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_HciW4eSETransaction_Complete
+**
+** Description      This function is called to wait for eSE transaction
+**                  to complete before NFCC shutdown or NFC service turn OFF
+**
+** Returns          None
+**
+*******************************************************************************/
+NFC_API extern void NFA_HciW4eSETransaction_Complete(tNFA_HCI_TRANSCV_STATE type);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* NFA_P2P_API_H */
-
diff --git a/src/nfa/include/nfa_hci_defs.h b/src/nfa/include/nfa_hci_defs.h
index dab93cf..866d38d 100644
--- a/src/nfa/include/nfa_hci_defs.h
+++ b/src/nfa/include/nfa_hci_defs.h
@@ -15,8 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  This file contains the NFA HCI related definitions from the
@@ -30,6 +47,11 @@
 /* Static gates */
 #define NFA_HCI_LOOP_BACK_GATE              0x04
 #define NFA_HCI_IDENTITY_MANAGEMENT_GATE    0x05
+#if(NXP_EXTNS == TRUE)
+#ifdef GEMALTO_SE_SUPPORT
+#define NFC_HCI_DEFAULT_DEST_GATE           0XF0
+#endif
+#endif
 
 #define NFA_HCI_FIRST_HOST_SPECIFIC_GENERIC_GATE    0x10
 #define NFA_HCI_LAST_HOST_SPECIFIC_GENERIC_GATE     0xEF
@@ -100,6 +122,9 @@
 #define NFA_HCI_EVT_POST_DATA               0x02
 #define NFA_HCI_EVT_HOT_PLUG                0x03
 
+#if (NXP_EXTNS == TRUE)
+#define NFA_HCI_EVT_WTX                     0x11
+#endif
 
 /* NFA HCI Connectivity gate Events */
 #define NFA_HCI_EVT_CONNECTIVITY            0x10
diff --git a/src/nfa/include/nfa_mem_co.h b/src/nfa/include/nfa_mem_co.h
index b425e91..4dfcacb 100644
--- a/src/nfa/include/nfa_mem_co.h
+++ b/src/nfa/include/nfa_mem_co.h
@@ -72,4 +72,3 @@
 #endif
 
 #endif /* NFA_MEM_CO_H */
-
diff --git a/src/nfa/include/nfa_nv_ci.h b/src/nfa/include/nfa_nv_ci.h
index 963a923..512bf78 100644
--- a/src/nfa/include/nfa_nv_ci.h
+++ b/src/nfa/include/nfa_nv_ci.h
@@ -106,4 +106,3 @@
 #endif
 
 #endif /* BTA_FS_CI_H */
-
diff --git a/src/nfa/include/nfa_p2p_api.h b/src/nfa/include/nfa_p2p_api.h
index e99f85e..45381ca 100644
--- a/src/nfa/include/nfa_p2p_api.h
+++ b/src/nfa/include/nfa_p2p_api.h
@@ -34,27 +34,27 @@
 *****************************************************************************/
 
 /* NFA P2P Reason of disconnection */
-#define NFA_P2P_DISC_REASON_REMOTE_INITIATE	    0x00    /* remote initiated to disconnect  */
-#define NFA_P2P_DISC_REASON_LOCAL_INITITATE	    0x01    /* local initiated to disconnect   */
-#define NFA_P2P_DISC_REASON_NO_SERVICE	        0x02    /* no service bound in remote      */
-#define NFA_P2P_DISC_REASON_REMOTE_REJECT	    0x03    /* remote rejected connection      */
-#define NFA_P2P_DISC_REASON_FRAME_ERROR	        0x04    /* sending or receiving FRMR PDU   */
-#define NFA_P2P_DISC_REASON_LLCP_DEACTIVATED	0x05    /* LLCP link deactivated           */
-#define NFA_P2P_DISC_REASON_NO_RESOURCE	        0x06    /* Out of resource in local device */
-#define NFA_P2P_DISC_REASON_NO_INFORMATION	    0x80    /* Without information             */
+#define NFA_P2P_DISC_REASON_REMOTE_INITIATE     0x00    /* remote initiated to disconnect  */
+#define NFA_P2P_DISC_REASON_LOCAL_INITITATE     0x01    /* local initiated to disconnect   */
+#define NFA_P2P_DISC_REASON_NO_SERVICE          0x02    /* no service bound in remote      */
+#define NFA_P2P_DISC_REASON_REMOTE_REJECT       0x03    /* remote rejected connection      */
+#define NFA_P2P_DISC_REASON_FRAME_ERROR         0x04    /* sending or receiving FRMR PDU   */
+#define NFA_P2P_DISC_REASON_LLCP_DEACTIVATED    0x05    /* LLCP link deactivated           */
+#define NFA_P2P_DISC_REASON_NO_RESOURCE         0x06    /* Out of resource in local device */
+#define NFA_P2P_DISC_REASON_NO_INFORMATION      0x80    /* Without information             */
 
 /* NFA P2P callback events */
 #define NFA_P2P_REG_SERVER_EVT      0x00    /* Server is registered                         */
 #define NFA_P2P_REG_CLIENT_EVT      0x01    /* Client is registered                         */
 #define NFA_P2P_ACTIVATED_EVT       0x02    /* LLCP Link has been activated                 */
-#define NFA_P2P_DEACTIVATED_EVT	    0x03    /* LLCP Link has been deactivated               */
+#define NFA_P2P_DEACTIVATED_EVT     0x03    /* LLCP Link has been deactivated               */
 #define NFA_P2P_CONN_REQ_EVT        0x04    /* Data link connection request from peer       */
 #define NFA_P2P_CONNECTED_EVT       0x05    /* Data link connection has been established    */
 #define NFA_P2P_DISC_EVT            0x06    /* Data link connection has been disconnected   */
 #define NFA_P2P_DATA_EVT            0x07    /* Data received from peer                      */
 #define NFA_P2P_CONGEST_EVT         0x08    /* Status indication of outgoing data           */
 #define NFA_P2P_LINK_INFO_EVT       0x09    /* link MIU and Well-Known Service list         */
-#define NFA_P2P_SDP_EVT	            0x0A    /* Remote SAP of SDP result                     */
+#define NFA_P2P_SDP_EVT             0x0A    /* Remote SAP of SDP result                     */
 
 typedef UINT8 tNFA_P2P_EVT;
 
@@ -573,4 +573,3 @@
 #endif
 
 #endif /* NFA_P2P_API_H */
-
diff --git a/src/nfa/include/nfa_rw_api.h b/src/nfa/include/nfa_rw_api.h
index 6534ccd..d677bb9 100644
--- a/src/nfa/include/nfa_rw_api.h
+++ b/src/nfa/include/nfa_rw_api.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -750,6 +768,32 @@
 *******************************************************************************/
 NFC_API extern tNFA_STATUS NFA_RwI93GetMultiBlockSecurityStatus (UINT8  first_block_number,
                                                                  UINT16 number_blocks);
+#if (NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFA_SetReconnectState
+**
+** Description:
+**      This function enable/disable p2p prio logic if re-connect is in progress
+**
+** Returns:
+**      void
+*******************************************************************************/
+NFC_API extern void NFA_SetReconnectState (BOOLEAN flag);
+
+/*******************************************************************************
+**
+** Function         NFA_SetEmvCoState
+**
+** Description:
+**      This function enable/disable p2p prio logic if emvco polling is enabled.
+**
+** Returns:
+**      void
+*******************************************************************************/
+NFC_API extern void NFA_SetEmvCoState (BOOLEAN flag);
+
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/src/nfa/include/nfa_snep_api.h b/src/nfa/include/nfa_snep_api.h
index 5c0f3f3..af6ae60 100644
--- a/src/nfa/include/nfa_snep_api.h
+++ b/src/nfa/include/nfa_snep_api.h
@@ -62,8 +62,8 @@
 #define NFA_SNEP_PUT_RESP_EVT               0x07    /* PUT response from server             */
 #define NFA_SNEP_DISC_EVT                   0x08    /* Failed to connect or disconnected    */
 
-#define NFA_SNEP_ALLOC_BUFF_EVT	            0x09    /* Request to allocate a buffer for NDEF*/
-#define NFA_SNEP_FREE_BUFF_EVT	            0x0A    /* Request to deallocate buffer for NDEF*/
+#define NFA_SNEP_ALLOC_BUFF_EVT             0x09    /* Request to allocate a buffer for NDEF*/
+#define NFA_SNEP_FREE_BUFF_EVT              0x0A    /* Request to deallocate buffer for NDEF*/
 #define NFA_SNEP_GET_RESP_CMPL_EVT          0x0B    /* GET response sent to client          */
 
 #define NFA_SNEP_DEFAULT_SERVER_STARTED_EVT 0x0C    /* SNEP default server is started       */
@@ -461,4 +461,3 @@
 #endif
 
 #endif /* NFA_P2P_API_H */
-
diff --git a/src/nfa/int/nfa_ce_int.h b/src/nfa/int/nfa_ce_int.h
index a9d3520..4e99849 100644
--- a/src/nfa/int/nfa_ce_int.h
+++ b/src/nfa/int/nfa_ce_int.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -59,6 +77,9 @@
     NFA_CE_REG_TYPE_ISO_DEP,
     NFA_CE_REG_TYPE_FELICA,
     NFA_CE_REG_TYPE_UICC
+#if(NXP_EXTNS == TRUE)
+    , NFA_CE_REG_TYPE_ESE
+#endif
 };
 typedef UINT8 tNFA_CE_REG_TYPE;
 
@@ -137,7 +158,9 @@
 #define NFA_CE_LISTEN_INFO_START_NTF_PND    0x00000100  /* App has not been notified of LISTEN_START yet                    */
 #define NFA_CE_LISTEN_INFO_FELICA           0x00000200  /* This is a listen_info for non-NDEF Felica                        */
 #define NFA_CE_LISTEN_INFO_UICC             0x00000400  /* This is a listen_info for UICC                                   */
-
+#if(NXP_EXTNS == TRUE)
+#define NFA_CE_LISTEN_INFO_ESE              0x00008000  /* This is a listen_info for ESE                                    */
+#endif
 
 /* Structure for listen look up table */
 typedef struct
@@ -213,4 +236,3 @@
 void nfa_ce_free_scratch_buf (void);
 BOOLEAN nfa_ce_restart_listen_check (void);
 #endif /* NFA_DM_INT_H */
-
diff --git a/src/nfa/int/nfa_dm_int.h b/src/nfa/int/nfa_dm_int.h
index fc9b906..3868f74 100644
--- a/src/nfa/int/nfa_dm_int.h
+++ b/src/nfa/int/nfa_dm_int.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -63,6 +82,9 @@
     NFA_DM_API_REG_VSC_EVT,
     NFA_DM_API_SEND_VSC_EVT,
     NFA_DM_TIMEOUT_DISABLE_EVT,
+#if(NXP_EXTNS == TRUE)
+    NFA_DM_API_SEND_NXP_EVT,
+#endif
     NFA_DM_MAX_EVT
 };
 
@@ -478,6 +500,10 @@
     tNFA_DM_CBACK              *p_dm_cback;         /* NFA DM callback                                      */
     TIMER_LIST_ENT              tle;
 
+#if(NXP_EXTNS == TRUE)
+    BOOLEAN                     presence_check_deact_pending; /* TRUE if deactivate while checking presence */
+    tNFA_DEACTIVATE_TYPE        presence_check_deact_type;    /* deactivate type                            */
+#endif
     /* NFC link connection management */
     tNFA_CONN_CBACK            *p_conn_cback;       /* callback for connection events       */
     tNFA_TECHNOLOGY_MASK        poll_mask;          /* technologies being polled            */
@@ -511,6 +537,9 @@
 
     /* NFCC power mode */
     UINT8                       nfcc_pwr_mode;          /* NFA_DM_PWR_MODE_FULL or NFA_DM_PWR_MODE_OFF_SLEEP */
+#if(NXP_EXTNS == TRUE)
+    UINT8                       eDtaMode;               /*For enable the DTA type modes. */
+#endif
 } tNFA_DM_CB;
 
 /* Internal function prototypes */
@@ -540,6 +569,14 @@
 extern tNCI_DISCOVER_MAPS *p_nfa_dm_interface_mapping;
 extern UINT8 nfa_dm_num_dm_interface_mapping;
 
+#if(NXP_EXTNS == TRUE)
+void nfa_dm_poll_disc_cback_dta_wrapper(tNFA_DM_RF_DISC_EVT event, tNFC_DISCOVER *p_data);
+#endif
+
+#if(NXP_EXTNS == TRUE)
+extern unsigned char appl_dta_mode_flag;
+#endif
+
 /* NFA device manager control block */
 #if NFA_DYNAMIC_MEMORY == FALSE
 extern tNFA_DM_CB nfa_dm_cb;
@@ -597,6 +634,10 @@
 BOOLEAN nfa_dm_tout (tNFA_DM_MSG *p_data);
 BOOLEAN nfa_dm_act_reg_vsc (tNFA_DM_MSG *p_data);
 BOOLEAN nfa_dm_act_send_vsc (tNFA_DM_MSG *p_data);
+#if(NXP_EXTNS == TRUE)
+BOOLEAN nfa_dm_act_send_nxp(tNFA_DM_MSG *p_data);
+UINT16 nfa_dm_act_get_rf_disc_duration ();
+#endif
 BOOLEAN nfa_dm_act_disable_timeout (tNFA_DM_MSG *p_data);
 BOOLEAN nfa_dm_act_nfc_cback_data (tNFA_DM_MSG *p_data);
 
@@ -630,7 +671,7 @@
 tNFC_STATUS nfa_dm_disc_start_kovio_presence_check (void);
 BOOLEAN nfa_dm_is_raw_frame_session (void);
 BOOLEAN nfa_dm_is_p2p_paused (void);
-
+void nfa_dm_p2p_prio_logic_cleanup (void);
 
 #if (NFC_NFCEE_INCLUDED == FALSE)
 #define nfa_ee_get_tech_route(ps, ha) memset(ha, NFC_DH_ID, NFA_DM_MAX_TECH_ROUTE);
@@ -642,4 +683,3 @@
 
 
 #endif /* NFA_DM_INT_H */
-
diff --git a/src/nfa/int/nfa_dta_int.h b/src/nfa/int/nfa_dta_int.h
index e1effbd..9534a9b 100644
--- a/src/nfa/int/nfa_dta_int.h
+++ b/src/nfa/int/nfa_dta_int.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -59,8 +77,12 @@
 #define NFA_DTA_SCRATCH_BUF_SIZE        T3T_MSG_BLOCKSIZE
 
 #ifndef NFA_DTA_DEFAULT_CO_OUT_DSAP
+#if(NXP_EXTNS == TRUE)
+#define NFA_DTA_DEFAULT_CO_OUT_DSAP     0x10    /* Default SAP[LT,CO-OUT-DEST] if SDP was not performed to get SAP from the LT */
+#else
 #define NFA_DTA_DEFAULT_CO_OUT_DSAP     0x12    /* Default SAP[LT,CO-OUT-DEST] if SDP was not performed to get SAP from the LT */
 #endif
+#endif
 
 /*****************************************************************************
 * DTA state machine definitions
@@ -72,6 +94,10 @@
     BOOLEAN t4at_nfcdep_priority;           /* NFA_DTA_CFG_T4AT_NFCDEP_PRIORITY */
     BOOLEAN reactivation;                   /* NFA_DTA_CFG_REACTIVATION   */
     UINT16  total_duration;                 /* NFA_DTA_CFG_TOTAL_DURATION */
+#if(NXP_EXTNS == TRUE)
+    BOOLEAN enable_dta_llcp;                /* NFA_DTA_CFG_LLCP */
+    tNFA_DTA_SNEP_MODE dta_snep_mode;       /* NFA_DTA_CFG_SNEP */
+#endif
     tNFA_DTA_EMVCO_PCD_MODE emvco_pcd_mode; /* NFA_DTA_CFG_EMVCO_PCD */
 } tNFA_DTA_CONFIG;
 
@@ -314,7 +340,15 @@
     tNFA_HANDLE             snep_server_handle;
     tNFA_HANDLE             snep_server_conn_handle;
     tNFA_HANDLE             snep_client_handle;
+#if(NXP_EXTNS == TRUE)
+#define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_DEFAULT_SERVER    0x01
+#define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_EXTENDED_SERVER   0x02
+#define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_PUT_SHORT_NDEF    0x04
+#define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_PUT_LONG_NDEF     0x08
+#define NFA_DTA_SNEP_CLIENT_TEST_FLAGS_GET               0x10
 
+    UINT8                   snep_client_test_flags;
+#endif
     UINT8                   *p_snep_short_ndef;
     UINT32                  snep_short_ndef_size;
     UINT8                   *p_snep_long_ndef;
@@ -408,6 +442,9 @@
 void nfa_dta_snep_init (void);
 void nfa_dta_snep_register (void);
 void nfa_dta_snep_deregister (void);
+#if(NXP_EXTNS == TRUE)
+void nfa_dta_snep_mode (tNFA_DTA_SNEP_MODE mode);
+#endif
 
 void nfa_dta_emvco_pcd_config_nfcc (BOOLEAN enable);
 void nfa_dta_emvco_pcd_start (void);
@@ -419,4 +456,3 @@
 
 #endif /* (NFA_DTA_INCLUDED == TRUE) */
 #endif /* NFA_DTA_INT_H */
-
diff --git a/src/nfa/int/nfa_ee_int.h b/src/nfa/int/nfa_ee_int.h
index c2014d3..98defc7 100644
--- a/src/nfa/int/nfa_ee_int.h
+++ b/src/nfa/int/nfa_ee_int.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -74,7 +93,6 @@
 
 };
 
-
 typedef UINT16 tNFA_EE_INT_EVT;
 #define NFA_EE_AE_ROUTE             0x80        /* for listen mode routing table*/
 #define NFA_EE_AE_VS                0x40
@@ -103,8 +121,33 @@
     NFA_EE_CONN_ST_MAX
 };
 typedef UINT8 tNFA_EE_CONN_ST;
+#if(NXP_EXTNS == TRUE)
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+/**
+ * Max Routing Table Size = 720
+ * After allocating size for Technology based routing and Protocol based routing,
+ * the remaining size can be used for AID based routing
+ *
+ * Size for 1 Technology route entry = 5 bytes (includes Type(1 byte),
+ * Length (1 byte), Value (3 bytes - Power state, Tech Type, Location)
+ * TOTAL TECH ROUTE SIZE = 5 * 3  = 15 (For Tech A, B, F)
+ *
+ * Size for 1 Protocol route entry = 5 bytes (includes Type(1 byte),
+ * Length (1 byte), Value (3 bytes - Power state, Tech Type, Location)
+ * TOTAL PROTOCOL ROUTE SIZE = 5 * 6 = 30 (Protocols ISO-DEP, NFC-DEP, ISO-7816, T1T, T2T, T3T)
+ *
+ * SIZE FOR AID = 720 - 15 - 30 = 675
+ * BUFFER for future extensions = 15
+ * TOTAL SIZE FOR AID = 675 - 15 = 660
+ */
+#define NFA_EE_MAX_AID_CFG_LEN  (660)
 
+#else
+#define NFA_EE_MAX_AID_CFG_LEN  (160)
+#endif
+#else
 #define NFA_EE_MAX_AID_CFG_LEN  (510)
+#endif
 #define NFA_EE_7816_STATUS_LEN  (2)
 
 /* NFA EE control block flags:
@@ -133,6 +176,12 @@
     tNFA_PROTOCOL_MASK      proto_switch_on;    /* default routing - protocols switch_on     */
     tNFA_PROTOCOL_MASK      proto_switch_off;   /* default routing - protocols switch_off    */
     tNFA_PROTOCOL_MASK      proto_battery_off;  /* default routing - protocols battery_off   */
+#if(NXP_EXTNS == TRUE)
+    tNFA_PROTOCOL_MASK      proto_screen_lock;   /* default routing - protocols screen_lock    */
+    tNFA_PROTOCOL_MASK      proto_screen_off;  /* default routing - protocols screen_off  */
+    tNFA_TECHNOLOGY_MASK    tech_screen_lock;    /* default routing - technologies screen_lock*/
+    tNFA_TECHNOLOGY_MASK    tech_screen_off;   /* default routing - technologies screen_off*/
+#endif
     tNFA_EE_CONN_ST         conn_st;            /* connection status */
     UINT8                   conn_id;            /* connection id */
     tNFA_EE_CBACK           *p_ee_cback;        /* the callback function */
@@ -145,6 +194,9 @@
     UINT8                   aid_len[NFA_EE_MAX_AID_ENTRIES];/* the actual lengths in aid_cfg */
     UINT8                   aid_pwr_cfg[NFA_EE_MAX_AID_ENTRIES];/* power configuration of this AID entry */
     UINT8                   aid_rt_info[NFA_EE_MAX_AID_ENTRIES];/* route/vs info for this AID entry */
+#if(NXP_EXTNS == TRUE)
+    UINT8                   aid_rt_loc[NFA_EE_MAX_AID_ENTRIES];/* route location info for this AID entry */
+#endif
     UINT8                   aid_cfg[NFA_EE_MAX_AID_CFG_LEN];/* routing entries based on AID */
     UINT8                   aid_entries;        /* The number of AID entries in aid_cfg */
     UINT8                   nfcee_id;           /* ID for this NFCEE */
@@ -162,6 +214,11 @@
     tNFA_NFC_PROTOCOL       lbp_protocol;       /* Listen B' protocol   */
     UINT8                   size_mask;          /* the size for technology and protocol routing */
     UINT16                  size_aid;           /* the size for aid routing */
+#if(NXP_EXTNS == TRUE)
+    tNFA_NFC_PROTOCOL       pa_protocol;        /* Passive poll A SWP Reader   */
+    tNFA_NFC_PROTOCOL       pb_protocol;        /* Passive poll B SWP Reader   */
+    UINT8                   ee_req_op;          /* add or remove req ntf*/
+#endif
 } tNFA_EE_ECB;
 
 /* data type for NFA_EE_API_DISCOVER_EVT */
@@ -203,6 +260,10 @@
     tNFA_TECHNOLOGY_MASK    technologies_switch_on;
     tNFA_TECHNOLOGY_MASK    technologies_switch_off;
     tNFA_TECHNOLOGY_MASK    technologies_battery_off;
+#if(NXP_EXTNS == TRUE)
+    tNFA_TECHNOLOGY_MASK    technologies_screen_lock;
+    tNFA_TECHNOLOGY_MASK    technologies_screen_off;
+#endif
 } tNFA_EE_API_SET_TECH_CFG;
 
 /* data type for NFA_EE_API_SET_PROTO_CFG_EVT */
@@ -214,6 +275,11 @@
     tNFA_PROTOCOL_MASK  protocols_switch_on;
     tNFA_PROTOCOL_MASK  protocols_switch_off;
     tNFA_PROTOCOL_MASK  protocols_battery_off;
+#if(NXP_EXTNS == TRUE)
+    tNFA_PROTOCOL_MASK  protocols_screen_lock;
+    tNFA_PROTOCOL_MASK  protocols_screen_off;
+#endif
+
 } tNFA_EE_API_SET_PROTO_CFG;
 
 /* data type for NFA_EE_API_ADD_AID_EVT */
@@ -225,6 +291,9 @@
     UINT8               aid_len;
     UINT8               *p_aid;
     tNFA_EE_PWR_STATE   power_state;
+#if(NXP_EXTNS == TRUE)
+    UINT8               vs_info;
+#endif
 } tNFA_EE_API_ADD_AID;
 
 /* data type for NFA_EE_API_REMOVE_AID_EVT */
@@ -392,6 +461,9 @@
 #define NFA_EE_FLAG_WAIT_HCI            0x01    /* set this bit when waiting for HCI to finish the initialization process in NFA_EE_EM_STATE_RESTORING */
 #define NFA_EE_FLAG_NOTIFY_HCI          0x02    /* set this bit when EE needs to notify the p_enable_cback at the end of NFCEE discover process in NFA_EE_EM_STATE_RESTORING */
 #define NFA_EE_FLAG_WAIT_DISCONN        0x04    /* set this bit when gracefully disable with outstanding NCI connections */
+#if(NXP_EXTNS == TRUE)
+#define NFA_EE_FLAG_CFG_NFC_DEP         0x05    /* set this bit when NFC-DEP is configured in the routing table */
+#endif
 typedef UINT8 tNFA_EE_FLAGS;
 
 
@@ -432,6 +504,9 @@
 extern tNFA_EE_CB *nfa_ee_cb_ptr;
 #define nfa_ee_cb (*nfa_ee_cb_ptr)
 #endif
+#if(NXP_EXTNS == TRUE)
+extern BOOLEAN gNfaProvisionMode;
+#endif
 
 /*****************************************************************************
 **  External functions
@@ -449,6 +524,10 @@
 void nfa_ee_proc_evt(tNFC_RESPONSE_EVT event, void *p_data);
 tNFA_EE_ECB * nfa_ee_find_ecb (UINT8 nfcee_id);
 tNFA_EE_ECB * nfa_ee_find_ecb_by_conn_id (UINT8 conn_id);
+#if(NXP_EXTNS == TRUE)
+UINT16 nfa_ee_lmrt_size();
+UINT8 nfa_ee_get_supported_tech_list(UINT8 nfcee_id);
+#endif
 UINT8 nfa_ee_ecb_to_mask (tNFA_EE_ECB *p_cb);
 void nfa_ee_restore_one_ecb (tNFA_EE_ECB *p_cb);
 BOOLEAN nfa_ee_is_active (tNFA_HANDLE nfcee_id);
@@ -479,6 +558,9 @@
 void nfa_ee_discv_timeout(tNFA_EE_MSG *p_data);
 void nfa_ee_lmrt_to_nfcc(tNFA_EE_MSG *p_data);
 void nfa_ee_update_rout(void);
+#if (NXP_EXTNS == TRUE)
+BOOLEAN nfa_ee_nfeeid_active(UINT8 nfee_id);
+#endif
 void nfa_ee_report_event(tNFA_EE_CBACK *p_cback, tNFA_EE_EVT event, tNFA_EE_CBACK_DATA *p_data);
 tNFA_EE_ECB * nfa_ee_find_aid_offset(UINT8 aid_len, UINT8 *p_aid, int *p_offset, int *p_entry);
 void nfa_ee_remove_labels(void);
@@ -486,6 +568,7 @@
 void nfa_ee_start_timer(void);
 void nfa_ee_reg_cback_enable_done (tNFA_EE_ENABLE_DONE_CBACK *p_cback);
 void nfa_ee_report_update_evt (void);
+void find_and_resolve_tech_conflict();
 
 extern void nfa_ee_proc_hci_info_cback (void);
 void nfa_ee_check_disable (void);
diff --git a/src/nfa/int/nfa_hci_int.h b/src/nfa/int/nfa_hci_int.h
index fe77a5c..3436899 100644
--- a/src/nfa/int/nfa_hci_int.h
+++ b/src/nfa/int/nfa_hci_int.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -57,6 +75,11 @@
 #define NFA_HCI_STATE_RESTORE               0x07     /* HCI restore */
 #define NFA_HCI_STATE_RESTORE_NETWK_ENABLE  0x08     /* HCI is waiting for initialization of other host in the network after restore */
 
+#if(NXP_EXTNS == TRUE)
+#define NFA_HCI_MAX_RSP_WAIT_TIME           0x0C
+#define NFA_HCI_CHAIN_PKT_RSP_TIMEOUT       30000    /* After the reception of WTX, maximum response timeout value is 30 sec */
+#endif
+
 typedef UINT8 tNFA_HCI_STATE;
 
 /* NFA HCI PIPE states */
@@ -361,8 +384,15 @@
 /* Internal flags */
 #define NFA_HCI_FL_DISABLING        0x01                /* sub system is being disabled */
 #define NFA_HCI_FL_NV_CHANGED       0x02                /* NV Ram changed */
+#if (NXP_EXTNS == TRUE)
+#define NFA_HCI_FL_CONN_PIPE 0x01
+#define NFA_HCI_FL_APDU_PIPE 0x02
+#define NFA_HCI_FL_OTHER_PIPE 0x04
 
-
+#define NFA_HCI_CONN_ESE_PIPE 0x16
+#define NFA_HCI_CONN_UICC_PIPE 0x0A
+#define NFA_HCI_APDU_PIPE 0x19
+#endif
 /* NFA HCI control block */
 typedef struct
 {
@@ -382,6 +412,10 @@
     BOOLEAN                         nv_write_needed;                    /* Something changed - NV write is needed */
     BOOLEAN                         assembling;                         /* Set true if in process of assembling a message  */
     BOOLEAN                         assembly_failed;                    /* Set true if Insufficient buffer to Reassemble incoming message */
+#if (NXP_EXTNS == TRUE)
+    UINT8                           assembling_flags;                   /* the flags to keep track of assembling status*/
+    UINT8                           assembly_failed_flags;              /* the flags to keep track of failed assembly*/
+#endif
     BOOLEAN                         w4_rsp_evt;                         /* Application command sent on HCP Event */
     tNFA_HANDLE                     app_in_use;                         /* Index of the application that is waiting for response */
     UINT8                           local_gate_in_use;                  /* Local gate currently working with */
@@ -396,6 +430,17 @@
     UINT16                          max_msg_len;                        /* Maximum reassembled message size */
     UINT8                           msg_data[NFA_MAX_HCI_EVENT_LEN];    /* For segmentation - the combined message data */
     UINT8                           *p_msg_data;                        /* For segmentation - reassembled message */
+#if (NXP_EXTNS == TRUE)
+    UINT8                           *p_evt_data;                        /* For segmentation - reassembled event data */
+    UINT16                          evt_len;                            /* For segmentation - length of the combined event data */
+    UINT16                          max_evt_len;                        /* Maximum reassembled message size */
+    UINT8                           evt_data[NFA_MAX_HCI_EVENT_LEN];    /* For segmentation - the combined event data */
+    UINT8                           type_evt;                               /* Instruction type of incoming message */
+    UINT8                           inst_evt;                               /* Instruction of incoming message */
+    UINT8                           type_msg;                               /* Instruction type of incoming message */
+    UINT8                           inst_msg;                               /* Instruction of incoming message */
+
+#endif
     UINT8                           type;                               /* Instruction type of incoming message */
     UINT8                           inst;                               /* Instruction of incoming message */
 
@@ -445,6 +490,10 @@
 extern void nfa_hci_startup_complete (tNFA_STATUS status);
 extern void nfa_hci_startup (void);
 extern void nfa_hci_restore_default_config (UINT8 *p_session_id);
+#if (NXP_EXTNS == TRUE)
+extern void nfa_hci_release_transcieve();
+extern void nfa_hci_network_enable();
+#endif
 
 /* Action functions in nfa_hci_act.c
 */
diff --git a/src/nfa/int/nfa_rw_int.h b/src/nfa/int/nfa_rw_int.h
index ec3b644..75b0d25 100644
--- a/src/nfa/int/nfa_rw_int.h
+++ b/src/nfa/int/nfa_rw_int.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -113,6 +131,10 @@
     NFA_RW_OP_I93_GET_SYS_INFO,
     NFA_RW_OP_I93_GET_MULTI_BLOCK_STATUS,
 
+#if(NXP_EXTNS == TRUE)
+    NFA_RW_OP_T3BT_PUPI,
+#endif
+
     NFA_RW_OP_MAX
 };
 typedef UINT8 tNFA_RW_OP;
@@ -350,5 +372,9 @@
 extern void    nfa_rw_free_ndef_rx_buf (void);
 extern void    nfa_rw_sys_disable (void);
 
-#endif /* NFA_DM_INT_H */
+#if(NXP_EXTNS == TRUE)
+extern void nfa_rw_set_cback(tNFC_DISCOVER *p_data);
+extern void nfa_rw_update_pupi_id(UINT8 *p, UINT8 len);
+#endif
 
+#endif /* NFA_DM_INT_H */
diff --git a/src/nfa/p2p/nfa_p2p_api.c b/src/nfa/p2p/nfa_p2p_api.c
index 94c9893..15a455b 100644
--- a/src/nfa/p2p/nfa_p2p_api.c
+++ b/src/nfa/p2p/nfa_p2p_api.c
@@ -1042,15 +1042,15 @@
 **                  NFA_STATUS_FAILED otherwise
 **
 *******************************************************************************/
-tNFA_STATUS NFA_P2pSetLLCPConfig (UINT16 link_miu,
-                                  UINT8  opt,
-                                  UINT8  wt,
-                                  UINT16 link_timeout,
-                                  UINT16 inact_timeout_init,
-                                  UINT16 inact_timeout_target,
-                                  UINT16 symm_delay,
-                                  UINT16 data_link_timeout,
-                                  UINT16 delay_first_pdu_timeout)
+tNFA_STATUS NFA_P2pSetLLCPConfig (UINT16  link_miu,
+                                  UINT8   opt,
+                                  UINT8   wt,
+                                  UINT16  link_timeout,
+                                  UINT16  inact_timeout_init,
+                                  UINT16  inact_timeout_target,
+                                  UINT16  symm_delay,
+                                  UINT16  data_link_timeout,
+                                  UINT16  delay_first_pdu_timeout)
 {
     tNFA_P2P_API_SET_LLCP_CFG *p_msg;
 
@@ -1132,8 +1132,7 @@
                      *p_link_miu, *p_opt, *p_wt, *p_link_timeout);
     P2P_TRACE_API4 ("                       inact_timeout(init:%d, target:%d), symm_delay:%d, data_link_timeout:%d",
                      *p_inact_timeout_init, *p_inact_timeout_target, *p_symm_delay, *p_data_link_timeout);
-    P2P_TRACE_API1 ("                       delay_first_pdu_timeout:%d", *p_delay_first_pdu_timeout);
-
+    P2P_TRACE_API1 ("delay_first_pdu_timeout:%d",*p_delay_first_pdu_timeout);
 }
 
 /*******************************************************************************
@@ -1153,4 +1152,3 @@
 
     return (nfa_p2p_cb.trace_level);
 }
-
diff --git a/src/nfa/p2p/nfa_p2p_main.c b/src/nfa/p2p/nfa_p2p_main.c
index 4ec71e7..2b743a3 100644
--- a/src/nfa/p2p/nfa_p2p_main.c
+++ b/src/nfa/p2p/nfa_p2p_main.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -132,7 +150,7 @@
         nfa_dm_conn_cback_event_notify (NFA_ACTIVATED_EVT, &evt_data);
 
         if ((p_data->activate.protocol        == NFC_PROTOCOL_NFC_DEP)
-          &&(p_data->activate.intf_param.type == NFC_INTERFACE_NFC_DEP))
+          &&((p_data->activate.intf_param.type == NFC_INTERFACE_NFC_DEP)))
         {
             nfa_p2p_activate_llcp (p_data);
 
@@ -248,10 +266,25 @@
     if (nfa_p2p_cb.listen_tech_mask & NFA_TECHNOLOGY_MASK_F_ACTIVE)
         p2p_listen_mask |= NFA_DM_DISC_MASK_LFA_NFC_DEP;
 
-    /* Configure listen technologies and protocols and register callback to NFA DM discovery */
-    nfa_p2p_cb.dm_disc_handle = nfa_dm_add_rf_discover (p2p_listen_mask,
-                                                        NFA_DM_DISC_HOST_ID_DH,
-                                                        nfa_p2p_discovery_cback);
+#if(NXP_EXTNS == TRUE)
+    /*For P2P mode(Default DTA mode) open Raw channel to bypass LLCP layer. For LLCP DTA mode activate LLCP
+     * Bypassing LLCP is handled in nfa_dm_poll_disc_cback*/
+    if ((appl_dta_mode_flag == 1) && (nfa_dm_cb.eDtaMode == NFA_DTA_DEFAULT_MODE))
+    {
+        /* Configure listen technologies and protocols and register callback to NFA DM discovery */
+        P2P_TRACE_DEBUG0 ("DTA mode1:Registering nfa_dm_poll_disc_cback to avoid LLCP in P2P ");
+        nfa_p2p_cb.dm_disc_handle = nfa_dm_add_rf_discover (p2p_listen_mask,
+                                                            NFA_DM_DISC_HOST_ID_DH,
+                                                            nfa_dm_poll_disc_cback_dta_wrapper);
+    }
+    else
+#endif
+    {
+        /* Configure listen technologies and protocols and register callback to NFA DM discovery */
+        nfa_p2p_cb.dm_disc_handle = nfa_dm_add_rf_discover (p2p_listen_mask,
+                                                            NFA_DM_DISC_HOST_ID_DH,
+                                                            nfa_p2p_discovery_cback);
+    }
 
     /* restart RF discovery to update RF technologies */
     if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof(BT_HDR))) != NULL)
@@ -360,7 +393,19 @@
         {
             if (nfa_p2p_cb.is_initiator)
             {
-                nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
+#if(NXP_EXTNS == TRUE)
+               /*For LLCP DTA test, Deactivate to Sleep is needed to send DSL_REQ*/
+               if((appl_dta_mode_flag == 1) && (nfa_dm_cb.eDtaMode == NFA_DTA_LLCP_MODE))
+               {
+                   nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_SLEEP);
+               }
+               else
+               {
+#endif
+                   nfa_dm_rf_deactivate (NFA_DEACTIVATE_TYPE_DISCOVERY);
+#if(NXP_EXTNS == TRUE)
+               }
+#endif
             }
             else if ((nfa_p2p_cb.is_active_mode) && (reason == LLCP_LINK_TIMEOUT))
             {
@@ -604,10 +649,26 @@
 
     if (p2p_listen_mask)
     {
-        /* Configure listen technologies and protocols and register callback to NFA DM discovery */
-        nfa_p2p_cb.dm_disc_handle = nfa_dm_add_rf_discover (p2p_listen_mask,
-                                                            NFA_DM_DISC_HOST_ID_DH,
-                                                            nfa_p2p_discovery_cback);
+#if(NXP_EXTNS == TRUE)
+        /*For P2P mode(Default DTA mode) open Raw channel to bypass LLCP layer. For LLCP DTA mode activate LLCP
+         * Bypassing LLCP is handled in nfa_dm_poll_disc_cback*/
+        if ((appl_dta_mode_flag == 1) && (nfa_dm_cb.eDtaMode == NFA_DTA_DEFAULT_MODE))
+        {
+            /* Configure listen technologies and protocols and register callback to NFA DM discovery */
+            P2P_TRACE_DEBUG0 ("DTA mode2:Registering nfa_dm_poll_disc_cback to avoid LLCP in P2P ");
+            nfa_p2p_cb.dm_disc_handle = nfa_dm_add_rf_discover (p2p_listen_mask,
+                                                                NFA_DM_DISC_HOST_ID_DH,
+                                                                nfa_dm_poll_disc_cback_dta_wrapper);
+        }
+        else
+#endif
+        {
+            /* Configure listen technologies and protocols and register callback to NFA DM discovery */
+            nfa_p2p_cb.dm_disc_handle = nfa_dm_add_rf_discover (p2p_listen_mask,
+                                                                NFA_DM_DISC_HOST_ID_DH,
+                                                                nfa_p2p_discovery_cback);
+        }
+
     }
 }
 
@@ -689,7 +750,11 @@
         }
 
         /* restart discovery without updating sub-module status */
-        if (nfa_p2p_cb.is_p2p_listening)
+        if (nfa_p2p_cb.is_p2p_listening
+#if(NXP_EXTNS == TRUE)
+                || appl_dta_mode_flag
+#endif
+            )
             nfa_p2p_enable_listening (NFA_ID_P2P, FALSE);
         else if (nfa_p2p_cb.is_cho_listening)
             nfa_p2p_enable_listening (NFA_ID_CHO, FALSE);
diff --git a/src/nfa/rw/nfa_rw_act.c b/src/nfa/rw/nfa_rw_act.c
index 7418ed1..13997b7 100644
--- a/src/nfa/rw/nfa_rw_act.c
+++ b/src/nfa/rw/nfa_rw_act.c
@@ -15,8 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 /******************************************************************************
  *
  *  This file contains the action functions the NFA_RW state machine.
@@ -75,6 +92,17 @@
 {
     UINT8      *p;
 
+    if(NULL == p_rw_data)
+    {
+        NFA_TRACE_DEBUG0("nfa_rw_store_ndef_rx_buf;  p_rw_data is NULL");
+        return;
+    }
+
+    if(NULL == p_rw_data->data.p_data)
+    {
+        NFA_TRACE_DEBUG0("nfa_rw_store_ndef_rx_buf;  p_rw_data->data.p_data is NULL");
+        return;
+    }
     p = (UINT8 *)(p_rw_data->data.p_data + 1) + p_rw_data->data.p_data->offset;
 
     /* Save data into buffer */
@@ -284,6 +312,9 @@
                 conn_evt_data.ndef_detect.cur_size = 0;
                 conn_evt_data.ndef_detect.max_size = 0;
                 conn_evt_data.ndef_detect.flags    = RW_NDEF_FL_UNKNOWN;
+#if(NXP_EXTNS == TRUE)
+                conn_evt_data.ndef_detect.status   = NFA_STATUS_TIMEOUT;
+#endif
             }
             else
             {
@@ -557,11 +588,36 @@
 static void nfa_rw_handle_t1t_evt (tRW_EVENT event, tRW_DATA *p_rw_data)
 {
     tNFA_CONN_EVT_DATA conn_evt_data;
+#if(NXP_EXTNS == TRUE)
+    tNFA_TAG_PARAMS tag_params;
+    UINT8 *p_rid_rsp;
+    tNFA_STATUS activation_status;
+#endif
 
     conn_evt_data.status = p_rw_data->data.status;
     switch (event)
     {
     case RW_T1T_RID_EVT:
+#if(NXP_EXTNS == TRUE)
+        if(p_rw_data->data.p_data != NULL)
+        {
+            /* Assume the data is just the response byte sequence */
+            p_rid_rsp = (UINT8 *) (p_rw_data->data.p_data + 1) + p_rw_data->data.p_data->offset;
+            /* Fetch HR from RID response message */
+            STREAM_TO_ARRAY (tag_params.t1t.hr,  p_rid_rsp, T1T_HR_LEN);
+            /* Fetch UID0-3 from RID response message */
+            STREAM_TO_ARRAY (tag_params.t1t.uid,  p_rid_rsp, T1T_CMD_UID_LEN);
+        }
+        /* Command complete - perform cleanup, notify the app */
+        nfa_rw_command_complete();
+
+        if (p_rw_data->status == NFC_STATUS_TIMEOUT)
+            activation_status = NFA_STATUS_TIMEOUT;
+        else
+            activation_status = NFA_STATUS_OK;
+        nfa_dm_notify_activation_status(activation_status, &tag_params);
+        break;
+#endif
     case RW_T1T_RALL_CPLT_EVT:
     case RW_T1T_READ_CPLT_EVT:
     case RW_T1T_RSEG_CPLT_EVT:
@@ -1004,6 +1060,23 @@
     case RW_T4T_NDEF_DETECT_EVT :           /* Result of NDEF detection procedure */
         nfa_rw_handle_ndef_detect(event, p_rw_data);
         break;
+#if(NXP_EXTNS == TRUE)
+    case RW_T4T_NDEF_FORMAT_CPLT_EVT:
+        /* Command complete - perform cleanup, notify the app */
+        nfa_rw_command_complete();
+        nfa_rw_cb.cur_op = NFA_RW_OP_MAX;
+        nfa_rw_cb.ndef_cur_size = p_rw_data->ndef.cur_size;
+        nfa_rw_cb.ndef_max_size = p_rw_data->ndef.max_size;
+        conn_evt_data.status = (p_rw_data->status == NFC_STATUS_OK) ? NFA_STATUS_OK : NFA_STATUS_FAILED;
+
+        nfa_dm_act_conn_cback_notify(NFA_FORMAT_CPLT_EVT, &conn_evt_data);
+        break;
+
+    case RW_T3BT_RAW_READ_CPLT_EVT:
+        nfa_rw_command_complete();
+        nfa_dm_act_conn_cback_notify(NFA_ACTIVATED_EVT, &conn_evt_data);
+        break;
+#endif
 
     case RW_T4T_NDEF_READ_EVT:              /* Segment of data received from type 4 tag */
         if (nfa_rw_cb.cur_op == NFA_RW_OP_READ_NDEF)
@@ -1088,6 +1161,14 @@
         }
         break;
 
+#if(NXP_EXTNS == TRUE)
+    case RW_T4T_RAW_FRAME_RF_WTX_EVT:
+        /* Stop the presence check timer */
+        nfa_rw_stop_presence_check_timer();
+        nfa_rw_check_start_presence_check_timer (NFA_RW_PRESENCE_CHECK_INTERVAL);
+        break;
+#endif
+
     case RW_T4T_SET_TO_RO_EVT:              /* Tag is set as read only          */
         conn_evt_data.status = p_rw_data->status;
         nfa_dm_act_conn_cback_notify(NFA_SET_TAG_RO_EVT, &conn_evt_data);
@@ -1396,7 +1477,24 @@
         break;
     }
 }
+#if(NXP_EXTNS == TRUE)
+static void nfa_rw_handle_t3bt_evt (tRW_EVENT event, tRW_DATA *p_rw_data)
+{
+    //tNFC_ACTIVATE_DEVT *activate_ntf = (tNFC_ACTIVATE_DEVT*)nfa_dm_cb.p_activate_ntf;
+    NFA_TRACE_DEBUG0("nfa_rw_handle_t3bt_evt:");
 
+    switch (event)
+    {
+    case RW_T3BT_RAW_READ_CPLT_EVT:
+        nfa_rw_command_complete();
+        break;
+    default:
+        NFA_TRACE_DEBUG0("nfa_rw_handle_t3bt_evt: default event");
+        break;
+    }
+    nfa_dm_notify_activation_status(NFA_STATUS_OK, NULL);
+}
+#endif
 /*******************************************************************************
 **
 ** Function         nfa_rw_cback
@@ -1409,7 +1507,11 @@
 static void nfa_rw_cback (tRW_EVENT event, tRW_DATA *p_rw_data)
 {
     NFA_TRACE_DEBUG1("nfa_rw_cback: event=0x%02x", event);
-
+    if(NULL == p_rw_data)
+    {
+        NFA_TRACE_ERROR0("nfa_rw_cback: p_rw_data is NULL");
+        return;
+    }
     /* Call appropriate event handler for tag type */
     if (event < RW_T1T_MAX_EVT)
     {
@@ -1436,6 +1538,13 @@
         /* Handle ISO 15693 tag events */
         nfa_rw_handle_i93_evt(event, p_rw_data);
     }
+#if(NXP_EXTNS == TRUE)
+    else if (event < RW_T3BT_MAX_EVT)
+    {
+        /* Handle ISO 14443-3B tag events */
+        nfa_rw_handle_t3bt_evt(event, p_rw_data);
+    }
+#endif
     else
     {
         NFA_TRACE_ERROR1("nfa_rw_cback: unhandled event=0x%02x", event);
@@ -1785,7 +1894,9 @@
     BOOLEAN             unsupported = FALSE;
     UINT8               option = NFA_RW_OPTION_INVALID;
     tNFA_RW_PRES_CHK_OPTION op_param = NFA_RW_PRES_CHK_DEFAULT;
-
+#if(NXP_EXTNS == TRUE)
+    UINT16              iso_15693_max_presence_check_timeout = NFA_DM_ISO_15693_MAX_PRESENCE_CHECK_TIMEOUT + RW_I93_MAX_RSP_TIMEOUT;
+#endif
     switch (protocol)
     {
     case NFC_PROTOCOL_T1T:    /* Type1Tag    - NFC-A */
@@ -1903,7 +2014,16 @@
         nfa_rw_handle_presence_check_rsp(NFC_STATUS_FAILED);
     else if (!unsupported)
     {
-        nfa_sys_start_timer (&nfa_rw_cb.tle, NFA_RW_PRESENCE_CHECK_TIMEOUT_EVT, p_nfa_dm_cfg->presence_check_timeout);
+#if(NXP_EXTNS == TRUE)
+        if( protocol == NFC_PROTOCOL_15693 )
+        {
+            nfa_sys_start_timer (&nfa_rw_cb.tle, NFA_RW_PRESENCE_CHECK_TIMEOUT_EVT, iso_15693_max_presence_check_timeout);
+        }
+        else
+#endif
+        {
+            nfa_sys_start_timer (&nfa_rw_cb.tle, NFA_RW_PRESENCE_CHECK_TIMEOUT_EVT, p_nfa_dm_cfg->presence_check_timeout);
+        }
     }
 }
 
@@ -1978,6 +2098,12 @@
         status = RW_I93FormatNDef();
     }
 
+#if(NXP_EXTNS == TRUE)
+    else if (protocol == NFC_PROTOCOL_ISO_DEP)
+    {
+        status = RW_T4tFormatNDef();
+    }
+#endif
     /* If unable to format NDEF, notify the app */
     if (status != NFC_STATUS_OK)
         nfa_rw_error_cleanup (NFA_FORMAT_CPLT_EVT);
@@ -2383,6 +2509,22 @@
     return TRUE;
 }
 
+#if(NXP_EXTNS == TRUE)
+static BOOLEAN nfa_rw_t3bt_get_pupi(tNFA_RW_MSG *p_data)
+{
+    tNFC_STATUS     status;
+
+    status = RW_T3BtGetPupiID();
+
+    if(status != NFC_STATUS_OK)
+    {
+        nfa_rw_command_complete();
+    }
+
+    return TRUE;
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         nfa_rw_i93_command
@@ -2584,6 +2726,11 @@
         &&(nfa_rw_cb.pa_sel_res == NFC_SEL_RES_NFC_FORUM_T2T)  )
     {
         /* Type 2 tag is wake up from HALT State */
+        if(nfa_dm_cb.p_activate_ntf != NULL)
+        {
+            GKI_freebuf (nfa_dm_cb.p_activate_ntf);
+            nfa_dm_cb.p_activate_ntf = NULL;
+        }
         NFA_TRACE_DEBUG0("nfa_rw_activate_ntf () - Type 2 tag wake up from HALT State");
         return TRUE;
     }
@@ -2617,7 +2764,11 @@
         if (  (p_activate_params->protocol != NFA_PROTOCOL_T1T)
             &&(p_activate_params->protocol != NFA_PROTOCOL_T2T)
             &&(p_activate_params->protocol != NFA_PROTOCOL_T3T)
-            &&(p_activate_params->protocol != NFC_PROTOCOL_15693)  )
+            &&(p_activate_params->protocol != NFC_PROTOCOL_15693)
+#if(NXP_EXTNS == TRUE)
+            &&(p_activate_params->protocol != NFA_PROTOCOL_T3BT)
+#endif
+           )
         {
             nfa_rw_cb.protocol = NFA_PROTOCOL_INVALID;
         }
@@ -2668,8 +2819,13 @@
     {
     case NFC_PROTOCOL_T1T:
         /* Retrieve HR and UID fields from activation notification */
-        memcpy (tag_params.t1t.hr, p_activate_params->intf_param.intf_param.frame.param, NFA_T1T_HR_LEN);
+        memcpy (tag_params.t1t.hr, p_activate_params->rf_tech_param.param.pa.hr, NFA_T1T_HR_LEN);
         memcpy (tag_params.t1t.uid, p_activate_params->rf_tech_param.param.pa.nfcid1, p_activate_params->rf_tech_param.param.pa.nfcid1_len);
+#if(NXP_EXTNS == TRUE)
+        msg.op = NFA_RW_OP_T1T_RID;
+        nfa_rw_handle_op_req((tNFA_RW_MSG *)&msg);
+        activate_notify = FALSE;                    /* Delay notifying upper layer of NFA_ACTIVATED_EVT until HR0/HR1 is received */
+#endif
         break;
 
     case NFC_PROTOCOL_T2T:
@@ -2678,11 +2834,32 @@
         break;
 
     case NFC_PROTOCOL_T3T:
-        /* Issue command to get Felica system codes */
+#if(NXP_EXTNS == TRUE)
+        if(appl_dta_mode_flag)
+        {
+            /*Incase of DTA mode Dont send commands to get system code. Just notify activation*/
+            activate_notify=TRUE;
+        }
+        else
+        {
+#endif
+            /* Delay notifying upper layer of NFA_ACTIVATED_EVT until system codes are retrieved */
+            activate_notify = FALSE;
+            /* Issue command to get Felica system codes */
+            msg.op = NFA_RW_OP_T3T_GET_SYSTEM_CODES;
+            nfa_rw_handle_op_req((tNFA_RW_MSG *)&msg);
+#if(NXP_EXTNS == TRUE)
+        }
+#endif
+        break;
+
+#if(NXP_EXTNS == TRUE)
+    case NFC_PROTOCOL_T3BT:
         activate_notify = FALSE;                    /* Delay notifying upper layer of NFA_ACTIVATED_EVT until system codes are retrieved */
-        msg.op = NFA_RW_OP_T3T_GET_SYSTEM_CODES;
+        msg.op = NFA_RW_OP_T3BT_PUPI;
         nfa_rw_handle_op_req((tNFA_RW_MSG *)&msg);
         break;
+#endif
 
     case NFC_PROTOCOL_15693:
         /* Delay notifying upper layer of NFA_ACTIVATED_EVT to retrieve additional tag infomation */
@@ -2983,6 +3160,12 @@
         nfa_rw_i93_command (p_data);
         break;
 
+#if(NXP_EXTNS == TRUE)
+    case NFA_RW_OP_T3BT_PUPI:
+        nfa_rw_t3bt_get_pupi(p_data);
+        break;
+#endif
+
     default:
         NFA_TRACE_ERROR1("nfa_rw_handle_api: unhandled operation: %i", p_data->op_req.op);
         break;
@@ -3094,3 +3277,34 @@
     /* Restart presence_check timer */
     nfa_rw_check_start_presence_check_timer (NFA_RW_PRESENCE_CHECK_INTERVAL);
 }
+
+#if(NXP_EXTNS == TRUE)
+void nfa_rw_set_cback(tNFC_DISCOVER *p_data)
+{
+    NFA_TRACE_DEBUG0("nfa_rw_set_cback:");
+    if ((p_data != NULL) &&
+        !nfa_dm_is_protocol_supported(p_data->activate.protocol, p_data->activate.rf_tech_param.param.pa.sel_rsp))
+    {
+        NFA_TRACE_DEBUG0("nfa_rw_set_cback: nfa_rw_raw_mode_data_cback");
+        /* Set data callback (pass all incoming data to upper layer using NFA_DATA_EVT) */
+        NFC_SetStaticRfCback(nfa_rw_raw_mode_data_cback);
+    }
+}
+
+void nfa_rw_update_pupi_id(UINT8 *p, UINT8 len)
+{
+    tNFC_ACTIVATE_DEVT *activate_ntf = (tNFC_ACTIVATE_DEVT*)nfa_dm_cb.p_activate_ntf;
+
+    NFA_TRACE_DEBUG0("nfa_rw_update_pupi_id:");
+    if(len != 0)
+    {
+        activate_ntf->rf_tech_param.param.pb.pupiid_len = len;
+        memcpy(activate_ntf->rf_tech_param.param.pb.pupiid, p, len);
+    }
+    else
+    {
+        NFA_TRACE_DEBUG1("nfa_rw_update_pupi_id: invalid resp_len=%d", len);
+    }
+
+}
+#endif
diff --git a/src/nfa/rw/nfa_rw_api.c b/src/nfa/rw/nfa_rw_api.c
index f0c90a1..bdc689c 100644
--- a/src/nfa/rw/nfa_rw_api.c
+++ b/src/nfa/rw/nfa_rw_api.c
@@ -646,7 +646,7 @@
 **      NFA_STATUS_FAILED otherwise
 **
 *******************************************************************************/
-tNFA_STATUS NFA_RwT2tWrite (UINT8 block_number,	UINT8 *p_data)
+tNFA_STATUS NFA_RwT2tWrite (UINT8 block_number, UINT8 *p_data)
 {
     tNFA_RW_OPERATION *p_msg;
 
@@ -768,7 +768,7 @@
 **      NFA_STATUS_FAILED otherwise
 **
 *******************************************************************************/
-tNFA_STATUS NFA_RwT3tWrite (UINT8 num_blocks, tNFA_T3T_BLOCK_DESC *t3t_blocks,	UINT8 *p_data)
+tNFA_STATUS NFA_RwT3tWrite (UINT8 num_blocks, tNFA_T3T_BLOCK_DESC *t3t_blocks,  UINT8 *p_data)
 {
     tNFA_RW_OPERATION *p_msg;
     UINT8 *p_block_desc, *p_data_area;
diff --git a/src/nfa/sys/nfa_sys_cfg.c b/src/nfa/sys/nfa_sys_cfg.c
index e6d322a..481dbdc 100644
--- a/src/nfa/sys/nfa_sys_cfg.c
+++ b/src/nfa/sys/nfa_sys_cfg.c
@@ -37,5 +37,3 @@
 };
 
 tNFA_SYS_CFG *p_nfa_sys_cfg = (tNFA_SYS_CFG *) &nfa_sys_cfg;
-
-
diff --git a/src/nfc/include/llcp_api.h b/src/nfc/include/llcp_api.h
index 8050173..d0f3f89 100644
--- a/src/nfc/include/llcp_api.h
+++ b/src/nfc/include/llcp_api.h
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -82,6 +101,8 @@
 #define LLCP_LINK_TIMEOUT                   0x06    /* Link has been deactivated by timeout     */
 #define LLCP_LINK_FRAME_ERROR               0x07    /* Link has been deactivated by frame error */
 #define LLCP_LINK_RF_LINK_LOSS_NO_RX_LLC    0x08    /* RF link loss without any rx LLC PDU      */
+
+
 #define LLCP_LINK_RF_TRANSMISSION_ERR       NFC_STATUS_RF_TRANSMISSION_ERR
 #define LLCP_LINK_RF_PROTOCOL_ERR           NFC_STATUS_RF_PROTOCOL_ERR
 #define LLCP_LINK_RF_TIMEOUT                NFC_STATUS_TIMEOUT
@@ -226,7 +247,7 @@
 **                  - Delay SYMM response
 **                  - Data link connection timeout
 **                  - Delay timeout to send first PDU as initiator
-**
+**                  - Firmware start symmetry
 ** Returns          void
 **
 *******************************************************************************/
@@ -254,7 +275,7 @@
 **                  - Delay SYMM response
 **                  - Data link connection timeout
 **                  - Delay timeout to send first PDU as initiator
-**
+**                  - Firmware start symmetry
 ** Returns          void
 **
 *******************************************************************************/
@@ -667,6 +688,20 @@
 *******************************************************************************/
 LLCP_API extern UINT8 LLCP_SetTraceLevel (UINT8 new_level);
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         LLCP_RegisterDtaCback
+**
+** Description      Register callback function for LLCP DTA testing
+**
+**
+** Returns          void
+**
+*******************************************************************************/
+LLCP_API extern void LLCP_RegisterDtaCback (tLLCP_DTA_CBACK *p_dta_cback);
+#endif
+
 #if (LLCP_TEST_INCLUDED == TRUE)
 /*******************************************************************************
 **
@@ -686,4 +721,3 @@
 #endif
 
 #endif  /* LLCP_API_H */
-
diff --git a/src/nfc/include/nci_hmsgs.h b/src/nfc/include/nci_hmsgs.h
index 0f24c00..5152ca6 100644
--- a/src/nfc/include/nci_hmsgs.h
+++ b/src/nfc/include/nci_hmsgs.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -39,6 +58,9 @@
 void nci_proc_rf_management_ntf (BT_HDR *p_msg);
 void nci_proc_ee_management_ntf (BT_HDR *p_msg);
 void nci_proc_prop_rsp (BT_HDR *p_msg);
+#if(NXP_EXTNS == TRUE)
+void nci_proc_prop_nxp_rsp (BT_HDR *p_msg);
+#endif
 void nci_proc_prop_ntf (BT_HDR *p_msg);
 
 
@@ -60,6 +82,7 @@
 UINT8 nci_snd_t3t_polling (UINT16 system_code, UINT8 rc, UINT8 tsn);
 UINT8 nci_snd_parameter_update_cmd (UINT8 *p_param_tlvs, UINT8 tlv_size);
 
+
 #if ((NFC_NFCEE_INCLUDED == TRUE) && (NFC_RW_ONLY == FALSE))
 UINT8 nci_snd_nfcee_discover (UINT8 discover_action);
 UINT8 nci_snd_nfcee_mode_set (UINT8 nfcee_id, UINT8 nfcee_mode);
diff --git a/src/nfc/include/nfc_api.h b/src/nfc/include/nfc_api.h
index cfd0c79..1b8fc7f 100644
--- a/src/nfc/include/nfc_api.h
+++ b/src/nfc/include/nfc_api.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -56,9 +74,24 @@
 #define NFC_STATUS_EE_PROTOCOL_ERR      NCI_STATUS_EE_PROTOCOL_ERR      /* EE protocol error    */
 #define NFC_STATUS_EE_TIMEOUT           NCI_STATUS_EE_TIMEOUT           /* EE Timeout           */
 
+#if (NXP_EXTNS == TRUE)
+//DTA API for MW Version need to change according to release
+#define NXP_EN_PN547C2                  1
+#define NXP_EN_PN65T                    1
+#define NXP_EN_PN548AD                  1
+#define NXP_EN_PN66T                    1
+#define NXP_ANDROID_VER                 (4U) /* NXP android version */
+#define NFC_NXP_MW_VERSION_MAJ          (1U) /* MW Major Version */
+#define NFC_NXP_MW_VERSION_MIN          (1U) /* MW Minor Version */
+#endif
 /* 0xE0 ~0xFF are proprietary status codes */
 #define NFC_STATUS_CMD_STARTED          0xE3/* Command started successfully                     */
+#if (NXP_EXTNS == TRUE)
+#define NFC_STATUS_HW_TIMEOUT           0xEC/* changed from 0xE4 (as 0xE4 is defined for STATUS_EMVCO_PCD_COLLISOIN
+                                             NFCC Timeout in responding to an NCI command     */
+#else
 #define NFC_STATUS_HW_TIMEOUT           0xE4/* NFCC Timeout in responding to an NCI command     */
+#endif
 #define NFC_STATUS_CONTINUE             0xE5/* More (same) event to follow                      */
 #define NFC_STATUS_REFUSED              0xE6/* API is called to perform illegal function        */
 #define NFC_STATUS_BAD_RESP             0xE7/* Wrong format of R-APDU, CC file or NDEF file     */
@@ -72,6 +105,9 @@
 #define NFC_STATUS_BAD_HANDLE           0xFE                      /* invalid handle             */
 #define NFC_STATUS_CONGESTED            0xFF                      /* congested                  */
 typedef UINT8 tNFC_STATUS;
+#if (NXP_EXTNS == TRUE)
+#define NFC_NFCC_INIT_MAX_RETRY         2
+#endif
 
 
 
@@ -194,7 +230,10 @@
     NFC_DEACTIVATE_CEVT,                    /* 2  Deactivate response/notificatn*/
     NFC_DATA_CEVT,                          /* 3  Data                          */
     NFC_ERROR_CEVT,                         /* 4  generic or interface error    */
-    NFC_DATA_START_CEVT                     /* 5  received the first fragment on RF link */
+    NFC_DATA_START_CEVT,                    /* 5  received the first fragment on RF link */
+#if (NXP_EXTNS == TRUE)
+    NFC_RF_WTX_CEVT                         /* 6  received rf wtx */
+#endif
 };
 typedef UINT16 tNFC_CONN_EVT;
 
@@ -233,6 +272,17 @@
     UINT8                   *p_param_tlvs;  /* TLV                  */
 } tNFC_GET_CONFIG_REVT;
 
+#if(NXP_EXTNS == TRUE)
+/* This data type is for FW Version */
+typedef struct
+{
+    UINT8           rom_code_version;    /* ROM code Version  */
+    UINT8           major_version;       /* Major Version */
+    UINT8           minor_version;       /* Minor Version  */
+} tNFC_FW_VERSION;
+#endif
+
+
 /* the data type associated with NFC_NFCEE_DISCOVER_REVT */
 typedef struct
 {
@@ -251,7 +301,11 @@
 #define NFC_NFCEE_TAG_ATR_BYTES         NCI_NFCEE_TAG_ATR_BYTES
 #define NFC_NFCEE_TAG_T3T_INFO          NCI_NFCEE_TAG_T3T_INFO
 #define NFC_NFCEE_TAG_HCI_HOST_ID       NCI_NFCEE_TAG_HCI_HOST_ID
+#if(NXP_EXTNS == TRUE)
+typedef UINT16 tNFC_NFCEE_TAG;
+#else
 typedef UINT8 tNFC_NFCEE_TAG;
+#endif
 /* additional NFCEE Info */
 typedef struct
 {
@@ -289,13 +343,17 @@
 #define NFC_MAX_AID_LEN     NCI_MAX_AID_LEN     /* 16 */
 
 /* the data type associated with NFC_CE_GET_ROUTING_REVT */
+
+/* Max payload size  */
+#define NFC_MAX_GET_ROUTING_PLD_SIZE    255
+
 typedef struct
 {
     tNFC_STATUS             status;         /* The event status                 */
     UINT8                   nfcee_id;       /* NFCEE ID                         */
     UINT8                   num_tlvs;       /* number of TLVs                   */
     UINT8                   tlv_size;       /* the total len of all TLVs        */
-    UINT8                   param_tlvs[NFC_MAX_EE_TLV_SIZE];/* the TLVs         */
+    UINT8                   param_tlvs[NFC_MAX_GET_ROUTING_PLD_SIZE];/* the TLVs*/
 } tNFC_GET_ROUTING_REVT;
 
 
@@ -342,6 +400,12 @@
 #define NFC_PROTOCOL_T3T        NCI_PROTOCOL_T3T      /* Type3Tag    - NFC-F            */
 #define NFC_PROTOCOL_ISO_DEP    NCI_PROTOCOL_ISO_DEP  /* Type 4A,4B  - NFC-A or NFC-B   */
 #define NFC_PROTOCOL_NFC_DEP    NCI_PROTOCOL_NFC_DEP  /* NFCDEP/LLCP - NFC-A or NFC-F       */
+#if (NXP_EXTNS == TRUE)
+#define NFC_PROTOCOL_ISO7816    NCI_PROTOCOL_ISO7816 /*ISO7816 -AID default Routing */
+#define NFC_PROTOCOL_MIFARE     NCI_PROTOCOL_MIFARE
+#define NFC_PROTOCOL_ISO7816    NCI_PROTOCOL_ISO7816
+#define NFC_PROTOCOL_T3BT       NCI_PROTOCOL_T3BT
+#endif
 #define NFC_PROTOCOL_B_PRIME    NCI_PROTOCOL_B_PRIME
 #define NFC_PROTOCOL_15693      NCI_PROTOCOL_15693
 #define NFC_PROTOCOL_KOVIO      NCI_PROTOCOL_KOVIO
@@ -391,6 +455,9 @@
 #define NFC_INTERFACE_LLCP_LOW      NCI_INTERFACE_LLCP_LOW
 #define NFC_INTERFACE_LLCP_HIGH     NCI_INTERFACE_LLCP_HIGH
 #define NFC_INTERFACE_VS_T2T_CE     NCI_INTERFACE_VS_T2T_CE
+#if (NXP_EXTNS == TRUE)
+#define NFC_INTERFACE_MIFARE        NCI_INTERFACE_MIFARE
+#endif
 typedef tNCI_INTF_TYPE tNFC_INTF_TYPE;
 
 /**********************************************
@@ -531,11 +598,18 @@
 typedef tNCI_RF_PA_PARAMS tNFC_RF_PA_PARAMS;
 #define NFC_MAX_SENSB_RES_LEN         NCI_MAX_SENSB_RES_LEN
 #define NFC_NFCID0_MAX_LEN          4
+#if (NXP_EXTNS == TRUE)
+#define NFC_PUPIID_MAX_LEN          8
+#endif
 typedef struct
 {
     UINT8       sensb_res_len;/* Length of SENSB_RES Response (Byte 2 - Byte 12 or 13) Available after Technology Detection */
     UINT8       sensb_res[NFC_MAX_SENSB_RES_LEN]; /* SENSB_RES Response (ATQ) */
     UINT8       nfcid0[NFC_NFCID0_MAX_LEN];
+#if (NXP_EXTNS == TRUE)
+    UINT8       pupiid_len;
+    UINT8       pupiid[NFC_PUPIID_MAX_LEN];
+#endif
 } tNFC_RF_PB_PARAMS;
 
 #define NFC_MAX_SENSF_RES_LEN       NCI_MAX_SENSF_RES_LEN
@@ -592,7 +666,11 @@
     UINT8                   rf_disc_id;     /* RF Discovery ID                  */
     UINT8                   protocol;       /* supported protocol               */
     tNFC_RF_TECH_PARAMS     rf_tech_param;  /* RF technology parameters         */
+#if(NXP_EXTNS == TRUE)
+    UINT8                   more;           /* 0: last notification             */
+#else
     BOOLEAN                 more;           /* 0: last notification             */
+#endif
 } tNFC_RESULT_DEVT;
 
 /* the data type associated with NFC_SELECT_DEVT */
@@ -1240,6 +1318,24 @@
                                              BT_HDR        *p_data,
                                              tNFC_VS_CBACK *p_cback);
 
+#if (NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFC_SendNxpNciCommand
+**
+** Description      This function is called to send the given nxp specific
+**                  command to NFCC. The response from NFCC is reported to the
+**                  given tNFC_VS_CBACK.
+**
+** Parameters       p_data - The command buffer
+**
+** Returns          tNFC_STATUS
+**
+*******************************************************************************/
+NFC_API extern tNFC_STATUS NFC_SendNxpNciCommand (BT_HDR        *p_data,
+                               tNFC_VS_CBACK *p_cback);
+#endif
+
 /*******************************************************************************
 **
 ** Function         NFC_TestLoopback
@@ -1284,6 +1380,56 @@
 NFC_API extern char * NFC_GetStatusName (tNFC_STATUS status);
 #endif
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfc_ncif_getFWVersion
+**
+** Description      This function sets the trace level for NFC.  If called with
+**                  a value of 0xFF, it simply returns the current trace level.
+**
+** Returns          The new or current trace level
+**
+*******************************************************************************/
+NFC_API extern tNFC_FW_VERSION nfc_ncif_getFWVersion();
+#if(NFC_POWER_MANAGEMENT == TRUE)
+
+/*******************************************************************************
+**
+** Function         NFC_ReqWiredAccess
+**
+** Description      This function request to pn54x driver to get access
+**                  of P61. Status would be updated to pdata
+**
+** Returns          0 if api call success, else -1
+**
+*******************************************************************************/
+INT32 NFC_ReqWiredAccess (void *pdata);
+/*******************************************************************************
+**
+** Function         NFC_RelWiredAccess
+**
+** Description      This function release access
+**                  of P61. Status would be updated to pdata
+**
+** Returns          0 if api call success, else -1
+**
+*******************************************************************************/
+INT32 NFC_RelWiredAccess (void *pdata);
+/*******************************************************************************
+**
+** Function         NFC_GetWiredAccess
+**
+** Description      This function gets the current access state
+**                  of P61. Current state would be updated to pdata
+**
+** Returns          0 if api call success, else -1
+**
+*******************************************************************************/
+INT32 NFC_GetP61Status (void *pdata);
+#endif
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/nfc/include/rw_api.h b/src/nfc/include/rw_api.h
index 6522417..f818e04 100644
--- a/src/nfc/include/rw_api.h
+++ b/src/nfc/include/rw_api.h
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -36,6 +54,9 @@
 #define RW_T3T_FIRST_EVT    0x60
 #define RW_T4T_FIRST_EVT    0x80
 #define RW_I93_FIRST_EVT    0xA0
+#if(NXP_EXTNS == TRUE)
+#define RW_T3BT_FIRST_EVT   0xB0
+#endif
 
 enum
 {
@@ -102,6 +123,10 @@
     RW_T4T_PRESENCE_CHECK_EVT,                  /* Response to RW_T4tPresenceCheck          */
     RW_T4T_RAW_FRAME_EVT,                       /* Response of raw frame sent               */
     RW_T4T_INTF_ERROR_EVT,                      /* RF Interface error event                 */
+#if(NXP_EXTNS == TRUE)
+    RW_T4T_NDEF_FORMAT_CPLT_EVT,                /* Format operation completed               */
+    RW_T4T_RAW_FRAME_RF_WTX_EVT,                /* Received RF WTX for raw frame sent       */
+#endif
     RW_T4T_MAX_EVT,
 
     /* ISO 15693 tag events for tRW_CBACK */
@@ -120,9 +145,17 @@
     RW_I93_PRESENCE_CHECK_EVT,                  /* Response to RW_I93PresenceCheck    */
     RW_I93_RAW_FRAME_EVT,                       /* Response of raw frame sent         */
     RW_I93_INTF_ERROR_EVT,                      /* RF Interface error event           */
+#if(NXP_EXTNS == TRUE)
+    RW_I93_MAX_EVT,
+    RW_T3BT_RAW_READ_CPLT_EVT,
+    RW_T3BT_MAX_EVT
+#else
     RW_I93_MAX_EVT
+#endif
 };
-
+#if(NXP_EXTNS == TRUE)
+#define RW_I93_MAX_RSP_TIMEOUT    1000
+#endif
 #define RW_RAW_FRAME_EVT     0xFF
 
 typedef UINT8 tRW_EVENT;
@@ -840,6 +873,24 @@
 *****************************************************************************/
 NFC_API extern tNFC_STATUS RW_T3tGetSystemCodes (void);
 
+#if(NXP_EXTNS == TRUE)
+/*****************************************************************************
+**
+** Function         RW_T4tFormatNDef
+**
+** Description
+**      Format a type-4 tag for NDEF.
+**
+**      Only Desifire tags are supported by this API. The
+**      RW_T4T_FORMAT_CPLT_EVT is used to notify the status of the operation.
+**
+** Returns
+**      NFC_STATUS_OK: if success
+**      NFC_STATUS_FAILED: other error
+*****************************************************************************/
+NFC_API extern tNFC_STATUS RW_T4tFormatNDef (void);
+#endif
+
 /*******************************************************************************
 **
 ** Function         RW_T4tDetectNDef
@@ -1307,4 +1358,8 @@
 *******************************************************************************/
 NFC_API extern UINT8 RW_SetTraceLevel (UINT8 new_level);
 
+#if(NXP_EXTNS == TRUE)
+NFC_API extern tNFC_STATUS RW_T3BtGetPupiID();
+#endif
+
 #endif /* RW_API_H */
diff --git a/src/nfc/include/tags_defs.h b/src/nfc/include/tags_defs.h
index 1ef48be..d63189a 100644
--- a/src/nfc/include/tags_defs.h
+++ b/src/nfc/include/tags_defs.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -157,7 +176,7 @@
 #define T2T_CC_LEN              4     /* the len of CC used in T2T tag                  */
 
 /* Capability Container definitions */
-#define T2T_CC_BLOCK		    0x03  /* Capability container block */
+#define T2T_CC_BLOCK            0x03  /* Capability container block */
 #define T2T_CC0_NMN_BYTE        0x0C  /* NDEF Magic Number byte number */
 #define T2T_CC1_VNO_BYTE        0x0D  /* Version Number byte number*/
 #define T2T_CC2_TMS_BYTE        0x0E  /* Tag Memory Size byte number */
@@ -179,8 +198,8 @@
 #define T2T_CMD_READ            0x30    /* read  4 blocks (16 bytes) */
 #define T2T_CMD_WRITE           0xA2    /* write 1 block  (4 bytes)  */
 #define T2T_CMD_SEC_SEL         0xC2    /* Sector select             */
-#define T2T_RSP_ACK			    0xA
-#define T2T_RSP_NACK5		    0x5
+#define T2T_RSP_ACK             0xA
+#define T2T_RSP_NACK5           0x5
 #define T2T_RSP_NACK1           0x1     /* Nack can be either 1    */
 
 #define T2T_FIRST_DATA_BLOCK    4
@@ -202,7 +221,11 @@
 #define T2T_TLEN_LOCK_CTRL_TLV    3      /* Tag len for LOCK_CTRL TLV per spec */
 #define T2T_TLEN_MEM_CTRL_TLV     3      /* Tag len for MEM_CTRL TLV per spec */
 
+#if(NXP_EXTNS == TRUE)
+#define T2T_MAX_SECTOR            3      /* Maximum number of sectors supported */
+#else
 #define T2T_MAX_SECTOR            2      /* Maximum number of sectors supported */
+#endif
 
 #define T2T_TLV_TYPE_LEN                1     /* Tlv type identifier len                */
 
@@ -335,6 +358,14 @@
 #define T4T_CMD_INS_SELECT              0xA4
 #define T4T_CMD_INS_READ_BINARY         0xB0
 #define T4T_CMD_INS_UPDATE_BINARY       0xD6
+#if(NXP_EXTNS == TRUE)
+#define T4T_CMD_DES_CLASS               0x90
+#define T4T_CMD_INS_GET_HW_VERSION      0x60
+#define T4T_CMD_CREATE_AID              0xCA
+#define T4T_CMD_SELECT_APP              0x5A
+#define T4T_CMD_CREATE_DATAFILE         0xCD
+#define T4T_CMD_DES_WRITE               0x3D
+#endif
 #define T4T_CMD_P1_SELECT_BY_NAME       0x04
 #define T4T_CMD_P1_SELECT_BY_FILE_ID    0x00
 #define T4T_CMD_P2_FIRST_OR_ONLY_00H    0x00
@@ -377,6 +408,18 @@
 #define T4T_FC_NO_WRITE_ACCESS          0xFF    /* no write access granted at all (read-only) */
 
 #define T4T_FILE_LENGTH_SIZE            0x02
+#if(NXP_EXTNS == TRUE)
+#define T4T_ADDI_FRAME_RESP             0xAFU
+#define T4T_SIZE_IDENTIFIER_2K          0x16U
+#define T4T_SIZE_IDENTIFIER_4K          0x18U
+#define T4T_SIZE_IDENTIFIER_8K          0x1AU
+#define T4T_DESEV1_MAJOR_VERSION        0x01U
+#define T4T_TYPE_DESFIRE_EV1            0x01U
+#define T4T_DESEV0_MAJOR_VERSION        0x00U
+#define T4T_DESEV0_MINOR_VERSION        0x06U
+#define T4T_DES_EV1_NFC_APP_ID          0x010000
+#define T4T_DES_EV0_NFC_APP_ID          0x10EEEE
+#endif
 
 /*
 **
diff --git a/src/nfc/int/llcp_int.h b/src/nfc/int/llcp_int.h
index d6aabbd..18f64b4 100644
--- a/src/nfc/int/llcp_int.h
+++ b/src/nfc/int/llcp_int.h
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -98,7 +117,6 @@
     UINT16              symm_delay;             /* Delay SYMM response                          */
     UINT16              data_link_timeout;      /* data link conneciton timeout                 */
     UINT16              delay_first_pdu_timeout;/* delay timeout to send first PDU as initiator */
-
 } tLLCP_LCB;
 
 /*
@@ -266,6 +284,10 @@
     UINT8           total_rx_ui_pdu;                /* total number of rx UI PDU in all of ui_rx_q  */
     UINT8           total_rx_i_pdu;                 /* total number of rx I PDU in all of i_rx_q    */
     BOOLEAN         overall_rx_congested;           /* TRUE if overall rx link is congested         */
+#if(NXP_EXTNS == TRUE)
+    tLLCP_DTA_CBACK *p_dta_cback;                   /* callback to notify DTA when respoding SNL    */
+    BOOLEAN         dta_snl_resp;                   /* TRUE if need to notify DTA when respoding SNL*/
+#endif
 } tLLCP_CB;
 
 #if (LLCP_TEST_INCLUDED == TRUE) /* this is for LLCP testing */
diff --git a/src/nfc/int/nfc_int.h b/src/nfc/int/nfc_int.h
index 7845c69..c55b6e9 100644
--- a/src/nfc/int/nfc_int.h
+++ b/src/nfc/int/nfc_int.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -51,7 +70,7 @@
 /* NFC Timer events */
 #define NFC_TTYPE_NCI_WAIT_RSP              0
 #define NFC_TTYPE_WAIT_2_DEACTIVATE         1
-
+#define NFC_TTYPE_NCI_WAIT_DATA_NTF         2
 #define NFC_TTYPE_LLCP_LINK_MANAGER         100
 #define NFC_TTYPE_LLCP_LINK_INACT           101
 #define NFC_TTYPE_LLCP_DATA_LINK            102
@@ -62,6 +81,11 @@
 #define NFC_TTYPE_RW_T4T_RESPONSE           107
 #define NFC_TTYPE_RW_I93_RESPONSE           108
 #define NFC_TTYPE_CE_T4T_UPDATE             109
+#if(NXP_EXTNS == TRUE)
+#define NFC_TTYPE_P2P_PRIO_RESPONSE         110  /* added for p2p prio logic timer */
+#define NFC_TTYPE_LISTEN_ACTIVATION         111  /* added for listen activation timer */
+#define NFC_TTYPE_P2P_PRIO_LOGIC_CLEANUP    112  /* added for p2p prio logic clenaup */
+#endif
 #define NFC_TTYPE_VS_BASE                   200
 
 
@@ -80,7 +104,11 @@
     NFC_STATE_NFCC_POWER_OFF_SLEEP  /* NFCC is power-off sleep mode             */
 };
 typedef UINT8 tNFC_STATE;
-
+enum
+{
+    I2C_FRAGMENATATION_ENABLED,     /*i2c fragmentation_enabled           */
+    I2C_FRAGMENTATION_DISABLED      /*i2c_fragmentation_disabled          */
+};
 /* NFC control block flags */
 #define NFC_FL_DEACTIVATING             0x0001  /* NFC_Deactivate () is called and the NCI cmd is not sent   */
 #define NFC_FL_RESTARTING               0x0002  /* restarting NFCC after PowerOffSleep          */
@@ -115,6 +143,10 @@
     UINT8       buff_size;      /* the max buffer size for this connection.     .   */
     UINT8       num_buff;       /* num of buffers left to send on this connection   */
     UINT8       init_credits;   /* initial num of buffer credits                    */
+#if(NXP_EXTNS == TRUE)
+    UINT8       act_interface;  /* the active interface on this logical i=connetion  */
+    UINT8       sel_res;        /* the sel_res of the activated rf interface connection */
+#endif
 } tNFC_CONN_CB;
 
 /* This data type is for NFC task to send a NCI VS command to NCIT task */
@@ -143,6 +175,17 @@
 
 /* NCI command buffer contains a VSC (in BT_HDR.layer_specific) */
 #define NFC_WAIT_RSP_VSC            0x01
+#if(NXP_EXTNS == TRUE)
+#define NFC_WAIT_RSP_NXP            0x02
+#endif
+
+typedef struct
+{
+    UINT8               data_ntf_timeout;           /* indicates credit ntf timeout occured         */
+    UINT8               nci_cmd_channel_busy;      /*  indicates to the data queue that cmd is sent */
+    UINT8               data_stored;               /*  indicates data is stored to be sent later  */
+    UINT8               conn_id;                   /*  stores the conn_id of the data stored       */
+}i2c_data;
 
 /* NFC control blocks */
 typedef struct
@@ -154,6 +197,9 @@
     tNFC_RESPONSE_CBACK *p_resp_cback;
     tNFC_TEST_CBACK     *p_test_cback;
     tNFC_VS_CBACK       *p_vs_cb[NFC_NUM_VS_CBACKS];/* Register for vendor specific events  */
+#if(NXP_EXTNS == TRUE)
+    UINT8               nxpCbflag;
+#endif
 
 #if (NFC_RW_ONLY == FALSE)
     /* NFCC information at init rsp */
@@ -168,6 +214,9 @@
     UINT16              nci_interfaces;             /* the NCI interfaces of NFCC       */
     UINT8               num_disc_maps;              /* number of RF Discovery interface mappings */
     void               *p_disc_pending;            /* the parameters associated with pending NFC_DiscoveryStart */
+#if(NXP_EXTNS == TRUE)
+    void               *p_last_disc;            /* the parameters associated with pending NFC_DiscoveryStart */
+#endif
 
     /* NFC_TASK timer management */
     TIMER_LIST_Q        timer_queue;                /* 1-sec timer event queue */
@@ -177,12 +226,24 @@
 
     tNFC_STATE          nfc_state;
     BOOLEAN             reassembly;         /* Reassemble fragmented data pkt */
+#if(NXP_EXTNS == TRUE)
+    tNFC_STATE          old_nfc_state;
+#endif
     UINT8               trace_level;
     UINT8               last_hdr[NFC_SAVED_HDR_SIZE];/* part of last NCI command header */
     UINT8               last_cmd[NFC_SAVED_CMD_SIZE];/* part of last NCI command payload */
+#if(NXP_EXTNS == TRUE)
+    UINT8              *last_cmd_buf;
+    UINT8               cmd_size;
+#endif
     void                *p_vsc_cback;       /* the callback function for last VSC command */
     BUFFER_Q            nci_cmd_xmit_q;     /* NCI command queue */
+#if(NXP_EXTNS == TRUE)
+    BUFFER_Q            nci_cmd_recov_xmit_q;     /* NCI recovery command queue */
+    TIMER_LIST_ENT      listen_activation_timer_list;           /* Timer for monitoring listen activation */
+#endif
     TIMER_LIST_ENT      nci_wait_rsp_timer; /* Timer for waiting for nci command response */
+    TIMER_LIST_ENT      nci_wait_data_ntf_timer; /* Timer for waiting for core credit ntf*/
     UINT16              nci_wait_rsp_tout;  /* NCI command timeout (in ms) */
     UINT8               nci_wait_rsp;       /* layer_specific for last NCI message */
 
@@ -190,7 +251,7 @@
 
     BT_HDR              *p_nci_init_rsp;    /* holding INIT_RSP until receiving HAL_NFC_POST_INIT_CPLT_EVT */
     tHAL_NFC_ENTRY      *p_hal;
-
+    i2c_data            i2c_data_t;         /* holding i2c fragmentation data */
 } tNFC_CB;
 
 
@@ -225,7 +286,7 @@
 extern UINT8 nfc_ncif_send_data (tNFC_CONN_CB *p_cb, BT_HDR *p_data);
 NFC_API extern void nfc_ncif_cmd_timeout (void);
 NFC_API extern void nfc_wait_2_deactivate_timeout (void);
-
+NFC_API extern void nfc_ncif_credit_ntf_timeout (void);
 NFC_API extern BOOLEAN nfc_ncif_process_event (BT_HDR *p_msg);
 NFC_API extern void nfc_ncif_check_cmd_queue (BT_HDR *p_buf);
 NFC_API extern void nfc_ncif_send_cmd (BT_HDR *p_buf);
@@ -249,6 +310,15 @@
 NFC_API extern void nfc_ncif_proc_init_rsp (BT_HDR *p_msg);
 NFC_API extern void nfc_ncif_proc_get_config_rsp (BT_HDR *p_msg);
 NFC_API extern void nfc_ncif_proc_data (BT_HDR *p_msg);
+#if(NXP_EXTNS == TRUE)
+NFC_API extern tNFC_STATUS nfc_ncif_store_FWVersion(UINT8 * p_buf);
+NFC_API extern BOOLEAN nfa_dm_p2p_prio_logic(UINT8 event, UINT8 *p, UINT8 ntf_rsp);
+NFC_API extern void nfc_ncif_update_window (void);
+NFC_API extern void nfa_dm_p2p_timer_event ();
+NFC_API extern void nfc_ncif_empty_cmd_queue ();
+NFC_API extern BOOLEAN nfc_ncif_proc_proprietary_rsp (UINT8 mt, UINT8 gid, UINT8 oid);
+NFC_API extern void nfc_ncif_proc_rf_wtx_ntf (UINT8 *p, UINT16 plen);
+#endif
 
 #if (NFC_RW_ONLY == FALSE)
 NFC_API extern void nfc_ncif_proc_rf_field_ntf (UINT8 rf_status);
@@ -275,7 +345,8 @@
 void nfc_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
 void nfc_stop_quick_timer (TIMER_LIST_ENT *p_tle);
 void nfc_process_quick_timer_evt (void);
-
+void set_i2c_fragmentation_enabled(int value);
+int  get_i2c_fragmentation_enabled();
 
 #ifdef __cplusplus
 }
diff --git a/src/nfc/int/rw_int.h b/src/nfc/int/rw_int.h
index 879f7a1..ba9d83c 100644
--- a/src/nfc/int/rw_int.h
+++ b/src/nfc/int/rw_int.h
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -191,6 +210,14 @@
 #define T2T_BRCM_STATIC_MEM                             0x2E01
 #define T2T_BRCM_DYNAMIC_MEM                            0x2E02
 
+#if(NXP_EXTNS == TRUE)
+/* CC2 value on MiFare ULC tag */
+#define T2T_MIFARE_ULC_TMS                              0x12
+/* Possible corrupt cc2 value range on MiFare ULC tags */
+#define T2T_INVALID_CC_TMS_VAL0                         0x10
+#define T2T_INVALID_CC_TMS_VAL1                         0x1F
+#endif
+
 #define T2T_NDEF_NOT_DETECTED                           0x00
 #define T2T_NDEF_DETECTED                               0x01
 #define T2T_NDEF_READ                                   0x02
@@ -465,6 +492,10 @@
 
     UINT16              max_read_size;      /* max reading size per a command   */
     UINT16              max_update_size;    /* max updating size per a command  */
+#if (NXP_EXTNS == TRUE)
+    UINT16              card_size;
+    UINT8               card_type;
+#endif
 } tRW_T4T_CB;
 
 /* RW retransmission statistics */
@@ -633,6 +664,8 @@
 extern tNFC_STATUS rw_i93_select (UINT8 *p_uid);
 extern void rw_i93_process_timeout (TIMER_LIST_ENT *p_tle);
 
+void nfa_rw_update_pupi_id(UINT8 *p, UINT8 len);
+
 #if (defined (RW_STATS_INCLUDED) && (RW_STATS_INCLUDED == TRUE))
 /* Internal fcns for statistics (from rw_main.c) */
 void rw_main_reset_stats (void);
diff --git a/src/nfc/llcp/llcp_api.c b/src/nfc/llcp/llcp_api.c
index fb70b0d..41b2b0c 100644
--- a/src/nfc/llcp/llcp_api.c
+++ b/src/nfc/llcp/llcp_api.c
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -62,6 +81,25 @@
 }
 #endif
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         LLCP_RegisterDtaCback
+**
+** Description      Register callback function for LLCP DTA testing
+**
+**
+** Returns          void
+**
+*******************************************************************************/
+void LLCP_RegisterDtaCback (tLLCP_DTA_CBACK *p_dta_cback)
+{
+    LLCP_TRACE_API0 ("LLCP_RegisterDtaCback ()");
+
+    llcp_cb.p_dta_cback = p_dta_cback;
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         LLCP_SetConfig
@@ -76,7 +114,7 @@
 **                  - Delay SYMM response
 **                  - Data link connection timeout
 **                  - Delay timeout to send first PDU as initiator
-**
+**                  - firmware start symmetry
 ** Returns          void
 **
 *******************************************************************************/
@@ -158,7 +196,7 @@
 **                  - Delay SYMM response
 **                  - Data link connection timeout
 **                  - Delay timeout to send first PDU as initiator
-**
+**                  - Firmware start symmetry
 ** Returns          void
 **
 *******************************************************************************/
@@ -1646,4 +1684,3 @@
 
     return LLCP_STATUS_FAIL;
 }
-
diff --git a/src/nfc/llcp/llcp_dlc.c b/src/nfc/llcp/llcp_dlc.c
index 95bcac5..9afdc98 100644
--- a/src/nfc/llcp/llcp_dlc.c
+++ b/src/nfc/llcp/llcp_dlc.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -877,6 +895,13 @@
     {
         error_flags = 0;
 
+        if((p_msg == NULL) && (p_i_pdu == NULL))
+        {
+            LLCP_TRACE_ERROR0 ("llcp_dlc_proc_i_pdu (): Both p_msg and p_i_pdu are NULL");
+            /* Frame reject cannot be sent in this case, as we don't have sequence number */
+            llcp_dlsm_execute (p_dlcb, LLCP_DLC_EVENT_FRAME_ERROR, NULL);
+            return;
+        }
         if (p_msg)
         {
             i_pdu_length = p_msg->len;
@@ -1497,5 +1522,3 @@
     }
 }
 #endif /* (BT_TRACE_VERBOSE == TRUE) */
-
-
diff --git a/src/nfc/llcp/llcp_link.c b/src/nfc/llcp/llcp_link.c
index d70349c..9161370 100644
--- a/src/nfc/llcp/llcp_link.c
+++ b/src/nfc/llcp/llcp_link.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -32,6 +50,7 @@
 #include "llcp_defs.h"
 #include "nfc_int.h"
 
+
 const UINT16 llcp_link_rwt[15] =  /* RWT = (302us)*2**WT; 302us = 256*16/fc; fc = 13.56MHz */
 {
        1, /* WT=0,     302us */
@@ -71,6 +90,10 @@
 extern tLLCP_TEST_PARAMS llcp_test_params;
 #endif
 
+#if(NXP_EXTNS == TRUE)
+extern unsigned char appl_dta_mode_flag;
+#endif
+
 /* debug functions type */
 #if (BT_TRACE_VERBOSE == TRUE)
 static char *llcp_pdu_type (UINT8 ptype);
@@ -131,13 +154,13 @@
     {
         /* wait for application layer sending data */
         nfc_start_quick_timer (&llcp_cb.lcb.timer, NFC_TTYPE_LLCP_LINK_MANAGER,
-                               (((UINT32) llcp_cb.lcb.symm_delay) * QUICK_TIMER_TICKS_PER_SEC) / 1000);
+                (((UINT32) llcp_cb.lcb.symm_delay) * QUICK_TIMER_TICKS_PER_SEC) / 1000);
     }
     else
     {
         /* wait for data to receive from remote */
         nfc_start_quick_timer (&llcp_cb.lcb.timer, NFC_TTYPE_LLCP_LINK_MANAGER,
-                               ((UINT32) llcp_cb.lcb.peer_lto) * QUICK_TIMER_TICKS_PER_SEC / 1000);
+                ((UINT32) llcp_cb.lcb.peer_lto) * QUICK_TIMER_TICKS_PER_SEC / 1000);
     }
 }
 
@@ -152,7 +175,7 @@
 *******************************************************************************/
 static void llcp_link_stop_link_timer (void)
 {
-    nfc_stop_quick_timer (&llcp_cb.lcb.timer);
+         nfc_stop_quick_timer (&llcp_cb.lcb.timer);
 }
 
 /*******************************************************************************
@@ -204,10 +227,16 @@
                              llcp_link_rwt[p_config->waiting_time],
                              llcp_cb.lcb.peer_lto);
     }
-
-    /* extend LTO as much as internally required processing time and propagation delays */
-    llcp_cb.lcb.peer_lto += LLCP_INTERNAL_TX_DELAY + LLCP_INTERNAL_RX_DELAY;
-
+#if(NXP_EXTNS == TRUE)
+    /*For DTA mode Peer LTO Should not include TX RX Delay, Just llcp deactivate after Peer LTO time */
+    if(!appl_dta_mode_flag)
+    {
+#endif
+       /* extend LTO as much as internally required processing time and propagation delays */
+       llcp_cb.lcb.peer_lto += LLCP_INTERNAL_TX_DELAY + LLCP_INTERNAL_RX_DELAY;
+#if(NXP_EXTNS == TRUE)
+    }
+#endif
     /* LLCP version number agreement */
     if (llcp_link_version_agreement () == FALSE)
     {
@@ -222,7 +251,6 @@
         }
         return LLCP_STATUS_FAIL;
     }
-
     llcp_cb.lcb.received_first_packet = FALSE;
     llcp_cb.lcb.is_initiator = p_config->is_initiator;
 
@@ -266,6 +294,7 @@
 
         /* wait for data to receive from remote */
         llcp_link_start_link_timer ();
+
     }
 
 
@@ -455,7 +484,6 @@
 
         NFC_FlushData (NFC_RF_CONN_ID);
     }
-
     llcp_deactivate_cleanup (reason);
 }
 
@@ -820,7 +848,6 @@
 {
     BT_HDR *p_msg;
     UINT8  *p;
-
     p_msg = (BT_HDR*) GKI_getpoolbuf (LLCP_POOL_ID);
 
     if (p_msg)
@@ -876,7 +903,6 @@
 void llcp_link_check_send_data (void)
 {
     BT_HDR *p_pdu;
-
     /* don't re-enter while processing to prevent out of sequence */
     if (llcp_cb.lcb.is_sending_data)
         return;
@@ -889,7 +915,7 @@
     */
     llcp_link_check_congestion ();
 
-    if (llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_LOCAL_XMIT_NEXT)
+    if(llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_LOCAL_XMIT_NEXT)
     {
         LLCP_TRACE_DEBUG0 ("llcp_link_check_send_data () in state of LLCP_LINK_SYMM_LOCAL_XMIT_NEXT");
 
@@ -1319,7 +1345,7 @@
     BOOLEAN free_buffer = TRUE;
     BOOLEAN frame_error = FALSE;
 
-    if (llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_REMOTE_XMIT_NEXT)
+    if(llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_REMOTE_XMIT_NEXT)
     {
         llcp_link_stop_link_timer ();
 
@@ -1404,7 +1430,6 @@
                     }
                 }
             }
-
             llcp_cb.lcb.symm_state = LLCP_LINK_SYMM_LOCAL_XMIT_NEXT;
 
             /* check if any pending packet */
@@ -1650,18 +1675,25 @@
         {
             /* Get a next PDU from link manager or data links */
             p_next_pdu = llcp_link_get_next_pdu (FALSE, &next_pdu_length);
+            if(p_next_pdu != NULL )
+            {
+                p = (UINT8 *) (p_agf + 1) + p_agf->offset + p_agf->len;
 
-            p = (UINT8 *) (p_agf + 1) + p_agf->offset + p_agf->len;
+                UINT16_TO_BE_STREAM (p, p_next_pdu->len);
+                memcpy (p, (UINT8 *) (p_next_pdu + 1) + p_next_pdu->offset, p_next_pdu->len);
 
-            UINT16_TO_BE_STREAM (p, p_next_pdu->len);
-            memcpy (p, (UINT8 *) (p_next_pdu + 1) + p_next_pdu->offset, p_next_pdu->len);
+                p_agf->len += 2 + p_next_pdu->len;
 
-            p_agf->len += 2 + p_next_pdu->len;
+                GKI_freebuf (p_next_pdu);
 
-            GKI_freebuf (p_next_pdu);
-
-            /* Get next PDU length from link manager or data links without dequeue */
-            llcp_link_get_next_pdu (TRUE, &next_pdu_length);
+                /* Get next PDU length from link manager or data links without dequeue */
+                llcp_link_get_next_pdu (TRUE, &next_pdu_length);
+            }
+            else
+            {
+                LLCP_TRACE_ERROR0 ("llcp_link_build_next_pdu (): Unable to get next pdu from queue");
+                break;
+            }
         }
         else
         {
@@ -1689,9 +1721,7 @@
 #if (BT_TRACE_PROTOCOL == TRUE)
     DispLLCP (p_pdu, FALSE);
 #endif
-
-    llcp_cb.lcb.symm_state = LLCP_LINK_SYMM_REMOTE_XMIT_NEXT;
-
+         llcp_cb.lcb.symm_state = LLCP_LINK_SYMM_REMOTE_XMIT_NEXT;
     NFC_SendData (NFC_RF_CONN_ID, p_pdu);
 }
 
@@ -1762,8 +1792,8 @@
     {
         if (llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_REMOTE_XMIT_NEXT)
         {
-            /* LLCP shall stop LTO timer when receiving the first bit of LLC PDU */
-            llcp_link_stop_link_timer ();
+             /* LLCP shall stop LTO timer when receiving the first bit of LLC PDU */
+             llcp_link_stop_link_timer ();
         }
     }
 
@@ -1821,4 +1851,3 @@
 }
 
 #endif
-
diff --git a/src/nfc/llcp/llcp_main.c b/src/nfc/llcp/llcp_main.c
index 6c7560b..1e0b397 100644
--- a/src/nfc/llcp/llcp_main.c
+++ b/src/nfc/llcp/llcp_main.c
@@ -164,7 +164,7 @@
         break;
 
     case NFC_TTYPE_LLCP_DELAY_FIRST_PDU:
-        llcp_link_check_send_data ();
+            llcp_link_check_send_data ();
         break;
 
     default:
diff --git a/src/nfc/llcp/llcp_sdp.c b/src/nfc/llcp/llcp_sdp.c
index b9daa98..0535b7e 100644
--- a/src/nfc/llcp/llcp_sdp.c
+++ b/src/nfc/llcp/llcp_sdp.c
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -31,6 +50,11 @@
 #include "llcp_int.h"
 #include "llcp_defs.h"
 
+#if(NXP_EXTNS == TRUE)
+#include "nfa_sys.h"
+#include "nfa_dm_int.h"
+#endif
+
 /*******************************************************************************
 **
 ** Function         llcp_sdp_proc_data
@@ -76,6 +100,17 @@
         GKI_enqueue (&llcp_cb.lcb.sig_xmit_q, llcp_cb.sdp_cb.p_snl);
         llcp_cb.sdp_cb.p_snl = NULL;
     }
+#if(NXP_EXTNS == TRUE)
+    else
+    {
+        /* Notify DTA after sending out SNL with SDRES not to send SNLs in AGF PDU */
+        if ((llcp_cb.p_dta_cback) && (llcp_cb.dta_snl_resp))
+        {
+            llcp_cb.dta_snl_resp = FALSE;
+            (*llcp_cb.p_dta_cback) ();
+        }
+    }
+#endif
 }
 
 /*******************************************************************************
@@ -174,14 +209,12 @@
     {
         status = LLCP_STATUS_FAIL;
     }
-
     /* if LM is waiting for PDUs from upper layer */
     if (  (status == LLCP_STATUS_SUCCESS)
         &&(llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_LOCAL_XMIT_NEXT)  )
     {
         llcp_link_check_send_data ();
     }
-
     return status;
 }
 
@@ -277,14 +310,12 @@
     {
         status = LLCP_STATUS_FAIL;
     }
-
     /* if LM is waiting for PDUs from upper layer */
     if (  (status == LLCP_STATUS_SUCCESS)
         &&(llcp_cb.lcb.symm_state == LLCP_LINK_SYMM_LOCAL_XMIT_NEXT)  )
     {
         llcp_link_check_send_data ();
     }
-
     return status;
 }
 
@@ -312,6 +343,14 @@
             &&(strlen((char*)p_app_cb->p_service_name) == length)
             &&(!strncmp((char*)p_app_cb->p_service_name, p_name, length))  )
         {
+#if(NXP_EXTNS == TRUE)
+            /* if device is under LLCP DTA testing */
+            if (  (llcp_cb.p_dta_cback)
+                &&(!strncmp((char*)p_app_cb->p_service_name, "urn:nfc:sn:cl-echo-in", length))  )
+            {
+                llcp_cb.dta_snl_resp = TRUE;
+            }
+#endif
             return (sap);
         }
     }
@@ -380,6 +419,9 @@
     }
 
     llcp_cb.sdp_cb.next_tid = 0;
+#if(NXP_EXTNS == TRUE)
+    llcp_cb.dta_snl_resp = FALSE;
+#endif
 }
 
 /*******************************************************************************
@@ -422,6 +464,16 @@
             }
             else
             {
+#if(NXP_EXTNS == TRUE)
+                /*For P2P in LLCP mode TC_CTO_TAR_BI_03_x(x=3) fix*/
+                if ((appl_dta_mode_flag == 1) && (nfa_dm_cb.eDtaMode == NFA_DTA_LLCP_MODE))
+                {
+                    LLCP_TRACE_ERROR0 ("DEBUG> llcp_sdp_proc_snl () Calling llcp_sdp_send_sdres");
+                    tid = 0x01;
+                    sap = 0x00;
+                    llcp_sdp_send_sdres (tid, sap);
+                }
+#endif
                 LLCP_TRACE_ERROR1 ("llcp_sdp_proc_snl (): bad length (%d) in LLCP_SDREQ_TYPE", length);
             }
             break;
diff --git a/src/nfc/nci/nci_hmsgs.c b/src/nfc/nci/nci_hmsgs.c
index af6ad5d..a399565 100644
--- a/src/nfc/nci/nci_hmsgs.c
+++ b/src/nfc/nci/nci_hmsgs.c
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -31,7 +50,6 @@
 #include "nci_hmsgs.h"
 #include "nfc_api.h"
 #include "nfc_int.h"
-
 /*******************************************************************************
 **
 ** Function         nci_snd_core_reset
@@ -77,7 +95,6 @@
 {
     BT_HDR *p;
     UINT8 *pp;
-
     if ((p = NCI_GET_CMD_BUF (NCI_CORE_PARAM_SIZE_INIT)) == NULL)
         return (NCI_STATUS_FAILED);
 
@@ -90,7 +107,6 @@
     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_INIT);
     UINT8_TO_STREAM (pp, NCI_CORE_PARAM_SIZE_INIT);
-
     nfc_ncif_send_cmd (p);
     return (NCI_STATUS_OK);
 }
@@ -108,21 +124,54 @@
 {
     BT_HDR *p;
     UINT8 *pp;
+#if(NXP_EXTNS == TRUE)
+    UINT8 bytes;
+    UINT8 propConfigCnt;
+#endif
 
     if ((p = NCI_GET_CMD_BUF (num_ids)) == NULL)
         return (NCI_STATUS_FAILED);
+#if(NXP_EXTNS == TRUE)
+    UINT32 idx = 0;
+    UINT8 *params =  param_ids;
+    propConfigCnt=0;
+    for(idx=0; idx<num_ids; idx++)
+    {
+        if(*params == 0xA0)
+        {
+            params++;
+            propConfigCnt++;
+        }
+        params++;
+
+    }
+    bytes = (num_ids - propConfigCnt) + (propConfigCnt<<1);
+#endif
 
     p->event            = BT_EVT_TO_NFC_NCI;
+#if(NXP_EXTNS == TRUE)
+    p->len              = NCI_MSG_HDR_SIZE + bytes + 1;
+#else
     p->len              = NCI_MSG_HDR_SIZE + num_ids + 1;
+#endif
+
     p->offset           = NCI_MSG_OFFSET_SIZE;
     p->layer_specific   = 0;
     pp                  = (UINT8 *) (p + 1) + p->offset;
 
     NCI_MSG_BLD_HDR0 (pp, NCI_MT_CMD, NCI_GID_CORE);
     NCI_MSG_BLD_HDR1 (pp, NCI_MSG_CORE_GET_CONFIG);
+#if(NXP_EXTNS == TRUE)
+    UINT8_TO_STREAM (pp, (UINT8) (bytes + 1));
+#else
     UINT8_TO_STREAM (pp, (UINT8) (num_ids + 1));
+#endif
     UINT8_TO_STREAM (pp, num_ids);
+#if(NXP_EXTNS == TRUE)
+    ARRAY_TO_STREAM (pp, param_ids, bytes);
+#else
     ARRAY_TO_STREAM (pp, param_ids, num_ids);
+#endif
 
     nfc_ncif_send_cmd (p);
     return (NCI_STATUS_OK);
@@ -340,6 +389,13 @@
     int xx;
     int size;
 
+#if(NXP_EXTNS == TRUE)
+    if(NULL == p_param)
+    {
+        return NCI_STATUS_FAILED;
+    }
+#endif
+
     size   = num * sizeof (tNCI_DISCOVER_PARAMS) + 1;
     if ((p = NCI_GET_CMD_BUF (size)) == NULL)
         return (NCI_STATUS_FAILED);
@@ -481,6 +537,7 @@
     nfc_ncif_send_cmd (p);
     return (NCI_STATUS_OK);
 }
+
 /*******************************************************************************
 **
 ** Function         nci_snd_t3t_polling
diff --git a/src/nfc/nci/nci_hrcv.c b/src/nfc/nci/nci_hrcv.c
index 0248212..9fd81c0 100644
--- a/src/nfc/nci/nci_hrcv.c
+++ b/src/nfc/nci/nci_hrcv.c
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -169,6 +188,9 @@
     switch (op_code)
     {
     case NCI_MSG_RF_DISCOVER:
+#if(NXP_EXTNS == TRUE)
+        nfa_dm_p2p_prio_logic(op_code, pp, 1);
+#endif
         nfc_ncif_rf_management_status (NFC_START_DEVT, *pp);
         break;
 
@@ -184,6 +206,13 @@
         break;
 
     case NCI_MSG_RF_DEACTIVATE:
+#if(NXP_EXTNS == TRUE)
+        if (FALSE == nfa_dm_p2p_prio_logic(op_code, pp, 1))
+        {
+            NFC_TRACE_ERROR0("Dont process the Response");
+            return;
+        }
+#endif
         nfc_ncif_proc_deactivate (*pp, *p_old, FALSE);
         break;
 
@@ -238,10 +267,24 @@
         break;
 
     case NCI_MSG_RF_DEACTIVATE:
+#if(NXP_EXTNS == TRUE)
+        if (FALSE == nfa_dm_p2p_prio_logic(op_code, pp, 2))
+        {
+            NFC_TRACE_ERROR0("Dont process the Event");
+            return;
+        }
+#endif
         nfc_ncif_proc_deactivate (NFC_STATUS_OK, *pp, TRUE);
         break;
 
     case NCI_MSG_RF_INTF_ACTIVATED:
+#if(NXP_EXTNS == TRUE)
+        if (FALSE == nfa_dm_p2p_prio_logic(op_code, pp, 2))
+        {
+            NFC_TRACE_ERROR0("Dont process the Event");
+            return;
+        }
+#endif
         nfc_ncif_proc_activate (pp, len);
         break;
 
@@ -398,7 +441,19 @@
 
         for (xx = 0; xx < nfcee_info.num_tlvs; xx++, p_tlv++)
         {
+#if(NXP_EXTNS == TRUE)
+            if(*pp < 0xA0)
+            {
+                p_tlv->tag = *pp++;
+            }
+            else
+            {
+                p_tlv->tag  = *pp++;
+                p_tlv->tag  = (p_tlv->tag << 8) | *pp++;
+            }
+#else
             p_tlv->tag  = *pp++;
+#endif
             p_tlv->len  = yy = *pp++;
             NFC_TRACE_DEBUG2 ("tag:0x%x, len:0x%x", p_tlv->tag, p_tlv->len);
             if (p_tlv->len > NFC_MAX_EE_INFO)
@@ -448,6 +503,39 @@
         (*p_cback) ((tNFC_VS_EVT) (NCI_RSP_BIT|op_code), p_msg->len, p_evt);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nci_proc_prop_nxp_rsp
+**
+** Description      Process NXP NCI responses
+**
+** Returns          void
+**
+*******************************************************************************/
+void nci_proc_prop_nxp_rsp (BT_HDR *p_msg)
+{
+    UINT8   *p;
+    UINT8   *p_evt;
+    UINT8   *pp, len, op_code;
+    tNFC_VS_CBACK   *p_cback = (tNFC_VS_CBACK *)nfc_cb.p_vsc_cback;
+
+    /* find the start of the NCI message and parse the NCI header */
+    p   = p_evt = (UINT8 *) (p_msg + 1) + p_msg->offset;
+    pp  = p+1;
+    NCI_MSG_PRS_HDR1 (pp, op_code);
+    len = *pp++;
+
+    /*If there's a pending/stored command, restore the associated address of the callback function */
+    if (p_cback)
+    {
+        (*p_cback) ((tNFC_VS_EVT) (NCI_RSP_BIT|op_code), p_msg->len, p_evt);
+        nfc_cb.p_vsc_cback = NULL;
+    }
+    nfc_ncif_update_window ();
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         nci_proc_prop_ntf
@@ -470,6 +558,18 @@
     NCI_MSG_PRS_HDR1 (pp, op_code);
     len = *pp++;
 
+#if(NXP_EXTNS == TRUE)
+    NFC_TRACE_DEBUG1 ("nci_proc_prop_ntf:op_code =0x%x", op_code);
+    switch(op_code)
+    {
+    case NCI_MSG_RF_WTX:
+        nfc_ncif_proc_rf_wtx_ntf (p, p_msg->len);
+        return;
+    default:
+        break;
+    }
+#endif
+
     for (i = 0; i < NFC_NUM_VS_CBACKS; i++)
     {
         if (nfc_cb.p_vs_cb[i])
diff --git a/src/nfc/ndef/ndef_cho_utils.c b/src/nfc/ndef/ndef_cho_utils.c
index 8787817..7dd8f42 100644
--- a/src/nfc/ndef/ndef_cho_utils.c
+++ b/src/nfc/ndef/ndef_cho_utils.c
@@ -587,4 +587,3 @@
 
     return (p_rec);
 }
-
diff --git a/src/nfc/ndef/ndef_utils.c b/src/nfc/ndef/ndef_utils.c
index 974005a..f6eea76 100644
--- a/src/nfc/ndef/ndef_utils.c
+++ b/src/nfc/ndef/ndef_utils.c
@@ -1567,4 +1567,3 @@
 
     return (status);
 }
-
diff --git a/src/nfc/nfc/nfc_main.c b/src/nfc/nfc/nfc_main.c
index 908942c..b087028 100644
--- a/src/nfc/nfc/nfc_main.c
+++ b/src/nfc/nfc/nfc_main.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -61,9 +79,17 @@
 #if NFC_DYNAMIC_MEMORY == FALSE
 tNFC_CB nfc_cb;
 #endif
-
+UINT8 i2c_fragmentation_enabled = 0xff;
 #if (NFC_RW_ONLY == FALSE)
-#define NFC_NUM_INTERFACE_MAP   2
+#if(NXP_EXTNS == TRUE)
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+#define NFC_NUM_INTERFACE_MAP   4
+#else
+#define NFC_NUM_INTERFACE_MAP   3
+#endif
+#else
+#define NFC_NUM_INTERFACE_MAP   3
+#endif
 #else
 #define NFC_NUM_INTERFACE_MAP   1
 #endif
@@ -85,6 +111,23 @@
         NCI_INTERFACE_NFC_DEP
     }
 #endif
+#if(NXP_EXTNS == TRUE)
+    ,
+    {
+        NCI_PROTOCOL_MIFARE,
+        NCI_INTERFACE_MODE_POLL,
+        NCI_INTERFACE_MIFARE
+    }
+#if(NFC_NXP_CHIP_TYPE != PN547C2)
+    ,
+    /* This mapping is for Felica on DH  */
+    {
+        NCI_PROTOCOL_T3T,
+        NCI_INTERFACE_MODE_LISTEN,
+        NCI_INTERFACE_FRAME
+    }
+#endif
+#endif
 };
 
 
@@ -163,6 +206,9 @@
     case HAL_NFC_ERROR_EVT:
         return ("HAL_NFC_ERROR_EVT");
 
+    case HAL_NFC_ENABLE_I2C_FRAGMENTATION_EVT:
+        return (" HAL_NFC_ENABLE_I2C_FRAGMENTATION_EVT ");
+
     default:
         return ("???? UNKNOWN EVENT");
     }
@@ -238,7 +284,11 @@
         {
             if ((*p) <= NCI_INTERFACE_MAX)
                 evt_data.enable.nci_interfaces |= (1 << (*p));
+            #if(NXP_EXTNS == TRUE)
+            else if (((*p) >= NCI_INTERFACE_FIRST_VS) && (yy < NFC_NFCC_MAX_NUM_VS_INTERFACE))
+            #else
             else if (((*p) > NCI_INTERFACE_FIRST_VS) && (yy < NFC_NFCC_MAX_NUM_VS_INTERFACE))
+            #endif
             {
                 /* save the VS RF interface in control block, if there's still room */
                 nfc_cb.vs_interface[yy++] = *p;
@@ -322,7 +372,17 @@
     if (nfc_cb.flags & NFC_FL_DISCOVER_PENDING)
     {
         nfc_cb.flags &= ~NFC_FL_DISCOVER_PENDING;
+
+#if(NXP_EXTNS == TRUE)
+        if(nfc_cb.p_last_disc)
+        {
+            GKI_freebuf (nfc_cb.p_last_disc);
+            nfc_cb.p_last_disc = NULL;
+        }
+        nfc_cb.p_last_disc = nfc_cb.p_disc_pending;
+#else
         GKI_freebuf (nfc_cb.p_disc_pending);
+#endif
         nfc_cb.p_disc_pending = NULL;
     }
 
@@ -423,7 +483,16 @@
             nfc_cb.flags &= ~NFC_FL_DISCOVER_PENDING;
             ps            = (UINT8 *)nfc_cb.p_disc_pending;
             nci_snd_discover_cmd (*ps, (tNFC_DISCOVER_PARAMS *)(ps + 1));
+#if(NXP_EXTNS == TRUE)
+            if(nfc_cb.p_last_disc)
+            {
+                GKI_freebuf( nfc_cb.p_last_disc);
+                nfc_cb.p_last_disc = NULL;
+            }
+            nfc_cb.p_last_disc = nfc_cb.p_disc_pending;
+#else
             GKI_freebuf (nfc_cb.p_disc_pending);
+#endif
             nfc_cb.p_disc_pending = NULL;
         }
         else
@@ -600,7 +669,12 @@
     case HAL_NFC_ERROR_EVT:
         nfc_main_post_hal_evt (event, status);
         break;
-
+    case HAL_NFC_ENABLE_I2C_FRAGMENTATION_EVT:
+    {
+        NFC_TRACE_DEBUG1 ("nfc_main_hal_cback handled  event  %x", event);
+        set_i2c_fragmentation_enabled(I2C_FRAGMENATATION_ENABLED);
+    }
+        break;
     default:
         NFC_TRACE_DEBUG1 ("nfc_main_hal_cback unhandled event %x", event);
         break;
@@ -840,10 +914,18 @@
     UINT8   xx, yy, num_intf, intf_mask;
     tNFC_DISCOVER_MAPS  max_maps[NFC_NFCC_MAX_NUM_VS_INTERFACE + NCI_INTERFACE_MAX];
     BOOLEAN is_supported;
-
+    #if (NXP_EXTNS == TRUE)
+    nfc_cb.num_disc_maps = num;
+    #endif
     nfc_cb.p_discv_cback = p_cback;
     num_intf             = 0;
     NFC_TRACE_DEBUG1 ("nci_interfaces supported by NFCC: 0x%x", nfc_cb.nci_interfaces);
+
+    for(xx = 0; xx < NFC_NFCC_MAX_NUM_VS_INTERFACE + NCI_INTERFACE_MAX; xx++)
+    {
+        memset(&max_maps[xx], 0x00, sizeof(tNFC_DISCOVER_MAPS));
+    }
+
     for (xx = 0; xx < num_disc_maps; xx++)
     {
         is_supported = FALSE;
@@ -873,6 +955,14 @@
         }
     }
 
+    NFC_TRACE_WARNING1 ("num_intf = 0x%2x",num_intf);
+
+    for(xx = 0; xx < NFC_NFCC_MAX_NUM_VS_INTERFACE + NCI_INTERFACE_MAX; xx++)
+    {
+        NFC_TRACE_WARNING2 ("max_maps[%d].intf_type = 0x%2x",xx,max_maps[xx].intf_type);
+        NFC_TRACE_WARNING2 ("max_maps[%d].mode = 0x%2x",xx,max_maps[xx].mode);
+        NFC_TRACE_WARNING2 ("max_maps[%d].protocol = 0x%2x",xx,max_maps[xx].protocol);
+    }
     return nci_snd_discover_map_cmd (num_intf, (tNCI_DISCOVER_MAPS *) max_maps);
 }
 
@@ -1176,7 +1266,16 @@
             /* if HAL did not request for control, clear this bit now */
             nfc_cb.flags &= ~NFC_FL_CONTROL_REQUESTED;
         }
+#if(NXP_EXTNS == TRUE)
+        if( nfc_cb.p_last_disc)
+        {
+            GKI_freebuf (nfc_cb.p_last_disc);
+            nfc_cb.p_last_disc = NULL;
+        }
+        nfc_cb.p_last_disc = nfc_cb.p_disc_pending;
+#else
         GKI_freebuf (nfc_cb.p_disc_pending);
+#endif
         nfc_cb.p_disc_pending = NULL;
         return NFC_STATUS_OK;
     }
@@ -1344,6 +1443,61 @@
 
     return (nfc_cb.trace_level);
 }
+void set_i2c_fragmentation_enabled(int value)
+{
+    i2c_fragmentation_enabled = value;
+}
+
+int  get_i2c_fragmentation_enabled()
+{
+    return i2c_fragmentation_enabled;
+}
+
+#if((NFC_POWER_MANAGEMENT == TRUE)&&(NXP_EXTNS == TRUE))
+/*******************************************************************************
+**
+** Function         NFC_ReqWiredAccess
+**
+** Description      This function request to pn54x driver to get access
+**                  of P61. Status would be updated to pdata
+**
+** Returns          0 if api call success, else -1
+**
+*******************************************************************************/
+INT32 NFC_ReqWiredAccess (void *pdata)
+{
+    return (nfc_cb.p_hal->ioctl(1, pdata));
+}
+/*******************************************************************************
+**
+** Function         NFC_RelWiredAccess
+**
+** Description      This function release access
+**                  of P61. Status would be updated to pdata
+**
+** Returns          0 if api call success, else -1
+**
+*******************************************************************************/
+INT32 NFC_RelWiredAccess (void *pdata)
+{
+    return (nfc_cb.p_hal->ioctl(0, pdata));
+}
+/*******************************************************************************
+**
+** Function         NFC_GetP61Status
+**
+** Description      This function gets the current access state
+**                  of P61. Current state would be updated to pdata
+**
+** Returns          0 if api call success, else -1
+**
+*******************************************************************************/
+INT32 NFC_GetP61Status (void *pdata)
+{
+    return (nfc_cb.p_hal->ioctl(2, pdata));
+}
+#endif
+
 
 #if (BT_TRACE_VERBOSE == TRUE)
 /*******************************************************************************
diff --git a/src/nfc/nfc/nfc_ncif.c b/src/nfc/nfc/nfc_ncif.c
index 4316807..f74d10e 100644
--- a/src/nfc/nfc/nfc_ncif.c
+++ b/src/nfc/nfc/nfc_ncif.c
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -24,8 +43,8 @@
  *  (callback). On the transmit side, it manages the command transmission.
  *
  ******************************************************************************/
-#include <stdlib.h>
 #include <string.h>
+#include <stdlib.h>
 #include "nfc_target.h"
 
 #if NFC_INCLUDED == TRUE
@@ -39,17 +58,37 @@
 #include "hcidefs.h"
 #include "nfc_hal_api.h"
 
+#if(NXP_EXTNS == TRUE)
+#include "nfa_ce_int.h"
+#include "nfa_sys.h"
+#include "nfa_dm_int.h"
+#include "nfa_hci_int.h"
+#endif
+tNFC_CONN_CB *p_cb_stored = NULL;
 #if (NFC_RW_ONLY == FALSE)
 static const UINT8 nfc_mpl_code_to_size[] =
 {64, 128, 192, 254};
 
 #endif /* NFC_RW_ONLY */
 
-
+#define NFC_NCI_WAIT_DATA_NTF_TOUT      2
 #define NFC_PB_ATTRIB_REQ_FIXED_BYTES   1
 #define NFC_LB_ATTRIB_REQ_FIXED_BYTES   8
 
+#if(NXP_EXTNS == TRUE)
+// Global Structure varibale for FW Version
+static tNFC_FW_VERSION nfc_fw_version;
+uint8_t sListenActivated;
+extern tNFA_CE_CB nfa_ce_cb;
+BOOLEAN core_reset_init_num_buff = FALSE;
+UINT8 nfcc_dh_conn_id;
+extern void nfa_hci_rsp_timeout (tNFA_HCI_EVENT_DATA *p_evt_data);
+void disc_deact_ntf_timeout_handler(tNFC_RESPONSE_EVT event);
+#endif
 
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+extern etsi_reader_in_progress;
+#endif
 /*******************************************************************************
 **
 ** Function         nfc_ncif_update_window
@@ -80,7 +119,22 @@
     /* Check if there were any commands waiting to be sent */
     nfc_ncif_check_cmd_queue (NULL);
 }
-
+/*******************************************************************************
+**
+** Function         nfc_ncif_update_data_queue
+**
+** Description      Update tx cmd window  to indicate that NFCC can received and core credit ntf received
+**
+** Returns          void
+**
+*********************************************************************************/
+void nfc_ncif_update_data_queue (void)
+{
+    nfc_cb.nci_cmd_window++;
+    NFC_TRACE_ERROR0 ("nfc_ncif_update_data_queue- incrementing window");
+    /* Check if there were any commands waiting to be sent */
+    nfc_ncif_check_cmd_queue(NULL);
+}
 /*******************************************************************************
 **
 ** Function         nfc_ncif_cmd_timeout
@@ -94,6 +148,127 @@
 {
     NFC_TRACE_ERROR0 ("nfc_ncif_cmd_timeout");
 
+#if(NXP_EXTNS == TRUE)
+
+    NFC_TRACE_ERROR0 ("Recovery Start!");
+    {
+        // TO DO:
+        // Sending command which are core_reset,init,discovery as raw packet (Hard coding)
+        // and we have to match the RF state between before entering recovery and after recovery.
+        // finally, executing the last command which is before entering recovery, and invoking the callback.
+
+        //step 1. sending core reset/init command
+        //step 2. deciding to send command whether discovery or not.
+        //step 3. invoking the callback function which is registered at last time before entering recovery.
+
+        /*
+            consist of buffer(p_core_init_rsp_params)
+            buffer[0] = Used by recovery. 0 or 1.  1- used for recovery 2-core reset is last command 3-core init is last command
+            buffer[1] = Last RF State, 0:Idle State 1:Discovery State
+            buffer[2] = Length of discovery packet.
+            buffer[3~34] = Last Discovery command(including phase data).(32 byte)
+            buffer[35] = Length of last command packet.
+            buffer[36~255] = Last Command /or Last Command & Data.
+        */
+        UINT8 *buffer = NULL;
+        UINT8 bufflen = 0xFF;
+        tNFC_STATUS status = NFC_STATUS_FAILED;
+        tNFC_CONN_CB * p_cb = NULL;
+        nfc_stop_timer (&nfc_cb.nci_wait_rsp_timer); // stop the command timeout timer.
+
+        buffer = (UINT8 *) malloc(bufflen*sizeof(UINT8));
+        if(NULL == buffer)
+        {
+            NFC_TRACE_ERROR0 ("Recovery MEM Allocation is failed!!");
+            return;
+        }
+        memset(buffer, 0x00, (bufflen*sizeof(UINT8)));
+        buffer[0] = 1;   //Sending reset/init command as raw packet in HAL layer.
+
+        NFC_TRACE_ERROR1 ("Last State nfa_dm_cb.disc_cb.disc_flags 0x%x", nfa_dm_cb.disc_cb.disc_flags);
+        NFC_TRACE_ERROR1 ("Last State nfa_dm_cb.disc_cb.disc_state 0x%x", nfa_dm_cb.disc_cb.disc_state);
+
+        if(!(nfa_dm_cb.disc_cb.disc_state > NFA_DM_RFST_IDLE))
+        {
+            NFC_TRACE_ERROR0 ("Last State is Idle!!");
+            buffer[1] = 0; //Idle State.
+        }
+        else
+        {
+            UINT8 *ps = (UINT8 *)nfc_cb.p_last_disc;
+            NFC_TRACE_ERROR0 ("Last State is Discovery!!");
+            buffer[1] = 1; //Discovery State.
+            nfa_dm_cb.disc_cb.disc_state = 0x01; //RF State is initialized to discovery.
+            nfa_ce_cb.flags = 0x00; // Listen Flag is initialized to 0x00.
+            if(ps[0])
+            {
+                buffer[2] = 2 + 1 + 1 + (ps[0] * 2); // HDR(2) + Length(1) + Entry(1) + Data(Tech(2) * 2)
+                memcpy((UINT8 *)&buffer[3], "\x21\x03", 2);
+                buffer[5] = 1 + (ps[0] * 2); // Entity(1) + Data(Tech(2) * 2)
+                memcpy((UINT8 *)&buffer[6], ps, buffer[5]);
+            }
+            else
+            {
+                buffer[2] = 26; //Length of packet
+                memcpy((UINT8 *)&buffer[3],
+                    "\x21\x03\x17\x0B\x00\x01\x01\x01\x02\x01\x03\x01\x80\x01\x81\x01\x82\x01\x83\x01\x85\x01\x06\x01\x77\x01", 24);
+            }
+        }
+        if((nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x06 && nfc_cb.last_cmd_buf[0] == 0x01 && nfc_cb.last_cmd_buf[1] == 0x01) ||
+           (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x04)  ||
+           (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x08) ||
+           (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x06 && nfc_cb.last_cmd_buf[0] == 0x01 && nfc_cb.last_cmd_buf[1] == 0x03))
+        {
+            buffer[35] = 0x00;
+        }
+        else if((nfc_cb.last_hdr[0] == 0x20 && (nfc_cb.last_hdr[1] == 0x02 || nfc_cb.last_hdr[1] == 0x03))
+        || (nfc_cb.last_hdr[0] == 0x2F && nfc_cb.last_hdr[1] == 0x15)
+        || (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x01)
+        || (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x06))
+        {
+            buffer[35] = nfc_cb.cmd_size + 3;  //HDR(2) + Lengh(1) + Cmd data(n)
+            memcpy(&buffer[36], nfc_cb.last_hdr, 2);
+            memcpy(&buffer[38], nfc_cb.last_cmd_buf, nfc_cb.cmd_size + 1);
+        }
+        else
+        {
+            buffer[35] = 2 + 1 + nfc_cb.cmd_size;  //HDR(2) + Lengh(1) + Command Size(2)
+            memcpy(&buffer[36], nfc_cb.last_hdr, NFC_SAVED_HDR_SIZE);
+            buffer[38] = nfc_cb.cmd_size; // Length of Command.(2)
+            if(nfc_cb.cmd_size > 0)
+                memcpy(&buffer[39], nfc_cb.last_cmd, NFC_SAVED_CMD_SIZE);
+            if(nfc_cb.last_hdr[0] == 0x20 && nfc_cb.last_hdr[1] == 0x00) buffer[0] = 2;   //last packet is CORE_RESET.
+            else if (nfc_cb.last_hdr[0] == 0x20 && nfc_cb.last_hdr[1] == 0x01) buffer[0] = 3; //last packet is CORE_INIT.
+        }
+        /* if HCI state is in wait response then stop the timer and send the response timeout event to the upper layer*/
+        if(nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_RSP)
+        {
+            BT_HDR *p_msg;
+            nfa_sys_stop_timer(&nfa_hci_cb.timer);
+            if ((p_msg = (BT_HDR *) GKI_getbuf (sizeof (BT_HDR))) != NULL)
+            {
+                NFC_TRACE_ERROR0("GKI Get Buffer Successful...Sending response timeout to upper layer");
+                p_msg->event = NFA_HCI_RSP_TIMEOUT_EVT;
+                p_msg->layer_specific = 0;
+                nfa_sys_sendmsg (p_msg);
+            }
+        }
+        /* Flush the data if any before proceeding further with the recovery */
+        p_cb = nfc_find_conn_cb_by_conn_id(nfcc_dh_conn_id);
+        NFC_TRACE_ERROR1("connection id %d", nfcc_dh_conn_id);
+        if(NULL != p_cb)
+        {
+            status = NFC_FlushData(p_cb->conn_id);
+            if(status != NFC_STATUS_OK)
+            {
+                NFC_TRACE_ERROR0 ("NFC data flush failed");
+            }
+        }
+        nfc_cb.p_hal->core_initialized (buffer);
+
+        if(buffer != NULL) free(buffer);
+    }
+#else
     /* report an error */
     nfc_ncif_event_status(NFC_GEN_ERROR_REVT, NFC_STATUS_HW_TIMEOUT);
     nfc_ncif_event_status(NFC_NFCC_TIMEOUT_REVT, NFC_STATUS_HW_TIMEOUT);
@@ -103,9 +278,9 @@
     {
         nfc_enabled (NFC_STATUS_FAILED, NULL);
     }
-
     /* XXX maco since this failure is unrecoverable, abort the process */
     abort();
+#endif
 }
 
 /*******************************************************************************
@@ -147,6 +322,25 @@
     UINT8   hdr0 = p_cb->conn_id;
     BOOLEAN fragmented = FALSE;
 
+#if(NXP_EXTNS == TRUE)
+    if(core_reset_init_num_buff == TRUE)
+    {
+        NFC_TRACE_ERROR0("Reinitializing the num_buff");
+        p_cb->num_buff++;
+        core_reset_init_num_buff = FALSE;
+    }
+#endif
+    if(get_i2c_fragmentation_enabled() == I2C_FRAGMENATATION_ENABLED)
+    {
+         if(nfc_cb.i2c_data_t.nci_cmd_channel_busy == 1 && p_data)
+         {
+             NFC_TRACE_DEBUG0 ("NxpNci : avoiding data packet sending data packet");
+             nfc_cb.i2c_data_t.conn_id = p_cb->conn_id;
+             GKI_enqueue (&p_cb->tx_q, p_data);
+             nfc_cb.i2c_data_t.data_stored = 1;
+             return NCI_STATUS_OK;
+         }
+    }
     NFC_TRACE_DEBUG3 ("nfc_ncif_send_data :%d, num_buff:%d qc:%d", p_cb->conn_id, p_cb->num_buff, p_cb->tx_q.count);
     if (p_cb->id == NFC_RF_CONN_ID)
     {
@@ -212,9 +406,9 @@
             p->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE + 1;
             if (p->len)
             {
-            pp        = (UINT8 *)(p + 1) + p->offset;
-            ps        = (UINT8 *)(p_data + 1) + p_data->offset;
-            memcpy (pp, ps, ulen);
+                pp        = (UINT8 *)(p + 1) + p->offset;
+                ps        = (UINT8 *)(p_data + 1) + p_data->offset;
+                memcpy (pp, ps, ulen);
             }
             /* adjust the BT_HDR on the old fragment */
             p_data->len     -= ulen;
@@ -228,23 +422,56 @@
         pp = (UINT8 *)(p + 1) + p->offset;
         /* build NCI Data packet header */
         NCI_DATA_PBLD_HDR(pp, pbf, hdr0, ulen);
-
         if (p_cb->num_buff != NFC_CONN_NO_FC)
             p_cb->num_buff--;
 
         /* send to HAL */
         HAL_WRITE(p);
-
+#if(NXP_EXTNS == TRUE)
+        /* start NFC data ntf timeout timer */
+        if( get_i2c_fragmentation_enabled () == I2C_FRAGMENATATION_ENABLED)
+        {
+            nfc_cb.nci_cmd_window--;
+        }
+        nfc_start_timer (&nfc_cb.nci_wait_data_ntf_timer, (UINT16)(NFC_TTYPE_NCI_WAIT_DATA_NTF), NFC_NCI_WAIT_DATA_NTF_TOUT);
         if (!fragmented)
         {
             /* check if there are more data to send */
             p_data = (BT_HDR *)GKI_getfirst (&p_cb->tx_q);
         }
+#endif
     }
 
     return (NCI_STATUS_OK);
 }
 
+#if(NXP_EXTNS == TRUE)
+/*Function to empty cmd queue.*/
+void nfc_ncif_empty_cmd_queue ()
+{
+    BT_HDR *p_buf = (BT_HDR *)GKI_dequeue (&nfc_cb.nci_cmd_xmit_q);
+
+    while(p_buf)
+    {
+        GKI_freebuf (p_buf);
+        p_buf = (BT_HDR *)GKI_dequeue (&nfc_cb.nci_cmd_xmit_q);
+    }
+}
+#endif
+
+#if(NXP_EXTNS == TRUE)
+/*Function to empty data queue.*/
+void nfc_ncif_empty_data_queue ()
+{
+    BT_HDR * p_data    = (BT_HDR *)GKI_dequeue (&p_cb_stored->tx_q);
+
+    while(p_data)
+    {
+        GKI_freebuf (p_data);
+        p_data    = (BT_HDR *)GKI_dequeue (&p_cb_stored->tx_q);
+    }
+}
+#endif
 /*******************************************************************************
 **
 ** Function         nfc_ncif_check_cmd_queue
@@ -264,10 +491,16 @@
         if ((nfc_cb.nci_cmd_xmit_q.count) || (nfc_cb.nci_cmd_window == 0))
         {
             GKI_enqueue (&nfc_cb.nci_cmd_xmit_q, p_buf);
+#if (NXP_EXTNS == TRUE)
+            if(p_buf != NULL){
+                NFC_TRACE_DEBUG0 ("nfc_ncif_check_cmd_queue : making  p_buf NULL.");
+                p_buf = NULL;
+            }
+#else
             p_buf = NULL;
+#endif
         }
     }
-
     /* If controller can accept another command, then send the next command */
     if (nfc_cb.nci_cmd_window > 0)
     {
@@ -277,19 +510,58 @@
 
         if (p_buf)
         {
+#if (NXP_EXTNS == TRUE)
+
+            /* save the message header to double check the response */
+            ps   = (UINT8 *)(p_buf + 1) + p_buf->offset;
+            memcpy(nfc_cb.last_hdr, ps, NFC_SAVED_HDR_SIZE);
+
+            if((nfc_cb.last_hdr[0] == 0x20 && (nfc_cb.last_hdr[1] == 0x02 || nfc_cb.last_hdr[1] == 0x03))
+                || (nfc_cb.last_hdr[0] == 0x2F && nfc_cb.last_hdr[1] == 0x15)
+                || (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x01)
+                || (nfc_cb.last_hdr[0] == 0x21 && nfc_cb.last_hdr[1] == 0x06))
+            {
+                nfc_cb.cmd_size = *(ps + NFC_SAVED_HDR_SIZE);
+                if (nfc_cb.last_cmd_buf != NULL)
+                {
+                    GKI_freebuf(nfc_cb.last_cmd_buf); // ======> Free before allocation
+                }
+                nfc_cb.last_cmd_buf = (UINT8 *) GKI_getbuf(nfc_cb.cmd_size +1 );
+                memcpy(nfc_cb.last_cmd_buf, ps + NFC_SAVED_HDR_SIZE, (nfc_cb.cmd_size + 1));
+                memcpy(nfc_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_SAVED_CMD_SIZE);
+            }
+            else
+            {
+                nfc_cb.cmd_size = *(ps + NFC_SAVED_HDR_SIZE);
+                memcpy(nfc_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_SAVED_CMD_SIZE);
+            }
+#else
             /* save the message header to double check the response */
             ps   = (UINT8 *)(p_buf + 1) + p_buf->offset;
             memcpy(nfc_cb.last_hdr, ps, NFC_SAVED_HDR_SIZE);
             memcpy(nfc_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_SAVED_CMD_SIZE);
+#endif
             if (p_buf->layer_specific == NFC_WAIT_RSP_VSC)
             {
                 /* save the callback for NCI VSCs)  */
                 nfc_cb.p_vsc_cback = (void *)((tNFC_NCI_VS_MSG *)p_buf)->p_cback;
             }
+#if(NXP_EXTNS == TRUE)
+            else if (p_buf->layer_specific == NFC_WAIT_RSP_NXP)
+            {
+                /* save the callback for NCI NXPs)  */
+                nfc_cb.p_vsc_cback = (void *)((tNFC_NCI_VS_MSG *)p_buf)->p_cback;
+                nfc_cb.nxpCbflag = TRUE;
+            }
+#endif
 
             /* send to HAL */
             HAL_WRITE(p_buf);
-
+            if (get_i2c_fragmentation_enabled () == I2C_FRAGMENATATION_ENABLED)
+            {
+                nfc_cb.i2c_data_t.nci_cmd_channel_busy= 1;
+                NFC_TRACE_DEBUG0 ("setting channel busy flag");
+            }
             /* Indicate command is pending */
             nfc_cb.nci_cmd_window--;
 
@@ -320,7 +592,16 @@
                     nfc_cb.flags         &= ~NFC_FL_DISCOVER_PENDING;
                     ps                    = (UINT8 *)nfc_cb.p_disc_pending;
                     nci_snd_discover_cmd (*ps, (tNFC_DISCOVER_PARAMS *)(ps + 1));
+#if(NXP_EXTNS == TRUE)
+                    if(nfc_cb.p_last_disc)
+                    {
+                        GKI_freebuf( nfc_cb.p_last_disc);
+                        nfc_cb.p_last_disc = NULL;
+                    }
+                    nfc_cb.p_last_disc = nfc_cb.p_disc_pending;
+#else
                     GKI_freebuf (nfc_cb.p_disc_pending);
+#endif
                     nfc_cb.p_disc_pending = NULL;
                 }
             }
@@ -348,6 +629,22 @@
 *******************************************************************************/
 void nfc_ncif_send_cmd (BT_HDR *p_buf)
 {
+#if(NXP_EXTNS == TRUE)
+    NFC_TRACE_DEBUG0 ("nfc_ncif_send_cmd.");
+    if(p_buf == NULL)
+    {
+        NFC_TRACE_DEBUG0 ("p_buf is NULL.");
+        return;
+    }
+    UINT8 *cmd = NULL;
+    cmd = (UINT8 *)(p_buf+1) + p_buf->offset;
+
+    if(sListenActivated == TRUE)
+    {
+        nfc_stop_timer (&nfc_cb.listen_activation_timer_list);
+        sListenActivated = FALSE;
+    }
+#endif
     /* post the p_buf to NCIT task */
     p_buf->event            = BT_EVT_TO_NFC_NCI;
     p_buf->layer_specific   = 0;
@@ -371,11 +668,27 @@
     BOOLEAN free = TRUE;
     UINT8   oid;
     UINT8   *p_old, old_gid, old_oid, old_mt;
-
     p = (UINT8 *) (p_msg + 1) + p_msg->offset;
 
     pp = p;
     NCI_MSG_PRS_HDR0 (pp, mt, pbf, gid);
+#if(NXP_EXTNS == TRUE)
+    oid = ((*pp) & NCI_OID_MASK);
+
+
+    if(sListenActivated == TRUE)
+    {
+        nfc_stop_timer (&nfc_cb.listen_activation_timer_list);
+        sListenActivated = FALSE;
+    }
+
+    if ((nfc_cb.nxpCbflag == TRUE)&&(nfc_ncif_proc_proprietary_rsp(mt,gid,oid) == TRUE))
+    {
+        nci_proc_prop_nxp_rsp(p_msg);
+        nfc_cb.nxpCbflag = FALSE;
+        return (free);
+    }
+#endif
 
     switch (mt)
     {
@@ -394,8 +707,32 @@
         /* make sure this is the RSP we are waiting for before updating the command window */
         if ((old_gid != gid) || (old_oid != oid))
         {
-            NFC_TRACE_ERROR2 ("nfc_ncif_process_event unexpected rsp: gid:0x%x, oid:0x%x", gid, oid);
-            return TRUE;
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+            if(((gid == NCI_GID_RF_MANAGE)&&(oid == NCI_MSG_RF_DISCOVER)) && (etsi_reader_in_progress == TRUE))
+            {
+                NFC_TRACE_DEBUG0 ("Changing disc_state and disc_flags");
+                nfa_dm_cb.disc_cb.disc_state = NFA_DM_RFST_IDLE;
+                nfa_dm_cb.disc_cb.disc_flags &= ~(NFA_DM_DISC_FLAGS_W4_NTF | NFA_DM_DISC_FLAGS_STOPPING);
+                nfa_dm_cb.disc_cb.disc_flags |= (NFA_DM_DISC_FLAGS_W4_RSP|NFA_DM_DISC_FLAGS_NOTIFY|NFA_DM_DISC_FLAGS_ENABLED);
+                disc_deact_ntf_timeout_handler(NFC_NFCC_TIMEOUT_REVT);
+            }
+            else
+            {
+#endif
+            /*no response after the deactivate command, handling the error scenario after the recovery*/
+            if((gid == NCI_GID_RF_MANAGE)&&(oid == NCI_MSG_RF_DISCOVER)&&(nfc_cb.nci_cmd_window == 0))
+            {
+                NFC_TRACE_DEBUG0 ("resetting the nci_cmd_window");
+                nfc_cb.nci_cmd_window ++;
+            }
+            else
+            {
+                NFC_TRACE_ERROR2 ("nfc_ncif_process_event unexpected rsp: gid:0x%x, oid:0x%x", gid, oid);
+                return TRUE;
+            }
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+            }
+#endif
         }
 
         switch (gid)
@@ -420,10 +757,33 @@
             NFC_TRACE_ERROR1 ("NFC: Unknown gid:%d", gid);
             break;
         }
-
-        nfc_ncif_update_window ();
+#if(NXP_EXTNS == TRUE)
+        //received command response
+        //set the saved header and command  buffer to zero
+        nfc_cb.cmd_size = 0x00;
+        memset(nfc_cb.last_hdr,0,NFC_SAVED_HDR_SIZE);
+        memset(nfc_cb.last_cmd,0,NFC_SAVED_CMD_SIZE);
+#endif
+        if(get_i2c_fragmentation_enabled() == I2C_FRAGMENATATION_ENABLED)
+        {
+            nfc_cb.i2c_data_t.nci_cmd_channel_busy = 0;
+            NFC_TRACE_DEBUG1("%s,updating window" , __FUNCTION__);
+            p_cb_stored = nfc_find_conn_cb_by_conn_id(nfc_cb.i2c_data_t.conn_id);
+            nfc_ncif_update_window ();
+            if(p_cb_stored &&
+                    (nfc_cb.i2c_data_t.data_stored == 1)  &&
+                    (nfc_cb.i2c_data_t.nci_cmd_channel_busy == 0x00) )
+            {
+                NFC_TRACE_ERROR0 ("resending the stored data  packet");
+                nfc_ncif_send_data (p_cb_stored, NULL);
+                nfc_cb.i2c_data_t.data_stored = 0;
+            }
+        }
+        else
+        {
+            nfc_ncif_update_window ();
+        }
         break;
-
     case NCI_MT_NTF:
         NFC_TRACE_DEBUG1 ("NFC received ntf gid:%d", gid);
         switch (gid)
@@ -595,6 +955,10 @@
                 p_cb->num_buff = p_cb->init_credits;
             }
 #endif
+            nfc_stop_timer (&nfc_cb.nci_wait_data_ntf_timer);
+            if(get_i2c_fragmentation_enabled() == I2C_FRAGMENATATION_ENABLED){
+                 nfc_ncif_update_data_queue();
+            }
             /* check if there's nay data in tx q to be sent */
             nfc_ncif_send_data (p_cb, NULL);
         }
@@ -747,6 +1111,34 @@
     }
 }
 
+#if (NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfc_ncif_proc_rf_wtx_ntf
+**
+** Description      This function is called to process rf wtx notification
+**
+** Returns          void
+**
+*******************************************************************************/
+void nfc_ncif_proc_rf_wtx_ntf (UINT8 *p, UINT16 plen)
+{
+    tNFC_CONN_CB *p_cb = NULL;
+    (void)p;
+    p_cb = nfc_find_conn_cb_by_conn_id (NFC_RF_CONN_ID);
+
+    if(NULL != p_cb)
+    {
+        if ((p_cb->conn_id == NFC_RF_CONN_ID)
+        &&(p_cb->p_cback)  )
+        {
+            /* Indicate upper layer that local device started receiving rf wtx */
+            (*p_cb->p_cback) (p_cb->conn_id, NFC_RF_WTX_CEVT, NULL);
+        }
+    }
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         nfc_ncif_proc_activate
@@ -786,6 +1178,12 @@
     if (evt_data.activate.protocol == NCI_PROTOCOL_18092_ACTIVE)
         evt_data.activate.protocol = NCI_PROTOCOL_NFC_DEP;
 
+#if (NXP_EXTNS == TRUE)
+    if ((evt_data.activate.protocol == NCI_PROTOCOL_UNKNOWN) &&
+        (p_intf->type == NCI_INTERFACE_FRAME))
+            evt_data.activate.protocol = NCI_PROTOCOL_T3BT;
+#endif
+
     evt_data.activate.rf_tech_param.mode    = *p++;
     buff_size                               = *p++;
     num_buff                                = *p++;
@@ -798,6 +1196,15 @@
     mode         = evt_data.activate.rf_tech_param.mode;
     len_act      = *p++;
     NFC_TRACE_DEBUG3 ("nfc_ncif_proc_activate:%d %d, mode:0x%02x", len, len_act, mode);
+
+#if (NXP_EXTNS == TRUE)
+    if( (evt_data.activate.protocol == NCI_PROTOCOL_NFC_DEP )&&(mode == NCI_DISCOVERY_TYPE_LISTEN_F) )
+    {
+        sListenActivated = TRUE;
+        nfc_start_timer (&nfc_cb.listen_activation_timer_list, (UINT16)(NFC_TTYPE_LISTEN_ACTIVATION),  2);
+    }
+#endif
+
     /* just in case the interface reports activation parameters not defined in the NCI spec */
     p_intf->intf_param.frame.param_len      = len_act;
     if (p_intf->intf_param.frame.param_len > NFC_MAX_RAW_PARAMS)
@@ -898,7 +1305,7 @@
 
     }
 #if (NFC_RW_ONLY == FALSE)
-    else if (evt_data.activate.intf_param.type == NCI_INTERFACE_NFC_DEP)
+    else if(evt_data.activate.intf_param.type == NCI_INTERFACE_NFC_DEP)
     {
         /* Make max payload of NCI aligned to max payload of NFC-DEP for better performance */
         if (buff_size > NCI_NFC_DEP_MAX_DATA)
@@ -958,8 +1365,23 @@
             p_pa->hr[1]     = *p++;
         }
     }
+#if(NXP_EXTNS == TRUE)
+    /*
+     * Code to handle the Reader over SWP.
+     * 1. Do not activate tag for this NTF.
+     * 2. Pass this info to JNI as START_READER_EVT.
+     */
+    else if (evt_data.activate.intf_param.type == NCI_INTERFACE_UICC_DIRECT || evt_data.activate.intf_param.type == NCI_INTERFACE_ESE_DIRECT)
+    {
+        NFC_TRACE_DEBUG1("nfc_ncif_proc_activate:interface type  %x", evt_data.activate.intf_param.type);
+    }
+#endif
 
     p_cb->act_protocol  = evt_data.activate.protocol;
+#if(NXP_EXTNS == TRUE)
+    p_cb->act_interface = evt_data.activate.intf_param.type;
+    p_cb->sel_res = evt_data.activate.rf_tech_param.param.pa.sel_rsp;
+#endif
     p_cb->buff_size     = buff_size;
     p_cb->num_buff      = num_buff;
     p_cb->init_credits  = num_buff;
@@ -1006,6 +1428,15 @@
     if (p_cb->p_cback)
         (*p_cb->p_cback) (NFC_RF_CONN_ID, NFC_DEACTIVATE_CEVT, (tNFC_CONN *) p_deact);
 
+#if (NXP_EXTNS == TRUE)
+    if((nfc_cb.flags & (NFC_FL_DISCOVER_PENDING | NFC_FL_CONTROL_REQUESTED))
+       && (deact_type == NFC_DEACTIVATE_TYPE_DISCOVERY) && (is_ntf == TRUE))
+    {
+        NFC_TRACE_DEBUG0 ("Abnormal State, Deactivate NTF is ignored, MW is already going to Discovery state");
+        return;
+    }
+#endif
+
     if (nfc_cb.p_discv_cback)
     {
         (*nfc_cb.p_discv_cback) (NFC_DEACTIVATE_DEVT, &evt_data);
@@ -1153,6 +1584,7 @@
     UINT8       more, num_entries, xx, yy, *pn, tl;
     tNFC_STATUS status = NFC_STATUS_CONTINUE;
 
+#if(NXP_EXTNS == FALSE)
     if (nfc_cb.p_resp_cback)
     {
         more        = *p++;
@@ -1177,6 +1609,22 @@
             (*nfc_cb.p_resp_cback) (NFC_GET_ROUTING_REVT, (tNFC_RESPONSE *) &evt_data);
         }
     }
+#endif
+#if(NXP_EXTNS == TRUE)
+    if (nfc_cb.p_resp_cback)
+    {
+        more        = *p;
+        if(more == FALSE)
+        {
+            status = NFC_STATUS_OK;
+        }
+        evt_data.status         = (tNFC_STATUS) status;
+        evt_data.num_tlvs       = *(p+1);
+        evt_data.tlv_size       = len;
+        memcpy(evt_data.param_tlvs,p,len);
+        (*nfc_cb.p_resp_cback) (NFC_GET_ROUTING_REVT, (tNFC_RESPONSE *) &evt_data);
+    }
+#endif
 }
 #endif
 
@@ -1216,6 +1664,12 @@
         if (status == NCI_STATUS_OK)
         {
             nfc_set_conn_id (p_cb, conn_id);
+#if(NXP_EXTNS == TRUE)
+                if(p_cb->id == 1)
+                {
+                    nfcc_dh_conn_id = conn_id;
+                }
+#endif
         }
         else
         {
@@ -1269,6 +1723,35 @@
 
     if (is_ntf)
     {
+#if(NXP_EXTNS == TRUE)
+        NFC_TRACE_ERROR1 ("reset notification nfc_state :0x%x ", nfc_cb.nfc_state);
+        NFC_TRACE_ERROR1 ("reset notification!!:0x%x ", status);
+        core_reset_init_num_buff = TRUE;
+        nfc_ncif_cmd_timeout();
+    }
+    else
+    {
+        NFC_TRACE_ERROR0 ("reset notification nfc_state : #### 1");
+
+        if (nfc_cb.flags & (NFC_FL_RESTARTING|NFC_FL_POWER_CYCLE_NFCC))
+        {
+            nfc_reset_all_conn_cbs ();
+        }
+
+        /*Check NCI version only in case of reset rsp*/
+        if (!is_ntf && status == NCI_STATUS_OK)
+        {
+            if ((*p) != NCI_VERSION)
+            {
+                NFC_TRACE_ERROR2 ("NCI version mismatch!!:0x%02x != 0x%02x ", NCI_VERSION, *p);
+                if ((*p) < NCI_VERSION_0_F)
+                {
+                    NFC_TRACE_ERROR0 ("NFCC version is too old");
+                    status = NCI_STATUS_FAILED;
+                }
+            }
+        }
+#else
         NFC_TRACE_ERROR1 ("reset notification!!:0x%x ", status);
         /* clean up, if the state is OPEN
          * FW does not report reset ntf right now */
@@ -1299,15 +1782,22 @@
         }
     }
 
-    if (status == NCI_STATUS_OK)
-    {
-        nci_snd_core_init ();
+#endif
+        if ( status == NCI_STATUS_OK)
+        {
+#if(NXP_EXTNS == TRUE)
+            NFC_TRACE_ERROR0 ("reset notification sending core init");
+#endif
+            nci_snd_core_init ();
+        }
+        else
+        {
+            NFC_TRACE_ERROR0 ("Failed to reset NFCC");
+            nfc_enabled (status, NULL);
+        }
+#if(NXP_EXTNS == TRUE)
     }
-    else
-    {
-        NFC_TRACE_ERROR0 ("Failed to reset NFCC");
-        nfc_enabled (status, NULL);
-    }
+#endif
 }
 
 /*******************************************************************************
@@ -1323,28 +1813,102 @@
 {
     UINT8 *p, status;
     tNFC_CONN_CB * p_cb = &nfc_cb.conn_cb[NFC_RF_CONN_ID];
+#if (NXP_EXTNS == TRUE)
+    static UINT8 retry_cnt = 0;
+    UINT8 fw_status;
+#endif
 
     p = (UINT8 *) (p_msg + 1) + p_msg->offset;
 
     /* handle init params in nfc_enabled */
     status   = *(p + NCI_MSG_HDR_SIZE);
-    if (status == NCI_STATUS_OK)
+#if(NXP_EXTNS == TRUE)
+    fw_status = nfc_ncif_store_FWVersion(p);
+#endif
+
+    if (status == NCI_STATUS_OK
+#if(NXP_EXTNS == TRUE)
+        &&
+        fw_status == NCI_STATUS_OK
+#endif
+       )
     {
         p_cb->id            = NFC_RF_CONN_ID;
         p_cb->act_protocol  = NCI_PROTOCOL_UNKNOWN;
-
+#if(NXP_EXTNS == TRUE)
+        retry_cnt = 0;
+#endif
         nfc_set_state (NFC_STATE_W4_POST_INIT_CPLT);
 
         nfc_cb.p_nci_init_rsp = p_msg;
         nfc_cb.p_hal->core_initialized (p);
     }
+#if(NXP_EXTNS == TRUE)
+    /*Recovery is added in case of corrupted init rsp is received
+     * eg: 400119 - only 3 bytes are received. In this case since the
+     * rsp buffer[3] is status and the value is 0x00 because of memset for the rsp buffer
+     * was done before copying the init response.
+     * Hence FW version check is added to do check the proper status and go for a recovery*/
+    else if(retry_cnt++ < NFC_NFCC_INIT_MAX_RETRY &&
+            fw_status != NCI_STATUS_OK)
+    {
+        GKI_send_event (NFC_TASK, NFC_TASK_EVT_TRANSPORT_READY);
+        GKI_freebuf (p_msg);
+    }
+#endif
     else
     {
+#if(NXP_EXTNS == TRUE)
+        status = NCI_STATUS_FAILED;
+        retry_cnt = 0;
+#endif
         nfc_enabled (status, NULL);
         GKI_freebuf (p_msg);
     }
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfc_ncif_store_FWVersion
+**
+** Description      This function is called to fill the structure with FW Version
+**
+** Returns          tNFC_STATUS
+**
+*******************************************************************************/
+tNFC_STATUS nfc_ncif_store_FWVersion(UINT8 * p_buf)
+{
+    UINT8 status = NFC_STATUS_OK;
+    int len = p_buf[2] + 2; /*include 2 byte header*/
+    memset (&nfc_fw_version, 0, sizeof(nfc_fw_version));
+    nfc_fw_version.rom_code_version = p_buf[len-2];
+    nfc_fw_version.major_version = p_buf[len-1];
+    nfc_fw_version.minor_version = p_buf[len];
+    if(nfc_fw_version.rom_code_version == 0 ||
+       nfc_fw_version.major_version == 0)
+    {
+        status = NFC_STATUS_FAILED;
+    }
+    NFC_TRACE_DEBUG3("FW Version: %x.%x.%x", nfc_fw_version.rom_code_version,
+                      nfc_fw_version.major_version,nfc_fw_version.minor_version);
+    return status;
+}
+
+/*******************************************************************************
+**
+** Function         nfc_ncif_getFWVersion
+**
+** Description      This function is called to fet the FW Version
+**
+** Returns          tNFC_FW_VERSION
+**
+*******************************************************************************/
+tNFC_FW_VERSION nfc_ncif_getFWVersion()
+{
+  return nfc_fw_version;
+}
+#endif
 /*******************************************************************************
 **
 ** Function         nfc_ncif_proc_get_config_rsp
@@ -1449,9 +2013,17 @@
                  */
                 if ((p_cb->act_protocol >= NCI_PROTOCOL_T1T) && (p_cb->act_protocol <= NCI_PROTOCOL_T3T))
                 {
-                    p_evt->len--;
-                    p                = (UINT8 *) (p_evt + 1);
-                    data_cevt.status = *(p + p_evt->offset + p_evt->len);
+#if(NXP_EXTNS == TRUE)
+                    if( (p_cb->act_protocol == NCI_PROTOCOL_T2T) && ( p_cb->act_interface == NCI_INTERFACE_FIRST_VS) && ( p_cb->sel_res == 0x01) )
+                    {
+                        NFC_TRACE_ERROR0 ("Skylander tag detected dont handle this");
+                    }else
+#endif
+                    {
+                        p_evt->len--;
+                        p                = (UINT8 *) (p_evt + 1);
+                        data_cevt.status = *(p + p_evt->offset + p_evt->len);
+                    }
                 }
             }
             (*p_cb->p_cback) (p_cb->conn_id, NFC_DATA_CEVT, (tNFC_CONN *) &data_cevt);
@@ -1492,7 +2064,13 @@
 
         p_msg->layer_specific       = 0;
         if (pbf)
+        {
+#if(NXP_EXTNS == TRUE)
+            NFC_TRACE_DEBUG0 ("nfc_ncif_proc_data requesting reassembly for chained data");
+            nfc_cb.reassembly = TRUE;
+#endif
             p_msg->layer_specific   = NFC_RAS_FRAGMENTED;
+        }
         p_last = (BT_HDR *)GKI_getlast (&p_cb->rx_q);
         if (p_last && (p_last->layer_specific & NFC_RAS_FRAGMENTED))
         {
@@ -1577,5 +2155,150 @@
     }
     GKI_freebuf (p_msg);
 }
+/*******************************************************************************
+**
+** Function         nfc_ncif_credit_ntf_timeout
+**
+** Description      Handle a credit ntf  timeout
+**
+** Returns          void
+**
+*******************************************************************************/
+void nfc_ncif_credit_ntf_timeout()
+{
+    NFC_TRACE_DEBUG0 ("nfc_ncif_credit_ntf_timeout : Enter");
+    if( get_i2c_fragmentation_enabled () == I2C_FRAGMENATATION_ENABLED)
+        {
+            nfc_cb.i2c_data_t.data_ntf_timeout = 1;
+        }
+        else
+        {
+            nfa_sys_stop_timer (&nfa_hci_cb.timer);
+            nfa_hci_rsp_timeout (NULL);
+        }
+
+    if( get_i2c_fragmentation_enabled () == I2C_FRAGMENATATION_ENABLED)
+    {
+        //nfc_cb.nfc_state = NFC_STATE_RECOVERY;
+        NFC_TRACE_DEBUG0 ("nfc_ncif_credit_ntf_timeout :decrementing window");
+        //TODO: Write logic for VEN_RESET.
+        nfc_cb.p_hal->power_cycle();
+        //Remove the pending cmds from the cmd queue. send any pending rsp/cback to jni
+        nfc_ncif_empty_cmd_queue();
+        //Cancel any ongoing data transfer.
+        /**
+         * send core reset - keep config
+         * send core init
+         * send discovery
+         * */
+
+        //Update the cmd window, since rsp has not came.
+        //nfc_ncif_update_window ();
+        nfc_ncif_empty_data_queue ();
+        if(nfc_cb.i2c_data_t.data_ntf_timeout)
+        {
+            nfc_cb.i2c_data_t.data_ntf_timeout = 0;
+        }
+    }
+    NFC_TRACE_ERROR0 ("cmd timeout sending core reset!!!");
+    nfc_ncif_cmd_timeout();
+    //nci_snd_core_reset(0x00);
+}
+#if(NFC_NXP_ESE == TRUE && NFC_NXP_CHIP_TYPE == PN548C2)
+void disc_deact_ntf_timeout_handler(tNFC_RESPONSE_EVT event)
+{
+    tNFC_RESPONSE   evt_data;
+    etsi_reader_in_progress = FALSE;
+    if (nfc_cb.p_resp_cback)
+    {
+        evt_data.status = (tNFC_STATUS) NFC_STATUS_HW_TIMEOUT;
+        (*nfc_cb.p_resp_cback) (event, &evt_data);
+    }
+}
+#endif
+
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         nfc_ncif_process_proprietary_rsp
+**
+** Description      Process the response to avoid collision
+**                  while nxpCbflag is set
+**
+** Returns          TRUE if proprietary response else FALSE
+**
+*******************************************************************************/
+
+BOOLEAN nfc_ncif_proc_proprietary_rsp (UINT8 mt, UINT8 gid, UINT8 oid)
+{
+    BOOLEAN stat = FALSE;
+    switch(mt)
+    {
+    case NCI_MT_DATA:
+        switch (gid)
+        {
+        case 0x03:
+            switch (oid)
+            {
+            case 0x00:      /*Data Response*/
+                stat = FALSE;
+                break;
+
+            default:
+                stat = TRUE;
+                break;
+            }
+            break;
+
+        default:
+            stat = TRUE;
+            break;
+        }
+        break;
+
+    case NCI_MT_NTF:
+        switch (gid)
+        {
+        case NCI_GID_CORE:
+            switch (oid)
+            {
+            case 0x06:      /*CORE_CONN_CREDITS_NTF*/
+                stat = FALSE;
+                break;
+            default:
+                stat = TRUE;
+                break;
+            }
+            break;
+        case NCI_GID_RF_MANAGE:
+            switch (oid)
+            {
+            case 0x06:      /*CORE_CONN_CREDITS_NTF*/
+                stat = FALSE;
+                break;
+            case 0x07:      /*RF FIELD INFO EVENT*/
+                stat = FALSE;
+                break;
+            case 0x09:      /*NFA_EE_ACTION_NTF*/
+                stat = FALSE;
+                break;
+            default:
+                stat = TRUE;
+                break;
+            }
+        default:
+            stat = TRUE;
+            break;
+        }
+        break;
+
+    default:
+        stat = TRUE;
+        break;
+
+    }
+    return stat;
+}
+#endif
 
 #endif /* NFC_INCLUDED == TRUE*/
diff --git a/src/nfc/nfc/nfc_task.c b/src/nfc/nfc/nfc_task.c
index 9d9b74a..d91e58a 100644
--- a/src/nfc/nfc/nfc_task.c
+++ b/src/nfc/nfc/nfc_task.c
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -131,6 +150,27 @@
         case NFC_TTYPE_WAIT_2_DEACTIVATE:
             nfc_wait_2_deactivate_timeout ();
             break;
+        case NFC_TTYPE_NCI_WAIT_DATA_NTF:
+        {
+#if(NXP_EXTNS == TRUE)
+            if( get_i2c_fragmentation_enabled () == I2C_FRAGMENATATION_ENABLED)
+            {
+                nfc_cb.i2c_data_t.nci_cmd_channel_busy = 0;
+                nfc_cb.i2c_data_t.data_stored = 0;
+            }
+            nfc_ncif_credit_ntf_timeout();
+#endif
+            break;
+        }
+#if(NXP_EXTNS == TRUE)
+        case NFC_TTYPE_LISTEN_ACTIVATION:
+            {
+                extern uint8_t sListenActivated;
+                sListenActivated = FALSE;
+                nfc_ncif_cmd_timeout();
+            }
+            break;
+#endif
 
         default:
             NFC_TRACE_DEBUG2 ("nfc_process_timer_evt: timer:0x%x event (0x%04x)", p_tle, p_tle->event);
@@ -278,6 +318,14 @@
         case NFC_TTYPE_RW_I93_RESPONSE:
             rw_i93_process_timeout (p_tle);
             break;
+#if(NXP_EXTNS == TRUE)
+        case NFC_TTYPE_P2P_PRIO_RESPONSE:
+            nfa_dm_p2p_timer_event ();
+            break;
+        case NFC_TTYPE_P2P_PRIO_LOGIC_CLEANUP:
+            nfa_dm_p2p_prio_logic_cleanup();
+            break;
+#endif
 #if (NFC_RW_ONLY == FALSE)
         case NFC_TTYPE_CE_T4T_UPDATE:
             ce_t4t_process_timeout (p_tle);
diff --git a/src/nfc/nfc/nfc_vs.c b/src/nfc/nfc/nfc_vs.c
index 9d745ec..7405854 100644
--- a/src/nfc/nfc/nfc_vs.c
+++ b/src/nfc/nfc/nfc_vs.c
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -140,8 +159,44 @@
     nfc_ncif_check_cmd_queue (p_data);
     return status;
 }
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         NFC_SendNxpNciCommand
+**
+** Description      This function is called to send the given nxp specific
+**                  command to NFCC. The response from NFCC is reported to the
+**                  given tNFC_VS_CBACK.
+**
+** Parameters       p_data - The command buffer
+**
+** Returns          tNFC_STATUS
+**
+*******************************************************************************/
+tNFC_STATUS NFC_SendNxpNciCommand (BT_HDR        *p_data,
+                               tNFC_VS_CBACK *p_cback)
+{
+    tNFC_STATUS     status = NFC_STATUS_OK;
+    UINT8           *pp;
 
+    /* Validate parameters */
+    if ((p_data == NULL) || (p_data->len > NCI_MAX_VSC_SIZE))
+    {
+        NFC_TRACE_ERROR1 ("buffer offset must be >= %d", NCI_VSC_MSG_HDR_SIZE);
+        if (p_data)
+            GKI_freebuf (p_data);
+        return NFC_STATUS_INVALID_PARAM;
+    }
 
+    p_data->event           = BT_EVT_TO_NFC_NCI;
+    p_data->layer_specific  = NFC_WAIT_RSP_NXP;
+    /* save the callback function in the BT_HDR, to receive the response */
+    ((tNFC_NCI_VS_MSG *) p_data)->p_cback = p_cback;
+    pp              = (UINT8 *) (p_data + 1) + p_data->offset;
 
+    nfc_ncif_check_cmd_queue (p_data);
+    return status;
+}
+#endif
 
 #endif /* NFC_INCLUDED == TRUE */
diff --git a/src/nfc/tags/rw_i93.c b/src/nfc/tags/rw_i93.c
index d77b231..7741aa6 100644
--- a/src/nfc/tags/rw_i93.c
+++ b/src/nfc/tags/rw_i93.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -35,7 +53,9 @@
 #include "rw_api.h"
 #include "rw_int.h"
 
-#define RW_I93_TOUT_RESP                        1000    /* Response timeout     */
+#if(NXP_EXTNS == TRUE)
+#define RW_I93_TOUT_RESP                        RW_I93_MAX_RSP_TIMEOUT    /* Response timeout     */
+#endif
 #define RW_I93_TOUT_STAY_QUIET                  200     /* stay quiet timeout   */
 #define RW_I93_READ_MULTI_BLOCK_SIZE            128     /* max reading data if read multi block is supported */
 #define RW_I93_FORMAT_DATA_LEN                  8       /* CC, zero length NDEF, Terminator TLV              */
@@ -1944,14 +1964,30 @@
 *******************************************************************************/
 void rw_i93_sm_read_ndef (BT_HDR *p_resp)
 {
+#if(NXP_EXTNS == TRUE)
+    UINT8      *p;
+    UINT16      offset = 0, length = 0;
+#else
     UINT8      *p = (UINT8 *) (p_resp + 1) + p_resp->offset;
-    UINT8       flags;
     UINT16      offset, length = p_resp->len;
+#endif
+
+    UINT8       flags;
+
     tRW_I93_CB *p_i93 = &rw_cb.tcb.i93;
     tRW_DATA    rw_data;
 
     RW_TRACE_DEBUG0 ("rw_i93_sm_read_ndef ()");
 
+    if(NULL == p_resp)
+    {
+        RW_TRACE_DEBUG0 ("rw_i93_sm_read_ndef: p_resp is NULL");
+        return;
+    }
+#if(NXP_EXTNS == TRUE)
+    p = (UINT8 *) (p_resp + 1) + p_resp->offset;
+    length = p_resp->len;
+#endif
     STREAM_TO_UINT8 (flags, p);
     length--;
 
@@ -3080,6 +3116,15 @@
         }
         else
         {
+#if(NXP_EXTNS == TRUE)
+            /* free retry buffer */
+            if ((event == NFC_DEACTIVATE_CEVT )&& p_i93->p_retry_cmd)
+            {
+                GKI_freebuf (p_i93->p_retry_cmd);
+                p_i93->p_retry_cmd = NULL;
+                p_i93->retry_count = 0;
+            }
+#endif
             NFC_SetStaticRfCback (NULL);
             p_i93->state = RW_I93_STATE_NOT_ACTIVATED;
         }
diff --git a/src/nfc/tags/rw_main.c b/src/nfc/tags/rw_main.c
index c11f592..a593e01 100644
--- a/src/nfc/tags/rw_main.c
+++ b/src/nfc/tags/rw_main.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -256,6 +274,9 @@
         break;
 
     case NFC_PROTOCOL_ISO_DEP:     /* ISODEP/4A,4B- NFC-A or NFC-B */
+#if(NXP_EXTNS == TRUE)
+    case NFC_PROTOCOL_T3BT:
+#endif
         if (  (p_activate_params->rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_B)
             ||(p_activate_params->rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_A)  )
         {
diff --git a/src/nfc/tags/rw_t1t.c b/src/nfc/tags/rw_t1t.c
index e7d373e..710b73e 100644
--- a/src/nfc/tags/rw_t1t.c
+++ b/src/nfc/tags/rw_t1t.c
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -34,6 +53,9 @@
 #include "nfc_int.h"
 #include "gki.h"
 
+#if(NXP_EXTNS == TRUE)
+extern unsigned char appl_dta_mode_flag;
+#endif
 /* Local Functions */
 static tRW_EVENT rw_t1t_handle_rid_rsp (BT_HDR *p_pkt);
 static void rw_t1t_data_cback (UINT8 conn_id, tNFC_CONN_EVT event, tNFC_CONN *p_data);
@@ -295,6 +317,14 @@
         {
             rw_t1t_process_error ();
         }
+#if(NXP_EXTNS == TRUE)
+        if((p_data != NULL) && (p_data->data.p_data != NULL))
+        {
+            /* Free the response buffer in case of invalid response*/
+            GKI_freebuf((BT_HDR *) (p_data->data.p_data));
+            p_data->data.p_data = NULL;
+        }
+#endif
         break;
 
     default:
@@ -473,6 +503,10 @@
 
     /* Fetch UID0-3 from RID response message */
     STREAM_TO_ARRAY (p_t1t->mem,  p_rid_rsp, T1T_CMD_UID_LEN);
+#if(NXP_EXTNS == TRUE)
+    /* Free the RID response buffer */
+    GKI_freebuf (p_pkt);
+#endif
 
     /* Notify RID response Event */
     return RW_T1T_RID_EVT;
@@ -686,7 +720,11 @@
 
     p_t1t->state    = RW_T1T_STATE_IDLE;
 #if (defined (RW_NDEF_INCLUDED) && (RW_NDEF_INCLUDED == TRUE))
+#if(NXP_EXTNS == TRUE)
+    if ((appl_dta_mode_flag == 0) && (p_t1t->state != RW_T1T_STATE_READ_NDEF))
+#else
     if (p_t1t->state != RW_T1T_STATE_READ_NDEF)
+#endif
     {
         p_t1t->b_update = FALSE;
         p_t1t->b_rseg   = FALSE;
diff --git a/src/nfc/tags/rw_t1t_ndef.c b/src/nfc/tags/rw_t1t_ndef.c
index 29aff77..d278b2d 100644
--- a/src/nfc/tags/rw_t1t_ndef.c
+++ b/src/nfc/tags/rw_t1t_ndef.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -159,7 +177,7 @@
         break;
 
     default:
-	    rw_event = t1t_info_to_evt (p_info);
+        rw_event = t1t_info_to_evt (p_info);
         break;
     }
     return rw_event;
@@ -2200,7 +2218,11 @@
                     {
                         /* Set/clear lock_attr byte bits based on whether a particular lock bit is set or not
                          * each bit in lock_attr represents one byte in Tag read only attribute */
+#if(NXP_EXTNS == TRUE)
+                        if ((p_t1t->lockbyte[num_dynamic_lock_bytes].lock_byte & rw_t1t_mask_bits[xx]) && (block_count < T1T_BLOCKS_PER_SEGMENT))
+#else
                         if (p_t1t->lockbyte[num_dynamic_lock_bytes].lock_byte & rw_t1t_mask_bits[xx])
+#endif
                         {
                             p_t1t->lock_attr[block_count] |= 0x01 << bits_covered;
                         }
diff --git a/src/nfc/tags/rw_t2t.c b/src/nfc/tags/rw_t2t.c
index de2de64..ddf5b9a 100644
--- a/src/nfc/tags/rw_t2t.c
+++ b/src/nfc/tags/rw_t2t.c
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -191,6 +210,15 @@
             {
                 p_t2t->b_read_hdr = TRUE;
                 memcpy (p_t2t->tag_hdr,  p, T2T_READ_DATA_LEN);
+#if(NXP_EXTNS == TRUE)
+                /* On Ultralight - C tag, if CC is corrupt, correct it */
+                if (  (p_t2t->tag_hdr[0] == TAG_MIFARE_MID)
+                    &&(p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] >= T2T_INVALID_CC_TMS_VAL0)
+                    &&(p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] <= T2T_INVALID_CC_TMS_VAL1)  )
+                {
+                    p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] = T2T_CC2_TMS_MULC;
+                }
+#endif
             }
             break;
 
@@ -346,6 +374,12 @@
         {
             rw_t2t_process_error ();
         }
+#if(NXP_EXTNS == TRUE)
+        /* Free the response buffer in case of invalid response*/
+        if (p_data != NULL) {
+                GKI_freebuf((BT_HDR *) (p_data->data.p_data));
+        }
+#endif
         break;
 
     default:
diff --git a/src/nfc/tags/rw_t2t_ndef.c b/src/nfc/tags/rw_t2t_ndef.c
index 3304a90..3ed7b3c 100644
--- a/src/nfc/tags/rw_t2t_ndef.c
+++ b/src/nfc/tags/rw_t2t_ndef.c
@@ -15,7 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -88,6 +106,15 @@
     {
         p_t2t->b_read_hdr = TRUE;
         memcpy (p_t2t->tag_hdr,  p_data, T2T_READ_DATA_LEN);
+#if(NXP_EXTNS == TRUE)
+        /* On Ultralight - C tag, if CC is corrupt, correct it */
+        if (  (p_t2t->tag_hdr[0] == TAG_MIFARE_MID)
+            &&(p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] >= T2T_INVALID_CC_TMS_VAL0)
+            &&(p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] <= T2T_INVALID_CC_TMS_VAL1)  )
+        {
+            p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] = T2T_CC2_TMS_MULC;
+        }
+#endif
     }
 
     switch (p_t2t->state)
@@ -207,7 +234,7 @@
         break;
 
     default:
-	    rw_event = t2t_info_to_evt (p_info);
+        rw_event = t2t_info_to_evt (p_info);
         break;
     }
     return rw_event;
@@ -838,6 +865,10 @@
     UINT16      block;
 
     if (  (p_t2t->tag_hdr[T2T_CC3_RWA_BYTE] != T2T_CC3_RWA_RW)
+#if(NXP_EXTNS == TRUE)
+        ||((p_t2t->tag_hdr[0] == TAG_MIFARE_MID) && (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == T2T_CC2_TMS_MULC))
+        ||((p_t2t->tag_hdr[0] == TAG_MIFARE_MID) && (p_t2t->tag_hdr[T2T_CC2_TMS_BYTE] == T2T_CC2_TMS_MUL))
+#endif
         ||(p_t2t->skip_dyn_locks)  )
     {
         /* Skip reading dynamic lock bytes if CC is set as Read only or layer above instructs to skip */
@@ -849,7 +880,11 @@
         }
     }
 
-    while (num_locks < p_t2t->num_lockbytes)
+    while ((num_locks < p_t2t->num_lockbytes)
+#if(NXP_EXTNS == TRUE)
+            && (num_locks < RW_T2T_MAX_LOCK_BYTES)
+#endif
+    )
     {
         if (p_t2t->lockbyte[num_locks].b_lock_read == FALSE)
         {
@@ -2348,7 +2383,11 @@
                 bytes_covered = 0;
                 while (bytes_covered < bytes_locked_per_lock_bit)
                 {
+#if(NXP_EXTNS == TRUE)
+                    if ((p_t2t->lockbyte[num_dyn_lock_bytes].lock_byte & rw_t2t_mask_bits[xx]) && (block_count < RW_T2T_SEGMENT_SIZE))
+#else
                     if (p_t2t->lockbyte[num_dyn_lock_bytes].lock_byte & rw_t2t_mask_bits[xx])
+#endif
                     {
                         /* If the bit is set then it is locked */
                         p_t2t->lock_attr[block_count] |= 0x01 << bits_covered;
diff --git a/src/nfc/tags/rw_t3t.c b/src/nfc/tags/rw_t3t.c
index 7db0fac..5bd44e4 100644
--- a/src/nfc/tags/rw_t3t.c
+++ b/src/nfc/tags/rw_t3t.c
@@ -15,6 +15,25 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 
 /******************************************************************************
@@ -1749,6 +1768,10 @@
             /* Add CHECK opcode to message  */
             UINT8_TO_STREAM (p, T3T_MSG_OPC_CHECK_CMD);
 
+#if(NXP_EXTNS == TRUE)
+            /* Update NFCID2 using SENSF_RES */
+            memcpy (p_cb->peer_nfcid2, (p_sensf_res_buf + NCI_SENSF_RES_OFFSET_NFCID2), NCI_NFCID2_LEN);
+#endif
             /* Add IDm to message */
             ARRAY_TO_STREAM (p, p_cb->peer_nfcid2, NCI_NFCID2_LEN);
 
@@ -2369,6 +2392,15 @@
             rw_t3t_data_cback (conn_id, &(p_data->data));
             break;
         }
+        else
+        {
+            RW_TRACE_DEBUG2 ("rw_t3t_conn_cback: p_data->data.p_data=0x%X p_data->data.status=0x%02x", p_data->data.p_data, p_data->data.status);
+            if(p_data->data.p_data)
+            {
+                GKI_freebuf(p_data->data.p_data);
+                p_data->data.p_data = NULL;
+            }
+        }
         /* Data event with error status...fall through to NFC_ERROR_CEVT case */
 
 
diff --git a/src/nfc/tags/rw_t4t.c b/src/nfc/tags/rw_t4t.c
index 6e2b4ad..df41927 100644
--- a/src/nfc/tags/rw_t4t.c
+++ b/src/nfc/tags/rw_t4t.c
@@ -16,6 +16,25 @@
  *
  ******************************************************************************/
 
+/******************************************************************************
+ *
+ *  The original Work has been changed by NXP Semiconductors.
+ *
+ *  Copyright (C) 2015 NXP Semiconductors
+ *
+ *  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.
+ *
+ ******************************************************************************/
 
 /******************************************************************************
  *
@@ -46,6 +65,10 @@
 #define RW_T4T_STATE_PRESENCE_CHECK             0x05    /* checking presence of tag             */
 #define RW_T4T_STATE_SET_READ_ONLY              0x06    /* convert tag to read only             */
 
+#if(NXP_EXTNS == TRUE)
+#define RW_T4T_STATE_NDEF_FORMAT                0x07    /* performing NDEF format               */
+#define RW_T3BT_STATE_GET_PROP_DATA             0x08
+#endif
 /* sub state */
 #define RW_T4T_SUBSTATE_WAIT_SELECT_APP         0x00    /* waiting for response of selecting AID    */
 #define RW_T4T_SUBSTATE_WAIT_SELECT_CC          0x01    /* waiting for response of selecting CC     */
@@ -57,6 +80,19 @@
 #define RW_T4T_SUBSTATE_WAIT_UPDATE_NLEN        0x07    /* waiting for response of updating NLEN    */
 #define RW_T4T_SUBSTATE_WAIT_UPDATE_CC          0x08    /* waiting for response of updating CC      */
 
+#if(NXP_EXTNS == TRUE)
+#define RW_T4T_SUBSTATE_WAIT_GET_HW_VERSION     0x09
+#define RW_T4T_SUBSTATE_WAIT_GET_SW_VERSION     0x0A
+#define RW_T4T_SUBSTATE_WAIT_GET_UID            0x0B
+#define RW_T4T_SUBSTATE_WAIT_CREATE_APP         0x0C
+#define RW_T4T_SUBSTATE_WAIT_CREATE_CC          0x0D
+#define RW_T4T_SUBSTATE_WAIT_CREATE_NDEF        0x0E
+#define RW_T4T_SUBSTATE_WAIT_WRITE_CC           0x0F
+#define RW_T4T_SUBSTATE_WAIT_WRITE_NDEF         0x10
+#define RW_T3BT_SUBSTATE_WAIT_GET_ATTRIB        0x11
+#define RW_T3BT_SUBSTATE_WAIT_GET_PUPI          0x12
+#endif
+
 #if (BT_TRACE_VERBOSE == TRUE)
 static char *rw_t4t_get_state_name (UINT8 state);
 static char *rw_t4t_get_sub_state_name (UINT8 sub_state);
@@ -70,6 +106,18 @@
 static BOOLEAN rw_t4t_update_cc_to_readonly (void);
 static BOOLEAN rw_t4t_select_application (UINT8 version);
 static BOOLEAN rw_t4t_validate_cc_file (void);
+
+#if(NXP_EXTNS == TRUE)
+static BOOLEAN rw_t4t_get_hw_version (void);
+static BOOLEAN rw_t4t_get_sw_version (void);
+static BOOLEAN rw_t4t_create_app (void);
+static BOOLEAN rw_t4t_select_app (void);
+static BOOLEAN rw_t4t_create_ccfile (void);
+static BOOLEAN rw_t4t_create_ndef (void);
+static BOOLEAN rw_t4t_write_cc (void);
+static BOOLEAN rw_t4t_write_ndef (void);
+static BOOLEAN rw_t3bt_get_pupi (void);
+#endif
 static void rw_t4t_handle_error (tNFC_STATUS status, UINT8 sw1, UINT8 sw2);
 static void rw_t4t_sm_detect_ndef (BT_HDR *p_r_apdu);
 static void rw_t4t_sm_read_ndef (BT_HDR *p_r_apdu);
@@ -77,6 +125,10 @@
 static void rw_t4t_sm_set_readonly (BT_HDR  *p_r_apdu);
 static void rw_t4t_data_cback (UINT8 conn_id, tNFC_CONN_EVT event, tNFC_CONN *p_data);
 
+#if(NXP_EXTNS == TRUE)
+static void rw_t4t_sm_ndef_format (BT_HDR  *p_r_apdu);
+static void rw_t3Bt_sm_get_card_id(BT_HDR *p_r_apdu);
+#endif
 /*******************************************************************************
 **
 ** Function         rw_t4t_send_to_lower
@@ -104,6 +156,534 @@
     return TRUE;
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         rw_t4t_get_hw_version
+**
+** Description      Send get hw version cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_get_hw_version (void)
+{
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_get_hw_version (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_CMD_INS_GET_HW_VERSION);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT8_TO_BE_FIELD(p,0x00);
+
+    p_c_apdu->len = T4T_CMD_MAX_HDR_SIZE;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_get_sw_version
+**
+** Description      Send get sw version cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_get_sw_version (void)
+{
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_get_sw_version (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_ADDI_FRAME_RESP);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT8_TO_BE_FIELD(p,0x00);
+
+    p_c_apdu->len = T4T_CMD_MAX_HDR_SIZE;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_update_version_details
+**
+** Description      Updates the size of the card
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_update_version_details(BT_HDR *p_r_apdu)
+{
+    tRW_T4T_CB      *p_t4t = &rw_cb.tcb.t4t;
+    UINT8 *p;
+    UINT16 major_version, minor_version;
+
+    p = (UINT8 *) (p_r_apdu + 1) + p_r_apdu->offset;
+    major_version = *(p+3);
+    minor_version = *(p+4);
+
+    if((T4T_DESEV0_MAJOR_VERSION == major_version) &&
+            (T4T_DESEV0_MINOR_VERSION == minor_version))
+    {
+            p_t4t->card_size = 0xEDE;
+    }
+    else if(major_version >= T4T_DESEV1_MAJOR_VERSION)
+    {
+            p_t4t->card_type = T4T_TYPE_DESFIRE_EV1;
+        switch (*(p + 5))
+        {
+        case T4T_SIZE_IDENTIFIER_2K:
+            p_t4t->card_size = 2048;
+            break;
+        case T4T_SIZE_IDENTIFIER_4K:
+            p_t4t->card_size = 4096;
+            break;
+        case T4T_SIZE_IDENTIFIER_8K:
+            p_t4t->card_size = 7680;
+            break;
+        default:
+            return FALSE;
+            break;
+        }
+    }
+    else
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_get_uid_details
+**
+** Description      Send get uid cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_get_uid_details (void)
+{
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_get_uid_details (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_ADDI_FRAME_RESP);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT8_TO_BE_FIELD(p,0x00);
+
+    p_c_apdu->len = T4T_CMD_MAX_HDR_SIZE;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_create_app
+**
+** Description      Send create application cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_create_app (void)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+        UINT8        df_name[] = {0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01};
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_create_app (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_CMD_CREATE_AID);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    if(p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)
+    {
+            UINT8_TO_BE_STREAM(p,(T4T_CMD_MAX_HDR_SIZE + sizeof(df_name)+2));
+            UINT24_TO_BE_STREAM(p, T4T_DES_EV1_NFC_APP_ID);
+        UINT16_TO_BE_STREAM(p, 0x0F21);                  /*Key settings and no.of keys */
+        UINT16_TO_BE_STREAM(p, 0x05E1);                  /* ISO file ID */
+        ARRAY_TO_BE_STREAM(p,df_name,sizeof(df_name));   /*DF file name */
+        UINT8_TO_BE_STREAM(p,0x00);                      /* Le */
+        p_c_apdu->len = 20;
+    }
+    else
+    {
+            UINT8_TO_BE_STREAM(p, T4T_CMD_MAX_HDR_SIZE);
+            UINT24_TO_BE_STREAM(p, T4T_DES_EV0_NFC_APP_ID);
+            UINT16_TO_BE_STREAM(p, 0x0F01);                  /*Key settings and no.of keys */
+            UINT8_TO_BE_STREAM(p,0x00);                      /* Le */
+            p_c_apdu->len = 11;
+    }
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_select_app
+**
+** Description      Select application cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_select_app (void)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_select_app (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_CMD_SELECT_APP);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT8_TO_BE_STREAM(p,0x03);                      /* Lc: length of wrapped data */
+    if(p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)
+    {
+        UINT24_TO_BE_STREAM(p, T4T_DES_EV1_NFC_APP_ID);
+    }
+    else
+    {
+            UINT24_TO_BE_STREAM(p, T4T_DES_EV0_NFC_APP_ID);
+    }
+    UINT8_TO_BE_STREAM(p,0x00);                      /* Le */
+
+    p_c_apdu->len = 9;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_create_ccfile
+**
+** Description      create capability container file cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_create_ccfile (void)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_create_ccfile (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_CMD_CREATE_DATAFILE);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    if(p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)
+    {
+        UINT8_TO_BE_STREAM(p,0x09);                    /* Lc: length of wrapped data */
+            UINT8_TO_BE_STREAM(p,0x01);                    /* EV1 CC file id             */
+        UINT16_TO_BE_STREAM(p,0x03E1);                 /* ISO file id                */
+    }
+    else
+    {
+            UINT8_TO_BE_STREAM(p,0x07);               /* Lc: length of wrapped data */
+            UINT8_TO_BE_STREAM(p,0x03);               /* DESFire CC file id         */
+    }
+    UINT8_TO_BE_STREAM(p,0x00);                   /* COMM settings              */
+    UINT16_TO_BE_STREAM(p,0xEEEE);                /* Access rights              */
+    UINT24_TO_BE_STREAM(p,0x0F0000);              /* Set file size              */
+    UINT8_TO_BE_STREAM(p,0x00);                   /* Le                         */
+
+    p_c_apdu->len = (p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)?15:13;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_create_ndef
+**
+** Description      creates an ndef file cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_create_ndef (void)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_create_ndef (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_CMD_CREATE_DATAFILE);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    if(p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)
+    {
+        UINT8_TO_BE_STREAM(p,0x09);                   /* Lc: length of wrapped data */
+            UINT8_TO_BE_STREAM(p,0x02);                   /* DESFEv1 NDEF file id       */
+        UINT16_TO_BE_STREAM(p,0x04E1);                /* ISO file id                */
+    }
+    else
+    {
+            UINT8_TO_BE_STREAM(p,0x07);
+            UINT8_TO_BE_STREAM(p,0x04);                   /* DESF4 NDEF file id        */
+    }
+
+    UINT8_TO_BE_STREAM(p,0x00);                       /* COMM settings              */
+    UINT16_TO_BE_STREAM(p,0xEEEE);                    /* Access rights              */
+    UINT16_TO_STREAM(p,p_t4t->card_size);
+        UINT8_TO_BE_STREAM(p,0x00);                       /* Set card size              */
+    UINT8_TO_BE_STREAM(p,0x00);                       /* Le                         */
+
+    p_c_apdu->len = (p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)?15:13;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_write_cc
+**
+** Description      sends write cc file cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_write_cc (void)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+    UINT8        CCFileBytes[]  = {0x00,0x0f,0x10,0x00,0x3B,0x00,0x34,0x04,0x06,0xE1,0x04,0x04,0x00,0x00,0x00};
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_write_cc (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_WRITE);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT8_TO_BE_STREAM(p,0x16);                    /* Lc: length of wrapped data  */
+    if(p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)
+    {
+            CCFileBytes[2]  = 0x20;
+            CCFileBytes[11] = p_t4t->card_size >> 8;
+            CCFileBytes[12] = (UINT8) p_t4t->card_size;
+        UINT8_TO_BE_STREAM(p, 0x01);               /* CC file id                  */
+    }
+    else
+    {
+            UINT8_TO_BE_STREAM(p, 0x03);
+    }
+    UINT24_TO_BE_STREAM(p, 0x000000);              /* Set the offset              */
+    UINT24_TO_BE_STREAM(p, 0x0F0000);              /* Set available length        */
+    ARRAY_TO_BE_STREAM(p, CCFileBytes, sizeof(CCFileBytes));
+    UINT8_TO_BE_STREAM(p,0x00);                    /* Le                         */
+
+    p_c_apdu->len = 28;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function         rw_t4t_write_ndef
+**
+** Description      sends write ndef file cmd to peer
+**
+** Returns          TRUE if success
+**
+*******************************************************************************/
+static BOOLEAN rw_t4t_write_ndef (void)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t4t_write_ndef (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_CLASS);
+    UINT8_TO_BE_STREAM (p, T4T_CMD_DES_WRITE);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT8_TO_BE_STREAM(p,0x09);                    /* Lc: length of wrapped data  */
+    if(p_t4t->card_type == T4T_TYPE_DESFIRE_EV1)
+    {
+        UINT8_TO_BE_STREAM(p, 0x02);               /* DESFEv1 Ndef file id        */
+    }
+    else
+    {
+            UINT8_TO_BE_STREAM(p, 0x04);
+    }
+    UINT24_TO_BE_STREAM(p, 0x000000);              /* Set the offset              */
+    UINT24_TO_BE_STREAM(p, 0x020000);              /* Set available length        */
+    UINT16_TO_BE_STREAM(p, 0x0000);                /* Ndef file bytes             */
+    UINT8_TO_BE_STREAM(p,0x00);                    /* Le                          */
+
+    p_c_apdu->len = 15;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+    return TRUE;
+}
+#endif
+
+#if(NXP_EXTNS == TRUE)
+static BOOLEAN rw_t3bt_get_pupi (void)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("rw_t3bt_get_pupi (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, 0x00);
+    UINT8_TO_BE_STREAM (p, 0x36);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT8_TO_BE_STREAM(p,0x08);                    /* Lc: length of wrapped data  */
+
+    p_c_apdu->len = 0x05;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+    return TRUE;
+}
+#endif
 /*******************************************************************************
 **
 ** Function         rw_t4t_select_file
@@ -571,6 +1151,16 @@
             event = RW_T4T_SET_TO_RO_EVT;
             break;
 
+#if(NXP_EXTNS == TRUE)
+        case RW_T4T_STATE_NDEF_FORMAT:
+            event = RW_T4T_NDEF_FORMAT_CPLT_EVT;
+            rw_data.status = NFC_STATUS_FAILED;
+            break;
+        case RW_T3BT_STATE_GET_PROP_DATA:
+            event = RW_T3BT_RAW_READ_CPLT_EVT;
+            rw_data.status = NFC_STATUS_FAILED;
+            break;
+#endif
         default:
             event = RW_T4T_MAX_EVT;
             break;
@@ -588,7 +1178,313 @@
         p_t4t->state = RW_T4T_STATE_IDLE;
     }
 }
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         rw_t4t_sm_ndef_format
+**
+** Description      State machine for NDEF format procedure
+**
+** Returns          none
+**
+*******************************************************************************/
+static void rw_t4t_sm_ndef_format(BT_HDR *p_r_apdu)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    UINT8       *p, type, length;
+    UINT16      status_words, nlen;
+    tRW_DATA    rw_data;
 
+#if (BT_TRACE_VERBOSE == TRUE)
+    RW_TRACE_DEBUG2 ("rw_t4t_sm_ndef_format (): sub_state:%s (%d)",
+                      rw_t4t_get_sub_state_name (p_t4t->sub_state), p_t4t->sub_state);
+#else
+    RW_TRACE_DEBUG1 ("rw_t4t_sm_ndef_format (): sub_state=%d", p_t4t->sub_state);
+#endif
+
+    /* get status words */
+    p = (UINT8 *) (p_r_apdu + 1) + p_r_apdu->offset;
+
+    switch (p_t4t->sub_state)
+    {
+    case RW_T4T_SUBSTATE_WAIT_GET_HW_VERSION:
+        p += (p_r_apdu->len - 1);
+        if(*(p) == T4T_ADDI_FRAME_RESP)
+        {
+            if(!rw_t4t_get_sw_version())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_GET_SW_VERSION;
+            }
+        }
+        else
+        {
+            rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_GET_SW_VERSION:
+        p += (p_r_apdu->len - 1);
+        if(*(p) == T4T_ADDI_FRAME_RESP)
+        {
+            if(!rw_t4t_update_version_details(p_r_apdu))
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            if(!rw_t4t_get_uid_details())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_GET_UID;
+        }
+        else
+        {
+            rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_GET_UID:
+        p += (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words != 0x9100)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            if(!rw_t4t_create_app())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_CREATE_APP;
+            }
+
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_CREATE_APP:
+        p += (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words == 0x91DE) /* DUPLICATE_ERROR, file already exist*/
+        {
+            status_words = 0x9100;
+        }
+        if(status_words != 0x9100)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            if(!rw_t4t_select_app())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_SELECT_APP;
+            }
+
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_SELECT_APP:
+        p += (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words != 0x9100)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            if(!rw_t4t_create_ccfile())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_CREATE_CC;
+            }
+
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_CREATE_CC:
+        p += (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words == 0x91DE) /* DUPLICATE_ERROR, file already exist*/
+        {
+            status_words = 0x9100;
+        }
+        if(status_words != 0x9100)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            if(!rw_t4t_create_ndef())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_CREATE_NDEF;
+            }
+
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_CREATE_NDEF:
+        p += (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words == 0x91DE) /* DUPLICATE_ERROR, file already exist*/
+        {
+            status_words = 0x9100;
+        }
+        if(status_words != 0x9100)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            if(!rw_t4t_write_cc())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_WRITE_CC;
+            }
+
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_WRITE_CC:
+        p += (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words != 0x9100)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            if(!rw_t4t_write_ndef())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T4T_SUBSTATE_WAIT_WRITE_NDEF;
+            }
+        }
+        break;
+
+    case RW_T4T_SUBSTATE_WAIT_WRITE_NDEF:
+        p += (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words != 0x9100)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            p_t4t->state       = RW_T4T_STATE_IDLE;
+            if (rw_cb.p_cback)
+            {
+                rw_data.ndef.status   = NFC_STATUS_OK;
+                rw_data.ndef.protocol = NFC_PROTOCOL_ISO_DEP;
+                rw_data.ndef.max_size = p_t4t->card_size;
+                rw_data.ndef.cur_size = 0x00;
+
+                (*(rw_cb.p_cback)) (RW_T4T_NDEF_FORMAT_CPLT_EVT, &rw_data);
+
+                RW_TRACE_DEBUG0 ("rw_t4t_ndef_format (): Sent RW_T4T_NDEF_FORMAT_CPLT_EVT");
+            }
+        }
+        break;
+
+    default:
+        RW_TRACE_ERROR1 ("rw_t4t_sm_ndef_format (): unknown sub_state=%d", p_t4t->sub_state);
+        rw_t4t_handle_error(NFC_STATUS_FAILED,0,0);
+        break;
+    }
+}
+#endif
+
+#if(NXP_EXTNS == TRUE)
+static void rw_t3Bt_sm_get_card_id(BT_HDR *p_r_apdu)
+{
+    tRW_T4T_CB  *p_t4t = &rw_cb.tcb.t4t;
+    UINT8       *p, type, length;
+    UINT16      status_words, nlen;
+    tRW_DATA    rw_data;
+
+#if (BT_TRACE_VERBOSE == TRUE)
+    RW_TRACE_DEBUG2 ("rw_t3Bt_sm_get_id (): sub_state:%s (%d)",
+                      rw_t4t_get_sub_state_name (p_t4t->sub_state), p_t4t->sub_state);
+#else
+    RW_TRACE_DEBUG1 ("rw_t3Bt_sm_get_id (): sub_state=%d", p_t4t->sub_state);
+#endif
+
+    /* get status words */
+    p = (UINT8 *) (p_r_apdu + 1) + p_r_apdu->offset;
+
+    switch (p_t4t->sub_state)
+    {
+    case RW_T3BT_SUBSTATE_WAIT_GET_ATTRIB:
+        if((p_r_apdu->len == 0x00) &&
+           ((*p != 0x00) && (*p++ != 0x00)))
+           {
+               rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+           }
+        else
+        {
+            if(!rw_t3bt_get_pupi())
+            {
+                rw_t4t_handle_error (NFC_STATUS_FAILED, 0, 0);
+            }
+            else
+            {
+                p_t4t->sub_state = RW_T3BT_SUBSTATE_WAIT_GET_PUPI;
+            }
+        }
+        break;
+
+    case RW_T3BT_SUBSTATE_WAIT_GET_PUPI:
+        p += (p_r_apdu->len - 3);
+        BE_STREAM_TO_UINT16 (status_words, p);
+        if(status_words != 0x9000)
+        {
+            rw_t4t_handle_error (NFC_STATUS_CMD_NOT_CMPLTD, *(p-2), *(p-1));
+        }
+        else
+        {
+            UINT8 rsp_len = p_r_apdu->len - 3;
+            p = (UINT8 *) (p_r_apdu + 1) + p_r_apdu->offset; //"p" points to start of response
+            p_t4t->state       = RW_T4T_STATE_IDLE;
+            nfa_rw_update_pupi_id(p, rsp_len);
+            if (rw_cb.p_cback)
+            {
+                (*(rw_cb.p_cback)) (RW_T3BT_RAW_READ_CPLT_EVT, &rw_data);
+            }
+            else
+            {
+                RW_TRACE_ERROR0 ("rw_t3Bt_sm_get_id (): NULL callback");
+            }
+        }
+        break;
+
+    default:
+        RW_TRACE_ERROR1 ("rw_t3Bt_sm_get_id (): unknown sub_state=%d", p_t4t->sub_state);
+        rw_t4t_handle_error(NFC_STATUS_FAILED,0,0);
+        break;
+    }
+}
+#endif
 /*******************************************************************************
 **
 ** Function         rw_t4t_sm_detect_ndef
@@ -1168,6 +2064,30 @@
         return;
 
     case NFC_ERROR_CEVT:
+#if(NXP_EXTNS == TRUE)
+        if (p_t4t->state == RW_T4T_STATE_PRESENCE_CHECK)
+        {
+            p_t4t->state   = RW_T4T_STATE_IDLE;
+            rw_data.status = NFC_STATUS_FAILED;
+            (*(rw_cb.p_cback)) (RW_T4T_PRESENCE_CHECK_EVT, &rw_data);
+        }
+        else if (p_t4t->state == RW_T4T_STATE_NDEF_FORMAT)
+        {
+            p_t4t->state   = RW_T4T_STATE_IDLE;
+            rw_data.status = NFC_STATUS_FAILED;
+            (*(rw_cb.p_cback)) (RW_T4T_NDEF_FORMAT_CPLT_EVT, &rw_data);
+        }
+        else if (p_t4t->state != RW_T4T_STATE_IDLE)
+        {
+            rw_t4t_handle_error (rw_data.status, 0, 0);
+        }
+        else
+        {
+            p_t4t->state   = RW_T4T_STATE_IDLE;
+            rw_data.status = (tNFC_STATUS) (*(UINT8*) p_data);
+            (*(rw_cb.p_cback)) (RW_T4T_INTF_ERROR_EVT, &rw_data);
+        }
+#else
         rw_data.status = (tNFC_STATUS) (*(UINT8*) p_data);
 
         if (p_t4t->state != RW_T4T_STATE_IDLE)
@@ -1178,12 +2098,32 @@
         {
             (*(rw_cb.p_cback)) (RW_T4T_INTF_ERROR_EVT, &rw_data);
         }
+#endif
         return;
 
     case NFC_DATA_CEVT:
         p_r_apdu = (BT_HDR *) p_data->data.p_data;
         break;
 
+#if (NXP_EXTNS == TRUE)
+    case NFC_RF_WTX_CEVT:
+        if(p_t4t->state == RW_T4T_STATE_IDLE)
+        {
+            /* WTX received for raw frame sent
+             * forward to upper layer without parsing */
+            if (rw_cb.p_cback)
+            {
+                (*(rw_cb.p_cback)) (RW_T4T_RAW_FRAME_RF_WTX_EVT, &rw_data);
+            }
+        }
+        else
+        {
+            nfc_start_quick_timer (&p_t4t->timer, NFC_TTYPE_RW_T4T_RESPONSE,
+                                  (RW_T4T_TOUT_RESP * QUICK_TIMER_TICKS_PER_SEC) / 1000);
+        }
+        return;
+#endif
+
     default:
         return;
     }
@@ -1245,6 +2185,16 @@
         rw_t4t_sm_set_readonly (p_r_apdu);
         GKI_freebuf (p_r_apdu);
         break;
+#if(NXP_EXTNS == TRUE)
+    case RW_T4T_STATE_NDEF_FORMAT:
+        rw_t4t_sm_ndef_format(p_r_apdu);
+        GKI_freebuf (p_r_apdu);
+        break;
+    case RW_T3BT_STATE_GET_PROP_DATA:
+        rw_t3Bt_sm_get_card_id(p_r_apdu);
+        GKI_freebuf (p_r_apdu);
+        break;
+#endif
     default:
         RW_TRACE_ERROR1 ("rw_t4t_data_cback (): invalid state=%d", p_t4t->state);
         GKI_freebuf (p_r_apdu);
@@ -1261,7 +2211,38 @@
 #endif
 }
 
+#if(NXP_EXTNS == TRUE)
+/*******************************************************************************
+**
+** Function         RW_T4tFormatNDef
+**
+** Description      format T4T tag
+**
+** Returns          NFC_STATUS_OK if success
+**
+*******************************************************************************/
+tNFC_STATUS RW_T4tFormatNDef(void)
+{
+    RW_TRACE_API0 ("RW_T4tFormatNDef ()");
 
+    if (rw_cb.tcb.t4t.state != RW_T4T_STATE_IDLE)
+    {
+        RW_TRACE_ERROR1 ("RW_T4tFormatNDef ():Unable to start command at state (0x%X)",
+                          rw_cb.tcb.t4t.state);
+        return NFC_STATUS_FAILED;
+    }
+
+        rw_cb.tcb.t4t.card_type = 0x00;
+    if(!rw_t4t_get_hw_version())
+    {
+        return NFC_STATUS_FAILED;
+    }
+    rw_cb.tcb.t4t.state = RW_T4T_STATE_NDEF_FORMAT;
+    rw_cb.tcb.t4t.sub_state = RW_T4T_SUBSTATE_WAIT_GET_HW_VERSION;
+
+    return NFC_STATUS_OK;
+}
+#endif
 /*******************************************************************************
 **
 ** Function         rw_t4t_select
@@ -1595,6 +2576,42 @@
     return (retval);
 }
 
+#if(NXP_EXTNS == TRUE)
+tNFC_STATUS RW_T3BtGetPupiID(void)
+{
+    BT_HDR      *p_c_apdu;
+    UINT8       *p;
+
+    p_c_apdu = (BT_HDR *) GKI_getpoolbuf (NFC_RW_POOL_ID);
+
+    if (!p_c_apdu)
+    {
+        RW_TRACE_ERROR0 ("RW_T3BtGetPupiID (): Cannot allocate buffer");
+        return FALSE;
+    }
+
+    p_c_apdu->offset = NCI_MSG_OFFSET_SIZE + NCI_DATA_HDR_SIZE;
+    p = (UINT8 *) (p_c_apdu + 1) + p_c_apdu->offset;
+
+    UINT8_TO_BE_STREAM (p, 0x1D);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT16_TO_BE_STREAM (p, 0x0000);
+    UINT16_TO_BE_STREAM(p,0x0008);
+    UINT16_TO_BE_STREAM (p, 0x0100);
+
+    p_c_apdu->len = 0x09;
+
+    if (!rw_t4t_send_to_lower (p_c_apdu))
+    {
+        return FALSE;
+    }
+
+    rw_cb.tcb.t4t.state = RW_T3BT_STATE_GET_PROP_DATA;
+    rw_cb.tcb.t4t.sub_state = RW_T3BT_SUBSTATE_WAIT_GET_ATTRIB;
+    return TRUE;
+}
+#endif
+
 #if (BT_TRACE_VERBOSE == TRUE)
 /*******************************************************************************
 **
@@ -1663,6 +2680,28 @@
         return ("WAIT_UPDATE_RESP");
     case RW_T4T_SUBSTATE_WAIT_UPDATE_NLEN:
         return ("WAIT_UPDATE_NLEN");
+#if(NXP_EXTNS == TRUE)
+    case RW_T4T_SUBSTATE_WAIT_GET_HW_VERSION:
+        return ("WAIT_GET_HW_VERSION");
+    case RW_T4T_SUBSTATE_WAIT_GET_SW_VERSION :
+        return ("WAIT_GET_SW_VERSION");
+    case RW_T4T_SUBSTATE_WAIT_GET_UID:
+        return ("WAIT_GET_UID");
+    case RW_T4T_SUBSTATE_WAIT_CREATE_APP:
+        return ("WAIT_CREATE_APP");
+    case RW_T4T_SUBSTATE_WAIT_CREATE_CC:
+        return ("WAIT_CREATE_CC");
+    case RW_T4T_SUBSTATE_WAIT_CREATE_NDEF:
+        return ("WAIT_CREATE_NDEF");
+    case RW_T4T_SUBSTATE_WAIT_WRITE_CC :
+        return ("WAIT_WRITE_CC");
+    case RW_T4T_SUBSTATE_WAIT_WRITE_NDEF:
+        return ("WAIT_WRITE_NDEF");
+    case RW_T3BT_SUBSTATE_WAIT_GET_ATTRIB:
+        return ("WAIT_GET_ATTRIB");
+    case RW_T3BT_SUBSTATE_WAIT_GET_PUPI:
+        return ("WAIT_GET_PUPI");
+#endif
     default:
         return ("???? UNKNOWN SUBSTATE");
     }
diff --git a/src/nfc/tags/tags_int.c b/src/nfc/tags/tags_int.c
index 910bdf2..f4cfb40 100644
--- a/src/nfc/tags/tags_int.c
+++ b/src/nfc/tags/tags_int.c
@@ -320,9 +320,9 @@
 static unsigned int tags_ones32 (register unsigned int x)
 {
         /* 32-bit recursive reduction using SWAR...
-	   but first step is mapping 2-bit values
-	   into sum of 2 1-bit values in sneaky way
-	*/
+       but first step is mapping 2-bit values
+       into sum of 2 1-bit values in sneaky way
+    */
         x -= ((x >> 1) & 0x55555555);
         x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
         x = (((x >> 4) + x) & 0x0f0f0f0f);
diff --git a/src/udrv/include/uipc.h b/src/udrv/include/uipc.h
index f5f1ec1..7a29645 100644
--- a/src/udrv/include/uipc.h
+++ b/src/udrv/include/uipc.h
@@ -154,5 +154,3 @@
 
 
 #endif  /* UIPC_H */
-
-
diff --git a/src/udrv/include/upio.h b/src/udrv/include/upio.h
index 77ee4ba..aa826ef 100644
--- a/src/udrv/include/upio.h
+++ b/src/udrv/include/upio.h
@@ -15,6 +15,12 @@
  *  limitations under the License.
  *
  ******************************************************************************/
+
+/******************************************************************************
+ *
+ *  Definitions for UPIO driver
+ *
+ ******************************************************************************/
 #ifndef UPIO_H
 #define UPIO_H
 
@@ -302,7 +308,7 @@
 **      cannot be masked together.
 **
 ** Input Parameters:
-**      Type:	The type of device.
+**      Type:   The type of device.
 **      pio:    Indicates the particular GUPIO.
 **
 ** Output Parameter:
diff --git a/src/udrv/include/uusb.h b/src/udrv/include/uusb.h
index 590a8fa..7a93920 100644
--- a/src/udrv/include/uusb.h
+++ b/src/udrv/include/uusb.h
@@ -76,10 +76,10 @@
 #define UUSB_HOST_TO_DEVICE      0x00    /* Data transfer directions */
 #define UUSB_DEVICE_TO_HOST      0x80    /* Data transfer directions */
 /* Types of requests */
-#define UUSB_REQUEST_TYPE		0x60	/* Mask to get request type */
-#define UUSB_STANDARD_REQUEST	0x00	/* Standard request */
-#define	UUSB_CLASS_REQUEST		0x20	/* Class request */
-#define	UUSB_VENDOR_REQUEST		0x40	/* Vendor request */
+#define UUSB_REQUEST_TYPE       0x60    /* Mask to get request type */
+#define UUSB_STANDARD_REQUEST   0x00    /* Standard request */
+#define UUSB_CLASS_REQUEST      0x20    /* Class request */
+#define UUSB_VENDOR_REQUEST     0x40    /* Vendor request */
   UINT8 bmRequestType;
   UINT8 bRequest;
   UINT16 wValue;
@@ -90,7 +90,7 @@
 typedef union
 {
 #define UUSB_HEAD_SIZE (8)
-	UINT8           HeadBytes[UUSB_HEAD_SIZE];
+    UINT8           HeadBytes[UUSB_HEAD_SIZE];
     tUUSB_SETUP_PKT Setup;
 } tSETUP_OR_HEAD;
 
@@ -133,20 +133,20 @@
 
 typedef enum _tUUSB_STANDART_REQ
 {
-	UUSB_GET_STATUS = 0,
-	UUSB_CLEAR_FEATURE,
-	UUSB_RESERVED1,
-	UUSB_SET_FEATURE,
-	UUSB_RESERVED2,
-	UUSB_SET_ADDRESS,
-	UUSB_GET_DESCRIPTOR,
-	UUSB_SET_DESCRIPTOR,
-	UUSB_GET_CONFIGURATION,
-	UUSB_SET_CONFIGURATION,
-	UUSB_GET_INTERFACE,
-	UUSB_SET_INTERFACE,
-	UUSB_TOTAL_sREQUEST,				/* Total number of Standard request */
-	UUSB_SYNCH_FRAME = 12
+    UUSB_GET_STATUS = 0,
+    UUSB_CLEAR_FEATURE,
+    UUSB_RESERVED1,
+    UUSB_SET_FEATURE,
+    UUSB_RESERVED2,
+    UUSB_SET_ADDRESS,
+    UUSB_GET_DESCRIPTOR,
+    UUSB_SET_DESCRIPTOR,
+    UUSB_GET_CONFIGURATION,
+    UUSB_SET_CONFIGURATION,
+    UUSB_GET_INTERFACE,
+    UUSB_SET_INTERFACE,
+    UUSB_TOTAL_sREQUEST,                /* Total number of Standard request */
+    UUSB_SYNCH_FRAME = 12
 } tUUSB_STANDART_REQ;