15d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
25d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Copyright (C) 2010 NXP Semiconductors
35d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
45d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Licensed under the Apache License, Version 2.0 (the "License");
55d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * you may not use this file except in compliance with the License.
65d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * You may obtain a copy of the License at
75d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
85d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *      http://www.apache.org/licenses/LICENSE-2.0
95d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Unless required by applicable law or agreed to in writing, software
115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * distributed under the License is distributed on an "AS IS" BASIS,
125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * See the License for the specific language governing permissions and
145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * limitations under the License.
155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* =========================================================================== *
195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \file  phHciNfc.c                                                           *
225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief HCI Interface Source for the HCI Management.                         *
235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Project: NFC-FRI-1.1                                                        *
265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Date: Thu Apr 22 17:49:47 2010 $                                           *
285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Author: ing04880 $                                                         *
295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Revision: 1.90 $                                                           *
305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Aliases: NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* =========================================================================== *
335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly################################################################################
385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly***************************** Header File Inclusion ****************************
395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly################################################################################
405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcConfig.h>
435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcCompId.h>
445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcIoctlCode.h>
455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc.h>
465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_Sequence.h>
475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_RFReader.h>
485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_LinkMgmt.h>
495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ENABLE_P2P
505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_NfcIPMgmt.h>
515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_Emulation.h>
535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_SWP.h>
545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_DevMgmt.h>
555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h>
565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/**/
585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*************************** Static Function Declaration **************************
615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Config_Emulation (
675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sEmulationCfg_t           *pEmulationConfig
705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        );
725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*************************** Function Definitions **************************
765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief Initialises the HCI Interface
815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function initialises the resources for the HCI Command and
835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Response Mechanism
845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Initialise (
885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHciNfc_Init_t                 init_mode,
915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sHwConfig_t               *pHwConfig,
925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        pphNfcIF_Notification_CB_t       pHalNotify,
935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psContext,
945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phNfcLayer_sCfg_t               *psHciLayerCfg
955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t *psHciContext = NULL;
9834ff48f6cd6595a899e05fbd56f4c84891840d3fNick Pelly    phNfcIF_sReference_t hciReference = { NULL, 0, 0 };
995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phNfcIF_sCallBack_t  if_callback = { NULL, NULL, NULL, NULL };
1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phNfc_sLowerIF_t    *plower_if = NULL;
1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS            status = NFCSTATUS_SUCCESS;
1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t              lower_index=0;
1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle) || (NULL == pHwRef) || (NULL == pHalNotify)
1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL== psContext) || (NULL == psHciLayerCfg) || (NULL == pHwConfig)
1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    )
1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL != *(phHciNfc_sContext_t **)psHciHandle )
1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_ALREADY_INITIALISED );
1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Create the memory for HCI Context */
1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext = (phHciNfc_sContext_t *)
1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phOsalNfc_GetMemory(sizeof(phHciNfc_sContext_t));
1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(psHciContext != NULL)
1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (void)memset((void *)psHciContext,0,
1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            sizeof(phHciNfc_sContext_t));
1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_state.cur_state = hciState_Reset;
1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_mode = hciMode_Reset;
1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_hw_ref = pHwRef;
1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->host_rf_type = phHal_eUnknown_DevType;
1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            HCI_PRINT("HCI Initialisation in Progress.... \n");
1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ESTABLISH_SESSION
1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /*(void)memcpy(((phHal_sHwReference_t *)pHwRef)->session_id,
1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                DEFAULT_SESSION, (sizeof(DEFAULT_SESSION) > 0x01) ?
1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  sizeof(DEFAULT_SESSION):
1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sizeof(((phHal_sHwReference_t *)pHwRef)->session_id));*/
1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            (void)memcpy(pHwConfig->session_id,
1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                DEFAULT_SESSION, ((sizeof(DEFAULT_SESSION) > 0x01)
1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    && (sizeof(DEFAULT_SESSION) <= 0x08 )) ?
1395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  sizeof(DEFAULT_SESSION):
1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    sizeof(pHwConfig->session_id));
1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            HCI_DEBUG("Sizeof Default Session %u\n",sizeof(DEFAULT_SESSION));
1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_upper_notify = pHalNotify;
1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_upper_context = psContext;
1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if_callback.pif_ctxt = psHciContext ;
1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if_callback.send_complete = &phHciNfc_Send_Complete;
1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if_callback.receive_complete= &phHciNfc_Receive_Complete;
1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if_callback.notify = &phHciNfc_Notify_Event;
1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            plower_if = hciReference.plower_if = &(psHciContext->lower_interface);
1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            *((phHciNfc_sContext_t **)psHciHandle) = psHciContext;
1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->init_mode = init_mode;
1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_hci_layer = psHciLayerCfg ;
1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            lower_index = psHciLayerCfg->layer_index - 1;
1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(NULL != psHciLayerCfg->layer_next->layer_registry)
1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
1585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = psHciLayerCfg->layer_next->layer_registry(
1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        &hciReference, if_callback,
1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (void *)&psHciLayerCfg[lower_index]);
1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                HCI_DEBUG("HCI Lower Layer Register, Status = %02X\n",status);
1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( (NFCSTATUS_SUCCESS == status) && (NULL != plower_if->init) )
1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_FSM_Update ( psHciContext,
1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        hciState_Initialise
1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        );
1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if(NFCSTATUS_SUCCESS == status)
1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->hci_seq = ADMIN_INIT_SEQ;
1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->target_release = FALSE;
1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->config_type = POLL_LOOP_CFG;
1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->p_config_params = pHwConfig ;
1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = plower_if->init((void *)plower_if->pcontext,
1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            (void *)psHciContext->p_hw_ref);
1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    HCI_DEBUG("HCI Lower Layer Initialisation, Status = %02X\n",status);
1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if( NFCSTATUS_PENDING != status )
1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        /* Roll Back the State Machine to its Original State */
1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHciNfc_FSM_Rollback ( psHciContext );
1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* TODO: Handle Initialisation in the Invalid State */
1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of Lower Layer Init */
1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        } /* End of Status Check for Memory */
1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
1905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            HCI_PRINT("HCI Context Memory Allocation Failed\n");
1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief Release of the HCI Interface .
2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function Closes all the open pipes and frees all the resources used by
2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * HCI Layer
2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Release (
2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    pphNfcIF_Notification_CB_t      pHalReleaseCB,
2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psContext
2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                  )
2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
2225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* This Scenario Forces the HCI and the lower layers
2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly     * to release its Resources
2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly     */
2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL == pHalReleaseCB )
2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Release the lower layer Resources */
2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_Release_Lower( psHciContext, pHwRef );
2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Release the HCI layer Resources */
2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_Release_Resources( &psHciContext );
2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL == psContext )
2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
2385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        HCI_PRINT("HCI Release in Progress.... \n");
2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Release );
2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if ((NFCSTATUS_SUCCESS == status)
2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef NXP_HCI_SHUTDOWN_OVERRIDE
2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            || (NFCSTATUS_INVALID_STATE == PHNFCSTATUS(status))
2475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
2485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            )
2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_upper_notify = pHalReleaseCB;
2515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_upper_context = psContext;
2525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* psHciContext->hci_seq = EMULATION_REL_SEQ;*/
2535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* psHciContext->hci_seq = READER_MGMT_REL_SEQ; */
2545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (HCI_SELF_TEST != psHciContext->init_mode)
2555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                psHciContext->hci_seq = PL_STOP_SEQ;
2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                psHciContext->hci_seq = ADMIN_REL_SEQ;
2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef NXP_HCI_SHUTDOWN_OVERRIDE
2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (NFCSTATUS_SUCCESS != status)
2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                psHciContext->hci_state.next_state = (uint8_t) hciState_Release;
2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = NFCSTATUS_PENDING;
2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
2715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_Release_Sequence(psHciContext,pHwRef);
2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* TODO: Return appropriate Error */
2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Starts the RF Device Discovery.
2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function Starts the Discovery Wheel.
2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Start_Discovery (
3015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
3025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef
3035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
3045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
3065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ( (NULL == psHciHandle)
3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      )
3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
3135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
3155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_ReaderMgmt_Enable_Discovery( psHciContext, pHwRef );
3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
3205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Stop the RF Device Discovery.
3255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
3265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function Stops the Discovery Wheel.
3275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
3285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
3315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Stop_Discovery (
3325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
3335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef
3345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
3355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
3375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
3385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ( (NULL == psHciHandle)
3405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
3415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      )
3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_ReaderMgmt_Disable_Discovery( psHciContext, pHwRef );
3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Configure the Device With the appropriate
3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Configuration Parameters .
3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function configures the Devices with the provided
3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * configuration attributes.
3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Configure (
3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_eConfigType_t             config_type,
3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_uConfig_t                 *pConfig
3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pConfig)
3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
3795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
3815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
3835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        switch(config_type)
3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case NFC_P2P_CONFIG:
3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ENABLE_P2P
3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_sContext_t  *psHciContext =
3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
3915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (NFCSTATUS_SUCCESS == status)
3945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
3955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->config_type = NFC_GENERAL_CFG;
3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->p_config_params = &(pConfig->nfcIPConfig);
3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->hci_seq = INITIATOR_GENERAL_SEQ;
3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_NfcIP_SetATRInfo( psHciHandle,
3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            pHwRef, NFCIP_INITIATOR,
4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    &(pConfig->nfcIPConfig));
4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if( NFCSTATUS_PENDING != status )
4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        /* Roll Back the State Machine to its Original State */
4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHciNfc_FSM_Rollback ( psHciContext );
4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    else
4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psHciContext->hci_seq = TARGET_GENERAL_SEQ;
4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
4135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case NFC_EMULATION_CONFIG:
4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_Config_Emulation( psHciHandle,
4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            pHwRef, &(pConfig->emuConfig));
4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case NFC_SE_PROTECTION_CONFIG:
4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_sContext_t  *psHciContext =
4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if (NFCSTATUS_SUCCESS == status)
4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->config_type = SWP_PROTECT_CFG;
4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->p_config_params = &(pConfig->protectionConfig);
4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->hci_seq = HCI_END_SEQ;
4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_SWP_Protection( psHciHandle,
4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                pHwRef, pConfig->protectionConfig.mode);
4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if( NFCSTATUS_PENDING != status )
4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        /* Roll Back the State Machine to its Original State */
4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHciNfc_FSM_Rollback ( psHciContext );
4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            default:
4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/* End of the Configuration Switch */
4505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }
4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Configure the RF Device Discovery using
4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * HCI Polling Loop Gate .
4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function configures the HCI Polling Loop Gate with the provided
4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * configuration attributes.
4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Config_Discovery (
4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sADD_Cfg_t                *pPollConfig
4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
4725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pPollConfig)
4775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
4785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        HCI_PRINT("HCI Poll Configuration .... \n");
4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
4905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(pPollConfig->PollDevInfo.PollEnabled)
4915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                psHciContext->hci_seq = PL_DURATION_SEQ;
4935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
4955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
4975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* psHciContext->hci_seq = (pPollConfig->NfcIP_Mode != 0 )?
4985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    PL_CONFIG_PHASE_SEQ:
4995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                        READER_DISABLE_SEQ; */
5005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
5015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_seq = PL_DURATION_SEQ;
5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->config_type = POLL_LOOP_CFG;
5045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_config_params = pPollConfig;
5055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_PollLoop_Sequence( psHciContext, pHwRef );
5065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
5085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
5105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
5115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
5125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
5145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* TODO: Return appropriate Error */
5165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
5185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
5195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
5205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
5225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Restart the RF Device Discovery.
5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function restarts the Discovery Wheel.
5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Restart_Discovery (
5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        uint8_t                         re_poll
5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal_eRemDevType_t     target_type = phHal_eUnknown_DevType;
5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ( (NULL == psHciHandle)
5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      )
5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* To be back in the Poll State to Re-Poll the Target */
5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Initialise );
5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch (psHciContext->host_rf_type)
5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_A_PCD:
5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    target_type = phHal_eISO14443_A_PICC;
5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Initiator:
5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    target_type = phHal_eNfcIP1_Target;
5635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B
5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PCD:
5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    target_type = phHal_eISO14443_B_PICC;
5695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
5705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_FELICA
5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PCD:
5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    target_type = phHal_eFelica_PICC;
5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_JEWEL
5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PCD:
5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    target_type = phHal_eJewel_PICC;
5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef  TYPE_ISO15693
5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO15693_PCD:
5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    target_type = phHal_eISO15693_PICC;
5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef    TYPE_ISO15693 */
5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B
5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PCD:
5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_FELICA
5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PCD:
5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_JEWEL
6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PCD:
6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B_PRIME
6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_BPrime_PCD:
6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eUnknown_DevType:
6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of the Remote Target Type Switch */
6205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_SUCCESS == status )
6215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_ReaderMgmt_Deselect(
6235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext, pHwRef, target_type, re_poll);
6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                if( NFCSTATUS_PENDING != status )
6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                else
6305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->host_rf_type = phHal_eUnknown_DevType;
6325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* TODO: Return appropriate Error */
6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Configure the device to emulation as
6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the tag, smart tag or p2p target .
6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function configures the HCI Polling Loop Gate with the provided
6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * configuration attributes.
6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly static
6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Config_Emulation (
6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
6595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sEmulationCfg_t           *pEmulationCfg
6605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
6615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
6625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
6635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
6645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
6665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
6675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pEmulationCfg)
6685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
6695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
6715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
6735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
6755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        HCI_PRINT("HCI Configure Emulation .... \n");
6775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
6785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_config_params = pEmulationCfg;
6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch( pEmulationCfg->emuType )
6845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_SMARTMX_EMULATION:
6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->config_type = SMX_WI_CFG;
6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_Emulation_Cfg(psHciContext,
6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                pHwRef, SMX_WI_CFG);
6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_UICC_EMULATION:
6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->config_type = UICC_SWP_CFG;
6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (void)phHciNfc_SWP_Update_Sequence(
6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        psHciContext, CONFIG_SEQ );
6985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_EmulationCfg_Sequence(
6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                psHciContext, pHwRef);
7005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
7015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_HOST_CE_A_EMULATION:
7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case NFC_HOST_CE_B_EMULATION:
7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if defined(HOST_EMULATION)
7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
7065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if(TRUE == pEmulationCfg->config.
7075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        hostEmuCfg_A.enableEmulation)
7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
7095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psHciContext->hci_seq = ADMIN_CE_SEQ;
7105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
7115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_EmulationCfg_Sequence(
7125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                psHciContext, pHwRef);
7135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
7145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
7155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
7165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
7175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
7185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
7195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
7205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            } /* End of Config Switch */
7225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
7235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
7255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
7265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
7295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* TODO: Return appropriate Error */
7315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Switch_SwpMode (
7395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_eSWP_Mode_t               swp_mode /* ,
7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pSwpCfg */
7435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                     )
7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        HCI_PRINT("HCI SWP Switch .... ");
7595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->config_type = SWP_EVT_CFG;
7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_SWP_Configure_Mode( psHciContext, pHwRef ,
7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                       (uint8_t) swp_mode );
7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Send the Success Status as this is an event */
7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = ((status == NFCSTATUS_SUCCESS)?
7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    NFCSTATUS_PENDING : status);
7695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                HCI_PRINT(" Execution Error \n");
7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
7785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                HCI_PRINT(" Successful \n");
7805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
7835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            HCI_PRINT(" Not allowed - Invalid State \n");
7855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* TODO: Return appropriate Error */
7865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
7905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
7955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Switch the Mode of the SmartMx from Virtual/Wired
7965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * to the other mode.
7975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
7985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function switches the mode of the SmartMX connected through WI(S2C)
7995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Interface to virtual/wired mode.
8005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
8015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
8045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Switch_SmxMode (
8055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *psHciHandle,
8065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                            *pHwRef,
8075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_eSmartMX_Mode_t           smx_mode,
8085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHal_sADD_Cfg_t                *pPollConfig
8095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    )
8105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
8115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
8125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
8135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
8155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
8165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pPollConfig)
8175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
8185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
8205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
8225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
8245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        HCI_PRINT("HCI Smart MX Mode Switch .... \n");
8265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Config );
8275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
8295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_seq = READER_DISABLE_SEQ;
8315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if ( (eSmartMx_Wired == psHciContext->smx_mode)
8325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                && ( hciState_Connect == psHciContext->hci_state.cur_state)
8335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                &&( eSmartMx_Wired != smx_mode)
8345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                )
8355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Workaround: For Wired Mode Disconnect
8375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                   All the statemachine updates should be done only with the
8385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                   Statemachine API and should not be overridden.
8395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 */
8405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 psHciContext->hci_state.cur_state = hciState_Disconnect;
8415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->config_type = SMX_WI_MODE;
8435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->smx_mode = smx_mode;
8445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_config_params = pPollConfig;
8455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_SmartMx_Mode_Sequence( psHciContext, pHwRef );
8465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
8475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
8495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
8505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
8515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
8535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* TODO: Return appropriate Error */
8555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
8565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
8595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
8605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
8635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Select the Next Remote Target Discovered during the
8645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * discovery sequence using the particular HCI Reader Gate .
8655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
8665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
8675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function Selects and Activates the next Remote Target
8685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Detected using the particular HCI Reader Gate.
8695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
8705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
8745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Select_Next_Target (
8755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
8765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef
8775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    )
8785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
8795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
8805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS            status = NFCSTATUS_SUCCESS;
8815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
8825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
8835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
8845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
8855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
8875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
8885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
8895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
8905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
8915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Select );
8925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
8935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
8945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_seq = READER_SELECT_SEQ;
8955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_ReaderMgmt_Activate_Next( psHciContext, pHwRef );
8965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
8975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
8985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
8995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
9005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
9015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
9025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
9035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
9045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
9055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
9065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
9095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
9115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
9145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Connect the Remote Target Discovered during the
9155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * discovery sequence using the particular HCI Reader Gate .
9165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
9175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
9185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function connects the Remote Target Detected using the particular
9195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * HCI Reader Gate with the appropriate configuration setup.
9205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
9215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
9245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Connect (
9255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
9265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
9275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHal_sRemoteDevInformation_t   *p_target_info
9285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
9295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
9305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
9315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS            status = NFCSTATUS_SUCCESS;
9325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* phHal_eRemDevType_t  target_type = phHal_eUnknown_DevType; */
9335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
9355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
9365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == p_target_info)
9375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
9385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
9405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
9415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
9425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
9435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
9445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Connect );
9455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
9465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
9475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_seq = READER_SELECT_SEQ;
9485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch (p_target_info->RemDevType)
9495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
9505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_A_PICC:
9515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4A_PICC:
9525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eMifare_PICC:
9535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_3A_PICC:
9545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ENABLE_P2P
9555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Target:
9565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
9575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B
9585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
9595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
9605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
9615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_FELICA
9625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
9635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
9645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_JEWEL
9655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
9665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
9675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef  TYPE_ISO15693
9685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO15693_PICC:
9695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef    TYPE_ISO15693 */
9705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
9715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
9725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->p_target_info = p_target_info;
9735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_ReaderMgmt_Select(
9745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    psHciContext, pHwRef,
9755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    p_target_info->RemDevType );
9765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
9775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
9785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B_PRIME
9795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_BPrime_PICC:
9805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
9815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eUnknown_DevType:
9825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
9835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
9845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
9855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
9865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
9875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
9885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
9895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of the Remote Target Type Switch */
9905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
9915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
9925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
9935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
9945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
9955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
9965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
9975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
9985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
9995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
10005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } /* End of the HCI Handle Validation */
10025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
10045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
10055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
10085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Reactivate the Remote Targets Discovered during the
10095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * discovery sequence using the particular HCI Reader Gate .
10105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
10115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
10125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function reactivates the Remote Target Detected using the particular
10135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * HCI Reader Gate with the appropriate configuration setup.
10145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
10155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
10185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Reactivate (
10195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
10205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
10215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHal_sRemoteDevInformation_t   *p_target_info
10225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
10235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
10245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
10255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS            status = NFCSTATUS_SUCCESS;
10265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* phHal_eRemDevType_t  target_type = phHal_eUnknown_DevType; */
10275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
10295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
10305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == p_target_info)
10315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
10325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
10335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
10345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
10355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
10365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
10375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
10385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Reactivate );
10395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
10405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
10415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_seq = READER_REACTIVATE_SEQ;
10425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch (p_target_info->RemDevType)
10435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
10445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_A_PICC:
10455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4A_PICC:
10465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eMifare_PICC:
10475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_3A_PICC:
10485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
10495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->host_rf_type = phHal_eISO14443_A_PCD;
10505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
10515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
10525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Target:
10535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
10545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->host_rf_type = phHal_eNfcIP1_Initiator;
10555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
10565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
10575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B
10585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
10595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
10605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
10615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->host_rf_type = phHal_eISO14443_B_PCD;
10625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
10635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
10645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
10655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_FELICA
10665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
10675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
10685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->host_rf_type = phHal_eFelica_PCD;
10695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
10705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
10715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
10725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B_PRIME
10735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_BPrime_PICC:
10745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
10755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Reactivate for Jewel is not Supported */
10765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
10775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eUnknown_DevType:
10785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
10795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
10805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
10815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
10825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
10835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
10845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
10855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of the Remote Target Type Switch */
10865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
10875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
10885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
10895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
10905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
10915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
10925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NFCSTATUS_SUCCESS == status )
10935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
10945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_target_info = p_target_info;
10955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_ReaderMgmt_Reactivate(
10965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            psHciContext, pHwRef, p_target_info->RemDevType );
10975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
10985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
10995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
11005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
11015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
11025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
11035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } /* End of the HCI Handle Validation */
11045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
11075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
11085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
11115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Disconnect the selected target.
11125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
11135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function disconnects the remote target selected.
11145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
11155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
11185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Disconnect (
11195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
11205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
11215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint8_t                         re_poll
11225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
11235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
11245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
11255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS            status = NFCSTATUS_SUCCESS;
11265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal_eRemDevType_t  target_type = phHal_eUnknown_DevType;
11275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* phHal_eSmartMX_Mode_t smx_mode = (phHal_eSmartMX_Mode_t)type; */
11285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    static  uint8_t      repoll=0;
11295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
11325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
11335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || ( NULL == psHciContext->p_target_info)
11345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    )
11355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
11365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
11375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
11385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
11395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
11405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
11415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        repoll = re_poll;
11425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_config_params = &repoll;
11435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* psHciContext->hci_seq = HCI_END_SEQ; */
11445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* To be back in the Poll State to Re-Poll the Target */
11465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Disconnect );
11475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
11485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
11495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->hci_seq = READER_UICC_DISPATCH_SEQ;
11505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            target_type = psHciContext->p_target_info->RemDevType;
11515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch (target_type)
11525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
11535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eMifare_PICC:
11545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_A_PICC:
11555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4A_PICC:
11565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_3A_PICC:
11575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Target:
11585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B
11595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
11605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
11615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
11625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_FELICA
11635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
11645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
11655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_JEWEL
11665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
11675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
11685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef  TYPE_ISO15693
11695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO15693_PICC:
11705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef    TYPE_ISO15693 */
11715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
11725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
11735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_Disconnect_Sequence(
11745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    psHciContext, pHwRef );
11755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
11765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
11775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B
11785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
11795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
11805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
11815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_FELICA
11825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
11835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
11845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_JEWEL
11855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
11865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
11875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B_PRIME
11885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_BPrime_PICC:
11895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
11905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
11915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
11925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
11935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
11945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
11955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
11965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eUnknown_DevType:
11975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
11985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
11995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
12005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
12015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
12025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
12035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
12045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of the Remote Target Type Switch */
12055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
12065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
12075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
12085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
12095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
12105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
12125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* TODO: Return appropriate Error */
12145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
12155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } /* End of the HCI Handle Validation */
12165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
12185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
12195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
12215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to exchange the data to/from
12225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected target.
12235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
12245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function sends and receives the data to/from
12255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected remote target.
12265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
12275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
12295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Exchange_Data (
12305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
12315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
12325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHal_sRemoteDevInformation_t   *p_target_info,
12335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_XchgInfo_t             *p_xchg_info
12345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
12355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
12365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
12375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
12385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
12395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
12405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
12415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == p_target_info)
12425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == p_xchg_info)
12435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
12445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
12465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if (p_target_info != psHciContext->p_target_info )
12485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_REMOTE_DEVICE);
12505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
12515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
12525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
12535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
12545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Transact );
12555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
12565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
12575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch (p_target_info->RemDevType)
12585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
12595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eMifare_PICC:
12605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_A_PICC:
12615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4A_PICC:
12625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_3A_PICC:
12635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B
12645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
12655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
12665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
12675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_FELICA
12685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
12695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
12705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_JEWEL
12715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
12725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
12735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef  TYPE_ISO15693
12745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO15693_PICC:
12755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef    TYPE_ISO15693 */
12765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
12775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->p_xchg_info = p_xchg_info;
12785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_ReaderMgmt_Exchange_Data(
12795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    psHciContext, pHwRef, p_xchg_info );
12805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
12815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
12825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B
12835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
12845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
12855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
12865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_FELICA
12875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
12885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
12895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_JEWEL
12905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
12915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
12925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Target:
12935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B_PRIME
12945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_BPrime_PICC:
12955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
12965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
12975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
12985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
12995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
13005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
13015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
13025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eUnknown_DevType:
13035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
13045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
13055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
13065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
13075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
13085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
13095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
13105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of the Remote Target Type Switch */
13125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
13135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
13145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
13155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
13165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
13175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
13195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
13215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
13225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } /* End of the HCI Handle Validation */
13235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
13255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
13265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
13285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Send the data to/from
13295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected NfcIP.
13305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
13315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function sends and receives the data to/from
13325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected remote target.
13335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
13345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
13365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Send_Data (
13375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
13385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
13395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHal_sRemoteDevInformation_t   *p_remote_dev_info,
13405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_XchgInfo_t             *p_send_param
13415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
13425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
13435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
13445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
13455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
13465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
13475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
13485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == p_send_param)
13495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
13505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
13515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
13525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
13535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
13545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
13555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
13565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Transact );
13575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
13585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
13595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch (psHciContext->host_rf_type)
13605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
13615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_A_PICC:
13625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
13635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4A_PICC:
13645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
13655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
13665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
13675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
13685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ENABLE_P2P
13695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Initiator:
13705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
13715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if (p_remote_dev_info !=
13725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    psHciContext->p_target_info )
13735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
13745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        status = PHNFCSTVAL(CID_NFC_HCI,
13755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        NFCSTATUS_INVALID_REMOTE_DEVICE);
13765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
13775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    else
13785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
13795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        psHciContext->p_xchg_info = p_send_param;
13805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        status = phHciNfc_NfcIP_Send_Data( psHciContext,
13815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                    pHwRef, p_send_param );
13825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
13835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
13845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
13855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Target:
13865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
13875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    psHciContext->p_xchg_info = p_send_param;
13885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_NfcIP_Send_Data( psHciContext,
13895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                pHwRef, p_send_param );
13905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
13915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
13925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
13935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B_PRIME
13945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_BPrime_PCD:
13955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PCD:
13965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
13975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
13985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
13995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
14005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
14015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
14025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
14035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eUnknown_DevType:
14045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
14055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
14065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
14075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
14085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
14095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
14105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
14115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of the Remote Target Type Switch */
14135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if defined( ENABLE_P2P ) || defined (TYPE_B_PRIME)
14145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
14155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
14165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
14175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
14185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
14195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
14205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
14215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
14225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
14235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
14245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
14255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } /* End of the HCI Handle Validation */
14265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
14285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }
14305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if 0
14325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
14345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Send the data from
14355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected NfcIP.
14365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
14375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function sends and receives the data to/from
14385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected remote target.
14395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
14405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
14425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Receive_Data (
14435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
14445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
14455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint8_t                         *p_data,
14465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint8_t                         length
14475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
14485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
14495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t  *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
14505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS   status = NFCSTATUS_SUCCESS;
14515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciHandle)
14535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
14545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
14555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
14565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
14575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
14585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
14595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
14605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
14615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
14625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Receive(psHciHandle, pHwRef, p_data, length);
14635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
14645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
14655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
14665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
14675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
14685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
14695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
14705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
14715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }
14735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
14755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly /*!
14775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief  Interface to Check for the presence of
14785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected target in the field .
14795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly *
14805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function checks the presence of the
14815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the selected remote target in the field .
14825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */
14835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
14875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Presence_Check (
14885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
14895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef
14905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    )
14915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
14925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
14935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext =
14945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
14955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal_eRemDevType_t     target_type = phHal_eUnknown_DevType;
14965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
14975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)
14985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
14995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
15005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
15015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
15025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
15035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
15045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
15055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
15065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Presence );
15075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
15085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
15095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            target_type = psHciContext->p_target_info->RemDevType;
15105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch (target_type)
15115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
15125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_A_PICC:
15135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eMifare_PICC:
15145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4A_PICC:
15155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_3A_PICC:
15165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B
15175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
15185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
15195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_FELICA
15215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
15225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_JEWEL
15245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
15255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef  TYPE_ISO15693
15275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO15693_PICC:
15285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #ifdef    TYPE_ISO15693 */
15295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ENABLE_P2P
15305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eNfcIP1_Target:
15315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
15335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_ReaderMgmt_Presence_Check(
15345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            psHciContext, pHwRef );
15355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
15365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
15375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef TYPE_B_PRIME
15385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_BPrime_PICC:
15395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_B
15415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_B_PICC:
15425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eISO14443_4B_PICC:
15435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_FELICA
15455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eFelica_PICC:
15465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifndef TYPE_JEWEL
15485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eJewel_PICC:
15495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
15505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case phHal_eUnknown_DevType:
15515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
15525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
15535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
15545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
15555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
15565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
15575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
15585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
15595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    /* Roll Back the State Machine to its Original State */
15605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phHciNfc_FSM_Rollback ( psHciContext );
15615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
15625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
15635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
15645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }/* End of the Remote Target Type Switch */
15665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
15675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
15685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
15695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
15705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
15715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
15725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
15735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
15745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
15755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
15765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    } /* End of the HCI Handle Validation */
15775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
15795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
15805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
15825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_PRBS_Test (
15835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
15845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
15855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint32_t                        test_type,
15865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phNfc_sData_t                   *test_param
15875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
15885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly {
15895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
15905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext =
15915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
15925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
15935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)
15945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
15955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (test_type != DEVMGMT_PRBS_TEST)
15965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
15975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
15985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
15995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
16005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
16015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
16025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
16035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
16045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
16055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
16065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_DevMgmt_Test(psHciContext, pHwRef,
16075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (uint8_t)(test_type & DEVMGMT_TEST_MASK), test_param);
16085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
16095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
16115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
16125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
16145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
16155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
16165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly }
16175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
16205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_System_Test (
16215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
16225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
16235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint32_t                        test_type,
16245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    phNfc_sData_t                   *test_param
16255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
16265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
16275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
16285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext =
16295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
16305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    static phNfc_sData_t test_result;
16315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    static uint8_t       gpio_status = 0;
16325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)
16345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
16355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
16365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
16375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
16385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
16395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
16405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
16415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
16425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_Test );
16435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
16445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
16455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if (test_type != NFC_GPIO_READ)
16465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_DevMgmt_Test(psHciContext, pHwRef,
16485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (uint8_t)(test_type & DEVMGMT_TEST_MASK), test_param);
16495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
16515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                test_result.buffer = &gpio_status;
16535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef,
16545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    (uint16_t)NFC_GPIO_READ, test_result.buffer);
16555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
16585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
16605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
16615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
16625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
16635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
16645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly     return status;
16665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
16675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
16705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_System_Configure (
16715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
16725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
16735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint32_t                        config_type,
16745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint8_t                         config_value
16755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
16765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
16775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
16785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext =
16795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
16805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)
16825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
16835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
16845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
16855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
16865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
16875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
16885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
16895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
16905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
16915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
16925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
16935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_DevMgmt_Configure(psHciContext, pHwRef,
16945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (uint16_t)config_type, config_value);
16955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
16965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
16975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
16985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
16995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
17005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
17015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
17025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
17035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status;
17045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
17055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
17075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_System_Get_Info(
17085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
17095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef,
17105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint32_t                        config_type,
17115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    uint8_t                         *p_config_value
17125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
17135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
17145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
17155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext =
17165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
17175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)
17195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
17205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == p_config_value)
17215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
17225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
17235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
17245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
17255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
17265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
17275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
17285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
17295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
17305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
17315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef,
17325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                (uint16_t)config_type, p_config_value);
17335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
17355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
17365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
17375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
17385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
17395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
17405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
17415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status;
17435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
17445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly NFCSTATUS
17475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phHciNfc_Get_Link_Status(
17485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *psHciHandle,
17495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    void                            *pHwRef
17505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                 )
17515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
17525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
17535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext =
17545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            ((phHciNfc_sContext_t *)psHciHandle);
17555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)
17575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (NULL == pHwRef)
17585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
17595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
17605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
17615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
17625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
17635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
17645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->p_hw_ref = pHwRef;
17655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = phHciNfc_FSM_Update ( psHciContext, hciState_IO );
17665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status)
17675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
17685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_LinkMgmt_Open(psHciContext, pHwRef);
17695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_PENDING != status )
17715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
17725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Roll Back the State Machine to its Original State */
17735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                phHciNfc_FSM_Rollback ( psHciContext );
17745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
17755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
17765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
17775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return status;
17795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
17805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
17825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1783