/*
 * Copyright (C) 2010 NXP Semiconductors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*!
* =========================================================================== *
*                                                                             *
*                                                                             *
* \file  phHciNfc_RFReaderA.c                                                 *
* \brief HCI Reader A Management Routines.                                    *
*                                                                             *
*                                                                             *
* Project: NFC-FRI-1.1                                                        *
*                                                                             *
* $Date: Wed Feb 17 16:19:04 2010 $                                           *
* $Author: ing02260 $                                                         *
* $Revision: 1.57 $                                                           *
* $Aliases: 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 $
*                                                                             *
* =========================================================================== *
*/

/*
***************************** Header File Inclusion ****************************
*/
#include <phNfcCompId.h>
#include <phHciNfc_Pipe.h>
#include <phHciNfc_RFReader.h>
#include <phHciNfc_RFReaderA.h>
#include <phOsalNfc.h>
/*
****************************** Macro Definitions *******************************
*/

/* Registry used for getting the data */
#define RDR_A_DATA_RATE_MAX_INDEX           0x01U
#define RDR_A_UID_INDEX                     0x02U
#define RDR_A_SAK_INDEX                     0x03U
#define RDR_A_ATQA_INDEX                    0x04U
#define RDR_A_APP_DATA_INDEX                0x05U
#define RDR_A_FWI_SFGT_INDEX                0x06U

/* Registry index for auto activation */
#define NXP_AUTO_ACTIVATION_INDEX           0x10U

#define RDR_A_SAK_FWI_SFGT_LENGTH           0x01U

#define RDR_A_SINGLE_TAG_FOUND              0x00U
#define RDR_A_MULTIPLE_TAGS_FOUND           0x03U

#define RDR_A_MAX_APP_DATA_LEN              0x30U

/* Time out */
#define RDR_A_MIFARE_STATUS                 0x00U

#define RDR_A_MIFARE_RAW_LENGTH             0x03U

/*
*************************** Structure and Enumeration ***************************
*/


/*
*************************** Static Function Declaration **************************
*/

static 
NFCSTATUS
phHciNfc_Recv_ReaderA_Response(
                        void                *psContext,
                        void                *pHwRef,
                        uint8_t             *pResponse,
#ifdef ONE_BYTE_LEN
                        uint8_t             length
#else
                        uint16_t            length
#endif
                       );

static
NFCSTATUS
phHciNfc_Recv_ReaderA_Event(
                             void               *psContext,
                             void               *pHwRef,
                             uint8_t            *pEvent,
#ifdef ONE_BYTE_LEN
                             uint8_t            length
#else
                             uint16_t           length
#endif
                       );

static
NFCSTATUS
phHciNfc_ReaderA_InfoUpdate(
                            phHciNfc_sContext_t     *psHciContext,
                            uint8_t                 index,
                            uint8_t                 *reg_value,
                            uint8_t                 reg_length
                         );

static
NFCSTATUS
phHciNfc_Recv_Mifare_Packet(
                            phHciNfc_sContext_t *psHciContext,
                            uint8_t             cmd,
                            uint8_t             *pResponse,
#ifdef ONE_BYTE_LEN
                            uint8_t             length
#else
                            uint16_t            length
#endif
                            );

static
NFCSTATUS
phHciNfc_Recv_Iso_A_Packet(
                           phHciNfc_sContext_t  *psHciContext,
                           uint8_t              *pResponse,
#ifdef ONE_BYTE_LEN
                            uint8_t             length
#else
                            uint16_t            length
#endif
                           );
/*
*************************** Function Definitions ***************************
*/
NFCSTATUS
phHciNfc_ReaderA_Get_PipeID(
                             phHciNfc_sContext_t        *psHciContext,
                             uint8_t                    *ppipe_id
                             )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;

    if( (NULL != psHciContext)
        && ( NULL != ppipe_id )
        && ( NULL != psHciContext->p_reader_a_info ) 
        )
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
            psHciContext->p_reader_a_info ;
        *ppipe_id =  p_rdr_a_info->pipe_id  ;
    }
    else 
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    return status;
}


NFCSTATUS
phHciNfc_ReaderA_Init_Resources(
                                phHciNfc_sContext_t     *psHciContext
                         )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    if( NULL == psHciContext )
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else
    {
        if(
            ( NULL == psHciContext->p_reader_a_info ) &&
             (phHciNfc_Allocate_Resource((void **)(&p_rdr_a_info),
            sizeof(phHciNfc_ReaderA_Info_t))== NFCSTATUS_SUCCESS)
          )
        {
            psHciContext->p_reader_a_info = p_rdr_a_info;
            p_rdr_a_info->current_seq = RDR_A_INVALID_SEQ;
            p_rdr_a_info->next_seq = RDR_A_INVALID_SEQ;
            p_rdr_a_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
        }
        else
        {
            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
        }
        
    }
    return status;
}

NFCSTATUS
phHciNfc_ReaderA_Update_PipeInfo(
                                  phHciNfc_sContext_t     *psHciContext,
                                  uint8_t                 pipeID,
                                  phHciNfc_Pipe_Info_t    *pPipeInfo
                                  )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;

    if( NULL == psHciContext )
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if(NULL == psHciContext->p_reader_a_info)
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_ReaderA_Info_t *p_rdr_a_info=NULL;
        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                                psHciContext->p_reader_a_info ;
        /* Update the pipe_id of the reader A Gate obtained from the HCI Response */
        p_rdr_a_info->pipe_id = pipeID;
        p_rdr_a_info->p_pipe_info = pPipeInfo;
        if (NULL != pPipeInfo)
        {
            /* Update the Response Receive routine of the reader A Gate */
            pPipeInfo->recv_resp = &phHciNfc_Recv_ReaderA_Response;
            /* Update the event Receive routine of the reader A Gate */
            pPipeInfo->recv_event = &phHciNfc_Recv_ReaderA_Event;
        }
    }

    return status;
}

NFCSTATUS
phHciNfc_ReaderA_Info_Sequence (
                       void             *psHciHandle,
                       void             *pHwRef
                       )
{
    NFCSTATUS               status = NFCSTATUS_SUCCESS;
    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);

    HCI_PRINT ("HCI : phHciNfc_ReaderA_Info_Sequence called... \n");
    if( (NULL == psHciContext) 
        || (NULL == pHwRef)
      )
    {
      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }   
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
        uint8_t                     pipeid = 0;
        
        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                                psHciContext->p_reader_a_info ;
        p_pipe_info = p_rdr_a_info->p_pipe_info;
        if(NULL == p_pipe_info )
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                            NFCSTATUS_INVALID_HCI_SEQUENCE);
        }
        else
        {
            HCI_DEBUG ("HCI : p_rdr_a_info->current_seq : %02X\n", p_rdr_a_info->current_seq);
            switch(p_rdr_a_info->current_seq)
            {
                case RDR_A_UID:
                {
                    p_pipe_info->reg_index = RDR_A_UID_INDEX;
                    pipeid = p_rdr_a_info->pipe_id ;
                    /* Fill the data buffer and send the command to the 
                            device */
                    status = 
                        phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 
                        pipeid, (uint8_t)ANY_GET_PARAMETER);
                    if(NFCSTATUS_PENDING == status )
                    {
                        p_rdr_a_info->next_seq = RDR_A_SAK;
                    }
                    break;
                }
                case RDR_A_SAK:
                {
                    p_pipe_info->reg_index = RDR_A_SAK_INDEX;
                    pipeid = p_rdr_a_info->pipe_id ;
                    /* Fill the data buffer and send the command to the 
                            device */
                    status = 
                        phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 
                        pipeid, (uint8_t)ANY_GET_PARAMETER);
                    if(NFCSTATUS_PENDING == status )
                    {
                        p_rdr_a_info->next_seq = RDR_A_ATQA;
                    }
                    break;
                }
                case RDR_A_ATQA:
                {
                    p_pipe_info->reg_index = RDR_A_ATQA_INDEX;
                    pipeid = p_rdr_a_info->pipe_id ;
                    /* Fill the data buffer and send the command to the 
                            device */
                    status = 
                        phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 
                        pipeid, (uint8_t)ANY_GET_PARAMETER);
                    if(NFCSTATUS_PENDING == status )
                    {
                        p_rdr_a_info->next_seq = RDR_A_END_SEQUENCE;
                    }
                    break;
                }
                case RDR_A_END_SEQUENCE:
                {
                    phNfc_sCompletionInfo_t     CompInfo;
                    if (RDR_A_MULTIPLE_TAGS_FOUND == 
                        p_rdr_a_info->multiple_tgts_found)
                    {
                        CompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
                    }
                    else
                    {
                        CompInfo.status = NFCSTATUS_SUCCESS;
                    }
                    
                    CompInfo.info = &(p_rdr_a_info->reader_a_info);

                    p_rdr_a_info->reader_a_info.RemDevType = phHal_eISO14443_A_PICC;
                    p_rdr_a_info->current_seq = RDR_A_UID;
                    p_rdr_a_info->next_seq = RDR_A_UID;
                    status = NFCSTATUS_SUCCESS;
                    HCI_DEBUG ("HCI : p_rdr_a_info->reader_a_info.RemDevType : %02X\n", p_rdr_a_info->reader_a_info.RemDevType);
                    HCI_DEBUG ("HCI : status notified: %02X\n", CompInfo.status);
                    /* Notify to the upper layer */
                    phHciNfc_Tag_Notify(psHciContext, 
                        pHwRef, 
                        NFC_NOTIFY_TARGET_DISCOVERED, 
                        &CompInfo);
                    break;
                }
                default:
                {
                    status = PHNFCSTVAL(CID_NFC_HCI, 
                                    NFCSTATUS_INVALID_HCI_RESPONSE);
                    break;
                }
            }
            HCI_DEBUG ("HCI : p_rdr_a_info->current_seq after : %02X\n", p_rdr_a_info->current_seq);
            HCI_DEBUG ("HCI : p_rdr_a_info->next_seq : %02X\n", p_rdr_a_info->next_seq);
        }
    }

    HCI_PRINT ("HCI : phHciNfc_ReaderA_Info_Sequence end \n");
    return status;
}


static
NFCSTATUS
phHciNfc_ReaderA_InfoUpdate(
                                phHciNfc_sContext_t     *psHciContext,
                                uint8_t                 index,
                                uint8_t                 *reg_value,
                                uint8_t                 reg_length
                         )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    phHal_sIso14443AInfo_t        *p_tag_a_info = NULL;
                                
    p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                                (psHciContext->p_reader_a_info );
    p_tag_a_info = &(p_rdr_a_info->reader_a_info.RemoteDevInfo.Iso14443A_Info);
    
    switch(index)
    {
        case RDR_A_UID_INDEX:
        {
            /* Maximum UID length can go upto 10 bytes */
            if (reg_length <= PHHAL_MAX_UID_LENGTH)
            {
                HCI_PRINT_BUFFER("\tReader A UID", reg_value, reg_length);
                /* Update UID buffer and length */
                p_tag_a_info->UidLength = reg_length;
                (void)memcpy(
                        p_tag_a_info->Uid, 
                        reg_value, 
                        p_tag_a_info->UidLength);
            } 
            else
            {
                status = PHNFCSTVAL(CID_NFC_HCI, 
                    NFCSTATUS_INVALID_HCI_RESPONSE);
            }
            break;
        }
        case RDR_A_SAK_INDEX:
        {
            /* SAK length is 1 byte */
            if (RDR_A_SAK_FWI_SFGT_LENGTH == reg_length)
            {
                HCI_PRINT_BUFFER("\tReader A SAK", reg_value, reg_length);
                /* Copy SAK byte */
                p_tag_a_info->Sak = *reg_value;
            } 
            else
            {
                status = PHNFCSTVAL(CID_NFC_HCI, 
                    NFCSTATUS_INVALID_HCI_RESPONSE);
            }
            break;
        }
        case RDR_A_ATQA_INDEX:
        {
            /* ATQA length shall be 2 bytes */
            if (PHHAL_ATQA_LENGTH == reg_length)
            {
                HCI_PRINT_BUFFER("\tReader A ATQA", reg_value, reg_length);
                /* Copy ATQA */
                (void)memcpy(p_tag_a_info->AtqA,
                    reg_value, 
                    reg_length);
            } 
            else
            {
                status = PHNFCSTVAL(CID_NFC_HCI, 
                    NFCSTATUS_INVALID_HCI_RESPONSE);
            }
            break;
        }
        case RDR_A_APP_DATA_INDEX:
        {
            /* Remote device info provided by the user */
            p_tag_a_info = 
                    &(psHciContext->p_target_info->RemoteDevInfo.Iso14443A_Info);
            /* Historical bytes length shall be 2 bytes */
            if (reg_length <= RDR_A_MAX_APP_DATA_LEN)
            {
                HCI_PRINT_BUFFER("\tReader A APP DATA", reg_value, reg_length);
                p_tag_a_info->AppDataLength = reg_length;
                /* Historical bytes */
                (void)memcpy(p_tag_a_info->AppData, 
                    reg_value, 
                    reg_length);
            } 
            else
            {
                status = PHNFCSTVAL(CID_NFC_HCI, 
                    NFCSTATUS_INVALID_HCI_RESPONSE);
            }
            break;
        }
        case RDR_A_FWI_SFGT_INDEX:
        {
            if (RDR_A_SAK_FWI_SFGT_LENGTH == reg_length)
            {
                HCI_PRINT_BUFFER("\tReader A FWI SFGT", reg_value, reg_length);
                p_tag_a_info->Fwi_Sfgt = *reg_value;
            } 
            else
            {
                status = PHNFCSTVAL(CID_NFC_HCI, 
                    NFCSTATUS_INVALID_HCI_RESPONSE);
            }
            break;
        }
        default:
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                            NFCSTATUS_INVALID_HCI_RESPONSE);
            break;
        }
    }
    return status;
}


static 
NFCSTATUS
phHciNfc_Recv_ReaderA_Response(
                        void                *psContext,
                        void                *pHwRef,
                        uint8_t             *pResponse,
#ifdef ONE_BYTE_LEN
                        uint8_t             length
#else
                        uint16_t            length
#endif
                       )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    phHciNfc_sContext_t         *psHciContext = 
                                (phHciNfc_sContext_t *)psContext ;
    

    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
        || (length == 0))
    {
      status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if(NULL == psHciContext->p_reader_a_info)
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        uint8_t                     prev_cmd = ANY_GET_PARAMETER;
        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                            psHciContext->p_reader_a_info ;
        if( NULL == p_rdr_a_info->p_pipe_info)
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                            NFCSTATUS_INVALID_HCI_SEQUENCE);
        }
        else
        {
            prev_cmd = p_rdr_a_info->p_pipe_info->prev_msg ;
            switch(prev_cmd)
            {
                case ANY_GET_PARAMETER:
                {
                    status = phHciNfc_ReaderA_InfoUpdate(psHciContext,
                                    p_rdr_a_info->p_pipe_info->reg_index, 
                                    &pResponse[HCP_HEADER_LEN],
                                    (uint8_t)(length - HCP_HEADER_LEN));
#if 0
                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext, 
                                                                UPDATE_SEQ);
#endif
                    break;
                }
                case ANY_SET_PARAMETER:
                {
                    HCI_PRINT("Reader A Parameter Set \n");
                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext, 
                                                    UPDATE_SEQ);
                    p_rdr_a_info->next_seq = RDR_A_UID;
                    break;
                }
                case ANY_OPEN_PIPE:
                {
                    HCI_PRINT("Reader A open pipe complete\n");
                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext, 
                                                    UPDATE_SEQ);
                    p_rdr_a_info->next_seq = RDR_A_UID;
                    break;
                }
                case ANY_CLOSE_PIPE:
                {
                    HCI_PRINT("Reader A close pipe complete\n");
                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext, 
                                                    UPDATE_SEQ);
                    break;
                }
                case NXP_WRA_CONTINUE_ACTIVATION:
                case NXP_WR_ACTIVATE_ID:
                {
                    HCI_PRINT("Reader A continue activation or ");
                    HCI_PRINT("reactivation completed \n");
                    status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext, 
                                                    UPDATE_SEQ);
                    break;
                }
                case NXP_MIFARE_RAW:
                case NXP_MIFARE_CMD:
                {
                    if (length > HCP_HEADER_LEN)
                    {
                        HCI_PRINT("Mifare packet received \n");
                        /* Copy buffer to the receive buffer */
                        phHciNfc_Append_HCPFrame(psHciContext->recv_buffer, 
                            0, pResponse, length);
                        psHciContext->rx_total = length;
                        status = phHciNfc_Recv_Mifare_Packet(psHciContext, 
                                                prev_cmd, 
                                                &pResponse[HCP_HEADER_LEN],
                                                (length - HCP_HEADER_LEN));

                    } 
                    else if (length == HCP_HEADER_LEN)
                    {
                        psHciContext->rx_total = length;
                        psHciContext->rx_index = HCP_HEADER_LEN;

                    }
                    else
                    {
                        status = PHNFCSTVAL(CID_NFC_HCI, 
                                        NFCSTATUS_INVALID_HCI_RESPONSE);
                    }
                    break;
                }
                case WR_XCHGDATA:
                {
                    if (length >= HCP_HEADER_LEN)
                    {
                        uint8_t         i = 1;
                        HCI_PRINT("ISO 14443-4A received \n");
                        /* Copy buffer to the receive buffer */
                        phHciNfc_Append_HCPFrame(psHciContext->recv_buffer, 
                            0, pResponse, (length - i));
                        psHciContext->rx_total = (length - i);
                        status = phHciNfc_Recv_Iso_A_Packet(psHciContext, 
                                                    &pResponse[HCP_HEADER_LEN],
                                                    (length - HCP_HEADER_LEN));
                    } 
                    else
                    {
                        status = PHNFCSTVAL(CID_NFC_HCI, 
                                            NFCSTATUS_INVALID_HCI_RESPONSE);
                    }
                    break;
                }
                case NXP_WR_PRESCHECK:
                {
                    HCI_PRINT("Presence check completed \n");
                    break;
                }
                case NXP_WR_ACTIVATE_NEXT:
                {
                    if (length > HCP_HEADER_LEN)
                    {
                        if (RDR_A_MULTIPLE_TAGS_FOUND == pResponse[HCP_HEADER_LEN])
                        {
                            p_rdr_a_info->multiple_tgts_found = 
                                RDR_A_MULTIPLE_TAGS_FOUND;
                        }
                        else
                        {
                            p_rdr_a_info->multiple_tgts_found = FALSE;
                        }
                        HCI_PRINT("Activate next completed \n");
                    }
                    else
                    {
                        status = PHNFCSTVAL(CID_NFC_HCI, 
                                        NFCSTATUS_INVALID_HCI_RESPONSE);
                    }
                    break;
                }
                case NXP_WR_DISPATCH_TO_UICC:
                {
                    switch(length)
                    {
                        case HCP_HEADER_LEN:
                        {
                            /* Optional error code, if no error code field 
                                in the response, then this command is 
                                successfully completed */
                            p_rdr_a_info->uicc_activation = 
                                    UICC_CARD_ACTIVATION_SUCCESS;
                            break;
                        }
                        case (HCP_HEADER_LEN + 1):
                        {
                            p_rdr_a_info->uicc_activation = 
                                        pResponse[HCP_HEADER_LEN];
                            break;
                        } /* End of case (HCP_HEADER_LEN + index) */
                        default:
                        {                            
                            status = PHNFCSTVAL(CID_NFC_HCI, 
                                                NFCSTATUS_INVALID_HCI_RESPONSE);
                            break;
                        }
                    } /* End of switch(length) */
                    if (NFCSTATUS_SUCCESS == status)
                    {
                        status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext, 
                                                                    UPDATE_SEQ);
                    }
                    break;
                }
                default:
                {
                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
                    break;
                }
            } /* End of switch(prev_cmd) */
            if( NFCSTATUS_SUCCESS == status )
            {
                p_rdr_a_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
                p_rdr_a_info->current_seq = p_rdr_a_info->next_seq;
            }
        }
    }
    return status;
}

static
NFCSTATUS
phHciNfc_Recv_Iso_A_Packet(
                            phHciNfc_sContext_t *psHciContext,
                            uint8_t             *pResponse,
#ifdef ONE_BYTE_LEN
                            uint8_t             length
#else
                            uint16_t            length
#endif
                            )
{
    NFCSTATUS       status = NFCSTATUS_SUCCESS;
    uint8_t         i = 1;
    
    psHciContext->rx_index = HCP_HEADER_LEN;
    /* command WRA_XCHG_DATA: so give ISO 14443-4A data to the upper layer */
    if(FALSE != pResponse[(length - i)])
    {
        status = PHNFCSTVAL(CID_NFC_HCI, 
                            NFCSTATUS_RF_ERROR);
    }
    HCI_PRINT_BUFFER("ISO 14443- 4A Bytes received", pResponse, length);
    
    return status;
}

static
NFCSTATUS
phHciNfc_Recv_Mifare_Packet(
                           phHciNfc_sContext_t  *psHciContext,
                           uint8_t              cmd,
                           uint8_t              *pResponse,
#ifdef ONE_BYTE_LEN
                           uint8_t              length
#else
                           uint16_t             length
#endif
                           )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;

    /* To remove "warning (VS C4100) : unreferenced formal parameter" */
    PHNFC_UNUSED_VARIABLE(pResponse);
    PHNFC_UNUSED_VARIABLE(length);
    
    if (NXP_MIFARE_RAW == cmd)
    {
#ifdef ENABLE_MIFARE_RAW
        uint8_t                 index = 0;
#ifndef HAL_SW_3A_STATUS
        if(phHal_eISO14443_3A_PICC == psHciContext->p_target_info->RemDevType)
        {
            index++;
            psHciContext->rx_index = (index + HCP_HEADER_LEN);
            HCI_PRINT_BUFFER("Mifare Bytes received", &pResponse[index], (length - index));
        }
        else
#endif
        if (RDR_A_MIFARE_STATUS == pResponse[index])  /* Status byte */
        {
            index++;
            psHciContext->rx_index = (index + HCP_HEADER_LEN);
            HCI_PRINT_BUFFER("Mifare Bytes received", &pResponse[index], (length - index));
        }
        else
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                                NFCSTATUS_INVALID_HCI_RESPONSE);
        }
#else
        psHciContext->rx_index = HCP_HEADER_LEN;
        /* Give Mifare data to the upper layer */
        HCI_PRINT_BUFFER("Mifare Bytes received", pResponse, length);        
#endif /* #ifdef ENABLE_MIFARE_RAW */
    } 
    else
    {
        psHciContext->rx_index = HCP_HEADER_LEN;
        /* command NXP_MIFARE_CMD: so give Mifare data to the upper layer */
        HCI_PRINT_BUFFER("Mifare Bytes received", pResponse, length);
    }
    
    return status;
}

static
NFCSTATUS
phHciNfc_Recv_ReaderA_Event(
                             void               *psContext,
                             void               *pHwRef,
                             uint8_t            *pEvent,
#ifdef ONE_BYTE_LEN
                             uint8_t            length
#else
                             uint16_t           length
#endif
                       )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    phHciNfc_sContext_t         *psHciContext = 
                                (phHciNfc_sContext_t *)psContext ;

    HCI_PRINT ("HCI : phHciNfc_Recv_ReaderA_Event called...\n");
    if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
        || (length == 0))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_HCP_Packet_t       *p_packet = NULL;
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        phHciNfc_HCP_Message_t      *message = NULL;
        uint8_t                     instruction=0, 
                                    i = 0;

        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                        psHciContext->p_reader_a_info ;
        p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
        message = &p_packet->msg.message;
        /* Get the instruction bits from the Message Header */
        instruction = (uint8_t) GET_BITS8( message->msg_header,
            HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);

        HCI_DEBUG ("HCI : instruction : %02X\n", instruction);
        HCI_DEBUG ("HCI : Multiple tag found : %02X\n", message->payload[i]);

        if ((EVT_TARGET_DISCOVERED == instruction) 
            && ((RDR_A_MULTIPLE_TAGS_FOUND == message->payload[i] ) 
                || (RDR_A_SINGLE_TAG_FOUND == message->payload[i])) 
          )
        {
            phNfc_sCompletionInfo_t pCompInfo;

            if (RDR_A_MULTIPLE_TAGS_FOUND == message->payload[i])
            {
                p_rdr_a_info->multiple_tgts_found = RDR_A_MULTIPLE_TAGS_FOUND;
                pCompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
            }
            else
            {
                p_rdr_a_info->multiple_tgts_found = FALSE;
                pCompInfo.status = NFCSTATUS_SUCCESS;
            }
            
            psHciContext->host_rf_type = phHal_eISO14443_A_PCD;
            p_rdr_a_info->reader_a_info.RemDevType = phHal_eISO14443_A_PICC;
            p_rdr_a_info->current_seq = RDR_A_UID;

            HCI_DEBUG ("HCI : psHciContext->host_rf_type : %02X\n", psHciContext->host_rf_type);
            HCI_DEBUG ("HCI : p_rdr_a_info->reader_a_info.RemDevType : %02X\n", p_rdr_a_info->reader_a_info.RemDevType);
            HCI_DEBUG ("HCI : p_rdr_a_info->current_seq : %02X\n", p_rdr_a_info->current_seq);

            /* Notify to the HCI Generic layer To Update the FSM */
            phHciNfc_Notify_Event(psHciContext, pHwRef, 
                                    NFC_NOTIFY_TARGET_DISCOVERED, 
                                    &pCompInfo);

        }
        else
        {
            status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
        }
    }
    HCI_PRINT ("HCI : phHciNfc_Recv_ReaderA_Event end\n");
    return status;
}

NFCSTATUS
phHciNfc_ReaderA_Auto_Activate(
                               void         *psContext,
                               void         *pHwRef,
                               uint8_t      activate_enable
                               )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    phHciNfc_sContext_t         *psHciContext = 
                                (phHciNfc_sContext_t *)psContext ;
    if( (NULL == psHciContext) || (NULL == pHwRef))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
        uint8_t                     pipeid = 0;

        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                                psHciContext->p_reader_a_info ;
        p_pipe_info = p_rdr_a_info->p_pipe_info;
        p_pipe_info->reg_index = NXP_AUTO_ACTIVATION_INDEX;
        p_pipe_info->param_info = &activate_enable;
        p_pipe_info->param_length = sizeof(activate_enable);
        pipeid = p_rdr_a_info->pipe_id ;
        status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 
                pipeid, (uint8_t)ANY_SET_PARAMETER);
        if(NFCSTATUS_PENDING == status )
        {
            status = NFCSTATUS_SUCCESS;
        }
    }
    return status;
}

NFCSTATUS
phHciNfc_ReaderA_Set_DataRateMax(
                               void         *psContext,
                               void         *pHwRef,
                               uint8_t      data_rate_value
                               )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    phHciNfc_sContext_t         *psHciContext = 
        (phHciNfc_sContext_t *)psContext ;
    if( (NULL == psHciContext) || (NULL == pHwRef))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
        uint8_t                     pipeid = 0;

        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                            psHciContext->p_reader_a_info ;
        p_pipe_info = p_rdr_a_info->p_pipe_info;
        p_pipe_info->reg_index = RDR_A_DATA_RATE_MAX_INDEX;
        p_pipe_info->param_info = &data_rate_value;
        p_pipe_info->param_length = sizeof(data_rate_value);
        pipeid = p_rdr_a_info->pipe_id ;
        status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 
                                    pipeid, (uint8_t)ANY_SET_PARAMETER);
    }
    return status;
}


NFCSTATUS
phHciNfc_Send_ReaderA_Command(
                              phHciNfc_sContext_t   *psHciContext,
                              void                  *pHwRef,
                              uint8_t               pipe_id,
                              uint8_t               cmd
                              )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    
    if( (NULL == psHciContext) || (NULL == pHwRef) )
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate) || 
        (HCI_UNKNOWN_PIPE_ID == 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        pipe_id) || 
        (pipe_id != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        pipe_id))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
        phHciNfc_HCP_Packet_t       *hcp_packet = NULL;
        phHciNfc_HCP_Message_t      *hcp_message = NULL;
        uint8_t                     i = 0;
        uint16_t                    length = HCP_HEADER_LEN;
        
        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                            psHciContext->p_reader_a_info ;
        p_pipe_info = p_rdr_a_info->p_pipe_info;
        if(NULL == p_pipe_info )
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                        NFCSTATUS_INVALID_HCI_SEQUENCE);
        }
        else
        {
            psHciContext->tx_total = 0 ;
            hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
            /* Construct the HCP Frame */
            switch(cmd)
            {
                case NXP_WRA_CONTINUE_ACTIVATION:
                case NXP_WR_ACTIVATE_ID:
                {
                    phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
                        (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
                    break;
                }

                case NXP_MIFARE_RAW:
                {
                    if (p_pipe_info->param_length < RDR_A_MIFARE_RAW_LENGTH) 
                    {
                        status = PHNFCSTVAL(CID_NFC_HCI, 
                                            NFCSTATUS_INVALID_PARAMETER);
                    }
                    else
                    {
                        /*  
                            Buffer shall be updated with 
                            TO -              Time out (1 byte)
                            Status -          b0 to b2 indicate valid bits (1 byte)
                            Data (with CRC) - params received from this function 
                        */
                        hcp_message = &(hcp_packet->msg.message);
#ifdef ENABLE_MIFARE_RAW
                        /* Time out */
                        hcp_message->payload[i++] = NXP_MIFARE_XCHG_TIMEOUT ;
                        /* Status */
                        hcp_message->payload[i++] = RDR_A_MIFARE_STATUS;
#else
                        cmd = NXP_MIFARE_CMD;
#endif /* #ifdef ENABLE_MIFARE_RAW */
                        phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
                            (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);

                        phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
                            i, (uint8_t *)p_pipe_info->param_info,
#ifdef ENABLE_MIFARE_RAW
                            p_pipe_info->param_length);
#else
                            (p_pipe_info->param_length - 2));
#endif /* #ifdef ENABLE_MIFARE_RAW */

#ifdef ENABLE_MIFARE_RAW
                        length =(uint16_t)(length + i + p_pipe_info->param_length);
#else
                        length =(uint16_t)(length + i + p_pipe_info->param_length - 2);
#endif /* #ifdef ENABLE_MIFARE_RAW */
                    }
                    break;
                }
                case NXP_MIFARE_CMD:
                {
                    /* 
                        Buffer shall be updated with 
                        Cmd -               Authentication A/B, read/write 
                                            (1 byte)
                        Addr -              Address associated with Mifare cmd
                                            (1 byte)
                        Data  -             params received from this function 
                    */
                    phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
                                (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
                    hcp_message = &(hcp_packet->msg.message);

                    /* Command */
                    hcp_message->payload[i++] = 
                                   psHciContext->p_xchg_info->params.tag_info.cmd_type ;
                     /* Address */
                    hcp_message->payload[i++] = 
                                    psHciContext->p_xchg_info->params.tag_info.addr ;
                    phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
                        i, (uint8_t *)p_pipe_info->param_info,
                        p_pipe_info->param_length);
                    length =(uint16_t)(length + i + p_pipe_info->param_length);
                    break;
                }
                default:
                {
                    status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_COMMAND);
                    break;
                }
            }
            if (NFCSTATUS_SUCCESS == status)
            {
                p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND;
                p_pipe_info->prev_msg = cmd;
                psHciContext->tx_total = length;
                psHciContext->response_pending = TRUE;

                /* Send the Constructed HCP packet to the lower layer */
                status = phHciNfc_Send_HCP( psHciContext, pHwRef);
                p_pipe_info->prev_status = status;
            }
        }
    }
    return status;
}

NFCSTATUS
phHciNfc_ReaderA_Cont_Activate (
                              phHciNfc_sContext_t       *psHciContext,
                              void                      *pHwRef
                              )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    
    if( (NULL == psHciContext) || (NULL == pHwRef) )
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                                    psHciContext->p_reader_a_info;
        /* 
            NXP_WRA_CONTINUE_ACTIVATION:
            for activation command */
        status = phHciNfc_Send_ReaderA_Command(psHciContext, 
                        pHwRef, (uint8_t)p_rdr_a_info->pipe_id, 
                        (uint8_t)NXP_WRA_CONTINUE_ACTIVATION);
    }
    return status;
}

NFCSTATUS
phHciNfc_ReaderA_Update_Info(
                             phHciNfc_sContext_t        *psHciContext,
                             uint8_t                    infotype,
                             void                       *rdr_a_info
                             )
{
    NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    
    if (NULL == psHciContext)
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if(NULL == psHciContext->p_reader_a_info)
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
                        psHciContext->p_reader_a_info ;

        switch(infotype)
        {
            case HCI_READER_A_ENABLE:
            {
                if(NULL != rdr_a_info)
                {
                    p_rdr_a_info->enable_rdr_a_gate = 
                                    *((uint8_t *)rdr_a_info);
                }
                break;
            }
            case HCI_READER_A_INFO_SEQ:
            {
                p_rdr_a_info->current_seq = RDR_A_UID;
                p_rdr_a_info->next_seq = RDR_A_UID;
                break;
            }           
            default:
            {
                status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
                break;
            }
        }
    }
    return status;
}

NFCSTATUS
phHciNfc_ReaderA_App_Data (
                                void             *psHciHandle,
                                void             *pHwRef
                                )
{
    NFCSTATUS               status = NFCSTATUS_SUCCESS;
    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
    if( (NULL == psHciContext) 
        || (NULL == pHwRef)
        )
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }   
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
        uint8_t                     pipeid = 0;

        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
            psHciContext->p_reader_a_info ;
        p_pipe_info = p_rdr_a_info->p_pipe_info;
        if(NULL == p_pipe_info )
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                NFCSTATUS_INVALID_HCI_SEQUENCE);
        }
        else
        {
            p_pipe_info->reg_index = RDR_A_APP_DATA_INDEX;
            pipeid = p_rdr_a_info->pipe_id ;
            /* Fill the data buffer and send the command to the 
            device */
            status = 
                phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 
                pipeid, (uint8_t)ANY_GET_PARAMETER);
        }
    }
    return status;
}

NFCSTATUS
phHciNfc_ReaderA_Fwi_Sfgt (
                           void             *psHciHandle,
                           void             *pHwRef
                           )
{
    NFCSTATUS               status = NFCSTATUS_SUCCESS;
    phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
    if( (NULL == psHciContext) 
        || (NULL == pHwRef)
        )
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    }
    else if((NULL == psHciContext->p_reader_a_info) || 
        (HCI_READER_A_ENABLE != 
        ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
        enable_rdr_a_gate))
    {
        status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    }   
    else
    {
        phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
        phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
        uint8_t                     pipeid = 0;

        p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
            psHciContext->p_reader_a_info ;
        p_pipe_info = p_rdr_a_info->p_pipe_info;
        if(NULL == p_pipe_info )
        {
            status = PHNFCSTVAL(CID_NFC_HCI, 
                NFCSTATUS_INVALID_HCI_SEQUENCE);
        }
        else
        {
            p_pipe_info->reg_index = RDR_A_FWI_SFGT_INDEX;
            pipeid = p_rdr_a_info->pipe_id ;
            /* Fill the data buffer and send the command to the 
            device */
            status = 
                phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 
                pipeid, (uint8_t)ANY_GET_PARAMETER);
        }
    }
    return status;
}

