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_RFReader.c                                                  *
     22 * \brief HCI RF Reader Management Gate Routines.                              *
     23 *                                                                             *
     24 *                                                                             *
     25 * Project: NFC-FRI-1.1                                                        *
     26 *                                                                             *
     27 * $Date: Wed Apr 21 12:21:15 2010 $                                           *
     28 * $Author: ing07385 $                                                         *
     29 * $Revision: 1.53 $                                                            *
     30 * $Aliases: NFC_FRI1.1_WK1007_R33_6 $                                                                *
     31 *                                                                             *
     32 * =========================================================================== *
     33 */
     34 
     35 /*
     36 ***************************** Header File Inclusion ****************************
     37 */
     38 #include <phNfcConfig.h>
     39 #include <phNfcCompId.h>
     40 #include <phHciNfc_Pipe.h>
     41 #include <phHciNfc_RFReader.h>
     42 #include <phHciNfc_RFReaderA.h>
     43 #ifdef TYPE_B
     44 #include <phHciNfc_RFReaderB.h>
     45 #endif
     46 #ifdef ENABLE_P2P
     47 #include <phHciNfc_NfcIPMgmt.h>
     48 #endif
     49 #ifdef TYPE_FELICA
     50 #include <phHciNfc_Felica.h>
     51 #endif
     52 #ifdef TYPE_JEWEL
     53 #include <phHciNfc_Jewel.h>
     54 #endif
     55 #ifdef TYPE_ISO15693
     56 #include <phHciNfc_ISO15693.h>
     57 #endif /* #ifdef    TYPE_ISO15693 */
     58 #include <phOsalNfc.h>
     59 
     60 /*
     61 ****************************** Macro Definitions *******************************
     62 */
     63 
     64 #define NFCIP_ACTIVATE_DELAY       0x05U
     65 
     66 /*
     67 *************************** Structure and Enumeration ***************************
     68 */
     69 
     70 
     71 /** \defgroup grp_hci_nfc HCI Reader RF Management Component
     72  *
     73  *
     74  */
     75 
     76 
     77 typedef enum phHciNfc_ReaderMgmt_Seq{
     78     READERA_PIPE_OPEN       = 0x00U,
     79     READERB_PIPE_OPEN,
     80     FELICA_PROP_PIPE_OPEN,
     81     JEWEL_PROP_PIPE_OPEN,
     82     ISO15693_PROP_PIPE_OPEN,
     83     NFCIP1_INITIATOR_PIPE_OPEN,
     84     NFCIP1_INITIATOR_MODE_CONFIG,
     85     NFCIP1_INITIATOR_PSL1_CONFIG,
     86     NFCIP1_INITIATOR_PSL2_CONFIG,
     87     READERA_DISABLE_AUTO_ACTIVATE,
     88 
     89 
     90     READERA_PIPE_CLOSE,
     91     READERB_PIPE_CLOSE,
     92     FELICA_PROP_PIPE_CLOSE,
     93     JEWEL_PROP_PIPE_CLOSE,
     94     ISO15693_PROP_PIPE_CLOSE,
     95     NFCIP1_INITIATOR_PIPE_CLOSE,
     96     END_READER_SEQUENCE
     97 } phHciNfc_ReaderMgmt_Seq_t;
     98 
     99 typedef struct phHciNfc_ReaderMgmt_Info{
    100     phHciNfc_ReaderMgmt_Seq_t   rf_gate_cur_seq;
    101     phHciNfc_ReaderMgmt_Seq_t   rf_gate_next_seq;
    102 } phHciNfc_ReaderMgmt_Info_t;
    103 
    104 
    105 /*
    106 *************************** Static Function Declaration **************************
    107 */
    108 static
    109 NFCSTATUS
    110 phHciNfc_ReaderMgmt_End_Discovery(
    111                                 phHciNfc_sContext_t     *psHciContext,
    112                                 void                    *pHwRef,
    113                                 uint8_t                 reader_pipe_id
    114                              );
    115 
    116 static
    117 NFCSTATUS
    118 phHciNfc_ReaderMgmt_Initiate_Discovery(
    119                                 phHciNfc_sContext_t     *psHciContext,
    120                                 void                    *pHwRef,
    121                                 uint8_t                 reader_pipe_id
    122                              );
    123 
    124 /*
    125 *************************** Function Definitions ***************************
    126 */
    127 
    128 #ifdef READER_INIT
    129 /*!
    130  * \brief Allocates the resources of RF Reader Managment Gate.
    131  *
    132  * This function Allocates the resources of the RF Reader Management
    133  * gate Information Structure.
    134  *
    135  */
    136 
    137 NFCSTATUS
    138 phHciNfc_ReaderMgmt_Init_Resources(
    139                                 phHciNfc_sContext_t     *psHciContext
    140                              )
    141 {
    142     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    143     phHciNfc_ReaderMgmt_Info_t  *p_reader_mgmt_info=NULL;
    144     if( NULL == psHciContext )
    145     {
    146         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    147     }
    148     else
    149     {
    150         if( ( NULL == psHciContext->p_reader_mgmt_info )
    151             && (phHciNfc_Allocate_Resource((void **)(&p_reader_mgmt_info),
    152                     sizeof(phHciNfc_ReaderMgmt_Info_t))== NFCSTATUS_SUCCESS)
    153         )
    154         {
    155             psHciContext->p_reader_mgmt_info = p_reader_mgmt_info;
    156             p_reader_mgmt_info->rf_gate_cur_seq = READERA_PIPE_OPEN;
    157             p_reader_mgmt_info->rf_gate_next_seq = END_READER_SEQUENCE;
    158         }
    159         else
    160         {
    161             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
    162         }
    163     }
    164     return status;
    165 }
    166 
    167 #endif
    168 
    169 /*!
    170  * \brief Updates the Sequence of RF Reader Managment Gate.
    171  *
    172  * This function Resets/Updates the sequence of the RF Reader Management
    173  * gate.
    174  *
    175  */
    176 
    177 NFCSTATUS
    178 phHciNfc_ReaderMgmt_Update_Sequence(
    179                                 phHciNfc_sContext_t     *psHciContext,
    180                                 phHciNfc_eSeqType_t     reader_seq
    181                              )
    182 {
    183     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    184     phHciNfc_ReaderMgmt_Info_t  *p_reader_mgmt_info = NULL;
    185     if( NULL == psHciContext )
    186     {
    187         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    188     }
    189     else
    190     {
    191         if( NULL == psHciContext->p_reader_mgmt_info )
    192         {
    193             status = PHNFCSTVAL(CID_NFC_HCI,
    194                         NFCSTATUS_INVALID_HCI_INFORMATION);
    195         }
    196         else
    197         {
    198             p_reader_mgmt_info = (phHciNfc_ReaderMgmt_Info_t *)
    199                                 psHciContext->p_reader_mgmt_info ;
    200             switch(reader_seq)
    201             {
    202                 case RESET_SEQ:
    203                 case INIT_SEQ:
    204                 {
    205                     p_reader_mgmt_info->rf_gate_cur_seq = READERA_PIPE_OPEN;
    206                     p_reader_mgmt_info->rf_gate_next_seq = END_READER_SEQUENCE;
    207                     break;
    208                 }
    209                 case UPDATE_SEQ:
    210                 {
    211                     p_reader_mgmt_info->rf_gate_cur_seq =
    212                                             p_reader_mgmt_info->rf_gate_next_seq;
    213                     break;
    214                 }
    215                 case INFO_SEQ:
    216                 {
    217                     status = phHciNfc_ReaderA_Update_Info(psHciContext,
    218                                             HCI_READER_A_INFO_SEQ, NULL);
    219 #if defined( TYPE_B )
    220                     status = phHciNfc_ReaderB_Update_Info(psHciContext,
    221                                             HCI_READER_B_INFO_SEQ, NULL);
    222 #endif /* end of #if defined(TYPE_B) */
    223 #if defined( TYPE_FELICA )
    224                     status = phHciNfc_Felica_Update_Info(psHciContext,
    225                                             HCI_FELICA_INFO_SEQ, NULL);
    226 #endif /* end of #if defined(TYPE_FELICA) */
    227 #if defined( TYPE_JEWEL )
    228                     status = phHciNfc_Jewel_Update_Info(psHciContext,
    229                                             HCI_JEWEL_INFO_SEQ, NULL);
    230 #endif /* end of #if defined(TYPE_JEWEL) */
    231 #if defined( TYPE_ISO15693 )
    232                     status = phHciNfc_ISO15693_Update_Info(psHciContext,
    233                                             HCI_ISO_15693_INFO_SEQ, NULL);
    234 #endif /* end of #if defined(TYPE_ISO15693) */
    235                     break;
    236                 }
    237                 case REL_SEQ:
    238                 {
    239                     p_reader_mgmt_info->rf_gate_cur_seq = READERA_PIPE_CLOSE;
    240                     p_reader_mgmt_info->rf_gate_next_seq = END_READER_SEQUENCE;
    241                     break;
    242                 }
    243                 default:
    244                 {
    245                     break;
    246                 }
    247             }
    248         }
    249     }
    250 
    251     return status;
    252 
    253 }
    254 
    255 
    256 /*!
    257  * \brief Initialisation of RF Reader Managment Gate.
    258  *
    259  * This function initialses the RF Reader Management gate and
    260  * populates the Reader Management Information Structure
    261  *
    262  */
    263 
    264 NFCSTATUS
    265 phHciNfc_ReaderMgmt_Initialise(
    266                                 phHciNfc_sContext_t     *psHciContext,
    267                                 void                    *pHwRef
    268                          )
    269 {
    270     NFCSTATUS                       status = NFCSTATUS_SUCCESS;
    271     phHciNfc_Pipe_Info_t            *p_pipe_info = NULL;
    272     phHciNfc_ReaderMgmt_Info_t      *p_reader_mgmt_info=NULL;
    273 
    274     if( NULL == psHciContext )
    275     {
    276         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    277     }
    278     else
    279     {
    280 
    281         if( ( NULL == psHciContext->p_reader_mgmt_info )
    282             && (phHciNfc_Allocate_Resource((void **)(&p_reader_mgmt_info),
    283                     sizeof(phHciNfc_ReaderMgmt_Info_t))== NFCSTATUS_SUCCESS)
    284         )
    285         {
    286             psHciContext->p_reader_mgmt_info = p_reader_mgmt_info;
    287             p_reader_mgmt_info->rf_gate_cur_seq = READERA_PIPE_OPEN;
    288             p_reader_mgmt_info->rf_gate_next_seq = END_READER_SEQUENCE;
    289         }
    290         else
    291         {
    292             p_reader_mgmt_info = (phHciNfc_ReaderMgmt_Info_t *)
    293                                 psHciContext->p_reader_mgmt_info ;
    294         }
    295 
    296         if( NULL == psHciContext->p_reader_mgmt_info )
    297         {
    298             status = PHNFCSTVAL(CID_NFC_HCI,
    299                                 NFCSTATUS_INSUFFICIENT_RESOURCES);
    300         }
    301 #ifdef ESTABLISH_SESSION
    302         else if( hciMode_Session == psHciContext->hci_mode )
    303         {
    304             status = NFCSTATUS_SUCCESS;
    305         }
    306 #endif
    307         else
    308         {
    309             switch(p_reader_mgmt_info->rf_gate_cur_seq )
    310             {
    311                 /* Reader A pipe open sequence */
    312                 case READERA_PIPE_OPEN:
    313                 {
    314                     p_pipe_info = ((phHciNfc_ReaderA_Info_t *)
    315                             psHciContext->p_reader_a_info)->p_pipe_info;
    316                     if(NULL == p_pipe_info )
    317                     {
    318                         status = PHNFCSTVAL(CID_NFC_HCI,
    319                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
    320                     }
    321                     else
    322                     {
    323                         status = phHciNfc_Open_Pipe( psHciContext,
    324                                                         pHwRef, p_pipe_info );
    325                         if(status == NFCSTATUS_SUCCESS)
    326                         {
    327                             uint8_t rdr_enable = TRUE;
    328                             status = phHciNfc_ReaderA_Update_Info(
    329                                     psHciContext, HCI_READER_A_ENABLE,
    330                                                             &rdr_enable);
    331 #if defined( TYPE_B )  && defined ( ENABLE_AUTO_ACTIVATE )
    332                             p_reader_mgmt_info->rf_gate_next_seq =
    333                                                     READERB_PIPE_OPEN;
    334                             status = NFCSTATUS_PENDING;
    335 /* end of #ifdef TYPE_B */
    336 #elif !defined( ENABLE_AUTO_ACTIVATE )
    337                             p_reader_mgmt_info->rf_gate_next_seq =
    338                                                         READERA_DISABLE_AUTO_ACTIVATE;
    339                             status = NFCSTATUS_PENDING;
    340 /* #ifdef ENABLE_AUTO_ACTIVATE */
    341 #elif defined( ENABLE_P2P )
    342                             p_reader_mgmt_info->rf_gate_next_seq =
    343                                                     NFCIP1_INITIATOR_PIPE_OPEN;
    344                             status = NFCSTATUS_PENDING;
    345 /* #ifdef ENABLE_P2P */
    346 #else
    347                             p_reader_mgmt_info->rf_gate_next_seq =
    348                                                 END_READER_SEQUENCE;
    349                             /* status = NFCSTATUS_PENDING; */
    350 #endif
    351                         }
    352                     }
    353                     break;
    354                 }
    355                 /* Reader A Auto Activate Disable */
    356                 case READERA_DISABLE_AUTO_ACTIVATE:
    357                 {
    358                     uint8_t     activate_enable = FALSE;
    359                     p_pipe_info = ((phHciNfc_ReaderA_Info_t *)
    360                             psHciContext->p_reader_a_info)->p_pipe_info;
    361                     if(NULL == p_pipe_info )
    362                     {
    363                         status = PHNFCSTVAL(CID_NFC_HCI,
    364                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
    365                     }
    366                     else
    367                     {
    368 
    369                         status = phHciNfc_ReaderA_Auto_Activate( psHciContext,
    370                                                         pHwRef, activate_enable );
    371                         if(status == NFCSTATUS_SUCCESS)
    372                         {
    373 #if defined (TYPE_B)
    374                             p_reader_mgmt_info->rf_gate_next_seq =
    375                                                     READERB_PIPE_OPEN;
    376                             status = NFCSTATUS_PENDING;
    377 /* end of #ifdef TYPE_B */
    378 #elif defined(TYPE_FELICA)
    379                             p_reader_mgmt_info->rf_gate_next_seq =
    380                                                         FELICA_PROP_PIPE_OPEN;
    381                             status = NFCSTATUS_PENDING;
    382 /* end of #elif defined(TYPE_FELICA) */
    383 #elif defined(TYPE_JEWEL)
    384                             p_reader_mgmt_info->rf_gate_next_seq =
    385                                                         JEWEL_PROP_PIPE_OPEN;
    386                             status = NFCSTATUS_PENDING;
    387 /* end of #elif defined(TYPE_JEWEL) */
    388 #elif defined (TYPE_ISO15693)
    389                             p_reader_mgmt_info->rf_gate_next_seq =
    390                                                     ISO15693_PROP_PIPE_OPEN;
    391                             status = NFCSTATUS_PENDING;
    392 /* end of #elif defined(TYPE_ISO15693) */
    393 #elif defined(ENABLE_P2P)
    394                             p_reader_mgmt_info->rf_gate_next_seq =
    395                                                     NFCIP1_INITIATOR_PIPE_OPEN;
    396                             status = NFCSTATUS_PENDING;
    397 /* end of #ifdef ENABLE_P2P */
    398 #else
    399                             p_reader_mgmt_info->rf_gate_next_seq =
    400                                                             END_READER_SEQUENCE;
    401                             /* status = NFCSTATUS_PENDING; */
    402 #endif /* #if !defined(ENABLE_P2P) && !defined(TYPE_B)*/
    403                         }
    404                     }
    405                     break;
    406                 }
    407 #ifdef TYPE_B
    408                 /* Reader B pipe open sequence */
    409                 case READERB_PIPE_OPEN:
    410                 {
    411                     p_pipe_info = ((phHciNfc_ReaderB_Info_t *)
    412                             psHciContext->p_reader_b_info)->p_pipe_info;
    413                     if(NULL == p_pipe_info )
    414                     {
    415                         status = PHNFCSTVAL(CID_NFC_HCI,
    416                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
    417                     }
    418                     else
    419                     {
    420                         status = phHciNfc_Open_Pipe( psHciContext,
    421                                                         pHwRef, p_pipe_info );
    422                         if(status == NFCSTATUS_SUCCESS)
    423                         {
    424 #if defined(TYPE_FELICA)
    425                             p_reader_mgmt_info->rf_gate_next_seq =
    426                                                         FELICA_PROP_PIPE_OPEN;
    427                             status = NFCSTATUS_PENDING;
    428 /* end of #ifdef TYPE_FELICA */
    429 #elif defined(TYPE_JEWEL)
    430                             p_reader_mgmt_info->rf_gate_next_seq =
    431                                                         JEWEL_PROP_PIPE_OPEN;
    432                             status = NFCSTATUS_PENDING;
    433 /* end of #elif defined(TYPE_JEWEL) */
    434 #elif defined (TYPE_ISO15693)
    435                             p_reader_mgmt_info->rf_gate_next_seq =
    436                                                     ISO15693_PROP_PIPE_OPEN;
    437                             status = NFCSTATUS_PENDING;
    438 /* end of #elif defined(TYPE_ISO15693) */
    439 #elif defined(ENABLE_P2P)
    440                             p_reader_mgmt_info->rf_gate_next_seq =
    441                                                     NFCIP1_INITIATOR_PIPE_OPEN;
    442                             status = NFCSTATUS_PENDING;
    443 /* end of #ifdef ENABLE_P2P */
    444 #else
    445                             p_reader_mgmt_info->rf_gate_next_seq =
    446                                                             END_READER_SEQUENCE;
    447                             /* status = NFCSTATUS_PENDING; */
    448 #endif /* #if !defined(ENABLE_P2P) && !defined(TYPE_FELICA)*/
    449                         }
    450                     }
    451                     break;
    452                 }
    453 #endif /* #ifdef TYPE_B */
    454 #ifdef TYPE_FELICA
    455                 /* Felica Reader pipe open sequence */
    456                 case FELICA_PROP_PIPE_OPEN:
    457                 {
    458                     p_pipe_info = ((phHciNfc_Felica_Info_t *)
    459                             psHciContext->p_felica_info)->p_pipe_info;
    460                     if(NULL == p_pipe_info )
    461                     {
    462                         status = PHNFCSTVAL(CID_NFC_HCI,
    463                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
    464                     }
    465                     else
    466                     {
    467                         status = phHciNfc_Open_Pipe( psHciContext,
    468                                                         pHwRef, p_pipe_info );
    469                         if(status == NFCSTATUS_SUCCESS)
    470                         {
    471 #if defined(TYPE_JEWEL)
    472                             p_reader_mgmt_info->rf_gate_next_seq =
    473                                                         JEWEL_PROP_PIPE_OPEN;
    474                             status = NFCSTATUS_PENDING;
    475 /* end of #if defined(TYPE_JEWEL) */
    476 #elif defined (TYPE_ISO15693)
    477                             p_reader_mgmt_info->rf_gate_next_seq =
    478                                                     ISO15693_PROP_PIPE_OPEN;
    479                             status = NFCSTATUS_PENDING;
    480 /* end of #elif defined(TYPE_ISO15693) */
    481 #elif defined(ENABLE_P2P)
    482                             p_reader_mgmt_info->rf_gate_next_seq =
    483                                                     NFCIP1_INITIATOR_PIPE_OPEN;
    484                             status = NFCSTATUS_PENDING;
    485  /* end of #ifdef ENABLE_P2P */
    486 #else
    487                             p_reader_mgmt_info->rf_gate_next_seq =
    488                                                             END_READER_SEQUENCE;
    489                             /* status = NFCSTATUS_PENDING; */
    490 #endif /* #if !defined(ENABLE_P2P) */
    491                         }
    492                     }
    493                     break;
    494                 }
    495 #endif
    496 #ifdef TYPE_JEWEL
    497                 /* Jewel Reader pipe open sequence */
    498                 case JEWEL_PROP_PIPE_OPEN:
    499                 {
    500                     p_pipe_info = ((phHciNfc_Jewel_Info_t *)
    501                             psHciContext->p_jewel_info)->p_pipe_info;
    502                     if(NULL == p_pipe_info )
    503                     {
    504                         status = PHNFCSTVAL(CID_NFC_HCI,
    505                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
    506                     }
    507                     else
    508                     {
    509                         status = phHciNfc_Open_Pipe( psHciContext,
    510                                                         pHwRef, p_pipe_info );
    511                         if(status == NFCSTATUS_SUCCESS)
    512                         {
    513 #if defined (TYPE_ISO15693)
    514                             p_reader_mgmt_info->rf_gate_next_seq =
    515                                                     ISO15693_PROP_PIPE_OPEN;
    516                             status = NFCSTATUS_PENDING;
    517 /* end of #if defined(TYPE_ISO15693) */
    518 #elif defined (ENABLE_P2P)
    519                             p_reader_mgmt_info->rf_gate_next_seq =
    520                                                     NFCIP1_INITIATOR_PIPE_OPEN;
    521                             status = NFCSTATUS_PENDING;
    522  /* end of #ifdef ENABLE_P2P */
    523 #else
    524                             p_reader_mgmt_info->rf_gate_next_seq =
    525                                                             END_READER_SEQUENCE;
    526                             /* status = NFCSTATUS_PENDING; */
    527 #endif /* #if !defined(ENABLE_P2P) */
    528                         }
    529                     }
    530                     break;
    531                 }
    532 #endif
    533 
    534 #ifdef TYPE_ISO15693
    535                 /* ISO15693 Reader pipe open sequence */
    536                 case ISO15693_PROP_PIPE_OPEN:
    537                 {
    538                     p_pipe_info = ((phHciNfc_ISO15693_Info_t *)
    539                         psHciContext->p_iso_15693_info)->ps_15693_pipe_info;
    540                     if(NULL == p_pipe_info )
    541                     {
    542                         status = PHNFCSTVAL(CID_NFC_HCI,
    543                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
    544                     }
    545                     else
    546                     {
    547                         status = phHciNfc_Open_Pipe( psHciContext,
    548                                                         pHwRef, p_pipe_info );
    549                         if(status == NFCSTATUS_SUCCESS)
    550                         {
    551 #ifdef ENABLE_P2P
    552                             p_reader_mgmt_info->rf_gate_next_seq =
    553                                                     NFCIP1_INITIATOR_PIPE_OPEN;
    554                             status = NFCSTATUS_PENDING;
    555  /* end of #ifdef ENABLE_P2P */
    556 #else
    557                             p_reader_mgmt_info->rf_gate_next_seq =
    558                                                             END_READER_SEQUENCE;
    559                             /* status = NFCSTATUS_PENDING; */
    560 #endif /* #if !defined(ENABLE_P2P) */
    561                         }
    562                     }
    563                     break;
    564                 }
    565 
    566 #endif
    567 
    568 #ifdef ENABLE_P2P
    569                 /* NFC-IP1 Initiator pipe open sequence */
    570                 case NFCIP1_INITIATOR_PIPE_OPEN:
    571                 {
    572                     p_pipe_info =
    573                         ((phHciNfc_NfcIP_Info_t *)psHciContext->
    574                                     p_nfcip_info)->p_init_pipe_info;
    575                     if(NULL == p_pipe_info )
    576                     {
    577                         status = PHNFCSTVAL(CID_NFC_HCI,
    578                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
    579                     }
    580                     else
    581                     {
    582                         status = phHciNfc_Open_Pipe( psHciContext,
    583                                                         pHwRef, p_pipe_info );
    584                         if(status == NFCSTATUS_SUCCESS)
    585                         {
    586                             p_reader_mgmt_info->rf_gate_next_seq =
    587                                                 NFCIP1_INITIATOR_MODE_CONFIG;
    588                             status = NFCSTATUS_PENDING;
    589                         }
    590                     }
    591                     break;
    592                 }
    593                 case NFCIP1_INITIATOR_MODE_CONFIG:
    594                 {
    595                     uint8_t mode = DEFAULT_NFCIP_MODE_SUPPORT;
    596                     status = phHciNfc_NfcIP_SetMode( psHciContext, pHwRef,
    597                                                 NFCIP_INITIATOR, mode);
    598                     if(status == NFCSTATUS_PENDING )
    599                     {
    600                         p_reader_mgmt_info->rf_gate_next_seq =
    601                                             NFCIP1_INITIATOR_PSL1_CONFIG;
    602                         /* status = NFCSTATUS_SUCCESS; */
    603                     }
    604                     break;
    605                 }
    606                 case NFCIP1_INITIATOR_PSL1_CONFIG:
    607                 {
    608                     uint8_t psl_config = NXP_NFCIP_PSL_BRS_DEFAULT;
    609                     status = phHciNfc_NfcIP_SetPSL1( psHciContext, pHwRef,
    610                                                 psl_config);
    611                     if(status == NFCSTATUS_PENDING )
    612                     {
    613                         p_reader_mgmt_info->rf_gate_next_seq =
    614                                                         END_READER_SEQUENCE;
    615                         status = NFCSTATUS_SUCCESS;
    616                     }
    617                     break;
    618                 }
    619 #endif
    620                 default:
    621                 {
    622                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
    623                     break;
    624                 }
    625 
    626             }/* End of the Sequence Switch */
    627 
    628         }/* End of the Reader Info Memory Check */
    629 
    630     } /* End of Null Context Check */
    631 
    632     return status;
    633 }
    634 
    635 
    636 /*!
    637  * \brief Initiate the Discovery for the RF Reader .
    638  *
    639  * This function starts the Polling Loop and initiates the discovery
    640  * of the Target.
    641  *
    642  */
    643 static
    644 NFCSTATUS
    645 phHciNfc_ReaderMgmt_Initiate_Discovery(
    646                                 phHciNfc_sContext_t     *psHciContext,
    647                                 void                    *pHwRef,
    648                                 uint8_t                 reader_pipe_id
    649                              )
    650 {
    651     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    652 
    653     if( ( NULL == psHciContext )
    654         || ( NULL == pHwRef )
    655         || ( HCI_UNKNOWN_PIPE_ID == reader_pipe_id)
    656         )
    657     {
    658         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    659     }
    660     else
    661     {
    662 
    663         status = phHciNfc_Send_RFReader_Event ( psHciContext, pHwRef,
    664                     reader_pipe_id,(uint8_t) EVT_READER_REQUESTED );
    665         status = ( (status == NFCSTATUS_PENDING)?
    666                                 NFCSTATUS_SUCCESS : status);
    667     }
    668     return status;
    669 }
    670 
    671 
    672 /*!
    673  * \brief End the Discovery of the RF Reader .
    674  *
    675  * This function stops the Polling Loop and ends the discovery
    676  * of the Target.
    677  *
    678  */
    679 static
    680 NFCSTATUS
    681 phHciNfc_ReaderMgmt_End_Discovery(
    682                                 phHciNfc_sContext_t     *psHciContext,
    683                                 void                    *pHwRef,
    684                                 uint8_t                 reader_pipe_id
    685                              )
    686 {
    687     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    688 
    689     if( ( NULL == psHciContext )
    690         || ( NULL == pHwRef )
    691         || ( HCI_UNKNOWN_PIPE_ID == reader_pipe_id)
    692         )
    693     {
    694         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    695     }
    696     else
    697     {
    698 
    699         status = phHciNfc_Send_RFReader_Event ( psHciContext, pHwRef,
    700                     reader_pipe_id,(uint8_t) EVT_END_OPERATION );
    701         status = ( (status == NFCSTATUS_PENDING)?
    702                                 NFCSTATUS_SUCCESS : status);
    703     }
    704     return status;
    705 }
    706 
    707 
    708 /*!
    709  * \brief Enable the Discovery of RF Reader Managment Gate.
    710  *
    711  * This function Enable the discovery of the RF Reader Management
    712  * gate.
    713  *
    714  */
    715 
    716 
    717 NFCSTATUS
    718 phHciNfc_ReaderMgmt_Enable_Discovery(
    719                                 phHciNfc_sContext_t     *psHciContext,
    720                                 void                    *pHwRef
    721                              )
    722 {
    723     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    724     phHciNfc_ReaderMgmt_Info_t  *p_reader_mgmt_info=NULL;
    725     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
    726     /* phHal_sADD_Cfg_t    *p_poll_config = (phHal_sADD_Cfg_t * )
    727                                             psHciContext->p_config_params; */
    728     PHNFC_UNUSED_VARIABLE(p_reader_mgmt_info);
    729     if( NULL != psHciContext->p_reader_mgmt_info )
    730     {
    731         uint8_t rdr_enable = FALSE;
    732         p_reader_mgmt_info = (phHciNfc_ReaderMgmt_Info_t *)
    733                             psHciContext->p_reader_mgmt_info ;
    734 #ifdef TYPE_B
    735         if ( (NULL != psHciContext->p_reader_b_info )
    736              /*   && (FALSE == rdr_enable) */
    737         )
    738         {
    739             /* Get the Reader B Pipe ID */
    740             status = phHciNfc_ReaderB_Get_PipeID
    741                                     (psHciContext, &reader_pipe_id);
    742 
    743             if( NFCSTATUS_SUCCESS == status )
    744             {
    745                 rdr_enable = (uint8_t)TRUE;
    746                 /* rdr_enable = (uint8_t)
    747                         p_poll_config->PollDevInfo.PollCfgInfo.EnableIso14443B; */
    748                 status =    phHciNfc_ReaderB_Update_Info(psHciContext,
    749                                         HCI_RDR_ENABLE_TYPE, &rdr_enable);
    750             }
    751         }
    752 #endif
    753 #ifdef TYPE_FELICA
    754         if ( (NULL != psHciContext->p_felica_info )
    755                /* && (FALSE == rdr_enable) */
    756         )
    757         {
    758             /* Get the Reader F Pipe ID */
    759             status = phHciNfc_Felica_Get_PipeID
    760                                     (psHciContext, &reader_pipe_id);
    761 
    762             if( NFCSTATUS_SUCCESS == status )
    763             {
    764                 rdr_enable = (uint8_t)TRUE;
    765                /* rdr_enable = (uint8_t)
    766                     ( p_poll_config->PollDevInfo.PollCfgInfo.EnableFelica212
    767                         || p_poll_config->PollDevInfo.PollCfgInfo.EnableFelica424 ); */
    768                 status =    phHciNfc_Felica_Update_Info(psHciContext,
    769                                         HCI_RDR_ENABLE_TYPE, &rdr_enable);
    770             }
    771         }
    772 #endif
    773 #ifdef TYPE_JEWEL
    774         if ( (NULL != psHciContext->p_jewel_info )
    775                /* && (FALSE == rdr_enable) */
    776         )
    777         {
    778             /* Get the Reader F Pipe ID */
    779             status = phHciNfc_Jewel_Get_PipeID
    780                                     (psHciContext, &reader_pipe_id);
    781 
    782             if( NFCSTATUS_SUCCESS == status )
    783             {
    784                 rdr_enable = (uint8_t)TRUE;
    785                 status =    phHciNfc_Jewel_Update_Info(psHciContext,
    786                                         HCI_RDR_ENABLE_TYPE, &rdr_enable);
    787             }
    788         }
    789 #endif /* #ifdef TYPE_JEWEL */
    790 #if defined(TYPE_ISO15693)
    791         if ( (NULL != psHciContext->p_iso_15693_info )
    792                /* && (FALSE == rdr_enable) */
    793         )
    794         {
    795             /* Get the Reader F Pipe ID */
    796             status = phHciNfc_ISO15693_Get_PipeID
    797                                     (psHciContext, &reader_pipe_id);
    798 
    799             if( NFCSTATUS_SUCCESS == status )
    800             {
    801                 rdr_enable = (uint8_t)TRUE;
    802                 status =    phHciNfc_ISO15693_Update_Info(psHciContext,
    803                                         HCI_RDR_ENABLE_TYPE, &rdr_enable);
    804             }
    805         }
    806 
    807 /* end of #elif defined(TYPE_ISO15693) */
    808 #endif
    809 
    810         if(NULL != psHciContext->p_reader_a_info)
    811         {
    812             /* Get the Reader A Pipe ID */
    813             status = phHciNfc_ReaderA_Get_PipeID
    814                                     (psHciContext, &reader_pipe_id);
    815 
    816             if( NFCSTATUS_SUCCESS == status )
    817             {
    818                 rdr_enable = (uint8_t)TRUE;
    819                 status =    phHciNfc_ReaderA_Update_Info(psHciContext,
    820                                         HCI_RDR_ENABLE_TYPE, &rdr_enable);
    821             }
    822 
    823         }
    824         if( ( NFCSTATUS_SUCCESS == status )
    825             && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
    826           )
    827         {
    828             status = phHciNfc_ReaderMgmt_Initiate_Discovery( psHciContext,
    829                          pHwRef, reader_pipe_id);
    830         }
    831 
    832     }/* End of the Reader Info Memory Check */
    833 
    834     return status;
    835 }
    836 
    837 /*!
    838  * \brief Disable the Discovery of RF Reader Managment Gate.
    839  *
    840  * This function Disable the discovery of the RF Reader Management
    841  * gate.
    842  *
    843  */
    844 
    845 NFCSTATUS
    846 phHciNfc_ReaderMgmt_Disable_Discovery(
    847                                 phHciNfc_sContext_t     *psHciContext,
    848                                 void                    *pHwRef
    849                              )
    850 {
    851     NFCSTATUS                   status = NFCSTATUS_FAILED;
    852     phHciNfc_ReaderMgmt_Info_t  *p_reader_mgmt_info=NULL;
    853     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
    854     /* phHal_sADD_Cfg_t         *p_poll_config = (phHal_sADD_Cfg_t * )
    855                                             psHciContext->p_config_params; */
    856     PHNFC_UNUSED_VARIABLE(p_reader_mgmt_info);
    857     if( NULL != psHciContext->p_reader_mgmt_info )
    858     {
    859         p_reader_mgmt_info = (phHciNfc_ReaderMgmt_Info_t *)
    860                             psHciContext->p_reader_mgmt_info ;
    861         if(NULL != psHciContext->p_reader_a_info)
    862         {
    863             /* Get the Reader A Pipe ID */
    864             status = phHciNfc_ReaderA_Get_PipeID
    865                                     (psHciContext, &reader_pipe_id);
    866 #if 0
    867             if( NFCSTATUS_SUCCESS == status )
    868             {
    869                 uint8_t rdr_enable = (uint8_t) FALSE;
    870                 status =    phHciNfc_ReaderA_Update_Info(psHciContext,
    871                                         HCI_RDR_ENABLE_TYPE, &rdr_enable);
    872             }
    873 #endif
    874 
    875         }
    876 #ifdef TYPE_B
    877         else if((NULL != psHciContext->p_reader_b_info )
    878             /* && (NFCSTATUS_SUCCESS != status) */
    879             )
    880         {
    881             /* Get the Reader B Pipe ID */
    882             status = phHciNfc_ReaderB_Get_PipeID
    883                                     (psHciContext, &reader_pipe_id);
    884         }
    885 #endif
    886 #ifdef TYPE_FELICA
    887         else if((NULL != psHciContext->p_felica_info )
    888             /* && (NFCSTATUS_SUCCESS != status) */
    889             )
    890         {
    891             /* Get the Reader B Pipe ID */
    892             status = phHciNfc_Felica_Get_PipeID
    893                                     (psHciContext, &reader_pipe_id);
    894         }
    895 #endif
    896 #ifdef TYPE_JEWEL
    897         else if((NULL != psHciContext->p_jewel_info )
    898             /* && (NFCSTATUS_SUCCESS != status) */
    899             )
    900         {
    901             /* Get the Reader B Pipe ID */
    902             status = phHciNfc_Jewel_Get_PipeID
    903                                     (psHciContext, &reader_pipe_id);
    904         }
    905 #endif /* #ifdef TYPE_JEWEL */
    906 #ifdef  TYPE_ISO15693
    907         else if((NULL != psHciContext->p_iso_15693_info )
    908             /* && (NFCSTATUS_SUCCESS != status) */
    909             )
    910         {
    911             /* Get the Reader B Pipe ID */
    912             status = phHciNfc_ISO15693_Get_PipeID
    913                                     (psHciContext, &reader_pipe_id);
    914         }
    915 #endif /* #ifdef    TYPE_ISO15693 */
    916 
    917         else
    918         {
    919             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_NOT_ALLOWED);
    920         }
    921 
    922         if( (NFCSTATUS_SUCCESS == status)
    923             && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
    924             )
    925         {
    926             status = phHciNfc_ReaderMgmt_End_Discovery( psHciContext,
    927                          pHwRef, reader_pipe_id);
    928         }
    929 
    930     }/* End of the Reader Info Memory Check */
    931 
    932     return status;
    933 }
    934 
    935 
    936 
    937 
    938 /*!
    939 * \brief Updates the Sequence of RF Reader Managment Gate.
    940 *
    941 * This function Resets/Updates the sequence of the RF Reader Management
    942 * gate.
    943 *
    944 */
    945 
    946 NFCSTATUS
    947 phHciNfc_ReaderMgmt_Info_Sequence(
    948                                    phHciNfc_sContext_t      *psHciContext,
    949                                    void                     *pHwRef
    950                                )
    951 {
    952 #if defined(NXP_NFCIP_ACTIVATE_DELAY)
    953     static uint8_t              nfc_atr_retry = 0;
    954 #endif
    955     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    956     phHciNfc_ReaderMgmt_Info_t  *p_reader_mgmt_info=NULL;
    957 #if 0
    958     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
    959     phHal_eRemDevType_t         target_type = phHal_eUnknown_DevType;
    960 #endif
    961 
    962 
    963     PHNFC_UNUSED_VARIABLE(p_reader_mgmt_info);
    964     if( NULL == psHciContext )
    965     {
    966         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    967     }
    968     else
    969     {
    970         if( NULL != psHciContext->p_reader_mgmt_info )
    971         {
    972             p_reader_mgmt_info = (phHciNfc_ReaderMgmt_Info_t *)
    973                 psHciContext->p_reader_mgmt_info ;
    974             switch( psHciContext->host_rf_type )
    975             {
    976 
    977                 case phHal_eISO14443_A_PCD:
    978                 {
    979                     /* If the Target Info is updated then the Target
    980                      * is connected.
    981                      */
    982                     if(NULL == psHciContext->p_target_info)
    983                     {
    984 #if defined(NXP_NFCIP_ACTIVATE_DELAY)
    985                         nfc_atr_retry = 0;
    986 #endif
    987                         status = phHciNfc_ReaderA_Info_Sequence(
    988                                                     psHciContext, pHwRef );
    989                     }
    990                     else
    991                     {
    992                             status = phHciNfc_ReaderA_App_Data(
    993                                                 psHciContext, pHwRef );
    994                             status = ((NFCSTATUS_PENDING == status )?
    995                                         NFCSTATUS_SUCCESS : status);
    996                     }
    997                     break;
    998                 }
    999 #ifdef ENABLE_P2P
   1000                 case phHal_eNfcIP1_Initiator:
   1001                 {
   1002                     /* If the Target Info is updated then the Target
   1003                      * is connected.
   1004                      */
   1005 #ifdef NFCIP_CHECK
   1006                     if(NULL == psHciContext->p_target_info)
   1007 #endif
   1008                     {
   1009                         status = phHciNfc_NfcIP_Info_Sequence(
   1010                                   psHciContext, pHwRef
   1011 #ifdef NOTIFY_REQD
   1012                                     ,(NULL == psHciContext->p_target_info)
   1013 #endif /* #ifdef NOTIFY_REQD */
   1014                                            );
   1015                     }
   1016 #ifdef NFCIP_CHECK
   1017                     else
   1018                     {
   1019                         status = phHciNfc_NfcIP_GetATRInfo(
   1020                                             psHciContext, pHwRef, NFCIP_INITIATOR );
   1021 #if defined(NXP_NFCIP_ACTIVATE_DELAY)
   1022                         if (
   1023                             (NFCSTATUS_PENDING == status)
   1024                             && ( NFCIP_ACTIVATE_DELAY <= nfc_atr_retry)
   1025                             )
   1026                         {
   1027                             nfc_atr_retry = 0;
   1028                             status = NFCSTATUS_SUCCESS;
   1029                         }
   1030                         else
   1031                         {
   1032                             nfc_atr_retry++;
   1033                         }
   1034 #else
   1035                         status = ((NFCSTATUS_PENDING == status )?
   1036                                         NFCSTATUS_SUCCESS : status);
   1037 #endif
   1038                     }
   1039 #endif
   1040                     break;
   1041                 }
   1042 #endif
   1043 #ifdef TYPE_B
   1044                 case phHal_eISO14443_B_PCD:
   1045                 {
   1046                     if(NULL == psHciContext->p_target_info)
   1047                     {
   1048                         status = phHciNfc_ReaderB_Info_Sequence(
   1049                                                     psHciContext, pHwRef );
   1050                     }
   1051                     break;
   1052                 }
   1053 #endif /* #ifdef TYPE_B */
   1054 #ifdef TYPE_FELICA
   1055                 case phHal_eFelica_PCD:
   1056                 {
   1057                     if(NULL == psHciContext->p_target_info)
   1058                     {
   1059 #if defined(NXP_NFCIP_ACTIVATE_DELAY)
   1060                         nfc_atr_retry = 0;
   1061 #endif
   1062                         status = phHciNfc_Felica_Info_Sequence(
   1063                                                     psHciContext, pHwRef );
   1064                     }
   1065                     break;
   1066                 }
   1067 #endif /* #ifdef TYPE_FELICA */
   1068 #ifdef TYPE_JEWEL
   1069                 case phHal_eJewel_PCD:
   1070                 {
   1071                     if(NULL == psHciContext->p_target_info)
   1072                     {
   1073                         status = phHciNfc_Jewel_Info_Sequence(
   1074                                                     psHciContext, pHwRef );
   1075                     }
   1076                     break;
   1077                 }
   1078 #endif /* #ifdef TYPE_JEWEL */
   1079 #if defined(TYPE_ISO15693)
   1080                 case phHal_eISO15693_PCD:
   1081                 {
   1082                     if(NULL == psHciContext->p_target_info)
   1083                     {
   1084                         status = phHciNfc_ISO15693_Info_Sequence(
   1085                                                     psHciContext, pHwRef );
   1086                     }
   1087                     break;
   1088                 }
   1089 #endif
   1090                 default:
   1091                 {
   1092                     break;
   1093                 }
   1094             }
   1095 
   1096         }/* End of the Reader Info Memory Check */
   1097 
   1098     } /* End of Null Context Check */
   1099 
   1100     return status;
   1101 
   1102 }
   1103 
   1104 
   1105 /*!
   1106  * \brief Connects the the selected tag via RF Reader Gates.
   1107  *
   1108  * This function connects the selected tags via RF Reader Gate.
   1109  * This function uses the RF Reader gate based on the type of the
   1110  * tag specified.
   1111  */
   1112 
   1113 
   1114 NFCSTATUS
   1115 phHciNfc_ReaderMgmt_Select(
   1116                                     phHciNfc_sContext_t     *psHciContext,
   1117                                     void                    *pHwRef,
   1118                                     phHal_eRemDevType_t     target_type
   1119                 )
   1120 {
   1121     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1122     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
   1123 
   1124     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1125     {
   1126       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1127     }
   1128     else
   1129     {
   1130         switch (target_type)
   1131         {
   1132             case phHal_eMifare_PICC:
   1133             case phHal_eISO14443_3A_PICC:
   1134             {
   1135                 /* Get the Reader A Pipe ID */
   1136                 status = phHciNfc_ReaderA_Get_PipeID
   1137                                         (psHciContext, &reader_pipe_id);
   1138 
   1139                 if( (NFCSTATUS_SUCCESS == status)
   1140                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1141                     )
   1142                 {
   1143                     status = phHciNfc_ReaderMgmt_Reactivate(
   1144                             psHciContext, pHwRef, target_type );
   1145                 }
   1146                 break;
   1147             }
   1148             case phHal_eISO14443_A_PICC:
   1149             case phHal_eISO14443_4A_PICC:
   1150             {
   1151 #ifdef ENABLE_AUTO_ACTIVATE
   1152                 /* Get the Reader A Pipe ID */
   1153                 status = phHciNfc_ReaderA_Get_PipeID
   1154                                         (psHciContext, &reader_pipe_id);
   1155 
   1156                 if( (NFCSTATUS_SUCCESS == status)
   1157                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1158                     )
   1159                 {
   1160                     status = phHciNfc_Send_RFReader_Command (psHciContext,
   1161                                     pHwRef, reader_pipe_id, NXP_WR_PRESCHECK );
   1162                 }
   1163 #else
   1164                 status = phHciNfc_ReaderA_Cont_Activate(
   1165                                                     psHciContext, pHwRef);
   1166 #endif /* #ifdef ENABLE_AUTO_ACTIVATE */
   1167                 break;
   1168             }
   1169 #ifdef TYPE_B
   1170             case phHal_eISO14443_B_PICC:
   1171             case phHal_eISO14443_4B_PICC:
   1172             {
   1173                 /* Get the Reader B Pipe ID */
   1174                 status = phHciNfc_ReaderB_Get_PipeID
   1175                                         (psHciContext, &reader_pipe_id);
   1176 
   1177                 if( (NFCSTATUS_SUCCESS == status)
   1178                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1179                     )
   1180                 {
   1181                     status = phHciNfc_Send_RFReader_Command (psHciContext,
   1182                                     pHwRef, reader_pipe_id, NXP_WR_PRESCHECK );
   1183                     /* status = phHciNfc_ReaderA_Set_DataRateMax(
   1184                                         psHciContext, pHwRef,
   1185                                         DATA_RATE_MAX_DEFAULT_VALUE ); */
   1186                     /* status = phHciNfc_ReaderMgmt_Reactivate(
   1187                             psHciContext, pHwRef, target_type ); */
   1188                 }
   1189                 break;
   1190             }
   1191 #endif /* #ifdef TYPE_B */
   1192 #ifdef TYPE_FELICA
   1193             case phHal_eFelica_PICC:
   1194             {
   1195                 status = phHciNfc_Felica_Get_PipeID
   1196                                         (psHciContext, &reader_pipe_id);
   1197 
   1198                 if( (NFCSTATUS_SUCCESS == status)
   1199                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1200                     )
   1201                 {
   1202                     /* Get the Reader Felica Pipe ID */
   1203                     /* status = phHciNfc_ReaderA_Set_DataRateMax(
   1204                                         psHciContext, pHwRef,
   1205                                         DATA_RATE_MAX_DEFAULT_VALUE ); */
   1206                     status = phHciNfc_ReaderMgmt_Reactivate(
   1207                             psHciContext, pHwRef, target_type );
   1208                 }
   1209                 break;
   1210             }
   1211 #endif /* #ifdef TYPE_FELICA */
   1212 #ifdef TYPE_JEWEL
   1213             case phHal_eJewel_PICC:
   1214             {
   1215                 /* Get the Reader jewel Pipe ID */
   1216                 status = phHciNfc_Jewel_Get_PipeID
   1217                                         (psHciContext, &reader_pipe_id);
   1218 
   1219                 if( (NFCSTATUS_SUCCESS == status)
   1220                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1221                     )
   1222                 {
   1223                     status = phHciNfc_Jewel_GetRID(
   1224                                         psHciContext, pHwRef);
   1225                 }
   1226                 break;
   1227             }
   1228 #endif /* #ifdef TYPE_JEWEL */
   1229 #ifdef  TYPE_ISO15693
   1230             case phHal_eISO15693_PICC:
   1231             {
   1232                 /* Get the Reader ISO 15693 Pipe ID */
   1233                 status = phHciNfc_ISO15693_Get_PipeID
   1234                                         (psHciContext, &reader_pipe_id);
   1235 
   1236                 if( (NFCSTATUS_SUCCESS == status)
   1237                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1238                     )
   1239                 {
   1240                     /* TODO */
   1241                     status = phHciNfc_ReaderA_Set_DataRateMax(
   1242                                         psHciContext, pHwRef,
   1243                                         DATA_RATE_MAX_DEFAULT_VALUE );
   1244                 }
   1245                 break;
   1246             }
   1247 #endif /* #ifdef    TYPE_ISO15693 */
   1248 #ifdef ENABLE_P2P
   1249             case phHal_eNfcIP1_Target:
   1250             {
   1251                 if ( (phHal_eISO14443_A_PCD ==
   1252                             psHciContext->host_rf_type )
   1253                    || (phHal_eFelica_PCD ==
   1254                             psHciContext->host_rf_type )
   1255                    )
   1256                 {
   1257                     status = phHciNfc_Initiator_Cont_Activate(
   1258                                                     psHciContext, pHwRef);
   1259                 }
   1260                 else
   1261                 {
   1262                     status = phHciNfc_NfcIP_Presence_Check (psHciContext, pHwRef);
   1263                 }
   1264                 break;
   1265             }
   1266 #endif
   1267 #if 0
   1268             case phHal_eNfcIP1_Initiator:
   1269             {
   1270 
   1271                 break;
   1272             }
   1273 #endif
   1274             default:
   1275             {
   1276                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1277                 break;
   1278             }
   1279 
   1280         } /* End of the tag_type Switch */
   1281     }
   1282 
   1283     return status;
   1284 }
   1285 
   1286 NFCSTATUS
   1287 phHciNfc_ReaderMgmt_UICC_Dispatch(
   1288                                     phHciNfc_sContext_t     *psHciContext,
   1289                                     void                    *pHwRef,
   1290                                     phHal_eRemDevType_t     target_type
   1291                 )
   1292 {
   1293     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1294     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
   1295     phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
   1296 
   1297 
   1298     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1299     {
   1300       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1301     }
   1302     else if (NULL == psHciContext->p_target_info)
   1303     {
   1304         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
   1305     }
   1306     else
   1307     {
   1308         switch (target_type)
   1309         {
   1310             case phHal_eISO14443_A_PICC:
   1311             case phHal_eISO14443_4A_PICC:
   1312             {
   1313                 /* Get the Reader A Pipe ID */
   1314                 status = phHciNfc_ReaderA_Get_PipeID(
   1315                                     psHciContext, &reader_pipe_id);
   1316                 p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1317                 p_pipe_info->param_info = &psHciContext->p_target_info->
   1318                                     RemoteDevInfo.Iso14443A_Info.Uid;
   1319                 p_pipe_info->param_length = psHciContext->p_target_info->
   1320                                     RemoteDevInfo.Iso14443A_Info.UidLength;
   1321 
   1322                 break;
   1323             }
   1324 #ifdef TYPE_B
   1325             case phHal_eISO14443_B_PICC:
   1326             case phHal_eISO14443_4B_PICC:
   1327             {
   1328                 /* Get the Reader B Pipe ID */
   1329                 status = phHciNfc_ReaderB_Get_PipeID
   1330                     (psHciContext, &reader_pipe_id);
   1331 
   1332                 p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1333                 p_pipe_info->param_info = &psHciContext->p_target_info->
   1334                         RemoteDevInfo.Iso14443B_Info.AtqB.AtqResInfo.Pupi;
   1335                 p_pipe_info->param_length = PHHAL_PUPI_LENGTH;
   1336                 break;
   1337             }
   1338 #endif /* #ifdef TYPE_B */
   1339             case phHal_eMifare_PICC:
   1340             case phHal_eISO14443_3A_PICC:
   1341             default:
   1342             {
   1343                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1344                 break;
   1345             }
   1346 
   1347         } /* End of the tag_type Switch */
   1348     }
   1349     if( (NFCSTATUS_SUCCESS == status)
   1350         && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1351         )
   1352     {
   1353         status = phHciNfc_Send_RFReader_Command (psHciContext,
   1354                         pHwRef, reader_pipe_id, NXP_WR_DISPATCH_TO_UICC );
   1355     }
   1356 
   1357     return status;
   1358 }
   1359 
   1360 
   1361 NFCSTATUS
   1362 phHciNfc_ReaderMgmt_Reactivate(
   1363                                     phHciNfc_sContext_t     *psHciContext,
   1364                                     void                    *pHwRef,
   1365                                     phHal_eRemDevType_t     target_type
   1366                 )
   1367 {
   1368     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1369     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
   1370     phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
   1371 
   1372 
   1373     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1374     {
   1375       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1376     }
   1377     else if (NULL == psHciContext->p_target_info)
   1378     {
   1379         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
   1380     }
   1381     else
   1382     {
   1383         switch (target_type)
   1384         {
   1385             case phHal_eISO14443_A_PICC:
   1386             case phHal_eMifare_PICC:
   1387             case phHal_eISO14443_4A_PICC:
   1388             case phHal_eISO14443_3A_PICC:
   1389             {
   1390                 /* Get the Reader A Pipe ID */
   1391                 status = phHciNfc_ReaderA_Get_PipeID(
   1392                                     psHciContext, &reader_pipe_id);
   1393                 p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1394                 p_pipe_info->param_info = &psHciContext->p_target_info->
   1395                                     RemoteDevInfo.Iso14443A_Info.Uid;
   1396                 p_pipe_info->param_length = psHciContext->p_target_info->
   1397                                     RemoteDevInfo.Iso14443A_Info.UidLength;
   1398 
   1399                 break;
   1400             }
   1401 #ifdef TYPE_B
   1402             case phHal_eISO14443_B_PICC:
   1403             case phHal_eISO14443_4B_PICC:
   1404             {
   1405                 /* Get the Reader B Pipe ID */
   1406                 status = phHciNfc_ReaderB_Get_PipeID
   1407                     (psHciContext, &reader_pipe_id);
   1408 
   1409                 p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1410                 p_pipe_info->param_info = &psHciContext->p_target_info->
   1411                         RemoteDevInfo.Iso14443B_Info.AtqB.AtqResInfo.Pupi;
   1412                 p_pipe_info->param_length = PHHAL_PUPI_LENGTH;
   1413                 break;
   1414             }
   1415 #endif /* #ifdef TYPE_B */
   1416 #ifdef TYPE_FELICA
   1417             case phHal_eFelica_PICC:
   1418             {
   1419                 /* Get the Felica Reader Pipe ID */
   1420                 status = phHciNfc_Felica_Get_PipeID
   1421                                         (psHciContext, &reader_pipe_id);
   1422 
   1423                 if( (NFCSTATUS_SUCCESS == status)
   1424                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1425                     )
   1426                 {
   1427                 p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1428                 p_pipe_info->param_info = &psHciContext->p_target_info->
   1429                     RemoteDevInfo.Felica_Info.IDm;
   1430                 p_pipe_info->param_length = PHHAL_FEL_ID_LEN;
   1431                 }
   1432                 break;
   1433             }
   1434 #endif /* #ifdef TYPE_FELICA */
   1435 #ifdef ENABLE_P2P
   1436             case phHal_eNfcIP1_Target:
   1437             {
   1438                 /* Get the Initiator Pipe ID */
   1439                 status = phHciNfc_Initiator_Get_PipeID(
   1440                                     psHciContext, &reader_pipe_id);
   1441                 p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1442                 p_pipe_info->param_info = &psHciContext->p_target_info->
   1443                                             RemoteDevInfo.NfcIP_Info.NFCID;
   1444                 p_pipe_info->param_length = psHciContext->p_target_info->
   1445                                         RemoteDevInfo.NfcIP_Info.NFCID_Length;
   1446                 break;
   1447             }
   1448             case phHal_eNfcIP1_Initiator:
   1449             {
   1450                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1451                 break;
   1452             }
   1453 #endif /* #ifdef ENABLE_P2P */
   1454             default:
   1455             {
   1456                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1457                 break;
   1458             }
   1459 
   1460         } /* End of the tag_type Switch */
   1461     }
   1462     if( (NFCSTATUS_SUCCESS == status)
   1463         && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1464         )
   1465     {
   1466         status = phHciNfc_Send_RFReader_Command (psHciContext,
   1467                         pHwRef, reader_pipe_id, NXP_WR_ACTIVATE_ID );
   1468     }
   1469 
   1470     return status;
   1471 }
   1472 
   1473 
   1474 /*!
   1475 * \brief Activates the next Remote Target in the field.
   1476 *
   1477 * This function selects and activates the next tag present in the field.
   1478 */
   1479 
   1480 
   1481 NFCSTATUS
   1482 phHciNfc_ReaderMgmt_Activate_Next(
   1483                                   phHciNfc_sContext_t       *psHciContext,
   1484                                   void                  *pHwRef
   1485                                   )
   1486 {
   1487     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1488     /* phHciNfc_Pipe_Info_t     *p_pipe_info = NULL; */
   1489     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
   1490 
   1491     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1492     {
   1493         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1494     }
   1495     else
   1496     {
   1497         switch ( psHciContext->host_rf_type )
   1498         {
   1499             case phHal_eISO14443_A_PCD:
   1500             {
   1501                 /* Get the Reader A Pipe ID */
   1502                 status = phHciNfc_ReaderA_Get_PipeID
   1503                     (psHciContext, &reader_pipe_id);
   1504 
   1505                 break;
   1506             }
   1507 #ifdef TYPE_B
   1508             case phHal_eISO14443_B_PCD:
   1509             {
   1510                 /* Get the Reader B Pipe ID */
   1511                 status = phHciNfc_ReaderB_Get_PipeID
   1512                     (psHciContext, &reader_pipe_id);
   1513 
   1514                 break;
   1515             }
   1516 #endif /* #ifdef TYPE_B */
   1517 #ifdef TYPE_FELICA
   1518             case phHal_eFelica_PCD:
   1519             {
   1520                 /* Get the Felica Reader Pipe ID */
   1521                 status = phHciNfc_Felica_Get_PipeID
   1522                                         (psHciContext, &reader_pipe_id);
   1523 
   1524                 break;
   1525             }
   1526 #endif /* #ifdef TYPE_FELICA */
   1527 #ifdef  TYPE_ISO15693
   1528             case phHal_eISO15693_PCD:
   1529             {
   1530                 /* Get the ISO 15693 Reader Pipe ID */
   1531                 status = phHciNfc_ISO15693_Get_PipeID
   1532                                         (psHciContext, &reader_pipe_id);
   1533 
   1534                 break;
   1535             }
   1536 #endif /* #ifdef TYPE_ISO15693 */
   1537             default:
   1538             {
   1539                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1540                 break;
   1541             }
   1542 
   1543         } /* End of the reader_type Switch */
   1544         if( (NFCSTATUS_SUCCESS == status)
   1545             && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1546           )
   1547         {
   1548             status = phHciNfc_Send_RFReader_Command (psHciContext,
   1549                 pHwRef, reader_pipe_id, NXP_WR_ACTIVATE_NEXT );
   1550         }
   1551 
   1552     }
   1553 
   1554     return status;
   1555 
   1556 }
   1557 
   1558 /*!
   1559 * \brief Checks the presence of the Remote Target in the field.
   1560 *
   1561 * This function checks the presence of the tag present in the field.
   1562 */
   1563 
   1564 
   1565 NFCSTATUS
   1566 phHciNfc_ReaderMgmt_Presence_Check(
   1567                                   phHciNfc_sContext_t       *psHciContext,
   1568                                   void                  *pHwRef
   1569                                   )
   1570 {
   1571     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1572     /* phHciNfc_Pipe_Info_t     *p_pipe_info = NULL; */
   1573     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
   1574     phHal_eRemDevType_t         target_type = phHal_eUnknown_DevType;
   1575 
   1576     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1577     {
   1578         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1579     }
   1580     else
   1581     {
   1582         target_type = psHciContext->p_target_info->RemDevType;
   1583         switch (target_type)
   1584         {
   1585             case phHal_eMifare_PICC:
   1586             case phHal_eISO14443_3A_PICC:
   1587             {
   1588                 /* Get the Reader A Pipe ID */
   1589                 status = phHciNfc_ReaderA_Get_PipeID
   1590                     (psHciContext, &reader_pipe_id);
   1591 
   1592                 if( (NFCSTATUS_SUCCESS == status)
   1593                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1594                     )
   1595                 {
   1596                     status = phHciNfc_ReaderMgmt_Reactivate(
   1597                             psHciContext, pHwRef, target_type );
   1598                 }
   1599                 break;
   1600             }
   1601             case phHal_eISO14443_A_PICC:
   1602             case phHal_eISO14443_4A_PICC:
   1603             {
   1604                 /* Get the Reader A Pipe ID */
   1605                 status = phHciNfc_ReaderA_Get_PipeID
   1606                     (psHciContext, &reader_pipe_id);
   1607 
   1608                 if( (NFCSTATUS_SUCCESS == status)
   1609                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1610                     )
   1611                 {
   1612                     status = phHciNfc_Send_RFReader_Command (psHciContext,
   1613                         pHwRef, reader_pipe_id, NXP_WR_PRESCHECK );
   1614                 }
   1615                 break;
   1616             }
   1617 #ifdef ENABLE_P2P
   1618             case phHal_eNfcIP1_Target:
   1619             {
   1620                 status = phHciNfc_NfcIP_Presence_Check (psHciContext, pHwRef);
   1621                 break;
   1622             }
   1623 #endif
   1624 #ifdef TYPE_B
   1625             case phHal_eISO14443_B_PICC:
   1626             case phHal_eISO14443_4B_PICC:
   1627             {
   1628                 /* Get the Reader B Pipe ID */
   1629                 status = phHciNfc_ReaderB_Get_PipeID
   1630                     (psHciContext, &reader_pipe_id);
   1631 
   1632                 if( (NFCSTATUS_SUCCESS == status)
   1633                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1634                     )
   1635                 {
   1636                     status = phHciNfc_Send_RFReader_Command (psHciContext,
   1637                             pHwRef, reader_pipe_id, NXP_WR_PRESCHECK );
   1638                 }
   1639                 break;
   1640             }
   1641 #endif /* #ifdef TYPE_B */
   1642 #ifdef TYPE_FELICA
   1643             case phHal_eFelica_PICC:
   1644             {
   1645                 /* Get the Felica Reader Pipe ID */
   1646                 status = phHciNfc_Felica_Get_PipeID
   1647                                         (psHciContext, &reader_pipe_id);
   1648 
   1649                 if( (NFCSTATUS_SUCCESS == status)
   1650                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1651                     )
   1652                 {
   1653                     status = phHciNfc_Felica_Request_Mode(psHciContext, pHwRef);
   1654                 }
   1655                 break;
   1656             }
   1657 #endif /* #ifdef TYPE_FELICA */
   1658 #ifdef TYPE_JEWEL
   1659             case phHal_eJewel_PICC:
   1660             {
   1661                 /* Get the Jewel Reader Pipe ID */
   1662                 status = phHciNfc_Jewel_Get_PipeID
   1663                                         (psHciContext, &reader_pipe_id);
   1664 
   1665                 if( (NFCSTATUS_SUCCESS == status)
   1666                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1667                     )
   1668                 {
   1669                     /* status = PHNFCSTVAL(CID_NFC_HCI,
   1670                                     NFCSTATUS_FEATURE_NOT_SUPPORTED); */
   1671                       status = phHciNfc_Jewel_GetRID(
   1672                                         psHciContext, pHwRef);
   1673                 }
   1674                 break;
   1675             }
   1676 #endif /* #ifdef TYPE_JEWEL */
   1677 #ifdef  TYPE_ISO15693
   1678             case phHal_eISO15693_PICC:
   1679             {
   1680                 /* Get the Reader ISO 15693 Pipe ID */
   1681                 status = phHciNfc_ISO15693_Get_PipeID
   1682                                         (psHciContext, &reader_pipe_id);
   1683 
   1684                 if( (NFCSTATUS_SUCCESS == status)
   1685                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1686                     )
   1687                 {
   1688                     uint8_t cmd[11];
   1689                     phHciNfc_Pipe_Info_t *p_pipe_info = NULL;
   1690                     p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1691                     p_pipe_info->param_info = &cmd;
   1692                     p_pipe_info->param_length = 11;
   1693                     // masked inventory command:
   1694                     // set #slots to 1 to use mask without padding,
   1695                     // need to set inventory flag to enable setting #slots
   1696                     cmd[0] = 0x04 | 0x20; // FLAG_INVENTORY | FLAG_SLOTS
   1697                     cmd[1] = 0x01; // CMD_INVENTORY
   1698                     cmd[2] = 64; // mask bit-length
   1699                     memcpy(cmd + 3, &(psHciContext->p_target_info->RemoteDevInfo.Iso15693_Info.Uid), 8);
   1700                     status = phHciNfc_Send_ISO15693_Command(
   1701                         psHciContext,  pHwRef
   1702                         ,reader_pipe_id, NXP_ISO15693_CMD );
   1703 
   1704                 }
   1705                 break;
   1706             }
   1707 #endif /* #ifdef    TYPE_ISO15693 */
   1708             default:
   1709             {
   1710                 status = PHNFCSTVAL(CID_NFC_HCI,
   1711                                     NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1712                 break;
   1713             }
   1714 
   1715         } /* End of the tag_type Switch */
   1716     }
   1717 
   1718     return status;
   1719 
   1720 }
   1721 
   1722 
   1723 /*!
   1724  * \brief Disconnects the the selected tag.
   1725  *
   1726  * This function disconnects the selected tags via RF Reader Gate.
   1727  * This function uses the RF Reader gate based on the type of the
   1728  * tag specified.
   1729  */
   1730 
   1731 
   1732 NFCSTATUS
   1733 phHciNfc_ReaderMgmt_Deselect(
   1734                                     phHciNfc_sContext_t     *psHciContext,
   1735                                     void                    *pHwRef,
   1736                                     phHal_eRemDevType_t     target_type,
   1737                                     uint8_t                 re_poll
   1738                 )
   1739 {
   1740     static  uint8_t             rls_param = FALSE;
   1741     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1742     uint8_t                     reader_pipe_id =
   1743                                     (uint8_t) HCI_UNKNOWN_PIPE_ID;
   1744     phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
   1745 
   1746 
   1747 
   1748     if( (NULL == psHciContext)
   1749         || (NULL == pHwRef)
   1750         )
   1751     {
   1752       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1753     }
   1754     else
   1755     {
   1756         rls_param = re_poll;
   1757 
   1758         switch (target_type)
   1759         {
   1760             case phHal_eMifare_PICC:
   1761             case phHal_eISO14443_A_PICC:
   1762             case phHal_eISO14443_3A_PICC:
   1763             case phHal_eISO14443_4A_PICC:
   1764             {
   1765                 /* Get the Reader A Pipe ID */
   1766                 status = phHciNfc_ReaderA_Get_PipeID
   1767                                         (psHciContext, &reader_pipe_id);
   1768                 break;
   1769             }
   1770 #ifdef TYPE_B
   1771             case phHal_eISO14443_B_PICC:
   1772             case phHal_eISO14443_4B_PICC:
   1773             {
   1774                 /* Get the Reader B Pipe ID */
   1775                 status = phHciNfc_ReaderB_Get_PipeID
   1776                     (psHciContext, &reader_pipe_id);
   1777 
   1778                 break;
   1779             }
   1780 #endif /* #ifdef TYPE_B */
   1781 #ifdef TYPE_FELICA
   1782             case phHal_eFelica_PICC:
   1783             {
   1784                 /* Get the Felica Pipe ID */
   1785                 status = phHciNfc_Felica_Get_PipeID
   1786                     (psHciContext, &reader_pipe_id);
   1787 
   1788                 break;
   1789             }
   1790 #endif /* #ifdef TYPE_FELICA */
   1791 #ifdef TYPE_JEWEL
   1792             case phHal_eJewel_PICC:
   1793             {
   1794                 /* Get the Jewel Pipe ID */
   1795                 status = phHciNfc_Jewel_Get_PipeID
   1796                     (psHciContext, &reader_pipe_id);
   1797 
   1798                 break;
   1799             }
   1800 #endif /* #ifdef TYPE_JEWEL */
   1801 #ifdef  TYPE_ISO15693
   1802             case phHal_eISO15693_PICC:
   1803             {
   1804                 /* Get the ISO 15693 Pipe ID */
   1805                 status = phHciNfc_ISO15693_Get_PipeID
   1806                     (psHciContext, &reader_pipe_id);
   1807 
   1808                 break;
   1809             }
   1810 #endif /* #ifdef    TYPE_ISO15693 */
   1811 #ifdef ENABLE_P2P
   1812             case phHal_eNfcIP1_Target:
   1813             {
   1814                 /* Get the Reader A Pipe ID */
   1815                 status = phHciNfc_Initiator_Get_PipeID
   1816                                         (psHciContext, &reader_pipe_id);
   1817 
   1818                 break;
   1819             }
   1820 #endif
   1821             default:
   1822             {
   1823                 status = PHNFCSTVAL(CID_NFC_HCI,
   1824                                             NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1825                 break;
   1826             }
   1827 
   1828         } /* End of the tag_type Switch */
   1829         p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1830         if( (NFCSTATUS_SUCCESS == status)
   1831             && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1832             && ( NULL != p_pipe_info ) )
   1833         {
   1834             if (TRUE == rls_param)
   1835             {
   1836                 p_pipe_info->param_info = &rls_param;
   1837                 p_pipe_info->param_length = sizeof(rls_param);
   1838             }
   1839             status = phHciNfc_Send_RFReader_Event ( psHciContext, pHwRef,
   1840                         reader_pipe_id,(uint8_t) NXP_EVT_RELEASE_TARGET );
   1841         }
   1842     }
   1843 
   1844     return status;
   1845 }
   1846 
   1847 
   1848 /*!
   1849  * \brief Exchanges the data to/from the selected tags via RF Reader Gates.
   1850  *
   1851  * This function Exchanges the data to/from the selected tags
   1852  * via RF Reader Gates. This function uses the RF Reader gate based on the
   1853  * type of the selected tag and the type of the Reader gate specified.
   1854  */
   1855 
   1856 
   1857 NFCSTATUS
   1858 phHciNfc_ReaderMgmt_Exchange_Data(
   1859                                     phHciNfc_sContext_t     *psHciContext,
   1860                                     void                    *pHwRef,
   1861                                     phHciNfc_XchgInfo_t     *p_xchg_info
   1862                 )
   1863 {
   1864     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1865     phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
   1866     uint8_t                     reader_pipe_id = (uint8_t) HCI_UNKNOWN_PIPE_ID;
   1867     phHal_eRemDevType_t         target_type = phHal_eUnknown_DevType;
   1868 
   1869     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1870     {
   1871       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1872     }
   1873     else if (NULL == psHciContext->p_xchg_info)
   1874     {
   1875         status = PHNFCSTVAL(CID_NFC_HCI,
   1876                 NFCSTATUS_INVALID_HCI_INFORMATION);
   1877 
   1878     }
   1879     else
   1880     {
   1881         switch (psHciContext->host_rf_type)
   1882         {
   1883             case phHal_eISO14443_A_PCD:
   1884             {
   1885                 /* Get the Reader A Pipe ID */
   1886                 status = phHciNfc_ReaderA_Get_PipeID
   1887                                         (psHciContext, &reader_pipe_id);
   1888 
   1889                 if( (NFCSTATUS_SUCCESS == status)
   1890                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1891                     )
   1892                 {
   1893                     p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1894                     p_pipe_info->param_info = p_xchg_info->tx_buffer;
   1895                     p_pipe_info->param_length = p_xchg_info->tx_length;
   1896                     target_type = psHciContext->p_target_info->RemDevType;
   1897                     switch (target_type)
   1898                     {
   1899                         case phHal_eMifare_PICC:
   1900                         case phHal_eISO14443_3A_PICC:
   1901                         {
   1902                             if ((uint8_t)phHal_eMifareRaw ==
   1903                                             p_xchg_info->params.tag_info.cmd_type)
   1904                             {
   1905                                 status = phHciNfc_Send_ReaderA_Command(
   1906                                     psHciContext,  pHwRef
   1907                                     ,reader_pipe_id, NXP_MIFARE_RAW );
   1908                             }
   1909                             else
   1910                             {
   1911                                 status = phHciNfc_Send_ReaderA_Command(
   1912                                     psHciContext, pHwRef,
   1913                                     reader_pipe_id, NXP_MIFARE_CMD );
   1914                             }
   1915                             break;
   1916                         }
   1917                         case phHal_eISO14443_A_PICC:
   1918                         case phHal_eISO14443_4A_PICC:
   1919                         {
   1920                             status = phHciNfc_Send_RFReader_Command(
   1921                                         psHciContext, pHwRef,
   1922                                         reader_pipe_id, WR_XCHGDATA );
   1923                             break;
   1924                         }
   1925                         default:
   1926                         {
   1927                             status = PHNFCSTVAL(CID_NFC_HCI,
   1928                                                 NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1929                             break;
   1930                         }
   1931                     } /* End of the tag_type Switch */
   1932                 } /* End of Pipe ID Check */
   1933                 break;
   1934             }
   1935 #ifdef TYPE_B
   1936             case phHal_eISO14443_B_PCD:
   1937             {
   1938                 /* Get the Reader B Pipe ID */
   1939                 status = phHciNfc_ReaderB_Get_PipeID
   1940                                         (psHciContext, &reader_pipe_id);
   1941 
   1942                 if( (NFCSTATUS_SUCCESS == status)
   1943                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1944                     )
   1945                 {
   1946                     p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1947                     p_pipe_info->param_info = p_xchg_info->tx_buffer;
   1948                     p_pipe_info->param_length = p_xchg_info->tx_length;
   1949                     status = phHciNfc_Send_RFReader_Command(
   1950                                 psHciContext, pHwRef,
   1951                                 reader_pipe_id, WR_XCHGDATA );
   1952                 }
   1953                 break;
   1954             }
   1955 #endif /* #ifdef TYPE_B */
   1956 #ifdef TYPE_FELICA
   1957             case phHal_eFelica_PCD:
   1958             {
   1959                 /* Get the Felica Reader Pipe ID */
   1960                 status = phHciNfc_Felica_Get_PipeID
   1961                                         (psHciContext, &reader_pipe_id);
   1962 
   1963                 if( (NFCSTATUS_SUCCESS == status)
   1964                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1965                     )
   1966                 {
   1967                     p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1968                     p_pipe_info->param_info = p_xchg_info->tx_buffer;
   1969                     p_pipe_info->param_length = p_xchg_info->tx_length;
   1970                     if ((uint8_t)phHal_eFelica_Raw ==
   1971                                     p_xchg_info->params.tag_info.cmd_type)
   1972                     {
   1973                         status = phHciNfc_Send_Felica_Command(
   1974                             psHciContext,  pHwRef
   1975                             ,reader_pipe_id, NXP_FELICA_RAW );
   1976                     }
   1977                     else
   1978                     {
   1979                         status = phHciNfc_Send_Felica_Command(
   1980                             psHciContext, pHwRef,
   1981                             reader_pipe_id, NXP_FELICA_CMD );
   1982                     }
   1983                 }
   1984                 break;
   1985             }
   1986 #endif /* #ifdef TYPE_FELICA */
   1987 #if defined(TYPE_ISO15693)
   1988             case phHal_eISO15693_PCD:
   1989             {
   1990                 /* Get the ISO15693 Reader Pipe ID */
   1991                 status = phHciNfc_ISO15693_Get_PipeID
   1992                                         (psHciContext, &reader_pipe_id);
   1993 
   1994                 if( (NFCSTATUS_SUCCESS == status)
   1995                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   1996                     )
   1997                 {
   1998                     p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   1999                     p_pipe_info->param_info = p_xchg_info->tx_buffer;
   2000                     p_pipe_info->param_length = p_xchg_info->tx_length;
   2001                     if (((uint8_t)phHal_eIso15693_Cmd  ==
   2002                                     p_xchg_info->params.tag_info.cmd_type)
   2003 #if defined(SUPPORT_ISO15693_RAW)
   2004                         || ((uint8_t) phHal_eIso15693_Raw ==
   2005                                     p_xchg_info->params.tag_info.cmd_type)
   2006 #endif
   2007                      )
   2008                     {
   2009                         status = phHciNfc_Send_ISO15693_Command(
   2010                             psHciContext,  pHwRef
   2011                             ,reader_pipe_id, NXP_ISO15693_CMD );
   2012                     }
   2013                     else
   2014                     {
   2015                         status = PHNFCSTVAL(CID_NFC_HCI,
   2016                                     NFCSTATUS_INVALID_PARAMETER);
   2017                     }
   2018                 }
   2019                 break;
   2020             }
   2021 #endif
   2022 #ifdef TYPE_JEWEL
   2023             case phHal_eJewel_PCD:
   2024             {
   2025                 /* Get the Jewel Reader Pipe ID */
   2026                 status = phHciNfc_Jewel_Get_PipeID
   2027                                         (psHciContext, &reader_pipe_id);
   2028 
   2029                 if( (NFCSTATUS_SUCCESS == status)
   2030                     && (reader_pipe_id != HCI_UNKNOWN_PIPE_ID )
   2031                     )
   2032                 {
   2033                     uint8_t         transact_type = 0;
   2034                     p_pipe_info = psHciContext->p_pipe_list[reader_pipe_id];
   2035                     p_pipe_info->param_info = p_xchg_info->tx_buffer;
   2036                     p_pipe_info->param_length = p_xchg_info->tx_length;
   2037                     switch(p_xchg_info->params.tag_info.cmd_type)
   2038                     {
   2039                         case phHal_eJewel_Raw:
   2040                         {
   2041                             transact_type = NXP_JEWEL_RAW;
   2042                             break;
   2043                         }
   2044                         case phHal_eJewel_Invalid:
   2045                         default:
   2046                         {
   2047                             status = PHNFCSTVAL(CID_NFC_HCI,
   2048                                                 NFCSTATUS_INVALID_PARAMETER);
   2049                             break;
   2050                         }
   2051                     }
   2052                     if(0 != transact_type)
   2053                     {
   2054                         status = phHciNfc_Send_Jewel_Command(
   2055                                     psHciContext,  pHwRef,
   2056                                     reader_pipe_id, transact_type );
   2057                     }
   2058                 }
   2059                 break;
   2060             }
   2061 #endif /* #ifdef TYPE_JEWEL */
   2062             default:
   2063             {
   2064                 status = PHNFCSTVAL(CID_NFC_HCI,
   2065                                                 NFCSTATUS_FEATURE_NOT_SUPPORTED);
   2066                 break;
   2067             }
   2068         }/* End of Reader Type Switch */
   2069     }
   2070 
   2071     return status;
   2072 }
   2073 
   2074 
   2075 
   2076 /*!
   2077  * \brief Releases the resources allocated the RF Reader Management.
   2078  *
   2079  * This function Releases the resources allocated the RF Reader Management.
   2080  */
   2081 
   2082 NFCSTATUS
   2083 phHciNfc_ReaderMgmt_Release(
   2084                                 phHciNfc_sContext_t     *psHciContext,
   2085                                 void                    *pHwRef
   2086                              )
   2087 {
   2088     NFCSTATUS                           status = NFCSTATUS_SUCCESS;
   2089     phHciNfc_Pipe_Info_t                *p_pipe_info = NULL;
   2090     phHciNfc_ReaderMgmt_Info_t          *p_reader_mgmt_info=NULL;
   2091 
   2092     if( (NULL == psHciContext) || (NULL == pHwRef) )
   2093     {
   2094       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   2095     }
   2096     else
   2097     {
   2098         if( NULL != psHciContext->p_reader_mgmt_info )
   2099         {
   2100             p_reader_mgmt_info = (phHciNfc_ReaderMgmt_Info_t *)
   2101                                 psHciContext->p_reader_mgmt_info ;
   2102             switch(p_reader_mgmt_info->rf_gate_cur_seq)
   2103             {
   2104                 /* Reader A pipe close sequence */
   2105                 case READERA_PIPE_CLOSE:
   2106                 {
   2107                     p_pipe_info = ((phHciNfc_ReaderA_Info_t *)
   2108                             psHciContext->p_reader_a_info)->p_pipe_info;
   2109 
   2110                     status = phHciNfc_Close_Pipe( psHciContext,
   2111                                                     pHwRef, p_pipe_info );
   2112                     if(status == NFCSTATUS_SUCCESS)
   2113                     {
   2114                         p_reader_mgmt_info->rf_gate_next_seq =
   2115                                                     READERB_PIPE_CLOSE;
   2116                         /* status = NFCSTATUS_PENDING; */
   2117                     }
   2118                     break;
   2119                 }
   2120 #ifdef TYPE_B
   2121                 /* Reader B pipe close sequence */
   2122                 case READERB_PIPE_CLOSE:
   2123                 {
   2124                     p_pipe_info = ((phHciNfc_ReaderB_Info_t *)
   2125                             psHciContext->p_reader_b_info)->p_pipe_info;
   2126 
   2127                     status = phHciNfc_Close_Pipe( psHciContext,
   2128                                                         pHwRef, p_pipe_info );
   2129                     if(status == NFCSTATUS_SUCCESS)
   2130                     {
   2131                         p_reader_mgmt_info->rf_gate_next_seq =
   2132                                                         FELICA_PROP_PIPE_CLOSE;
   2133                         status = NFCSTATUS_PENDING;
   2134                     }
   2135                     break;
   2136                 }
   2137 #endif /* #ifdef TYPE_B */
   2138 #ifdef TYPE_FELICA
   2139                 /* Felica Reader pipe close sequence */
   2140                 case FELICA_PROP_PIPE_CLOSE:
   2141                 {
   2142                     p_pipe_info = ((phHciNfc_Felica_Info_t *)
   2143                             psHciContext->p_felica_info)->p_pipe_info;
   2144 
   2145                     status = phHciNfc_Close_Pipe( psHciContext,
   2146                                                         pHwRef, p_pipe_info );
   2147                     if(status == NFCSTATUS_SUCCESS)
   2148                     {
   2149                         p_reader_mgmt_info->rf_gate_next_seq =
   2150                                                 NFCIP1_INITIATOR_PIPE_CLOSE;
   2151                         /* status = NFCSTATUS_PENDING; */
   2152                     }
   2153                     break;
   2154                 }
   2155 #endif /* #ifdef TYPE_FELICA */
   2156 #ifdef ENABLE_P2P
   2157                 /* NFC-IP1 Initiator pipe Close sequence */
   2158                 case NFCIP1_INITIATOR_PIPE_CLOSE:
   2159                 {
   2160                     p_pipe_info =
   2161                         ((phHciNfc_NfcIP_Info_t *)psHciContext->
   2162                                     p_nfcip_info)->p_init_pipe_info;
   2163                     if(NULL == p_pipe_info )
   2164                     {
   2165                         status = PHNFCSTVAL(CID_NFC_HCI,
   2166                                         NFCSTATUS_INVALID_HCI_SEQUENCE);
   2167                     }
   2168                     else
   2169                     {
   2170                         status = phHciNfc_Open_Pipe( psHciContext,
   2171                                                         pHwRef, p_pipe_info );
   2172                         if(status == NFCSTATUS_SUCCESS)
   2173                         {
   2174                             p_reader_mgmt_info->rf_gate_next_seq = READERA_PIPE_CLOSE;
   2175                             status = NFCSTATUS_PENDING;
   2176                         }
   2177                     }
   2178                     break;
   2179                 }
   2180 #endif /* #ifdef ENABLE_P2P */
   2181                 default:
   2182                 {
   2183                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
   2184                     break;
   2185                 }
   2186 
   2187             }/* End of the Sequence Switch */
   2188 
   2189         }/* End of the Reader Info Memory Check */
   2190 
   2191     } /* End of Null Context Check */
   2192 
   2193     return status;
   2194 }
   2195 
   2196 
   2197 /*!
   2198  * \brief Sends the RF Reader HCI Events to the connected reader device.
   2199  *
   2200  * This function Sends the RF Reader HCI Event frames in the HCP packet format to the
   2201  * connected reader device.
   2202  */
   2203 
   2204  NFCSTATUS
   2205  phHciNfc_Send_RFReader_Event (
   2206                                 phHciNfc_sContext_t *psHciContext,
   2207                                 void                *pHwRef,
   2208                                 uint8_t             pipe_id,
   2209                                 uint8_t             event
   2210                     )
   2211  {
   2212     phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
   2213     phHciNfc_HCP_Message_t  *hcp_message = NULL;
   2214     phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
   2215     uint8_t                 length = 0;
   2216     uint8_t                 i = 0;
   2217     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   2218 
   2219     if( (NULL == psHciContext)
   2220         || ( pipe_id > PHHCINFC_MAX_PIPE)
   2221         ||(NULL == psHciContext->p_pipe_list[pipe_id])
   2222       )
   2223     {
   2224         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   2225         HCI_DEBUG("%s: Invalid Arguments passed \n",
   2226                                                 "phHciNfc_Send_RFReader_Event");
   2227     }
   2228     else
   2229     {
   2230         p_pipe_info = (phHciNfc_Pipe_Info_t *)
   2231                                 psHciContext->p_pipe_list[pipe_id];
   2232         psHciContext->tx_total = 0 ;
   2233         length +=  HCP_HEADER_LEN ;
   2234         switch( event )
   2235         {
   2236             case EVT_READER_REQUESTED:
   2237             case EVT_END_OPERATION:
   2238             {
   2239 
   2240                 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   2241                 /* Construct the HCP Frame */
   2242                 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   2243                                         (uint8_t) pipe_id, HCP_MSG_TYPE_EVENT, event);
   2244                 break;
   2245             }
   2246             case NXP_EVT_RELEASE_TARGET:
   2247             {
   2248                 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   2249                 /* Construct the HCP Frame */
   2250                 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   2251                                         (uint8_t) pipe_id, HCP_MSG_TYPE_EVENT, event);
   2252                 hcp_message = &(hcp_packet->msg.message);
   2253                 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
   2254                                             i, p_pipe_info->param_info,
   2255                                             p_pipe_info->param_length);
   2256                 length =(uint8_t)(length + i + p_pipe_info->param_length);
   2257                 break;
   2258             }
   2259             default:
   2260             {
   2261                 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
   2262                 HCI_DEBUG("%s: Statement Should Not Occur \n",
   2263                                             "phHciNfc_Send_RFReader_Event");
   2264                 break;
   2265             }
   2266         }
   2267         if( NFCSTATUS_SUCCESS == status )
   2268         {
   2269             p_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT ;
   2270             p_pipe_info->prev_msg = event ;
   2271             psHciContext->tx_total = length;
   2272 
   2273             /* Send the Constructed HCP packet to the lower layer */
   2274             status = phHciNfc_Send_HCP( psHciContext, pHwRef );
   2275             p_pipe_info->prev_status = NFCSTATUS_PENDING;
   2276         }
   2277     }
   2278 
   2279     return status;
   2280 }
   2281 
   2282 /*!
   2283  * \brief Sends the RF Reader HCI Additonal Commands to the connected
   2284  * reader device.
   2285  *
   2286  * This function Sends the RF Reader HCI Command frames in the HCP packet
   2287  * format to the connected reader device.
   2288  */
   2289 
   2290  NFCSTATUS
   2291  phHciNfc_Send_RFReader_Command (
   2292                                 phHciNfc_sContext_t *psHciContext,
   2293                                 void                *pHwRef,
   2294                                 uint8_t             pipe_id,
   2295                                 uint8_t             cmd
   2296                     )
   2297  {
   2298     phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
   2299     phHciNfc_HCP_Message_t  *hcp_message = NULL;
   2300     phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
   2301     uint8_t                 i = 0;
   2302     uint8_t                 length=0;
   2303     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   2304 
   2305     if( (NULL == psHciContext)
   2306         || ( pipe_id > PHHCINFC_MAX_PIPE)
   2307         ||(NULL == psHciContext->p_pipe_list[pipe_id])
   2308       )
   2309     {
   2310         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   2311         HCI_DEBUG("%s: Invalid Arguments passed \n",
   2312                                                 "phHciNfc_Send_RFReader_Command");
   2313     }
   2314     else
   2315     {
   2316         p_pipe_info = (phHciNfc_Pipe_Info_t *)
   2317                                 psHciContext->p_pipe_list[pipe_id];
   2318         psHciContext->tx_total = 0 ;
   2319         length +=  HCP_HEADER_LEN ;
   2320         switch( cmd )
   2321         {
   2322             case WR_XCHGDATA:
   2323             {
   2324 
   2325                 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   2326                 /* Construct the HCP Frame */
   2327                 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   2328                                         (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
   2329                 hcp_message = &(hcp_packet->msg.message);
   2330                 /* Frame Wait Timeout */
   2331                 hcp_message->payload[i++] = NXP_ISO_XCHG_TIMEOUT ;
   2332                 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
   2333                                             i, p_pipe_info->param_info,
   2334                                             p_pipe_info->param_length);
   2335                 length =(uint8_t)(length + i + p_pipe_info->param_length);
   2336                 break;
   2337             }
   2338             case NXP_WR_PRESCHECK:
   2339             case NXP_WR_ACTIVATE_NEXT:
   2340             {
   2341 
   2342                 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   2343                 /* Construct the HCP Frame */
   2344                 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   2345                                         (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
   2346                 break;
   2347             }
   2348             case NXP_WR_DISPATCH_TO_UICC:
   2349             case NXP_WR_ACTIVATE_ID:
   2350             {
   2351 
   2352                 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   2353                 /* Construct the HCP Frame */
   2354                 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   2355                                         (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
   2356                 hcp_message = &(hcp_packet->msg.message);
   2357                 /* UID of the Card */
   2358                 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
   2359                                             i, p_pipe_info->param_info,
   2360                                             p_pipe_info->param_length);
   2361                 length =(uint8_t)(length + i + p_pipe_info->param_length);
   2362                 break;
   2363             }
   2364             default:
   2365             {
   2366                 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
   2367                 HCI_DEBUG("%s: Statement Should Not Occur \n",
   2368                                                 "phHciNfc_Send_RFReader_Command");
   2369                 break;
   2370             }
   2371         }
   2372         if( NFCSTATUS_SUCCESS == status )
   2373         {
   2374             p_pipe_info->sent_msg_type = HCP_MSG_TYPE_COMMAND;
   2375             p_pipe_info->prev_msg = cmd;
   2376             psHciContext->tx_total = length;
   2377             psHciContext->response_pending = TRUE ;
   2378 
   2379             /* Send the Constructed HCP packet to the lower layer */
   2380             status = phHciNfc_Send_HCP( psHciContext, pHwRef );
   2381             p_pipe_info->prev_status = NFCSTATUS_PENDING;
   2382         }
   2383     }
   2384 
   2385     return status;
   2386 }
   2387 
   2388 
   2389 
   2390