summaryrefslogtreecommitdiffstats
path: root/halimpl/bcm2079x/hal
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2012-12-13 14:55:37 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2012-12-13 14:55:37 -0800
commite9df6ba5a8fcccf306a80b1670b423be8fe7746a (patch)
tree2db644956baf1d1f764d6ffcfbe2d0d727cfbffe /halimpl/bcm2079x/hal
downloadandroid_hardware_broadcom_nfc-e9df6ba5a8fcccf306a80b1670b423be8fe7746a.tar.gz
android_hardware_broadcom_nfc-e9df6ba5a8fcccf306a80b1670b423be8fe7746a.tar.bz2
android_hardware_broadcom_nfc-e9df6ba5a8fcccf306a80b1670b423be8fe7746a.zip
Snapshot 7ddd630e136a035ba463c427285c5c3e9f199ee0
Change-Id: If08c7b905da667dd9e5110231e4592842b634006
Diffstat (limited to 'halimpl/bcm2079x/hal')
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_api.c288
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_brcm.c29
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_dm.c1092
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_dm_cfg.c133
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_hci.c441
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_hci_ci.c88
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_main.c596
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_nci.c871
-rw-r--r--halimpl/bcm2079x/hal/hal/nfc_hal_prm.c1119
-rw-r--r--halimpl/bcm2079x/hal/include/gki_hal_target.h255
-rw-r--r--halimpl/bcm2079x/hal/include/nci_defs.h851
-rw-r--r--halimpl/bcm2079x/hal/include/nfc_hal_api.h223
-rw-r--r--halimpl/bcm2079x/hal/include/nfc_hal_target.h244
-rw-r--r--halimpl/bcm2079x/hal/include/nfc_types.h147
-rw-r--r--halimpl/bcm2079x/hal/int/nfc_brcm_defs.h239
-rw-r--r--halimpl/bcm2079x/hal/int/nfc_hal_int.h473
-rw-r--r--halimpl/bcm2079x/hal/int/nfc_hal_int_api.h293
-rw-r--r--halimpl/bcm2079x/hal/int/nfc_hal_nv_ci.h88
-rw-r--r--halimpl/bcm2079x/hal/int/nfc_hal_nv_co.h108
-rw-r--r--halimpl/bcm2079x/hal/int/nfc_hal_post_reset.h66
20 files changed, 7644 insertions, 0 deletions
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_api.c b/halimpl/bcm2079x/hal/hal/nfc_hal_api.c
new file mode 100644
index 0000000..06c970c
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_api.c
@@ -0,0 +1,288 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * NFC Hardware Abstraction Layer API: Implementation for Broadcom NFC
+ * controllers
+ *
+ ******************************************************************************/
+#include "gki.h"
+#include "nfc_hal_target.h"
+#include "nfc_hal_api.h"
+#include "nfc_hal_int.h"
+
+/*******************************************************************************
+** NFC_HAL_TASK declarations
+*******************************************************************************/
+#define NFC_HAL_TASK_STR ((INT8 *) "NFC_HAL_TASK")
+#define NFC_HAL_TASK_STACK_SIZE 0x400
+UINT32 nfc_hal_task_stack[(NFC_HAL_TASK_STACK_SIZE+3)/4];
+
+/*******************************************************************************
+**
+** Function HAL_NfcInitialize
+**
+** Description Called when HAL library is loaded.
+**
+** Initialize GKI and start the HCIT task
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcInitialize (void)
+{
+ NCI_TRACE_API0 ("HAL_NfcInitialize ()");
+
+ /* Initialize HAL control block */
+ nfc_hal_main_init ();
+
+ /* Initialize OS */
+ GKI_init ();
+
+ /* Enable interrupts */
+ GKI_enable ();
+
+ /* Create the NCI transport task */
+ GKI_create_task ((TASKPTR)nfc_hal_main_task,
+ NFC_HAL_TASK,
+ NFC_HAL_TASK_STR,
+ (UINT16 *) ((UINT8 *)nfc_hal_task_stack + NFC_HAL_TASK_STACK_SIZE),
+ sizeof(nfc_hal_task_stack), NULL, NULL);
+
+ /* Start tasks */
+ GKI_run (0);
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcTerminate
+**
+** Description Called to terminate NFC HAL
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcTerminate(void)
+{
+ NCI_TRACE_API0 ("HAL_NfcTerminate ()");
+}
+
+
+/*******************************************************************************
+**
+** Function HAL_NfcOpen
+**
+** Description Open transport and intialize the NFCC, and
+** Register callback for HAL event notifications,
+**
+** HAL_OPEN_CPLT_EVT will notify when operation is complete.
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback)
+{
+ NCI_TRACE_API0 ("HAL_NfcOpen ()");
+
+ /* Only handle if HAL is not opened (stack cback is NULL) */
+ if (p_hal_cback)
+ {
+ nfc_hal_dm_init ();
+ nfc_hal_cb.p_stack_cback = p_hal_cback;
+ nfc_hal_cb.p_data_cback = p_data_cback;
+
+ /* Send startup event to NFC_HAL_TASK */
+ GKI_send_event (NFC_HAL_TASK, NFC_HAL_TASK_EVT_INITIALIZE);
+ }
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcClose
+**
+** Description Prepare for shutdown. A HAL_CLOSE_DONE_EVENT will be
+** reported when complete.
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcClose (void)
+{
+ NCI_TRACE_API0 ("HAL_NfcClose ()");
+
+ /* Only handle if HAL is opened (stack cback is not-NULL) */
+ if (nfc_hal_cb.p_stack_cback)
+ {
+ /* Send shutdown event to NFC_HAL_TASK */
+ GKI_send_event (NFC_HAL_TASK, NFC_HAL_TASK_EVT_TERMINATE);
+ }
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcCoreInitialized
+**
+** Description Called after the CORE_INIT_RSP is received from the NFCC.
+** At this time, the HAL can do any chip-specific configuration,
+** and when finished signal the libnfc-nci with event
+** HAL_POST_INIT_DONE.
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcCoreInitialized (UINT8 *p_core_init_rsp_params)
+{
+ NFC_HDR *p_msg;
+ UINT16 size;
+
+ NCI_TRACE_API0 ("HAL_NfcCoreInitialized ()");
+
+ /* NCI payload len + NCI header size */
+ size = p_core_init_rsp_params[2] + NCI_MSG_HDR_SIZE;
+
+ /* Send message to NFC_HAL_TASK */
+ if ((p_msg = (NFC_HDR *)GKI_getbuf ((UINT16)(size + NFC_HDR_SIZE))) != NULL)
+ {
+ p_msg->event = NFC_HAL_EVT_POST_CORE_RESET;
+ p_msg->offset = 0;
+ p_msg->len = size;
+ p_msg->layer_specific = 0;
+ memcpy ((UINT8 *)(p_msg + 1) + p_msg->offset, p_core_init_rsp_params, size);
+
+ GKI_send_msg (NFC_HAL_TASK, NFC_HAL_TASK_MBOX, p_msg);
+ }
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcWrite
+**
+** Description Send an NCI control message or data packet to the
+** transport. If an NCI command message exceeds the transport
+** size, HAL is responsible for fragmenting it, Data packets
+** must be of the correct size.
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcWrite (UINT16 data_len, UINT8 *p_data)
+{
+ NFC_HDR *p_msg;
+ UINT8 mt;
+
+ NCI_TRACE_API0 ("HAL_NfcWrite ()");
+
+ if (data_len > (NCI_MAX_CTRL_SIZE + NCI_MSG_HDR_SIZE))
+ {
+ NCI_TRACE_ERROR1 ("HAL_NfcWrite (): too many bytes (%d)", data_len);
+ return;
+ }
+
+ /* Send message to NFC_HAL_TASK */
+ if ((p_msg = (NFC_HDR *)GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
+ {
+ p_msg->event = NFC_HAL_EVT_TO_NFC_NCI;
+ p_msg->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE;
+ p_msg->len = data_len;
+ memcpy ((UINT8 *)(p_msg+1) + p_msg->offset, p_data, data_len);
+
+ /* Check if message is a command or data */
+ mt = (*(p_data) & NCI_MT_MASK) >> NCI_MT_SHIFT;
+ p_msg->layer_specific = (mt == NCI_MT_CMD) ? NFC_HAL_WAIT_RSP_CMD : 0;
+
+
+ GKI_send_msg (NFC_HAL_TASK, NFC_HAL_TASK_MBOX, p_msg);
+ }
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcPreDiscover
+**
+** Description Perform any vendor-specific pre-discovery actions (if needed)
+** If any actions were performed TRUE will be returned, and
+** HAL_PRE_DISCOVER_DONE_EVENT will notify when actions are
+** completed.
+**
+** Returns TRUE if vendor-specific pre-discovery actions initialized
+** FALSE if no vendor-specific pre-discovery actions are needed.
+**
+*******************************************************************************/
+BOOLEAN HAL_NfcPreDiscover (void)
+{
+ BOOLEAN status = FALSE;
+
+ NCI_TRACE_API1 ("HAL_NfcPreDiscover status:%d", status);
+ return status;
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcControlGranted
+**
+** Description Grant control to HAL control for sending NCI commands.
+**
+** Call in response to HAL_REQUEST_CONTROL_EVENT.
+**
+** Must only be called when there are no NCI commands pending.
+**
+** HAL_RELEASE_CONTROL_EVENT will notify when HAL no longer
+** needs control of NCI.
+**
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcControlGranted (void)
+{
+ NFC_HDR *p_msg;
+ NCI_TRACE_API0 ("HAL_NfcControlGranted ()");
+
+ /* Send message to NFC_HAL_TASK */
+ if ((p_msg = (NFC_HDR *)GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
+ {
+ p_msg->event = NFC_HAL_EVT_CONTROL_GRANTED;
+ GKI_send_msg (NFC_HAL_TASK, NFC_HAL_TASK_MBOX, p_msg);
+ }
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcPowerCycle
+**
+** Description Restart NFCC by power cyle
+**
+** HAL_OPEN_CPLT_EVT will notify when operation is complete.
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcPowerCycle (void)
+{
+ NCI_TRACE_API0 ("HAL_NfcPowerCycle ()");
+
+ /* Only handle if HAL is opened (stack cback is not-NULL) */
+ if (nfc_hal_cb.p_stack_cback)
+ {
+ /* Send power cycle event to NFC_HAL_TASK */
+ GKI_send_event (NFC_HAL_TASK, NFC_HAL_TASK_EVT_POWER_CYCLE);
+ }
+}
+
+
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_brcm.c b/halimpl/bcm2079x/hal/hal/nfc_hal_brcm.c
new file mode 100644
index 0000000..d52119a
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_brcm.c
@@ -0,0 +1,29 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2010-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains function of the NFC unit to receive/process NFC VS
+ * commands.
+ *
+ ******************************************************************************/
+#include <string.h>
+#include "gki.h"
+#include "nfc_hal_int.h"
+#include "userial.h"
+
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_dm.c b/halimpl/bcm2079x/hal/hal/nfc_hal_dm.c
new file mode 100644
index 0000000..c4d4a3f
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_dm.c
@@ -0,0 +1,1092 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Vendor-specific handler for DM events
+ *
+ ******************************************************************************/
+#include "nfc_hal_int.h"
+#include "nfc_hal_post_reset.h"
+#include "userial.h"
+#include "upio.h"
+
+/*****************************************************************************
+** Constants and types
+*****************************************************************************/
+
+#define NFC_HAL_I93_RW_CFG_LEN (5)
+#define NFC_HAL_I93_RW_CFG_PARAM_LEN (3)
+#define NFC_HAL_I93_AFI (0)
+#define NFC_HAL_I93_ENABLE_SMART_POLL (1)
+
+static UINT8 nfc_hal_dm_i93_rw_cfg[NFC_HAL_I93_RW_CFG_LEN] =
+{
+ NCI_PARAM_ID_I93_DATARATE,
+ NFC_HAL_I93_RW_CFG_PARAM_LEN,
+ NFC_HAL_I93_FLAG_DATA_RATE, /* Bit0:Sub carrier, Bit1:Data rate, Bit4:Enable/Disable AFI */
+ NFC_HAL_I93_AFI, /* AFI if Bit 4 is set in the flag byte */
+ NFC_HAL_I93_ENABLE_SMART_POLL /* Bit0:Enable/Disable smart poll */
+};
+
+static UINT8 nfc_hal_dm_set_fw_fsm_cmd[NCI_MSG_HDR_SIZE + 1] =
+{
+ NCI_MTS_CMD|NCI_GID_PROP,
+ NCI_MSG_SET_FWFSM,
+ 0x01,
+ 0x00,
+};
+#define NCI_SET_FWFSM_OFFSET_ENABLE 3
+
+const UINT8 nfc_hal_dm_core_reset_cmd[NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET] =
+{
+ NCI_MTS_CMD|NCI_GID_CORE,
+ NCI_MSG_CORE_RESET,
+ NCI_CORE_PARAM_SIZE_RESET,
+ NCI_RESET_TYPE_RESET_CFG
+};
+
+#define NCI_PROP_PARAM_SIZE_XTAL_INDEX 3 /* length of parameters in XTAL_INDEX CMD */
+
+const UINT8 nfc_hal_dm_get_build_info_cmd[NCI_MSG_HDR_SIZE] =
+{
+ NCI_MTS_CMD|NCI_GID_PROP,
+ NCI_MSG_GET_BUILD_INFO,
+ 0x00
+};
+#define NCI_BUILD_INFO_OFFSET_HWID 25 /* HW ID offset in build info RSP */
+
+const UINT8 nfc_hal_dm_get_patch_version_cmd [NCI_MSG_HDR_SIZE] =
+{
+ NCI_MTS_CMD|NCI_GID_PROP,
+ NCI_MSG_GET_PATCH_VERSION,
+ 0x00
+};
+#define NCI_PATCH_INFO_OFFSET_NVMTYPE 35 /* NVM Type offset in patch info RSP */
+
+/*****************************************************************************
+** Extern function prototypes
+*****************************************************************************/
+extern UINT8 *p_nfc_hal_dm_lptd_cfg;
+extern UINT8 *p_nfc_hal_dm_pll_325_cfg;
+extern UINT8 *p_nfc_hal_dm_start_up_cfg;
+extern UINT8 *p_nfc_hal_dm_start_up_vsc_cfg;
+
+/*****************************************************************************
+** Local function prototypes
+*****************************************************************************/
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_set_config
+**
+** Description Send NCI config items to NFCC
+**
+** Returns tHAL_NFC_STATUS
+**
+*******************************************************************************/
+tHAL_NFC_STATUS nfc_hal_dm_set_config (UINT8 tlv_size,
+ UINT8 *p_param_tlvs,
+ tNFC_HAL_NCI_CBACK *p_cback)
+{
+ UINT8 *p_buff, *p;
+ UINT8 num_param = 0, param_len, rem_len, *p_tlv;
+ UINT16 cmd_len = NCI_MSG_HDR_SIZE + tlv_size + 1;
+ tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED;
+
+ if ((tlv_size == 0)||(p_param_tlvs == NULL))
+ {
+ return status;
+ }
+
+ if ((p_buff = (UINT8 *) GKI_getbuf ((UINT16)(NCI_MSG_HDR_SIZE + tlv_size))) != NULL)
+ {
+ p = p_buff;
+
+ NCI_MSG_BLD_HDR0 (p, NCI_MT_CMD, NCI_GID_CORE);
+ NCI_MSG_BLD_HDR1 (p, NCI_MSG_CORE_SET_CONFIG);
+ UINT8_TO_STREAM (p, (UINT8) (tlv_size + 1));
+
+ rem_len = tlv_size;
+ p_tlv = p_param_tlvs;
+ while (rem_len > 1)
+ {
+ num_param++; /* number of params */
+
+ p_tlv ++; /* param type */
+ param_len = *p_tlv++; /* param length */
+
+ rem_len -= 2; /* param type and length */
+ if (rem_len >= param_len)
+ {
+ rem_len -= param_len;
+ p_tlv += param_len; /* next param_type */
+
+ if (rem_len == 0)
+ {
+ status = HAL_NFC_STATUS_OK;
+ break;
+ }
+ }
+ else
+ {
+ /* error found */
+ break;
+ }
+ }
+
+ if (status == HAL_NFC_STATUS_OK)
+ {
+ UINT8_TO_STREAM (p, num_param);
+ ARRAY_TO_STREAM (p, p_param_tlvs, tlv_size);
+
+ nfc_hal_dm_send_nci_cmd (p_buff, cmd_len, p_cback);
+ }
+ else
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_dm_set_config ():Bad TLV");
+ }
+
+ GKI_freebuf (p_buff);
+ }
+
+ return status;
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_get_xtal_index
+**
+** Description Convert xtal frequency to index
+**
+** Returns xtal index
+**
+*******************************************************************************/
+static tNFC_HAL_XTAL_INDEX nfc_hal_dm_get_xtal_index (UINT16 xtal_freq)
+{
+ tNFC_HAL_XTAL_INDEX xtal_index;
+
+ switch (xtal_freq)
+ {
+ case 9600: xtal_index = NFC_HAL_XTAL_INDEX_9600; break;
+ case 13000: xtal_index = NFC_HAL_XTAL_INDEX_13000; break;
+ case 16200: xtal_index = NFC_HAL_XTAL_INDEX_16200; break;
+ case 19200: xtal_index = NFC_HAL_XTAL_INDEX_19200; break;
+ case 24000: xtal_index = NFC_HAL_XTAL_INDEX_24000; break;
+ case 26000: xtal_index = NFC_HAL_XTAL_INDEX_26000; break;
+ case 38400: xtal_index = NFC_HAL_XTAL_INDEX_38400; break;
+ case 52000: xtal_index = NFC_HAL_XTAL_INDEX_52000; break;
+ case 37400: xtal_index = NFC_HAL_XTAL_INDEX_37400; break;
+ default : xtal_index = NFC_HAL_XTAL_INDEX_MAX;
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_get_xtal_index ():No matched index for %d", xtal_freq);
+ break;
+ }
+
+ return xtal_index;
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_set_fw_fsm
+**
+** Description Enable or disable FW FSM
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_set_fw_fsm (BOOLEAN enable, tNFC_HAL_NCI_CBACK *p_cback)
+{
+ if (enable)
+ nfc_hal_dm_set_fw_fsm_cmd[NCI_SET_FWFSM_OFFSET_ENABLE] = 0x01; /* Enable, default is disabled */
+ else
+ nfc_hal_dm_set_fw_fsm_cmd[NCI_SET_FWFSM_OFFSET_ENABLE] = 0x00; /* Disable */
+
+ nfc_hal_dm_send_nci_cmd (nfc_hal_dm_set_fw_fsm_cmd, NCI_MSG_HDR_SIZE + 1, p_cback);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_config_nfcc_cback
+**
+** Description Callback for NCI vendor specific command complete
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_config_nfcc_cback (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data)
+{
+ if (nfc_hal_cb.dev_cb.next_dm_config == NFC_HAL_DM_CONFIG_NONE)
+ {
+ nfc_hal_hci_enable ();
+ }
+ else
+ {
+ nfc_hal_dm_config_nfcc ();
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_send_startup_vsc
+**
+** Description Send VS command before NFA start-up
+**
+** Returns None
+**
+*******************************************************************************/
+void nfc_hal_dm_send_startup_vsc (void)
+{
+ UINT8 *p, *p_end;
+ UINT16 len;
+
+ NCI_TRACE_DEBUG0 ("nfc_hal_dm_send_startup_vsc ()");
+
+ /* VSC must have NCI header at least */
+ if (nfc_hal_cb.dev_cb.next_startup_vsc + NCI_MSG_HDR_SIZE - 1 <= *p_nfc_hal_dm_start_up_vsc_cfg)
+ {
+ p = p_nfc_hal_dm_start_up_vsc_cfg + nfc_hal_cb.dev_cb.next_startup_vsc;
+ len = *(p + 2);
+ p_end = p + NCI_MSG_HDR_SIZE - 1 + len;
+
+ if (p_end <= p_nfc_hal_dm_start_up_vsc_cfg + *p_nfc_hal_dm_start_up_vsc_cfg)
+ {
+ /* move to next VSC */
+ nfc_hal_cb.dev_cb.next_startup_vsc += NCI_MSG_HDR_SIZE + len;
+
+ /* if this is last VSC */
+ if (p_end == p_nfc_hal_dm_start_up_vsc_cfg + *p_nfc_hal_dm_start_up_vsc_cfg)
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_NONE;
+
+ nfc_hal_dm_send_nci_cmd (p, (UINT16)(NCI_MSG_HDR_SIZE + len), nfc_hal_dm_config_nfcc_cback);
+ return;
+ }
+ }
+
+ NCI_TRACE_ERROR0 ("nfc_hal_dm_send_startup_vsc (): Bad start-up VSC");
+
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_config_nfcc
+**
+** Description Send VS config before NFA start-up
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_config_nfcc (void)
+{
+ UINT8 *p;
+ UINT8 xtal_index;
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_config_nfcc (): next_dm_config = %d", nfc_hal_cb.dev_cb.next_dm_config);
+
+ if ((p_nfc_hal_dm_lptd_cfg[0]) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_LPTD))
+ {
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_PLL_325;
+
+ if (nfc_hal_dm_set_config (p_nfc_hal_dm_lptd_cfg[0],
+ &p_nfc_hal_dm_lptd_cfg[1],
+ nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
+ {
+ return;
+ }
+ else
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
+ return;
+ }
+ }
+
+ if ((p_nfc_hal_dm_pll_325_cfg) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_PLL_325))
+ {
+ xtal_index = nfc_hal_dm_get_xtal_index (nfc_post_reset_cb.dev_init_config.xtal_freq);
+ if (xtal_index < NFC_HAL_XTAL_INDEX_MAX)
+ {
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_START_UP;
+ p = p_nfc_hal_dm_pll_325_cfg + (xtal_index * NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN);
+ if (nfc_hal_dm_set_config (NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN,
+ p,
+ nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
+ {
+ return;
+ }
+ else
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
+ return;
+ }
+ }
+ }
+
+ if ((p_nfc_hal_dm_start_up_cfg[0]) && (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_START_UP))
+ {
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_I93_DATA_RATE;
+ if (nfc_hal_dm_set_config (p_nfc_hal_dm_start_up_cfg[0],
+ &p_nfc_hal_dm_start_up_cfg[1],
+ nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
+ {
+ return;
+ }
+ else
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
+ return;
+ }
+ }
+
+#if (NFC_HAL_I93_FLAG_DATA_RATE == NFC_HAL_I93_FLAG_DATA_RATE_HIGH)
+ if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_I93_DATA_RATE)
+ {
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_FW_FSM;
+ if (nfc_hal_dm_set_config (NFC_HAL_I93_RW_CFG_LEN,
+ nfc_hal_dm_i93_rw_cfg,
+ nfc_hal_dm_config_nfcc_cback) == HAL_NFC_STATUS_OK)
+ {
+ return;
+ }
+ else
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_FAILED);
+ return;
+ }
+ }
+#endif
+
+ /* FW FSM is disabled as default in NFCC */
+ if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_FW_FSM)
+ {
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_START_UP_VSC;
+ nfc_hal_dm_set_fw_fsm (NFC_HAL_DM_MULTI_TECH_RESP, nfc_hal_dm_config_nfcc_cback);
+ return;
+ }
+
+ if (nfc_hal_cb.dev_cb.next_dm_config <= NFC_HAL_DM_CONFIG_START_UP_VSC)
+ {
+ if (p_nfc_hal_dm_start_up_vsc_cfg && *p_nfc_hal_dm_start_up_vsc_cfg)
+ {
+ nfc_hal_dm_send_startup_vsc ();
+ return;
+ }
+ }
+
+ /* nothing to config */
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_NONE;
+ nfc_hal_dm_config_nfcc_cback (0, 0, NULL);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_set_xtal_freq_index
+**
+** Description Set crystal frequency index
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_set_xtal_freq_index (void)
+{
+ UINT8 nci_brcm_xtal_index_cmd[NCI_MSG_HDR_SIZE + NCI_PROP_PARAM_SIZE_XTAL_INDEX];
+ UINT8 *p;
+ tNFC_HAL_XTAL_INDEX xtal_index;
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_set_xtal_freq_index (): xtal_freq = %d", nfc_post_reset_cb.dev_init_config.xtal_freq);
+
+ xtal_index = nfc_hal_dm_get_xtal_index (nfc_post_reset_cb.dev_init_config.xtal_freq);
+
+ switch (xtal_index)
+ {
+ case NFC_HAL_XTAL_INDEX_9600:
+ case NFC_HAL_XTAL_INDEX_13000:
+ case NFC_HAL_XTAL_INDEX_19200:
+ case NFC_HAL_XTAL_INDEX_26000:
+ case NFC_HAL_XTAL_INDEX_38400:
+ case NFC_HAL_XTAL_INDEX_52000:
+
+ {
+ /* no need to set xtal index for these frequency */
+ NCI_TRACE_DEBUG0 ("nfc_hal_dm_set_xtal_freq_index (): no need to set xtal index");
+
+ nfc_post_reset_cb.dev_init_config.flags &= ~NFC_HAL_DEV_INIT_FLAGS_SET_XTAL_FREQ;
+ nfc_hal_dm_send_reset_cmd ();
+ return;
+ }
+ break;
+ }
+
+ p = nci_brcm_xtal_index_cmd;
+ UINT8_TO_STREAM (p, (NCI_MTS_CMD|NCI_GID_PROP));
+ UINT8_TO_STREAM (p, NCI_MSG_GET_XTAL_INDEX_FROM_DH);
+ UINT8_TO_STREAM (p, NCI_PROP_PARAM_SIZE_XTAL_INDEX);
+ UINT8_TO_STREAM (p, xtal_index);
+ UINT16_TO_STREAM (p, nfc_post_reset_cb.dev_init_config.xtal_freq);
+
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_XTAL_SET);
+
+ nfc_hal_dm_send_nci_cmd (nci_brcm_xtal_index_cmd, NCI_MSG_HDR_SIZE + NCI_PROP_PARAM_SIZE_XTAL_INDEX, NULL);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_send_reset_cmd
+**
+** Description Send CORE RESET CMD
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_send_reset_cmd (void)
+{
+ /* Proceed with start up sequence: send CORE_RESET_CMD */
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_RESET);
+
+ nfc_hal_dm_send_nci_cmd (nfc_hal_dm_core_reset_cmd, NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET, NULL);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_proc_msg_during_init
+**
+** Description Process NCI message while initializing NFCC
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_proc_msg_during_init (NFC_HDR *p_msg)
+{
+ UINT8 *p;
+ UINT8 reset_reason, reset_type;
+ UINT8 mt, pbf, gid, op_code;
+ UINT8 *p_old, old_gid, old_oid, old_mt;
+ tNFC_HAL_NCI_CBACK *p_cback = NULL;
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_proc_msg_during_init(): init state:%d", nfc_hal_cb.dev_cb.initializing_state);
+
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+
+ NCI_MSG_PRS_HDR0 (p, mt, pbf, gid);
+ NCI_MSG_PRS_HDR1 (p, op_code);
+
+ /* check if waiting for this response */
+ if ( (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_CMD)
+ ||(nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_VSC) )
+ {
+ if (mt == NCI_MT_RSP)
+ {
+ p_old = nfc_hal_cb.ncit_cb.last_hdr;
+ NCI_MSG_PRS_HDR0 (p_old, old_mt, pbf, old_gid);
+ old_oid = ((*p_old) & NCI_OID_MASK);
+ /* make sure this is the RSP we are waiting for before updating the command window */
+ if ((old_gid == gid) && (old_oid == op_code))
+ {
+ nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE;
+ p_cback = (tNFC_HAL_NCI_CBACK *)nfc_hal_cb.ncit_cb.p_vsc_cback;
+ nfc_hal_cb.ncit_cb.p_vsc_cback = NULL;
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer);
+ }
+ }
+ }
+
+ if (gid == NCI_GID_CORE)
+ {
+ if (op_code == NCI_MSG_CORE_RESET)
+ {
+ if (mt == NCI_MT_RSP)
+ {
+ if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_RE_INIT)
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_APP_COMPLETE);
+ nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, nfc_hal_cb.p_reinit_cback);
+ }
+ else
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_BUILD_INFO);
+
+ /* get build information to find out HW */
+ nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_build_info_cmd, NCI_MSG_HDR_SIZE, NULL);
+ }
+ }
+ else
+ {
+ /* Call reset notification callback */
+ p++; /* Skip over param len */
+ STREAM_TO_UINT8 (reset_reason, p);
+ STREAM_TO_UINT8 (reset_type, p);
+ nfc_hal_prm_spd_reset_ntf (reset_reason, reset_type);
+ }
+ }
+ else if (p_cback)
+ {
+ (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code),
+ p_msg->len,
+ (UINT8 *) (p_msg + 1) + p_msg->offset);
+ }
+ }
+ else if (gid == NCI_GID_PROP) /* this is for download patch */
+ {
+ if (mt == NCI_MT_NTF)
+ op_code |= NCI_NTF_BIT;
+ else
+ op_code |= NCI_RSP_BIT;
+
+ if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_XTAL_SET)
+ {
+ if (op_code == (NCI_RSP_BIT|NCI_MSG_GET_XTAL_INDEX_FROM_DH))
+ {
+ /* wait for crystal setting in NFCC */
+ GKI_delay (100);
+
+ /* Crytal frequency configured. Proceed with start up sequence: send CORE_RESET_CMD */
+ nfc_hal_dm_send_reset_cmd ();
+ }
+ }
+ else if ( (op_code == NFC_VS_GET_BUILD_INFO_EVT)
+ &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_BUILD_INFO) )
+ {
+ p += NCI_BUILD_INFO_OFFSET_HWID;
+
+ STREAM_TO_UINT32 (nfc_hal_cb.dev_cb.brcm_hw_id, p);
+
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_PATCH_INFO);
+
+ nfc_hal_dm_send_nci_cmd (nfc_hal_dm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, NULL);
+ }
+ else if ( (op_code == NFC_VS_GET_PATCH_VERSION_EVT)
+ &&(nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_PATCH_INFO) )
+ {
+ p += NCI_PATCH_INFO_OFFSET_NVMTYPE;
+
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_APP_COMPLETE);
+
+ /* let platform update baudrate or download patch */
+ nfc_hal_post_reset_init (nfc_hal_cb.dev_cb.brcm_hw_id, *p);
+ }
+ else if (p_cback)
+ {
+ (*p_cback) ((tNFC_HAL_NCI_EVT) (op_code),
+ p_msg->len,
+ (UINT8 *) (p_msg + 1) + p_msg->offset);
+ }
+ else if (op_code == NFC_VS_SEC_PATCH_AUTH_EVT)
+ {
+ NCI_TRACE_DEBUG0 ("signature!!");
+ nfc_hal_prm_nci_command_complete_cback ((tNFC_HAL_NCI_EVT) (op_code),
+ p_msg->len,
+ (UINT8 *) (p_msg + 1) + p_msg->offset);
+ }
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_send_nci_cmd
+**
+** Description Send NCI command to NFCC while initializing BRCM NFCC
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_send_nci_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_NCI_CBACK *p_cback)
+{
+ NFC_HDR *p_buf;
+ UINT8 *ps;
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_send_nci_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp);
+
+ if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE)
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_dm_send_nci_cmd(): no command window");
+ return;
+ }
+
+ if ((p_buf = (NFC_HDR *)GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
+ {
+ nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_VSC;
+
+ p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE;
+ p_buf->event = NFC_HAL_EVT_TO_NFC_NCI;
+ p_buf->len = len;
+
+ memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len);
+
+ /* Keep a copy of the command and send to NCI transport */
+
+ /* save the message header to double check the response */
+ ps = (UINT8 *)(p_buf + 1) + p_buf->offset;
+ memcpy(nfc_hal_cb.ncit_cb.last_hdr, ps, NFC_HAL_SAVED_HDR_SIZE);
+ memcpy(nfc_hal_cb.ncit_cb.last_cmd, ps + NCI_MSG_HDR_SIZE, NFC_HAL_SAVED_CMD_SIZE);
+
+ /* save the callback for NCI VSCs */
+ nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback;
+
+ nfc_hal_nci_send_cmd (p_buf);
+
+ /* start NFC command-timeout timer */
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP),
+ ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_send_pend_cmd
+**
+** Description Send a command to NFCC
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_send_pend_cmd (void)
+{
+ NFC_HDR *p_buf = nfc_hal_cb.ncit_cb.p_pend_cmd;
+ UINT8 *p;
+
+ if (p_buf == NULL)
+ return;
+
+ /* check low power mode state */
+ if (!nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TX_DATA_EVT))
+ {
+ return;
+ }
+
+ if (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_PROP)
+ {
+#if (NFC_HAL_TRACE_PROTOCOL == TRUE)
+ DispHciCmd (p_buf);
+#endif
+
+ /* save the message header to double check the response */
+ p = (UINT8 *)(p_buf + 1) + p_buf->offset;
+ memcpy(nfc_hal_cb.ncit_cb.last_hdr, p, NFC_HAL_SAVED_HDR_SIZE);
+
+ /* add packet type for BT message */
+ p_buf->offset--;
+ p_buf->len++;
+
+ p = (UINT8 *) (p_buf + 1) + p_buf->offset;
+ *p = HCIT_TYPE_COMMAND;
+
+ USERIAL_Write (USERIAL_NFC_PORT, p, p_buf->len);
+
+ GKI_freebuf (p_buf);
+ nfc_hal_cb.ncit_cb.p_pend_cmd = NULL;
+
+ /* start NFC command-timeout timer */
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer, (UINT16)(NFC_HAL_TTYPE_NCI_WAIT_RSP),
+ ((UINT32) NFC_HAL_CMD_TOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
+
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_send_bt_cmd
+**
+** Description Send BT message to NFCC while initializing BRCM NFCC
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_send_bt_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_BTVSC_CPLT_CBACK *p_cback)
+{
+ NFC_HDR *p_buf;
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_send_bt_cmd (): nci_wait_rsp = 0x%x", nfc_hal_cb.ncit_cb.nci_wait_rsp);
+
+ if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE)
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_dm_send_bt_cmd(): no command window");
+ return;
+ }
+
+ if ((p_buf = (NFC_HDR *) GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
+ {
+ nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_PROP;
+
+ p_buf->offset = NFC_HAL_NCI_MSG_OFFSET_SIZE;
+ p_buf->len = len;
+
+ memcpy ((UINT8*) (p_buf + 1) + p_buf->offset, p_data, len);
+
+ /* save the callback for NCI VSCs) */
+ nfc_hal_cb.ncit_cb.p_vsc_cback = (void *)p_cback;
+
+ nfc_hal_cb.ncit_cb.p_pend_cmd = p_buf;
+ if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_IDLE)
+ {
+ NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_W4_CONTROL_DONE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_REQUEST_CONTROL_EVT, HAL_NFC_STATUS_OK);
+ return;
+ }
+
+ nfc_hal_dm_send_pend_cmd();
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_set_nfc_wake
+**
+** Description Set NFC_WAKE line
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_set_nfc_wake (UINT8 cmd)
+{
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_set_nfc_wake () %s",
+ (cmd == NFC_HAL_ASSERT_NFC_WAKE ? "ASSERT" : "DEASSERT"));
+
+ /*
+ ** nfc_wake_active_mode cmd result of voltage on NFC_WAKE
+ **
+ ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_ASSERT_NFC_WAKE (0) pull down NFC_WAKE (GND)
+ ** NFC_HAL_LP_ACTIVE_LOW (0) NFC_HAL_DEASSERT_NFC_WAKE (1) pull up NFC_WAKE (VCC)
+ ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_ASSERT_NFC_WAKE (0) pull up NFC_WAKE (VCC)
+ ** NFC_HAL_LP_ACTIVE_HIGH (1) NFC_HAL_DEASSERT_NFC_WAKE (1) pull down NFC_WAKE (GND)
+ */
+
+ if (cmd == nfc_hal_cb.dev_cb.nfc_wake_active_mode)
+ UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_OFF); /* pull down NFC_WAKE */
+ else
+ UPIO_Set (UPIO_GENERAL, NFC_HAL_LP_NFC_WAKE_GPIO, UPIO_ON); /* pull up NFC_WAKE */
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_power_mode_execute
+**
+** Description If snooze mode is enabled in full power mode,
+** Assert NFC_WAKE before sending data
+** Deassert NFC_WAKE when idle timer expires
+**
+** Returns TRUE if DH can send data to NFCC
+**
+*******************************************************************************/
+BOOLEAN nfc_hal_dm_power_mode_execute (tNFC_HAL_LP_EVT event)
+{
+ BOOLEAN send_to_nfcc = FALSE;
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_dm_power_mode_execute () event = %d", event);
+
+ if (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL)
+ {
+ if (nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE)
+ {
+ /* if any transport activity */
+ if ( (event == NFC_HAL_LP_TX_DATA_EVT)
+ ||(event == NFC_HAL_LP_RX_DATA_EVT) )
+ {
+ /* if idle timer is not running */
+ if (nfc_hal_cb.dev_cb.lp_timer.in_use == FALSE)
+ {
+ nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE);
+ }
+
+ /* start or extend idle timer */
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00,
+ ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
+ }
+ else if (event == NFC_HAL_LP_TIMEOUT_EVT)
+ {
+ /* let NFCC go to snooze mode */
+ nfc_hal_dm_set_nfc_wake (NFC_HAL_DEASSERT_NFC_WAKE);
+ }
+ }
+
+ send_to_nfcc = TRUE;
+ }
+
+ return (send_to_nfcc);
+}
+
+/*******************************************************************************
+**
+** Function nci_brcm_lp_timeout_cback
+**
+** Description callback function for low power timeout
+**
+** Returns void
+**
+*******************************************************************************/
+static void nci_brcm_lp_timeout_cback (void *p_tle)
+{
+ NCI_TRACE_DEBUG0 ("nci_brcm_lp_timeout_cback ()");
+
+ nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TIMEOUT_EVT);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_pre_init_nfcc
+**
+** Description This function initializes Broadcom specific control blocks for
+** NCI transport
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_pre_init_nfcc (void)
+{
+ NCI_TRACE_DEBUG0 ("nfc_hal_dm_pre_init_nfcc ()");
+
+ if (nfc_post_reset_cb.dev_init_config.flags & NFC_HAL_DEV_INIT_FLAGS_SET_XTAL_FREQ)
+ {
+ nfc_hal_dm_set_xtal_freq_index ();
+ }
+ else
+ {
+ /* Send RESET CMD if application registered callback for device initialization */
+ nfc_hal_dm_send_reset_cmd ();
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_shutting_down_nfcc
+**
+** Description This function initializes Broadcom specific control blocks for
+** NCI transport
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_shutting_down_nfcc (void)
+{
+ NCI_TRACE_DEBUG0 ("nfc_hal_dm_shutting_down_nfcc ()");
+
+ nfc_hal_cb.dev_cb.initializing_state = NFC_HAL_INIT_STATE_CLOSING;
+
+ /* reset low power mode variables */
+ if ( (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL)
+ &&(nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE) )
+ {
+ nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE);
+ }
+
+ nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE;
+ nfc_hal_cb.hci_cb.b_check_clear_all_pipe_cmd = FALSE;
+
+ nfc_hal_cb.dev_cb.power_mode = NFC_HAL_POWER_MODE_FULL;
+ nfc_hal_cb.dev_cb.snooze_mode = NFC_HAL_LP_SNOOZE_MODE_NONE;
+
+ /* Stop all timers */
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer);
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer);
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.prm.timer);
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.hci_cb.hci_timer);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_init
+**
+** Description This function initializes Broadcom specific control blocks for
+** NCI transport
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_dm_init (void)
+{
+ NCI_TRACE_DEBUG0 ("nfc_hal_dm_init ()");
+
+ nfc_hal_cb.dev_cb.lp_timer.p_cback = nci_brcm_lp_timeout_cback;
+
+ nfc_hal_cb.ncit_cb.nci_wait_rsp_timer.p_cback = nfc_hal_nci_cmd_timeout_cback;
+
+ nfc_hal_cb.hci_cb.hci_timer.p_cback = nfc_hal_hci_timeout_cback;
+
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcDevInitDone
+**
+** Description Notify that pre-initialization of NFCC is complete
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcPreInitDone (tHAL_NFC_STATUS status)
+{
+ NCI_TRACE_DEBUG1 ("HAL_NfcPreInitDone () status=%d", status);
+
+ if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE)
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+
+ nfc_hal_main_pre_init_done (status);
+ }
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcReInit
+**
+** Description This function is called to send an RESET and GET_PATCH_VERSION
+** command to NFCC.
+**
+** p_cback - The callback function to receive the command
+** status
+**
+** Note This function should be called only during the HAL init process
+**
+** Returns HAL_NFC_STATUS_OK if successfully initiated
+** HAL_NFC_STATUS_FAILED otherwise
+**
+*******************************************************************************/
+tHAL_NFC_STATUS HAL_NfcReInit (tNFC_HAL_NCI_CBACK *p_cback)
+{
+ tHAL_NFC_STATUS status = HAL_NFC_STATUS_FAILED;
+ NCI_TRACE_DEBUG1 ("HAL_NfcReInit () init st=0x%x", nfc_hal_cb.dev_cb.initializing_state);
+ if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE)
+ {
+ /* Proceed with start up sequence: send CORE_RESET_CMD */
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_RE_INIT);
+ nfc_hal_cb.p_reinit_cback = p_cback;
+
+ nfc_hal_dm_send_nci_cmd (nfc_hal_dm_core_reset_cmd, NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET, NULL);
+ status = HAL_NFC_STATUS_OK;
+ }
+ return status;
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_dm_set_snooze_mode_cback
+**
+** Description This is baud rate update complete callback.
+**
+** Returns void
+**
+*******************************************************************************/
+static void nfc_hal_dm_set_snooze_mode_cback (tNFC_HAL_BTVSC_CPLT *pData)
+{
+ UINT8 status = pData->p_param_buf[0];
+ tHAL_NFC_STATUS hal_status;
+ tHAL_NFC_STATUS_CBACK *p_cback;
+
+ /* if it is completed */
+ if (status == HCI_SUCCESS)
+ {
+ /* update snooze mode */
+ nfc_hal_cb.dev_cb.snooze_mode = nfc_hal_cb.dev_cb.new_snooze_mode;
+
+ nfc_hal_dm_set_nfc_wake (NFC_HAL_ASSERT_NFC_WAKE);
+
+ if ( nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE)
+ {
+ /* start idle timer */
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.dev_cb.lp_timer, 0x00,
+ ((UINT32) NFC_HAL_LP_IDLE_TIMEOUT) * QUICK_TIMER_TICKS_PER_SEC / 1000);
+ }
+ else
+ {
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.dev_cb.lp_timer);
+ }
+ hal_status = HAL_NFC_STATUS_OK;
+ }
+ else
+ {
+ hal_status = HAL_NFC_STATUS_FAILED;
+ }
+
+ if (nfc_hal_cb.dev_cb.p_prop_cback)
+ {
+ p_cback = nfc_hal_cb.dev_cb.p_prop_cback;
+ nfc_hal_cb.dev_cb.p_prop_cback = NULL;
+ (*p_cback) (hal_status);
+ }
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcSetSnoozeMode
+**
+** Description Set snooze mode
+** snooze_mode
+** NFC_HAL_LP_SNOOZE_MODE_NONE - Snooze mode disabled
+** NFC_HAL_LP_SNOOZE_MODE_UART - Snooze mode for UART
+** NFC_HAL_LP_SNOOZE_MODE_SPI_I2C - Snooze mode for SPI/I2C
+**
+** idle_threshold_dh/idle_threshold_nfcc
+** Idle Threshold Host in 100ms unit
+**
+** nfc_wake_active_mode/dh_wake_active_mode
+** NFC_HAL_LP_ACTIVE_LOW - high to low voltage is asserting
+** NFC_HAL_LP_ACTIVE_HIGH - low to high voltage is asserting
+**
+** p_snooze_cback
+** Notify status of operation
+**
+** Returns tHAL_NFC_STATUS
+**
+*******************************************************************************/
+tHAL_NFC_STATUS HAL_NfcSetSnoozeMode (UINT8 snooze_mode,
+ UINT8 idle_threshold_dh,
+ UINT8 idle_threshold_nfcc,
+ UINT8 nfc_wake_active_mode,
+ UINT8 dh_wake_active_mode,
+ tHAL_NFC_STATUS_CBACK *p_snooze_cback)
+{
+ UINT8 cmd[NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH];
+ UINT8 *p;
+
+ NCI_TRACE_API1 ("HAL_NfcSetSnoozeMode (): snooze_mode = %d", snooze_mode);
+
+ nfc_hal_cb.dev_cb.new_snooze_mode = snooze_mode;
+ nfc_hal_cb.dev_cb.nfc_wake_active_mode = nfc_wake_active_mode;
+ nfc_hal_cb.dev_cb.p_prop_cback = p_snooze_cback;
+
+ p = cmd;
+
+ /* Add the HCI command */
+ UINT16_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE);
+ UINT8_TO_STREAM (p, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH);
+
+ memset (p, 0x00, HCI_BRCM_WRITE_SLEEP_MODE_LENGTH);
+
+ UINT8_TO_STREAM (p, snooze_mode); /* Sleep Mode */
+
+ UINT8_TO_STREAM (p, idle_threshold_dh); /* Idle Threshold Host */
+ UINT8_TO_STREAM (p, idle_threshold_nfcc); /* Idle Threshold HC */
+ UINT8_TO_STREAM (p, nfc_wake_active_mode); /* BT Wake Active Mode */
+ UINT8_TO_STREAM (p, dh_wake_active_mode); /* Host Wake Active Mode */
+
+ nfc_hal_dm_send_bt_cmd (cmd,
+ NFC_HAL_BT_HCI_CMD_HDR_SIZE + HCI_BRCM_WRITE_SLEEP_MODE_LENGTH,
+ nfc_hal_dm_set_snooze_mode_cback);
+ return (NCI_STATUS_OK);
+}
+
+
+
+
+
+
+
+
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_dm_cfg.c b/halimpl/bcm2079x/hal/hal/nfc_hal_dm_cfg.c
new file mode 100644
index 0000000..f16aae7
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_dm_cfg.c
@@ -0,0 +1,133 @@
+/******************************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains compile-time configurable constants for BRCM HAL
+ * modules
+ *
+ ******************************************************************************/
+#include "nfc_hal_int.h"
+#include "nci_defs.h"
+#include "nfc_brcm_defs.h"
+
+/* the SetConfig at start up*/
+UINT8 nfc_hal_start_up_cfg[] = {
+ /* TLV len */ 28,
+ /* B0 */ NCI_PARAM_ID_EMVCO_ENABLE,
+ /* B1 */ 1,
+ /* B2 */ 1, /* (1 = enable emvco mode, 0 = disable emvco mode) Default = 0.*/
+ /* B3 */ NCI_PARAM_ID_CONTINUE_MODE, /* NFCC will restart discovery after deactivated */
+ /* B4 */ 1,
+ /* B5 */ 1, /* (1 = enable, 0 = disable) Default = 0.*/
+ /* B6 */ NCI_PARAM_ID_RFU_CONFIG,
+ /* B7 */ 0x14,
+ /* B8 */ 0x00,
+ /* B9 */ 0x00,
+ /* B10*/ 0x00,
+ /* B11*/ 0x00,
+ /* B12*/ 0x02,
+ /* B13*/ 0xE8,
+ /* B14*/ 0x03,
+ /* B15*/ 0x00,
+ /* B16*/ 0x00,
+ /* B17*/ 0x00,
+ /* B18*/ 0x00,
+ /* B19*/ 0x00,
+ /* B20*/ 0x00,
+ /* B21*/ 0x00,
+ /* B22*/ 0x00,
+ /* B23*/ 0x00,
+ /* B24*/ 0x00,
+ /* B25*/ 0x00,
+ /* B26*/ 0x00,
+ /* B27*/ 0x00
+};
+
+UINT8 *p_nfc_hal_dm_start_up_cfg = (UINT8 *) nfc_hal_start_up_cfg;
+
+/* the VSCs at start up:
+ * The VSCs are specified in TLV format similar to nfa_start_up_cfg[]
+ * first byte is the TLV total len.
+ * B0 is the first T; i.e. the opcode for the VSC
+ * B1 is the len of the VSC parameters/payload
+ * */
+UINT8 nfc_hal_dm_start_up_vsc_cfg[] = {
+ /* TLV len */ 5,
+ /* B0 */ NCI_MTS_CMD|NCI_GID_PROP,
+ /* B1 */ NCI_MSG_FRAME_LOG,
+ /* B2 */ 2,
+ /* B3 */ 0, /* 1 to enable RF frames */
+ /* B4 */ 1 /* 1 to enable SWP frames */
+};
+
+UINT8 *p_nfc_hal_dm_start_up_vsc_cfg = NULL;
+
+/* LPTD parameters (LowPowerTagDetection)
+ * This is typical values for 20791B2
+ * The timing and threshold parameters used for a customer handset/hardware may vary
+ * depending on antenna and should be verified during a customer testing phase.
+ * the data fields without comments are too complicated. Please see ""
+ * */
+const UINT8 nfc_hal_dm_lptd_cfg[] =
+{
+ 21, /* total TLV length excluding itself */
+ NCI_PARAM_ID_TAGSNIFF_CFG, /* type */
+ 19, /* length */
+ 0x01, /* B0 enable: 0/disable, 1/enable*/
+ 0x02, /* B1 poll count: number of full power poll before starting lptd poll */
+ 0xFF, /* B2 sniff count lsb: number of lptd poll before switching to full power poll */
+ 0xFF, /* B3 sniff count msb */
+ 0x80, /* B4 threshold: Bigger thresholds give a smaller LPTD range but more immunity to false detections. Smaller thresholds increase LPTD range at the cost of greater likelihood of false detections. */
+ 0x40, /* B5 delay lsb: delay (us) to sampling power */
+ 0x00, /* B6 delay msb */
+ 0x40, /* B7 carrier threshold lsb */
+ 0x00, /* B8 carrier threshold msb */
+ 0x80, /* B9 mode: Bitwise variable used to enable various algorithm modes.*/
+ 0x80, /* B10 0-offset lsb */
+ 0x00, /* B11 0-offset msb */
+ 0x10, /* B12 field sense time lsb */
+ 0x00, /* B13 field sense time msb */
+ 0x00, /* B14 false detect threshold lsb: 0x00 to disable LPTD NTF. The number of false tag detections to resport LPTD NTF. */
+ 0x00, /* B15 false detect threshold msb. A false tag detect - full poll results in no tag being detected.*/
+ 0x75, /* B16 mode1; Bitwise variable used to enable various algorithm modes. */
+ 0x0D, /* B17 lptd ant cfg rx */
+ 0x30, /* B18 lptd rdr cfg ve */
+};
+
+UINT8 *p_nfc_hal_dm_lptd_cfg = (UINT8 *) &nfc_hal_dm_lptd_cfg[0];
+
+/* This must be configured before setting reader mode for 20791. No need to configure for 43341. */
+const UINT8 nfc_hal_dm_pll_325_cfg[NFC_HAL_XTAL_INDEX_MAX][NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN] =
+{
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0x9A, 0x99, 0x99, 0x99, 0xD7, 0x03, 0x00, 0x87, 0x04, 0x1C, 0x0F, 0x00, 0x0B, FALSE}, /* 9.6 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0xEF, 0x90, 0xA8, 0x22, 0xD0, 0x03, 0x00, 0x64, 0x06, 0x26, 0x0F, 0x00, 0x08, FALSE}, /* 13.0 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0x5B, 0xB0, 0x05, 0x5B, 0xD8, 0x03, 0x00, 0x50, 0x07, 0x30, 0x0F, 0x00, 0x06, FALSE}, /* 16.2 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0xCD, 0xCC, 0xCC, 0xCC, 0xD7, 0x03, 0x00, 0x43, 0x09, 0x39, 0x0F, 0x00, 0x04, FALSE}, /* 19.2 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0xD7, 0xA3, 0x70, 0x3D, 0xD0, 0x03, 0x00, 0x36, 0x0B, 0x47, 0x0F, 0x00, 0x03, FALSE}, /* 24.0 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0x78, 0x48, 0x54, 0x11, 0xD0, 0x03, 0x00, 0x32, 0x0C, 0x4D, 0x0F, 0x00, 0x02, FALSE}, /* 26.0 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0xCD, 0xCC, 0xCC, 0xCC, 0xD7, 0x03, 0x00, 0x43, 0x09, 0x39, 0x0F, 0x00, 0x04, TRUE}, /* 38.4 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0x78, 0x48, 0x54, 0x11, 0xD0, 0x03, 0x00, 0x32, 0x0C, 0x4D, 0x0F, 0x00, 0x02, TRUE}, /* 52.0 MHz */
+ {NCI_PARAM_ID_PLL325_CFG_PARAM, NCI_PARAM_LEN_PLL325_CFG_PARAM, 0x29, 0xB4, 0xE2, 0x9C, 0xCF, 0x03, 0x00, 0x45, 0x08, 0x37, 0x0F, 0x00, 0x04, TRUE} /* 37.4 MHz */
+};
+
+UINT8 *p_nfc_hal_dm_pll_325_cfg = (UINT8 *) nfc_hal_dm_pll_325_cfg;
+
+
+/* set nfc_hal_prm_nvm_required to TRUE, if the platform wants to abort PRM process without NVM */
+BOOLEAN nfc_hal_prm_nvm_required = FALSE;
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_hci.c b/halimpl/bcm2079x/hal/hal/nfc_hal_hci.c
new file mode 100644
index 0000000..1504c94
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_hci.c
@@ -0,0 +1,441 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Vendor-specific handler for HCI events
+ *
+ ******************************************************************************/
+#include "gki.h"
+#include "nfc_hal_api.h"
+#include "nfc_hal_int.h"
+#include "nfc_hal_nv_ci.h"
+#include "nfc_hal_nv_co.h"
+
+#include <string.h>
+#include "nfc_hal_nv_co.h"
+
+#ifndef NFC_HAL_HCI_NV_READ_TIMEOUT
+#define NFC_HAL_HCI_NV_READ_TIMEOUT 1000
+#endif
+
+#ifndef NFC_HAL_HCI_NFCC_RSP_TIMEOUT
+#define NFC_HAL_HCI_NFCC_RSP_TIMEOUT 3000
+#endif
+
+static void nfc_hal_hci_set_next_hci_netwk_config (UINT8 block);
+static void nfc_hal_hci_handle_nv_read (UINT8 block, tHAL_NFC_STATUS status, UINT16 size);
+static void nfc_hal_hci_init_complete (tHAL_NFC_STATUS status);
+static void nfc_hal_hci_vsc_cback (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data);
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_evt_hdlr
+**
+** Description Processing event for NFA HCI
+**
+** Returns None
+**
+*******************************************************************************/
+void nfc_hal_hci_evt_hdlr (tNFC_HAL_HCI_EVENT_DATA *p_evt_data)
+{
+ switch (p_evt_data->hdr.event)
+ {
+ case NFC_HAL_HCI_RSP_NV_READ_EVT:
+ nfc_hal_hci_handle_nv_read (p_evt_data->nv_read.block, p_evt_data->nv_read.status, p_evt_data->nv_read.size);
+ break;
+
+ case NFC_HAL_HCI_RSP_NV_WRITE_EVT:
+ /* NV Ram write completed - nothing to do... */
+ break;
+
+ default:
+ break;
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_enable
+**
+** Description Program nv data on to controller
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_hci_enable (void)
+{
+
+ UINT8 *p_hci_netwk_cmd;
+
+ if (nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf)
+ {
+ p_hci_netwk_cmd = (UINT8 *) (nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf - NCI_MSG_HDR_SIZE);
+ GKI_freebuf (p_hci_netwk_cmd);
+ nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf = NULL;
+ }
+
+ if (nfc_hal_cb.hci_cb.p_hci_netwk_info_buf)
+ {
+ p_hci_netwk_cmd = (UINT8 *) (nfc_hal_cb.hci_cb.p_hci_netwk_info_buf - NCI_MSG_HDR_SIZE);
+ GKI_freebuf (p_hci_netwk_cmd);
+ nfc_hal_cb.hci_cb.p_hci_netwk_info_buf = NULL;
+ }
+
+ if ((p_hci_netwk_cmd = (UINT8 *) GKI_getbuf (NCI_MSG_HDR_SIZE + NFC_HAL_HCI_NETWK_INFO_SIZE)) == NULL)
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_hci_enable: unable to allocate buffer for reading hci network info from nvram");
+ nfc_hal_hci_init_complete (HAL_NFC_STATUS_FAILED);
+ }
+ else
+ {
+ nfc_hal_cb.hci_cb.p_hci_netwk_info_buf = (UINT8 *) (p_hci_netwk_cmd + NCI_MSG_HDR_SIZE);
+ nfc_hal_cb.hci_cb.hci_netwk_config_block = 0;
+ memset (nfc_hal_cb.hci_cb.p_hci_netwk_info_buf, 0, NFC_HAL_HCI_NETWK_INFO_SIZE);
+ nfc_hal_nv_co_read ((UINT8 *) nfc_hal_cb.hci_cb.p_hci_netwk_info_buf, NFC_HAL_HCI_NETWK_INFO_SIZE, HC_F3_NV_BLOCK);
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.hci_cb.hci_timer, NFC_HAL_HCI_VSC_TIMEOUT_EVT, NFC_HAL_HCI_NV_READ_TIMEOUT);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_handle_hci_netwk_info
+**
+** Description Handler function for HCI Network Notification
+**
+** Returns None
+**
+*******************************************************************************/
+void nfc_hal_hci_handle_hci_netwk_info (UINT8 *p_data)
+{
+ UINT8 *p = p_data;
+ UINT16 data_len;
+ UINT8 target_handle;
+ UINT8 hci_netwk_cmd[1 + NFC_HAL_HCI_SESSION_ID_LEN];
+
+ NCI_TRACE_DEBUG0 ("nfc_hal_hci_handle_hci_netwk_info()");
+
+ /* skip NCI header byte0 (MT,GID), byte1 (OID) */
+ p += 2;
+
+ STREAM_TO_UINT8 (data_len, p);
+ target_handle = *(UINT8 *) p;
+
+ if (target_handle == NFC_HAL_HCI_DH_TARGET_HANDLE)
+ nfc_hal_nv_co_write (p, data_len,HC_DH_NV_BLOCK);
+
+ else if (target_handle == NFC_HAL_HCI_UICC0_TARGET_HANDLE)
+ {
+ if (p[12] & 0x80)
+ {
+ /* HCI Network notification received for UICC 0, Update nv data */
+ nfc_hal_nv_co_write (p, data_len,HC_F3_NV_BLOCK);
+ }
+ else
+ {
+ NCI_TRACE_DEBUG1 ("nfc_hal_hci_handle_hci_netwk_info(): Type A Card Emulation invalid, Reset nv file: 0x%02x", p[15]);
+ hci_netwk_cmd[0] = NFC_HAL_HCI_UICC0_TARGET_HANDLE;
+ memset (&hci_netwk_cmd[1], 0xFF, NFC_HAL_HCI_SESSION_ID_LEN);
+ nfc_hal_nv_co_write (hci_netwk_cmd, 1, HC_F3_NV_BLOCK);
+ }
+ }
+ else if (target_handle == NFC_HAL_HCI_UICC1_TARGET_HANDLE)
+ {
+ if (p[12] & 0x80)
+ {
+ /* HCI Network notification received for UICC 1, Update nv data */
+ nfc_hal_nv_co_write (p, data_len,HC_F4_NV_BLOCK);
+ }
+ else
+ {
+ NCI_TRACE_DEBUG1 ("nfc_hal_hci_handle_hci_netwk_info(): Type A Card Emulation invalid, Reset nv file: 0x%02x", p[15]);
+ hci_netwk_cmd[0] = NFC_HAL_HCI_UICC1_TARGET_HANDLE;
+ /* Reset Session ID */
+ memset (&hci_netwk_cmd[1], 0xFF, NFC_HAL_HCI_SESSION_ID_LEN);
+ nfc_hal_nv_co_write (hci_netwk_cmd, 1, HC_F4_NV_BLOCK);
+ }
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_handle_hcp_pkt
+**
+** Description Handle HCP Packet
+**
+** Returns None
+**
+*******************************************************************************/
+void nfc_hal_hci_handle_hcp_pkt (UINT8 *p_data)
+{
+ UINT8 chaining_bit;
+ UINT8 pipe;
+ UINT8 type;
+ UINT8 inst;
+ UINT8 hci_netwk_cmd[1 + NFC_HAL_HCI_SESSION_ID_LEN];
+ UINT8 source_host;
+
+ chaining_bit = ((*p_data) >> 0x07) & 0x01;
+ pipe = (*p_data++) & 0x7F;
+
+ if ( (chaining_bit)
+ &&(pipe == NFC_HAL_HCI_ADMIN_PIPE) )
+ {
+ type = ((*p_data) >> 0x06) & 0x03;
+
+ if (type == NFC_HAL_HCI_COMMAND_TYPE)
+ {
+ inst = (*p_data++ & 0x3F);
+
+ if (inst == NFC_HAL_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED)
+ {
+
+ STREAM_TO_UINT8 (source_host, p_data);
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_hci_handle_hcp_pkt(): Received Clear All pipe command for UICC: 0x%02x", source_host);
+ if (source_host == NFC_HAL_HCI_HOST_ID_UICC0)
+ {
+ hci_netwk_cmd[0] = NFC_HAL_HCI_UICC0_TARGET_HANDLE;
+ /* Reset Session ID */
+ memset (&hci_netwk_cmd[1], 0xFF, NFC_HAL_HCI_SESSION_ID_LEN);
+ nfc_hal_nv_co_write (hci_netwk_cmd, 1, HC_F3_NV_BLOCK);
+ NCI_TRACE_DEBUG1 ("nfc_hal_hci_handle_hcp_pkt(): Sent command to reset nv file for block: 0x%02x", HC_F3_NV_BLOCK);
+ }
+ else if (source_host == NFC_HAL_HCI_HOST_ID_UICC1)
+ {
+ hci_netwk_cmd[0] = NFC_HAL_HCI_UICC1_TARGET_HANDLE;
+ /* Reset Session ID */
+ memset (&hci_netwk_cmd[1], 0xFF, NFC_HAL_HCI_SESSION_ID_LEN);
+ nfc_hal_nv_co_write (hci_netwk_cmd, 1, HC_F4_NV_BLOCK);
+ NCI_TRACE_DEBUG1 ("nfc_hal_hci_handle_hcp_pkt(): Sent command to reset nv file for block: 0x%02x", HC_F4_NV_BLOCK);
+ }
+ }
+ }
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_handle_nv_read
+**
+** Description handler function for nv read complete event
+**
+** Returns None
+**
+*******************************************************************************/
+void nfc_hal_hci_handle_nv_read (UINT8 block, tHAL_NFC_STATUS status, UINT16 size)
+{
+ NFC_HDR *p_data = NULL;
+ UINT8 *p;
+ UINT8 *p_hci_netwk_info = NULL;
+
+ /* Stop timer as NVDATA Read Completed */
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.hci_cb.hci_timer);
+
+ switch (block)
+ {
+ case HC_F3_NV_BLOCK:
+ case HC_F4_NV_BLOCK:
+ if ( (status != HAL_NFC_STATUS_OK)
+ ||(size > NFC_HAL_HCI_NETWK_INFO_SIZE) )
+ {
+ NCI_TRACE_DEBUG0 ("nfc_hal_hci_handle_nv_read: Invalid data from nv memory, Set DEFAULT Configuration!");
+ memset (nfc_hal_cb.hci_cb.p_hci_netwk_info_buf, 0, NFC_HAL_HCI_NETWK_INFO_SIZE);
+ nfc_hal_cb.hci_cb.p_hci_netwk_info_buf[0] = (block == HC_F3_NV_BLOCK) ? NFC_HAL_HCI_UICC0_TARGET_HANDLE : NFC_HAL_HCI_UICC1_TARGET_HANDLE;
+ memset (&nfc_hal_cb.hci_cb.p_hci_netwk_info_buf[1], 0xFF, NFC_HAL_HCI_SESSION_ID_LEN);
+ size = NFC_HAL_HCI_NETWK_INFO_SIZE;
+ }
+
+ p_hci_netwk_info = (UINT8 *) nfc_hal_cb.hci_cb.p_hci_netwk_info_buf - NCI_MSG_HDR_SIZE;
+ break;
+
+ case HC_DH_NV_BLOCK:
+ if ( (status == HAL_NFC_STATUS_OK)
+ &&(size <= NFC_HAL_HCI_DH_NETWK_INFO_SIZE) )
+ {
+ p_hci_netwk_info = (UINT8 *) (nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf - NCI_MSG_HDR_SIZE);
+ }
+ else
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_hci_handle_nv_read: Invalid data from nv memory, Skip DH Configuration!");
+ }
+ break;
+
+ default:
+ return;
+ }
+
+ if (p_hci_netwk_info)
+ {
+ p = p_hci_netwk_info;
+ /* Send HCI Network ntf command using nv data */
+ NCI_MSG_BLD_HDR0 (p, NCI_MT_CMD, NCI_GID_PROP);
+ NCI_MSG_BLD_HDR1 (p, NCI_MSG_HCI_NETWK);
+ UINT8_TO_STREAM (p, (UINT8) size);
+
+ nfc_hal_dm_send_nci_cmd (p_hci_netwk_info, (UINT16) (NCI_MSG_HDR_SIZE + size), nfc_hal_hci_vsc_cback);
+
+ nfc_hal_cb.hci_cb.hci_netwk_config_block = block;
+ }
+ else
+ {
+ /* Set next HCI Network configuration */
+ nfc_hal_hci_set_next_hci_netwk_config (block);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_init_complete
+**
+** Description Notify VSC initialization is complete
+**
+** Returns None
+**
+*******************************************************************************/
+void nfc_hal_hci_init_complete (tHAL_NFC_STATUS status)
+{
+ UINT8 *p_hci_netwk_cmd;
+
+ if (nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf)
+ {
+ p_hci_netwk_cmd = (UINT8 *) (nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf - NCI_MSG_HDR_SIZE);
+ GKI_freebuf (p_hci_netwk_cmd);
+ nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf = NULL;
+ }
+
+ if (nfc_hal_cb.hci_cb.p_hci_netwk_info_buf)
+ {
+ p_hci_netwk_cmd = (UINT8 *) (nfc_hal_cb.hci_cb.p_hci_netwk_info_buf - NCI_MSG_HDR_SIZE);
+ GKI_freebuf (p_hci_netwk_cmd);
+ nfc_hal_cb.hci_cb.p_hci_netwk_info_buf = NULL;
+ }
+
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_OK);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_set_next_hci_netwk_config
+**
+** Description set next hci network configuration
+**
+** Returns None
+**
+*******************************************************************************/
+void nfc_hal_hci_set_next_hci_netwk_config (UINT8 block)
+{
+ UINT8 *p_hci_netwk_cmd;
+
+ switch (block)
+ {
+ case HC_F3_NV_BLOCK:
+ /* Send command to read nvram data for 0xF4 */
+ memset (nfc_hal_cb.hci_cb.p_hci_netwk_info_buf, 0, NFC_HAL_HCI_NETWK_INFO_SIZE);
+ nfc_hal_nv_co_read ((UINT8 *) nfc_hal_cb.hci_cb.p_hci_netwk_info_buf, NFC_HAL_HCI_NETWK_INFO_SIZE, HC_F4_NV_BLOCK);
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.hci_cb.hci_timer, NFC_HAL_HCI_VSC_TIMEOUT_EVT, NFC_HAL_HCI_NV_READ_TIMEOUT);
+ break;
+
+ case HC_F4_NV_BLOCK:
+ if ((p_hci_netwk_cmd = (UINT8 *) GKI_getbuf (NCI_MSG_HDR_SIZE + NFC_HAL_HCI_DH_NETWK_INFO_SIZE)) == NULL)
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_hci_set_next_hci_netwk_config: unable to allocate buffer for reading hci network info from nvram");
+ nfc_hal_hci_init_complete (HAL_NFC_STATUS_FAILED);
+ }
+ else
+ {
+ nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf = (UINT8 *) (p_hci_netwk_cmd + NCI_MSG_HDR_SIZE);
+ /* Send command to read nvram data for 0xF2 */
+ memset (nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf, 0, NFC_HAL_HCI_DH_NETWK_INFO_SIZE);
+ nfc_hal_nv_co_read ((UINT8 *) nfc_hal_cb.hci_cb.p_hci_netwk_dh_info_buf, NFC_HAL_HCI_DH_NETWK_INFO_SIZE, HC_DH_NV_BLOCK);
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.hci_cb.hci_timer, NFC_HAL_HCI_VSC_TIMEOUT_EVT, NFC_HAL_HCI_NV_READ_TIMEOUT);
+ }
+ break;
+
+ case HC_DH_NV_BLOCK:
+ nfc_hal_hci_init_complete (HAL_NFC_STATUS_OK);
+ break;
+
+ default:
+ NCI_TRACE_ERROR1 ("nfc_hal_hci_set_next_hci_netwk_config: unable to allocate buffer to send VSC 0x%02x", block);
+ /* Brcm initialization failed */
+ nfc_hal_hci_init_complete (HAL_NFC_STATUS_FAILED);
+ break;
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_hci_vsc_cback
+**
+** Description process VS callback event from stack
+**
+** Returns none
+**
+*******************************************************************************/
+static void nfc_hal_hci_vsc_cback (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data)
+{
+ UINT8 *p_ret = NULL;
+ UINT8 status;
+
+ p_ret = p_data + NCI_MSG_HDR_SIZE;
+ status = *p_ret;
+
+ if (event != NFC_VS_HCI_NETWK_RSP)
+ return;
+
+ if (status != HAL_NFC_STATUS_OK)
+ nfc_hal_hci_init_complete (HAL_NFC_STATUS_FAILED);
+
+ switch (nfc_hal_cb.hci_cb.hci_netwk_config_block)
+ {
+ case HC_F3_NV_BLOCK:
+ case HC_F4_NV_BLOCK:
+ case HC_DH_NV_BLOCK:
+ nfc_hal_hci_set_next_hci_netwk_config (nfc_hal_cb.hci_cb.hci_netwk_config_block);
+ break;
+
+ default:
+ /* Ignore the event */
+ break;
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_nci_cmd_timeout_cback
+**
+** Description callback function for timeout
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_hci_timeout_cback (void *p_tle)
+{
+ TIMER_LIST_ENT *p_tlent = (TIMER_LIST_ENT *)p_tle;
+
+ NCI_TRACE_DEBUG0 ("nfc_hal_hci_timeout_cback ()");
+
+ if (p_tlent->event == NFC_HAL_HCI_VSC_TIMEOUT_EVT)
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_hci_timeout_cback: Timeout - NFC HAL HCI BRCM Initialization Failed!");
+ nfc_hal_hci_init_complete (HAL_NFC_STATUS_FAILED);
+ }
+}
+
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_hci_ci.c b/halimpl/bcm2079x/hal/hal/nfc_hal_hci_ci.c
new file mode 100644
index 0000000..d9e999e
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_hci_ci.c
@@ -0,0 +1,88 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2010-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains the call-in functions for NFC HAL HCI
+ *
+ ******************************************************************************/
+#include <string.h>
+#include "nfc_hal_api.h"
+#include "nfc_hal_int.h"
+#include "nfc_hal_nv_ci.h"
+#include "nfc_hal_nv_co.h"
+
+/*******************************************************************************
+**
+** Function nfa_nv_ci_read
+**
+** Description call-in function for non volatile memory read acess
+**
+** Returns none
+**
+*******************************************************************************/
+void nfc_hal_nv_ci_read (UINT16 num_bytes_read, tNFC_HAL_NV_CO_STATUS status, UINT8 block)
+{
+ tNFC_HAL_HCI_EVENT_DATA *p_msg;
+
+ /* Send message to NCIT task */
+ if ((p_msg = (tNFC_HAL_HCI_EVENT_DATA *) GKI_getbuf (sizeof (tNFC_HAL_HCI_EVENT_DATA))) != NULL)
+ {
+ p_msg->nv_read.hdr.event = NFC_HAL_HCI_RSP_NV_READ_EVT;
+ p_msg->hdr.offset = 0;
+ p_msg->hdr.len = sizeof (tNFC_HAL_HCI_RSP_NV_READ_EVT);
+ p_msg->hdr.layer_specific = 0;
+
+ if ( (status == NFC_HAL_NV_CO_OK)
+ &&(num_bytes_read != 0) )
+ p_msg->nv_read.status = HAL_NFC_STATUS_OK;
+ else
+ p_msg->nv_read.status = HAL_NFC_STATUS_FAILED;
+
+ p_msg->nv_read.size = num_bytes_read;
+ p_msg->nv_read.block = block;
+
+ GKI_send_msg (NFC_HAL_TASK, NFC_HAL_TASK_MBOX, p_msg);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfa_nv_ci_write
+**
+** Description call-in function for non volatile memory write acess
+**
+** Returns none
+**
+*******************************************************************************/
+void nfc_hal_nv_ci_write (tNFC_HAL_NV_CO_STATUS status)
+{
+ tNFC_HAL_HCI_EVENT_DATA *p_msg;
+
+ if ((p_msg = (tNFC_HAL_HCI_EVENT_DATA *) GKI_getbuf (sizeof (tNFC_HAL_HCI_EVENT_DATA))) != NULL)
+ {
+ p_msg->nv_write.hdr.event = NFC_HAL_HCI_RSP_NV_WRITE_EVT;
+ p_msg->nv_write.hdr.offset = 0;
+ p_msg->nv_write.hdr.len = sizeof (tNFC_HAL_HCI_RSP_NV_READ_EVT);
+ p_msg->nv_write.hdr.layer_specific = 0;
+ p_msg->nv_write.status = HAL_NFC_STATUS_OK;
+
+ GKI_send_msg (NFC_HAL_TASK, NFC_HAL_TASK_MBOX, p_msg);
+ }
+}
+
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_main.c b/halimpl/bcm2079x/hal/hal/nfc_hal_main.c
new file mode 100644
index 0000000..82e696f
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_main.c
@@ -0,0 +1,596 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2010-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Functions for handling NFC HAL NCI Transport events
+ *
+ ******************************************************************************/
+#include <string.h>
+#include "nfc_hal_int.h"
+#include "userial.h"
+#include "upio.h"
+
+/****************************************************************************
+** Definitions
+****************************************************************************/
+
+/* Default NFC HAL NCI port configuration */
+NFC_HAL_TRANS_CFG_QUALIFIER tNFC_HAL_TRANS_CFG nfc_hal_trans_cfg =
+{
+ NFC_HAL_SHARED_TRANSPORT_ENABLED, /* bSharedTransport */
+ USERIAL_BAUD_115200, /* Baud rate */
+ USERIAL_FC_HW /* Flow control */
+};
+
+/* Control block for NFC HAL NCI transport */
+#if NFC_DYNAMIC_MEMORY == FALSE
+tNFC_HAL_CB nfc_hal_cb;
+#endif
+
+/****************************************************************************
+** Internal function prototypes
+****************************************************************************/
+static void nfc_hal_main_userial_cback (tUSERIAL_PORT port, tUSERIAL_EVT evt, tUSERIAL_EVT_DATA *p_data);
+static void nfc_hal_main_handle_terminate (void);
+
+
+#if (NFC_HAL_DEBUG == TRUE)
+const char * const nfc_hal_init_state_str[] =
+{
+ "IDLE", /* Initialization is done */
+ "W4_XTAL_SET", /* Waiting for crystal setting rsp */
+ "W4_RESET", /* Waiting for reset rsp */
+ "W4_BUILD_INFO", /* Waiting for build info rsp */
+ "W4_PATCH_INFO", /* Waiting for patch info rsp */
+ "W4_APP_COMPL", /* Waiting for complete from application */
+ "W4_POST_INIT", /* Waiting for complete of post init */
+ "W4_CONTROL", /* Waiting for control release */
+ "W4_PREDISC", /* Waiting for complete of prediscover */
+ "W4_RE_INIT", /* Waiting for reset rsp on ReInit */
+ "CLOSING" /* Shutting down */
+};
+#endif
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_init
+**
+** Description This function initializes control block for NFC HAL
+**
+** Returns nothing
+**
+*******************************************************************************/
+void nfc_hal_main_init (void)
+{
+ /* Clear control block */
+ memset (&nfc_hal_cb, 0, sizeof (tNFC_HAL_CB));
+
+ nfc_hal_cb.ncit_cb.nci_ctrl_size = NFC_HAL_NCI_INIT_CTRL_PAYLOAD_SIZE;
+ nfc_hal_cb.trace_level = NFC_HAL_INITIAL_TRACE_LEVEL;
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_open_transport
+**
+** Description Open transport and prepare for new incoming message;
+**
+** Returns nothing
+**
+*******************************************************************************/
+static void nfc_hal_main_open_transport (void)
+{
+ tUSERIAL_OPEN_CFG open_cfg;
+
+ /* Initialize control block */
+ nfc_hal_cb.ncit_cb.rcv_state = NFC_HAL_RCV_IDLE_ST; /* to process packet type */
+
+ if (nfc_hal_cb.ncit_cb.p_rcv_msg)
+ {
+ GKI_freebuf (nfc_hal_cb.ncit_cb.p_rcv_msg);
+ nfc_hal_cb.ncit_cb.p_rcv_msg = NULL;
+ }
+
+ /* open transport */
+ open_cfg.fmt = (USERIAL_DATABITS_8 | USERIAL_PARITY_NONE | USERIAL_STOPBITS_1);
+ open_cfg.baud = nfc_hal_trans_cfg.userial_baud;
+ open_cfg.fc = nfc_hal_trans_cfg.userial_fc;
+ open_cfg.buf = USERIAL_BUF_BYTE;
+
+ USERIAL_Open (USERIAL_NFC_PORT, &open_cfg, nfc_hal_main_userial_cback);
+
+ /* notify transport openned */
+ nfc_hal_dm_pre_init_nfcc ();
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_send_error
+**
+** Description send an Error event to NFC stack
+**
+** Returns nothing
+**
+*******************************************************************************/
+void nfc_hal_main_send_error (tHAL_NFC_STATUS status)
+{
+ /* Notify stack */
+ nfc_hal_cb.p_stack_cback(HAL_NFC_ERROR_EVT, status);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_userial_cback
+**
+** Description USERIAL callback for NCI transport
+**
+** Returns nothing
+**
+*******************************************************************************/
+static void nfc_hal_main_userial_cback (tUSERIAL_PORT port, tUSERIAL_EVT evt, tUSERIAL_EVT_DATA *p_data)
+{
+ if (evt == USERIAL_RX_READY_EVT)
+ {
+ /* Notify transport task of serial port event */
+ GKI_send_event (NFC_HAL_TASK, NFC_HAL_TASK_EVT_DATA_RDY);
+ }
+ else if (evt == USERIAL_TX_DONE_EVT)
+ {
+ /* Serial driver has finshed sending data from USERIAL_Write */
+ /* Currently, no action is needed for this event */
+ }
+ else if (evt == USERIAL_ERR_EVT)
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_main_userial_cback: USERIAL_ERR_EVT. Notifying NFC_TASK of transport error");
+ if (nfc_hal_cb.ncit_cb.nci_wait_rsp != NFC_HAL_WAIT_RSP_NONE)
+ {
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer);
+ nfc_hal_nci_cmd_timeout_cback ((void *)&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer);
+ }
+ else
+ {
+ nfc_hal_main_send_error (HAL_NFC_STATUS_ERR_TRANSPORT);
+ }
+ }
+ else if (evt == USERIAL_WAKEUP_EVT)
+ {
+ NCI_TRACE_DEBUG1 ("nfc_hal_main_userial_cback: USERIAL_WAKEUP_EVT: %d", p_data->sigs);
+ }
+ else
+ {
+ NCI_TRACE_DEBUG1 ("nfc_hal_main_userial_cback: unhandled userial evt: %i", evt);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_pre_init_done
+**
+** Description notify complete of pre-initialization
+**
+** Returns nothing
+**
+*******************************************************************************/
+void nfc_hal_main_pre_init_done (tHAL_NFC_STATUS status)
+{
+ NCI_TRACE_DEBUG1 ("nfc_hal_main_pre_init_done () status = %d", status);
+
+ if (status != HAL_NFC_STATUS_OK)
+ {
+ nfc_hal_main_handle_terminate ();
+
+ /* Close uart */
+ USERIAL_Close (USERIAL_NFC_PORT);
+ }
+
+ /* Notify NFC Task the status of initialization */
+ nfc_hal_cb.p_stack_cback (HAL_NFC_OPEN_CPLT_EVT, status);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_timeout_cback
+**
+** Description callback function for timeout
+**
+** Returns void
+**
+*******************************************************************************/
+static void nfc_hal_main_timeout_cback (void *p_tle)
+{
+ TIMER_LIST_ENT *p_tlent = (TIMER_LIST_ENT *) p_tle;
+
+ NCI_TRACE_DEBUG0 ("nfc_hal_main_timeout_cback ()");
+
+ switch (p_tlent->event)
+ {
+ case NFC_HAL_TTYPE_POWER_CYCLE:
+ nfc_hal_main_open_transport ();
+ break;
+
+ default:
+ NCI_TRACE_DEBUG1 ("nfc_hal_main_timeout_cback: unhandled timer event (0x%04x)", p_tlent->event);
+ break;
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_handle_terminate
+**
+** Description Handle NFI transport shutdown
+**
+** Returns nothing
+**
+*******************************************************************************/
+static void nfc_hal_main_handle_terminate (void)
+{
+ NFC_HDR *p_msg;
+
+ /* dequeue and free buffer */
+ if (nfc_hal_cb.ncit_cb.p_pend_cmd != NULL)
+ {
+ GKI_freebuf (nfc_hal_cb.ncit_cb.p_pend_cmd);
+ nfc_hal_cb.ncit_cb.p_pend_cmd = NULL;
+ }
+
+ /* Free unsent nfc rx buffer */
+ if (nfc_hal_cb.ncit_cb.p_rcv_msg)
+ {
+ GKI_freebuf (nfc_hal_cb.ncit_cb.p_rcv_msg);
+ nfc_hal_cb.ncit_cb.p_rcv_msg = NULL;
+ }
+
+ /* Free buffer for pending fragmented response/notification */
+ if (nfc_hal_cb.ncit_cb.p_frag_msg)
+ {
+ GKI_freebuf (nfc_hal_cb.ncit_cb.p_frag_msg);
+ nfc_hal_cb.ncit_cb.p_frag_msg = NULL;
+ }
+
+ /* Free buffers in the tx mbox */
+ while ((p_msg = (NFC_HDR *) GKI_read_mbox (NFC_HAL_TASK_MBOX)) != NULL)
+ {
+ GKI_freebuf (p_msg);
+ }
+
+ /* notify closing transport */
+ nfc_hal_dm_shutting_down_nfcc ();
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_start_quick_timer
+**
+** Description Start a timer for the specified amount of time.
+** NOTE: The timeout resolution depends on including modules.
+** QUICK_TIMER_TICKS_PER_SEC should be used to convert from
+** time to ticks.
+**
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_main_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout)
+{
+ NFC_HDR *p_msg;
+
+ /* if timer list is currently empty, start periodic GKI timer */
+ if (nfc_hal_cb.quick_timer_queue.p_first == NULL)
+ {
+ /* if timer starts on other than NCIT task (script wrapper) */
+ if(GKI_get_taskid () != NFC_HAL_TASK)
+ {
+ /* post event to start timer in NCIT task */
+ if ((p_msg = (NFC_HDR *) GKI_getbuf (NFC_HDR_SIZE)) != NULL)
+ {
+ p_msg->event = NFC_HAL_EVT_TO_START_QUICK_TIMER;
+ GKI_send_msg (NFC_HAL_TASK, NFC_HAL_TASK_MBOX, p_msg);
+ }
+ }
+ else
+ {
+ GKI_start_timer (NFC_HAL_QUICK_TIMER_ID, ((GKI_SECS_TO_TICKS (1) / QUICK_TIMER_TICKS_PER_SEC)), TRUE);
+ }
+ }
+
+ GKI_remove_from_timer_list (&nfc_hal_cb.quick_timer_queue, p_tle);
+
+ p_tle->event = type;
+ p_tle->ticks = timeout; /* Save the number of ticks for the timer */
+
+ GKI_add_to_timer_list (&nfc_hal_cb.quick_timer_queue, p_tle);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_stop_quick_timer
+**
+** Description Stop a timer.
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_main_stop_quick_timer (TIMER_LIST_ENT *p_tle)
+{
+ GKI_remove_from_timer_list (&nfc_hal_cb.quick_timer_queue, p_tle);
+
+ /* if timer list is empty stop periodic GKI timer */
+ if (nfc_hal_cb.quick_timer_queue.p_first == NULL)
+ {
+ GKI_stop_timer (NFC_HAL_QUICK_TIMER_ID);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_process_quick_timer_evt
+**
+** Description Process quick timer event
+**
+** Returns void
+**
+*******************************************************************************/
+static void nfc_hal_main_process_quick_timer_evt (void)
+{
+ TIMER_LIST_ENT *p_tle;
+
+ GKI_update_timer_list (&nfc_hal_cb.quick_timer_queue, 1);
+
+ while ((nfc_hal_cb.quick_timer_queue.p_first) && (!nfc_hal_cb.quick_timer_queue.p_first->ticks))
+ {
+ p_tle = nfc_hal_cb.quick_timer_queue.p_first;
+ GKI_remove_from_timer_list (&nfc_hal_cb.quick_timer_queue, p_tle);
+
+ if (p_tle->p_cback)
+ {
+ (*p_tle->p_cback) (p_tle);
+ }
+ }
+
+ /* if timer list is empty stop periodic GKI timer */
+ if (nfc_hal_cb.quick_timer_queue.p_first == NULL)
+ {
+ GKI_stop_timer (NFC_HAL_QUICK_TIMER_ID);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_send_message
+**
+** Description This function is calledto send an NCI message.
+**
+** Returns void
+**
+*******************************************************************************/
+static void nfc_hal_main_send_message (NFC_HDR *p_msg)
+{
+ UINT8 *ps;
+ UINT16 len = p_msg->len;
+#ifdef DISP_NCI
+ UINT8 delta;
+#endif
+
+ NCI_TRACE_DEBUG1 ("nfc_hal_main_send_message() ls:0x%x", p_msg->layer_specific);
+ if ( (p_msg->layer_specific == NFC_HAL_WAIT_RSP_CMD)
+ ||(p_msg->layer_specific == NFC_HAL_WAIT_RSP_VSC) )
+ {
+ nfc_hal_nci_send_cmd (p_msg);
+ }
+ else
+ {
+ /* NFC task has fragmented the data packet to the appropriate size
+ * and data credit is available; just send it */
+
+ /* add NCI packet type in front of message */
+ nfc_hal_nci_add_nfc_pkt_type (p_msg);
+
+ /* send this packet to transport */
+ ps = (UINT8 *) (p_msg + 1) + p_msg->offset;
+#ifdef DISP_NCI
+ delta = p_msg->len - len;
+ DISP_NCI (ps + delta, (UINT16) (p_msg->len - delta), FALSE);
+#endif
+ USERIAL_Write (USERIAL_NFC_PORT, ps, p_msg->len);
+ GKI_freebuf (p_msg);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_main_task
+**
+** Description NFC HAL NCI transport event processing task
+**
+** Returns 0
+**
+*******************************************************************************/
+UINT32 nfc_hal_main_task (UINT32 param)
+{
+ UINT16 event;
+ UINT8 byte;
+ UINT8 num_interfaces;
+ UINT8 *p;
+ NFC_HDR *p_msg;
+ BOOLEAN free_msg;
+
+ NCI_TRACE_DEBUG0 ("NFC_HAL_TASK started");
+
+ /* Main loop */
+ while (TRUE)
+ {
+ event = GKI_wait (0xFFFF, 0);
+
+ /* Handle NFC_HAL_TASK_EVT_INITIALIZE (for initializing NCI transport) */
+ if (event & NFC_HAL_TASK_EVT_INITIALIZE)
+ {
+ NCI_TRACE_DEBUG0 ("NFC_HAL_TASK got NFC_HAL_TASK_EVT_INITIALIZE signal. Opening NFC transport...");
+
+ nfc_hal_main_open_transport ();
+ }
+
+ /* Check for terminate event */
+ if (event & NFC_HAL_TASK_EVT_TERMINATE)
+ {
+ NCI_TRACE_DEBUG0 ("NFC_HAL_TASK got NFC_HAL_TASK_EVT_TERMINATE");
+ nfc_hal_main_handle_terminate ();
+
+ /* Close uart */
+ USERIAL_Close (USERIAL_NFC_PORT);
+
+ nfc_hal_cb.p_stack_cback (HAL_NFC_CLOSE_CPLT_EVT, HAL_NFC_STATUS_OK);
+ nfc_hal_cb.p_stack_cback = NULL;
+ continue;
+ }
+
+ /* Check for power cycle event */
+ if (event & NFC_HAL_TASK_EVT_POWER_CYCLE)
+ {
+ NCI_TRACE_DEBUG0 ("NFC_HAL_TASK got NFC_HAL_TASK_EVT_POWER_CYCLE");
+ nfc_hal_main_handle_terminate ();
+
+ /* Close uart */
+ USERIAL_Close (USERIAL_NFC_PORT);
+
+ /* power cycle timeout */
+ nfc_hal_cb.timer.p_cback = nfc_hal_main_timeout_cback;
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.timer, NFC_HAL_TTYPE_POWER_CYCLE,
+ (NFC_HAL_POWER_CYCLE_DELAY*QUICK_TIMER_TICKS_PER_SEC)/1000);
+ continue;
+ }
+
+ /* NCI message ready to be sent to NFCC */
+ if (event & NFC_HAL_TASK_EVT_MBOX)
+ {
+ while ((p_msg = (NFC_HDR *) GKI_read_mbox (NFC_HAL_TASK_MBOX)) != NULL)
+ {
+ free_msg = TRUE;
+ switch (p_msg->event & NFC_EVT_MASK)
+ {
+ case NFC_HAL_EVT_TO_NFC_NCI:
+ nfc_hal_main_send_message (p_msg);
+ /* do not free buffer. NCI VS code may keep it for processing later */
+ free_msg = FALSE;
+ break;
+
+ case NFC_HAL_EVT_POST_CORE_RESET:
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_W4_POST_INIT_DONE);
+
+ /* set NCI Control packet size from CORE_INIT_RSP */
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset + NCI_MSG_HDR_SIZE;
+ p += 5;
+ STREAM_TO_UINT8 (num_interfaces, p);
+ p += (num_interfaces + 3);
+ nfc_hal_cb.ncit_cb.nci_ctrl_size = *p;
+
+ /* start post initialization */
+ nfc_hal_cb.dev_cb.next_dm_config = NFC_HAL_DM_CONFIG_LPTD;
+ nfc_hal_cb.dev_cb.next_startup_vsc = 1;
+
+ nfc_hal_dm_config_nfcc ();
+ break;
+
+ case NFC_HAL_EVT_TO_START_QUICK_TIMER:
+ GKI_start_timer (NFC_HAL_QUICK_TIMER_ID, ((GKI_SECS_TO_TICKS (1) / QUICK_TIMER_TICKS_PER_SEC)), TRUE);
+ break;
+
+ case NFC_HAL_EVT_HCI:
+ nfc_hal_hci_evt_hdlr ((tNFC_HAL_HCI_EVENT_DATA *) p_msg);
+ break;
+
+
+ case NFC_HAL_EVT_CONTROL_GRANTED:
+ nfc_hal_dm_send_pend_cmd ();
+ break;
+
+ default:
+ break;
+ }
+
+ if (free_msg)
+ GKI_freebuf (p_msg);
+ }
+ }
+
+ /* Data waiting to be read from serial port */
+ if (event & NFC_HAL_TASK_EVT_DATA_RDY)
+ {
+ while (TRUE)
+ {
+ /* Read one byte to see if there is anything waiting to be read */
+ if (USERIAL_Read (USERIAL_NFC_PORT, &byte, 1) == 0)
+ {
+ break;
+ }
+
+ if (nfc_hal_nci_receive_msg (byte))
+ {
+ /* complete of receiving NCI message */
+ nfc_hal_nci_assemble_nci_msg ();
+ if (nfc_hal_cb.ncit_cb.p_rcv_msg)
+ {
+ if (nfc_hal_nci_preproc_rx_nci_msg (nfc_hal_cb.ncit_cb.p_rcv_msg))
+ {
+ /* Send NCI message to the stack */
+ nfc_hal_cb.p_data_cback(nfc_hal_cb.ncit_cb.p_rcv_msg->len, (UINT8 *)((nfc_hal_cb.ncit_cb.p_rcv_msg + 1)
+ + nfc_hal_cb.ncit_cb.p_rcv_msg->offset));
+
+ }
+ }
+
+ if (nfc_hal_cb.ncit_cb.p_rcv_msg)
+ {
+ GKI_freebuf(nfc_hal_cb.ncit_cb.p_rcv_msg);
+ nfc_hal_cb.ncit_cb.p_rcv_msg = NULL;
+ }
+ }
+ } /* while (TRUE) */
+ }
+
+ /* Process quick timer tick */
+ if (event & NFC_HAL_QUICK_TIMER_EVT_MASK)
+ {
+ nfc_hal_main_process_quick_timer_evt ();
+ }
+ }
+
+ NCI_TRACE_DEBUG0 ("nfc_hal_main_task terminated");
+
+ GKI_exit_task (GKI_get_taskid ());
+ return 0;
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcSetTraceLevel
+**
+** Description This function sets the trace level for HAL. If called with
+** a value of 0xFF, it simply returns the current trace level.
+**
+** Returns The new or current trace level
+**
+*******************************************************************************/
+UINT8 HAL_NfcSetTraceLevel (UINT8 new_level)
+{
+ if (new_level != 0xFF)
+ nfc_hal_cb.trace_level = new_level;
+
+ return (nfc_hal_cb.trace_level);
+}
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_nci.c b/halimpl/bcm2079x/hal/hal/nfc_hal_nci.c
new file mode 100644
index 0000000..977d7a4
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_nci.c
@@ -0,0 +1,871 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2010-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains function of the NFC unit to receive/process NCI/VS
+ * commands/responses.
+ *
+ ******************************************************************************/
+#include <string.h>
+#include "nfc_hal_int.h"
+#include "nfc_hal_post_reset.h"
+#include "userial.h"
+#include "nci_defs.h"
+
+
+/*****************************************************************************
+** Constants and types
+*****************************************************************************/
+
+/*****************************************************************************
+** Local function prototypes
+*****************************************************************************/
+
+/*******************************************************************************
+**
+** Function nfc_hal_nci_assemble_nci_msg
+**
+** Description This function is called to reassemble the received NCI
+** response/notification packet, if required.
+** (The data packets are posted to NFC task for reassembly)
+**
+** Returns void.
+**
+*******************************************************************************/
+void nfc_hal_nci_assemble_nci_msg (void)
+{
+ NFC_HDR *p_msg = nfc_hal_cb.ncit_cb.p_rcv_msg;
+ UINT8 u8;
+ UINT8 *p, *pp;
+ UINT8 hdr[2];
+ UINT8 *ps, *pd;
+ UINT16 size, needed;
+ BOOLEAN disp_again = FALSE;
+
+ if ((p_msg == NULL) || (p_msg->len < NCI_MSG_HDR_SIZE))
+ return;
+
+#ifdef DISP_NCI
+ DISP_NCI ((UINT8 *) (p_msg + 1) + p_msg->offset, (UINT16) (p_msg->len), TRUE);
+#endif
+
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+ u8 = *p++;
+ /* remove the PBF bit for potential reassembly later */
+ hdr[0] = u8 & ~NCI_PBF_MASK;
+ if ((u8 & NCI_MT_MASK) == NCI_MT_DATA)
+ {
+ /* clear the RFU in octet1 */
+ *(p) = 0;
+ /* data packet reassembly is performed in NFC task */
+ return;
+ }
+ else
+ {
+ *(p) &= NCI_OID_MASK;
+ }
+
+ hdr[1] = *p;
+ pp = hdr;
+ /* save octet0 and octet1 of an NCI header in layer_specific for the received packet */
+ STREAM_TO_UINT16 (p_msg->layer_specific, pp);
+
+ if (nfc_hal_cb.ncit_cb.p_frag_msg)
+ {
+ if (nfc_hal_cb.ncit_cb.p_frag_msg->layer_specific != p_msg->layer_specific)
+ {
+ /* check if these fragments are of the same NCI message */
+ NCI_TRACE_ERROR2 ("nfc_hal_nci_assemble_nci_msg() - different messages 0x%x, 0x%x!!", nfc_hal_cb.ncit_cb.p_frag_msg->layer_specific, p_msg->layer_specific);
+ nfc_hal_cb.ncit_cb.nci_ras |= NFC_HAL_NCI_RAS_ERROR;
+ }
+ else if (nfc_hal_cb.ncit_cb.nci_ras == 0)
+ {
+ disp_again = TRUE;
+ /* if not previous reassembly error, append the new fragment */
+ p_msg->offset += NCI_MSG_HDR_SIZE;
+ p_msg->len -= NCI_MSG_HDR_SIZE;
+ size = GKI_get_buf_size (nfc_hal_cb.ncit_cb.p_frag_msg);
+ needed = (NFC_HDR_SIZE + nfc_hal_cb.ncit_cb.p_frag_msg->len + nfc_hal_cb.ncit_cb.p_frag_msg->offset + p_msg->len);
+ if (size >= needed)
+ {
+ /* the buffer for reassembly is big enough to append the new fragment */
+ ps = (UINT8 *) (p_msg + 1) + p_msg->offset;
+ pd = (UINT8 *) (nfc_hal_cb.ncit_cb.p_frag_msg + 1) + nfc_hal_cb.ncit_cb.p_frag_msg->offset + nfc_hal_cb.ncit_cb.p_frag_msg->len;
+ memcpy (pd, ps, p_msg->len);
+ nfc_hal_cb.ncit_cb.p_frag_msg->len += p_msg->len;
+ /* adjust the NCI packet length */
+ pd = (UINT8 *) (nfc_hal_cb.ncit_cb.p_frag_msg + 1) + nfc_hal_cb.ncit_cb.p_frag_msg->offset + 2;
+ *pd = (UINT8) (nfc_hal_cb.ncit_cb.p_frag_msg->len - NCI_MSG_HDR_SIZE);
+ }
+ else
+ {
+ nfc_hal_cb.ncit_cb.nci_ras |= NFC_HAL_NCI_RAS_TOO_BIG;
+ NCI_TRACE_ERROR2 ("nfc_hal_nci_assemble_nci_msg() buffer overrun (%d + %d)!!", nfc_hal_cb.ncit_cb.p_frag_msg->len, p_msg->len);
+ }
+ }
+ /* we are done with this new fragment, free it */
+ GKI_freebuf (p_msg);
+ }
+ else
+ {
+ nfc_hal_cb.ncit_cb.p_frag_msg = p_msg;
+ }
+
+
+ if ((u8 & NCI_PBF_MASK) == NCI_PBF_NO_OR_LAST)
+ {
+ /* last fragment */
+ p_msg = nfc_hal_cb.ncit_cb.p_frag_msg;
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+ *p = u8; /* this should make the PBF flag as Last Fragment */
+ nfc_hal_cb.ncit_cb.p_frag_msg = NULL;
+
+ p_msg->layer_specific = nfc_hal_cb.ncit_cb.nci_ras;
+ /* still report the data packet, if the incoming packet is too big */
+ if (nfc_hal_cb.ncit_cb.nci_ras & NFC_HAL_NCI_RAS_ERROR)
+ {
+ /* NFCC reported NCI fragments for different NCI messages and this is the last fragment - drop it */
+ NCI_TRACE_ERROR0 ("nfc_hal_nci_assemble_nci_msg() clearing NCI_RAS_ERROR");
+ GKI_freebuf (p_msg);
+ p_msg = NULL;
+ }
+#ifdef DISP_NCI
+ if ((nfc_hal_cb.ncit_cb.nci_ras == 0) && (disp_again))
+ {
+ DISP_NCI ((UINT8 *) (p_msg + 1) + p_msg->offset, (UINT16) (p_msg->len), TRUE);
+ }
+#endif
+ /* clear the error flags, so the next NCI packet is clean */
+ nfc_hal_cb.ncit_cb.nci_ras = 0;
+ }
+ else
+ {
+ /* still reassembling */
+ p_msg = NULL;
+ }
+
+ nfc_hal_cb.ncit_cb.p_rcv_msg = p_msg;
+}
+
+/*****************************************************************************
+**
+** Function nfc_hal_nci_receive_nci_msg
+**
+** Description
+** Handle incoming data (NCI events) from the serial port.
+**
+** If there is data waiting from the serial port, this funciton reads the
+** data and parses it. Once an entire NCI message has been read, it sends
+** the message the the NFC_TASK for processing
+**
+*****************************************************************************/
+static BOOLEAN nfc_hal_nci_receive_nci_msg (tNFC_HAL_NCIT_CB *p_cb, UINT8 byte)
+{
+ UINT16 len;
+ BOOLEAN msg_received = FALSE;
+
+ switch (p_cb->rcv_state)
+ {
+ case NFC_HAL_RCV_NCI_MSG_ST:
+
+ /* Initialize rx parameters */
+ p_cb->rcv_state = NFC_HAL_RCV_NCI_HDR_ST;
+ p_cb->rcv_len = NCI_MSG_HDR_SIZE;
+
+ /* Start of new message. Allocate a buffer for message */
+ if ((p_cb->p_rcv_msg = (NFC_HDR *) GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
+ {
+ /* Initialize NFC_HDR */
+ p_cb->p_rcv_msg->len = 0;
+ p_cb->p_rcv_msg->event = 0;
+ p_cb->p_rcv_msg->offset = 0;
+
+ *((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len++) = byte;
+ }
+ else
+ {
+ NCI_TRACE_ERROR0 ("Unable to allocate buffer for incoming NCI message.");
+ }
+ p_cb->rcv_len--;
+ break;
+
+ case NFC_HAL_RCV_NCI_HDR_ST:
+
+ if (p_cb->p_rcv_msg)
+ {
+ *((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len++) = byte;
+ }
+
+ p_cb->rcv_len--;
+
+ /* Check if we read in entire NFC message header yet */
+ if (p_cb->rcv_len == 0)
+ {
+ p_cb->rcv_len = byte;
+
+ /* If non-zero payload, then go to receive-data state */
+ if (byte > 0)
+ {
+ p_cb->rcv_state = NFC_HAL_RCV_NCI_PAYLOAD_ST;
+ }
+ else
+ {
+ msg_received = TRUE;
+ p_cb->rcv_state = NFC_HAL_RCV_IDLE_ST;
+ }
+ }
+ break;
+
+ case NFC_HAL_RCV_NCI_PAYLOAD_ST:
+
+ p_cb->rcv_len--;
+ if (p_cb->p_rcv_msg)
+ {
+ *((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len++) = byte;
+
+ if (p_cb->rcv_len > 0)
+ {
+ /* Read in the rest of the message */
+ len = USERIAL_Read (USERIAL_NFC_PORT, ((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len), p_cb->rcv_len);
+ p_cb->p_rcv_msg->len += len;
+ p_cb->rcv_len -= len;
+ }
+ }
+
+ /* Check if we read in entire message yet */
+ if (p_cb->rcv_len == 0)
+ {
+ msg_received = TRUE;
+ p_cb->rcv_state = NFC_HAL_RCV_IDLE_ST;
+ }
+ break;
+ }
+
+ return (msg_received);
+}
+
+/*****************************************************************************
+**
+** Function nfc_hal_nci_receive_bt_msg
+**
+** Description
+** Handle incoming BRCM specific data from the serial port.
+**
+** If there is data waiting from the serial port, this funciton reads the
+** data and parses it. Once an entire message has been read, it returns
+** TRUE.
+**
+*****************************************************************************/
+static BOOLEAN nfc_hal_nci_receive_bt_msg (tNFC_HAL_NCIT_CB *p_cb, UINT8 byte)
+{
+ UINT16 len;
+ BOOLEAN msg_received = FALSE;
+
+ switch (p_cb->rcv_state)
+ {
+ case NFC_HAL_RCV_BT_MSG_ST:
+
+ /* Initialize rx parameters */
+ p_cb->rcv_state = NFC_HAL_RCV_BT_HDR_ST;
+ p_cb->rcv_len = HCIE_PREAMBLE_SIZE;
+
+ if ((p_cb->p_rcv_msg = (NFC_HDR *) GKI_getpoolbuf (NFC_HAL_NCI_POOL_ID)) != NULL)
+ {
+ /* Initialize NFC_HDR */
+ p_cb->p_rcv_msg->len = 0;
+ p_cb->p_rcv_msg->event = 0;
+ p_cb->p_rcv_msg->offset = 0;
+
+ *((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len++) = byte;
+ }
+ else
+ {
+ NCI_TRACE_ERROR0 ("[nfc] Unable to allocate buffer for incoming NCI message.");
+ }
+ p_cb->rcv_len--;
+ break;
+
+ case NFC_HAL_RCV_BT_HDR_ST:
+ if (p_cb->p_rcv_msg)
+ {
+ *((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len++) = byte;
+ }
+ p_cb->rcv_len--;
+
+ /* Check if we received entire preamble yet */
+ if (p_cb->rcv_len == 0)
+ {
+ /* Received entire preamble. Length is in the last byte(s) of the preamble */
+ p_cb->rcv_len = byte;
+
+ /* Verify that buffer is big enough to fit message */
+ if ((sizeof (NFC_HDR) + HCIE_PREAMBLE_SIZE + byte) > GKI_get_buf_size (p_cb->p_rcv_msg))
+ {
+ /* Message cannot fit into buffer */
+ GKI_freebuf (p_cb->p_rcv_msg);
+ p_cb->p_rcv_msg = NULL;
+
+ NCI_TRACE_ERROR0 ("Invalid length for incoming BT HCI message.");
+ }
+
+ /* Message length is valid */
+ if (byte)
+ {
+ /* Read rest of message */
+ p_cb->rcv_state = NFC_HAL_RCV_BT_PAYLOAD_ST;
+ }
+ else
+ {
+ /* Message has no additional parameters. (Entire message has been received) */
+ msg_received = TRUE;
+ p_cb->rcv_state = NFC_HAL_RCV_IDLE_ST; /* Next, wait for packet type of next message */
+ }
+ }
+ break;
+
+ case NFC_HAL_RCV_BT_PAYLOAD_ST:
+ p_cb->rcv_len--;
+ if (p_cb->p_rcv_msg)
+ {
+ *((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len++) = byte;
+
+ if (p_cb->rcv_len > 0)
+ {
+ /* Read in the rest of the message */
+ len = USERIAL_Read (USERIAL_NFC_PORT, ((UINT8 *) (p_cb->p_rcv_msg + 1) + p_cb->p_rcv_msg->offset + p_cb->p_rcv_msg->len), p_cb->rcv_len);
+ p_cb->p_rcv_msg->len += len;
+ p_cb->rcv_len -= len;
+ }
+ }
+
+ /* Check if we read in entire message yet */
+ if (p_cb->rcv_len == 0)
+ {
+ msg_received = TRUE;
+ p_cb->rcv_state = NFC_HAL_RCV_IDLE_ST; /* Next, wait for packet type of next message */
+ }
+ break;
+ }
+
+ /* If we received entire message */
+ if (msg_received)
+ {
+ /* Display protocol trace message */
+#if (NFC_HAL_TRACE_PROTOCOL == TRUE)
+ DispHciEvt (p_cb->p_rcv_msg);
+#endif
+ }
+
+ return (msg_received);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_nci_proc_rx_bt_msg
+**
+** Description Received BT message from NFCC
+**
+** Notify command complete if initializing NFCC
+** Forward BT message to NFC task
+**
+** Returns void
+**
+*******************************************************************************/
+static void nfc_hal_nci_proc_rx_bt_msg (void)
+{
+ UINT8 *p;
+ NFC_HDR *p_msg;
+ UINT16 opcode, old_opcode;
+ tNFC_HAL_BTVSC_CPLT vcs_cplt_params;
+ tNFC_HAL_BTVSC_CPLT_CBACK *p_cback = NULL;
+
+ /* if complete BT message is received successfully */
+ if (nfc_hal_cb.ncit_cb.p_rcv_msg)
+ {
+ p_msg = nfc_hal_cb.ncit_cb.p_rcv_msg;
+ NCI_TRACE_DEBUG1 ("nfc_hal_nci_proc_rx_bt_msg (): GOT an BT msgs init_sta:%d", nfc_hal_cb.dev_cb.initializing_state);
+ NCI_TRACE_DEBUG2 ("event: 0x%x, wait_rsp:0x%x", p_msg->event, nfc_hal_cb.ncit_cb.nci_wait_rsp);
+ /* increase the cmd window here */
+ if (nfc_hal_cb.ncit_cb.nci_wait_rsp == NFC_HAL_WAIT_RSP_PROP)
+ {
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+ if (*p == HCI_COMMAND_COMPLETE_EVT)
+ {
+ p += 3; /* code, len, cmd window */
+ STREAM_TO_UINT16 (opcode, p);
+ p = nfc_hal_cb.ncit_cb.last_hdr;
+ STREAM_TO_UINT16 (old_opcode, p);
+ if (opcode == old_opcode)
+ {
+ nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE;
+ p_cback = (tNFC_HAL_BTVSC_CPLT_CBACK *)nfc_hal_cb.ncit_cb.p_vsc_cback;
+ nfc_hal_cb.ncit_cb.p_vsc_cback = NULL;
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.ncit_cb.nci_wait_rsp_timer);
+ }
+ }
+ }
+
+ /* if initializing BRCM NFCC */
+ if ((nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE) ||
+ (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_CONTROL_DONE))
+ {
+ /* this is command complete event for baud rate update or download patch */
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+
+ p += 1; /* skip opcode */
+ STREAM_TO_UINT8 (vcs_cplt_params.param_len, p);
+
+ p += 1; /* skip num command packets */
+ STREAM_TO_UINT16 (vcs_cplt_params.opcode, p);
+
+ vcs_cplt_params.param_len -= 3;
+ vcs_cplt_params.p_param_buf = p;
+
+ if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_CONTROL_DONE)
+ {
+ NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_RELEASE_CONTROL_EVT, HAL_NFC_STATUS_OK);
+ }
+ if (p_cback)
+ {
+ nfc_hal_cb.ncit_cb.p_vsc_cback = NULL;
+ (*p_cback) (&vcs_cplt_params);
+ }
+
+ /* do not BT send message to NFC task */
+ GKI_freebuf (p_msg);
+ }
+ else
+ {
+ /* do not BT send message to NFC task */
+ GKI_freebuf(nfc_hal_cb.ncit_cb.p_rcv_msg);
+ }
+ nfc_hal_cb.ncit_cb.p_rcv_msg = NULL;
+ }
+}
+
+/*****************************************************************************
+**
+** Function nfc_hal_nci_receive_msg
+**
+** Description
+** Handle incoming data (NCI events) from the serial port.
+**
+** If there is data waiting from the serial port, this funciton reads the
+** data and parses it. Once an entire NCI message has been read, it sends
+** the message the the NFC_TASK for processing
+**
+*****************************************************************************/
+BOOLEAN nfc_hal_nci_receive_msg (UINT8 byte)
+{
+ tNFC_HAL_NCIT_CB *p_cb = &(nfc_hal_cb.ncit_cb);
+ BOOLEAN msg_received = FALSE;
+
+ if (p_cb->rcv_state == NFC_HAL_RCV_IDLE_ST)
+ {
+ /* if this is NCI message */
+ if (byte == HCIT_TYPE_NFC)
+ {
+ p_cb->rcv_state = NFC_HAL_RCV_NCI_MSG_ST;
+ }
+ /* if this is BT message */
+ else if (byte == HCIT_TYPE_EVENT)
+ {
+ p_cb->rcv_state = NFC_HAL_RCV_BT_MSG_ST;
+ }
+ else
+ {
+ NCI_TRACE_ERROR1 ("Unknown packet type drop this byte 0x%x", byte);
+ }
+ }
+ else if (p_cb->rcv_state <= NFC_HAL_RCV_NCI_PAYLOAD_ST)
+ {
+ msg_received = nfc_hal_nci_receive_nci_msg (p_cb, byte);
+ }
+ else
+ {
+ if (nfc_hal_nci_receive_bt_msg (p_cb, byte))
+ {
+ /* received BT message */
+ nfc_hal_nci_proc_rx_bt_msg ();
+ }
+ }
+
+ return (msg_received);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_nci_preproc_rx_nci_msg
+**
+** Description NFCC sends NCI message to DH while initializing NFCC
+** processing low power mode
+**
+** Returns TRUE, if NFC task need to receive NCI message
+**
+*******************************************************************************/
+BOOLEAN nfc_hal_nci_preproc_rx_nci_msg (NFC_HDR *p_msg)
+{
+ UINT8 *p, *pp, cid;
+ UINT8 mt, pbf, gid, op_code;
+ UINT8 payload_len;
+ UINT16 data_len;
+
+ NCI_TRACE_DEBUG0 ("nfc_hal_nci_preproc_rx_nci_msg()");
+
+ /* if initializing BRCM NFCC */
+ if (nfc_hal_cb.dev_cb.initializing_state != NFC_HAL_INIT_STATE_IDLE)
+ {
+ nfc_hal_dm_proc_msg_during_init (p_msg);
+ /* do not send message to NFC task while initializing NFCC */
+ return (FALSE);
+ }
+ else
+ {
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+ pp = p;
+ NCI_MSG_PRS_HDR0 (p, mt, pbf, gid);
+ NCI_MSG_PRS_HDR1 (p, op_code);
+ payload_len = *p++;
+
+ if (mt == NCI_MT_DATA)
+ {
+ if (nfc_hal_cb.hci_cb.b_check_clear_all_pipe_cmd)
+ {
+ NCI_DATA_PRS_HDR(pp, pbf, cid, data_len);
+ if (cid == nfc_hal_cb.hci_cb.hcp_conn_id)
+ {
+ nfc_hal_hci_handle_hcp_pkt (pp);
+ }
+
+ }
+ }
+
+ if (gid == NCI_GID_PROP) /* this is for hci netwk ntf */
+ {
+ if (mt == NCI_MT_NTF)
+ {
+ if (op_code == NCI_MSG_HCI_NETWK)
+ {
+ nfc_hal_hci_handle_hci_netwk_info ((UINT8 *) (p_msg + 1) + p_msg->offset);
+ }
+ }
+ }
+ else if (gid == NCI_GID_RF_MANAGE)
+ {
+ if (mt == NCI_MT_NTF)
+ {
+ if (op_code == NCI_MSG_RF_INTF_ACTIVATED)
+ {
+ if ((nfc_hal_cb.max_rf_credits) && (payload_len > 5))
+ {
+ /* API used wants to limit the RF data credits */
+ p += 5; /* skip RF disc id, interface, protocol, tech&mode, payload size */
+ if (*p > nfc_hal_cb.max_rf_credits)
+ {
+ NCI_TRACE_DEBUG2 ("RfDataCredits %d->%d", *p, nfc_hal_cb.max_rf_credits);
+ *p = nfc_hal_cb.max_rf_credits;
+ }
+ }
+ }
+ }
+ }
+ else if (gid == NCI_GID_CORE)
+ {
+ if (mt == NCI_MT_RSP)
+ {
+ if (op_code == NCI_MSG_CORE_CONN_CREATE)
+ {
+ if (nfc_hal_cb.hci_cb.b_wait_hcp_conn_create_rsp)
+ {
+ p++; /* skip status byte */
+ nfc_hal_cb.hci_cb.b_wait_hcp_conn_create_rsp = FALSE;
+ p++; /* skip buff size */
+ p++; /* num of buffers */
+ nfc_hal_cb.hci_cb.hcp_conn_id = *p;
+ nfc_hal_cb.hci_cb.b_check_clear_all_pipe_cmd = TRUE;
+ }
+ }
+ }
+ }
+ }
+
+ if (nfc_hal_cb.dev_cb.power_mode == NFC_HAL_POWER_MODE_FULL)
+ {
+ if (nfc_hal_cb.dev_cb.snooze_mode != NFC_HAL_LP_SNOOZE_MODE_NONE)
+ {
+ /* extend idle timer */
+ nfc_hal_dm_power_mode_execute (NFC_HAL_LP_RX_DATA_EVT);
+ }
+ }
+
+ return (TRUE);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_nci_add_nfc_pkt_type
+**
+** Description Add packet type (HCIT_TYPE_NFC)
+**
+** Returns TRUE, if NFCC can receive NCI message
+**
+*******************************************************************************/
+void nfc_hal_nci_add_nfc_pkt_type (NFC_HDR *p_msg)
+{
+ UINT8 *p;
+ BOOLEAN send_to_nfcc = TRUE;
+ UINT8 hcit;
+
+ /* add packet type in front of NCI header */
+ if (p_msg->offset > 0)
+ {
+ p_msg->offset--;
+ p_msg->len++;
+
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+ *p = HCIT_TYPE_NFC;
+ }
+ else
+ {
+ NCI_TRACE_ERROR0 ("nfc_hal_nci_add_nfc_pkt_type () : No space for packet type");
+ hcit = HCIT_TYPE_NFC;
+ USERIAL_Write (USERIAL_NFC_PORT, &hcit, 1);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nci_brcm_check_cmd_create_hcp_connection
+**
+** Description Check if this is command to create HCP connection
+**
+** Returns None
+**
+*******************************************************************************/
+static void nci_brcm_check_cmd_create_hcp_connection (NFC_HDR *p_msg)
+{
+ UINT8 *p;
+ UINT8 mt, pbf, gid, op_code;
+
+ nfc_hal_cb.hci_cb.b_wait_hcp_conn_create_rsp = FALSE;
+
+ p = (UINT8 *) (p_msg + 1) + p_msg->offset;
+
+ if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_IDLE)
+ {
+ NCI_MSG_PRS_HDR0 (p, mt, pbf, gid);
+ NCI_MSG_PRS_HDR1 (p, op_code);
+
+ if (gid == NCI_GID_CORE)
+ {
+ if (mt == NCI_MT_CMD)
+ {
+ if (op_code == NCI_MSG_CORE_CONN_CREATE)
+ {
+ if ( ((NCI_CORE_PARAM_SIZE_CON_CREATE + 4) == *p++)
+ &&(NCI_DEST_TYPE_NFCEE == *p++)
+ &&(1 == *p++)
+ &&(NCI_CON_CREATE_TAG_NFCEE_VAL == *p++)
+ &&(2 == *p++) )
+ {
+ p++;
+ if (NCI_NFCEE_INTERFACE_HCI_ACCESS == *p)
+ {
+ nfc_hal_cb.hci_cb.b_wait_hcp_conn_create_rsp = TRUE;
+ return;
+ }
+ }
+
+ }
+ }
+ }
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_nci_send_cmd
+**
+** Description Send NCI command to the transport
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_nci_send_cmd (NFC_HDR *p_buf)
+{
+ BOOLEAN continue_to_process = TRUE;
+ UINT8 *ps, *pd;
+ UINT16 max_len;
+ UINT16 buf_len, offset;
+ UINT8 *p;
+ UINT8 hdr[NCI_MSG_HDR_SIZE];
+ UINT8 nci_ctrl_size = nfc_hal_cb.ncit_cb.nci_ctrl_size;
+ UINT8 delta = 0;
+
+ nci_brcm_check_cmd_create_hcp_connection ((NFC_HDR*) p_buf);
+
+ /* check low power mode state */
+ continue_to_process = nfc_hal_dm_power_mode_execute (NFC_HAL_LP_TX_DATA_EVT);
+
+ if (!continue_to_process)
+ {
+ /* save the command to be sent until NFCC is free. */
+ nfc_hal_cb.ncit_cb.p_pend_cmd = p_buf;
+ return;
+ }
+
+ max_len = nci_ctrl_size + NCI_MSG_HDR_SIZE;
+ buf_len = p_buf->len;
+ offset = p_buf->offset;
+#ifdef DISP_NCI
+ if (buf_len > max_len)
+ {
+ /* this command needs to be fragmented. display the complete packet first */
+ DISP_NCI ((UINT8 *) (p_buf + 1) + p_buf->offset, p_buf->len, FALSE);
+ }
+#endif
+ ps = (UINT8 *) (p_buf + 1) + p_buf->offset;
+ memcpy (hdr, ps, NCI_MSG_HDR_SIZE);
+ while (buf_len > max_len)
+ {
+ NCI_TRACE_DEBUG2 ("buf_len (%d) > max_len (%d)", buf_len, max_len);
+ /* the NCI command is bigger than the NFCC Max Control Packet Payload Length
+ * fragment the command */
+
+ p_buf->len = max_len;
+ ps = (UINT8 *) (p_buf + 1) + p_buf->offset;
+ /* mark the control packet as fragmented */
+ *ps |= NCI_PBF_ST_CONT;
+ /* adjust the length of this fragment */
+ ps += 2;
+ *ps = nci_ctrl_size;
+
+ /* add NCI packet type in front of message */
+ nfc_hal_nci_add_nfc_pkt_type (p_buf);
+
+ /* send this fragment to transport */
+ p = (UINT8 *) (p_buf + 1) + p_buf->offset;
+
+#ifdef DISP_NCI
+ delta = p_buf->len - max_len;
+ DISP_NCI (p + delta, (UINT16) (p_buf->len - delta), FALSE);
+#endif
+ USERIAL_Write (USERIAL_NFC_PORT, p, p_buf->len);
+
+ /* adjust the len and offset to reflect that part of the command is already sent */
+ buf_len -= nci_ctrl_size;
+ offset += nci_ctrl_size;
+ NCI_TRACE_DEBUG2 ("p_buf->len: %d buf_len (%d)", p_buf->len, buf_len);
+ p_buf->len = buf_len;
+ p_buf->offset = offset;
+ pd = (UINT8 *) (p_buf + 1) + p_buf->offset;
+ /* restore the NCI header */
+ memcpy (pd, hdr, NCI_MSG_HDR_SIZE);
+ pd += 2;
+ *pd = (UINT8) (p_buf->len - NCI_MSG_HDR_SIZE);
+ }
+
+ NCI_TRACE_DEBUG1 ("p_buf->len: %d", p_buf->len);
+
+ /* add NCI packet type in front of message */
+ nfc_hal_nci_add_nfc_pkt_type (p_buf);
+
+ /* send this fragment to transport */
+ p = (UINT8 *) (p_buf + 1) + p_buf->offset;
+
+#ifdef DISP_NCI
+ delta = p_buf->len - buf_len;
+ DISP_NCI (p + delta, (UINT16) (p_buf->len - delta), FALSE);
+#endif
+ USERIAL_Write (USERIAL_NFC_PORT, p, p_buf->len);
+
+ GKI_freebuf (p_buf);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_nci_cmd_timeout_cback
+**
+** Description callback function for timeout
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_nci_cmd_timeout_cback (void *p_tle)
+{
+ TIMER_LIST_ENT *p_tlent = (TIMER_LIST_ENT *)p_tle;
+
+ NCI_TRACE_DEBUG0 ("nfc_hal_nci_cmd_timeout_cback ()");
+
+ nfc_hal_cb.ncit_cb.nci_wait_rsp = NFC_HAL_WAIT_RSP_NONE;
+
+ if (p_tlent->event == NFC_HAL_TTYPE_NCI_WAIT_RSP)
+ {
+ if (nfc_hal_cb.dev_cb.initializing_state <= NFC_HAL_INIT_STATE_W4_PATCH_INFO)
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_main_pre_init_done (HAL_NFC_STATUS_ERR_CMD_TIMEOUT);
+ }
+ else if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_APP_COMPLETE)
+ {
+ if (nfc_hal_cb.prm.state != NFC_HAL_PRM_ST_IDLE)
+ {
+ nfc_hal_prm_process_timeout (NULL);
+ }
+ else
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_main_pre_init_done (HAL_NFC_STATUS_ERR_CMD_TIMEOUT);
+ }
+ }
+ else if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_POST_INIT_DONE)
+ {
+ NFC_HAL_SET_INIT_STATE (NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_POST_INIT_CPLT_EVT, HAL_NFC_STATUS_ERR_CMD_TIMEOUT);
+ }
+ else if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_CONTROL_DONE)
+ {
+ NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_RELEASE_CONTROL_EVT, HAL_NFC_STATUS_ERR_CMD_TIMEOUT);
+ }
+ else if (nfc_hal_cb.dev_cb.initializing_state == NFC_HAL_INIT_STATE_W4_PREDISCOVER_DONE)
+ {
+ NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_IDLE);
+ nfc_hal_cb.p_stack_cback (HAL_NFC_PRE_DISCOVER_CPLT_EVT, HAL_NFC_STATUS_ERR_CMD_TIMEOUT);
+ }
+ }
+}
+
+
+/*******************************************************************************
+**
+** Function HAL_NfcSetMaxRfDataCredits
+**
+** Description This function sets the maximum RF data credit for HAL.
+** If 0, use the value reported from NFCC.
+**
+** Returns none
+**
+*******************************************************************************/
+void HAL_NfcSetMaxRfDataCredits (UINT8 max_credits)
+{
+ NCI_TRACE_DEBUG2 ("HAL_NfcSetMaxRfDataCredits %d->%d", nfc_hal_cb.max_rf_credits, max_credits);
+ nfc_hal_cb.max_rf_credits = max_credits;
+}
diff --git a/halimpl/bcm2079x/hal/hal/nfc_hal_prm.c b/halimpl/bcm2079x/hal/hal/nfc_hal_prm.c
new file mode 100644
index 0000000..7fa9236
--- /dev/null
+++ b/halimpl/bcm2079x/hal/hal/nfc_hal_prm.c
@@ -0,0 +1,1119 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+#include <string.h>
+#include "nfc_hal_int.h"
+#include "userial.h"
+
+/*****************************************************************************
+* Definitions
+*****************************************************************************/
+
+/* Internal flags */
+#define NFC_HAL_PRM_FLAGS_USE_PATCHRAM_BUF 0x01 /* Application provided patchram in a single buffer */
+#define NFC_HAL_PRM_FLAGS_RFU 0x02 /* Reserved for future use */
+#define NFC_HAL_PRM_FLAGS_SIGNATURE_SENT 0x04 /* Signature sent to NFCC */
+#define NFC_HAL_PRM_FLAGS_I2C_FIX_REQUIRED 0x08 /* PreI2C patch required */
+#define NFC_HAL_PRM_FLAGS_NO_NVM 0x10 /* Not NVM available (patch downloaded to SRAM) */
+#define NFC_HAL_PRM_FLAGS_SUPPORT_RESET_NTF 0x20 /* Support RESET_NTF from NFCC after sending signature */
+#define NFC_HAL_PRM_FLAGS_NVM_FPM_CORRUPTED 0x40 /* FPM patch in NVM failed CRC check */
+#define NFC_HAL_PRM_FLAGS_NVM_LPM_CORRUPTED 0x80 /* LPM patch in NVM failed CRC check */
+
+/* Secure patch download definitions */
+#define NFC_HAL_PRM_NCD_PATCHFILE_HDR_LEN 7 /* PRJID + MAJORVER + MINORVER + COUNT */
+#define NFC_HAL_PRM_NCD_PATCH_VERSION_LEN 16
+
+#define NFC_HAL_PRM_SPD_PRE_DOWNLOAD_DELAY (500) /* Delay before starting to patch download (in ms) */
+
+/* Enumeration of power modes IDs */
+#define NFC_HAL_PRM_SPD_POWER_MODE_LPM 0
+#define NFC_HAL_PRM_SPD_POWER_MODE_FPM 1
+
+/* Version string for BCM20791B3 */
+const UINT8 NFC_HAL_PRM_BCM20791B3_STR[] = "20791B3";
+#define NFC_HAL_PRM_BCM20791B3_STR_LEN (sizeof (NFC_HAL_PRM_BCM20791B3_STR)-1)
+
+#define NFC_HAL_PRM_SPD_TOUT (6000) /* timeout for SPD events (in ms) */
+#define NFC_HAL_PRM_END_DELAY (250) /* delay before sending any new command (ms)*/
+
+/* command to get currently downloaded patch version */
+static UINT8 nfc_hal_prm_get_patch_version_cmd [NCI_MSG_HDR_SIZE] =
+{
+ NCI_MTS_CMD|NCI_GID_PROP,
+ NCI_MSG_GET_PATCH_VERSION,
+ 0x00
+};
+
+#if (NFC_HAL_PRM_DEBUG == TRUE)
+#define NFC_HAL_PRM_STATE(str) NCI_TRACE_DEBUG2 ("%s st: %d", str, nfc_hal_cb.prm.state)
+#else
+#define NFC_HAL_PRM_STATE(str)
+#endif
+
+void nfc_hal_prm_post_baud_update (tHAL_NFC_STATUS status);
+
+/*****************************************************************************
+** Extern variable from nfc_hal_dm_cfg.c
+*****************************************************************************/
+extern BOOLEAN nfc_hal_prm_nvm_required;
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_spd_handle_download_complete
+**
+** Description Patch download complete (for secure patch download)
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_spd_handle_download_complete (UINT8 event)
+{
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_IDLE;
+
+ /* Notify application now */
+ if (nfc_hal_cb.prm.p_cback)
+ (nfc_hal_cb.prm.p_cback) (event);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_spd_send_next_segment
+**
+** Description Send next patch segment (for secure patch download)
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_spd_send_next_segment (void)
+{
+ UINT8 *p_src;
+ UINT16 len, offset = nfc_hal_cb.prm.cur_patch_offset;
+ UINT8 hcit, oid, hdr0, type;
+ UINT8 chipverlen;
+ UINT8 chipverstr[NCI_SPD_HEADER_CHIPVER_LEN];
+ UINT8 patch_hdr_size = NCI_MSG_HDR_SIZE + 1; /* 1 is for HCIT */
+
+ /* Validate that segment is at least big enought to have NCI_MSG_HDR_SIZE + 1 (hcit) */
+ if (nfc_hal_cb.prm.cur_patch_len_remaining < patch_hdr_size)
+ {
+ NCI_TRACE_ERROR0 ("Unexpected end of patch.");
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT);
+ return;
+ }
+
+ /* Parse NCI command header */
+ p_src = (UINT8*) (nfc_hal_cb.prm.p_cur_patch_data + offset);
+ STREAM_TO_UINT8 (hcit, p_src);
+ STREAM_TO_UINT8 (hdr0, p_src);
+ STREAM_TO_UINT8 (oid, p_src);
+ STREAM_TO_UINT8 (len, p_src);
+ STREAM_TO_UINT8 (type, p_src);
+
+
+ /* Update number of bytes comsumed */
+ nfc_hal_cb.prm.cur_patch_offset += (len + patch_hdr_size);
+ nfc_hal_cb.prm.cur_patch_len_remaining -= (len + patch_hdr_size);
+
+ /* Check if sending signature byte */
+ if ( (oid == NCI_MSG_SECURE_PATCH_DOWNLOAD )
+ &&(type == NCI_SPD_TYPE_SIGNATURE) )
+ {
+ nfc_hal_cb.prm.flags |= NFC_HAL_PRM_FLAGS_SIGNATURE_SENT;
+ }
+ /* Check for header */
+ else if ( (oid == NCI_MSG_SECURE_PATCH_DOWNLOAD )
+ &&(type == NCI_SPD_TYPE_HEADER) )
+ {
+ /* Check if patch is for BCM20791B3 */
+ p_src += NCI_SPD_HEADER_OFFSET_CHIPVERLEN;
+ STREAM_TO_UINT8 (chipverlen, p_src);
+ STREAM_TO_ARRAY (chipverstr, p_src, NCI_SPD_HEADER_CHIPVER_LEN);
+
+ if (memcmp (NFC_HAL_PRM_BCM20791B3_STR, chipverstr, NFC_HAL_PRM_BCM20791B3_STR_LEN) == 0)
+ {
+ /* Patch is for BCM2079B3 - do not wait for RESET_NTF after patch download */
+ nfc_hal_cb.prm.flags &= ~NFC_HAL_PRM_FLAGS_SUPPORT_RESET_NTF;
+ }
+ else
+ {
+ /* Patch is for BCM2079B4 or newer - wait for RESET_NTF after patch download */
+ nfc_hal_cb.prm.flags |= NFC_HAL_PRM_FLAGS_SUPPORT_RESET_NTF;
+ }
+ }
+
+ /* Send the command (not including HCIT here) */
+ nfc_hal_dm_send_nci_cmd ((UINT8*) (nfc_hal_cb.prm.p_cur_patch_data + offset + 1), (UINT8) (len + NCI_MSG_HDR_SIZE),
+ nfc_hal_prm_nci_command_complete_cback);
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_spd_handle_next_patch_start
+**
+** Description Handle start of next patch (for secure patch download)
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_spd_handle_next_patch_start (void)
+{
+ UINT32 cur_patch_mask;
+ UINT32 cur_patch_len;
+ BOOLEAN found_patch_to_download = FALSE;
+
+ while (!found_patch_to_download)
+ {
+ /* Get length of current patch */
+ cur_patch_len = nfc_hal_cb.prm.spd_patch_desc[nfc_hal_cb.prm.spd_cur_patch_idx].len;
+
+ /* Check if this is a patch we need to download */
+ cur_patch_mask = ((UINT32) 1 << nfc_hal_cb.prm.spd_patch_desc[nfc_hal_cb.prm.spd_cur_patch_idx].power_mode);
+ if (nfc_hal_cb.prm.spd_patch_needed_mask & cur_patch_mask)
+ {
+ found_patch_to_download = TRUE;
+ }
+ else
+ {
+ /* Do not need to download this patch. Skip to next patch */
+ NCI_TRACE_DEBUG1 ("Skipping patch for power_mode %i.", nfc_hal_cb.prm.spd_patch_desc[nfc_hal_cb.prm.spd_cur_patch_idx].power_mode);
+
+ nfc_hal_cb.prm.spd_cur_patch_idx++;
+ if (nfc_hal_cb.prm.spd_cur_patch_idx >= nfc_hal_cb.prm.spd_patch_count)
+ {
+ /* No more to download */
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_COMPLETE_EVT);
+ return;
+ }
+ else if (!(nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_USE_PATCHRAM_BUF))
+ {
+ /* Notify adaptation layer to call HAL_NfcPrmDownloadContinue with the next patch header */
+ (nfc_hal_cb.prm.p_cback) (NFC_HAL_PRM_SPD_GET_NEXT_PATCH);
+ return;
+ }
+ else
+ {
+ /* Patch in buffer. Skip over current patch. Check next patch */
+ nfc_hal_cb.prm.cur_patch_len_remaining -= (UINT16) cur_patch_len;
+ nfc_hal_cb.prm.cur_patch_offset += (UINT16) cur_patch_len;
+ }
+ }
+ }
+
+
+ /* Begin downloading patch */
+ NCI_TRACE_DEBUG1 ("Downloading patch for power_mode %i.", nfc_hal_cb.prm.spd_patch_desc[nfc_hal_cb.prm.spd_cur_patch_idx].power_mode);
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_DOWNLOADING;
+ nfc_hal_prm_spd_send_next_segment ();
+}
+
+#if (defined (NFC_HAL_PRE_I2C_PATCH_INCLUDED) && (NFC_HAL_PRE_I2C_PATCH_INCLUDED == TRUE))
+/*******************************************************************************
+**
+** Function nfc_hal_prm_spd_download_i2c_fix
+**
+** Description Start downloading patch for i2c fix
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_spd_download_i2c_fix (void)
+{
+ UINT8 *p, *p_start;
+ UINT16 patchfile_project_id;
+ UINT16 patchfile_ver_major;
+ UINT16 patchfile_ver_minor;
+ UINT16 patchfile_patchsize;
+ UINT8 u8;
+
+ NCI_TRACE_DEBUG0 ("Downloading I2C fix...");
+
+ /* Save pointer and offset of patchfile, so we can resume after downloading the i2c fix */
+ nfc_hal_cb.prm.spd_patch_offset = nfc_hal_cb.prm.cur_patch_offset;
+ nfc_hal_cb.prm.spd_patch_len_remaining = nfc_hal_cb.prm.cur_patch_len_remaining;
+
+ /* Initialize pointers for downloading i2c fix */
+ nfc_hal_cb.prm.p_cur_patch_data = nfc_hal_cb.prm_i2c.p_patch;
+ nfc_hal_cb.prm.cur_patch_offset = 0;
+ nfc_hal_cb.prm.cur_patch_len_remaining = nfc_hal_cb.prm_i2c.len;
+
+ /* Parse the i2c patchfile */
+ if (nfc_hal_cb.prm.cur_patch_len_remaining >= NFC_HAL_PRM_NCD_PATCHFILE_HDR_LEN)
+ {
+ /* Parse patchfile header */
+ p = (UINT8 *) nfc_hal_cb.prm.p_cur_patch_data;
+ p_start = p;
+ STREAM_TO_UINT16 (patchfile_project_id, p);
+ STREAM_TO_UINT16 (patchfile_ver_major, p);
+ STREAM_TO_UINT16 (patchfile_ver_minor, p);
+
+ /* RFU */
+ p++;
+
+ /* Check how many patches are in the patch file */
+ STREAM_TO_UINT8 (u8, p);
+
+ /* Should only be one patch */
+ if (u8 > 1)
+ {
+ NCI_TRACE_ERROR1 ("Invalid i2c fix: invalid number of patches (%i)", u8);
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT);
+ return;
+ }
+
+
+ /* Get info about the i2c patch*/
+ STREAM_TO_UINT8 (u8, p); /* power mode (not needed for i2c patch) */
+ STREAM_TO_UINT16 (patchfile_patchsize, p); /* size of patch */
+
+ /* 5 byte RFU */
+ p += 5;
+
+ /* Adjust length to exclude patchfiloe header */
+ nfc_hal_cb.prm.cur_patch_len_remaining -= (UINT16) (p - p_start); /* Adjust size of patchfile */
+ nfc_hal_cb.prm.cur_patch_offset += (UINT16) (p - p_start); /* Bytes of patchfile transmitted/processed so far */
+
+ /* Begin sending patch to the NFCC */
+ nfc_hal_prm_spd_send_next_segment ();
+ }
+ else
+ {
+ /* ERROR: Bad length for patchfile */
+ NCI_TRACE_ERROR0 ("Invalid i2c fix: unexpected end of patch");
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT);
+ }
+}
+#endif /* NFC_HAL_PRE_I2C_PATCH_INCLUDED */
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_spd_check_version
+**
+** Description Check patchfile version with current downloaded version
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_spd_check_version (void)
+{
+ UINT8 *p, *p_start, i;
+ UINT32 patchfile_patch_present_mask;
+ UINT16 patchfile_project_id;
+ UINT16 patchfile_ver_major = 0;
+ UINT16 patchfile_ver_minor;
+ UINT16 patchfile_patchsize;
+
+ UINT8 return_code = NFC_HAL_PRM_COMPLETE_EVT;
+
+ /* Initialize patchfile offset pointers */
+ p = p_start = NULL;
+ patchfile_patchsize = 0;
+
+ /* Get patchfile version */
+ if (nfc_hal_cb.prm.cur_patch_len_remaining >= NFC_HAL_PRM_NCD_PATCHFILE_HDR_LEN)
+ {
+ /* Parse patchfile header */
+ p = (UINT8 *) nfc_hal_cb.prm.p_cur_patch_data;
+ p_start = p;
+ STREAM_TO_UINT16 (patchfile_project_id, p);
+ STREAM_TO_UINT16 (patchfile_ver_major, p);
+ STREAM_TO_UINT16 (patchfile_ver_minor, p);
+
+ /* RFU */
+ p++;
+
+ /* Check how many patches are in the patch file */
+ STREAM_TO_UINT8 (nfc_hal_cb.prm.spd_patch_count, p);
+
+ if (nfc_hal_cb.prm.spd_patch_count > NFC_HAL_PRM_MAX_PATCH_COUNT)
+ {
+ NCI_TRACE_ERROR2 ("Unsupported patchfile (number of patches (%i) exceeds maximum (%i)",
+ nfc_hal_cb.prm.spd_patch_count, NFC_HAL_PRM_MAX_PATCH_COUNT);
+ }
+
+ /* Mask of patches that are present in the patchfile */
+ patchfile_patch_present_mask = 0;
+
+ /* Get lengths for each patch */
+ for (i = 0; i < nfc_hal_cb.prm.spd_patch_count; i++)
+ {
+ /* Get power mode for this patch */
+ STREAM_TO_UINT8 (nfc_hal_cb.prm.spd_patch_desc[i].power_mode, p);
+
+ /* Update mask of power-modes present in the patchfile */
+ patchfile_patch_present_mask |= ((UINT32) 1 << nfc_hal_cb.prm.spd_patch_desc[i].power_mode);
+
+ /* Get length of patch */
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_patch_desc[i].len, p);
+
+ /* Add total size of patches */
+ patchfile_patchsize += nfc_hal_cb.prm.spd_patch_desc[i].len;
+
+ /* 5 byte RFU */
+ p += 5;
+ }
+
+ /* Adjust offset to after the patch file header */
+ nfc_hal_cb.prm.cur_patch_offset += (UINT16) (p - p_start); /* Bytes of patchfile transmitted/processed so far */
+ nfc_hal_cb.prm.cur_patch_len_remaining -= (UINT16) (p - p_start); /* Adjust size of patchfile */
+
+
+ NCI_TRACE_DEBUG6 ("Patchfile info: ProjID=0x%04x, Ver=%i.%i, Num patches=%i, PatchMask=0x%08x, PatchSize=%i",
+ patchfile_project_id, patchfile_ver_major, patchfile_ver_minor,
+ nfc_hal_cb.prm.spd_patch_count, patchfile_patch_present_mask, patchfile_patchsize);
+
+ /*********************************************************************
+ * Version check of patchfile against NVM
+ *********************************************************************/
+
+#if (!defined (NFC_HAL_PRM_SKIP_VERSION_CHECK) || (NFC_HAL_PRM_SKIP_VERSION_CHECK == FALSE))
+ /* Download the patchfile if no patches in NVM */
+ if ((nfc_hal_cb.prm.spd_project_id == 0) || (nfc_hal_cb.prm.spd_nvm_patch_mask == 0))
+ {
+ /* No patch in NVM, need to download all */
+ nfc_hal_cb.prm.spd_patch_needed_mask = patchfile_patch_present_mask;
+
+ NCI_TRACE_DEBUG2 ("No previous patch detected. Downloading patch %i.%i",
+ patchfile_ver_major, patchfile_ver_minor);
+ }
+ /* Skip download if project ID of patchfile does not match NVM */
+ else if (nfc_hal_cb.prm.spd_project_id != patchfile_project_id)
+ {
+ /* Project IDs mismatch */
+ NCI_TRACE_DEBUG2 ("Patch download skipped: Mismatched Project ID (NVM ProjId: 0x%04x, Patchfile ProjId: 0x%04x)",
+ nfc_hal_cb.prm.spd_project_id, patchfile_project_id);
+
+ return_code = NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT;
+ }
+ /* Skip download if version of patchfile older or equal to version in NVM */
+ /* unless NVM is corrupted (then don't skip download if patchfile has the same major ver)*/
+ else if ( (nfc_hal_cb.prm.spd_ver_major > patchfile_ver_major)
+ ||( (nfc_hal_cb.prm.spd_ver_major == patchfile_ver_major) && (nfc_hal_cb.prm.spd_ver_minor == patchfile_ver_minor)
+ && !((patchfile_patch_present_mask & ( 1 << NFC_HAL_PRM_SPD_POWER_MODE_LPM)) && (nfc_hal_cb.prm.spd_lpm_patch_size == 0)) /* Do not skip download: patchfile has LPM, but NVM does not */
+ && !((patchfile_patch_present_mask & ( 1 << NFC_HAL_PRM_SPD_POWER_MODE_FPM)) && (nfc_hal_cb.prm.spd_fpm_patch_size == 0)) /* Do not skip download: patchfile has FPM, but NVM does not */
+ && !(nfc_hal_cb.prm.flags & (NFC_HAL_PRM_FLAGS_NVM_FPM_CORRUPTED |NFC_HAL_PRM_FLAGS_NVM_LPM_CORRUPTED)) ) )
+ {
+ /* NVM version is newer than patchfile */
+ NCI_TRACE_DEBUG2 ("Patch download skipped. NVM patch (version %i.%i) is newer than the patchfile ",
+ nfc_hal_cb.prm.spd_ver_major, nfc_hal_cb.prm.spd_ver_minor);
+
+ return_code = NFC_HAL_PRM_COMPLETE_EVT;
+ }
+ /* Remaining cases: patchfile major version is newer than NVM; or major version is the same with different minor version */
+ /* Download all patches in the patchfile */
+ else
+ {
+ nfc_hal_cb.prm.spd_patch_needed_mask = patchfile_patch_present_mask;
+
+ NCI_TRACE_DEBUG4 ("Downloading patch version: %i.%i (previous version in NVM: %i.%i)...",
+ patchfile_ver_major, patchfile_ver_minor,
+ nfc_hal_cb.prm.spd_ver_major, nfc_hal_cb.prm.spd_ver_minor);
+ }
+#else /* NFC_HAL_PRM_SKIP_VERSION_CHECK */
+ nfc_hal_cb.prm.spd_patch_needed_mask = patchfile_patch_present_mask;
+#endif
+ }
+ else
+ {
+ /* Invalid patch file header */
+ NCI_TRACE_ERROR0 ("Invalid patch file header.");
+
+ return_code = NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT;
+ }
+
+ /* If we need to download anything, get the first patch to download */
+ if (nfc_hal_cb.prm.spd_patch_needed_mask)
+ {
+ NCI_TRACE_ERROR4 ("Downloading patch version: %i.%i (previous version in NVM: %i.%i)...",
+ patchfile_ver_major, patchfile_ver_minor,
+ nfc_hal_cb.prm.spd_ver_major, nfc_hal_cb.prm.spd_ver_minor);
+#if (defined (NFC_HAL_PRE_I2C_PATCH_INCLUDED) && (NFC_HAL_PRE_I2C_PATCH_INCLUDED == TRUE))
+ /* Check if I2C patch is needed: if */
+ /* - I2C patch file was provided using HAL_NfcPrmSetI2cPatch, and */
+ /* - current patch in NVM has ProjectID=0, or */
+ /* FPM is not present or corrupted, or */
+ /* or patchfile is major-ver 76+ */
+ if ( (nfc_hal_cb.prm_i2c.p_patch)
+ &&( (nfc_hal_cb.prm.spd_project_id == 0)
+ ||(nfc_hal_cb.prm.spd_fpm_patch_size == 0)
+ ||(nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_NVM_FPM_CORRUPTED)
+ ||(patchfile_ver_major >= 76)))
+ {
+ NCI_TRACE_DEBUG0 ("I2C patch fix required.");
+ nfc_hal_cb.prm.flags |= NFC_HAL_PRM_FLAGS_I2C_FIX_REQUIRED;
+
+ /* Download i2c fix first */
+ nfc_hal_prm_spd_download_i2c_fix ();
+ return;
+ }
+#endif /* NFC_HAL_PRE_I2C_PATCH_INCLUDED */
+
+ /* Download first segment */
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_GET_PATCH_HEADER;
+ if (!(nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_USE_PATCHRAM_BUF))
+ {
+ /* Notify adaptation layer to call HAL_NfcPrmDownloadContinue with the next patch segment */
+ (nfc_hal_cb.prm.p_cback) (NFC_HAL_PRM_SPD_GET_NEXT_PATCH);
+ }
+ else
+ {
+ nfc_hal_prm_spd_handle_next_patch_start ();
+ }
+ }
+ else
+ {
+ static BOOLEAN firstTime = TRUE;
+ if (firstTime) {
+ NCI_TRACE_ERROR2 ("BCM2079x: NVM patch version is %d.%d",
+ nfc_hal_cb.prm.spd_ver_major, nfc_hal_cb.prm.spd_ver_minor);
+ firstTime = FALSE;
+ }
+ /* Download complete */
+ nfc_hal_prm_spd_handle_download_complete (return_code);
+ }
+}
+
+#if (NFC_HAL_TRACE_VERBOSE == TRUE)
+/*******************************************************************************
+**
+** Function nfc_hal_prm_spd_status_str
+**
+** Description Return status string for a given spd status code
+**
+** Returns Status string
+**
+*******************************************************************************/
+UINT8 *nfc_hal_prm_spd_status_str (UINT8 spd_status_code)
+{
+ char *p_str;
+
+ switch (spd_status_code)
+ {
+ case NCI_STATUS_SPD_ERROR_DEST:
+ p_str = "SPD_ERROR_DEST";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_PROJECTID:
+ p_str = "SPD_ERROR_PROJECTID";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_CHIPVER:
+ p_str = "SPD_ERROR_CHIPVER";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_MAJORVER:
+ p_str = "SPD_ERROR_MAJORVER";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_INVALID_PARAM:
+ p_str = "SPD_ERROR_INVALID_PARAM";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_INVALID_SIG:
+ p_str = "SPD_ERROR_INVALID_SIG";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_NVM_CORRUPTED:
+ p_str = "SPD_ERROR_NVM_CORRUPTED";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_PWR_MODE:
+ p_str = "SPD_ERROR_PWR_MODE";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_MSG_LEN:
+ p_str = "SPD_ERROR_MSG_LEN";
+ break;
+
+ case NCI_STATUS_SPD_ERROR_PATCHSIZE:
+ p_str = "SPD_ERROR_PATCHSIZE";
+ break;
+
+ default:
+ p_str = "Unspecified Error";
+ break;
+
+ }
+
+ return ((UINT8*) p_str);
+}
+#endif /* (NFC_HAL_TRACE_VERBOSE == TRUE) */
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_nci_command_complete_cback
+**
+** Description Callback for NCI vendor specific command complete
+** (for secure patch download)
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_nci_command_complete_cback (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data)
+{
+ UINT8 status, u8;
+ UINT8 *p;
+ UINT32 post_signature_delay;
+
+ NFC_HAL_PRM_STATE ("nfc_hal_prm_nci_command_complete_cback");
+
+ /* Stop the command-timeout timer */
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.prm.timer);
+
+ /* Skip over NCI header */
+ p = p_data + NCI_MSG_HDR_SIZE;
+
+ /* Handle GET_PATCH_VERSION Rsp */
+ if (event == NFC_VS_GET_PATCH_VERSION_EVT)
+ {
+ /* Get project id */
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_project_id, p);
+
+ /* RFU */
+ p++;
+
+ /* Get chip version string */
+ STREAM_TO_UINT8 (u8, p);
+ p += NFC_HAL_PRM_NCD_PATCH_VERSION_LEN;
+
+ /* Get major/minor version */
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_ver_major, p);
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_ver_minor, p);
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_nvm_max_size, p);
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_patch_max_size, p);
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_lpm_patch_size, p);
+ STREAM_TO_UINT16 (nfc_hal_cb.prm.spd_fpm_patch_size, p);
+
+ /* LPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */
+ STREAM_TO_UINT8 (u8, p);
+ if (!u8)
+ {
+ nfc_hal_cb.prm.spd_nvm_patch_mask |= (1 << NFC_HAL_PRM_SPD_POWER_MODE_LPM);
+ }
+ else
+ {
+ /* LPM patch in NVM fails CRC check */
+ nfc_hal_cb.prm.flags |= NFC_HAL_PRM_FLAGS_NVM_LPM_CORRUPTED;
+ }
+
+
+ /* FPMPatchCodeHasBadCRC (if not bad crc, then indicate LPM patch is present in nvm) */
+ STREAM_TO_UINT8 (u8, p);
+ if (!u8)
+ {
+ nfc_hal_cb.prm.spd_nvm_patch_mask |= (1 << NFC_HAL_PRM_SPD_POWER_MODE_FPM);
+ }
+ else
+ {
+ /* FPM patch in NVM fails CRC check */
+ nfc_hal_cb.prm.flags |= NFC_HAL_PRM_FLAGS_NVM_FPM_CORRUPTED;
+ }
+
+ /* Check if downloading patch to RAM only (no NVM) */
+ STREAM_TO_UINT8 (u8, p);
+ if (!u8)
+ {
+ if (nfc_hal_prm_nvm_required)
+ {
+ NCI_TRACE_ERROR0 ("This platform requires NVM and the NVM is not available - Abort");
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_NO_NVM_EVT);
+ return;
+ }
+ nfc_hal_cb.prm.flags |= NFC_HAL_PRM_FLAGS_NO_NVM;
+ }
+ /* Get patchfile version number */
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_COMPARE_VERSION;
+
+ if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_USE_PATCHRAM_BUF)
+ {
+ /* If patch is in a buffer, get patch version from buffer */
+ nfc_hal_prm_spd_check_version ();
+ }
+ else
+ {
+ /* Notify adaptation layer to send patch version (via HAL_NfcPrmDownloadContinue) */
+ (nfc_hal_cb.prm.p_cback) (NFC_HAL_PRM_SPD_GET_PATCHFILE_HDR_EVT);
+ }
+
+ }
+ /* Handle SECURE_PATCH_DOWNLOAD Rsp */
+ else if (event == NFC_VS_SEC_PATCH_DOWNLOAD_EVT)
+ {
+ /* Status and error code */
+ STREAM_TO_UINT8 (status, p);
+ STREAM_TO_UINT8 (u8, p);
+
+ if (status != NCI_STATUS_OK)
+ {
+#if (NFC_HAL_TRACE_VERBOSE == TRUE)
+ NCI_TRACE_ERROR2 ("Patch download failed, reason code=0x%X (%s)", status, nfc_hal_prm_spd_status_str (status));
+#else
+ NCI_TRACE_ERROR1 ("Patch download failed, reason code=0x%X", status);
+#endif
+
+ /* Notify application */
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT);
+ return;
+ }
+
+ /* If last segment (SIGNATURE) sent */
+ if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_SIGNATURE_SENT)
+ {
+ /* Wait for authentication complate (SECURE_PATCH_DOWNLOAD NTF) */
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_AUTHENTICATING;
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.prm.timer, 0x00,
+ (NFC_HAL_PRM_SPD_TOUT * QUICK_TIMER_TICKS_PER_SEC) / 1000);
+ return;
+ }
+ /* Download next segment */
+ else if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_USE_PATCHRAM_BUF)
+ {
+ /* If patch is in a buffer, get next patch from buffer */
+ nfc_hal_prm_spd_send_next_segment ();
+ }
+ else
+ {
+ /* Notify adaptation layer to get next patch segment (via HAL_NfcPrmDownloadContinue) */
+ (nfc_hal_cb.prm.p_cback) (NFC_HAL_PRM_CONTINUE_EVT);
+ }
+ }
+ /* Handle SECURE_PATCH_DOWNLOAD NTF */
+ else if (event == NFC_VS_SEC_PATCH_AUTH_EVT)
+ {
+ NCI_TRACE_DEBUG1 ("prm flags:0x%x.", nfc_hal_cb.prm.flags);
+ /* Status and error code */
+ STREAM_TO_UINT8 (status, p);
+ STREAM_TO_UINT8 (u8, p);
+
+ /* Sanity check - should only get this NTF while in AUTHENTICATING stage */
+ if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_AUTHENTICATING)
+ {
+ if (status != NCI_STATUS_OK)
+ {
+ NCI_TRACE_ERROR0 ("Patch authentication failed");
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_BAD_SIGNATURE_EVT);
+ return;
+ }
+
+#if (defined (NFC_HAL_PRE_I2C_PATCH_INCLUDED) && (NFC_HAL_PRE_I2C_PATCH_INCLUDED == TRUE))
+ if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_I2C_FIX_REQUIRED)
+ {
+ NCI_TRACE_DEBUG1 ("PreI2C patch downloaded...waiting %i ms for NFCC to reboot.", nfc_hal_cb.prm_i2c.prei2c_delay);
+
+ /* Restore pointers to patchfile */
+ nfc_hal_cb.prm.flags &= ~NFC_HAL_PRM_FLAGS_I2C_FIX_REQUIRED;
+ nfc_hal_cb.prm.p_cur_patch_data = nfc_hal_cb.prm.p_spd_patch;
+ nfc_hal_cb.prm.cur_patch_offset = nfc_hal_cb.prm.spd_patch_offset;
+ nfc_hal_cb.prm.cur_patch_len_remaining = nfc_hal_cb.prm.spd_patch_len_remaining;
+
+ /* Resume normal patch download */
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_GET_PATCH_HEADER;
+ nfc_hal_cb.prm.flags &= ~NFC_HAL_PRM_FLAGS_SIGNATURE_SENT;
+
+ /* Post PreI2C delay */
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.prm.timer, 0x00, (nfc_hal_cb.prm_i2c.prei2c_delay * QUICK_TIMER_TICKS_PER_SEC) / 1000);
+
+ return;
+ }
+#endif /* NFC_HAL_PRE_I2C_PATCH_INCLUDED */
+
+
+ /* Wait for NFCC to save the patch to NVM */
+ if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_SUPPORT_RESET_NTF)
+ {
+ /* 20791B4 or newer - wait for RESET_NTF */
+ post_signature_delay = NFC_HAL_PRM_RESET_NTF_DELAY;
+ NCI_TRACE_DEBUG1 ("Patch downloaded and authenticated. Waiting %i ms for RESET NTF...", post_signature_delay);
+
+ }
+ else if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_NO_NVM)
+ {
+ /* No NVM. Wait for NFCC to restart */
+ post_signature_delay = NFC_HAL_PRM_END_DELAY;
+ NCI_TRACE_DEBUG1 ("Patch downloaded and authenticated. Waiting %i ms for NFCC to restart...", post_signature_delay);
+ }
+ else
+ {
+ /* Wait for NFCC to save the patch to NVM (need about 1 ms per byte) */
+ post_signature_delay = nfc_hal_cb.prm.spd_patch_desc[nfc_hal_cb.prm.spd_cur_patch_idx].len;
+ if (post_signature_delay < nfc_hal_cb.prm.patchram_delay)
+ post_signature_delay = nfc_hal_cb.prm.patchram_delay;
+ NCI_TRACE_DEBUG1 ("Patch downloaded and authenticated. Waiting %i ms for NVM update to complete...", post_signature_delay);
+ }
+
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_AUTH_DONE;
+
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.prm.timer, 0x00,
+ (post_signature_delay * QUICK_TIMER_TICKS_PER_SEC) / 1000);
+ }
+ else
+ {
+ NCI_TRACE_ERROR0 ("Got unexpected SECURE_PATCH_DOWNLOAD NTF");
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_EVT);
+ }
+ }
+ else
+ {
+ /* Invalid response from NFCC during patch download */
+ NCI_TRACE_ERROR1 ("Invalid response from NFCC during patch download (opcode=0x%02X)", event);
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT);
+ }
+
+ NFC_HAL_PRM_STATE ("prm_nci_command_complete_cback");
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_nfcc_ready_to_continue
+**
+** Description Continue to download patch or notify application completition
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_nfcc_ready_to_continue (void)
+{
+ /* Clear the bit for the patch we just downloaded */
+ nfc_hal_cb.prm.spd_patch_needed_mask &= ~ ((UINT32) 1 << nfc_hal_cb.prm.spd_patch_desc[nfc_hal_cb.prm.spd_cur_patch_idx].power_mode);
+
+ /* Check if another patch to download */
+ nfc_hal_cb.prm.spd_cur_patch_idx++;
+ if ((nfc_hal_cb.prm.spd_patch_needed_mask) && (nfc_hal_cb.prm.spd_cur_patch_idx < nfc_hal_cb.prm.spd_patch_count))
+ {
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_GET_PATCH_HEADER;
+ nfc_hal_cb.prm.flags &= ~NFC_HAL_PRM_FLAGS_SIGNATURE_SENT;
+
+ if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_USE_PATCHRAM_BUF)
+ {
+ /* If patch is in a buffer, get next patch from buffer */
+ nfc_hal_prm_spd_handle_next_patch_start ();
+ }
+ else
+ {
+ /* Notify adaptation layer to get next patch header (via HAL_NfcPrmDownloadContinue) */
+ (nfc_hal_cb.prm.p_cback) (NFC_HAL_PRM_SPD_GET_NEXT_PATCH);
+ }
+
+ }
+ else
+ {
+ /* Done downloading */
+ NCI_TRACE_DEBUG0 ("Patch downloaded and authenticated.");
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_COMPLETE_EVT);
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_spd_reset_ntf
+**
+** Description Received RESET NTF from NFCC, indicating it has completed
+** reset after patch download.
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_spd_reset_ntf (UINT8 reset_reason, UINT8 reset_type)
+{
+ /* Check if we were expecting a RESET NTF */
+ if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_AUTH_DONE)
+ {
+ NCI_TRACE_DEBUG2 ("Received RESET NTF after patch download (reset_reason=%i, reset_type=%i)", reset_reason, reset_type);
+
+ /* Stop waiting for RESET NTF */
+ nfc_hal_main_stop_quick_timer (&nfc_hal_cb.prm.timer);
+
+ {
+ /* Continue with patch download */
+ nfc_hal_prm_nfcc_ready_to_continue ();
+ }
+ }
+ else
+ {
+ NCI_TRACE_ERROR2 ("Received unexpected RESET NTF (reset_reason=%i, reset_type=%i)", reset_reason, reset_type);
+ }
+}
+
+/*******************************************************************************
+**
+** Function: nfc_post_final_baud_update
+**
+** Description: Called after baud rate udate
+**
+** Returns: Nothing
+**
+*******************************************************************************/
+void nfc_hal_prm_post_baud_update (tHAL_NFC_STATUS status)
+{
+ NFC_HAL_PRM_STATE ("nfc_hal_prm_post_baud_update");
+
+ if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_AUTH_DONE)
+ {
+ /* Proceed with next step of patch download sequence */
+ nfc_hal_prm_nfcc_ready_to_continue ();
+ }
+}
+
+/*******************************************************************************
+**
+** Function nfc_hal_prm_process_timeout
+**
+** Description Process timer expireation for patch download
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_prm_process_timeout (void *p_tle)
+{
+ NFC_HAL_PRM_STATE ("nfc_hal_prm_process_timeout");
+
+ if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_IDLE)
+ {
+ nfc_hal_cb.prm.state = NFC_HAL_PRM_ST_SPD_GET_VERSION;
+
+ /* Get currently downloaded patch version */
+ nfc_hal_dm_send_nci_cmd (nfc_hal_prm_get_patch_version_cmd, NCI_MSG_HDR_SIZE, nfc_hal_prm_nci_command_complete_cback);
+ }
+ else if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_AUTH_DONE)
+ {
+ if (nfc_hal_cb.prm.flags & NFC_HAL_PRM_FLAGS_SUPPORT_RESET_NTF)
+ {
+ /* Timeout waiting for RESET NTF after signature sent */
+ NCI_TRACE_ERROR0 ("Timeout waiting for RESET NTF after patch download");
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_EVT);
+ }
+ else
+ {
+ nfc_hal_prm_nfcc_ready_to_continue ();
+ }
+ }
+ else if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_GET_PATCH_HEADER)
+ {
+ NCI_TRACE_DEBUG0 ("Delay after PreI2C patch download...proceeding to download firmware patch");
+ nfc_hal_prm_spd_handle_next_patch_start ();
+ }
+ else
+ {
+ NCI_TRACE_ERROR1 ("Patch download: command timeout (state=%i)", nfc_hal_cb.prm.state);
+
+ nfc_hal_prm_spd_handle_download_complete (NFC_HAL_PRM_ABORT_EVT);
+ }
+
+ NFC_HAL_PRM_STATE ("nfc_hal_prm_process_timeout");
+}
+
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmDownloadStart
+**
+** Description Initiate patch download
+**
+** Input Params
+** format_type patch format type
+** (NFC_HAL_PRM_FORMAT_BIN, NFC_HAL_PRM_FORMAT_HCD, or
+** NFC_HAL_PRM_FORMAT_NCD)
+**
+** dest_address destination adderess (needed for BIN format only)
+**
+** p_patchram_buf pointer to patchram buffer. If NULL,
+** then app must call HAL_NfcPrmDownloadContinue when
+** NFC_HAL_PRM_CONTINUE_EVT is received, to send the next
+** segment of patchram
+**
+** patchram_len size of p_patchram_buf (if non-NULL)
+**
+** patchram_delay The delay after each patch.
+** If the given value is less than the size of the patchram,
+** the size of patchram is used instead.
+**
+** p_cback callback for download status
+**
+**
+** Returns TRUE if successful, otherwise FALSE
+**
+**
+*******************************************************************************/
+BOOLEAN HAL_NfcPrmDownloadStart (tNFC_HAL_PRM_FORMAT format_type,
+ UINT32 dest_address,
+ UINT8 *p_patchram_buf,
+ UINT32 patchram_len,
+ UINT32 patchram_delay,
+ tNFC_HAL_PRM_CBACK *p_cback)
+{
+ NCI_TRACE_API0 ("HAL_NfcPrmDownloadStart ()");
+
+ memset (&nfc_hal_cb.prm, 0, sizeof (tNFC_HAL_PRM_CB));
+
+ if (p_patchram_buf)
+ {
+ nfc_hal_cb.prm.p_cur_patch_data = p_patchram_buf;
+ nfc_hal_cb.prm.cur_patch_offset = 0;
+ nfc_hal_cb.prm.cur_patch_len_remaining = (UINT16) patchram_len;
+ nfc_hal_cb.prm.flags |= NFC_HAL_PRM_FLAGS_USE_PATCHRAM_BUF;
+
+ if (patchram_len == 0)
+ return FALSE;
+ }
+
+ nfc_hal_cb.prm.p_cback = p_cback;
+ nfc_hal_cb.prm.dest_ram = dest_address;
+ nfc_hal_cb.prm.format = format_type;
+ nfc_hal_cb.prm.patchram_delay = patchram_delay;
+
+ nfc_hal_cb.prm.timer.p_cback = nfc_hal_prm_process_timeout;
+
+ if (format_type == NFC_HAL_PRM_FORMAT_NCD)
+ {
+ /* Store patch buffer pointer and length */
+ nfc_hal_cb.prm.p_spd_patch = p_patchram_buf;
+ nfc_hal_cb.prm.spd_patch_len_remaining = (UINT16)patchram_len;
+ nfc_hal_cb.prm.spd_patch_offset = 0;
+
+ /* Need delay for controller to finish resetting */
+ nfc_hal_main_start_quick_timer (&nfc_hal_cb.prm.timer, 0x00,
+ (NFC_HAL_PRM_SPD_PRE_DOWNLOAD_DELAY * QUICK_TIMER_TICKS_PER_SEC) / 1000);
+ }
+ else
+ {
+ NCI_TRACE_ERROR0 ("Unexpected patch format.");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmDownloadContinue
+**
+** Description Send next segment of patchram to controller. Called when
+** NFC_HAL_PRM_CONTINUE_EVT is received.
+**
+** Only needed if HAL_NfcPrmDownloadStart was called with
+** p_patchram_buf=NULL
+**
+** Input Params p_patch_data pointer to patch data
+** patch_data_len patch data len
+**
+** Returns TRUE if successful, otherwise FALSE
+**
+*******************************************************************************/
+BOOLEAN HAL_NfcPrmDownloadContinue (UINT8 *p_patch_data,
+ UINT16 patch_data_len)
+{
+ NCI_TRACE_API2 ("HAL_NfcPrmDownloadContinue ():state = %d, patch_data_len=%d",
+ nfc_hal_cb.prm.state, patch_data_len);
+
+ /* Check if we are in a valid state for this API */
+ if ( (nfc_hal_cb.prm.state != NFC_HAL_PRM_ST_SPD_COMPARE_VERSION)
+ &&(nfc_hal_cb.prm.state != NFC_HAL_PRM_ST_SPD_GET_PATCH_HEADER)
+ &&(nfc_hal_cb.prm.state != NFC_HAL_PRM_ST_SPD_DOWNLOADING) )
+ return FALSE;
+
+ if (patch_data_len == 0)
+ return FALSE;
+
+ nfc_hal_cb.prm.cur_patch_offset = 0;
+ nfc_hal_cb.prm.p_cur_patch_data = p_patch_data;
+ nfc_hal_cb.prm.cur_patch_len_remaining = patch_data_len;
+
+ /* Call appropriate handler */
+ if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_COMPARE_VERSION)
+ {
+ nfc_hal_prm_spd_check_version ();
+ }
+ else if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_GET_PATCH_HEADER)
+ {
+ nfc_hal_prm_spd_handle_next_patch_start ();
+ }
+ else if (nfc_hal_cb.prm.state == NFC_HAL_PRM_ST_SPD_DOWNLOADING)
+ {
+ nfc_hal_prm_spd_send_next_segment ();
+ }
+ else
+ {
+ NCI_TRACE_ERROR1 ("Unexpected patch state:%d.", nfc_hal_cb.prm.state);
+ }
+
+ return TRUE;
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmSetI2cPatch
+**
+** Description Specify patchfile for BCM20791B3 I2C fix. This fix
+** must be downloaded prior to initial patch download for I2C
+** transport
+**
+** Input Params p_i2c_patchfile_buf: pointer to patch for i2c fix
+** i2c_patchfile_len: length of patch
+** prei2c_delay: the delay before downloading main patch
+** if 0 is given, NFC_HAL_PRM_POST_I2C_FIX_DELAY is used instead.
+**
+** Returns Nothing
+**
+**
+*******************************************************************************/
+void HAL_NfcPrmSetI2cPatch (UINT8 *p_i2c_patchfile_buf, UINT16 i2c_patchfile_len, UINT32 prei2c_delay)
+{
+#if (defined (NFC_HAL_PRE_I2C_PATCH_INCLUDED) && (NFC_HAL_PRE_I2C_PATCH_INCLUDED == TRUE))
+ NCI_TRACE_API0 ("HAL_NfcPrmSetI2cPatch ()");
+
+ nfc_hal_cb.prm_i2c.prei2c_delay = NFC_HAL_PRM_POST_I2C_FIX_DELAY;
+ if (prei2c_delay)
+ nfc_hal_cb.prm_i2c.prei2c_delay = prei2c_delay;
+ nfc_hal_cb.prm_i2c.p_patch = p_i2c_patchfile_buf;
+ nfc_hal_cb.prm_i2c.len = i2c_patchfile_len;
+#endif /* NFC_HAL_PRE_I2C_PATCH_INCLUDED */
+}
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmSetSpdNciCmdPayloadSize
+**
+** Description Set Host-to-NFCC NCI message size for secure patch download
+**
+** This API must be called before calling HAL_NfcPrmDownloadStart.
+** If the API is not called, then PRM will use the default
+** message size.
+**
+** Typically, this API is only called for platforms that have
+** message-size limitations in the transport/driver.
+**
+** Valid message size range: NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE to 255.
+**
+** Returns HAL_NFC_STATUS_OK if successful
+** HAL_NFC_STATUS_FAILED otherwise
+**
+**
+*******************************************************************************/
+tHAL_NFC_STATUS HAL_NfcPrmSetSpdNciCmdPayloadSize (UINT8 max_payload_size)
+{
+ /* Validate: minimum size is NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE */
+ if (max_payload_size < NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE)
+ {
+ NCI_TRACE_ERROR2 ("HAL_NfcPrmSetSpdNciCmdPayloadSize: invalid size (%i). Must be between %i and 255", max_payload_size, NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE);
+ return (HAL_NFC_STATUS_FAILED);
+ }
+ else
+ {
+ NCI_TRACE_API1 ("HAL_NfcPrmSetSpdNciCmdPayloadSize: new message size during download: %i", max_payload_size);
+ nfc_hal_cb.ncit_cb.nci_ctrl_size = max_payload_size;
+ return (HAL_NFC_STATUS_OK);
+ }
+}
diff --git a/halimpl/bcm2079x/hal/include/gki_hal_target.h b/halimpl/bcm2079x/hal/include/gki_hal_target.h
new file mode 100644
index 0000000..9a9aec9
--- /dev/null
+++ b/halimpl/bcm2079x/hal/include/gki_hal_target.h
@@ -0,0 +1,255 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+#ifndef GKI_HAL_TARGET_H
+#define GKI_HAL_TARGET_H
+
+#ifdef BUILDCFG
+#include "buildcfg_hal.h"
+#endif
+
+#include "data_types.h"
+
+/* Define export prefixes for modules exported by HAL */
+#ifndef GKI_API
+#define GKI_API
+#endif
+
+#ifndef UDRV_API
+#define UDRV_API
+#endif
+
+#ifndef EXPORT_API
+#define EXPORT_API
+#endif
+
+
+/******************************************************************************
+**
+** Task configuration
+**
+******************************************************************************/
+
+/* Definitions of task IDs for inter-task messaging */
+#ifndef NFC_HAL_TASK
+#define NFC_HAL_TASK 0
+#endif
+
+/* The number of GKI tasks in the software system. */
+#ifndef GKI_MAX_TASKS
+#define GKI_MAX_TASKS 1
+#endif
+
+/******************************************************************************
+**
+** Timer configuration
+**
+******************************************************************************/
+
+/* The number of GKI timers in the software system. */
+#ifndef GKI_NUM_TIMERS
+#define GKI_NUM_TIMERS 2
+#endif
+
+/* A conversion value for translating ticks to calculate GKI timer. */
+#ifndef TICKS_PER_SEC
+#define TICKS_PER_SEC 100
+#endif
+
+/************************************************************************
+** Utility macros converting ticks to time with user define OS ticks per sec
+**/
+#ifndef GKI_MS_TO_TICKS
+#define GKI_MS_TO_TICKS(x) ((x) / (1000 / TICKS_PER_SEC))
+#endif
+
+#ifndef GKI_SECS_TO_TICKS
+#define GKI_SECS_TO_TICKS(x) ((x) * (TICKS_PER_SEC))
+#endif
+
+#ifndef GKI_TICKS_TO_MS
+#define GKI_TICKS_TO_MS(x) ((x) * 1000 / TICKS_PER_SEC)
+#endif
+
+#ifndef GKI_TICKS_TO_SECS
+#define GKI_TICKS_TO_SECS(x) ((x) / TICKS_PER_SEC)
+#endif
+
+
+
+/* TICK per second from OS (OS dependent change this macro accordingly to various OS) */
+#ifndef OS_TICKS_PER_SEC
+#define OS_TICKS_PER_SEC 1000
+#endif
+
+/************************************************************************
+** Utility macros converting ticks to time with user define OS ticks per sec
+**/
+
+#ifndef GKI_OS_TICKS_TO_MS
+#define GKI_OS_TICKS_TO_MS(x) ((x) * 1000 / OS_TICKS_PER_SEC)
+#endif
+
+
+#ifndef GKI_OS_TICKS_TO_SECS
+#define GKI_OS_TICKS_TO_SECS(x) ((x) / OS_TICKS_PER_SEC))
+#endif
+
+
+/* delay in ticks before stopping system tick. */
+#ifndef GKI_DELAY_STOP_SYS_TICK
+#define GKI_DELAY_STOP_SYS_TICK 10
+#endif
+
+/* Option to guarantee no preemption during timer expiration (most system don't need this) */
+#ifndef GKI_TIMER_LIST_NOPREEMPT
+#define GKI_TIMER_LIST_NOPREEMPT FALSE
+#endif
+
+/******************************************************************************
+**
+** Buffer configuration
+**
+******************************************************************************/
+
+/* TRUE if GKI uses dynamic buffers. */
+#ifndef GKI_USE_DYNAMIC_BUFFERS
+#define GKI_USE_DYNAMIC_BUFFERS FALSE
+#endif
+
+/* The size of the buffers in pool 0. */
+#ifndef GKI_BUF0_SIZE
+#define GKI_BUF0_SIZE 64
+#endif
+
+/* The number of buffers in buffer pool 0. */
+#ifndef GKI_BUF0_MAX
+#define GKI_BUF0_MAX 8
+#endif
+
+/* The ID of buffer pool 0. */
+#ifndef GKI_POOL_ID_0
+#define GKI_POOL_ID_0 0
+#endif
+
+/* The size of the buffers in pool 1. */
+#ifndef GKI_BUF1_SIZE
+#define GKI_BUF1_SIZE 288
+#endif
+
+/* The number of buffers in buffer pool 1. */
+#ifndef GKI_BUF1_MAX
+#define GKI_BUF1_MAX 8
+#endif
+
+/* The ID of buffer pool 1. */
+#ifndef GKI_POOL_ID_1
+#define GKI_POOL_ID_1 1
+#endif
+
+/* The size of the largest PUBLIC fixed buffer in system. */
+#ifndef GKI_MAX_BUF_SIZE
+#define GKI_MAX_BUF_SIZE GKI_BUF1_SIZE
+#endif
+
+/* The pool ID of the largest PUBLIC fixed buffer in system. */
+#ifndef GKI_MAX_BUF_SIZE_POOL_ID
+#define GKI_MAX_BUF_SIZE_POOL_ID GKI_POOL_ID_1
+#endif
+
+/* buffer size for USERIAL, it must large enough to hold NFC_HDR and max packet size */
+#ifndef USERIAL_POOL_BUF_SIZE
+#define USERIAL_POOL_BUF_SIZE GKI_BUF1_SIZE
+#endif
+
+/* buffer pool ID for USERIAL */
+#ifndef USERIAL_POOL_ID
+#define USERIAL_POOL_ID GKI_POOL_ID_1
+#endif
+
+#ifndef GKI_NUM_FIXED_BUF_POOLS
+#define GKI_NUM_FIXED_BUF_POOLS 2
+#endif
+
+/* The number of fixed and dynamic buffer pools */
+#ifndef GKI_NUM_TOTAL_BUF_POOLS
+#define GKI_NUM_TOTAL_BUF_POOLS 2
+#endif
+
+/* The buffer pool usage mask. */
+#ifndef GKI_DEF_BUFPOOL_PERM_MASK
+#define GKI_DEF_BUFPOOL_PERM_MASK 0xfff0
+#endif
+
+/* The buffer corruption check flag. */
+#ifndef GKI_ENABLE_BUF_CORRUPTION_CHECK
+#define GKI_ENABLE_BUF_CORRUPTION_CHECK TRUE
+#endif
+
+/* The GKI severe error macro. */
+#ifndef GKI_SEVERE
+#define GKI_SEVERE(code)
+#endif
+
+/* TRUE if GKI includes debug functionality. */
+#ifndef GKI_DEBUG
+#define GKI_DEBUG FALSE
+#endif
+
+/* Maximum number of exceptions logged. */
+#ifndef GKI_MAX_EXCEPTION
+#define GKI_MAX_EXCEPTION 8
+#endif
+
+/* Maximum number of chars stored for each exception message. */
+#ifndef GKI_MAX_EXCEPTION_MSGLEN
+#define GKI_MAX_EXCEPTION_MSGLEN 64
+#endif
+
+#ifndef GKI_SEND_MSG_FROM_ISR
+#define GKI_SEND_MSG_FROM_ISR FALSE
+#endif
+
+
+#define GKI_TRACE_0(m)
+#define GKI_TRACE_1(m,p1)
+#define GKI_TRACE_2(m,p1,p2)
+#define GKI_TRACE_3(m,p1,p2,p3)
+#define GKI_TRACE_4(m,p1,p2,p3,p4)
+#define GKI_TRACE_5(m,p1,p2,p3,p4,p5)
+#define GKI_TRACE_6(m,p1,p2,p3,p4,p5,p6)
+
+#define GKI_TRACE_ERROR_0(m) LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI | TRACE_TYPE_ERROR,m)
+#define GKI_TRACE_ERROR_1(m,p1) LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI | TRACE_TYPE_ERROR,m,p1)
+#define GKI_TRACE_ERROR_2(m,p1,p2) LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI | TRACE_TYPE_ERROR,m,p1,p2)
+#define GKI_TRACE_ERROR_3(m,p1,p2,p3) LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI | TRACE_TYPE_ERROR,m,p1,p2,p3)
+#define GKI_TRACE_ERROR_4(m,p1,p2,p3,p4) LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI | TRACE_TYPE_ERROR,m,p1,p2,p3,p4)
+#define GKI_TRACE_ERROR_5(m,p1,p2,p3,p4,p5) LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI | TRACE_TYPE_ERROR,m,p1,p2,p3,p4,p5)
+#define GKI_TRACE_ERROR_6(m,p1,p2,p3,p4,p5,p6) LogMsg(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI | TRACE_TYPE_ERROR,m,p1,p2,p3,p4,p5,p6)
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+extern void LogMsg (UINT32 trace_set_mask, const char *fmt_str, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GKI_TARGET_H */
diff --git a/halimpl/bcm2079x/hal/include/nci_defs.h b/halimpl/bcm2079x/hal/include/nci_defs.h
new file mode 100644
index 0000000..befffd9
--- /dev/null
+++ b/halimpl/bcm2079x/hal/include/nci_defs.h
@@ -0,0 +1,851 @@
+/******************************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains the definition from NCI specification
+ *
+ ******************************************************************************/
+
+#ifndef NFC_NCI_DEFS_H
+#define NFC_NCI_DEFS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NCI_BRCM_CO_ID 0x2E
+
+/* Define the message header size for all NCI Commands and Notifications.
+*/
+#define NCI_MSG_HDR_SIZE 3 /* per NCI spec */
+#define NCI_DATA_HDR_SIZE 3 /* per NCI spec */
+#define NCI_MAX_PAYLOAD_SIZE 0xFE
+#define NCI_MAX_CTRL_SIZE 0xFF/* max control message size */
+#define NCI_CTRL_INIT_SIZE 32 /* initial NFCC control payload size */
+#define NCI_MAX_VSC_SIZE 0xFF
+#define NCI_VSC_MSG_HDR_SIZE 12 /* NCI header (3) + callback function pointer(8; use 8 to be safe) + HCIT (1 byte) */
+#define NCI_TL_SIZE 2
+
+#define NCI_ISO_DEP_MAX_INFO 253 /* Max frame size (256) - Prologue (1) - Epilogue (2) in ISO-DEP, CID and NAD are not used*/
+#define NCI_NFC_DEP_MAX_DATA 251 /* Max payload (254) - Protocol Header (3) in NFC-DEP, DID and NAD are not used */
+
+/* NCI Command and Notification Format:
+ * 3 byte message header:
+ * byte 0: MT PBF GID
+ * byte 1: OID
+ * byte 2: Message Length */
+/* MT: Message Type (byte 0) */
+#define NCI_MT_MASK 0xE0
+#define NCI_MT_SHIFT 5
+#define NCI_MT_DATA 0x00
+#define NCI_MT_CMD 1 /* (NCI_MT_CMD << NCI_MT_SHIFT) = 0x20 */
+#define NCI_MT_RSP 2 /* (NCI_MT_RSP << NCI_MT_SHIFT) = 0x40 */
+#define NCI_MT_NTF 3 /* (NCI_MT_NTF << NCI_MT_SHIFT) = 0x60 */
+#define NCI_MT_CFG 4 /* (NCI_MT_CFG << NCI_MT_SHIFT) = 0x80 */
+
+#define NCI_MTS_CMD 0x20
+#define NCI_MTS_RSP 0x40
+#define NCI_MTS_NTF 0x60
+#define NCI_MTS_CFG 0x80
+
+#define NCI_NTF_BIT 0x80 /* the tNFC_VS_EVT is a notification */
+#define NCI_RSP_BIT 0x40 /* the tNFC_VS_EVT is a response */
+
+/* for internal use only; not from specification */
+/* the following 2 flags are used in layer_specific for fragmentation/reassembly of data packets */
+#define NCI_LS_DATA 0x00
+#define NCI_LS_DATA_PBF 0x01
+
+/* PBF: Packet Boundary Flag (byte 0) */
+#define NCI_PBF_MASK 0x10
+#define NCI_PBF_SHIFT 4
+#define NCI_PBF_NO_OR_LAST 0x00 /* not fragmented or last fragment */
+#define NCI_PBF_ST_CONT 0x10 /* start or continuing fragment */
+
+/* GID: Group Identifier (byte 0) */
+#define NCI_GID_MASK 0x0F
+#define NCI_GID_SHIFT 0
+#define NCI_GID_CORE 0x00 /* 0000b NCI Core group */
+#define NCI_GID_RF_MANAGE 0x01 /* 0001b RF Management group */
+#define NCI_GID_EE_MANAGE 0x02 /* 0010b NFCEE Management group */
+#define NCI_GID_PROP 0x0F /* 1111b Proprietary */
+/* 0111b - 1110b RFU */
+
+/* OID: Opcode Identifier (byte 1) */
+#define NCI_OID_MASK 0x3F
+#define NCI_OID_SHIFT 0
+
+/* For routing */
+#define NCI_DH_ID 0 /* for DH */
+/* To identify the loopback test */
+#define NCI_TEST_ID 0xFE/* for loopback test */
+
+/* Destination Type */
+#define NCI_DEST_TYPE_NFCC 1 /* NFCC - loopback */
+#define NCI_DEST_TYPE_REMOTE 2 /* Remote NFC Endpoint */
+#define NCI_DEST_TYPE_NFCEE 3 /* NFCEE */
+
+/* builds byte0 of NCI Command and Notification packet */
+#define NCI_MSG_BLD_HDR0(p, mt, gid) \
+ *(p)++ = (UINT8) (((mt) << NCI_MT_SHIFT) | (gid));
+
+#define NCI_MSG_PBLD_HDR0(p, mt, pbf, gid) \
+ *(p)++ = (UINT8) (((mt) << NCI_MT_SHIFT) | ((pbf) << NCI_PBF_SHIFT) | (gid));
+
+/* builds byte1 of NCI Command and Notification packet */
+#define NCI_MSG_BLD_HDR1(p, oid) \
+ *(p)++ = (UINT8) (((oid) << NCI_OID_SHIFT));
+
+/* parse byte0 of NCI packet */
+#define NCI_MSG_PRS_HDR0(p, mt, pbf, gid) \
+ mt = (*(p) & NCI_MT_MASK) >> NCI_MT_SHIFT; \
+ pbf = (*(p) & NCI_PBF_MASK) >> NCI_PBF_SHIFT; \
+ gid = *(p)++ & NCI_GID_MASK;
+
+/* parse MT and PBF bits of NCI packet */
+#define NCI_MSG_PRS_MT_PBF(p, mt, pbf) \
+ mt = (*(p) & NCI_MT_MASK) >> NCI_MT_SHIFT; \
+ pbf = (*(p) & NCI_PBF_MASK) >> NCI_PBF_SHIFT;
+
+/* parse byte1 of NCI Cmd/Ntf */
+#define NCI_MSG_PRS_HDR1(p, oid) \
+ oid = (*(p) & NCI_OID_MASK); (p)++;
+
+/* NCI Data Format:
+ * byte 0: MT(0) PBF CID
+ * byte 1: RFU
+ * byte 2: Data Length */
+/* CID: Connection Identifier (byte 0) 1-0xF Dynamically assigned (by NFCC), 0 is predefined */
+#define NCI_CID_MASK 0x0F
+
+/* builds 3-byte message header of NCI Data packet */
+#define NCI_DATA_BLD_HDR(p, cid, len) \
+ *(p)++ = (UINT8) (cid); *(p)++ = 0; *(p)++ = (UINT8) (len);
+
+#define NCI_DATA_PBLD_HDR(p, pbf, cid, len) \
+ *(p)++ = (UINT8) (((pbf) << NCI_PBF_SHIFT) | (cid)); *(p)++=0; *(p)++ = (len);
+
+#define NCI_DATA_PRS_HDR(p, pbf, cid, len) \
+ (pbf) = (*(p) & NCI_PBF_MASK) >> NCI_PBF_SHIFT; (cid) = (*(p) & NCI_CID_MASK); p++; p++; (len) = *(p)++;
+
+
+/* Logical target ID 0x01-0xFE */
+
+
+
+/* Status Codes */
+#define NCI_STATUS_OK 0x00
+#define NCI_STATUS_REJECTED 0x01
+#define NCI_STATUS_MESSAGE_CORRUPTED 0x02
+#define NCI_STATUS_BUFFER_FULL 0xE0
+#define NCI_STATUS_FAILED 0x03
+#define NCI_STATUS_NOT_INITIALIZED 0x04
+#define NCI_STATUS_SYNTAX_ERROR 0x05
+#define NCI_STATUS_SEMANTIC_ERROR 0x06
+#define NCI_STATUS_UNKNOWN_GID 0x07
+#define NCI_STATUS_UNKNOWN_OID 0x08
+#define NCI_STATUS_INVALID_PARAM 0x09
+#define NCI_STATUS_MSG_SIZE_TOO_BIG 0x0A
+/* discovery */
+#define NCI_STATUS_ALREADY_STARTED 0xA0
+#define NCI_STATUS_ACTIVATION_FAILED 0xA1
+#define NCI_STATUS_TEAR_DOWN 0xA2
+/* RF Interface */
+#define NCI_STATUS_RF_TRANSMISSION_ERR 0xB0
+#define NCI_STATUS_RF_PROTOCOL_ERR 0xB1
+#define NCI_STATUS_TIMEOUT 0xB2
+/* NFCEE Interface */
+#define NCI_STATUS_EE_INTF_ACTIVE_FAIL 0xC0
+#define NCI_STATUS_EE_TRANSMISSION_ERR 0xC1
+#define NCI_STATUS_EE_PROTOCOL_ERR 0xC2
+#define NCI_STATUS_EE_TIMEOUT 0xC3
+
+
+typedef UINT8 tNCI_STATUS;
+
+/* RF Technologies */
+#define NCI_RF_TECHNOLOGY_A 0x00
+#define NCI_RF_TECHNOLOGY_B 0x01
+#define NCI_RF_TECHNOLOGY_F 0x02
+#define NCI_RF_TECHNOLOGY_15693 0x03
+
+/* Bit Rates */
+#define NCI_BIT_RATE_106 0x00/* 106 kbit/s */
+#define NCI_BIT_RATE_212 0x01/* 212 kbit/s */
+#define NCI_BIT_RATE_424 0x02/* 424 kbit/s */
+#define NCI_BIT_RATE_848 0x03/* 848 Kbit/s */
+#define NCI_BIT_RATE_1696 0x04/* 1696 Kbit/s*/
+#define NCI_BIT_RATE_3392 0x05/* 3392 Kbit/s*/
+#define NCI_BIT_RATE_6784 0x06/* 6784 Kbit/s*/
+
+/**********************************************
+ * NCI Core Group Opcode - 0
+ **********************************************/
+#define NCI_MSG_CORE_RESET 0
+#define NCI_MSG_CORE_INIT 1
+#define NCI_MSG_CORE_SET_CONFIG 2
+#define NCI_MSG_CORE_GET_CONFIG 3
+#define NCI_MSG_CORE_CONN_CREATE 4
+#define NCI_MSG_CORE_CONN_CLOSE 5
+#define NCI_MSG_CORE_CONN_CREDITS 6
+#define NCI_MSG_CORE_GEN_ERR_STATUS 7
+#define NCI_MSG_CORE_INTF_ERR_STATUS 8
+
+/**********************************************
+ * RF MANAGEMENT Group Opcode - 1
+ **********************************************/
+#define NCI_MSG_RF_DISCOVER_MAP 0
+#define NCI_MSG_RF_SET_ROUTING 1
+#define NCI_MSG_RF_GET_ROUTING 2
+#define NCI_MSG_RF_DISCOVER 3
+#define NCI_MSG_RF_DISCOVER_SELECT 4
+#define NCI_MSG_RF_INTF_ACTIVATED 5
+#define NCI_MSG_RF_DEACTIVATE 6
+#define NCI_MSG_RF_FIELD 7
+#define NCI_MSG_RF_T3T_POLLING 8
+#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
+ **********************************************/
+#define NCI_MSG_NFCEE_DISCOVER 0
+#define NCI_MSG_NFCEE_MODE_SET 1
+
+/**********************************************
+ * NCI Proprietary Group - F
+ **********************************************/
+
+/**********************************************
+ * NCI Core Group Params
+ **********************************************/
+#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_RSP 0x11
+#define NCI_CORE_INIT_RSP_OFFSET_NUM_INTF 0x05
+
+#define NCI_CORE_PARAM_SIZE_SET_CONFIG_RSP 0x02 /* Status (1 octet) and number of params */
+
+
+/* octet 0 */
+#define NCI_FEAT_DISCOVERY_FREG 0x00000001
+#define NCI_FEAT_DISCOVERY_CFGM 0x00000006
+/* octet 1 */
+#define NCI_FEAT_TECHNOLOGY_ROUTING 0x00000200
+#define NCI_FEAT_PROTOCOL_ROUTING 0x00000400
+#define NCI_FEAT_AID_ROUTING 0x00000800
+/* octet 2 */
+#define NCI_FEAT_BATTERY_OFF_MD 0x00010000
+#define NCI_FEAT_SWITCH_OFF_MD 0x00020000
+
+
+/* supported Interfaces */
+#define NCI_SUP_INTF_FRAME 0x0001
+#define NCI_SUP_INTF_ISO_DEP 0x0002
+#define NCI_SUP_INTF_NFC_DEP 0x0004
+
+
+
+#define NCI_CORE_PARAM_SIZE_CON_CREATE 0x02 /* handle, num_tlv, (tlv) */
+#define NCI_CORE_PARAM_SIZE_CON_CREATE_RSP 0x04 /* status, size, credits, conn_id */
+#define NCI_CON_CREATE_TAG_EE_INTF 0x00 /* old */
+#define NCI_CON_CREATE_TAG_RF_DISC_ID 0x00
+#define NCI_CON_CREATE_TAG_NFCEE_VAL 0x01
+
+#define NCI_CORE_PARAM_SIZE_CON_CLOSE 0x01 /* Conn ID (1 octet) */
+#define NCI_CORE_PARAM_SIZE_CON_CLOSE_RSP 0x01 /* Status (1 octet) */
+
+#define NCI_CORE_PARAM_SIZE_RF_FIELD_NTF 0x01 /* RF Field Status (1 octet) */
+
+#define NCI_RESET_TYPE_KEEP_CFG 0x00 /* Keep the NCI configuration (if possible) and perform NCI initialization. */
+#define NCI_RESET_TYPE_RESET_CFG 0x01 /* Reset the NCI configuration, and perform NCI initialization. */
+
+#define NCI_RESET_STATUS_KEPT_CFG 0x00 /* NCI Configuration has been kept */
+#define NCI_RESET_STATUS_RESET_CFG 0x01 /* NCI Configuration has been reset */
+
+#define NCI_RF_STS_NO_REMOTE 0x00 /* No operating field generated by remote device */
+#define NCI_RF_STS_REMOTE 0x01 /* Operating field generated by remote device */
+
+
+#define NCI_PARAM_SIZE_DISCOVER_NFCEE 0x01 /* Discovery Action (1 octet) */
+#define NCI_PARAM_SIZE_DISCOVER_NFCEE_RSP 0x02 /* Status (1 octet)Number of NFCEEs (1 octet) */
+
+#define NCI_DISCOVER_ACTION_DISABLE 0
+#define NCI_DISCOVER_ACTION_ENABLE 1
+
+#define NCI_EE_DISCOVER_REQ_TYPE_LISTEN 0x01
+#define NCI_EE_DISCOVER_REQ_TYPE_POLL 0x02
+
+#define NCI_RF_PARAM_ID_TECH_N_MODE 0x00 /* RF Technology and Mode */
+#define NCI_RF_PARAM_ID_TX_BIT_RATE 0x01 /* Transmit Bit Rate */
+#define NCI_RF_PARAM_ID_RX_BIT_RATE 0x02 /* Receive Bit Rate */
+#define NCI_RF_PARAM_ID_B_DATA_EX_PARAM 0x03 /* B Data Exchange config param */
+
+
+#define NCI_NFCEE_INTERFACE_APDU 0x00
+#define NCI_NFCEE_INTERFACE_HCI_ACCESS 0x01
+#define NCI_NFCEE_INTERFACE_T3T 0x02
+#define NCI_NFCEE_INTERFACE_TRANSPARENT 0x03
+#define NCI_NFCEE_INTERFACE_PROPRIETARY 0x80
+
+#define NCI_NFCEE_STS_CONN_ACTIVE 0x00
+#define NCI_NFCEE_STS_CONN_INACTIVE 0x01
+#define NCI_NFCEE_STS_REMOVED 0x02
+#define NCI_NUM_NFCEE_STS 3
+
+#define NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET 0x02 /* Logical Target ID (1 octet)NFCEE Mode (1 octet) */
+#define NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET_RSP 0x01 /* Status (1 octet) */
+
+#define NCI_NFCEE_MD_DEACTIVATE 0x00 /* Deactivate the connected NFCEE */
+#define NCI_NFCEE_MD_ACTIVATE 0x01 /* Activate the connected NFCEE */
+#define NCI_NUM_NFCEE_MODE 2
+
+/**********************************************
+ * NCI Deactivation Type
+ **********************************************/
+#define NCI_DEACTIVATE_TYPE_IDLE 0 /* Idle Mode */
+#define NCI_DEACTIVATE_TYPE_SLEEP 1 /* Sleep Mode */
+#define NCI_DEACTIVATE_TYPE_SLEEP_AF 2 /* Sleep_AF Mode */
+#define NCI_DEACTIVATE_TYPE_DISCOVERY 3 /* Discovery */
+
+/**********************************************
+ * NCI Deactivation Reasons
+ **********************************************/
+#define NCI_DEACTIVATE_REASON_DH_REQ 0 /* DH Request */
+#define NCI_DEACTIVATE_REASON_ENDPOINT_REQ 1 /* Endpoint Request */
+#define NCI_DEACTIVATE_REASON_RF_LINK_LOSS 2 /* RF Link Loss */
+#define NCI_DEACTIVATE_REASON_NFCB_BAD_AFI 3 /* NFC-B Bad AFI */
+
+ /**********************************************
+ * NCI Interface Mode
+ **********************************************/
+#define NCI_INTERFACE_MODE_POLL 1
+#define NCI_INTERFACE_MODE_LISTEN 2
+#define NCI_INTERFACE_MODE_POLL_N_LISTEN 3
+
+/**********************************************
+ * NCI Interface Types
+ **********************************************/
+#define NCI_INTERFACE_EE_DIRECT_RF 0
+#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
+typedef UINT8 tNCI_INTF_TYPE;
+
+/**********************************************
+ * NCI RF Management / DISCOVERY Group Params
+ **********************************************/
+#define NCI_DISCOVER_PARAM_SIZE_RSP 0x01
+
+#define NCI_DISCOVER_PARAM_SIZE_SELECT 0x03 /* ID, protocol, interface */
+#define NCI_DISCOVER_PARAM_SIZE_SELECT_RSP 0x01 /* Status (1 octet) */
+#define NCI_DISCOVER_PARAM_SIZE_STOP 0x00 /* */
+#define NCI_DISCOVER_PARAM_SIZE_STOP_RSP 0x01 /* Status (1 octet) */
+#define NCI_DISCOVER_PARAM_SIZE_DEACT 0x01 /* type */
+#define NCI_DISCOVER_PARAM_SIZE_DEACT_RSP 0x01 /* Status (1 octet) */
+#define NCI_DISCOVER_PARAM_SIZE_DEACT_NTF 0x01 /* type */
+
+/**********************************************
+ * Supported Protocols
+ **********************************************/
+#define NCI_PROTOCOL_UNKNOWN 0x00
+#define NCI_PROTOCOL_T1T 0x01
+#define NCI_PROTOCOL_T2T 0x02
+#define NCI_PROTOCOL_T3T 0x03
+#define NCI_PROTOCOL_ISO_DEP 0x04
+#define NCI_PROTOCOL_NFC_DEP 0x05
+/**********************************************
+ * Proprietary Protocols
+ **********************************************/
+#ifndef NCI_PROTOCOL_18092_ACTIVE
+#define NCI_PROTOCOL_18092_ACTIVE 0x80
+#endif
+#ifndef NCI_PROTOCOL_B_PRIME
+#define NCI_PROTOCOL_B_PRIME 0x81
+#endif
+#ifndef NCI_PROTOCOL_DUAL
+#define NCI_PROTOCOL_DUAL 0x82
+#endif
+#ifndef NCI_PROTOCOL_15693
+#define NCI_PROTOCOL_15693 0x83
+#endif
+#ifndef NCI_PROTOCOL_KOVIO
+#define NCI_PROTOCOL_KOVIO 0x8a
+#endif
+
+
+/* Discovery Types/Detected Technology and Mode */
+#define NCI_DISCOVERY_TYPE_POLL_A 0x00
+#define NCI_DISCOVERY_TYPE_POLL_B 0x01
+#define NCI_DISCOVERY_TYPE_POLL_F 0x02
+#define NCI_DISCOVERY_TYPE_POLL_A_ACTIVE 0x03
+#define NCI_DISCOVERY_TYPE_POLL_F_ACTIVE 0x05
+#define NCI_DISCOVERY_TYPE_POLL_B_PRIME 0x74
+#define NCI_DISCOVERY_TYPE_POLL_KOVIO 0x77
+#define NCI_DISCOVERY_TYPE_LISTEN_A 0x80
+#define NCI_DISCOVERY_TYPE_LISTEN_B 0x81
+#define NCI_DISCOVERY_TYPE_LISTEN_F 0x82
+#define NCI_DISCOVERY_TYPE_LISTEN_A_ACTIVE 0x83
+#define NCI_DISCOVERY_TYPE_LISTEN_F_ACTIVE 0x85
+#define NCI_DISCOVERY_TYPE_LISTEN_B_PRIME 0xF4
+#define NCI_DISCOVERY_TYPE_POLL_ISO15693 0x06
+#define NCI_DISCOVERY_TYPE_LISTEN_ISO15693 0x86
+#define NCI_DISCOVERY_TYPE_MAX NCI_DISCOVERY_TYPE_LISTEN_ISO15693
+
+typedef UINT8 tNCI_DISCOVERY_TYPE;
+
+#define NCI_EE_TRIG_7816_SELECT 0x00
+#define NCI_EE_TRIG_RF_PROTOCOL 0x01
+#define NCI_EE_TRIG_RF_TECHNOLOGY 0x02
+#define NCI_EE_TRIG_APP_INIT 0x10
+
+#define NCI_EE_ACT_TAG_AID 0xC0 /* AID */
+#define NCI_EE_ACT_TAG_PROTO 0xC1 /* RF protocol */
+#define NCI_EE_ACT_TAG_TECH 0xC2 /* RF technology */
+#define NCI_EE_ACT_TAG_DATA 0xC3 /* hex data for app */
+#define NCI_EE_ACT_TAG_DEBUG 0xC4 /* debug trace */
+
+#define NCI_ROUTE_TAG_TECH 0x00 /* Technology based routing */
+#define NCI_ROUTE_TAG_PROTO 0x01 /* Protocol based routing */
+#define NCI_ROUTE_TAG_AID 0x02 /* AID routing */
+
+#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 */
+
+#define NCI_NFCEE_TAG_HW_ID 0x00 /* Hardware / Registration Identification */
+#define NCI_NFCEE_TAG_ATR_BYTES 0x01 /* ATR Bytes */
+#define NCI_NFCEE_TAG_T3T_INFO 0x02 /* T3T Command Set Interface Supplementary Info */
+#define NCI_NFCEE_TAG_HCI_HOST_ID 0xA0 /* HCI host ID */
+
+#define NCI_DISCOVER_NTF_LAST 0x00
+#define NCI_DISCOVER_NTF_LAST_ABORT 0x01
+#define NCI_DISCOVER_NTF_MORE 0x02
+
+
+/* NCI RF Management Group Params */
+#define NCI_RF_PARAM_SIZE_T3T_POLLING 0x04 /* System Code, RC, TSN */
+
+/**********************************************
+ * NCI Parameter IDs
+ **********************************************/
+
+#define NCI_PARAM_ID_TOTAL_DURATION 0x00
+#define NCI_PARAM_ID_CON_DEVICES_LIMIT 0x01
+#define NCI_PARAM_ID_PA_BAILOUT 0x08
+#define NCI_PARAM_ID_PB_AFI 0x10
+#define NCI_PARAM_ID_PB_BAILOUT 0x11
+#define NCI_PARAM_ID_PB_ATTRIB_PARAM1 0x12
+#define NCI_PARAM_ID_PF_BIT_RATE 0x18
+#define NCI_PARAM_ID_PB_H_INFO 0x20
+#define NCI_PARAM_ID_PI_BIT_RATE 0x21
+
+#define NCI_PARAM_ID_BITR_NFC_DEP 0x28
+#define NCI_PARAM_ID_ATR_REQ_GEN_BYTES 0x29
+#define NCI_PARAM_ID_ATR_REQ_CONFIG 0x2A
+
+#define NCI_PARAM_ID_LA_BIT_FRAME_SDD 0x30
+#define NCI_PARAM_ID_LA_PLATFORM_CONFIG 0x31
+#define NCI_PARAM_ID_LA_SEL_INFO 0x32
+#define NCI_PARAM_ID_LA_NFCID1 0x33
+#define NCI_PARAM_ID_LB_SENSB_INFO 0x38
+#define NCI_PARAM_ID_LB_NFCID0 0x39
+#define NCI_PARAM_ID_LB_APPDATA 0x3A
+#define NCI_PARAM_ID_LB_SFGI 0x3B
+#define NCI_PARAM_ID_LB_ADC_FO 0x3C
+#define NCI_PARAM_ID_LB_PROTOCOL NCI_PARAM_ID_LB_SENSB_INFO
+
+#define NCI_PARAM_ID_LF_T3T_ID1 0x40
+#define NCI_PARAM_ID_LF_T3T_ID2 0x41
+#define NCI_PARAM_ID_LF_T3T_ID3 0x42
+#define NCI_PARAM_ID_LF_T3T_ID4 0x43
+#define NCI_PARAM_ID_LF_T3T_ID5 0x44
+#define NCI_PARAM_ID_LF_T3T_ID6 0x45
+#define NCI_PARAM_ID_LF_T3T_ID7 0x46
+#define NCI_PARAM_ID_LF_T3T_ID8 0x47
+#define NCI_PARAM_ID_LF_T3T_ID9 0x48
+#define NCI_PARAM_ID_LF_T3T_ID10 0x49
+#define NCI_PARAM_ID_LF_T3T_ID11 0x4A
+#define NCI_PARAM_ID_LF_T3T_ID12 0x4B
+#define NCI_PARAM_ID_LF_T3T_ID13 0x4C
+#define NCI_PARAM_ID_LF_T3T_ID14 0x4D
+#define NCI_PARAM_ID_LF_T3T_ID15 0x4E
+#define NCI_PARAM_ID_LF_T3T_ID16 0x4F
+#define NCI_PARAM_ID_LF_PROTOCOL 0x50
+#define NCI_PARAM_ID_LF_T3T_PMM 0x51
+#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_FWI 0x58
+#define NCI_PARAM_ID_LA_HIST_BY 0x59
+#define NCI_PARAM_ID_LB_H_INFO_RSP 0x5A
+#define NCI_PARAM_ID_LI_BIT_RATE 0x5B
+
+#define NCI_PARAM_ID_WT 0x60
+#define NCI_PARAM_ID_ATR_RES_GEN_BYTES 0x61
+#define NCI_PARAM_ID_ATR_RSP_CONFIG 0x62
+
+#define NCI_PARAM_ID_RF_FIELD_INFO 0x80
+#define NCI_PARAM_ID_RF_NFCEE_ACTION 0x81
+#define NCI_PARAM_ID_NFC_DEP_OP 0x82
+
+
+
+/* NCI_PARAM_ID_HOST_LISTEN_MASK (byte1 for DH, byte2 for UICC) */
+#define NCI_LISTEN_MASK_A 0x01 /* (0x01 << (NCI_DISCOVERY_TYPE_LISTEN_A_PASSIVE & 0x0F)) */
+#define NCI_LISTEN_MASK_B 0x02 /* (0x01 << (NCI_DISCOVERY_TYPE_LISTEN_B_PASSIVE & 0x0F)) */
+#define NCI_LISTEN_MASK_F 0x04 /* (0x01 << (NCI_DISCOVERY_TYPE_LISTEN_F_PASSIVE & 0x0F)) */
+#define NCI_LISTEN_MASK_A_ACTIVE 0x08 /* (0x01 << (NCI_DISCOVERY_TYPE_LISTEN_A_ACTIVE & 0x0F)) */
+#define NCI_LISTEN_MASK_B_PRIME 0x10 /* (0x01 << (NCI_DISCOVERY_TYPE_LISTEN_B_PRIME & 0x0F)) */
+#define NCI_LISTEN_MASK_F_ACTIVE 0x20 /* (0x01 << (NCI_DISCOVERY_TYPE_LISTEN_F_ACTIVE & 0x0F)) */
+#define NCI_LISTEN_MASK_ISO15693 0x40 /* (0x01 << (NCI_DISCOVERY_TYPE_LISTEN_ISO15693 & 0x0F)) */
+
+/* Type A Parameters */
+#define NCI_PARAM_PLATFORM_T1T 0x0C
+#define NCI_PARAM_SEL_INFO_ISODEP 0x20
+#define NCI_PARAM_SEL_INFO_NFCDEP 0x40
+/**********************************************
+ * NCI Parameter ID Lens
+ **********************************************/
+#define NCI_PARAM_LEN_TOTAL_DURATION 2
+
+#define NCI_PARAM_LEN_PA_FSDI 1
+
+#define NCI_PARAM_LEN_LA_BIT_FRAME_SDD 1
+#define NCI_PARAM_LEN_LA_PLATFORM_CONFIG 1
+#define NCI_PARAM_LEN_LA_SEL_INFO 1
+
+#define NCI_PARAM_LEN_LB_SENSB_INFO 1
+#define NCI_PARAM_LEN_LB_NFCID0 4
+#define NCI_PARAM_LEN_LB_APPDATA 4
+#define NCI_PARAM_LEN_LB_ADC_FO 1
+
+#define NCI_PARAM_LEN_LF_PROTOCOL 1
+#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_FWI 1
+#define NCI_PARAM_LEN_WT 1
+/* GEN_BYTES - variable */
+
+/* Listen protocol bits - NCI_PARAM_ID_LF_PROTOCOL and NCI_PARAM_ID_LB_SENSB_INFO */
+#define NCI_LISTEN_PROTOCOL_ISO_DEP 0x01
+#define NCI_LISTEN_PROTOCOL_NFC_DEP 0x02
+
+#define NCI_DISCOVER_PARAM_SIZE_TEST_RF 0x06
+
+
+/* LF_T3T_FLAGS2 listen bits all-disabled definition */
+#define NCI_LF_T3T_FLAGS2_ALL_DISABLED 0x0000
+#define NCI_LF_T3T_FLAGS2_ID1_ENABLED 0x0001
+
+typedef struct
+{
+ UINT16 addr;
+ UINT8 len;
+ UINT8 *data;
+} NCIP_T1T_SETMEM_CMD_t;
+
+typedef struct
+{
+ UINT8 status;
+} NCIP_T1T_SETMEM_RSP_t;
+
+typedef struct
+{
+ UINT16 addr;
+} NCIP_T1T_GETMEM_CMD_t;
+
+typedef struct
+{
+ UINT8 status;
+ UINT8 *data;
+} NCIP_T1T_GETMEM_RSP_t;
+
+typedef struct
+{
+ UINT8 hr0;
+ UINT8 hr1;
+} NCIP_T1T_SETHR_CMD_t;
+
+typedef struct
+{
+ UINT8 status;
+} NCIP_T1T_SETHR_RSP_t;
+
+
+#ifndef NCI_GET_CMD_BUF
+#if (!defined (HCI_USE_VARIABLE_SIZE_CMD_BUF) || (HCI_USE_VARIABLE_SIZE_CMD_BUF == FALSE))
+/* Allocate fixed-size buffer from HCI_CMD_POOL (default case) */
+#define NCI_GET_CMD_BUF(paramlen) ((BT_HDR *) GKI_getpoolbuf (NFC_NCI_POOL_ID))
+#else
+/* Allocate smallest possible buffer (for platforms with limited RAM) */
+#define NCI_GET_CMD_BUF(paramlen) ((BT_HDR *) GKI_getbuf ((UINT16) (BT_HDR_SIZE + NCI_MSG_HDR_SIZE + NCI_MSG_OFFSET_SIZE + (paramlen))))
+#endif
+#endif /* NCI_GET_CMD_BUF */
+
+
+#define NCI_MAX_AID_LEN 16
+
+
+typedef struct
+{
+ UINT8 type;
+ UINT8 frequency;
+} tNCI_DISCOVER_PARAMS;
+
+typedef struct
+{
+ UINT8 protocol;
+ UINT8 mode;
+ UINT8 intf_type;
+} tNCI_DISCOVER_MAPS;
+
+#define NCI_NFCID1_MAX_LEN 10
+typedef struct
+{
+ UINT8 sens_res[2];/* SENS_RES Response (ATQA). Available after Technology Detection */
+ UINT8 nfcid1_len; /* 4, 7 or 10 */
+ UINT8 nfcid1[NCI_NFCID1_MAX_LEN]; /* AKA NFCID1 */
+ UINT8 sel_rsp; /* SEL_RSP (SAK) Available after Collision Resolution */
+} tNCI_RF_PA_PARAMS;
+
+
+#define NCI_MAX_SENSB_RES_LEN 12
+typedef struct
+{
+ UINT8 sensb_res_len;/* Length of SENSB_RES Response (Byte 2 - Byte 12 or 13) Available after Technology Detection */
+ UINT8 sensb_res[NCI_MAX_SENSB_RES_LEN]; /* SENSB_RES Response (ATQ) */
+} tNCI_RF_PB_PARAMS;
+
+#define NCI_MAX_SENSF_RES_LEN 18
+#define NCI_SENSF_RES_OFFSET_PAD0 8
+#define NCI_SENSF_RES_OFFSET_RD 16
+#define NCI_NFCID2_LEN 8
+#define NCI_T3T_PMM_LEN 8
+#define NCI_SYSTEMCODE_LEN 2
+#define NCI_RF_F_UID_LEN NCI_NFCID2_LEN
+#define NCI_MRTI_CHECK_INDEX 13
+#define NCI_MRTI_UPDATE_INDEX 14
+typedef struct
+{
+ UINT8 bit_rate;/* NFC_BIT_RATE_212 or NFC_BIT_RATE_424 */
+ UINT8 sensf_res_len;/* Length of SENSF_RES Response (Byte 2 - Byte 17 or 19) Available after Technology Detection */
+ UINT8 sensf_res[NCI_MAX_SENSF_RES_LEN]; /* SENSB_RES Response */
+} tNCI_RF_PF_PARAMS;
+
+typedef struct
+{
+ UINT8 nfcid2[NCI_NFCID2_LEN]; /* NFCID2 generated by the Local NFCC for NFC-DEP Protocol.Available for Frame Interface */
+} tNCI_RF_LF_PARAMS;
+
+typedef struct
+{
+ tNCI_DISCOVERY_TYPE mode;
+ union
+ {
+ tNCI_RF_PA_PARAMS pa;
+ tNCI_RF_PB_PARAMS pb;
+ tNCI_RF_PF_PARAMS pf;
+ tNCI_RF_LF_PARAMS lf;
+ } param; /* Discovery Type specific parameters */
+} tNCI_RF_TECH_PARAMS;
+
+
+#ifndef NCI_MAX_ATS_LEN
+#define NCI_MAX_ATS_LEN 60
+#endif
+#ifndef NCI_MAX_HIS_BYTES_LEN
+#define NCI_MAX_HIS_BYTES_LEN 50
+#endif
+#ifndef NCI_MAX_GEN_BYTES_LEN
+#define NCI_MAX_GEN_BYTES_LEN 48
+#endif
+
+#define NCI_ATS_T0_INDEX 0
+#define NCI_ATS_TC_MASK 0x40
+#define NCI_ATS_TB_MASK 0x20
+#define NCI_ATS_TA_MASK 0x10
+#define NCI_ATS_FSCI_MASK 0x0F
+typedef struct
+{
+ UINT8 ats_res_len; /* Length of ATS RES */
+ UINT8 ats_res[NCI_MAX_ATS_LEN]; /* ATS RES defined in [DIGPROT] */
+} tNCI_INTF_PA_ISO_DEP;
+
+typedef struct
+{
+ UINT8 rats; /* RATS */
+} tNCI_INTF_LA_ISO_DEP;
+
+#define NCI_P_GEN_BYTE_INDEX 15
+#define NCI_L_GEN_BYTE_INDEX 14
+#define NCI_L_NFC_DEP_TO_INDEX 13
+typedef struct
+{
+ UINT8 atr_res_len; /* Length of ATR_RES */
+ UINT8 atr_res[NCI_MAX_ATS_LEN]; /* ATR_RES (Byte 3 - Byte 17+n) as defined in [DIGPROT] */
+} tNCI_INTF_PA_NFC_DEP;
+
+/* Note: keep tNCI_INTF_PA_NFC_DEP data member in the same order as tNCI_INTF_LA_NFC_DEP */
+typedef struct
+{
+ UINT8 atr_req_len; /* Length of ATR_REQ */
+ UINT8 atr_req[NCI_MAX_ATS_LEN]; /* ATR_REQ (Byte 3 - Byte 18+n) as defined in [DIGPROT] */
+} tNCI_INTF_LA_NFC_DEP;
+typedef tNCI_INTF_LA_NFC_DEP tNCI_INTF_LF_NFC_DEP;
+typedef tNCI_INTF_PA_NFC_DEP tNCI_INTF_PF_NFC_DEP;
+
+#define NCI_MAX_ATTRIB_LEN (10 + NCI_MAX_GEN_BYTES_LEN)
+
+typedef struct
+{
+ UINT8 attrib_res_len; /* Length of ATTRIB RES */
+ UINT8 attrib_res[NCI_MAX_ATTRIB_LEN]; /* ATTRIB RES as defined in [DIGPROT] */
+} tNCI_INTF_PB_ISO_DEP;
+
+typedef struct
+{
+ UINT8 attrib_req_len; /* Length of ATTRIB REQ */
+ UINT8 attrib_req[NCI_MAX_ATTRIB_LEN]; /* ATTRIB REQ (Byte 2 - Byte 10+k) as defined in [DIGPROT] */
+} tNCI_INTF_LB_ISO_DEP;
+
+typedef struct
+{
+ tNCI_INTF_TYPE type; /* Interface Type 1 Byte See Table 67 */
+ union
+ {
+ tNCI_INTF_LA_ISO_DEP la_iso;
+ tNCI_INTF_PA_ISO_DEP pa_iso;
+ tNCI_INTF_LB_ISO_DEP lb_iso;
+ tNCI_INTF_PB_ISO_DEP pb_iso;
+ tNCI_INTF_LA_NFC_DEP la_nfc;
+ tNCI_INTF_PA_NFC_DEP pa_nfc;
+ tNCI_INTF_LF_NFC_DEP lf_nfc;
+ tNCI_INTF_PF_NFC_DEP pf_nfc;
+ } intf_param; /* Activation Parameters 0 - n Bytes */
+} tNCI_INTF_PARAMS;
+
+/*
+** HCI Network CMD/NTF structure
+*/
+typedef struct
+{
+ UINT8 pipe_id; /* if MSB is set then valid, 7 bits for Pipe ID */
+ UINT8 mode; /* Type A card emulation enabled indicator, 0x02:enabled */
+ UINT8 sak;
+ UINT8 uid_reg_len;
+ UINT8 uid_reg[10];
+ UINT8 atqa[2]; /* ATQA response code */
+ UINT8 app_data_len;
+ UINT8 app_data[15]; /* 15 bytes optional storage for historic data, use 2 slots */
+ UINT8 fwi_sfgi; /* FRAME WAITING TIME, START-UP FRAME GUARD TIME */
+ UINT8 cid_support;
+ UINT8 datarate_max[3];
+ UINT8 clt_support;
+} tNCI_HCI_CE_RF_A;
+
+typedef struct
+{
+ UINT8 pipe_id; /* if MSB is set then valid, 7 bits for Pipe ID */
+ UINT8 mode; /* Type B card emulation enabled indicator, 0x02:enabled */
+ UINT8 pupi_len;
+ UINT8 pupi_reg[4];
+ UINT8 afi;
+ UINT8 atqb[4]; /* 4 bytes ATQB application data */
+ UINT8 higherlayer_resp[61]; /* 0~ 61 bytes ATRB_INF use 1~4 personality slots */
+ UINT8 datarate_max[3];
+ UINT8 natrb;
+} tNCI_HCI_CE_RF_B;
+
+typedef struct
+{
+ UINT8 pipe_id; /* if MSB is set then valid, 7 bits for Pipe ID */
+ UINT8 mode; /* Type B prime card emulation enabled indicator, 0x02:enabled */
+ UINT8 pat_in_len;
+ UINT8 pat_in[8];
+ UINT8 dat_out_len;
+ UINT8 dat_out[40]; /* ISO7816-3 <=64 byte, and other fields are 9 bytes */
+ UINT8 natr;
+} tNCI_HCI_CE_RF_BP;
+
+typedef struct
+{
+ UINT8 pipe_id; /* if MSB is set then valid, 7 bits for Pipe ID */
+ UINT8 mode; /* Type F card emulation enabled indicator, 0x02:enabled */
+ UINT8 speed_cap;
+ UINT8 clt_support;
+} tNCI_HCI_CE_RF_F;
+
+typedef struct
+{
+ UINT8 pipe_id; /* if MSB is set then valid, 7 bits for Pipe ID */
+ UINT8 datarate_max;
+} tNCI_HCI_RD_RF_A;
+
+typedef struct
+{
+ UINT8 pipe_id; /* if MSB is set then valid, 7 bits for Pipe ID */
+ UINT8 afi;
+ UINT8 hldata_len;
+ UINT8 high_layer_data[61]; /* INF field in ATTRIB command */
+} tNCI_HCI_RD_RF_B;
+
+typedef struct
+{
+ UINT8 source_host;
+ UINT8 dest_host;
+ UINT8 source_gate;
+ UINT8 dest_gate;
+ UINT8 pipe_id; /* if MSB is set then valid, 7 bits for Pipe ID */
+} tNCI_HCI_DYN_PIPE_INFO;
+
+typedef struct
+{
+ UINT8 target_handle;
+ UINT8 session_id[8];
+ UINT8 sync_id[2];
+ UINT8 static_pipe_info;
+ tNCI_HCI_CE_RF_A ce_rf_a;
+ tNCI_HCI_CE_RF_B ce_rf_b;
+ tNCI_HCI_CE_RF_BP ce_rf_bp;
+ tNCI_HCI_CE_RF_F ce_rf_f;
+} tNCI_HCI_NETWK;
+
+typedef struct
+{
+ UINT8 target_handle;
+ UINT8 session_id[8];
+ UINT8 static_pipe_info;
+ UINT8 num_dyn_pipes;
+ tNCI_HCI_DYN_PIPE_INFO dyn_pipe_info[20];
+} tNCI_HCI_NETWK_DH;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NFC_NCI_DEFS_H */
diff --git a/halimpl/bcm2079x/hal/include/nfc_hal_api.h b/halimpl/bcm2079x/hal/include/nfc_hal_api.h
new file mode 100644
index 0000000..d147527
--- /dev/null
+++ b/halimpl/bcm2079x/hal/include/nfc_hal_api.h
@@ -0,0 +1,223 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * NFC Hardware Abstraction Layer API
+ *
+ ******************************************************************************/
+#ifndef NFC_HAL_API_H
+#define NFC_HAL_API_H
+#include <hardware/nfc.h>
+#include "data_types.h"
+
+/****************************************************************************
+** NFC_HDR header definition for NFC messages
+*****************************************************************************/
+typedef struct
+{
+ UINT16 event;
+ UINT16 len;
+ UINT16 offset;
+ UINT16 layer_specific;
+} NFC_HDR;
+#define NFC_HDR_SIZE (sizeof (NFC_HDR))
+
+typedef UINT8 tHAL_NFC_STATUS;
+
+typedef void (tHAL_NFC_STATUS_CBACK) (tHAL_NFC_STATUS status);
+typedef void (tHAL_NFC_CBACK) (UINT8 event, tHAL_NFC_STATUS status);
+typedef void (tHAL_NFC_DATA_CBACK) (UINT16 data_len, UINT8 *p_data);
+
+/*******************************************************************************
+** tHAL_NFC_ENTRY HAL entry-point lookup table
+*******************************************************************************/
+
+typedef void (tHAL_API_INITIALIZE) (void);
+typedef void (tHAL_API_TERMINATE) (void);
+typedef void (tHAL_API_OPEN) (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback);
+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);
+typedef BOOLEAN (tHAL_API_PREDISCOVER) (void);
+typedef void (tHAL_API_CONTROL_GRANTED) (void);
+typedef void (tHAL_API_POWER_CYCLE) (void);
+
+
+typedef struct
+{
+ tHAL_API_INITIALIZE *initialize;
+ tHAL_API_TERMINATE *terminate;
+ tHAL_API_OPEN *open;
+ tHAL_API_CLOSE *close;
+ tHAL_API_CORE_INITIALIZED *core_initialized;
+ tHAL_API_WRITE *write;
+ tHAL_API_PREDISCOVER *prediscover;
+ tHAL_API_CONTROL_GRANTED *control_granted;
+ tHAL_API_POWER_CYCLE *power_cycle;
+
+
+} tHAL_NFC_ENTRY;
+
+
+/*******************************************************************************
+** HAL API Function Prototypes
+*******************************************************************************/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* Toolset-specific macro for exporting API funcitons */
+#if (defined(NFC_HAL_TARGET) && (NFC_HAL_TARGET == TRUE)) && (defined(_WINDLL))
+#define EXPORT_HAL_API __declspec(dllexport)
+#else
+#define EXPORT_HAL_API
+#endif
+
+/*******************************************************************************
+**
+** Function HAL_NfcInitialize
+**
+** Description Called when HAL library is loaded.
+**
+** Initialize GKI and start the HCIT task
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcInitialize(void);
+
+/*******************************************************************************
+**
+** Function HAL_NfcTerminate
+**
+** Description Called to terminate NFC HAL
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcTerminate(void);
+
+/*******************************************************************************
+**
+** Function HAL_NfcOpen
+**
+** Description Open transport and intialize the NFCC, and
+** Register callback for HAL event notifications,
+**
+** HAL_OPEN_CPLT_EVT will notify when operation is complete.
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback);
+
+/*******************************************************************************
+**
+** Function HAL_NfcClose
+**
+** Description Prepare for shutdown. A HAL_CLOSE_CPLT_EVT will be
+** reported when complete.
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcClose (void);
+
+/*******************************************************************************
+**
+** Function HAL_NfcCoreInitialized
+**
+** Description Called after the CORE_INIT_RSP is received from the NFCC.
+** At this time, the HAL can do any chip-specific configuration,
+** and when finished signal the libnfc-nci with event
+** HAL_POST_INIT_CPLT_EVT.
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcCoreInitialized (UINT8 *p_core_init_rsp_params);
+
+/*******************************************************************************
+**
+** Function HAL_NfcWrite
+**
+** Description Send an NCI control message or data packet to the
+** transport. If an NCI command message exceeds the transport
+** size, HAL is responsible for fragmenting it, Data packets
+** must be of the correct size.
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcWrite (UINT16 data_len, UINT8 *p_data);
+
+/*******************************************************************************
+**
+** Function HAL_NfcPreDiscover
+**
+** Description Perform any vendor-specific pre-discovery actions (if needed)
+** If any actions were performed TRUE will be returned, and
+** HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are
+** completed.
+**
+** Returns TRUE if vendor-specific pre-discovery actions initialized
+** FALSE if no vendor-specific pre-discovery actions are needed.
+**
+*******************************************************************************/
+EXPORT_HAL_API BOOLEAN HAL_NfcPreDiscover (void);
+
+/*******************************************************************************
+**
+** Function HAL_NfcControlGranted
+**
+** Description Grant control to HAL control for sending NCI commands.
+**
+** Call in response to HAL_REQUEST_CONTROL_EVT.
+**
+** Must only be called when there are no NCI commands pending.
+**
+** HAL_RELEASE_CONTROL_EVT will notify when HAL no longer
+** needs control of NCI.
+**
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcControlGranted (void);
+
+/*******************************************************************************
+**
+** Function HAL_NfcPowerCycle
+**
+** Description Restart NFCC by power cyle
+**
+** HAL_OPEN_CPLT_EVT will notify when operation is complete.
+**
+** Returns void
+**
+*******************************************************************************/
+EXPORT_HAL_API void HAL_NfcPowerCycle (void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NFC_HAL_API_H */
diff --git a/halimpl/bcm2079x/hal/include/nfc_hal_target.h b/halimpl/bcm2079x/hal/include/nfc_hal_target.h
new file mode 100644
index 0000000..b6eedc9
--- /dev/null
+++ b/halimpl/bcm2079x/hal/include/nfc_hal_target.h
@@ -0,0 +1,244 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+#ifndef NFC_HAL_TARGET_H
+#define NFC_HAL_TARGET_H
+
+#include "data_types.h"
+
+#ifdef BUILDCFG
+#include "buildcfg_hal.h"
+#endif
+
+/****************************************************************************
+** NCI related configuration
+****************************************************************************/
+
+/* GKI pool for NCI messages */
+#ifndef NFC_HAL_NCI_POOL_ID
+#define NFC_HAL_NCI_POOL_ID GKI_POOL_ID_1
+#endif
+
+#ifndef NFC_HAL_NCI_POOL_BUF_SIZE
+#define NFC_HAL_NCI_POOL_BUF_SIZE GKI_BUF1_SIZE
+#endif
+
+/* Initial Max Control Packet Payload Size (until receiving payload size in INIT_CORE_RSP) */
+#ifndef NFC_HAL_NCI_INIT_CTRL_PAYLOAD_SIZE
+#define NFC_HAL_NCI_INIT_CTRL_PAYLOAD_SIZE 0xFF
+#endif
+
+/* Number of bytes to reserve in front of NCI messages (e.g. for transport header) */
+#ifndef NFC_HAL_NCI_MSG_OFFSET_SIZE
+#define NFC_HAL_NCI_MSG_OFFSET_SIZE 1
+#endif
+
+/* NFC-WAKE */
+#ifndef NFC_HAL_LP_NFC_WAKE_GPIO
+#define NFC_HAL_LP_NFC_WAKE_GPIO UPIO_GENERAL3
+#endif
+
+/* NFCC snooze mode idle timeout before deassert NFC_WAKE in ms */
+#ifndef NFC_HAL_LP_IDLE_TIMEOUT
+#define NFC_HAL_LP_IDLE_TIMEOUT 100
+#endif
+
+/* NFC snooze mode */
+#ifndef NFC_HAL_LP_SNOOZE_MODE
+#define NFC_HAL_LP_SNOOZE_MODE NFC_HAL_LP_SNOOZE_MODE_UART
+#endif
+
+/* Idle Threshold Host in 100ms unit */
+#ifndef NFC_HAL_LP_IDLE_THRESHOLD_HOST
+#define NFC_HAL_LP_IDLE_THRESHOLD_HOST 0
+#endif
+
+/* Idle Threshold HC in 100ms unit */
+#ifndef NFC_HAL_LP_IDLE_THRESHOLD_HC
+#define NFC_HAL_LP_IDLE_THRESHOLD_HC 0
+#endif
+
+
+/* Default NFCC power-up baud rate */
+#ifndef NFC_HAL_DEFAULT_BAUD
+#define NFC_HAL_DEFAULT_BAUD USERIAL_BAUD_115200
+#endif
+
+/* time (in ms) between power off and on NFCC */
+#ifndef NFC_HAL_POWER_CYCLE_DELAY
+#define NFC_HAL_POWER_CYCLE_DELAY 100
+#endif
+
+#ifndef NFC_HAL_PRM_DEBUG
+#define NFC_HAL_PRM_DEBUG TRUE
+#endif
+
+/* max patch data length (Can be overridden by platform for ACL HCI command size) */
+#ifndef NFC_HAL_PRM_HCD_CMD_MAXLEN
+#define NFC_HAL_PRM_HCD_CMD_MAXLEN 250
+#endif
+
+/* Require PreI2C patch by default */
+#ifndef NFC_HAL_PRE_I2C_PATCH_INCLUDED
+#define NFC_HAL_PRE_I2C_PATCH_INCLUDED TRUE
+#endif
+
+/* Set to TRUE to always download patch regardless of version */
+#ifndef NFC_HAL_PRM_SKIP_VERSION_CHECK
+#define NFC_HAL_PRM_SKIP_VERSION_CHECK FALSE
+#endif
+
+/* Mininum payload size for SPD NCI commands (used to validate HAL_NfcPrmSetSpdNciCmdPayloadSize) */
+/* Default is 32, as required by the NCI specifications; however this value may be */
+/* over-riden for platforms that have transport packet limitations */
+#ifndef NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE
+#define NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE (32)
+#endif
+
+/* amount of time to wait for RESET NTF after patch download */
+#ifndef NFC_HAL_PRM_RESET_NTF_DELAY
+#define NFC_HAL_PRM_RESET_NTF_DELAY (10000)
+#endif
+
+/* amount of time to wait after downloading preI2C patch before downloading LPM/FPM patch */
+#ifndef NFC_HAL_PRM_POST_I2C_FIX_DELAY
+#define NFC_HAL_PRM_POST_I2C_FIX_DELAY (200)
+#endif
+
+/* NFCC will respond to more than one technology during listen discovery */
+#ifndef NFC_HAL_DM_MULTI_TECH_RESP
+#define NFC_HAL_DM_MULTI_TECH_RESP TRUE
+#endif
+
+/* Data rate for 15693 command/response, it must be same as RW_I93_FLAG_DATA_RATE in nfc_target.h */
+#define NFC_HAL_I93_FLAG_DATA_RATE_LOW 0x00
+#define NFC_HAL_I93_FLAG_DATA_RATE_HIGH 0x02
+
+#ifndef NFC_HAL_I93_FLAG_DATA_RATE
+#define NFC_HAL_I93_FLAG_DATA_RATE NFC_HAL_I93_FLAG_DATA_RATE_HIGH
+#endif
+
+/* Quick Timer */
+#ifndef QUICK_TIMER_TICKS_PER_SEC
+#define QUICK_TIMER_TICKS_PER_SEC 100 /* 10ms timer */
+#endif
+
+#ifndef NFC_HAL_SHARED_TRANSPORT_ENABLED
+#define NFC_HAL_SHARED_TRANSPORT_ENABLED FALSE
+#endif
+
+/* Enable verbose tracing by default */
+#ifndef NFC_HAL_TRACE_VERBOSE
+#define NFC_HAL_TRACE_VERBOSE TRUE
+#endif
+
+#ifndef NFC_HAL_INITIAL_TRACE_LEVEL
+#define NFC_HAL_INITIAL_TRACE_LEVEL 5
+#endif
+
+/* Map NFC serial port to USERIAL_PORT_6 by default */
+#ifndef USERIAL_NFC_PORT
+#define USERIAL_NFC_PORT (USERIAL_PORT_6)
+#endif
+
+/* Restore NFCC baud rate to default on shutdown if baud rate was updated */
+#ifndef NFC_HAL_RESTORE_BAUD_ON_SHUTDOWN
+#define NFC_HAL_RESTORE_BAUD_ON_SHUTDOWN TRUE
+#endif
+
+/* Enable protocol tracing by default */
+#ifndef NFC_HAL_TRACE_PROTOCOL
+#define NFC_HAL_TRACE_PROTOCOL TRUE
+#endif
+#define BT_TRACE_PROTOCOL (NFC_HAL_TRACE_PROTOCOL)
+
+#define LogMsg_0 LogMsg
+#define LogMsg_1 LogMsg
+#define LogMsg_2 LogMsg
+#define LogMsg_3 LogMsg
+#define LogMsg_4 LogMsg
+#define LogMsg_5 LogMsg
+#define LogMsg_6 LogMsg
+
+/* Trace macros */
+#define BT_TRACE_0(l,t,m) LogMsg_0((TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t)),(m))
+#define BT_TRACE_1(l,t,m,p1) LogMsg_1(TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t),(m),(UINT32)(p1))
+#define BT_TRACE_2(l,t,m,p1,p2) LogMsg_2(TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t),(m),(UINT32)(p1), \
+ (UINT32)(p2))
+#define BT_TRACE_3(l,t,m,p1,p2,p3) LogMsg_3(TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t),(m),(UINT32)(p1), \
+ (UINT32)(p2),(UINT32)(p3))
+#define BT_TRACE_4(l,t,m,p1,p2,p3,p4) LogMsg_4(TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t),(m),(UINT32)(p1), \
+ (UINT32)(p2),(UINT32)(p3),(UINT32)(p4))
+#define BT_TRACE_5(l,t,m,p1,p2,p3,p4,p5) LogMsg_5(TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t),(m),(UINT32)(p1), \
+ (UINT32)(p2),(UINT32)(p3),(UINT32)(p4), \
+ (UINT32)(p5))
+#define BT_TRACE_6(l,t,m,p1,p2,p3,p4,p5,p6) LogMsg_6(TRACE_CTRL_GENERAL | (l) | TRACE_ORG_STACK | (t),(m),(UINT32)(p1), \
+ (UINT32)(p2),(UINT32)(p3),(UINT32)(p4), \
+ (UINT32)(p5),(UINT32)(p6))
+
+#define NCI_TRACE_ERROR0(m) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE_0(TRACE_LAYER_NCI, TRACE_TYPE_ERROR, m);}
+#define NCI_TRACE_ERROR1(m,p1) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE_1(TRACE_LAYER_NCI, TRACE_TYPE_ERROR, m,p1);}
+#define NCI_TRACE_ERROR2(m,p1,p2) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE_2(TRACE_LAYER_NCI, TRACE_TYPE_ERROR, m,p1,p2);}
+#define NCI_TRACE_ERROR3(m,p1,p2,p3) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE_3(TRACE_LAYER_NCI, TRACE_TYPE_ERROR, m,p1,p2,p3);}
+#define NCI_TRACE_ERROR4(m,p1,p2,p3,p4) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE_4(TRACE_LAYER_NCI, TRACE_TYPE_ERROR, m,p1,p2,p3,p4);}
+#define NCI_TRACE_ERROR5(m,p1,p2,p3,p4,p5) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE_5(TRACE_LAYER_NCI, TRACE_TYPE_ERROR, m,p1,p2,p3,p4,p5);}
+#define NCI_TRACE_ERROR6(m,p1,p2,p3,p4,p5,p6) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_ERROR) BT_TRACE_6(TRACE_LAYER_NCI, TRACE_TYPE_ERROR, m,p1,p2,p3,p4,p5,p6);}
+
+#define NCI_TRACE_WARNING0(m) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE_0(TRACE_LAYER_NCI, TRACE_TYPE_WARNING, m);}
+#define NCI_TRACE_WARNING1(m,p1) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE_1(TRACE_LAYER_NCI, TRACE_TYPE_WARNING, m,p1);}
+#define NCI_TRACE_WARNING2(m,p1,p2) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE_2(TRACE_LAYER_NCI, TRACE_TYPE_WARNING, m,p1,p2);}
+#define NCI_TRACE_WARNING3(m,p1,p2,p3) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE_3(TRACE_LAYER_NCI, TRACE_TYPE_WARNING, m,p1,p2,p3);}
+#define NCI_TRACE_WARNING4(m,p1,p2,p3,p4) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE_4(TRACE_LAYER_NCI, TRACE_TYPE_WARNING, m,p1,p2,p3,p4);}
+#define NCI_TRACE_WARNING5(m,p1,p2,p3,p4,p5) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE_5(TRACE_LAYER_NCI, TRACE_TYPE_WARNING, m,p1,p2,p3,p4,p5);}
+#define NCI_TRACE_WARNING6(m,p1,p2,p3,p4,p5,p6) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_WARNING) BT_TRACE_6(TRACE_LAYER_NCI, TRACE_TYPE_WARNING, m,p1,p2,p3,p4,p5,p6);}
+
+#define NCI_TRACE_API0(m) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_API) BT_TRACE_0(TRACE_LAYER_NCI, TRACE_TYPE_API, m);}
+#define NCI_TRACE_API1(m,p1) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_API) BT_TRACE_1(TRACE_LAYER_NCI, TRACE_TYPE_API, m,p1);}
+#define NCI_TRACE_API2(m,p1,p2) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_API) BT_TRACE_2(TRACE_LAYER_NCI, TRACE_TYPE_API, m,p1,p2);}
+#define NCI_TRACE_API3(m,p1,p2,p3) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_API) BT_TRACE_3(TRACE_LAYER_NCI, TRACE_TYPE_API, m,p1,p2,p3);}
+#define NCI_TRACE_API4(m,p1,p2,p3,p4) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_API) BT_TRACE_4(TRACE_LAYER_NCI, TRACE_TYPE_API, m,p1,p2,p3,p4);}
+#define NCI_TRACE_API5(m,p1,p2,p3,p4,p5) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_API) BT_TRACE_5(TRACE_LAYER_NCI, TRACE_TYPE_API, m,p1,p2,p3,p4,p5);}
+#define NCI_TRACE_API6(m,p1,p2,p3,p4,p5,p6) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_API) BT_TRACE_6(TRACE_LAYER_NCI, TRACE_TYPE_API, m,p1,p2,p3,p4,p5,p6);}
+
+#define NCI_TRACE_EVENT0(m) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE_0(TRACE_LAYER_NCI, TRACE_TYPE_EVENT, m);}
+#define NCI_TRACE_EVENT1(m,p1) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE_1(TRACE_LAYER_NCI, TRACE_TYPE_EVENT, m, p1);}
+#define NCI_TRACE_EVENT2(m,p1,p2) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE_2(TRACE_LAYER_NCI, TRACE_TYPE_EVENT, m,p1,p2);}
+#define NCI_TRACE_EVENT3(m,p1,p2,p3) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE_3(TRACE_LAYER_NCI, TRACE_TYPE_EVENT, m,p1,p2,p3);}
+#define NCI_TRACE_EVENT4(m,p1,p2,p3,p4) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE_4(TRACE_LAYER_NCI, TRACE_TYPE_EVENT, m,p1,p2,p3,p4);}
+#define NCI_TRACE_EVENT5(m,p1,p2,p3,p4,p5) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE_5(TRACE_LAYER_NCI, TRACE_TYPE_EVENT, m,p1,p2,p3,p4,p5);}
+#define NCI_TRACE_EVENT6(m,p1,p2,p3,p4,p5,p6) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_EVENT) BT_TRACE_6(TRACE_LAYER_NCI, TRACE_TYPE_EVENT, m,p1,p2,p3,p4,p5,p6);}
+
+#define NCI_TRACE_DEBUG0(m) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE_0(TRACE_LAYER_NCI, TRACE_TYPE_DEBUG, m);}
+#define NCI_TRACE_DEBUG1(m,p1) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE_1(TRACE_LAYER_NCI, TRACE_TYPE_DEBUG, m,p1);}
+#define NCI_TRACE_DEBUG2(m,p1,p2) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE_2(TRACE_LAYER_NCI, TRACE_TYPE_DEBUG, m,p1,p2);}
+#define NCI_TRACE_DEBUG3(m,p1,p2,p3) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE_3(TRACE_LAYER_NCI, TRACE_TYPE_DEBUG, m,p1,p2,p3);}
+#define NCI_TRACE_DEBUG4(m,p1,p2,p3,p4) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE_4(TRACE_LAYER_NCI, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);}
+#define NCI_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE_5(TRACE_LAYER_NCI, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);}
+#define NCI_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {if (nfc_hal_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) BT_TRACE_6(TRACE_LAYER_NCI, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);}
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+extern void LogMsg (UINT32 trace_set_mask, const char *fmt_str, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GKI_TARGET_H */
diff --git a/halimpl/bcm2079x/hal/include/nfc_types.h b/halimpl/bcm2079x/hal/include/nfc_types.h
new file mode 100644
index 0000000..c4a963f
--- /dev/null
+++ b/halimpl/bcm2079x/hal/include/nfc_types.h
@@ -0,0 +1,147 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+
+#ifndef NFC_TYPES_H
+#define NFC_TYPES_H
+
+/* Mask for NFC_HDR event field */
+#define NFC_EVT_MASK 0xFF00
+#define NFC_SUB_EVT_MASK 0x00FF
+
+/****************************************************************************
+** NFC_HAL_TASK definitions
+*****************************************************************************/
+
+/* NFC_HAL_TASK event messages */
+#define NFC_HAL_EVT_TO_NFC_NCI 0x0100 /* NCI message for sending to NFCC */
+#define NFC_HAL_EVT_POST_CORE_RESET 0x0200 /* Request to start NCIT quick timer */
+#define NFC_HAL_EVT_TO_START_QUICK_TIMER 0x0300 /* Request to start chip-specific config */
+#define NFC_HAL_EVT_HCI 0x0400 /* NCI message for hci persistency data */
+#define NFC_HAL_EVT_PRE_DISCOVER 0x0500 /* NCI message to issue prediscover config */
+#define NFC_HAL_EVT_CONTROL_GRANTED 0x0600 /* permission to send commands queued in HAL*/
+
+/* NFC_HAL_TASK sub event messages */
+#define NFC_HAL_HCI_RSP_NV_READ_EVT (0x01 | NFC_HAL_EVT_HCI)
+#define NFC_HAL_HCI_RSP_NV_WRITE_EVT (0x02 | NFC_HAL_EVT_HCI)
+#define NFC_HAL_HCI_VSC_TIMEOUT_EVT (0x03 | NFC_HAL_EVT_HCI)
+
+
+/* Event masks for NFC_TASK messages */
+#define NFC_EVT_TO_NFC_NCI 0x4000 /* NCI message for sending to host stack */
+#define NFC_EVT_TO_NFC_ERR 0x4100 /* Error notification to NFC Task */
+#define NFC_EVT_TO_NFC_MSGS 0x4200 /* Messages between NFC and NCI task */
+
+/*****************************************************************************
+** Macros to get and put bytes to and from a stream (Little Endian format).
+*****************************************************************************/
+
+#define UINT32_TO_STREAM(p, u32) {*(p)++ = (UINT8)(u32); *(p)++ = (UINT8)((u32) >> 8); *(p)++ = (UINT8)((u32) >> 16); *(p)++ = (UINT8)((u32) >> 24);}
+#define UINT24_TO_STREAM(p, u24) {*(p)++ = (UINT8)(u24); *(p)++ = (UINT8)((u24) >> 8); *(p)++ = (UINT8)((u24) >> 16);}
+#define UINT16_TO_STREAM(p, u16) {*(p)++ = (UINT8)(u16); *(p)++ = (UINT8)((u16) >> 8);}
+#define UINT8_TO_STREAM(p, u8) {*(p)++ = (UINT8)(u8);}
+#define INT8_TO_STREAM(p, u8) {*(p)++ = (INT8)(u8);}
+#define ARRAY32_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < 32; ijk++) *(p)++ = (UINT8) a[31 - ijk];}
+#define ARRAY16_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < 16; ijk++) *(p)++ = (UINT8) a[15 - ijk];}
+#define ARRAY8_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < 8; ijk++) *(p)++ = (UINT8) a[7 - ijk];}
+#define BDADDR_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *(p)++ = (UINT8) a[BD_ADDR_LEN - 1 - ijk];}
+#define LAP_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < LAP_LEN; ijk++) *(p)++ = (UINT8) a[LAP_LEN - 1 - ijk];}
+#define DEVCLASS_TO_STREAM(p, a) {register int ijk; for (ijk = 0; ijk < DEV_CLASS_LEN;ijk++) *(p)++ = (UINT8) a[DEV_CLASS_LEN - 1 - ijk];}
+#define ARRAY_TO_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[ijk];}
+#define REVERSE_ARRAY_TO_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[len - 1 - ijk];}
+
+#define STREAM_TO_UINT8(u8, p) {u8 = (UINT8)(*(p)); (p) += 1;}
+#define STREAM_TO_UINT16(u16, p) {u16 = ((UINT16)(*(p)) + (((UINT16)(*((p) + 1))) << 8)); (p) += 2;}
+#define STREAM_TO_UINT24(u32, p) {u32 = (((UINT32)(*(p))) + ((((UINT32)(*((p) + 1)))) << 8) + ((((UINT32)(*((p) + 2)))) << 16) ); (p) += 3;}
+#define STREAM_TO_UINT32(u32, p) {u32 = (((UINT32)(*(p))) + ((((UINT32)(*((p) + 1)))) << 8) + ((((UINT32)(*((p) + 2)))) << 16) + ((((UINT32)(*((p) + 3)))) << 24)); (p) += 4;}
+#define STREAM_TO_BDADDR(a, p) {register int ijk; register UINT8 *pbda = (UINT8 *)a + BD_ADDR_LEN - 1; for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *pbda-- = *p++;}
+#define STREAM_TO_ARRAY32(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + 31; for (ijk = 0; ijk < 32; ijk++) *_pa-- = *p++;}
+#define STREAM_TO_ARRAY16(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + 15; for (ijk = 0; ijk < 16; ijk++) *_pa-- = *p++;}
+#define STREAM_TO_ARRAY8(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + 7; for (ijk = 0; ijk < 8; ijk++) *_pa-- = *p++;}
+#define STREAM_TO_DEVCLASS(a, p) {register int ijk; register UINT8 *_pa = (UINT8 *)a + DEV_CLASS_LEN - 1; for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *p++;}
+#define STREAM_TO_LAP(a, p) {register int ijk; register UINT8 *plap = (UINT8 *)a + LAP_LEN - 1; for (ijk = 0; ijk < LAP_LEN; ijk++) *plap-- = *p++;}
+#define STREAM_TO_ARRAY(a, p, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) ((UINT8 *) a)[ijk] = *p++;}
+#define REVERSE_STREAM_TO_ARRAY(a, p, len) {register int ijk; register UINT8 *_pa = (UINT8 *)a + len - 1; for (ijk = 0; ijk < len; ijk++) *_pa-- = *p++;}
+
+/*****************************************************************************
+** Macros to get and put bytes to and from a field (Little Endian format).
+** These are the same as to stream, except the pointer is not incremented.
+*****************************************************************************/
+
+#define UINT32_TO_FIELD(p, u32) {*(UINT8 *)(p) = (UINT8)(u32); *((UINT8 *)(p)+1) = (UINT8)((u32) >> 8); *((UINT8 *)(p)+2) = (UINT8)((u32) >> 16); *((UINT8 *)(p)+3) = (UINT8)((u32) >> 24);}
+#define UINT24_TO_FIELD(p, u24) {*(UINT8 *)(p) = (UINT8)(u24); *((UINT8 *)(p)+1) = (UINT8)((u24) >> 8); *((UINT8 *)(p)+2) = (UINT8)((u24) >> 16);}
+#define UINT16_TO_FIELD(p, u16) {*(UINT8 *)(p) = (UINT8)(u16); *((UINT8 *)(p)+1) = (UINT8)((u16) >> 8);}
+#define UINT8_TO_FIELD(p, u8) {*(UINT8 *)(p) = (UINT8)(u8);}
+
+
+/*****************************************************************************
+** Macros to get and put bytes to and from a stream (Big Endian format)
+*****************************************************************************/
+
+#define UINT32_TO_BE_STREAM(p, u32) {*(p)++ = (UINT8)((u32) >> 24); *(p)++ = (UINT8)((u32) >> 16); *(p)++ = (UINT8)((u32) >> 8); *(p)++ = (UINT8)(u32); }
+#define UINT24_TO_BE_STREAM(p, u24) {*(p)++ = (UINT8)((u24) >> 16); *(p)++ = (UINT8)((u24) >> 8); *(p)++ = (UINT8)(u24);}
+#define UINT16_TO_BE_STREAM(p, u16) {*(p)++ = (UINT8)((u16) >> 8); *(p)++ = (UINT8)(u16);}
+#define UINT8_TO_BE_STREAM(p, u8) {*(p)++ = (UINT8)(u8);}
+#define ARRAY_TO_BE_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) *(p)++ = (UINT8) a[ijk];}
+
+#define BE_STREAM_TO_UINT8(u8, p) {u8 = (UINT8)(*(p)); (p) += 1;}
+#define BE_STREAM_TO_UINT16(u16, p) {u16 = (UINT16)(((UINT16)(*(p)) << 8) + (UINT16)(*((p) + 1))); (p) += 2;}
+#define BE_STREAM_TO_UINT24(u32, p) {u32 = (((UINT32)(*((p) + 2))) + ((UINT32)(*((p) + 1)) << 8) + ((UINT32)(*(p)) << 16)); (p) += 3;}
+#define BE_STREAM_TO_UINT32(u32, p) {u32 = ((UINT32)(*((p) + 3)) + ((UINT32)(*((p) + 2)) << 8) + ((UINT32)(*((p) + 1)) << 16) + ((UINT32)(*(p)) << 24)); (p) += 4;}
+#define BE_STREAM_TO_ARRAY(p, a, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) ((UINT8 *) a)[ijk] = *p++;}
+
+
+/*****************************************************************************
+** Macros to get and put bytes to and from a field (Big Endian format).
+** These are the same as to stream, except the pointer is not incremented.
+*****************************************************************************/
+
+#define UINT32_TO_BE_FIELD(p, u32) {*(UINT8 *)(p) = (UINT8)((u32) >> 24); *((UINT8 *)(p)+1) = (UINT8)((u32) >> 16); *((UINT8 *)(p)+2) = (UINT8)((u32) >> 8); *((UINT8 *)(p)+3) = (UINT8)(u32); }
+#define UINT24_TO_BE_FIELD(p, u24) {*(UINT8 *)(p) = (UINT8)((u24) >> 16); *((UINT8 *)(p)+1) = (UINT8)((u24) >> 8); *((UINT8 *)(p)+2) = (UINT8)(u24);}
+#define UINT16_TO_BE_FIELD(p, u16) {*(UINT8 *)(p) = (UINT8)((u16) >> 8); *((UINT8 *)(p)+1) = (UINT8)(u16);}
+#define UINT8_TO_BE_FIELD(p, u8) {*(UINT8 *)(p) = (UINT8)(u8);}
+
+/*****************************************************************************
+** Define trace levels
+*****************************************************************************/
+
+#define BT_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */
+#define BT_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */
+#define BT_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */
+#define BT_TRACE_LEVEL_API 3 /* API traces */
+#define BT_TRACE_LEVEL_EVENT 4 /* Debug messages for events */
+#define BT_TRACE_LEVEL_DEBUG 5 /* Full debug messages */
+
+
+#define TRACE_CTRL_GENERAL 0x00000000
+#define TRACE_LAYER_NCI 0x00280000
+#define TRACE_LAYER_GKI 0x001a0000
+#define TRACE_ORG_STACK 0x00000000
+#define TRACE_ORG_GKI 0x00000400
+
+#define TRACE_TYPE_ERROR 0x00000000
+#define TRACE_TYPE_WARNING 0x00000001
+#define TRACE_TYPE_API 0x00000002
+#define TRACE_TYPE_EVENT 0x00000003
+#define TRACE_TYPE_DEBUG 0x00000004
+
+
+/* Define a function for logging */
+typedef void (BT_LOG_FUNC) (int trace_type, const char *fmt_str, ...);
+
+#endif /* NFC_TYPES_H */
+
diff --git a/halimpl/bcm2079x/hal/int/nfc_brcm_defs.h b/halimpl/bcm2079x/hal/int/nfc_brcm_defs.h
new file mode 100644
index 0000000..9ce68e3
--- /dev/null
+++ b/halimpl/bcm2079x/hal/int/nfc_brcm_defs.h
@@ -0,0 +1,239 @@
+/******************************************************************************
+ *
+ * Copyright (C) 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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This file contains the Broadcom-specific defintions that are shared
+ * between HAL, nfc stack, adaptation layer and applications.
+ *
+ ******************************************************************************/
+
+#ifndef NFC_BRCM_DEFS_H
+#define NFC_BRCM_DEFS_H
+
+/*****************************************************************************
+** Broadcom-specific NCI definitions
+*****************************************************************************/
+
+/**********************************************
+ * NCI Message Proprietary Group - F
+ **********************************************/
+#define NCI_MSG_TAG_SET_MEM 0x00
+#define NCI_MSG_TAG_GET_MEM 0x01
+#define NCI_MSG_T1T_SET_HR 0x02
+#define NCI_MSG_SET_CLF_REGISTERS 0x03
+#define NCI_MSG_GET_BUILD_INFO 0x04
+#define NCI_MSG_HCI_NETWK 0x05
+#define NCI_MSG_SET_FWFSM 0x06
+#define NCI_MSG_SET_UICCRDRF 0x07
+#define NCI_MSG_POWER_LEVEL 0x08
+#define NCI_MSG_FRAME_LOG 0x09
+#define NCI_MSG_UICC_READER_ACTION 0x0A
+#define NCI_MSG_SET_PPSE_RESPONSE 0x0B
+#define NCI_MSG_PRBS_SET 0x0C
+#define NCI_MSG_RESET_ALL_UICC_CFG 0x0D /* reset HCI network/close all pipes (S,D) register */
+#define NCI_MSG_GET_NFCEE_INFO 0x0E
+#define NCI_MSG_DISABLE_INIT_CHECK 0x0F
+#define NCI_MSG_ANTENNA_SELF_TEST 0x10
+#define NCI_MSG_SET_MAX_PKT_SIZE 0x11
+#define NCI_MSG_NCIP_CLK_REQ_OR_CAR_DET 0x12
+#define NCI_MSG_NCIP_CONFIG_DBUART 0x13
+#define NCI_MSG_NCIP_ENABLE_DVT_DRIVER 0x14
+#define NCI_MSG_SET_ASWP 0x15
+#define NCI_MSG_ENCAPSULATE_NCI 0x16
+#define NCI_MSG_CONFIGURE_ARM_JTAG 0x17
+#define NCI_MSG_STATISTICS 0x18
+#define NCI_MSG_SET_DSP_TABLE 0x19
+#define NCI_MSG_GET_DSP_TABLE 0x1a
+#define NCI_MSG_READY_RX_CMD 0x1b
+#define NCI_MSG_GET_VBAT 0x1c
+#define NCI_MSG_GET_XTAL_INDEX_FROM_DH 0x1d
+#define NCI_MSG_SWP_LOG 0x1e
+#define NCI_MSG_GET_PWRLEVEL 0x1f
+#define NCI_MSG_SET_VBAT_MONITOR 0x20
+#define NCI_MSG_SET_TINT_MODE 0x21
+#define NCI_MSG_ACCESS_APP 0x22
+#define NCI_MSG_SET_SECURE_MODE 0x23
+#define NCI_MSG_GET_NV_DEVICE 0x24
+#define NCI_MSG_LPTD 0x25
+#define NCI_MSG_SET_CE4_AS_SNOOZE 0x26
+#define NCI_MSG_NFCC_SEND_HCI 0x27
+#define NCI_MSG_CE4_PATCH_DOWNLOAD_DONE 0x28
+#define NCI_MSG_EEPROM_RW 0x29
+#define NCI_MSG_GET_CLF_REGISTERS 0x2A
+#define NCI_MSG_RF_TEST 0x2B
+#define NCI_MSG_DEBUG_PRINT 0x2C
+#define NCI_MSG_GET_PATCH_VERSION 0x2D
+#define NCI_MSG_SECURE_PATCH_DOWNLOAD 0x2E
+#define NCI_MSG_SPD_FORMAT_NVM 0x2F
+#define NCI_MSG_SPD_READ_NVM 0x30
+
+/**********************************************
+ * Proprietary NCI status codes
+ **********************************************/
+#define NCI_STATUS_SPD_ERROR_ORDER 0xE0
+#define NCI_STATUS_SPD_ERROR_DEST 0xE1
+#define NCI_STATUS_SPD_ERROR_PROJECTID 0xE2
+#define NCI_STATUS_SPD_ERROR_CHIPVER 0xE3
+#define NCI_STATUS_SPD_ERROR_MAJORVER 0xE4
+#define NCI_STATUS_SPD_ERROR_INVALID_PARAM 0xE5
+#define NCI_STATUS_SPD_ERROR_INVALID_SIG 0xE6
+#define NCI_STATUS_SPD_ERROR_NVM_CORRUPTED 0xE7
+#define NCI_STATUS_SPD_ERROR_PWR_MODE 0xE8
+#define NCI_STATUS_SPD_ERROR_MSG_LEN 0xE9
+#define NCI_STATUS_SPD_ERROR_PATCHSIZE 0xEA
+
+
+
+#define NCI_NV_DEVICE_NONE 0x00
+#define NCI_NV_DEVICE_EEPROM 0x08
+#define NCI_NV_DEVICE_UICC1 0x10
+
+/* The events reported on tNFC_VS_CBACK */
+/* The event is (NCI_NTF_BIT|oid) or (NCI_RSP_BIT|oid) */
+#define NFC_VS_HCI_NETWK_EVT (NCI_NTF_BIT|NCI_MSG_HCI_NETWK)
+#define NFC_VS_HCI_NETWK_RSP (NCI_RSP_BIT|NCI_MSG_HCI_NETWK)
+#define NFC_VS_UICC_READER_ACTION_EVT (NCI_NTF_BIT|NCI_MSG_UICC_READER_ACTION)
+#define NFC_VS_POWER_LEVEL_RSP (NCI_RSP_BIT|NCI_MSG_POWER_LEVEL)
+#define NFC_VS_GET_NV_DEVICE_EVT (NCI_RSP_BIT|NCI_MSG_GET_NV_DEVICE)
+#define NFC_VS_LPTD_EVT (NCI_NTF_BIT|NCI_MSG_LPTD)
+#define NFC_VS_GET_BUILD_INFO_EVT (NCI_RSP_BIT|NCI_MSG_GET_BUILD_INFO)
+#define NFC_VS_GET_PATCH_VERSION_EVT (NCI_RSP_BIT|NCI_MSG_GET_PATCH_VERSION)
+#define NFC_VS_SEC_PATCH_DOWNLOAD_EVT (NCI_RSP_BIT|NCI_MSG_SECURE_PATCH_DOWNLOAD)
+#define NFC_VS_SEC_PATCH_AUTH_EVT (NCI_NTF_BIT|NCI_MSG_SECURE_PATCH_DOWNLOAD)
+
+#define NCI_GET_PATCH_VERSION_NVM_OFFSET 37
+
+
+#define NCI_NFCC_PIPE_INFO_NV_SIZE 24 /* Static and dynamic pipe id and status for each pipe to uicc0 and uicc1. */
+#define NCI_PERSONALITY_SLOT_SIZE 19
+#define NCI_DYNAMIC_PIPE_SIZE 8
+
+#define NCI_SWP_INTERFACE_TYPE 0xFF /* Type of TLV in NCI_MSG_HCI_NETWK */
+#define NCI_HCI_GATE_TYPE 0xFE /* Type of TLV in NCI_MSG_HCI_NETWK */
+
+/* Secure Patch Download definitions (patch type definitions) */
+#define NCI_SPD_TYPE_HEADER 0x00
+#define NCI_SPD_TYPE_SRAM 0x01
+#define NCI_SPD_TYPE_AON 0x02
+#define NCI_SPD_TYPE_PATCH_TABLE 0x03
+#define NCI_SPD_TYPE_SECURE_CONFIG 0x04
+#define NCI_SPD_TYPE_CONTROLLED_CONFIG 0x05
+#define NCI_SPD_TYPE_SIGNATURE 0x06
+#define NCI_SPD_TYPE_SIGCHEK 0x07
+
+/* Secure Patch Download definitions (NCI_SPD_TYPE_HEADER definitions) */
+#define NCI_SPD_HEADER_OFFSET_CHIPVERLEN 0x18
+#define NCI_SPD_HEADER_CHIPVER_LEN 16
+
+/* NVM Type (in GET_PATCH_VERSION RSP) */
+#define NCI_SPD_NVM_TYPE_NONE 0x00
+#define NCI_SPD_NVM_TYPE_EEPROM 0x01
+#define NCI_SPD_NVM_TYPE_UICC 0x02
+
+/**********************************************
+ * NCI NFCC proprietary features in octet 3
+ **********************************************/
+#define NCI_FEAT_SIGNED_PATCH 0x01000000
+
+/**********************************************
+ * NCI Interface Types
+ **********************************************/
+#define NCI_INTERFACE_VS_CALYPSO_CE 0x81
+#define NCI_INTERFACE_VS_T2T_CE 0x82 /* for Card Emulation side */
+#define NCI_INTERFACE_VS_15693 0x83 /* for both Reader/Writer and Card Emulation side */
+#define NCI_INTERFACE_VS_T1T_CE 0x84 /* for Card Emulation side */
+
+/**********************************************
+ * NCI Proprietary Parameter IDs
+ **********************************************/
+#define NCI_PARAM_ID_LA_FSDI 0xA0
+#define NCI_PARAM_ID_LB_FSDI 0xA1
+#define NCI_PARAM_ID_HOST_LISTEN_MASK 0xA2
+#define NCI_PARAM_ID_CHIP_TYPE 0xA3 /* NFCDEP */
+#define NCI_PARAM_ID_PA_ANTICOLL 0xA4
+#define NCI_PARAM_ID_CONTINUE_MODE 0xA5
+#define NCI_PARAM_ID_LBP 0xA6
+#define NCI_PARAM_ID_T1T_RDR_ONLY 0xA7
+#define NCI_PARAM_ID_LA_SENS_RES 0xA8
+#define NCI_PARAM_ID_PWR_SETTING_BITMAP 0xA9
+#define NCI_PARAM_ID_WI_NTF_ENABLE 0xAA
+#define NCI_PARAM_ID_LN_BITRATE 0xAB /* NFCDEP Listen Bitrate */
+#define NCI_PARAM_ID_LF_BITRATE 0xAC /* FeliCa */
+#define NCI_PARAM_ID_SWP_BITRATE_MASK 0xAD
+#define NCI_PARAM_ID_KOVIO 0xAE
+#define NCI_PARAM_ID_UICC_NTF_TO 0xAF
+#define NCI_PARAM_ID_NFCDEP 0xB0
+#define NCI_PARAM_ID_CLF_REGS_CFG 0xB1
+#define NCI_PARAM_ID_NFCDEP_TRANS_TIME 0xB2
+#define NCI_PARAM_ID_CREDIT_TIMER 0xB3
+#define NCI_PARAM_ID_CORRUPT_RX 0xB4
+#define NCI_PARAM_ID_ISODEP 0xB5
+#define NCI_PARAM_ID_LF_CONFIG 0xB6
+#define NCI_PARAM_ID_I93_DATARATE 0xB7
+#define NCI_PARAM_ID_CREDITS_THRESHOLD 0xB8
+#define NCI_PARAM_ID_TAGSNIFF_CFG 0xB9
+#define NCI_PARAM_ID_PA_FSDI 0xBA /* ISODEP */
+#define NCI_PARAM_ID_PB_FSDI 0xBB /* ISODEP */
+#define NCI_PARAM_ID_FRAME_INTF_RETXN 0xBC
+
+#define NCI_PARAM_ID_UICC_RDR_PRIORITY 0xBD
+#define NCI_PARAM_ID_GUARD_TIME 0xBE
+#define NCI_PARAM_ID_STDCONFIG 0xBF /* dont not use this config item */
+#define NCI_PARAM_ID_PROPCFG 0xC0 /* dont not use this config item */
+#define NCI_PARAM_ID_MAXTRY2ACTIVATE 0xC1
+#define NCI_PARAM_ID_SWPCFG 0xC2
+#define NCI_PARAM_ID_CLF_LPM_CFG 0xC3
+#define NCI_PARAM_ID_DCLB 0xC4
+#define NCI_PARAM_ID_ACT_ORDER 0xC5
+#define NCI_PARAM_ID_DEP_DELAY_ACT 0xC6
+#define NCI_PARAM_ID_DH_PARITY_CRC_CTL 0xC7
+#define NCI_PARAM_ID_PREINIT_DSP_CFG 0xC8
+#define NCI_PARAM_ID_FW_WORKAROUND 0xC9
+#define NCI_PARAM_ID_RFU_CONFIG 0xCA
+#define NCI_PARAM_ID_EMVCO_ENABLE 0xCB
+#define NCI_PARAM_ID_ANTDRIVER_PARAM 0xCC
+#define NCI_PARAM_ID_PLL325_CFG_PARAM 0xCD
+#define NCI_PARAM_ID_OPNLP_ADPLL_ENABLE 0xCE
+#define NCI_PARAM_ID_CONFORMANCE_MODE 0xCF
+
+#define NCI_PARAM_ID_LPO_ON_OFF_ENABLE 0xD0
+#define NCI_PARAM_ID_FORCE_VANT 0xD1
+#define NCI_PARAM_ID_COEX_CONFIG 0xD2
+#define NCI_PARAM_ID_INTEL_MODE 0xD3
+
+#define NCI_PARAM_ID_AID 0xFF
+
+/**********************************************
+ * NCI Parameter ID Lens
+ **********************************************/
+#define NCI_PARAM_LEN_PWR_SETTING_BITMAP 3
+#define NCI_PARAM_LEN_HOST_LISTEN_MASK 2
+#define NCI_PARAM_LEN_PLL325_CFG_PARAM 14
+
+/**********************************************
+ * Snooze Mode
+ **********************************************/
+#define NFC_SNOOZE_MODE_NONE 0x00 /* Snooze mode disabled */
+#define NFC_SNOOZE_MODE_UART 0x01 /* Snooze mode for UART */
+#define NFC_SNOOZE_MODE_SPI_I2C 0x08 /* Snooze mode for SPI/I2C */
+
+#define NFC_SNOOZE_ACTIVE_LOW 0x00 /* high to low voltage is asserting */
+#define NFC_SNOOZE_ACTIVE_HIGH 0x01 /* low to high voltage is asserting */
+
+#endif /* NFC_BRCM_DEFS_H */
diff --git a/halimpl/bcm2079x/hal/int/nfc_hal_int.h b/halimpl/bcm2079x/hal/int/nfc_hal_int.h
new file mode 100644
index 0000000..ca8dc20
--- /dev/null
+++ b/halimpl/bcm2079x/hal/int/nfc_hal_int.h
@@ -0,0 +1,473 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2009-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * this file contains the NCI transport internal definitions and functions.
+ *
+ ******************************************************************************/
+
+#ifndef NFC_HAL_INT_H
+#define NFC_HAL_INT_H
+
+#include "nfc_hal_target.h"
+#include "gki.h"
+#include "nci_defs.h"
+#include "nfc_brcm_defs.h"
+#include "nfc_hal_api.h"
+#include "nfc_hal_int_api.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/****************************************************************************
+** NFC HAL TASK transport definitions
+****************************************************************************/
+/* NFC HAL Task event masks */
+#define NFC_HAL_TASK_EVT_DATA_RDY EVENT_MASK (APPL_EVT_0)
+#define NFC_HAL_TASK_EVT_INITIALIZE EVENT_MASK (APPL_EVT_5)
+#define NFC_HAL_TASK_EVT_TERMINATE EVENT_MASK (APPL_EVT_6)
+#define NFC_HAL_TASK_EVT_POWER_CYCLE EVENT_MASK (APPL_EVT_7)
+
+#define NFC_HAL_TASK_EVT_MBOX (TASK_MBOX_0_EVT_MASK)
+
+/* NFC HAL Task mailbox definitions */
+#define NFC_HAL_TASK_MBOX (TASK_MBOX_0)
+
+/* NFC HAL Task Timer events */
+#ifndef NFC_HAL_QUICK_TIMER_EVT_MASK
+#define NFC_HAL_QUICK_TIMER_EVT_MASK (TIMER_0_EVT_MASK)
+#endif
+
+#ifndef NFC_HAL_QUICK_TIMER_ID
+#define NFC_HAL_QUICK_TIMER_ID (TIMER_0)
+#endif
+
+/* NFC HAL Task Timer types */
+#define NFC_HAL_TTYPE_NCI_WAIT_RSP 0
+#define NFC_HAL_TTYPE_POWER_CYCLE 1
+
+/* NFC HAL Task Wait Response flag */
+#define NFC_HAL_WAIT_RSP_CMD 0x10 /* wait response on an NCI command */
+#define NFC_HAL_WAIT_RSP_VSC 0x20 /* wait response on an NCI vendor specific command */
+#define NFC_HAL_WAIT_RSP_PROP 0x40 /* wait response on a proprietary command */
+#define NFC_HAL_WAIT_RSP_NONE 0x00 /* not waiting for anything */
+
+typedef UINT8 tNFC_HAL_WAIT_RSP;
+
+typedef UINT16 tNFC_HAL_HCI_EVT;
+
+
+#define NFC_HAL_HCI_DH_TARGET_HANDLE 0xF2
+#define NFC_HAL_HCI_UICC0_TARGET_HANDLE 0xF3
+#define NFC_HAL_HCI_UICC1_TARGET_HANDLE 0xF4
+
+#define NFC_HAL_HCI_SESSION_ID_LEN 0x08
+#define NFC_HAL_HCI_NETWK_INFO_SIZE 184
+#define NFC_HAL_HCI_DH_NETWK_INFO_SIZE 111
+
+#define NFC_HAL_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED 0x15
+#define NFC_HAL_HCI_ADMIN_PIPE 0x01
+#define NFC_HAL_HCI_HOST_ID_UICC0 0x02 /* Host ID for UICC 0 */
+#define NFC_HAL_HCI_HOST_ID_UICC1 0x03 /* Host ID for UICC 1 */
+#define NFC_HAL_HCI_COMMAND_TYPE 0x00
+
+/* NFC HAL transport configuration */
+typedef struct
+{
+ BOOLEAN shared_transport; /* TRUE if using shared HCI/NCI transport */
+ UINT8 userial_baud;
+ UINT8 userial_fc;
+} tNFC_HAL_TRANS_CFG;
+
+#ifdef TESTER
+#define NFC_HAL_TRANS_CFG_QUALIFIER /* For Insight, ncit_cfg is runtime-configurable */
+#else
+#define NFC_HAL_TRANS_CFG_QUALIFIER const /* For all other platforms, ncit_cfg is constant */
+#endif
+extern NFC_HAL_TRANS_CFG_QUALIFIER tNFC_HAL_TRANS_CFG nfc_hal_trans_cfg;
+
+/*****************************************************************************
+* BT HCI definitions
+*****************************************************************************/
+#define BT_HDR NFC_HDR
+
+/* Tranport message type */
+#define HCIT_TYPE_COMMAND 0x01
+#define HCIT_TYPE_EVENT 0x04
+#define HCIT_TYPE_NFC 0x10
+
+/* Vendor-Specific BT HCI definitions */
+#define HCI_SUCCESS 0x00
+#define HCI_GRP_VENDOR_SPECIFIC (0x3F << 10) /* 0xFC00 */
+#define HCI_BRCM_WRITE_SLEEP_MODE (0x0027 | HCI_GRP_VENDOR_SPECIFIC)
+#define HCI_GRP_HOST_CONT_BASEBAND_CMDS (0x03 << 10) /* 0x0C00 */
+#define HCI_RESET (0x0003 | HCI_GRP_HOST_CONT_BASEBAND_CMDS)
+#define HCI_COMMAND_COMPLETE_EVT 0x0E
+#define HCI_BRCM_WRITE_SLEEP_MODE_LENGTH 12
+#define HCI_BRCM_UPDATE_BAUD_RATE_UNENCODED_LENGTH 0x06
+#define HCIE_PREAMBLE_SIZE 2
+
+/****************************************************************************
+** Internal constants and definitions
+****************************************************************************/
+
+/* NFC HAL receiving states */
+enum
+{
+ NFC_HAL_RCV_IDLE_ST, /* waiting for packet type byte */
+ NFC_HAL_RCV_NCI_MSG_ST, /* waiting for the first byte of NCI header */
+ NFC_HAL_RCV_NCI_HDR_ST, /* reading NCI header */
+ NFC_HAL_RCV_NCI_PAYLOAD_ST, /* reading NCI payload */
+ NFC_HAL_RCV_BT_MSG_ST, /* waiting for the first byte of BT header */
+ NFC_HAL_RCV_BT_HDR_ST, /* reading BT HCI header */
+ NFC_HAL_RCV_BT_PAYLOAD_ST /* reading BT HCI payload */
+};
+
+/* errors during NCI packet reassembly process */
+#define NFC_HAL_NCI_RAS_TOO_BIG 0x01
+#define NFC_HAL_NCI_RAS_ERROR 0x02
+typedef UINT8 tNFC_HAL_NCI_RAS;
+
+/* NFC HAL power mode */
+enum
+{
+ NFC_HAL_POWER_MODE_FULL, /* NFCC is full power mode */
+ NFC_HAL_POWER_MODE_LAST
+};
+typedef UINT8 tNFC_HAL_POWER_MODE;
+
+
+/* NFC HAL event for low power mode */
+enum
+{
+ NFC_HAL_LP_TX_DATA_EVT, /* DH is sending data to NFCC */
+ NFC_HAL_LP_RX_DATA_EVT, /* DH received data from NFCC */
+ NFC_HAL_LP_TIMEOUT_EVT, /* Timeout */
+ NFC_HAL_LP_LAST_EVT
+};
+typedef UINT8 tNFC_HAL_LP_EVT;
+
+#define NFC_HAL_ASSERT_NFC_WAKE 0x00 /* assert NFC_WAKE */
+#define NFC_HAL_DEASSERT_NFC_WAKE 0x01 /* deassert NFC_WAKE */
+
+#define NFC_HAL_BT_HCI_CMD_HDR_SIZE 3 /* opcode (2) + length (1) */
+#define NFC_HAL_CMD_TOUT (2000) /* timeout for NCI CMD (in ms) */
+
+#define NFC_HAL_SAVED_HDR_SIZE (2)
+#define NFC_HAL_SAVED_CMD_SIZE (2)
+
+#ifndef NFC_HAL_DEBUG
+#define NFC_HAL_DEBUG TRUE
+#endif
+
+#if (NFC_HAL_DEBUG == TRUE)
+extern const char * const nfc_hal_init_state_str[];
+#define NFC_HAL_SET_INIT_STATE(state) NCI_TRACE_DEBUG3 ("init state: %d->%d(%s)", nfc_hal_cb.dev_cb.initializing_state, state, nfc_hal_init_state_str[state]); nfc_hal_cb.dev_cb.initializing_state = state;
+#else
+#define NFC_HAL_SET_INIT_STATE(state) nfc_hal_cb.dev_cb.initializing_state = state;
+#endif
+
+
+/* NFC HAL - NFCC initializing state */
+enum
+{
+ NFC_HAL_INIT_STATE_IDLE, /* Initialization is done */
+ NFC_HAL_INIT_STATE_W4_XTAL_SET, /* Waiting for crystal setting rsp */
+ NFC_HAL_INIT_STATE_W4_RESET, /* Waiting for reset rsp */
+ NFC_HAL_INIT_STATE_W4_BUILD_INFO, /* Waiting for build info rsp */
+ NFC_HAL_INIT_STATE_W4_PATCH_INFO, /* Waiting for patch info rsp */
+ NFC_HAL_INIT_STATE_W4_APP_COMPLETE, /* Waiting for complete from application */
+ NFC_HAL_INIT_STATE_W4_POST_INIT_DONE, /* Waiting for complete of post init */
+ NFC_HAL_INIT_STATE_W4_CONTROL_DONE, /* Waiting for control release */
+ NFC_HAL_INIT_STATE_W4_PREDISCOVER_DONE,/* Waiting for complete of prediscover */
+ NFC_HAL_INIT_STATE_W4_RE_INIT, /* Waiting for reset rsp on ReInit */
+ NFC_HAL_INIT_STATE_CLOSING /* Shutting down */
+};
+typedef UINT8 tNFC_HAL_INIT_STATE;
+
+/* NFC HAL - NFCC config items during post initialization */
+enum
+{
+ NFC_HAL_DM_CONFIG_LPTD,
+ NFC_HAL_DM_CONFIG_PLL_325,
+ NFC_HAL_DM_CONFIG_START_UP,
+ NFC_HAL_DM_CONFIG_I93_DATA_RATE,
+ NFC_HAL_DM_CONFIG_FW_FSM,
+ NFC_HAL_DM_CONFIG_START_UP_VSC,
+ NFC_HAL_DM_CONFIG_NONE
+};
+typedef UINT8 tNFC_HAL_DM_CONFIG;
+
+/* callback function prototype */
+typedef struct
+{
+ UINT16 opcode;
+ UINT16 param_len;
+ UINT8 *p_param_buf;
+} tNFC_HAL_BTVSC_CPLT;
+
+typedef void (tNFC_HAL_BTVSC_CPLT_CBACK) (tNFC_HAL_BTVSC_CPLT *p1);
+
+
+/* data type for NFC_HAL_HCI_RSP_NV_READ_EVT */
+typedef struct
+{
+ NFC_HDR hdr;
+ UINT8 block;
+ UINT16 size;
+ tHAL_NFC_STATUS status;
+} tNFC_HAL_HCI_RSP_NV_READ_EVT;
+
+/* data type for NFC_HAL_HCI_RSP_NV_WRITE_EVT */
+typedef struct
+{
+ NFC_HDR hdr;
+ tHAL_NFC_STATUS status;
+} tNFC_HAL_HCI_RSP_NV_WRITE_EVT;
+
+
+/* union of all event data types */
+typedef union
+{
+ NFC_HDR hdr;
+ /* Internal events */
+ tNFC_HAL_HCI_RSP_NV_READ_EVT nv_read;
+ tNFC_HAL_HCI_RSP_NV_WRITE_EVT nv_write;
+} tNFC_HAL_HCI_EVENT_DATA;
+
+/*****************************************************************************
+** Control block for NFC HAL
+*****************************************************************************/
+
+/* Patch RAM Download Control block */
+
+/* PRM states */
+enum
+{
+ NFC_HAL_PRM_ST_IDLE,
+
+ /* Secure patch download stated */
+ NFC_HAL_PRM_ST_SPD_GET_VERSION,
+ NFC_HAL_PRM_ST_SPD_COMPARE_VERSION,
+ NFC_HAL_PRM_ST_SPD_GET_PATCH_HEADER,
+ NFC_HAL_PRM_ST_SPD_DOWNLOADING,
+ NFC_HAL_PRM_ST_SPD_AUTHENTICATING,
+ NFC_HAL_PRM_ST_SPD_AUTH_DONE
+};
+typedef UINT8 tNFC_HAL_PRM_STATE;
+
+/* Maximum number of patches (currently 2: LPM and FPM) */
+#define NFC_HAL_PRM_MAX_PATCH_COUNT 2
+#define NFC_HAL_PRM_PATCH_MASK_ALL 0xFFFFFFFF
+
+/* Structures for PRM Control Block */
+typedef struct
+{
+ UINT8 power_mode;
+ UINT16 len;
+} tNFC_HAL_PRM_PATCHDESC;
+
+typedef struct
+{
+ tNFC_HAL_PRM_STATE state; /* download state */
+ UINT32 flags; /* internal flags */
+ UINT16 cur_patch_len_remaining;/* bytes remaining in patchfile to process */
+ const UINT8* p_cur_patch_data; /* pointer to patch currently being downloaded */
+ UINT16 cur_patch_offset; /* offset of next byte to process */
+ UINT32 dest_ram;
+ TIMER_LIST_ENT timer; /* Timer for patch download */
+
+ /* Secure Patch Download */
+ UINT32 spd_patch_needed_mask; /* Mask of patches that need to be downloaded */
+ UINT32 spd_nvm_patch_mask; /* Mask of patches currently in NVM */
+ UINT16 spd_project_id; /* Current project_id of patch in nvm */
+ UINT16 spd_nvm_max_size;
+ UINT16 spd_patch_max_size;
+ UINT16 spd_fpm_patch_size;
+ UINT16 spd_lpm_patch_size;
+
+ UINT8 spd_patch_count; /* Number of patches left to download */
+ UINT8 spd_cur_patch_idx; /* Current patch being downloaded */
+ UINT16 spd_ver_major; /* Current major version of patch in nvm */
+ UINT16 spd_ver_minor; /* Current minor version of patch in nvm */
+ tNFC_HAL_PRM_PATCHDESC spd_patch_desc[NFC_HAL_PRM_MAX_PATCH_COUNT];
+
+ /* I2C-patch */
+ UINT8 *p_spd_patch; /* pointer to spd patch */
+ UINT16 spd_patch_len_remaining;/* patch length */
+ UINT16 spd_patch_offset; /* offset of next byte to process */
+
+ tNFC_HAL_PRM_FORMAT format; /* format of patch ram */
+ tNFC_HAL_PRM_CBACK *p_cback; /* Callback for download status notifications */
+ UINT32 patchram_delay; /* the dealy after patch */
+} tNFC_HAL_PRM_CB;
+
+/* Patch for I2C fix */
+typedef struct
+{
+ UINT8 *p_patch; /* patch for i2c fix */
+ UINT32 prei2c_delay; /* the dealy after preI2C patch */
+ UINT16 len; /* i2c patch length */
+} tNFC_HAL_PRM_I2C_FIX_CB;
+
+/* Control block for NCI transport */
+typedef struct
+{
+ UINT8 nci_ctrl_size; /* Max size for NCI messages */
+ UINT8 rcv_state; /* current rx state */
+ UINT16 rcv_len; /* bytes remaining to be received in current rx state */
+ NFC_HDR *p_rcv_msg; /* buffer to receive NCI message */
+ NFC_HDR *p_frag_msg; /* fragmented NCI message; waiting for last fragment */
+ NFC_HDR *p_pend_cmd; /* pending NCI message; waiting for NFCC state to be free */
+ tNFC_HAL_NCI_RAS nci_ras; /* nci reassembly error status */
+ TIMER_LIST_ENT nci_wait_rsp_timer; /* Timer for waiting for nci command response */
+ tNFC_HAL_WAIT_RSP nci_wait_rsp; /* nci wait response flag */
+ UINT8 last_hdr[NFC_HAL_SAVED_HDR_SIZE];/* part of last NCI command header */
+ UINT8 last_cmd[NFC_HAL_SAVED_CMD_SIZE];/* part of last NCI command payload */
+ void *p_vsc_cback; /* the callback function for last VSC command */
+} tNFC_HAL_NCIT_CB;
+
+/* Control block for device initialization */
+typedef struct
+{
+ tNFC_HAL_INIT_STATE initializing_state; /* state of initializing NFCC */
+
+ UINT32 brcm_hw_id; /* BRCM NFCC HW ID */
+ tNFC_HAL_DM_CONFIG next_dm_config; /* next config in post initialization */
+ UINT8 next_startup_vsc; /* next start-up VSC offset in post init */
+
+ tNFC_HAL_POWER_MODE power_mode; /* NFCC power mode */
+ UINT8 snooze_mode; /* current snooze mode */
+ UINT8 new_snooze_mode; /* next snooze mode after receiving cmpl */
+ UINT8 nfc_wake_active_mode; /* NFC_HAL_LP_ACTIVE_LOW/HIGH */
+ TIMER_LIST_ENT lp_timer; /* timer for low power mode */
+
+
+ tHAL_NFC_STATUS_CBACK *p_prop_cback; /* callback to notify complete of proprietary update */
+} tNFC_HAL_DEV_CB;
+
+/* data members for NFC_HAL-HCI */
+typedef struct
+{
+ TIMER_LIST_ENT hci_timer; /* Timer to avoid indefinitely waiting for response */
+ UINT8 *p_hci_netwk_info_buf; /* Buffer for reading HCI Network information */
+ UINT8 *p_hci_netwk_dh_info_buf; /* Buffer for reading HCI Network DH information */
+ UINT8 hci_netwk_config_block; /* Rsp awaiting for hci network configuration block */
+ BOOLEAN b_wait_hcp_conn_create_rsp; /* Waiting for hcp connection create response */
+ BOOLEAN b_check_clear_all_pipe_cmd;
+ UINT8 hcp_conn_id;
+} tNFC_HAL_HCI_CB;
+
+typedef struct
+{
+ tHAL_NFC_CBACK *p_stack_cback; /* Callback for HAL event notification */
+ tHAL_NFC_DATA_CBACK *p_data_cback; /* Callback for data event notification */
+
+ TIMER_LIST_Q quick_timer_queue; /* timer list queue */
+ TIMER_LIST_ENT timer; /* timer for NCI transport task */
+
+ tNFC_HAL_NCIT_CB ncit_cb; /* NCI transport */
+ tNFC_HAL_DEV_CB dev_cb; /* device initialization */
+
+ /* Patchram control block */
+ tNFC_HAL_PRM_CB prm;
+ tNFC_HAL_PRM_I2C_FIX_CB prm_i2c;
+
+ /* data members for NFC_HAL-HCI */
+ tNFC_HAL_HCI_CB hci_cb;
+
+
+ tNFC_HAL_NCI_CBACK *p_reinit_cback;
+ UINT8 max_rf_credits; /* NFC Max RF data credits */
+ UINT8 trace_level; /* NFC HAL trace level */
+} tNFC_HAL_CB;
+
+/* Global NCI data */
+#if NFC_DYNAMIC_MEMORY == FALSE
+extern tNFC_HAL_CB nfc_hal_cb;
+#else
+#define nfc_hal_cb (*nfc_hal_cb_ptr)
+extern tNFC_HAL_CB *nfc_hal_cb_ptr;
+#endif
+
+/****************************************************************************
+** Internal nfc functions
+****************************************************************************/
+
+/* From nfc_hal_main.c */
+UINT32 nfc_hal_main_task (UINT32 param);
+void nfc_hal_main_init (void);
+void nfc_hal_main_pre_init_done (tHAL_NFC_STATUS);
+void nfc_hal_main_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
+void nfc_hal_main_stop_quick_timer (TIMER_LIST_ENT *p_tle);
+void nfc_hal_main_send_error (tHAL_NFC_STATUS status);
+
+/* nfc_hal_nci.c */
+BOOLEAN nfc_hal_nci_receive_msg (UINT8 byte);
+BOOLEAN nfc_hal_nci_preproc_rx_nci_msg (NFC_HDR *p_msg);
+void nfc_hal_nci_assemble_nci_msg (void);
+void nfc_hal_nci_add_nfc_pkt_type (NFC_HDR *p_msg);
+void nfc_hal_nci_send_cmd (NFC_HDR *p_buf);
+void nfc_hal_nci_cmd_timeout_cback (void *p_tle);
+
+/* nfc_hal_dm.c */
+void nfc_hal_dm_init (void);
+void nfc_hal_dm_set_xtal_freq_index (void);
+void nfc_hal_dm_send_reset_cmd (void);
+void nfc_hal_dm_proc_msg_during_init (NFC_HDR *p_msg);
+void nfc_hal_dm_config_nfcc (void);
+void nfc_hal_dm_send_nci_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_NCI_CBACK *p_cback);
+void nfc_hal_dm_send_bt_cmd (const UINT8 *p_data, UINT16 len, tNFC_HAL_BTVSC_CPLT_CBACK *p_cback);
+void nfc_hal_dm_set_nfc_wake (UINT8 cmd);
+void nfc_hal_dm_pre_init_nfcc (void);
+void nfc_hal_dm_shutting_down_nfcc (void);
+BOOLEAN nfc_hal_dm_power_mode_execute (tNFC_HAL_LP_EVT event);
+void nfc_hal_dm_send_pend_cmd (void);
+
+/* nfc_hal_prm.c */
+void nfc_hal_prm_spd_reset_ntf (UINT8 reset_reason, UINT8 reset_type);
+void nfc_hal_prm_nci_command_complete_cback (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data);
+void nfc_hal_prm_process_timeout (void *p_tle);
+
+/* nfc_hal_hci.c */
+void nfc_hal_hci_enable (void);
+void nfc_hal_hci_evt_hdlr (tNFC_HAL_HCI_EVENT_DATA *p_evt_data);
+void nfc_hal_hci_handle_hci_netwk_info (UINT8 *p_data);
+void nfc_hal_hci_handle_hcp_pkt (UINT8 *p_data);
+void nfc_hal_hci_timeout_cback (void *p_tle);
+
+
+/* Define default NCI protocol trace function (if protocol tracing is enabled) */
+#if (defined(NFC_HAL_TRACE_PROTOCOL) && (NFC_HAL_TRACE_PROTOCOL == TRUE))
+#if !defined (DISP_NCI)
+#define DISP_NCI (DispNci)
+void DispNci (UINT8 *p, UINT16 len, BOOLEAN is_recv);
+#endif /* DISP_NCI */
+
+/* For displaying vendor-specific HCI commands */
+void DispHciCmd (BT_HDR *p_buf);
+void DispHciEvt (BT_HDR *p_buf);
+#endif /* NFC_HAL_TRACE_PROTOCOL */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NFC_HAL_INT_H */
diff --git a/halimpl/bcm2079x/hal/int/nfc_hal_int_api.h b/halimpl/bcm2079x/hal/int/nfc_hal_int_api.h
new file mode 100644
index 0000000..5385bb4
--- /dev/null
+++ b/halimpl/bcm2079x/hal/int/nfc_hal_int_api.h
@@ -0,0 +1,293 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2009-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Internal NFC HAL API functions.
+ *
+ ******************************************************************************/
+#ifndef NFC_HAL_INT_API_H
+#define NFC_HAL_INT_API_H
+
+/****************************************************************************
+** Device Configuration definitions
+****************************************************************************/
+
+#define NFC_HAL_PLL_325_SETCONFIG_PARAM_LEN (2 + NCI_PARAM_LEN_PLL325_CFG_PARAM)
+
+/* Crystal Frequency Index (in 1 KHz) */
+enum
+{
+ NFC_HAL_XTAL_INDEX_9600,
+ NFC_HAL_XTAL_INDEX_13000,
+ NFC_HAL_XTAL_INDEX_16200,
+ NFC_HAL_XTAL_INDEX_19200,
+ NFC_HAL_XTAL_INDEX_24000,
+ NFC_HAL_XTAL_INDEX_26000,
+ NFC_HAL_XTAL_INDEX_38400,
+ NFC_HAL_XTAL_INDEX_52000,
+ NFC_HAL_XTAL_INDEX_37400,
+ NFC_HAL_XTAL_INDEX_MAX
+};
+typedef UINT8 tNFC_HAL_XTAL_INDEX;
+
+/* Broadcom specific device initialization before sending NCI reset */
+#define NFC_HAL_DEV_INIT_FLAGS_SET_XTAL_FREQ 0x02 /* set crystal frequency */
+typedef UINT8 tNFC_HAL_DEV_INIT_FLAGS;
+
+typedef struct
+{
+ tNFC_HAL_DEV_INIT_FLAGS flags;
+ UINT16 xtal_freq;
+} tNFC_HAL_DEV_INIT_CFG;
+
+/*****************************************************************************
+** Low Power Mode definitions
+*****************************************************************************/
+
+#define NFC_HAL_LP_SNOOZE_MODE_NONE NFC_SNOOZE_MODE_NONE /* Snooze mode disabled */
+#define NFC_HAL_LP_SNOOZE_MODE_UART NFC_SNOOZE_MODE_UART /* Snooze mode for UART */
+#define NFC_HAL_LP_SNOOZE_MODE_SPI_I2C NFC_SNOOZE_MODE_SPI_I2C /* Snooze mode for SPI/I2C */
+
+#define NFC_HAL_LP_ACTIVE_LOW NFC_SNOOZE_ACTIVE_LOW /* high to low voltage is asserting */
+#define NFC_HAL_LP_ACTIVE_HIGH NFC_SNOOZE_ACTIVE_HIGH /* low to high voltage is asserting */
+
+/*****************************************************************************
+** Patch RAM Constants
+*****************************************************************************/
+
+/* patch format type */
+#define NFC_HAL_PRM_FORMAT_BIN 0x00
+#define NFC_HAL_PRM_FORMAT_HCD 0x01
+#define NFC_HAL_PRM_FORMAT_NCD 0x02
+typedef UINT8 tNFC_HAL_PRM_FORMAT;
+
+/*****************************************************************************
+** Patch RAM Callback for event notificaton
+*****************************************************************************/
+/* Events for tNFC_HAL_PRM_CBACK */
+enum
+{
+ NFC_HAL_PRM_CONTINUE_EVT,
+ NFC_HAL_PRM_COMPLETE_EVT,
+ NFC_HAL_PRM_ABORT_EVT,
+ NFC_HAL_PRM_ABORT_INVALID_PATCH_EVT, /* Patch is invalid (bad version, project id, or chip) */
+ NFC_HAL_PRM_ABORT_BAD_SIGNATURE_EVT, /* Patch has invalid signature */
+ NFC_HAL_PRM_SPD_GET_PATCHFILE_HDR_EVT, /* Secure Patch Download: request for patchfile header */
+ NFC_HAL_PRM_SPD_GET_NEXT_PATCH, /* Get first command of next patch in patchfile */
+ NFC_HAL_PRM_ABORT_NO_NVM_EVT /* nfc_hal_prm_nvm_required is TRUE and NVM is unavail */
+};
+
+typedef void (tNFC_HAL_PRM_CBACK) (UINT8 event);
+
+typedef UINT8 tNFC_HAL_NCI_EVT; /* MT + Opcode */
+typedef void (tNFC_HAL_NCI_CBACK) (tNFC_HAL_NCI_EVT event, UINT16 data_len, UINT8 *p_data);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*******************************************************************************
+**
+** Function HAL_NfcPreInitDone
+**
+** Description Notify that pre-initialization of NFCC is complete
+**
+** Returns void
+**
+*******************************************************************************/
+void HAL_NfcPreInitDone (tHAL_NFC_STATUS status);
+
+/*******************************************************************************
+**
+** Function HAL_NfcReInit
+**
+** Description This function is called to send an RESET and GET_PATCH_VERSION
+** command to NFCC.
+**
+** p_cback - The callback function to receive the command
+** status
+**
+** Note This function should be called only during the HAL init process
+**
+** Returns HAL_NFC_STATUS_OK if successfully initiated
+** HAL_NFC_STATUS_FAILED otherwise
+**
+*******************************************************************************/
+tHAL_NFC_STATUS HAL_NfcReInit (tNFC_HAL_NCI_CBACK *p_cback);
+
+/*******************************************************************************
+**
+** Function HAL_NfcSetSnoozeMode
+**
+** Description Set snooze mode
+** snooze_mode
+** NFC_HAL_LP_SNOOZE_MODE_NONE - Snooze mode disabled
+** NFC_HAL_LP_SNOOZE_MODE_UART - Snooze mode for UART
+** NFC_HAL_LP_SNOOZE_MODE_SPI_I2C - Snooze mode for SPI/I2C
+**
+** idle_threshold_dh/idle_threshold_nfcc
+** Idle Threshold Host in 100ms unit
+**
+** nfc_wake_active_mode/dh_wake_active_mode
+** NFC_HAL_LP_ACTIVE_LOW - high to low voltage is asserting
+** NFC_HAL_LP_ACTIVE_HIGH - low to high voltage is asserting
+**
+** p_snooze_cback
+** Notify status of operation
+**
+** Returns tHAL_NFC_STATUS
+**
+*******************************************************************************/
+tHAL_NFC_STATUS HAL_NfcSetSnoozeMode (UINT8 snooze_mode,
+ UINT8 idle_threshold_dh,
+ UINT8 idle_threshold_nfcc,
+ UINT8 nfc_wake_active_mode,
+ UINT8 dh_wake_active_mode,
+ tHAL_NFC_STATUS_CBACK *p_snooze_cback);
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmDownloadStart
+**
+** Description Initiate patch download
+**
+** Input Params
+** format_type patch format type
+** (NFC_HAL_PRM_FORMAT_BIN, NFC_HAL_PRM_FORMAT_HCD, or
+** NFC_HAL_PRM_FORMAT_NCD)
+**
+** dest_address destination adderess (needed for BIN format only)
+**
+** p_patchram_buf pointer to patchram buffer. If NULL,
+** then app must call HAL_NfcPrmDownloadContinue when
+** NFC_HAL_PRM_CONTINUE_EVT is received, to send the next
+** segment of patchram
+**
+** patchram_len size of p_patchram_buf (if non-NULL)
+**
+** patchram_delay The delay after each patch.
+** If the given value is less than the size of the patchram,
+** the size of patchram is used instead.
+**
+** p_cback callback for download status
+**
+**
+** Returns TRUE if successful, otherwise FALSE
+**
+**
+*******************************************************************************/
+BOOLEAN HAL_NfcPrmDownloadStart (tNFC_HAL_PRM_FORMAT format_type,
+ UINT32 dest_address,
+ UINT8 *p_patchram_buf,
+ UINT32 patchram_len,
+ UINT32 patchram_delay,
+ tNFC_HAL_PRM_CBACK *p_cback);
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmDownloadContinue
+**
+** Description Send next segment of patchram to controller. Called when
+** NFC_HAL_PRM_CONTINUE_EVT is received.
+**
+** Only needed if HAL_NfcPrmDownloadStart was called with
+** p_patchram_buf=NULL
+**
+** Input Params p_patch_data pointer to patch data
+** patch_data_len patch data len
+**
+** Returns TRUE if successful, otherwise FALSE
+**
+*******************************************************************************/
+BOOLEAN HAL_NfcPrmDownloadContinue (UINT8 *p_patch_data,
+ UINT16 patch_data_len);
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmSetI2cPatch
+**
+** Description Specify patchfile for BCM20791B3 I2C fix. This fix
+** must be downloaded prior to initial patch download for I2C
+** transport
+**
+** Input Params p_i2c_patchfile_buf: pointer to patch for i2c fix
+** i2c_patchfile_len: length of patch
+** prei2c_delay: the delay before downloading main patch
+** if 0 is given, NFC_HAL_PRM_POST_I2C_FIX_DELAY is used instead.
+**
+** Returns Nothing
+**
+**
+*******************************************************************************/
+void HAL_NfcPrmSetI2cPatch (UINT8 *p_i2c_patchfile_buf,
+ UINT16 i2c_patchfile_len, UINT32 prei2c_delay);
+
+/*******************************************************************************
+**
+** Function HAL_NfcPrmSetSpdNciCmdPayloadSize
+**
+** Description Set Host-to-NFCC NCI message size for secure patch download
+**
+** This API must be called before calling HAL_NfcPrmDownloadStart.
+** If the API is not called, then PRM will use the default
+** message size.
+**
+** Typically, this API is only called for platforms that have
+** message-size limitations in the transport/driver.
+**
+** Valid message size range: NFC_HAL_PRM_MIN_NCI_CMD_PAYLOAD_SIZE to 255.
+**
+** Returns HAL_NFC_STATUS_OK if successful
+** HAL_NFC_STATUS_FAILED otherwise
+**
+**
+*******************************************************************************/
+tHAL_NFC_STATUS HAL_NfcPrmSetSpdNciCmdPayloadSize (UINT8 max_payload_size);
+
+/*******************************************************************************
+**
+** Function HAL_NfcSetMaxRfDataCredits
+**
+** Description This function sets the maximum RF data credit for HAL.
+** If 0, use the value reported from NFCC.
+**
+** Returns none
+**
+*******************************************************************************/
+void HAL_NfcSetMaxRfDataCredits (UINT8 max_credits);
+
+/*******************************************************************************
+**
+** Function HAL_NfcSetTraceLevel
+**
+** Description This function sets the trace level for HAL. If called with
+** a value of 0xFF, it simply returns the current trace level.
+**
+** Returns The new or current trace level
+**
+*******************************************************************************/
+UINT8 HAL_NfcSetTraceLevel (UINT8 new_level);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NFC_HAL_INT_API_H */
+
diff --git a/halimpl/bcm2079x/hal/int/nfc_hal_nv_ci.h b/halimpl/bcm2079x/hal/int/nfc_hal_nv_ci.h
new file mode 100644
index 0000000..a77c207
--- /dev/null
+++ b/halimpl/bcm2079x/hal/int/nfc_hal_nv_ci.h
@@ -0,0 +1,88 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2003-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This is the interface file for non valtile memory call-in functions.
+ *
+ ******************************************************************************/
+#ifndef NFC_HAL_NV_CI_H
+#define NFC_HAL_NV_CI_H
+
+#include "nfc_hal_nv_co.h"
+
+
+/*****************************************************************************
+** Function Declarations
+*****************************************************************************/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*******************************************************************************
+**
+** Function nfc_hal_nv_ci_write
+**
+** Description This function sends an event to NFAA indicating the phone
+** has written the number of bytes specified in the call-out
+** function, nfa_nv_co_write (), and is ready for more data.
+** This function is used to control the TX data flow.
+** Note: The data buffer is released by the stack aioer
+** calling this function.
+**
+** Parameters status - NFA_NV_CO_OK, NFA_NV_CO_NOSPACE, or NFA_NV_CO_FAIL
+** evt - Used Internally by NFA -> MUST be same value passed
+** in call-out function.
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_nv_ci_write (tNFC_HAL_NV_CO_STATUS status);
+
+/*******************************************************************************
+**
+** Function nfc_hal_nv_ci_read
+**
+** Description This function sends an event to NCIT indicating the phone has
+** read in the requested amount of data specified in the
+** nfa_nv_co_read () call-out function. It should only be called
+** when the requested number of bytes has been read.
+**
+** Parameters num_bytes_read - number of bytes read into the buffer
+** specified in the read callout-function.
+** status - NFC_HAL_NV_CO_OK if full buffer of data,
+** NFC_HAL_NV_CO_EOF if the end of file has been reached,
+** NFC_HAL_NV_CO_FAIL if an error has occurred.
+** evt - Used Internally by NFA -> MUST be same value passed
+** in call-out function.
+**
+** Returns void
+**
+*******************************************************************************/
+void nfc_hal_nv_ci_read (UINT16 num_bytes_read,
+ tNFC_HAL_NV_CO_STATUS status,
+ UINT8 block);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NFC_HAL_NV_CI_H */
+
diff --git a/halimpl/bcm2079x/hal/int/nfc_hal_nv_co.h b/halimpl/bcm2079x/hal/int/nfc_hal_nv_co.h
new file mode 100644
index 0000000..2264cfe
--- /dev/null
+++ b/halimpl/bcm2079x/hal/int/nfc_hal_nv_co.h
@@ -0,0 +1,108 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2003-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * This is the interface file for storing nv data
+ *
+ ******************************************************************************/
+#ifndef NFC_HAL_NV_CO_H
+#define NFC_HAL_NV_CO_H
+
+#include <time.h>
+
+
+/*****************************************************************************
+** Constants and Data Types
+*****************************************************************************/
+
+
+/**************************
+** Common Definitions
+***************************/
+
+/* Status codes returned by call-out functions, or in call-in functions as status */
+#define NFC_HAL_NV_CO_OK 0x00
+#define NFC_HAL_NV_CO_FAIL 0x01 /* Used to pass all other errors */
+#define NFC_HAL_NV_CO_EACCES 0x02
+#define NFC_HAL_NV_CO_ENOTEMPTY 0x03
+#define NFC_HAL_NV_CO_EOF 0x04
+#define NFC_HAL_NV_CO_EODIR 0x05
+#define NFC_HAL_NV_CO_ENOSPACE 0x06 /* Returned in nfa_nv_ci_open if no room */
+#define NFC_HAL_NV_CO_EIS_DIR 0x07
+#define NFC_HAL_NV_CO_RESUME 0x08 /* used in nfa_nv_ci_open, on resume */
+#define NFC_HAL_NV_CO_NONE 0x09 /* used in nfa_nv_ci_open, on resume (no file to resume) */
+
+typedef UINT8 tNFC_HAL_NV_CO_STATUS;
+
+#define DH_NV_BLOCK 0x01
+#define HC_F3_NV_BLOCK 0x02
+#define HC_F4_NV_BLOCK 0x03
+#define HC_DH_NV_BLOCK 0x04
+
+/*****************************************************************************
+** Function Declarations
+*****************************************************************************/
+/**************************
+** Common Functions
+***************************/
+
+/*******************************************************************************
+**
+** Function nfc_hal_nv_co_read
+**
+** Description This function is called by NFA to read in data from the
+** previously opened file.
+**
+** Parameters p_buf - buffer to read the data into.
+** nbytes - number of bytes to read into the buffer.
+**
+** Returns void
+**
+** Note: Upon completion of the request, nfa_nv_ci_read () is
+** called with the buffer of data, along with the number
+** of bytes read into the buffer, and a status. The
+** call-in function should only be called when ALL requested
+** bytes have been read, the end of file has been detected,
+** or an error has occurred.
+**
+*******************************************************************************/
+void nfc_hal_nv_co_read (UINT8 *p_buf, UINT16 nbytes, UINT8 block);
+
+/*******************************************************************************
+**
+** Function nfc_hal_nv_co_write
+**
+** Description This function is called by io to send file data to the
+** phone.
+**
+** Parameters p_buf - buffer to read the data from.
+** nbytes - number of bytes to write out to the file.
+**
+** Returns void
+**
+** Note: Upon completion of the request, nfa_nv_ci_write () is
+** called with the file descriptor and the status. The
+** call-in function should only be called when ALL requested
+** bytes have been written, or an error has been detected,
+**
+*******************************************************************************/
+void nfc_hal_nv_co_write (const UINT8 *p_buf, UINT16 nbytes, UINT8 block);
+
+
+#endif /* NFC_HAL_NV_CO_H */
diff --git a/halimpl/bcm2079x/hal/int/nfc_hal_post_reset.h b/halimpl/bcm2079x/hal/int/nfc_hal_post_reset.h
new file mode 100644
index 0000000..95da455
--- /dev/null
+++ b/halimpl/bcm2079x/hal/int/nfc_hal_post_reset.h
@@ -0,0 +1,66 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2009-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.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * Post NCI reset routines
+ *
+ ******************************************************************************/
+#ifndef NFC_HAL_POST_RESET_H
+#define NFC_HAL_POST_RESET_H
+
+
+/*****************************************************************************
+** Application control block definitions
+******************************************************************************/
+#define NFA_APP_PATCHFILE_MAX_PATH 255
+
+typedef struct
+{
+ UINT8 prm_file[NFA_APP_PATCHFILE_MAX_PATH+1]; /* Filename of patchram */
+ UINT8 *p_prm_buf; /* Pointer to buffer for holding patchram data */
+
+ /* Patchfile for I2C fix */
+ UINT8 prm_i2c_patchfile[NFA_APP_PATCHFILE_MAX_PATH+1];
+ UINT8 *p_prm_i2c_buf;
+
+ UINT8 userial_baud;
+
+ tNFC_HAL_DEV_INIT_CFG dev_init_config;
+
+ /* snooze mode setting */
+ UINT8 snooze_mode;
+ UINT8 idle_threshold_dh;
+ UINT8 idle_threshold_nfcc;
+ UINT8 nfc_wake_active_mode;
+ UINT8 dh_wake_active_mode;
+
+} tNFC_POST_RESET_CB;
+extern tNFC_POST_RESET_CB nfc_post_reset_cb;
+
+/*
+** Post NCI reset handler
+**
+** This function is called to start device pre-initialization after NCI CORE-RESET.
+** When pre-initialization is completed,
+** HAL_NfcPreInitDone() must be called to proceed with stack start up.
+*/
+void nfc_hal_post_reset_init (UINT32 brcm_hw_id, UINT8 nvm_type);
+
+
+#endif /* NFC_HAL_POST_RESET_H */