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_WI.c                                                        *
225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief HCI WI gate Management Routines.                                     *
235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* Project: NFC-FRI-1.1                                                        *
265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*                                                                             *
275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Date: Tue Aug 18 10:22:34 2009 $                                           *
285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Author: ing04880 $                                                         *
295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Revision: 1.33 $                                                            *
305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* $Aliases: NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,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***************************** Header File Inclusion ****************************
365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phNfcCompId.h>
385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_Pipe.h>
395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_WI.h>
405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h>
415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phHciNfc_Emulation.h>
425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly****************************** Macro Definitions *******************************
445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*  WI gate specific Events definition */
465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define NXP_EVT_SE_START_OF_TRANSACTION (0x01U)
475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define NXP_EVT_SE_END_OF_TRANSACTION   (0x02U)
485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define NXP_EVT_SE_SWITCH_MODE          (0x03U)
495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define NXP_EVT_SE_TRANSACTION          (0x04U)
505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* WI Gate registry Settings */
525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* set default mode mode as virtual mode */
535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define NXP_SE_DEFAULTMODE_INDEX        (0x01)
545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define NXP_SE_EVENTS_INDEX             (0x05)
555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* Set Bit 0 and Bit 1 to report Start of transaction and End of transaction*/
57325757574e3fdca117f89c84d6db1766d8160b2adaniel_tomas#define WI_ENABLE_EVENTS                (0x04)
585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define WI_VIRTUALMODE                  (0x01)
595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define WI_OFFMODE                      (0x00)
605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#define AID_SIZE                        (0x20)
615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/****************** Structure and Enumeration ****************************/
625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/****************** Static Function Declaration **************************/
655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
66967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomasstatic uint8_t paypass_removal[2]          = {0x50, 0x00};
67967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomasstatic uint8_t mifare_access               = 0x60;
68967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas
695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Recv_WI_Response(
725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void  *psContext,
735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void  *pHwRef,
745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              uint8_t *pResponse,
755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ONE_BYTE_LEN
765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              uint8_t            length
775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              uint16_t           length
795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                         );
815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Recv_WI_Event(
855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void    *psContext,
865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void    *pHwRef,
875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        uint8_t *pEvent,
885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ONE_BYTE_LEN
895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        uint8_t            length
905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        uint16_t           length
925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    );
945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Send_WI_Event(
985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        phHciNfc_sContext_t     *psHciContext,
995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        void                    *pHwRef,
1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        uint8_t                 pipe_id,
1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        uint8_t                 event
1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    );
1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_InfoUpdate(
1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            phHciNfc_sContext_t     *psHciContext,
1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            uint8_t                 index,
1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            uint8_t                 *reg_value,
1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            uint8_t                 reg_length
1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            );
1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if defined (WI_UPDATE_SEQ)
1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Update_Sequence(
1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHciNfc_sContext_t     *psHciContext,
1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHciNfc_eSeqType_t     WI_seq
1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                         );
1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if defined (WI_UPDATE_SEQ) */
1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*
1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*************************** Function Definitions ***************************
1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Init_Resources(
1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           phHciNfc_sContext_t  *psHciContext
1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          )
1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_WI_Info_t          *p_WI_info=NULL;
1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( NULL == psHciContext )
1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(( NULL == psHciContext->p_wi_info ) &&
1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly             (phHciNfc_Allocate_Resource((void **)(&p_WI_info),
1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            sizeof(phHciNfc_WI_Info_t))== NFCSTATUS_SUCCESS))
1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_wi_info = p_WI_info;
1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_WI_info->current_seq = eWI_PipeOpen;
1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_WI_info->next_seq = eWI_PipeOpen;
1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_WI_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Get_PipeID(
1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            phHciNfc_sContext_t        *psHciContext,
1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            uint8_t                    *ppipe_id
1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            )
1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL != psHciContext)
1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        && ( NULL != ppipe_id )
1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        && ( NULL != psHciContext->p_wi_info )
1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t     *p_wi_info=NULL;
1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wi_info = (phHciNfc_WI_Info_t *)
1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_wi_info ;
1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        *ppipe_id =  p_wi_info->pipe_id  ;
1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Update_PipeInfo(
1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  phHciNfc_sContext_t     *psHciContext,
1905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  uint8_t                 pipeID,
1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                  phHciNfc_Pipe_Info_t    *pPipeInfo
1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                           )
1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( NULL == psHciContext )
1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(NULL == psHciContext->p_wi_info)
2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t *p_WI_info=NULL;
2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_WI_info = (phHciNfc_WI_Info_t *)
2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                psHciContext->p_wi_info ;
2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Update the pipe_id of the WI Gate obtained from HCI Response */
2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_WI_info->pipe_id = pipeID;
2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_WI_info->p_pipe_info = pPipeInfo;
2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if ( NULL != pPipeInfo)
2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Update the Response Receive routine of the WI Gate */
2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pPipeInfo->recv_resp = &phHciNfc_Recv_WI_Response;
2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Update the event Receive routine of the WI Gate */
2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            pPipeInfo->recv_event = &phHciNfc_Recv_WI_Event;
2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
2195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
2225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
2235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#if defined (WI_UPDATE_SEQ)
2255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
2265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
2275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Update_Sequence(
2285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHciNfc_sContext_t     *psHciContext,
2295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                phHciNfc_eSeqType_t     WI_seq
2305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                             )
2315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
2325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
2335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_WI_Info_t          *p_WI_info=NULL;
2345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( NULL == psHciContext )
2355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
2375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL == psHciContext->p_wi_info )
2395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI,
2415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NFCSTATUS_INVALID_HCI_INFORMATION);
2425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
2445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_WI_info = (phHciNfc_WI_Info_t *)
2465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            psHciContext->p_wi_info ;
2475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        switch(WI_seq)
2485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
2495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case RESET_SEQ:
2505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case INIT_SEQ:
2515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                p_WI_info->current_seq = eWI_PipeOpen;
2535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                p_WI_info->next_seq = eWI_SetDefaultMode ;
2545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }break;
2555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case UPDATE_SEQ:
2565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                p_WI_info->current_seq = p_WI_info->next_seq;
2585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }break;
2605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case REL_SEQ:
2615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                p_WI_info->current_seq = eWI_PipeOpen;
2635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                p_WI_info->next_seq = eWI_PipeClose ;
2645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }break;
2655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            default:
2665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
2675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
2685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
2695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/* End of Update Sequence Switch */
2705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
2725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
2745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif /* #if defined (WI_UPDATE_SEQ) */
2755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
2775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Configure_Default(
2785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void                  *psHciHandle,
2795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void                  *pHwRef,
2805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              uint8_t               enable_type
2815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          )
2825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
2835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
2845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    static uint8_t          param = 0;
2855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
2865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
2875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)||(NULL == pHwRef))
2885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
2905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL == psHciContext->p_wi_info )
2925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI,
2945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NFCSTATUS_INVALID_HCI_INFORMATION);
2955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
2965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
2975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
2985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t          *p_wi_info=NULL;
2995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
3005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wi_info = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
3025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_pipe_info = p_wi_info->p_pipe_info;
3045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NULL == p_pipe_info)
3055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI,
3075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFCSTATUS_INVALID_HCI_INFORMATION);
3085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
3105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->reg_index = NXP_SE_DEFAULTMODE_INDEX;
3125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Enable/Disable Default Virtual Mode for SmartMx */
3135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            param = (uint8_t)enable_type;
3145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->param_info =(void*)&param ;
3155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->param_length = sizeof(param) ;
3165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
3175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    p_wi_info->pipe_id,(uint8_t)ANY_SET_PARAMETER);
3185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/* End of else part*/
3205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
3225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
3255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Get_Default(
3265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void                  *psHciHandle,
3275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void                  *pHwRef
3285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              )
3295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
3315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
3325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)||(NULL == pHwRef))
3345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
3365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL == psHciContext->p_wi_info )
3385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI,
3405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFCSTATUS_INVALID_HCI_INFORMATION);
3415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
3435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t          *p_wiinfo=NULL;
3455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
3465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wiinfo = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
3485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_pipe_info = p_wiinfo->p_pipe_info;
3505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NULL == p_pipe_info)
3515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI,
3535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_INVALID_HCI_INFORMATION);
3545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
3555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
3565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->reg_index = NXP_SE_DEFAULTMODE_INDEX;
3585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
3605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            p_wiinfo->pipe_id,
3615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            (uint8_t)ANY_GET_PARAMETER);
3625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/* End of else part*/
3645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
3665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
3675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
3705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Configure_Mode(
3715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void                *psHciHandle,
3725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              void                *pHwRef,
3735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                              phHal_eSmartMX_Mode_t   e_smx_mode
3745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          )
3755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
3765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
3775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    static uint8_t          param = 0;
3785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
3795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)||(NULL == pHwRef))
3815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
3835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL == psHciContext->p_wi_info )
3855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI,
3875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NFCSTATUS_INVALID_HCI_INFORMATION);
3885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
3895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
3905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
3915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t          *p_wi_info=NULL;
3925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
3935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wi_info = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
3955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
3965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_pipe_info = p_wi_info->p_pipe_info;
3975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NULL == p_pipe_info)
3985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
3995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI,
4005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFCSTATUS_INVALID_HCI_INFORMATION);
4015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
4025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
4035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
4045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Switch the Mode of the SmartMx */
4055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            param = (uint8_t)e_smx_mode;
4065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->param_info =(void*)&param ;
4075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->param_length = sizeof(param) ;
4085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Send_WI_Event( psHciContext, pHwRef,
4095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                p_wi_info->pipe_id, NXP_EVT_SE_SWITCH_MODE );
4105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Send the Success Status as this is an event */
4115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = ( (status == NFCSTATUS_PENDING)?
4125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_SUCCESS : status);
4135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }/* End of else part*/
4155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
4175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
4215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_Configure_Notifications(
4225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    void        *psHciHandle,
4235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    void        *pHwRef,
4245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    phHciNfc_WI_Events_t eNotification
4255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                )
4265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
4285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    static uint8_t          param = 0;
4295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
4305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)||(NULL == pHwRef))
4325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
4345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if ( NULL == psHciContext->p_wi_info )
4365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI,
4385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        NFCSTATUS_INVALID_HCI_INFORMATION);
4395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
4415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
4425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t          *p_wi_info=NULL;
4435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
4445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wi_info = (phHciNfc_WI_Info_t*)psHciContext->p_wi_info;
4475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_pipe_info = p_wi_info->p_pipe_info;
4485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if(NULL == p_pipe_info)
4495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
4505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI,
4515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_INVALID_HCI_INFORMATION);
4525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
4535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
4545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
4555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if(eEnableEvents == eNotification)
4565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Enable start and end of transaction events*/
4585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                param = WI_ENABLE_EVENTS;
4595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            else
4615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
4625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* Disable Events*/
4635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                param = FALSE ;
4645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
4655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->reg_index = NXP_SE_EVENTS_INDEX;
4665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->param_info =(void*)&param ;
4675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->param_length = sizeof(param) ;
4685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
4705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_wi_info->pipe_id,(uint8_t)ANY_SET_PARAMETER);
4715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
4725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
4735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
4745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
4755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/*!
4785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \brief Sends WI gate specfic HCI Events to the connected reader device.
4795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* This function Sends the WI mode specific HCI Event frames in the HCP packet format to the
4805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* connected reader device.
4815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly*/
4825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
4845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
4855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Send_WI_Event(
4865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       phHciNfc_sContext_t      *psHciContext,
4875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       void                     *pHwRef,
4885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint8_t                  pipe_id,
4895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint8_t                  event
4905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       )
4915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
4925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
4935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_HCP_Message_t  *hcp_message = NULL;
4945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
4955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 length = 0;
4965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    uint8_t                 i=0;
4975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
4985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
4995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext)
5005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || ( pipe_id > PHHCINFC_MAX_PIPE)
5015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        ||(NULL == psHciContext->p_pipe_list[pipe_id])
5025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        )
5035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
5055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        HCI_DEBUG("%s: Invalid Arguments passed \n",
5065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            "phHciNfc_Send_WI_Event");
5075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
5085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
5095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_pipe_info = (phHciNfc_Pipe_Info_t *)
5115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->p_pipe_list[pipe_id];
5125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        psHciContext->tx_total = 0 ;
5135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        length =length+HCP_HEADER_LEN ;
5145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if( NXP_EVT_SE_SWITCH_MODE == event)
5165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
5185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Construct the HCP Frame */
5195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
5205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                    (uint8_t) pipe_id, HCP_MSG_TYPE_EVENT, event);
5215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            hcp_message = &(hcp_packet->msg.message);
5225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
5235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            i, (uint8_t *)p_pipe_info->param_info,
5245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            p_pipe_info->param_length);
5255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            length =(uint8_t)(length + i + p_pipe_info->param_length);
5265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
5285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INSTRUCTION );
5305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            HCI_DEBUG("%s: Invalid Send Event Request \n","phHciNfc_Send_WI_Event");
5315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if( NFCSTATUS_SUCCESS == status )
5345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT ;
5365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->prev_msg = event ;
5375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            psHciContext->tx_total = length;
5385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            /* Send the Constructed HCP packet to the lower layer */
5405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = phHciNfc_Send_HCP( psHciContext, pHwRef );
5415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            p_pipe_info->prev_status = NFCSTATUS_PENDING;
5425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
5445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
5455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
5465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
5485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
5495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Recv_WI_Response(
5505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          void                *psContext,
5515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          void                *pHwRef,
5525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          uint8_t             *pResponse,
5535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ONE_BYTE_LEN
5545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          uint8_t             length
5555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
5565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          uint16_t            length
5575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
5585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                          )
5595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
5605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
5615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t         *psHciContext =
5625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                (phHciNfc_sContext_t *)psContext;
5635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
5665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (length == 0))
5675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
5695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
5705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(NULL == psHciContext->p_wi_info)
5715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
5735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
5745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
5755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
5765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t     *p_wiinfo=NULL;
5775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uint8_t                 prev_cmd = ANY_GET_PARAMETER;
5785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wiinfo = (phHciNfc_WI_Info_t *)psHciContext->p_wi_info ;
5795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
5805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if( NULL == p_wiinfo->p_pipe_info)
5815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            status = PHNFCSTVAL(CID_NFC_HCI,
5835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                NFCSTATUS_INVALID_HCI_INFORMATION);
5845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
5855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        else
5865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
5875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            prev_cmd = p_wiinfo->p_pipe_info->prev_msg ;
5885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            switch(prev_cmd)
5895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
5905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case ANY_GET_PARAMETER:
5915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
5925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    if (length > HCP_HEADER_LEN)
5935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
5945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        status = phHciNfc_WI_InfoUpdate (psHciContext,
5955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        p_wiinfo->p_pipe_info->reg_index,
5965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        &pResponse[HCP_HEADER_LEN],
5975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                        (uint8_t)(length - HCP_HEADER_LEN));
5985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
5995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    else
6005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    {
6015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                        status = PHNFCSTVAL(CID_NFC_HCI,
6025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                            NFCSTATUS_INVALID_HCI_RESPONSE);
6035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    }
6045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case ANY_SET_PARAMETER:
6075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    HCI_PRINT("WI Parameter Set \n");
6095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
6105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                        UPDATE_SEQ);
6115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case ANY_OPEN_PIPE:
6145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    HCI_PRINT("WI gate open pipe complete\n");
6165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
6175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                        UPDATE_SEQ);
6185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                case ANY_CLOSE_PIPE:
6215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    HCI_PRINT("WI close pipe complete\n");
6235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = phHciNfc_EmuMgmt_Update_Seq(psHciContext,
6245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                                        UPDATE_SEQ);
6255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                default:
6285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
6295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
6305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    break;
6315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
6325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            if( NFCSTATUS_SUCCESS == status )
6345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                p_wiinfo->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
6365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                p_wiinfo->current_seq = p_wiinfo->next_seq;
6375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
6395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
6415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
6425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
6445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
6455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_Recv_WI_Event(
6465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       void               *psContext,
6475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       void               *pHwRef,
6485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint8_t            *pEvent,
6495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ONE_BYTE_LEN
6505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint8_t             length
6515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else
6525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint16_t            length
6535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif
6545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       )
6555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
6565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
6575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHal_sEventInfo_t          EventInfo;
6585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    /* phNfc_sNotificationInfo_t   NotificationInfo; */
6595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_sContext_t         *psHciContext =(phHciNfc_sContext_t *)psContext;
6605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
6635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        || (length == 0))
6645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
6665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else if(NULL == psHciContext->p_wi_info)
6685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
6705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
6715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
6725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
6735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_HCP_Packet_t       *p_packet = NULL;
6745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_HCP_Message_t      *message = NULL;
6755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        phHciNfc_WI_Info_t          *p_wi_info = NULL;
6765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        uint8_t                     EventType = 0;
6775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wi_info = (phHciNfc_WI_Info_t *)psHciContext->p_wi_info ;
6795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
6815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        message = &(p_packet->msg.message);
6825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Get the instruction bits from the Message Header */
6835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        EventType = (uint8_t) GET_BITS8( message->msg_header,
6845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
6855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
6865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        EventInfo.eventHost = phHal_eHostController;
6875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        EventInfo.eventSource = phHal_ePICC_DevType;
6885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        /* Now check for possible Transaction events for reporting */
6895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        switch(EventType)
6905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
6915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case NXP_EVT_SE_START_OF_TRANSACTION:
6925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                EventInfo.eventType = NFC_EVT_START_OF_TRANSACTION;
6945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
6955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
6965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case NXP_EVT_SE_END_OF_TRANSACTION:
6975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
6985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                EventInfo.eventType = NFC_EVT_END_OF_TRANSACTION;
6995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
7005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            case NXP_EVT_SE_TRANSACTION:
7025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                EventInfo.eventType = NFC_EVT_TRANSACTION;
7045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                EventInfo.eventInfo.aid.buffer = (uint8_t *)p_wi_info->aid;
7055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                /* check for AID data is at least 1 byte is their */
706967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                if (length > HCP_HEADER_LEN)
7075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                {
7085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                    EventInfo.eventInfo.aid.length = length - HCP_HEADER_LEN;
709967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    memcpy((void *)p_wi_info->aid, message->payload,
710967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                           EventInfo.eventInfo.aid.length );
711967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                }
712967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas
713967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                /* Filter Transaction event */
714967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                if (EventInfo.eventInfo.aid.length == 4)
715967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                {
716967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    EventInfo.eventType = NFC_EVT_APDU_RECEIVED;
717967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                }
718967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                else if (EventInfo.eventInfo.aid.length == 2)
719967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                {
720967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    if (!memcmp(paypass_removal, EventInfo.eventInfo.aid.buffer, EventInfo.eventInfo.aid.length))
721967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    {
722967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                        EventInfo.eventType = NFC_EVT_EMV_CARD_REMOVAL;
723967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    }
724967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    else if(mifare_access == EventInfo.eventInfo.aid.buffer[0])
725967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    {
726967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                        EventInfo.eventType = NFC_EVT_MIFARE_ACCESS;
727967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                    }
7285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                }
729967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas
730967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                EventInfo.eventInfo.aid.buffer = (uint8_t *)p_wi_info->aid;
731967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                (void) memcpy((void *)p_wi_info->aid,message->payload,
732967359c892ff74962b4f4243d989f447ffe4ae11Daniel Tomas                                EventInfo.eventInfo.aid.length );
7335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
7345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            default:
7365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            {
7375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                status = PHNFCSTVAL(CID_NFC_HCI,
7385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                                NFCSTATUS_INVALID_HCI_INSTRUCTION);
7395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                break;
7405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            }
7415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        if (NFCSTATUS_SUCCESS == status )
7435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        {
7445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            phHciNfc_Notify_Event(  psHciContext, pHwRef,
7455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly            NFC_NOTIFY_EVENT, (void*)&EventInfo);
7465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        }
7475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
7495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellystatic
7525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyNFCSTATUS
7535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick PellyphHciNfc_WI_InfoUpdate(
7545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       phHciNfc_sContext_t     *psHciContext,
7555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint8_t                 index,
7565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint8_t                 *reg_value,
7575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       uint8_t                 reg_length
7585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                       )
7595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{
7605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    NFCSTATUS               status = NFCSTATUS_SUCCESS;
7615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    phHciNfc_WI_Info_t      *p_wiinfo = NULL;
7625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    p_wiinfo = psHciContext->p_wi_info;
7645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    if ((NXP_SE_DEFAULTMODE_INDEX == index) &&
7665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        (sizeof(*reg_value) == reg_length))
7675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
7685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        p_wiinfo->default_type = *reg_value;
7695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    else
7715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    {
7725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly        status = PHNFCSTVAL(CID_NFC_HCI,
7735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly                            NFCSTATUS_INVALID_HCI_RESPONSE);
7745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    }
7755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
7765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly    return status;
7775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly}
7785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly
779