Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 NXP Semiconductors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*!
     18 * =========================================================================== *
     19 *                                                                             *
     20 *                                                                             *
     21 * \file  phHciNfc_RFReaderA.c                                                 *
     22 * \brief HCI Reader A Management Routines.                                    *
     23 *                                                                             *
     24 *                                                                             *
     25 * Project: NFC-FRI-1.1                                                        *
     26 *                                                                             *
     27 * $Date: Wed Feb 17 16:19:04 2010 $                                           *
     28 * $Author: ing02260 $                                                         *
     29 * $Revision: 1.57 $                                                           *
     30 * $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 $
     31 *                                                                             *
     32 * =========================================================================== *
     33 */
     34 
     35 /*
     36 ***************************** Header File Inclusion ****************************
     37 */
     38 #include <phNfcCompId.h>
     39 #include <phHciNfc_Pipe.h>
     40 #include <phHciNfc_RFReader.h>
     41 #include <phHciNfc_RFReaderA.h>
     42 #include <phOsalNfc.h>
     43 /*
     44 ****************************** Macro Definitions *******************************
     45 */
     46 
     47 /* Registry used for getting the data */
     48 #define RDR_A_DATA_RATE_MAX_INDEX           0x01U
     49 #define RDR_A_UID_INDEX                     0x02U
     50 #define RDR_A_SAK_INDEX                     0x03U
     51 #define RDR_A_ATQA_INDEX                    0x04U
     52 #define RDR_A_APP_DATA_INDEX                0x05U
     53 #define RDR_A_FWI_SFGT_INDEX                0x06U
     54 
     55 /* Registry index for auto activation */
     56 #define NXP_AUTO_ACTIVATION_INDEX           0x10U
     57 
     58 #define RDR_A_SAK_FWI_SFGT_LENGTH           0x01U
     59 
     60 #define RDR_A_SINGLE_TAG_FOUND              0x00U
     61 #define RDR_A_MULTIPLE_TAGS_FOUND           0x03U
     62 
     63 #define RDR_A_MAX_APP_DATA_LEN              0x30U
     64 
     65 /* Time out */
     66 #define RDR_A_MIFARE_STATUS                 0x00U
     67 
     68 #define RDR_A_MIFARE_RAW_LENGTH             0x03U
     69 
     70 uint8_t nxp_nfc_mifareraw_timeout = NXP_MIFARE_XCHG_TIMEOUT;
     71 /*
     72 *************************** Structure and Enumeration ***************************
     73 */
     74 
     75 
     76 /*
     77 *************************** Static Function Declaration **************************
     78 */
     79 
     80 static
     81 NFCSTATUS
     82 phHciNfc_Recv_ReaderA_Response(
     83                         void                *psContext,
     84                         void                *pHwRef,
     85                         uint8_t             *pResponse,
     86 #ifdef ONE_BYTE_LEN
     87                         uint8_t             length
     88 #else
     89                         uint16_t            length
     90 #endif
     91                        );
     92 
     93 static
     94 NFCSTATUS
     95 phHciNfc_Recv_ReaderA_Event(
     96                              void               *psContext,
     97                              void               *pHwRef,
     98                              uint8_t            *pEvent,
     99 #ifdef ONE_BYTE_LEN
    100                              uint8_t            length
    101 #else
    102                              uint16_t           length
    103 #endif
    104                        );
    105 
    106 static
    107 NFCSTATUS
    108 phHciNfc_ReaderA_InfoUpdate(
    109                             phHciNfc_sContext_t     *psHciContext,
    110                             uint8_t                 index,
    111                             uint8_t                 *reg_value,
    112                             uint8_t                 reg_length
    113                          );
    114 
    115 static
    116 NFCSTATUS
    117 phHciNfc_Recv_Mifare_Packet(
    118                             phHciNfc_sContext_t *psHciContext,
    119                             uint8_t             cmd,
    120                             uint8_t             *pResponse,
    121 #ifdef ONE_BYTE_LEN
    122                             uint8_t             length
    123 #else
    124                             uint16_t            length
    125 #endif
    126                             );
    127 
    128 static
    129 NFCSTATUS
    130 phHciNfc_Recv_Iso_A_Packet(
    131                            phHciNfc_sContext_t  *psHciContext,
    132                            uint8_t              *pResponse,
    133 #ifdef ONE_BYTE_LEN
    134                             uint8_t             length
    135 #else
    136                             uint16_t            length
    137 #endif
    138                            );
    139 /*
    140 *************************** Function Definitions ***************************
    141 */
    142 NFCSTATUS
    143 phHciNfc_ReaderA_Get_PipeID(
    144                              phHciNfc_sContext_t        *psHciContext,
    145                              uint8_t                    *ppipe_id
    146                              )
    147 {
    148     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    149 
    150     if( (NULL != psHciContext)
    151         && ( NULL != ppipe_id )
    152         && ( NULL != psHciContext->p_reader_a_info )
    153         )
    154     {
    155         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    156         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    157             psHciContext->p_reader_a_info ;
    158         *ppipe_id =  p_rdr_a_info->pipe_id  ;
    159     }
    160     else
    161     {
    162         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    163     }
    164     return status;
    165 }
    166 
    167 
    168 NFCSTATUS
    169 phHciNfc_ReaderA_Init_Resources(
    170                                 phHciNfc_sContext_t     *psHciContext
    171                          )
    172 {
    173     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    174     phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    175     if( NULL == psHciContext )
    176     {
    177         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    178     }
    179     else
    180     {
    181         if(
    182             ( NULL == psHciContext->p_reader_a_info ) &&
    183              (phHciNfc_Allocate_Resource((void **)(&p_rdr_a_info),
    184             sizeof(phHciNfc_ReaderA_Info_t))== NFCSTATUS_SUCCESS)
    185           )
    186         {
    187             psHciContext->p_reader_a_info = p_rdr_a_info;
    188             p_rdr_a_info->current_seq = RDR_A_INVALID_SEQ;
    189             p_rdr_a_info->next_seq = RDR_A_INVALID_SEQ;
    190             p_rdr_a_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
    191         }
    192         else
    193         {
    194             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
    195         }
    196 
    197     }
    198     return status;
    199 }
    200 
    201 NFCSTATUS
    202 phHciNfc_ReaderA_Update_PipeInfo(
    203                                   phHciNfc_sContext_t     *psHciContext,
    204                                   uint8_t                 pipeID,
    205                                   phHciNfc_Pipe_Info_t    *pPipeInfo
    206                                   )
    207 {
    208     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    209 
    210     if( NULL == psHciContext )
    211     {
    212         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    213     }
    214     else if(NULL == psHciContext->p_reader_a_info)
    215     {
    216         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    217     }
    218     else
    219     {
    220         phHciNfc_ReaderA_Info_t *p_rdr_a_info=NULL;
    221         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    222                                 psHciContext->p_reader_a_info ;
    223         /* Update the pipe_id of the reader A Gate obtained from the HCI Response */
    224         p_rdr_a_info->pipe_id = pipeID;
    225         p_rdr_a_info->p_pipe_info = pPipeInfo;
    226         if (NULL != pPipeInfo)
    227         {
    228             /* Update the Response Receive routine of the reader A Gate */
    229             pPipeInfo->recv_resp = &phHciNfc_Recv_ReaderA_Response;
    230             /* Update the event Receive routine of the reader A Gate */
    231             pPipeInfo->recv_event = &phHciNfc_Recv_ReaderA_Event;
    232         }
    233     }
    234 
    235     return status;
    236 }
    237 
    238 NFCSTATUS
    239 phHciNfc_ReaderA_Info_Sequence (
    240                        void             *psHciHandle,
    241                        void             *pHwRef
    242                        )
    243 {
    244     NFCSTATUS               status = NFCSTATUS_SUCCESS;
    245     phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
    246 
    247     HCI_PRINT ("HCI : phHciNfc_ReaderA_Info_Sequence called... \n");
    248     if( (NULL == psHciContext)
    249         || (NULL == pHwRef)
    250       )
    251     {
    252       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    253     }
    254     else if((NULL == psHciContext->p_reader_a_info) ||
    255         (HCI_READER_A_ENABLE !=
    256         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
    257         enable_rdr_a_gate))
    258     {
    259         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    260     }
    261     else
    262     {
    263         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    264         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
    265         uint8_t                     pipeid = 0;
    266 
    267         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    268                                 psHciContext->p_reader_a_info ;
    269         p_pipe_info = p_rdr_a_info->p_pipe_info;
    270         if(NULL == p_pipe_info )
    271         {
    272             status = PHNFCSTVAL(CID_NFC_HCI,
    273                             NFCSTATUS_INVALID_HCI_SEQUENCE);
    274         }
    275         else
    276         {
    277             HCI_DEBUG ("HCI : p_rdr_a_info->current_seq : %02X\n", p_rdr_a_info->current_seq);
    278             switch(p_rdr_a_info->current_seq)
    279             {
    280                 case RDR_A_UID:
    281                 {
    282                     p_pipe_info->reg_index = RDR_A_UID_INDEX;
    283                     pipeid = p_rdr_a_info->pipe_id ;
    284                     /* Fill the data buffer and send the command to the
    285                             device */
    286                     status =
    287                         phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    288                         pipeid, (uint8_t)ANY_GET_PARAMETER);
    289                     if(NFCSTATUS_PENDING == status )
    290                     {
    291                         p_rdr_a_info->next_seq = RDR_A_SAK;
    292                     }
    293                     break;
    294                 }
    295                 case RDR_A_SAK:
    296                 {
    297                     p_pipe_info->reg_index = RDR_A_SAK_INDEX;
    298                     pipeid = p_rdr_a_info->pipe_id ;
    299                     /* Fill the data buffer and send the command to the
    300                             device */
    301                     status =
    302                         phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    303                         pipeid, (uint8_t)ANY_GET_PARAMETER);
    304                     if(NFCSTATUS_PENDING == status )
    305                     {
    306                         p_rdr_a_info->next_seq = RDR_A_ATQA;
    307                     }
    308                     break;
    309                 }
    310                 case RDR_A_ATQA:
    311                 {
    312                     p_pipe_info->reg_index = RDR_A_ATQA_INDEX;
    313                     pipeid = p_rdr_a_info->pipe_id ;
    314                     /* Fill the data buffer and send the command to the
    315                             device */
    316                     status =
    317                         phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    318                         pipeid, (uint8_t)ANY_GET_PARAMETER);
    319                     if(NFCSTATUS_PENDING == status )
    320                     {
    321                         p_rdr_a_info->next_seq = RDR_A_END_SEQUENCE;
    322                     }
    323                     break;
    324                 }
    325                 case RDR_A_END_SEQUENCE:
    326                 {
    327                     phNfc_sCompletionInfo_t     CompInfo;
    328                     if (RDR_A_MULTIPLE_TAGS_FOUND ==
    329                         p_rdr_a_info->multiple_tgts_found)
    330                     {
    331                         CompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
    332                     }
    333                     else
    334                     {
    335                         CompInfo.status = NFCSTATUS_SUCCESS;
    336                     }
    337 
    338                     CompInfo.info = &(p_rdr_a_info->reader_a_info);
    339 
    340                     p_rdr_a_info->reader_a_info.RemDevType = phHal_eISO14443_A_PICC;
    341                     p_rdr_a_info->current_seq = RDR_A_UID;
    342                     p_rdr_a_info->next_seq = RDR_A_UID;
    343                     status = NFCSTATUS_SUCCESS;
    344                     HCI_DEBUG ("HCI : p_rdr_a_info->reader_a_info.RemDevType : %02X\n", p_rdr_a_info->reader_a_info.RemDevType);
    345                     HCI_DEBUG ("HCI : status notified: %02X\n", CompInfo.status);
    346                     /* Notify to the upper layer */
    347                     phHciNfc_Tag_Notify(psHciContext,
    348                         pHwRef,
    349                         NFC_NOTIFY_TARGET_DISCOVERED,
    350                         &CompInfo);
    351                     break;
    352                 }
    353                 default:
    354                 {
    355                     status = PHNFCSTVAL(CID_NFC_HCI,
    356                                     NFCSTATUS_INVALID_HCI_RESPONSE);
    357                     break;
    358                 }
    359             }
    360             HCI_DEBUG ("HCI : p_rdr_a_info->current_seq after : %02X\n", p_rdr_a_info->current_seq);
    361             HCI_DEBUG ("HCI : p_rdr_a_info->next_seq : %02X\n", p_rdr_a_info->next_seq);
    362         }
    363     }
    364 
    365     HCI_PRINT ("HCI : phHciNfc_ReaderA_Info_Sequence end \n");
    366     return status;
    367 }
    368 
    369 
    370 static
    371 NFCSTATUS
    372 phHciNfc_ReaderA_InfoUpdate(
    373                                 phHciNfc_sContext_t     *psHciContext,
    374                                 uint8_t                 index,
    375                                 uint8_t                 *reg_value,
    376                                 uint8_t                 reg_length
    377                          )
    378 {
    379     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    380     phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    381     phHal_sIso14443AInfo_t        *p_tag_a_info = NULL;
    382 
    383     p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    384                                 (psHciContext->p_reader_a_info );
    385     p_tag_a_info = &(p_rdr_a_info->reader_a_info.RemoteDevInfo.Iso14443A_Info);
    386 
    387     switch(index)
    388     {
    389         case RDR_A_UID_INDEX:
    390         {
    391             /* Maximum UID length can go upto 10 bytes */
    392             if (reg_length <= PHHAL_MAX_UID_LENGTH)
    393             {
    394                 HCI_PRINT_BUFFER("\tReader A UID", reg_value, reg_length);
    395                 /* Update UID buffer and length */
    396                 p_tag_a_info->UidLength = reg_length;
    397                 (void)memcpy(
    398                         p_tag_a_info->Uid,
    399                         reg_value,
    400                         p_tag_a_info->UidLength);
    401             }
    402             else
    403             {
    404                 status = PHNFCSTVAL(CID_NFC_HCI,
    405                     NFCSTATUS_INVALID_HCI_RESPONSE);
    406             }
    407             break;
    408         }
    409         case RDR_A_SAK_INDEX:
    410         {
    411             /* SAK length is 1 byte */
    412             if (RDR_A_SAK_FWI_SFGT_LENGTH == reg_length)
    413             {
    414                 HCI_PRINT_BUFFER("\tReader A SAK", reg_value, reg_length);
    415                 /* Copy SAK byte */
    416                 p_tag_a_info->Sak = *reg_value;
    417             }
    418             else
    419             {
    420                 status = PHNFCSTVAL(CID_NFC_HCI,
    421                     NFCSTATUS_INVALID_HCI_RESPONSE);
    422             }
    423             break;
    424         }
    425         case RDR_A_ATQA_INDEX:
    426         {
    427             /* ATQA length shall be 2 bytes */
    428             if (PHHAL_ATQA_LENGTH == reg_length)
    429             {
    430                 HCI_PRINT_BUFFER("\tReader A ATQA", reg_value, reg_length);
    431                 /* Copy ATQA */
    432                 (void)memcpy(p_tag_a_info->AtqA,
    433                     reg_value,
    434                     reg_length);
    435             }
    436             else
    437             {
    438                 status = PHNFCSTVAL(CID_NFC_HCI,
    439                     NFCSTATUS_INVALID_HCI_RESPONSE);
    440             }
    441             break;
    442         }
    443         case RDR_A_APP_DATA_INDEX:
    444         {
    445             /* Remote device info provided by the user */
    446             p_tag_a_info =
    447                     &(psHciContext->p_target_info->RemoteDevInfo.Iso14443A_Info);
    448             /* Historical bytes length shall be 2 bytes */
    449             if (reg_length <= RDR_A_MAX_APP_DATA_LEN)
    450             {
    451                 HCI_PRINT_BUFFER("\tReader A APP DATA", reg_value, reg_length);
    452                 p_tag_a_info->AppDataLength = reg_length;
    453                 /* Historical bytes */
    454                 (void)memcpy(p_tag_a_info->AppData,
    455                     reg_value,
    456                     reg_length);
    457             }
    458             else
    459             {
    460                 status = PHNFCSTVAL(CID_NFC_HCI,
    461                     NFCSTATUS_INVALID_HCI_RESPONSE);
    462             }
    463             break;
    464         }
    465         case RDR_A_FWI_SFGT_INDEX:
    466         {
    467             if (RDR_A_SAK_FWI_SFGT_LENGTH == reg_length)
    468             {
    469                 HCI_PRINT_BUFFER("\tReader A FWI SFGT", reg_value, reg_length);
    470                 p_tag_a_info->Fwi_Sfgt = *reg_value;
    471             }
    472             else
    473             {
    474                 status = PHNFCSTVAL(CID_NFC_HCI,
    475                     NFCSTATUS_INVALID_HCI_RESPONSE);
    476             }
    477             break;
    478         }
    479         default:
    480         {
    481             status = PHNFCSTVAL(CID_NFC_HCI,
    482                             NFCSTATUS_INVALID_HCI_RESPONSE);
    483             break;
    484         }
    485     }
    486     return status;
    487 }
    488 
    489 
    490 static
    491 NFCSTATUS
    492 phHciNfc_Recv_ReaderA_Response(
    493                         void                *psContext,
    494                         void                *pHwRef,
    495                         uint8_t             *pResponse,
    496 #ifdef ONE_BYTE_LEN
    497                         uint8_t             length
    498 #else
    499                         uint16_t            length
    500 #endif
    501                        )
    502 {
    503     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    504     phHciNfc_sContext_t         *psHciContext =
    505                                 (phHciNfc_sContext_t *)psContext ;
    506 
    507 
    508     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
    509         || (length == 0))
    510     {
    511       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    512     }
    513     else if(NULL == psHciContext->p_reader_a_info)
    514     {
    515         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    516     }
    517     else
    518     {
    519         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    520         uint8_t                     prev_cmd = ANY_GET_PARAMETER;
    521         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    522                             psHciContext->p_reader_a_info ;
    523         if( NULL == p_rdr_a_info->p_pipe_info)
    524         {
    525             status = PHNFCSTVAL(CID_NFC_HCI,
    526                             NFCSTATUS_INVALID_HCI_SEQUENCE);
    527         }
    528         else
    529         {
    530             prev_cmd = p_rdr_a_info->p_pipe_info->prev_msg ;
    531             switch(prev_cmd)
    532             {
    533                 case ANY_GET_PARAMETER:
    534                 {
    535                     status = phHciNfc_ReaderA_InfoUpdate(psHciContext,
    536                                     p_rdr_a_info->p_pipe_info->reg_index,
    537                                     &pResponse[HCP_HEADER_LEN],
    538                                     (uint8_t)(length - HCP_HEADER_LEN));
    539 #if 0
    540                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    541                                                                 UPDATE_SEQ);
    542 #endif
    543                     break;
    544                 }
    545                 case ANY_SET_PARAMETER:
    546                 {
    547                     HCI_PRINT("Reader A Parameter Set \n");
    548                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    549                                                     UPDATE_SEQ);
    550                     p_rdr_a_info->next_seq = RDR_A_UID;
    551                     break;
    552                 }
    553                 case ANY_OPEN_PIPE:
    554                 {
    555                     HCI_PRINT("Reader A open pipe complete\n");
    556                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    557                                                     UPDATE_SEQ);
    558                     p_rdr_a_info->next_seq = RDR_A_UID;
    559                     break;
    560                 }
    561                 case ANY_CLOSE_PIPE:
    562                 {
    563                     HCI_PRINT("Reader A close pipe complete\n");
    564                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    565                                                     UPDATE_SEQ);
    566                     break;
    567                 }
    568                 case NXP_WRA_CONTINUE_ACTIVATION:
    569                 case NXP_WR_ACTIVATE_ID:
    570                 {
    571                     HCI_PRINT("Reader A continue activation or ");
    572                     HCI_PRINT("reactivation completed \n");
    573                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    574                                                     UPDATE_SEQ);
    575                     break;
    576                 }
    577                 case NXP_MIFARE_RAW:
    578                 case NXP_MIFARE_CMD:
    579                 {
    580                     if (length > HCP_HEADER_LEN)
    581                     {
    582                         HCI_PRINT("Mifare packet received \n");
    583                         /* Copy buffer to the receive buffer */
    584                         phHciNfc_Append_HCPFrame(psHciContext->recv_buffer,
    585                             0, pResponse, length);
    586                         psHciContext->rx_total = length;
    587                         status = phHciNfc_Recv_Mifare_Packet(psHciContext,
    588                                                 prev_cmd,
    589                                                 &pResponse[HCP_HEADER_LEN],
    590                                                 (length - HCP_HEADER_LEN));
    591 
    592                     }
    593                     else if (length == HCP_HEADER_LEN)
    594                     {
    595                         psHciContext->rx_total = length;
    596                         psHciContext->rx_index = HCP_HEADER_LEN;
    597 
    598                     }
    599                     else
    600                     {
    601                         status = PHNFCSTVAL(CID_NFC_HCI,
    602                                         NFCSTATUS_INVALID_HCI_RESPONSE);
    603                     }
    604                     break;
    605                 }
    606                 case WR_XCHGDATA:
    607                 {
    608                     if (length >= HCP_HEADER_LEN)
    609                     {
    610                         uint8_t         i = 1;
    611                         HCI_PRINT("ISO 14443-4A received \n");
    612                         /* Copy buffer to the receive buffer */
    613                         phHciNfc_Append_HCPFrame(psHciContext->recv_buffer,
    614                             0, pResponse, (length - i));
    615                         psHciContext->rx_total = (length - i);
    616                         status = phHciNfc_Recv_Iso_A_Packet(psHciContext,
    617                                                     &pResponse[HCP_HEADER_LEN],
    618                                                     (length - HCP_HEADER_LEN));
    619                     }
    620                     else
    621                     {
    622                         status = PHNFCSTVAL(CID_NFC_HCI,
    623                                             NFCSTATUS_INVALID_HCI_RESPONSE);
    624                     }
    625                     break;
    626                 }
    627                 case NXP_WR_PRESCHECK:
    628                 {
    629                     HCI_PRINT("Presence check completed \n");
    630                     break;
    631                 }
    632                 case NXP_WR_ACTIVATE_NEXT:
    633                 {
    634                     if (length > HCP_HEADER_LEN)
    635                     {
    636                         if (RDR_A_MULTIPLE_TAGS_FOUND == pResponse[HCP_HEADER_LEN])
    637                         {
    638                             p_rdr_a_info->multiple_tgts_found =
    639                                 RDR_A_MULTIPLE_TAGS_FOUND;
    640                         }
    641                         else
    642                         {
    643                             p_rdr_a_info->multiple_tgts_found = FALSE;
    644                         }
    645                         HCI_PRINT("Activate next completed \n");
    646                     }
    647                     else
    648                     {
    649                         status = PHNFCSTVAL(CID_NFC_HCI,
    650                                         NFCSTATUS_INVALID_HCI_RESPONSE);
    651                     }
    652                     break;
    653                 }
    654                 case NXP_WR_DISPATCH_TO_UICC:
    655                 {
    656                     switch(length)
    657                     {
    658                         case HCP_HEADER_LEN:
    659                         {
    660                             /* Optional error code, if no error code field
    661                                 in the response, then this command is
    662                                 successfully completed */
    663                             p_rdr_a_info->uicc_activation =
    664                                     UICC_CARD_ACTIVATION_SUCCESS;
    665                             break;
    666                         }
    667                         case (HCP_HEADER_LEN + 1):
    668                         {
    669                             p_rdr_a_info->uicc_activation =
    670                                         pResponse[HCP_HEADER_LEN];
    671                             break;
    672                         } /* End of case (HCP_HEADER_LEN + index) */
    673                         default:
    674                         {
    675                             status = PHNFCSTVAL(CID_NFC_HCI,
    676                                                 NFCSTATUS_INVALID_HCI_RESPONSE);
    677                             break;
    678                         }
    679                     } /* End of switch(length) */
    680                     if (NFCSTATUS_SUCCESS == status)
    681                     {
    682                         status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    683                                                                     UPDATE_SEQ);
    684                     }
    685                     break;
    686                 }
    687                 default:
    688                 {
    689                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
    690                     break;
    691                 }
    692             } /* End of switch(prev_cmd) */
    693             if( NFCSTATUS_SUCCESS == status )
    694             {
    695                 p_rdr_a_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
    696                 p_rdr_a_info->current_seq = p_rdr_a_info->next_seq;
    697             }
    698         }
    699     }
    700     return status;
    701 }
    702 
    703 static
    704 NFCSTATUS
    705 phHciNfc_Recv_Iso_A_Packet(
    706                             phHciNfc_sContext_t *psHciContext,
    707                             uint8_t             *pResponse,
    708 #ifdef ONE_BYTE_LEN
    709                             uint8_t             length
    710 #else
    711                             uint16_t            length
    712 #endif
    713                             )
    714 {
    715     NFCSTATUS       status = NFCSTATUS_SUCCESS;
    716     uint8_t         i = 1;
    717 
    718     psHciContext->rx_index = HCP_HEADER_LEN;
    719     /* command WRA_XCHG_DATA: so give ISO 14443-4A data to the upper layer */
    720     if(FALSE != pResponse[(length - i)])
    721     {
    722         status = PHNFCSTVAL(CID_NFC_HCI,
    723                             NFCSTATUS_RF_ERROR);
    724     }
    725     HCI_PRINT_BUFFER("ISO 14443- 4A Bytes received", pResponse, length);
    726 
    727     return status;
    728 }
    729 
    730 static
    731 NFCSTATUS
    732 phHciNfc_Recv_Mifare_Packet(
    733                            phHciNfc_sContext_t  *psHciContext,
    734                            uint8_t              cmd,
    735                            uint8_t              *pResponse,
    736 #ifdef ONE_BYTE_LEN
    737                            uint8_t              length
    738 #else
    739                            uint16_t             length
    740 #endif
    741                            )
    742 {
    743     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    744 
    745     /* To remove "warning (VS C4100) : unreferenced formal parameter" */
    746     PHNFC_UNUSED_VARIABLE(pResponse);
    747     PHNFC_UNUSED_VARIABLE(length);
    748 
    749     if (NXP_MIFARE_RAW == cmd)
    750     {
    751 #ifdef ENABLE_MIFARE_RAW
    752         uint8_t                 index = 0;
    753 #ifndef HAL_SW_3A_STATUS
    754         if(phHal_eISO14443_3A_PICC == psHciContext->p_target_info->RemDevType)
    755         {
    756             index++;
    757             psHciContext->rx_index = (index + HCP_HEADER_LEN);
    758             HCI_PRINT_BUFFER("Mifare Bytes received", &pResponse[index], (length - index));
    759         }
    760         else
    761 #endif
    762         if (RDR_A_MIFARE_STATUS == pResponse[index])  /* Status byte */
    763         {
    764             index++;
    765             psHciContext->rx_index = (index + HCP_HEADER_LEN);
    766             HCI_PRINT_BUFFER("Mifare Bytes received", &pResponse[index], (length - index));
    767         }
    768         else
    769         {
    770             status = PHNFCSTVAL(CID_NFC_HCI,
    771                                 NFCSTATUS_INVALID_HCI_RESPONSE);
    772         }
    773 #else
    774         psHciContext->rx_index = HCP_HEADER_LEN;
    775         /* Give Mifare data to the upper layer */
    776         HCI_PRINT_BUFFER("Mifare Bytes received", pResponse, length);
    777 #endif /* #ifdef ENABLE_MIFARE_RAW */
    778     }
    779     else
    780     {
    781         psHciContext->rx_index = HCP_HEADER_LEN;
    782         /* command NXP_MIFARE_CMD: so give Mifare data to the upper layer */
    783         HCI_PRINT_BUFFER("Mifare Bytes received", pResponse, length);
    784     }
    785 
    786     return status;
    787 }
    788 
    789 static
    790 NFCSTATUS
    791 phHciNfc_Recv_ReaderA_Event(
    792                              void               *psContext,
    793                              void               *pHwRef,
    794                              uint8_t            *pEvent,
    795 #ifdef ONE_BYTE_LEN
    796                              uint8_t            length
    797 #else
    798                              uint16_t           length
    799 #endif
    800                        )
    801 {
    802     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    803     phHciNfc_sContext_t         *psHciContext =
    804                                 (phHciNfc_sContext_t *)psContext ;
    805 
    806     HCI_PRINT ("HCI : phHciNfc_Recv_ReaderA_Event called...\n");
    807     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
    808         || (length == 0))
    809     {
    810         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    811     }
    812     else if((NULL == psHciContext->p_reader_a_info) ||
    813         (HCI_READER_A_ENABLE !=
    814         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
    815         enable_rdr_a_gate))
    816     {
    817         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    818     }
    819     else
    820     {
    821         phHciNfc_HCP_Packet_t       *p_packet = NULL;
    822         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    823         phHciNfc_HCP_Message_t      *message = NULL;
    824         uint8_t                     instruction=0,
    825                                     i = 0;
    826 
    827         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    828                         psHciContext->p_reader_a_info ;
    829         p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
    830         message = &p_packet->msg.message;
    831         /* Get the instruction bits from the Message Header */
    832         instruction = (uint8_t) GET_BITS8( message->msg_header,
    833             HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
    834 
    835         HCI_DEBUG ("HCI : instruction : %02X\n", instruction);
    836         HCI_DEBUG ("HCI : Multiple tag found : %02X\n", message->payload[i]);
    837 
    838         if ((EVT_TARGET_DISCOVERED == instruction)
    839             && ((RDR_A_MULTIPLE_TAGS_FOUND == message->payload[i] )
    840                 || (RDR_A_SINGLE_TAG_FOUND == message->payload[i]))
    841           )
    842         {
    843             phNfc_sCompletionInfo_t pCompInfo;
    844 
    845             if (RDR_A_MULTIPLE_TAGS_FOUND == message->payload[i])
    846             {
    847                 p_rdr_a_info->multiple_tgts_found = RDR_A_MULTIPLE_TAGS_FOUND;
    848                 pCompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
    849             }
    850             else
    851             {
    852                 p_rdr_a_info->multiple_tgts_found = FALSE;
    853                 pCompInfo.status = NFCSTATUS_SUCCESS;
    854             }
    855 
    856             psHciContext->host_rf_type = phHal_eISO14443_A_PCD;
    857             p_rdr_a_info->reader_a_info.RemDevType = phHal_eISO14443_A_PICC;
    858             p_rdr_a_info->current_seq = RDR_A_UID;
    859 
    860             HCI_DEBUG ("HCI : psHciContext->host_rf_type : %02X\n", psHciContext->host_rf_type);
    861             HCI_DEBUG ("HCI : p_rdr_a_info->reader_a_info.RemDevType : %02X\n", p_rdr_a_info->reader_a_info.RemDevType);
    862             HCI_DEBUG ("HCI : p_rdr_a_info->current_seq : %02X\n", p_rdr_a_info->current_seq);
    863 
    864             /* Notify to the HCI Generic layer To Update the FSM */
    865             phHciNfc_Notify_Event(psHciContext, pHwRef,
    866                                     NFC_NOTIFY_TARGET_DISCOVERED,
    867                                     &pCompInfo);
    868 
    869         }
    870         else
    871         {
    872             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
    873         }
    874     }
    875     HCI_PRINT ("HCI : phHciNfc_Recv_ReaderA_Event end\n");
    876     return status;
    877 }
    878 
    879 NFCSTATUS
    880 phHciNfc_ReaderA_Auto_Activate(
    881                                void         *psContext,
    882                                void         *pHwRef,
    883                                uint8_t      activate_enable
    884                                )
    885 {
    886     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    887     phHciNfc_sContext_t         *psHciContext =
    888                                 (phHciNfc_sContext_t *)psContext ;
    889     if( (NULL == psHciContext) || (NULL == pHwRef))
    890     {
    891         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    892     }
    893     else if((NULL == psHciContext->p_reader_a_info) ||
    894         (HCI_READER_A_ENABLE !=
    895         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
    896         enable_rdr_a_gate))
    897     {
    898         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    899     }
    900     else
    901     {
    902         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    903         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
    904         uint8_t                     pipeid = 0;
    905 
    906         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    907                                 psHciContext->p_reader_a_info ;
    908         p_pipe_info = p_rdr_a_info->p_pipe_info;
    909         p_pipe_info->reg_index = NXP_AUTO_ACTIVATION_INDEX;
    910         p_pipe_info->param_info = &activate_enable;
    911         p_pipe_info->param_length = sizeof(activate_enable);
    912         pipeid = p_rdr_a_info->pipe_id ;
    913         status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    914                 pipeid, (uint8_t)ANY_SET_PARAMETER);
    915         if(NFCSTATUS_PENDING == status )
    916         {
    917             status = NFCSTATUS_SUCCESS;
    918         }
    919     }
    920     return status;
    921 }
    922 
    923 NFCSTATUS
    924 phHciNfc_ReaderA_Set_DataRateMax(
    925                                void         *psContext,
    926                                void         *pHwRef,
    927                                uint8_t      data_rate_value
    928                                )
    929 {
    930     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    931     phHciNfc_sContext_t         *psHciContext =
    932         (phHciNfc_sContext_t *)psContext ;
    933     if( (NULL == psHciContext) || (NULL == pHwRef))
    934     {
    935         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    936     }
    937     else if((NULL == psHciContext->p_reader_a_info) ||
    938         (HCI_READER_A_ENABLE !=
    939         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
    940         enable_rdr_a_gate))
    941     {
    942         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    943     }
    944     else
    945     {
    946         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    947         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
    948         uint8_t                     pipeid = 0;
    949 
    950         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
    951                             psHciContext->p_reader_a_info ;
    952         p_pipe_info = p_rdr_a_info->p_pipe_info;
    953         p_pipe_info->reg_index = RDR_A_DATA_RATE_MAX_INDEX;
    954         p_pipe_info->param_info = &data_rate_value;
    955         p_pipe_info->param_length = sizeof(data_rate_value);
    956         pipeid = p_rdr_a_info->pipe_id ;
    957         status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    958                                     pipeid, (uint8_t)ANY_SET_PARAMETER);
    959     }
    960     return status;
    961 }
    962 
    963 
    964 NFCSTATUS
    965 phHciNfc_Send_ReaderA_Command(
    966                               phHciNfc_sContext_t   *psHciContext,
    967                               void                  *pHwRef,
    968                               uint8_t               pipe_id,
    969                               uint8_t               cmd
    970                               )
    971 {
    972     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    973 
    974     if( (NULL == psHciContext) || (NULL == pHwRef) )
    975     {
    976         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    977     }
    978     else if((NULL == psHciContext->p_reader_a_info) ||
    979         (HCI_READER_A_ENABLE !=
    980         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
    981         enable_rdr_a_gate) ||
    982         (HCI_UNKNOWN_PIPE_ID ==
    983         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
    984         pipe_id) ||
    985         (pipe_id !=
    986         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
    987         pipe_id))
    988     {
    989         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    990     }
    991     else
    992     {
    993         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
    994         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
    995         phHciNfc_HCP_Packet_t       *hcp_packet = NULL;
    996         phHciNfc_HCP_Message_t      *hcp_message = NULL;
    997         uint8_t                     i = 0;
    998         uint16_t                    length = HCP_HEADER_LEN;
    999 
   1000         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
   1001                             psHciContext->p_reader_a_info ;
   1002         p_pipe_info = p_rdr_a_info->p_pipe_info;
   1003         if(NULL == p_pipe_info )
   1004         {
   1005             status = PHNFCSTVAL(CID_NFC_HCI,
   1006                         NFCSTATUS_INVALID_HCI_SEQUENCE);
   1007         }
   1008         else
   1009         {
   1010             psHciContext->tx_total = 0 ;
   1011             hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   1012             /* Construct the HCP Frame */
   1013             switch(cmd)
   1014             {
   1015                 case NXP_WRA_CONTINUE_ACTIVATION:
   1016                 case NXP_WR_ACTIVATE_ID:
   1017                 {
   1018                     phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   1019                         (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
   1020                     break;
   1021                 }
   1022 
   1023                 case NXP_MIFARE_RAW:
   1024                 {
   1025                     if (p_pipe_info->param_length < RDR_A_MIFARE_RAW_LENGTH)
   1026                     {
   1027                         status = PHNFCSTVAL(CID_NFC_HCI,
   1028                                             NFCSTATUS_INVALID_PARAMETER);
   1029                     }
   1030                     else
   1031                     {
   1032                         /*
   1033                             Buffer shall be updated with
   1034                             TO -              Time out (1 byte)
   1035                             Status -          b0 to b2 indicate valid bits (1 byte)
   1036                             Data (with CRC) - params received from this function
   1037                         */
   1038                         hcp_message = &(hcp_packet->msg.message);
   1039 #ifdef ENABLE_MIFARE_RAW
   1040                         /* Time out */
   1041                         hcp_message->payload[i++] = nxp_nfc_mifareraw_timeout;
   1042                         /* Status */
   1043                         hcp_message->payload[i++] = RDR_A_MIFARE_STATUS;
   1044 #else
   1045                         cmd = NXP_MIFARE_CMD;
   1046 #endif /* #ifdef ENABLE_MIFARE_RAW */
   1047                         phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   1048                             (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
   1049 
   1050                         phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
   1051                             i, (uint8_t *)p_pipe_info->param_info,
   1052 #ifdef ENABLE_MIFARE_RAW
   1053                             p_pipe_info->param_length);
   1054 #else
   1055                             (p_pipe_info->param_length - 2));
   1056 #endif /* #ifdef ENABLE_MIFARE_RAW */
   1057 
   1058 #ifdef ENABLE_MIFARE_RAW
   1059                         length =(uint16_t)(length + i + p_pipe_info->param_length);
   1060 #else
   1061                         length =(uint16_t)(length + i + p_pipe_info->param_length - 2);
   1062 #endif /* #ifdef ENABLE_MIFARE_RAW */
   1063                     }
   1064                     break;
   1065                 }
   1066                 case NXP_MIFARE_CMD:
   1067                 {
   1068                     /*
   1069                         Buffer shall be updated with
   1070                         Cmd -               Authentication A/B, read/write
   1071                                             (1 byte)
   1072                         Addr -              Address associated with Mifare cmd
   1073                                             (1 byte)
   1074                         Data  -             params received from this function
   1075                     */
   1076                     phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   1077                                 (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
   1078                     hcp_message = &(hcp_packet->msg.message);
   1079 
   1080                     /* Command */
   1081                     hcp_message->payload[i++] =
   1082                                    psHciContext->p_xchg_info->params.tag_info.cmd_type ;
   1083                      /* Address */
   1084                     hcp_message->payload[i++] =
   1085                                     psHciContext->p_xchg_info->params.tag_info.addr ;
   1086                     phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
   1087                         i, (uint8_t *)p_pipe_info->param_info,
   1088                         p_pipe_info->param_length);
   1089                     length =(uint16_t)(length + i + p_pipe_info->param_length);
   1090                     break;
   1091                 }
   1092                 default:
   1093                 {
   1094                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_COMMAND);
   1095                     break;
   1096                 }
   1097             }
   1098             if (NFCSTATUS_SUCCESS == status)
   1099             {
   1100                 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND;
   1101                 p_pipe_info->prev_msg = cmd;
   1102                 psHciContext->tx_total = length;
   1103                 psHciContext->response_pending = TRUE;
   1104 
   1105                 /* Send the Constructed HCP packet to the lower layer */
   1106                 status = phHciNfc_Send_HCP( psHciContext, pHwRef);
   1107                 p_pipe_info->prev_status = status;
   1108             }
   1109         }
   1110     }
   1111     return status;
   1112 }
   1113 
   1114 NFCSTATUS
   1115 phHciNfc_ReaderA_Cont_Activate (
   1116                               phHciNfc_sContext_t       *psHciContext,
   1117                               void                      *pHwRef
   1118                               )
   1119 {
   1120     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1121 
   1122     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1123     {
   1124         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1125     }
   1126     else if((NULL == psHciContext->p_reader_a_info) ||
   1127         (HCI_READER_A_ENABLE !=
   1128         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
   1129         enable_rdr_a_gate))
   1130     {
   1131         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1132     }
   1133     else
   1134     {
   1135         phHciNfc_ReaderA_Info_t     *p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
   1136                                     psHciContext->p_reader_a_info;
   1137         /*
   1138             NXP_WRA_CONTINUE_ACTIVATION:
   1139             for activation command */
   1140         status = phHciNfc_Send_ReaderA_Command(psHciContext,
   1141                         pHwRef, (uint8_t)p_rdr_a_info->pipe_id,
   1142                         (uint8_t)NXP_WRA_CONTINUE_ACTIVATION);
   1143     }
   1144     return status;
   1145 }
   1146 
   1147 NFCSTATUS
   1148 phHciNfc_ReaderA_Update_Info(
   1149                              phHciNfc_sContext_t        *psHciContext,
   1150                              uint8_t                    infotype,
   1151                              void                       *rdr_a_info
   1152                              )
   1153 {
   1154     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1155 
   1156     if (NULL == psHciContext)
   1157     {
   1158         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1159     }
   1160     else if(NULL == psHciContext->p_reader_a_info)
   1161     {
   1162         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1163     }
   1164     else
   1165     {
   1166         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
   1167         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
   1168                         psHciContext->p_reader_a_info ;
   1169 
   1170         switch(infotype)
   1171         {
   1172             case HCI_READER_A_ENABLE:
   1173             {
   1174                 if(NULL != rdr_a_info)
   1175                 {
   1176                     p_rdr_a_info->enable_rdr_a_gate =
   1177                                     *((uint8_t *)rdr_a_info);
   1178                 }
   1179                 break;
   1180             }
   1181             case HCI_READER_A_INFO_SEQ:
   1182             {
   1183                 p_rdr_a_info->current_seq = RDR_A_UID;
   1184                 p_rdr_a_info->next_seq = RDR_A_UID;
   1185                 break;
   1186             }
   1187             default:
   1188             {
   1189                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1190                 break;
   1191             }
   1192         }
   1193     }
   1194     return status;
   1195 }
   1196 
   1197 NFCSTATUS
   1198 phHciNfc_ReaderA_App_Data (
   1199                                 void             *psHciHandle,
   1200                                 void             *pHwRef
   1201                                 )
   1202 {
   1203     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   1204     phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
   1205     if( (NULL == psHciContext)
   1206         || (NULL == pHwRef)
   1207         )
   1208     {
   1209         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1210     }
   1211     else if((NULL == psHciContext->p_reader_a_info) ||
   1212         (HCI_READER_A_ENABLE !=
   1213         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
   1214         enable_rdr_a_gate))
   1215     {
   1216         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1217     }
   1218     else
   1219     {
   1220         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
   1221         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
   1222         uint8_t                     pipeid = 0;
   1223 
   1224         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
   1225             psHciContext->p_reader_a_info ;
   1226         p_pipe_info = p_rdr_a_info->p_pipe_info;
   1227         if(NULL == p_pipe_info )
   1228         {
   1229             status = PHNFCSTVAL(CID_NFC_HCI,
   1230                 NFCSTATUS_INVALID_HCI_SEQUENCE);
   1231         }
   1232         else
   1233         {
   1234             p_pipe_info->reg_index = RDR_A_APP_DATA_INDEX;
   1235             pipeid = p_rdr_a_info->pipe_id ;
   1236             /* Fill the data buffer and send the command to the
   1237             device */
   1238             status =
   1239                 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
   1240                 pipeid, (uint8_t)ANY_GET_PARAMETER);
   1241         }
   1242     }
   1243     return status;
   1244 }
   1245 
   1246 NFCSTATUS
   1247 phHciNfc_ReaderA_Fwi_Sfgt (
   1248                            void             *psHciHandle,
   1249                            void             *pHwRef
   1250                            )
   1251 {
   1252     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   1253     phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
   1254     if( (NULL == psHciContext)
   1255         || (NULL == pHwRef)
   1256         )
   1257     {
   1258         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1259     }
   1260     else if((NULL == psHciContext->p_reader_a_info) ||
   1261         (HCI_READER_A_ENABLE !=
   1262         ((phHciNfc_ReaderA_Info_t *)(psHciContext->p_reader_a_info))->
   1263         enable_rdr_a_gate))
   1264     {
   1265         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1266     }
   1267     else
   1268     {
   1269         phHciNfc_ReaderA_Info_t     *p_rdr_a_info=NULL;
   1270         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
   1271         uint8_t                     pipeid = 0;
   1272 
   1273         p_rdr_a_info = (phHciNfc_ReaderA_Info_t *)
   1274             psHciContext->p_reader_a_info ;
   1275         p_pipe_info = p_rdr_a_info->p_pipe_info;
   1276         if(NULL == p_pipe_info )
   1277         {
   1278             status = PHNFCSTVAL(CID_NFC_HCI,
   1279                 NFCSTATUS_INVALID_HCI_SEQUENCE);
   1280         }
   1281         else
   1282         {
   1283             p_pipe_info->reg_index = RDR_A_FWI_SFGT_INDEX;
   1284             pipeid = p_rdr_a_info->pipe_id ;
   1285             /* Fill the data buffer and send the command to the
   1286             device */
   1287             status =
   1288                 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
   1289                 pipeid, (uint8_t)ANY_GET_PARAMETER);
   1290         }
   1291     }
   1292     return status;
   1293 }
   1294 
   1295