NCI2.0 Added HCI network initialization and NFCEE Discover
support.

Test: Compiles.

Change-Id: I34548e302b6ee7d3a3faf2bd25a1f17528c0a6d1
diff --git a/src/hal/include/nci_defs.h b/src/hal/include/nci_defs.h
index 46969e0..c18eb20 100644
--- a/src/hal/include/nci_defs.h
+++ b/src/hal/include/nci_defs.h
@@ -250,7 +250,8 @@
  **********************************************/
 #define NCI_MSG_NFCEE_DISCOVER 0
 #define NCI_MSG_NFCEE_MODE_SET 1
-
+#define NCI_MSG_NFCEE_STATUS 2
+#define NCI_MSG_NFCEE_POWER_LINK_CTRL 3
 /**********************************************
  * NCI Proprietary  Group       - F
  **********************************************/
@@ -262,6 +263,11 @@
 #define NCI_CORE_PARAM_SIZE_RESET_RSP 0x03
 #define NCI_CORE_PARAM_SIZE_RESET_NTF 0x02
 
+/**********************************************
+ * NCI Feature Bit
+ **********************************************/
+#define NCI_FEAT_HCI_NETWORK 0x00000008
+
 #define NCI_CORE_PARAM_SIZE_INIT(X) (((X) == NCI_VERSION_2_0) ? (0x02) : (0x00))
 #define NCI2_0_CORE_INIT_CMD_BYTE_0 0x00
 #define NCI2_0_CORE_INIT_CMD_BYTE_1 0x00
@@ -316,7 +322,9 @@
 /* Operating field generated by remote device  */
 #define NCI_RF_STS_REMOTE 0x01
 
-#define NCI_PARAM_SIZE_DISCOVER_NFCEE 0x01 /* Discovery Action (1 octet) */
+/* Discovery Action (1 octet) */
+#define NCI_PARAM_SIZE_DISCOVER_NFCEE(X) \
+  (((X) == NCI_VERSION_2_0) ? 0X00 : 0X01)
 /* Status (1 octet)Number of NFCEEs (1 octet) */
 #define NCI_PARAM_SIZE_DISCOVER_NFCEE_RSP 0x02
 
@@ -338,6 +346,13 @@
 #define NCI_NFCEE_INTERFACE_T3T 0x02
 #define NCI_NFCEE_INTERFACE_TRANSPARENT 0x03
 #define NCI_NFCEE_INTERFACE_PROPRIETARY 0x80
+/****************************************************
+ * NCI NFCEE INterface specific status Codes
+ ****************************************************/
+#define NCI_NFCEE_STS_INTF_ACTIVATION_FAILED 0xC0
+#define NCI_NFCEE_STS_TRANSMISSION_ERROR 0xC1
+#define NCI_NFCEE_STS_PROTOCOL_ERROR 0xC2
+#define NCI_NFCEE_STS_TIMEOUT_ERROR 0xC3
 
 #define NCI_NFCEE_STS_CONN_ACTIVE 0x00
 #define NCI_NFCEE_STS_CONN_INACTIVE 0x01
@@ -372,6 +387,19 @@
 /* DH Request Failed due to error */
 #define NCI_DEACTIVATE_REASON_DH_REQ_FAILED 4
 
+/* The NFCEE status in NFCEE Status Notification */
+#define NCI_NFCEE_NTF_STATUS_ERROR 0x00        /* Unrecoverable Error */
+#define NCI_NFCEE_NTF_STATUS_INIT_STARTED 0x01 /* NFCEE init seq started */
+#define NCI_NFCEE_NTF_STATUS_INIT_DONE 0x02    /* NFCEE init seq completed */
+typedef uint8_t tNCI_EE_NTF_STATUS;
+
+/* NFCEE Power and Link Configuration */
+#define NFCEE_PL_CONFIG_NFCC_DECIDES 0x00
+#define NFCEE_PL_CONFIG_PWR_ALWAYS_ON 0x01
+#define NFCEE_PL_CONFIG_LNK_ON_WHEN_PWR_ON 0x02
+#define NFCEE_PL_CONFIG_PWR_LNK_ALWAYS_ON 0x03
+typedef uint8_t tNCI_NFCEE_PL_CONFIG;
+
 /**********************************************
 * NCI Interface Mode
 **********************************************/
@@ -447,6 +475,10 @@
 #define NCI_EE_ACT_TAG_DATA 0xC3  /* hex data for app    */
 #define NCI_EE_ACT_TAG_DEBUG 0xC4 /* debug trace         */
 
+/* NFCEE ID (1 octet) PL config (1 octet) */
+#define NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL 0x02
+/* Status (1 octet) */
+#define NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL_RSP 0x01
 /* Technology based routing  */
 #define NCI_ROUTE_TAG_TECH 0x00
 /* Protocol based routing  */
diff --git a/src/nfa/dm/nfa_dm_api.c b/src/nfa/dm/nfa_dm_api.c
index 474a525..08d9ac6 100644
--- a/src/nfa/dm/nfa_dm_api.c
+++ b/src/nfa/dm/nfa_dm_api.c
@@ -152,6 +152,19 @@
 
   return (NFA_STATUS_FAILED);
 }
+
+/*******************************************************************************
+**
+** Function         NFA_GetNCIVersion
+**
+** Description      Returns the NCI version of the NFCC to upper layer
+**
+**
+** Returns          NCI version NCI2.0 / NCI1.0
+**
+*******************************************************************************/
+uint8_t NFA_GetNCIVersion() { return NFC_GetNCIVersion(); }
+
 /*******************************************************************************
 **
 ** Function         NFA_SetPowerSubStateForScreenState
diff --git a/src/nfa/ee/nfa_ee_act.c b/src/nfa/ee/nfa_ee_act.c
index 3ae939d..c8c4944 100644
--- a/src/nfa/ee/nfa_ee_act.c
+++ b/src/nfa/ee/nfa_ee_act.c
@@ -514,7 +514,7 @@
                    nfa_ee_cb.discv_timer.in_use);
   if (nfa_ee_cb.discv_timer.in_use) {
     nfa_sys_stop_timer(&nfa_ee_cb.discv_timer);
-    NFC_NfceeDiscover(false);
+    if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false);
   }
   if (nfa_ee_cb.p_ee_disc_cback == NULL &&
       NFC_NfceeDiscover(true) == NFC_STATUS_OK) {
@@ -599,10 +599,18 @@
 *******************************************************************************/
 void nfa_ee_api_mode_set(tNFA_EE_MSG* p_data) {
   tNFA_EE_ECB* p_cb = p_data->cfg_hdr.p_cb;
-
+  tNFA_EE_MODE_SET mode_set;
   NFA_TRACE_DEBUG2("nfa_ee_api_mode_set() handle:0x%02x mode:%d",
                    p_cb->nfcee_id, p_data->mode_set.mode);
-  NFC_NfceeModeSet(p_cb->nfcee_id, p_data->mode_set.mode);
+  mode_set.status = NFC_NfceeModeSet(p_cb->nfcee_id, p_data->mode_set.mode);
+  if (mode_set.status != NFC_STATUS_OK) {
+    /* the api is rejected at NFC layer, report the failure status right away */
+    mode_set.ee_handle = (tNFA_HANDLE)p_cb->nfcee_id | NFA_HANDLE_GROUP_EE;
+    mode_set.ee_status = p_data->mode_set.mode;
+    nfa_ee_report_event(NULL, NFA_EE_MODE_SET_EVT,
+                        (tNFA_EE_CBACK_DATA*)&mode_set);
+    return;
+  }
   /* set the NFA_EE_STATUS_PENDING bit to indicate the status is not exactly
    * active */
   if (p_data->mode_set.mode == NFC_MODE_ACTIVATE)
@@ -1244,7 +1252,7 @@
     if ((nfa_ee_cb.num_ee_expecting == 0) &&
         (nfa_ee_cb.p_ee_disc_cback != NULL)) {
       /* Discovery triggered by API function */
-      NFC_NfceeDiscover(false);
+      if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false);
     }
   }
   switch (nfa_ee_cb.em_state) {
@@ -1309,7 +1317,8 @@
     memcpy(p_cb->ee_interface, p_ee->ee_interface, p_ee->num_interface);
     p_cb->num_tlvs = p_ee->num_tlvs;
     memcpy(p_cb->ee_tlv, p_ee->ee_tlv, p_ee->num_tlvs * sizeof(tNFA_EE_TLV));
-
+    if (NFA_GetNCIVersion() == NCI_VERSION_2_0)
+      p_cb->ee_power_supply_status = p_ee->nfcee_power_ctrl;
     if (nfa_ee_cb.em_state == NFA_EE_EM_STATE_RESTORING) {
       /* NCI spec says: An NFCEE_DISCOVER_NTF that contains a Protocol type of
        * "HCI Access"
@@ -1337,6 +1346,8 @@
         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));
+        if (NFA_GetNCIVersion() == NCI_VERSION_2_0)
+          p_info->ee_power_supply_status = p_cb->ee_power_supply_status;
         nfa_ee_report_event(NULL, NFA_EE_NEW_EE_EVT, &evt_data);
       }
     } else
@@ -1489,19 +1500,18 @@
   tNFA_EE_MODE_SET mode_set;
   tNFC_NFCEE_MODE_SET_REVT* p_rsp = p_data->mode_set_rsp.p_data;
 
-  NFA_TRACE_DEBUG2("nfa_ee_nci_mode_set_rsp() handle:0x%02x mode:%d",
-                   p_rsp->nfcee_id, p_rsp->mode);
+  NFA_TRACE_DEBUG3("%s handle:0x%02x mode:%d", __func__, p_rsp->nfcee_id,
+                   p_rsp->mode);
   p_cb = nfa_ee_find_ecb(p_rsp->nfcee_id);
   if (p_cb == NULL) {
-    NFA_TRACE_ERROR1(
-        "nfa_ee_nci_mode_set_rsp() Can not find cb for handle:0x%02x",
-        p_rsp->nfcee_id);
+    NFA_TRACE_ERROR2("%s Can not find cb for handle:0x%02x", __func__,
+                     p_rsp->nfcee_id);
     return;
   }
 
   /* update routing table and vs on mode change */
   nfa_ee_start_timer();
-
+  NFA_TRACE_ERROR2("%s p_rsp->status:0x%02x", __func__, p_rsp->status);
   if (p_rsp->status == NFA_STATUS_OK) {
     if (p_rsp->mode == NFA_EE_MD_ACTIVATE) {
       p_cb->ee_status = NFC_NFCEE_STATUS_ACTIVE;
@@ -1522,6 +1532,8 @@
       p_cb->aid_entries = 0;
       p_cb->ee_status = NFC_NFCEE_STATUS_INACTIVE;
     }
+  } else if (p_rsp->mode == NFA_EE_MD_ACTIVATE) {
+    p_cb->ee_status = NFC_NFCEE_STATUS_REMOVED;
   }
   NFA_TRACE_DEBUG4("status:%d ecb_flags  :0x%02x ee_cfged:0x%02x ee_status:%d",
                    p_rsp->status, p_cb->ecb_flags, nfa_ee_cb.ee_cfged,
@@ -1551,6 +1563,8 @@
       nfa_ee_report_discover_req_evt();
     }
   }
+  if (nfa_ee_cb.p_enable_cback)
+    (*nfa_ee_cb.p_enable_cback)(NFA_EE_MODE_SET_COMPLETE);
 }
 
 /*******************************************************************************
@@ -2244,7 +2258,7 @@
 **
 *******************************************************************************/
 void nfa_ee_discv_timeout(tNFA_EE_MSG* p_data) {
-  NFC_NfceeDiscover(false);
+  if (NFA_GetNCIVersion() != NCI_VERSION_2_0) NFC_NfceeDiscover(false);
   if (nfa_ee_cb.p_enable_cback)
     (*nfa_ee_cb.p_enable_cback)(NFA_EE_DISC_STS_OFF);
 }
diff --git a/src/nfa/ee/nfa_ee_api.c b/src/nfa/ee/nfa_ee_api.c
index a1290b7..87fe0be 100644
--- a/src/nfa/ee/nfa_ee_api.c
+++ b/src/nfa/ee/nfa_ee_api.c
@@ -119,6 +119,7 @@
     p_info->num_tlvs = p_cb->num_tlvs;
     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->ee_power_supply_status = p_cb->ee_power_supply_status;
     p_info++;
     num_ret++;
   }
diff --git a/src/nfa/hci/nfa_hci_act.c b/src/nfa/hci/nfa_hci_act.c
index d68cddf..9226f35 100644
--- a/src/nfa/hci/nfa_hci_act.c
+++ b/src/nfa/hci/nfa_hci_act.c
@@ -1359,6 +1359,11 @@
           if ((nfa_hci_cb.hci_state == NFA_HCI_STATE_STARTUP) ||
               (nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE))
             nfa_hci_dh_startup_complete();
+          if (NFA_GetNCIVersion() == NCI_VERSION_2_0) {
+            nfa_hci_cb.hci_state = NFA_HCI_STATE_WAIT_NETWK_ENABLE;
+            NFA_EeGetInfo(&nfa_hci_cb.num_nfcee, nfa_hci_cb.ee_info);
+            nfa_hci_enable_one_nfcee();
+          }
         }
         break;
 
diff --git a/src/nfa/hci/nfa_hci_api.c b/src/nfa/hci/nfa_hci_api.c
index c40ed3e..987176a 100644
--- a/src/nfa/hci/nfa_hci_api.c
+++ b/src/nfa/hci/nfa_hci_api.c
@@ -981,12 +981,12 @@
 
     case NFA_HCI_DEBUG_ENABLE_LOOPBACK:
       NFA_TRACE_API0("NFA_HciDebug  HCI_LOOPBACK_DEBUG = TRUE");
-      HCI_LOOPBACK_DEBUG = true;
+      HCI_LOOPBACK_DEBUG = NFA_HCI_DEBUG_ON;
       break;
 
     case NFA_HCI_DEBUG_DISABLE_LOOPBACK:
       NFA_TRACE_API0("NFA_HciDebug  HCI_LOOPBACK_DEBUG = FALSE");
-      HCI_LOOPBACK_DEBUG = false;
+      HCI_LOOPBACK_DEBUG = NFA_HCI_DEBUG_OFF;
       break;
   }
 }
diff --git a/src/nfa/hci/nfa_hci_main.c b/src/nfa/hci/nfa_hci_main.c
index 28067e8..4cf2208 100644
--- a/src/nfa/hci/nfa_hci_main.c
+++ b/src/nfa/hci/nfa_hci_main.c
@@ -82,8 +82,6 @@
 **
 *******************************************************************************/
 void nfa_hci_ee_info_cback(tNFA_EE_DISC_STS status) {
-  uint8_t num_nfcee = 3;
-  tNFA_EE_INFO ee_info[3];
 
   NFA_TRACE_DEBUG1("nfa_hci_ee_info_cback (): %d", status);
 
@@ -104,9 +102,6 @@
     case NFA_EE_DISC_STS_OFF:
       if (nfa_hci_cb.ee_disable_disc) break;
       nfa_hci_cb.ee_disable_disc = true;
-      /* Discovery operation is complete, retrieve discovery result */
-      NFA_EeGetInfo(&num_nfcee, ee_info);
-      nfa_hci_cb.num_nfcee = num_nfcee;
 
       if ((nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_NETWK_ENABLE) ||
           (nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE_NETWK_ENABLE)) {
@@ -144,7 +139,8 @@
             (nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE_NETWK_ENABLE)) {
           /* Received DISC REQ Ntf while waiting for other Host in the network
            * to bootup after DH host bootup is complete */
-          if (nfa_hci_cb.num_ee_dis_req_ntf == (nfa_hci_cb.num_nfcee - 1)) {
+          if ((nfa_hci_cb.num_ee_dis_req_ntf == (nfa_hci_cb.num_nfcee - 1)) &&
+              NFC_GetNCIVersion() != NCI_VERSION_2_0) {
             /* Received expected number of EE DISC REQ Ntf(s) */
             nfa_sys_stop_timer(&nfa_hci_cb.timer);
             nfa_hci_cb.w4_hci_netwk_init = false;
@@ -161,6 +157,15 @@
         }
       }
       break;
+    case NFA_EE_MODE_SET_COMPLETE:
+      /*received mode set Ntf */
+      if ((nfa_hci_cb.hci_state == NFA_HCI_STATE_WAIT_NETWK_ENABLE) ||
+          (nfa_hci_cb.hci_state == NFA_HCI_STATE_RESTORE_NETWK_ENABLE)) {
+        /* Discovery operation is complete, retrieve discovery result */
+        NFA_EeGetInfo(&nfa_hci_cb.num_nfcee, nfa_hci_cb.ee_info);
+        nfa_hci_enable_one_nfcee();
+      }
+      break;
   }
 }
 
@@ -180,7 +185,7 @@
   memset(&nfa_hci_cb, 0, sizeof(tNFA_HCI_CB));
 
   nfa_hci_cb.hci_state = NFA_HCI_STATE_STARTUP;
-
+  nfa_hci_cb.num_nfcee = NFA_HCI_MAX_HOST_IN_NETWORK;
   /* register message handler on NFA SYS */
   nfa_sys_register(NFA_ID_HCI, &nfa_hci_sys_reg);
 }
@@ -261,7 +266,12 @@
                          nfa_hci_cb.cfg.dyn_gates[xx].gate_owner);
         return false;
       }
-      if (nfa_hci_cb.cfg.dyn_gates[xx].gate_id != NFA_HCI_CONNECTIVITY_GATE) {
+      if (!((nfa_hci_cb.cfg.dyn_gates[xx].gate_id ==
+             NFA_HCI_CONNECTIVITY_GATE) ||
+            ((nfa_hci_cb.cfg.dyn_gates[xx].gate_id >=
+              NFA_HCI_PROP_GATE_FIRST) ||
+             (nfa_hci_cb.cfg.dyn_gates[xx].gate_id <=
+              NFA_HCI_PROP_GATE_LAST)))) {
         /* The gate owner should be one of the registered application */
         for (zz = 0; zz < app_count; zz++) {
           if (nfa_hci_cb.cfg.dyn_gates[xx].gate_owner == reg_app[zz]) break;
@@ -509,6 +519,34 @@
 
 /*******************************************************************************
 **
+** Function         nfa_hci_enable_one_nfcee
+**
+** Description      Enable NFCEE Hosts which are discovered.
+**
+** Returns          None
+**
+*******************************************************************************/
+void nfa_hci_enable_one_nfcee(void) {
+  uint8_t xx;
+  uint8_t nfceeid = 0;
+
+  NFA_TRACE_DEBUG1("nfa_hci_enable_one_nfcee () %d", nfa_hci_cb.num_nfcee);
+
+  for (xx = 0; xx < nfa_hci_cb.num_nfcee; xx++) {
+    nfceeid = nfa_hci_cb.ee_info[xx].ee_handle & ~NFA_HANDLE_GROUP_EE;
+    if (nfa_hci_cb.ee_info[xx].ee_status == NFA_EE_STATUS_INACTIVE) {
+      NFC_NfceeModeSet(nfceeid, NFC_MODE_ACTIVATE);
+      return;
+    }
+  }
+
+  if (xx == nfa_hci_cb.num_nfcee) {
+    nfa_hciu_send_get_param_cmd(NFA_HCI_ADMIN_PIPE, NFA_HCI_HOST_LIST_INDEX);
+  }
+}
+
+/*******************************************************************************
+**
 ** Function         nfa_hci_startup
 **
 ** Description      Perform HCI startup
@@ -518,13 +556,11 @@
 *******************************************************************************/
 void nfa_hci_startup(void) {
   tNFA_STATUS status = NFA_STATUS_FAILED;
-  tNFA_EE_INFO ee_info[2];
-  uint8_t num_nfcee = 2;
   uint8_t target_handle;
   uint8_t count = 0;
   bool found = false;
 
-  if (HCI_LOOPBACK_DEBUG) {
+  if (HCI_LOOPBACK_DEBUG == NFA_HCI_DEBUG_ON) {
     /* First step in initialization is to open the admin pipe */
     nfa_hciu_send_open_pipe_cmd(NFA_HCI_ADMIN_PIPE);
     return;
@@ -533,38 +569,42 @@
   /* We can only start up if NV Ram is read and EE discovery is complete */
   if (nfa_hci_cb.nv_read_cmplt && nfa_hci_cb.ee_disc_cmplt &&
       (nfa_hci_cb.conn_id == 0)) {
-    NFA_EeGetInfo(&num_nfcee, ee_info);
+    if (NFC_GetNCIVersion() == NCI_VERSION_2_0) {
+      NFC_SetStaticHciCback(nfa_hci_conn_cback);
+    } else {
+      NFA_EeGetInfo(&nfa_hci_cb.num_nfcee, nfa_hci_cb.ee_info);
 
-    while ((count < num_nfcee) && (!found)) {
-      target_handle = (uint8_t)ee_info[count].ee_handle;
+      while ((count < nfa_hci_cb.num_nfcee) && (!found)) {
+        target_handle = (uint8_t)nfa_hci_cb.ee_info[count].ee_handle;
 
-      if (ee_info[count].ee_interface[0] == NFA_EE_INTERFACE_HCI_ACCESS) {
-        found = true;
+        if (nfa_hci_cb.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);
+          if (nfa_hci_cb.ee_info[count].ee_status == NFA_EE_STATUS_INACTIVE) {
+            NFC_NfceeModeSet(target_handle, NFC_MODE_ACTIVATE);
+          }
+          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 {
+            nfa_hci_cb.hci_state = NFA_HCI_STATE_DISABLED;
+            NFA_TRACE_ERROR0(
+                "nfa_hci_startup - Failed to Create Logical connection. HCI "
+                "Initialization/Restore failed");
+            nfa_hci_startup_complete(NFA_STATUS_FAILED);
+          }
         }
-        status =
-            NFC_ConnCreate(NCI_DEST_TYPE_NFCEE, target_handle,
-                           NFA_EE_INTERFACE_HCI_ACCESS, nfa_hci_conn_cback);
-        if (status == NFA_STATUS_OK)
-          nfa_sys_start_timer(&nfa_hci_cb.timer, NFA_HCI_RSP_TIMEOUT_EVT,
-                              NFA_HCI_CON_CREATE_TIMEOUT_VAL);
-        else {
-          nfa_hci_cb.hci_state = NFA_HCI_STATE_DISABLED;
-          NFA_TRACE_ERROR0(
-              "nfa_hci_startup - Failed to Create Logical connection. HCI "
-              "Initialization/Restore failed");
-          nfa_hci_startup_complete(NFA_STATUS_FAILED);
-        }
+        count++;
       }
-      count++;
-    }
-    if (!found) {
-      NFA_TRACE_ERROR0(
-          "nfa_hci_startup - HCI ACCESS Interface not discovered. HCI "
-          "Initialization/Restore failed");
-      nfa_hci_startup_complete(NFA_STATUS_FAILED);
+      if (!found) {
+        NFA_TRACE_ERROR0(
+            "nfa_hci_startup - HCI ACCESS Interface not discovered. HCI "
+            "Initialization/Restore failed");
+        nfa_hci_startup_complete(NFA_STATUS_FAILED);
+      }
     }
   }
 }
@@ -605,8 +645,10 @@
   if (nfa_hci_cb.conn_id) {
     if (nfa_sys_is_graceful_disable()) {
       /* Tell all applications stack is down */
-      nfa_hciu_send_to_all_apps(NFA_HCI_EXIT_EVT, &evt_data);
-      NFC_ConnClose(nfa_hci_cb.conn_id);
+      if (NFC_GetNCIVersion() == NCI_VERSION_1_0) {
+        nfa_hciu_send_to_all_apps(NFA_HCI_EXIT_EVT, &evt_data);
+        NFC_ConnClose(nfa_hci_cb.conn_id);
+      }
       return;
     }
     nfa_hci_cb.conn_id = 0;
@@ -636,7 +678,8 @@
 #if (BT_TRACE_VERBOSE == TRUE)
   char buff[100];
 #endif
-
+  NFA_TRACE_EVENT3("%s State: %u  Cmd: %u", __func__, nfa_hci_cb.hci_state,
+                   event);
   if (event == NFC_CONN_CREATE_CEVT) {
     nfa_hci_cb.conn_id = conn_id;
     nfa_hci_cb.buff_size = p_data->conn_create.buff_size;
@@ -1094,7 +1137,7 @@
         break;
 
       case NFA_HCI_CHECK_QUEUE_EVT:
-        if (HCI_LOOPBACK_DEBUG) {
+        if (HCI_LOOPBACK_DEBUG == NFA_HCI_DEBUG_ON) {
           if (p_msg->len != 0) {
             tNFC_DATA_CEVT xx;
             xx.p_data = p_msg;
diff --git a/src/nfa/hci/nfa_hci_utils.c b/src/nfa/hci/nfa_hci_utils.c
index 895f09e..75a67b2 100644
--- a/src/nfa/hci/nfa_hci_utils.c
+++ b/src/nfa/hci/nfa_hci_utils.c
@@ -35,7 +35,7 @@
 
 static void handle_debug_loopback(NFC_HDR* p_buf, uint8_t pipe, uint8_t type,
                                   uint8_t instruction);
-bool HCI_LOOPBACK_DEBUG = false;
+uint8_t HCI_LOOPBACK_DEBUG = NFA_HCI_DEBUG_OFF;
 
 /*******************************************************************************
 **
@@ -357,7 +357,7 @@
               (bool)((p_buf->len - data_len) == 2));
 #endif
 
-      if (HCI_LOOPBACK_DEBUG)
+      if (HCI_LOOPBACK_DEBUG == NFA_HCI_DEBUG_ON)
         handle_debug_loopback(p_buf, pipe_id, type, instruction);
       else
         status = NFC_SendData(nfa_hci_cb.conn_id, p_buf);
diff --git a/src/nfa/include/nfa_api.h b/src/nfa/include/nfa_api.h
index 3467fdb..552b7ba 100644
--- a/src/nfa/include/nfa_api.h
+++ b/src/nfa/include/nfa_api.h
@@ -1430,7 +1430,6 @@
 extern uint8_t NFA_SetTraceLevel(uint8_t new_level);
 
 /*******************************************************************************
-**
 ** Function:        NFA_EnableDTA_TypeMode
 **
 ** Description:     Initialize and get global DTA type mode from .conf
@@ -1441,6 +1440,17 @@
 extern void NFA_EnableDtamode(tNFA_eDtaModes eDtaMode);
 
 /*******************************************************************************
+** Function         NFA_GetNCIVersion
+**
+** Description      Called by higher layer to get the current nci
+**                  version of nfc.
+**
+** Returns          NCI version NCI2.0 / NCI1.0
+**
+*******************************************************************************/
+extern uint8_t NFA_GetNCIVersion();
+
+/*******************************************************************************
 ** Function:        NFA_SetPowerSubStateForScreenState
 **
 ** Description:     This function send the current screen state
diff --git a/src/nfa/include/nfa_ee_api.h b/src/nfa/include/nfa_ee_api.h
index f4acbe0..28661d2 100644
--- a/src/nfa/include/nfa_ee_api.h
+++ b/src/nfa/include/nfa_ee_api.h
@@ -132,6 +132,7 @@
       ee_interface[NFC_MAX_EE_INTERFACE]; /* NFCEE supported interface */
   uint8_t num_tlvs;                       /* number of TLVs           */
   tNFA_EE_TLV ee_tlv[NFC_MAX_EE_TLVS];    /* the TLV                  */
+  uint8_t ee_power_supply_status;         /* The NFCEE Power supply */
 } tNFA_EE_INFO;
 
 typedef struct {
diff --git a/src/nfa/include/nfa_hci_defs.h b/src/nfa/include/nfa_hci_defs.h
index 67d5a33..981febb 100644
--- a/src/nfa/include/nfa_hci_defs.h
+++ b/src/nfa/include/nfa_hci_defs.h
@@ -38,6 +38,10 @@
 /* Generic Gates */
 #define NFA_HCI_CONNECTIVITY_GATE 0x41
 
+/* Proprietary Gates */
+#define NFA_HCI_PROP_GATE_FIRST 0xF0
+#define NFA_HCI_PROP_GATE_LAST 0xFF
+
 /* Static pipes */
 #define NFA_HCI_LINK_MANAGEMENT_PIPE 0x00
 #define NFA_HCI_ADMIN_PIPE 0x01
diff --git a/src/nfa/int/nfa_ee_int.h b/src/nfa/int/nfa_ee_int.h
index 28b049d..349b0ad 100644
--- a/src/nfa/int/nfa_ee_int.h
+++ b/src/nfa/int/nfa_ee_int.h
@@ -174,6 +174,7 @@
   tNFA_EE_TLV ee_tlv[NFC_MAX_EE_TLVS];    /* the TLV */
   uint8_t num_interface;                  /* number of Target interface */
   uint8_t num_tlvs;                       /* number of TLVs */
+  uint8_t ee_power_supply_status;         /* power supply of NFCEE*/
   tNFA_EE_ECB_FLAGS ecb_flags;            /* the flags of this control block */
   tNFA_EE_INTERFACE use_interface; /* NFCEE interface used for the connection */
   tNFA_NFC_PROTOCOL la_protocol;   /* Listen A protocol    */
@@ -406,6 +407,8 @@
 #define NFA_EE_DISC_STS_OFF 0x01
 /* received NFCEE DISCOVER REQ NTF  */
 #define NFA_EE_DISC_STS_REQ 0x02
+/* received NFA_EE_MODE_SET_COMPLETE  */
+#define NFA_EE_MODE_SET_COMPLETE 0x03
 typedef uint8_t tNFA_EE_DISC_STS;
 
 typedef void(tNFA_EE_ENABLE_DONE_CBACK)(tNFA_EE_DISC_STS status);
diff --git a/src/nfa/int/nfa_hci_int.h b/src/nfa/int/nfa_hci_int.h
index ca84f4b..393e17b 100644
--- a/src/nfa/int/nfa_hci_int.h
+++ b/src/nfa/int/nfa_hci_int.h
@@ -24,11 +24,14 @@
 #ifndef NFA_HCI_INT_H
 #define NFA_HCI_INT_H
 
+#include "nfa_ee_api.h"
 #include "nfa_hci_api.h"
 #include "nfa_sys.h"
+extern uint8_t HCI_LOOPBACK_DEBUG;
 
-extern bool HCI_LOOPBACK_DEBUG;
-
+/* NFA HCI DEBUG states */
+#define NFA_HCI_DEBUG_ON 0x01
+#define NFA_HCI_DEBUG_OFF 0x00
 /*****************************************************************************
 **  Constants and data types
 *****************************************************************************/
@@ -364,6 +367,7 @@
 typedef struct {
   tNFA_HCI_STATE hci_state;   /* state of the HCI */
   uint8_t num_nfcee;          /* Number of NFCEE ID Discovered */
+  tNFA_EE_INFO ee_info[NFA_HCI_MAX_HOST_IN_NETWORK]; /*NFCEE ID Info*/
   uint8_t num_ee_dis_req_ntf; /* Number of ee discovery request ntf received */
   uint8_t num_hot_plug_evts;  /* Number of Hot plug events received after ee
                                  discovery disable ntf */
@@ -442,6 +446,7 @@
 extern void nfa_hci_startup_complete(tNFA_STATUS status);
 extern void nfa_hci_startup(void);
 extern void nfa_hci_restore_default_config(uint8_t* p_session_id);
+extern void nfa_hci_enable_one_nfcee(void);
 
 /* Action functions in nfa_hci_act.c
 */
diff --git a/src/nfc/include/nci_hmsgs.h b/src/nfc/include/nci_hmsgs.h
index d013cde..8fba6a8 100644
--- a/src/nfc/include/nci_hmsgs.h
+++ b/src/nfc/include/nci_hmsgs.h
@@ -69,6 +69,7 @@
 uint8_t nci_snd_set_routing_cmd(bool more, uint8_t num_tlv, uint8_t tlv_size,
                                 uint8_t* p_param_tlvs);
 uint8_t nci_snd_get_routing_cmd(void);
+uint8_t nci_snd_nfcee_power_link_control(uint8_t nfcee_id, uint8_t pl_config);
 #endif
 
 #ifdef __cplusplus
diff --git a/src/nfc/include/nfc_api.h b/src/nfc/include/nfc_api.h
index ae9b0df..6dbd124 100644
--- a/src/nfc/include/nfc_api.h
+++ b/src/nfc/include/nfc_api.h
@@ -223,6 +223,8 @@
   NFC_NFCC_TRANSPORT_ERR_REVT,      /* 16 NCI Tranport error            */
   NFC_NFCC_POWER_OFF_REVT,          /* 17 NFCC turned off               */
   NFC_SET_POWER_SUB_STATE_REVT,     /* 18 Set power sub state response  */
+  NFC_NFCEE_PL_CONTROL_REVT,        /* NFCEE Power/Link Ctrl response*/
+  NFC_NFCEE_STATUS_REVT,            /* NFCEE Status Notification     */
   NFC_FIRST_VS_REVT                 /* First vendor-specific rsp event  */
 };
 typedef uint16_t tNFC_RESPONSE_EVT;
@@ -304,6 +306,12 @@
 #define NFC_NFCEE_STATUS_ACTIVE NCI_NFCEE_STS_CONN_ACTIVE
 /* NFCEE removed                */
 #define NFC_NFCEE_STATUS_REMOVED NCI_NFCEE_STS_REMOVED
+
+#define NFC_NFCEE_STS_INTF_ACTIVATION_FAILED \
+  NCI_NFCEE_STS_INTF_ACTIVATION_FAILED
+#define NFC_NFCEE_STS_TRANSMISSION_ERROR NCI_NFCEE_STS_TRANSMISSION_ERROR
+#define NFC_NFCEE_STS_PROTOCOL_ERROR NCI_NFCEE_STS_PROTOCOL_ERROR
+#define NFC_NFCEE_STS_TIMEOUT_ERROR NCI_NFCEE_STS_TIMEOUT_ERROR
 /* the data type associated with NFC_NFCEE_INFO_REVT */
 typedef struct {
   tNFC_STATUS status;    /* The event status - place holder  */
@@ -313,6 +321,7 @@
   uint8_t ee_interface[NFC_MAX_EE_INTERFACE]; /* NFCEE interface       */
   uint8_t num_tlvs;                       /* number of TLVs                   */
   tNFC_NFCEE_TLV ee_tlv[NFC_MAX_EE_TLVS]; /* The TLVs associated with NFCEE   */
+  bool nfcee_power_ctrl; /* 1, if NFCC has control of NFCEE Power Supply */
 } tNFC_NFCEE_INFO_REVT;
 
 #define NFC_MODE_ACTIVATE NCI_NFCEE_MD_ACTIVATE
@@ -364,6 +373,19 @@
   NFC_HDR* p_data;    /* The received Data                */
 } tNFC_DATA_CEVT;
 
+/* the data type associated with NFC_NFCEE_PL_CONTROL_REVT */
+typedef struct {
+  tNFC_STATUS status;              /* The event status */
+  uint8_t nfcee_id;                /* NFCEE ID */
+  tNCI_NFCEE_PL_CONFIG pl_control; /* Power/Link Control command */
+} tNFC_NFCEE_PL_CONTROL_REVT;
+
+/* the data type associated with NFC_NFCEE_STATUS_REVT */
+typedef struct {
+  tNFC_STATUS status;              /* The event status */
+  uint8_t nfcee_id;                /* NFCEE ID */
+  tNCI_EE_NTF_STATUS nfcee_status; /* NFCEE status */
+} tNFC_NFCEE_STATUS_REVT;
 /* RF Field Status */
 /* No field generated by remote device  */
 #define NFC_RF_STS_NO_REMOTE NCI_RF_STS_NO_REMOTE
@@ -550,6 +572,8 @@
   tNFC_NFCEE_DISCOVER_REVT nfcee_discover;
   tNFC_NFCEE_INFO_REVT nfcee_info;
   tNFC_NFCEE_MODE_SET_REVT mode_set;
+  tNFC_NFCEE_PL_CONTROL_REVT pl_control;
+  tNFC_NFCEE_STATUS_REVT nfcee_status;
   tNFC_RF_FIELD_REVT rf_field;
   tNFC_STATUS cfg_routing;
   tNFC_GET_ROUTING_REVT get_routing;
@@ -863,6 +887,8 @@
 #define NFC_ILLEGAL_CONN_ID 0xFF
 /* the static connection ID for RF traffic */
 #define NFC_RF_CONN_ID 0
+/* the static connection ID for HCI transport */
+#define NFC_HCI_CONN_ID 1
 
 /*************************************
 **  Status callback function
@@ -1366,6 +1392,45 @@
 extern tNFC_FW_VERSION nfc_ncif_getFWVersion();
 #endif
 
+/*******************************************************************************
+**
+** Function         NFC_NfceePLConfig
+**
+** Description      This function is called to set the Power and Link Control
+**                  to an NFCEE connected to the NFCC.
+**                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
+**                  as NFC_NFCEE_PL_CONTROL_REVT.
+**
+** Parameters       nfcee_id - the NFCEE to activate or de-activate.
+**                 pl_config -
+**                 NFCEE_PL_CONFIG_NFCC_DECIDES -NFCC decides (default)
+**                 NFCEE_PL_CONFIG_PWR_ALWAYS_ON -NFCEE power supply always on
+**                 NFCEE_PL_CONFIG_LNK_ON_WHEN_PWR_ON -
+**                                     communication link is always active
+**                                     when NFCEE is powered on
+**                 NFCEE_PL_CONFIG_PWR_LNK_ALWAYS_ON -
+**                                     power supply and communication
+**                                     link are always on
+** Returns          tNFC_STATUS
+**
+*******************************************************************************/
+extern tNFC_STATUS NFC_NfceePLConfig(uint8_t nfcee_id,
+                                     tNCI_NFCEE_PL_CONFIG pl_config);
+
+/*******************************************************************************
+**
+** Function         NFC_SetStaticHciCback
+**
+** Description      This function to update the data callback function
+**                  to receive the data for the static Hci connection id.
+**
+** Parameters       p_cback - the connection callback function
+**
+** Returns          Nothing
+**
+*******************************************************************************/
+extern void NFC_SetStaticHciCback(tNFC_CONN_CBACK* p_cback);
+
 #if (BT_TRACE_VERBOSE == TRUE)
 /*******************************************************************************
 **
diff --git a/src/nfc/int/nfc_int.h b/src/nfc/int/nfc_int.h
index 347456e..49ab99e 100644
--- a/src/nfc/int/nfc_int.h
+++ b/src/nfc/int/nfc_int.h
@@ -50,6 +50,7 @@
 #define NFC_TTYPE_NCI_WAIT_RSP 0
 #define NFC_TTYPE_WAIT_2_DEACTIVATE 1
 #define NFC_WAIT_RSP_RAW_VS 0x02
+#define NFC_TTYPE_WAIT_MODE_SET_NTF 2
 
 #define NFC_TTYPE_LLCP_LINK_MANAGER 100
 #define NFC_TTYPE_LLCP_LINK_INACT 101
@@ -66,7 +67,8 @@
 /* added for p2p prio logic clenaup */
 #define NFC_TTYPE_P2P_PRIO_LOGIC_CLEANUP 111
 #define NFC_TTYPE_VS_BASE 200
-
+/* time out for mode set notification */
+#define NFC_MODE_SET_NTF_TIMEOUT 2
 /* NFC Task event messages */
 
 enum {
@@ -105,6 +107,8 @@
 #define NFC_FL_DISCOVER_PENDING 0x0040
 /* NFC_FL_CONTROL_REQUESTED on HAL request      */
 #define NFC_FL_HAL_REQUESTED 0x0080
+/* Waiting for NFCEE Mode Set NTF                 */
+#define NFC_FL_WAIT_MODE_SET_NTF 0x0100
 
 #define NFC_PEND_CONN_ID 0xFE
 #define NFC_CONN_ID_INT_MASK 0xF0
@@ -196,7 +200,7 @@
   /* NFC_TASK timer management */
   TIMER_LIST_Q timer_queue; /* 1-sec timer event queue */
   TIMER_LIST_Q quick_timer_queue;
-
+  TIMER_LIST_ENT mode_set_ntf_timer; /* Timer to wait for deactivation */
   TIMER_LIST_ENT deactivate_timer; /* Timer to wait for deactivation */
 
   tNFC_STATE nfc_state;
@@ -229,6 +233,8 @@
   uint8_t rawVsCbflag;
   uint8_t deact_reason;
 
+  TIMER_LIST_ENT nci_mode_set_ntf_timer; /*Mode set notification timer*/
+
 } tNFC_CB;
 
 /*****************************************************************************
@@ -261,6 +267,7 @@
 extern uint8_t nfc_ncif_send_data(tNFC_CONN_CB* p_cb, NFC_HDR* p_data);
 extern void nfc_ncif_cmd_timeout(void);
 extern void nfc_wait_2_deactivate_timeout(void);
+extern void nfc_mode_set_ntf_timeout(void);
 
 extern bool nfc_ncif_process_event(NFC_HDR* p_msg);
 extern void nfc_ncif_check_cmd_queue(NFC_HDR* p_buf);
diff --git a/src/nfc/nci/nci_hmsgs.c b/src/nfc/nci/nci_hmsgs.c
index aa4aa94..245b06a 100644
--- a/src/nfc/nci/nci_hmsgs.c
+++ b/src/nfc/nci/nci_hmsgs.c
@@ -260,20 +260,22 @@
   NFC_HDR* p;
   uint8_t* pp;
 
-  p = NCI_GET_CMD_BUF(NCI_PARAM_SIZE_DISCOVER_NFCEE);
+  p = NCI_GET_CMD_BUF(NCI_PARAM_SIZE_DISCOVER_NFCEE(NFC_GetNCIVersion()));
   if (p == NULL) return (NCI_STATUS_FAILED);
 
   p->event = BT_EVT_TO_NFC_NCI;
-  p->len = NCI_MSG_HDR_SIZE + NCI_PARAM_SIZE_DISCOVER_NFCEE;
+  p->len =
+      NCI_MSG_HDR_SIZE + NCI_PARAM_SIZE_DISCOVER_NFCEE(NFC_GetNCIVersion());
   p->offset = NCI_MSG_OFFSET_SIZE;
   p->layer_specific = 0;
   pp = (uint8_t*)(p + 1) + p->offset;
 
   NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_EE_MANAGE);
   NCI_MSG_BLD_HDR1(pp, NCI_MSG_NFCEE_DISCOVER);
-  UINT8_TO_STREAM(pp, NCI_PARAM_SIZE_DISCOVER_NFCEE);
-  UINT8_TO_STREAM(pp, discover_action);
-
+  UINT8_TO_STREAM(pp, NCI_PARAM_SIZE_DISCOVER_NFCEE(NFC_GetNCIVersion()));
+  if (NFC_GetNCIVersion() != NCI_VERSION_2_0) {
+    UINT8_TO_STREAM(pp, discover_action);
+  }
   nfc_ncif_send_cmd(p);
   return (NCI_STATUS_OK);
 }
@@ -579,6 +581,37 @@
   return (NCI_STATUS_OK);
 }
 
+/*******************************************************************************
+**
+** Function         nci_snd_nfcee_power_link_control
+**
+** Description      compose and send NFCEE Management NFCEE Power and Link
+**                  Control command to command queue
+**
+** Returns          status
+**
+*******************************************************************************/
+uint8_t nci_snd_nfcee_power_link_control(uint8_t nfcee_id, uint8_t pl_config) {
+  uint8_t* pp;
+  NFC_HDR* p = NCI_GET_CMD_BUF(NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL);
+  if (p == NULL) return NCI_STATUS_FAILED;
+
+  p->event = NFC_EVT_TO_NFC_NCI;
+  p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL;
+  p->offset = NCI_MSG_OFFSET_SIZE;
+  p->layer_specific = 0;
+  pp = (uint8_t*)(p + 1) + p->offset;
+
+  NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_EE_MANAGE);
+  NCI_MSG_BLD_HDR1(pp, NCI_MSG_NFCEE_POWER_LINK_CTRL);
+  UINT8_TO_STREAM(pp, NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL);
+  UINT8_TO_STREAM(pp, nfcee_id);
+  UINT8_TO_STREAM(pp, pl_config);
+
+  nfc_ncif_send_cmd(p);
+  return NCI_STATUS_OK;
+}
+
 #if (NFC_NFCEE_INCLUDED == TRUE)
 #if (NFC_RW_ONLY == FALSE)
 /*******************************************************************************
diff --git a/src/nfc/nci/nci_hrcv.c b/src/nfc/nci/nci_hrcv.c
index 07757de..a74325a 100644
--- a/src/nfc/nci/nci_hrcv.c
+++ b/src/nfc/nci/nci_hrcv.c
@@ -304,6 +304,7 @@
   tNFC_NFCEE_DISCOVER_REVT nfcee_discover;
   tNFC_NFCEE_INFO_REVT nfcee_info;
   tNFC_NFCEE_MODE_SET_REVT mode_set;
+  tNFC_NFCEE_PL_CONTROL_REVT pl_control;
   tNFC_RESPONSE* p_evt = (tNFC_RESPONSE*)&nfcee_info;
   tNFC_RESPONSE_EVT event = NFC_NFCEE_INFO_REVT;
   uint8_t* p_old = nfc_cb.last_cmd;
@@ -329,12 +330,24 @@
     case NCI_MSG_NFCEE_MODE_SET:
       p_evt = (tNFC_RESPONSE*)&mode_set;
       mode_set.status = *pp;
-      mode_set.nfcee_id = 0;
-      event = NFC_NFCEE_MODE_SET_REVT;
       mode_set.nfcee_id = *p_old++;
       mode_set.mode = *p_old++;
+      if (nfc_cb.nci_version != NCI_VERSION_2_0 || *pp != NCI_STATUS_OK) {
+        nfc_cb.flags &= ~NFC_FL_WAIT_MODE_SET_NTF;
+        event = NFC_NFCEE_MODE_SET_REVT;
+      } else {
+        /* else response reports OK status on notification */
+        return;
+      }
       break;
 
+    case NCI_MSG_NFCEE_POWER_LINK_CTRL:
+      p_evt = (tNFC_RESPONSE*)&pl_control;
+      p_evt->pl_control.status = *pp;
+      p_evt->pl_control.nfcee_id = *p_old++;
+      p_evt->pl_control.pl_control = *p_old++;
+      event = NFC_NFCEE_PL_CONTROL_REVT;
+      break;
     default:
       p_cback = NULL;
       NFC_TRACE_ERROR1("unknown opcode:0x%x", op_code);
@@ -360,11 +373,13 @@
   tNFC_NFCEE_INFO_REVT nfcee_info;
   tNFC_RESPONSE* p_evt = (tNFC_RESPONSE*)&nfcee_info;
   tNFC_RESPONSE_EVT event = NFC_NFCEE_INFO_REVT;
+  uint8_t* p_old = nfc_cb.last_cmd;
   uint8_t xx;
   uint8_t yy;
   uint8_t ee_status;
   tNFC_NFCEE_TLV* p_tlv;
-
+  tNFC_NFCEE_MODE_SET_REVT mode_set;
+  tNFC_NFCEE_STATUS_REVT nfcee_status;
   /* find the start of the NCI message and parse the NCI header */
   p = (uint8_t*)(p_msg + 1) + p_msg->offset;
   pp = p + 1;
@@ -408,6 +423,20 @@
       STREAM_TO_ARRAY(p_tlv->info, pp, p_tlv->len);
       pp = p += yy;
     }
+  } else if (op_code == NCI_MSG_NFCEE_MODE_SET) {
+    p_evt = (tNFC_RESPONSE*)&mode_set;
+    mode_set.status = *pp;
+    mode_set.nfcee_id = *p_old++;
+    mode_set.mode = *p_old++;
+    event = NFC_NFCEE_MODE_SET_REVT;
+    nfc_cb.flags &= ~NFC_FL_WAIT_MODE_SET_NTF;
+    nfc_stop_timer(&nfc_cb.nci_mode_set_ntf_timer);
+  } else if (op_code == NCI_MSG_NFCEE_STATUS) {
+    p_evt = (tNFC_RESPONSE*)&nfcee_status;
+    event = NFC_NFCEE_STATUS_REVT;
+    nfcee_status.status = NCI_STATUS_OK;
+    nfcee_status.nfcee_id = *pp++;
+    nfcee_status.nfcee_status = *pp;
   } else {
     p_cback = NULL;
     NFC_TRACE_ERROR1("unknown opcode:0x%x", op_code);
diff --git a/src/nfc/nfc/nfc_ee.c b/src/nfc/nfc/nfc_ee.c
index c2c4115..24d2c26 100644
--- a/src/nfc/nfc/nfc_ee.c
+++ b/src/nfc/nfc/nfc_ee.c
@@ -67,12 +67,29 @@
 **
 *******************************************************************************/
 tNFC_STATUS NFC_NfceeModeSet(uint8_t nfcee_id, tNFC_NFCEE_MODE mode) {
-  if (mode >= NCI_NUM_NFCEE_MODE) {
-    NFC_TRACE_ERROR1("NFC_NfceeModeSet bad mode:%d", mode);
+  tNFC_STATUS status = NCI_STATUS_OK;
+  if (mode >= NCI_NUM_NFCEE_MODE || nfcee_id == NCI_DH_ID) {
+    NFC_TRACE_ERROR2("%s invalid parameter:%d", __func__, mode);
     return NFC_STATUS_FAILED;
   }
-
-  return nci_snd_nfcee_mode_set(nfcee_id, mode);
+  if (nfc_cb.nci_version != NCI_VERSION_2_0)
+    status = nci_snd_nfcee_mode_set(nfcee_id, mode);
+  else {
+    if (nfc_cb.flags & NFC_FL_WAIT_MODE_SET_NTF)
+      status = NFC_STATUS_REFUSED;
+    else {
+      status = nci_snd_nfcee_mode_set(nfcee_id, mode);
+      if (status == NCI_STATUS_OK) {
+        /* Mode set command is successfully queued or sent.
+         * do not allow another Mode Set command until NTF is received */
+        nfc_cb.flags |= NFC_FL_WAIT_MODE_SET_NTF;
+        nfc_start_timer(&nfc_cb.nci_mode_set_ntf_timer,
+                        (uint16_t)(NFC_TTYPE_WAIT_MODE_SET_NTF),
+                        NFC_MODE_SET_NTF_TIMEOUT);
+      }
+    }
+  }
+  return status;
 }
 
 /*******************************************************************************
@@ -105,3 +122,30 @@
 **
 *******************************************************************************/
 tNFC_STATUS NFC_GetRouting(void) { return nci_snd_get_routing_cmd(); }
+
+/*******************************************************************************
+**
+** Function         NFC_NfceePLConfig
+**
+** Description      This function is called to set the Power and Link Control to
+**                  an NFCEE connected to the NFCC.
+**                  The response from NFCC is reported by tNFC_RESPONSE_CBACK
+**                  as NFC_NFCEE_PL_CONTROL_REVT.
+**
+** Parameters       nfcee_id - the NFCEE to activate or de-activate.
+**                  pl_config -
+**                   NFCEE_PL_CONFIG_NFCC_DECIDES  NFCC decides (default)
+**                   NFCEE_PL_CONFIG_PWR_ALWAYS_ON  NFCEE power supply is
+**                                                          always on
+**                   NFCEE_PL_CONFIG_LNK_ON_WHEN_PWR_ON  communication link is
+**                                       always active when NFCEE is powered on
+**                   NFCEE_PL_CONFIG_PWR_LNK_ALWAYS_ON  power supply and
+**                                       communication link are always on
+**
+** Returns          tNFC_STATUS
+**
+*******************************************************************************/
+tNFC_STATUS NFC_NfceePLConfig(uint8_t nfcee_id,
+                              tNCI_NFCEE_PL_CONFIG pl_config) {
+  return nci_snd_nfcee_power_link_control(nfcee_id, pl_config);
+}
diff --git a/src/nfc/nfc/nfc_main.c b/src/nfc/nfc/nfc_main.c
index 9eb147d..4b142d2 100644
--- a/src/nfc/nfc/nfc_main.c
+++ b/src/nfc/nfc/nfc_main.c
@@ -236,8 +236,21 @@
     p_cb->init_credits = p_cb->num_buff = 0;
     nfc_set_conn_id(p_cb, NFC_RF_CONN_ID);
     if (nfc_cb.nci_version == NCI_VERSION_2_0) {
-      evt_data.enable.hci_packet_size = *p++;
-      evt_data.enable.hci_conn_credits = *p++;
+      if (evt_data.enable.nci_features & NCI_FEAT_HCI_NETWORK) {
+        p_cb = &nfc_cb.conn_cb[NFC_HCI_CONN_ID];
+        nfc_set_conn_id(p_cb, NFC_HCI_CONN_ID);
+        p_cb->id = NFC_HCI_CONN_ID;
+        STREAM_TO_UINT8(p_cb->buff_size, p);
+        STREAM_TO_UINT8(p_cb->num_buff, p);
+        p_cb->init_credits = p_cb->num_buff;
+        evt_data.enable.hci_packet_size = p_cb->buff_size;
+        evt_data.enable.hci_conn_credits = p_cb->init_credits;
+        NFC_TRACE_DEBUG2("hci num_buf=%d buf_size=%d", p_cb->num_buff,
+                         p_cb->buff_size);
+      } else {
+        /*HCI n/w not enabled skip data buff size and data credit HCI conn */
+        p += 2;
+      }
       STREAM_TO_UINT16(evt_data.enable.max_nfc_v_size, p);
       STREAM_TO_UINT8(num_interfaces, p);
 #if (NFC_RW_ONLY == FALSE)
@@ -1326,6 +1339,34 @@
   return nci_snd_iso_dep_nak_presence_check_cmd();
 }
 
+/*******************************************************************************
+**
+** Function         NFC_SetStaticHciCback
+**
+** Description      This function is called to update the data callback function
+**                  to receive the data for the static Hci connection id.
+**
+** Parameters       p_cback - the connection callback function
+**
+** Returns          Nothing
+**
+*******************************************************************************/
+void NFC_SetStaticHciCback(tNFC_CONN_CBACK* p_cback) {
+  NFC_TRACE_DEBUG2("%s dest: %d", __func__, NCI_DEST_TYPE_NFCEE);
+  tNFC_CONN_CB* p_cb = &nfc_cb.conn_cb[NFC_HCI_CONN_ID];
+  tNFC_CONN evt_data;
+
+  p_cb->p_cback = p_cback;
+  if (p_cback && p_cb->buff_size && p_cb->num_buff) {
+    NFC_TRACE_DEBUG2("%s dest: %d", __func__, NCI_DEST_TYPE_NFCEE);
+    evt_data.conn_create.status = NFC_STATUS_OK;
+    evt_data.conn_create.dest_type = NCI_DEST_TYPE_NFCEE;
+    evt_data.conn_create.id = p_cb->id;
+    evt_data.conn_create.buff_size = p_cb->buff_size;
+    evt_data.conn_create.num_buffs = p_cb->num_buff;
+    (*p_cback)(NFC_HCI_CONN_ID, NFC_CONN_CREATE_CEVT, &evt_data);
+  }
+}
 #if (BT_TRACE_VERBOSE == TRUE)
 /*******************************************************************************
 **
diff --git a/src/nfc/nfc/nfc_ncif.cc b/src/nfc/nfc/nfc_ncif.cc
index 47f49e2..7df175a 100644
--- a/src/nfc/nfc/nfc_ncif.cc
+++ b/src/nfc/nfc/nfc_ncif.cc
@@ -1659,3 +1659,25 @@
   NFC_TRACE_DEBUG2("%s: exit status=%u", __func__, stat);
   return stat;
 }
+
+/*******************************************************************************
+** Function         nfc_mode_set_ntf_timeout
+**
+** Description      This function is invoked on mode set ntf timeout
+**
+** Returns          void
+**
+*******************************************************************************/
+void nfc_mode_set_ntf_timeout() {
+  NFC_TRACE_ERROR1("%s", __func__);
+  tNFC_NFCEE_MODE_SET_REVT mode_set_info;
+  mode_set_info.status = NCI_STATUS_FAILED;
+  mode_set_info.nfcee_id = *nfc_cb.last_cmd;
+  mode_set_info.mode = NCI_NFCEE_MD_DEACTIVATE;
+
+  tNFC_RESPONSE* p_evt = (tNFC_RESPONSE*)&mode_set_info;
+
+  tNFC_RESPONSE_CBACK* p_cback = nfc_cb.p_resp_cback;
+  tNFC_RESPONSE_EVT event = NFC_NFCEE_MODE_SET_REVT;
+  if (p_cback) (*p_cback)(event, p_evt);
+}
diff --git a/src/nfc/nfc/nfc_task.c b/src/nfc/nfc/nfc_task.c
index 3cd9c7a..dc008f9 100644
--- a/src/nfc/nfc/nfc_task.c
+++ b/src/nfc/nfc/nfc_task.c
@@ -118,7 +118,9 @@
       case NFC_TTYPE_WAIT_2_DEACTIVATE:
         nfc_wait_2_deactivate_timeout();
         break;
-
+      case NFC_TTYPE_WAIT_MODE_SET_NTF:
+        nfc_mode_set_ntf_timeout();
+        break;
       default:
         NFC_TRACE_DEBUG2("nfc_process_timer_evt: timer:0x%x event (0x%04x)",
                          p_tle, p_tle->event);