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 *                                                                             *
     22 * \file  phHciNfc_Sequence.c                                                  *
     23 * \brief State Machine Implementation for the HCI Management and              *
     24 * and the Function Sequence for a particular State                            *
     25 *                                                                             *
     26 *                                                                             *
     27 * Project: NFC-FRI-1.1                                                        *
     28 *                                                                             *
     29 * $Date: Tue Jun  8 09:33:46 2010 $                                           *
     30 * $Author: ing04880 $                                                         *
     31 * $Revision: 1.85 $                                                           *
     32 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $
     33 *                                                                             *
     34 * =========================================================================== *
     35 */
     36 
     37 /*
     38 ################################################################################
     39 ***************************** Header File Inclusion ****************************
     40 ################################################################################
     41 */
     42 
     43 #include <phNfcCompId.h>
     44 #include <phNfcConfig.h>
     45 #include <phHciNfc.h>
     46 #include <phHciNfc_Sequence.h>
     47 #include <phHciNfc_AdminMgmt.h>
     48 #include <phHciNfc_IDMgmt.h>
     49 #include <phHciNfc_LinkMgmt.h>
     50 #include <phHciNfc_DevMgmt.h>
     51 #include <phHciNfc_PollingLoop.h>
     52 #include <phHciNfc_RFReader.h>
     53 #include <phHciNfc_RFReaderA.h>
     54 #include <phHciNfc_Emulation.h>
     55 #ifdef ENABLE_P2P
     56 #include <phHciNfc_NfcIPMgmt.h>
     57 #endif
     58 #include <phHciNfc_SWP.h>
     59 #include <phHciNfc_WI.h>
     60 #include <phOsalNfc.h>
     61 
     62 /*
     63 ################################################################################
     64 ****************************** Macro Definitions *******************************
     65 ################################################################################
     66 */
     67 
     68 /* Address Definitions for HAL Configuration */
     69 #define NFC_ADDRESS_HAL_CONF            0x9FD0U
     70 
     71 
     72 /*
     73 ################################################################################
     74 ********************** Structure/Enumeration Definitions ***********************
     75 ################################################################################
     76 */
     77 
     78 
     79 #ifdef VALIDATE_FSM
     80 
     81 typedef struct phHciNfc_sFsm
     82 {
     83     phHciNfc_eState_t from_state;
     84     phHciNfc_eState_t to_state;
     85     uint8_t           valid;
     86 }phHciNfc_sFsm_t;
     87 
     88 static phHciNfc_sFsm_t phHciNfc_Valid_Fsm[] = {
     89     {hciState_Reset,        hciState_Initialise ,   TRUE},
     90         /*  {hciState_Reset,        hciState_Config,            FALSE}, */
     91     {hciState_Initialise,   hciState_Config,            TRUE},
     92     {hciState_Initialise,   hciState_Release,       TRUE},
     93     {hciState_Config,       hciState_Connect,       TRUE},
     94     {hciState_Config,       hciState_Release,       TRUE},
     95     {hciState_Connect,      hciState_Activate,      TRUE},
     96     {hciState_Connect,      hciState_Transact,      TRUE},
     97     {hciState_Connect,      hciState_Disconnect,    TRUE},
     98     {hciState_Disconnect,   hciState_Config,            TRUE},
     99     /*  {hciState_Disconnect,   hciState_Release,       TRUE}, */
    100     {hciState_Reset,        hciState_Initialise,    TRUE},
    101 };
    102 
    103 #endif
    104 
    105 
    106 /*
    107 ################################################################################
    108 ************************* Function Prototype Declaration ***********************
    109 ################################################################################
    110 */
    111 
    112 
    113 static
    114 NFCSTATUS
    115 phHciNfc_Config_Sequence(
    116                          phHciNfc_sContext_t        *psHciContext,
    117                          void                   *pHwRef
    118                          );
    119 
    120 
    121 /**
    122  * \ingroup grp_hci_nfc
    123  *
    124  *  The phHciNfc_Connect_Sequence function sequence selects the
    125  *  discovered target for performing the transaction.
    126  *
    127  *  \param[in]  psHciContext            psHciContext is the context of
    128  *                                      the HCI Layer.
    129  *  \param[in]  pHwRef                  pHwRef is the Information of
    130  *                                      the Device Interface Link .
    131  *
    132  *  \retval NFCSTATUS_SUCCESS           HCI target selection sequence successful.
    133  *  \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
    134  *                                      could not be interpreted properly.
    135  *  \retval Other errors                Other related errors
    136  *
    137  */
    138 
    139 static
    140 NFCSTATUS
    141 phHciNfc_Transact_Sequence(
    142                             phHciNfc_sContext_t     *psHciContext,
    143                             void                    *pHwRef
    144                          );
    145 
    146 /**
    147  * \ingroup grp_hci_nfc
    148  *
    149  *  The phHciNfc_Info_Sequence function sequence selects the
    150  *  discovered target for performing the transaction.
    151  *
    152  *  \param[in]  psHciContext            psHciContext is the context of
    153  *                                      the HCI Layer.
    154  *  \param[in]  pHwRef                  pHwRef is the Information of
    155  *                                      the Device Interface Link .
    156  *
    157  *  \retval NFCSTATUS_SUCCESS           HCI target selection sequence successful.
    158  *  \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
    159  *                                      could not be interpreted properly.
    160  *  \retval Other errors                Other related errors
    161  *
    162  */
    163 
    164 static
    165 NFCSTATUS
    166 phHciNfc_Info_Sequence(
    167                             phHciNfc_sContext_t     *psHciContext,
    168                             void                    *pHwRef
    169                    );
    170 
    171 static
    172 NFCSTATUS
    173 phHciNfc_Test_Sequence(
    174                             phHciNfc_sContext_t     *psHciContext,
    175                             void                    *pHwRef,
    176                             NFCSTATUS               test_status,
    177                             uint8_t                 *pdata,
    178                             uint8_t                 length
    179                          );
    180 
    181 #ifdef HCI_FSM_RESET
    182 
    183 static
    184 void
    185 phHciNfc_FSM_Reset(
    186                         phHciNfc_sContext_t *psHciContext
    187                     );
    188 
    189 #endif
    190 
    191 static
    192 NFCSTATUS
    193 phHciNfc_IO_Sequence(
    194                             phHciNfc_sContext_t     *psHciContext,
    195                             void                    *pHwRef,
    196                             NFCSTATUS               test_status,
    197                             uint8_t                 *pdata,
    198                             uint8_t                 length
    199                     );
    200 
    201 static
    202 NFCSTATUS
    203 phHciNfc_Pending_Sequence(
    204                                 phHciNfc_sContext_t     *psHciContext,
    205                                 void                    *pHwRef
    206                           );
    207 
    208 
    209 /*
    210 ################################################################################
    211 ***************************** Function Definitions *****************************
    212 ################################################################################
    213 */
    214 
    215 NFCSTATUS
    216 phHciNfc_FSM_Validate(
    217                       phHciNfc_sContext_t *psHciContext,
    218                       phHciNfc_eState_t state,
    219                       uint8_t validate_type
    220                     )
    221 {
    222     NFCSTATUS           status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
    223     phHciNfc_eState_t   cur_state = (phHciNfc_eState_t)
    224         psHciContext->hci_state.cur_state;
    225 
    226     switch(validate_type)
    227     {
    228         case NFC_FSM_CURRENT:
    229         {
    230             if( cur_state == (uint8_t) state )
    231             {
    232                 status = NFCSTATUS_SUCCESS;
    233             }
    234             break;
    235         }
    236         case NFC_FSM_NEXT:
    237         {
    238             phHciNfc_eState_t   next_state = state;
    239             switch (cur_state)
    240             {
    241                 case hciState_Reset:
    242                 {
    243                     switch(next_state)
    244                     {
    245                         /* Specifies the Starting of the init Sequence */
    246                         case hciState_Initialise:
    247                         /* Initialise to Perform Test on
    248                            the Antenna/SWP Link */
    249                         case hciState_Test:
    250                         {
    251                             status = NFCSTATUS_SUCCESS;
    252                             break;
    253                         }
    254                         default:
    255                             break;
    256                     }
    257                     break;
    258                 }
    259                 case hciState_Initialise:
    260                 {
    261                     switch(next_state)
    262                     {
    263                         /* Discovery Resume after connect failure */
    264                         case hciState_Initialise:
    265                         /* Configuring the Discovery/Emulation */
    266                         case hciState_Config:
    267                         /* Configuring the Memory */
    268                         case hciState_IO:
    269                         /* Occurence of the Tag Discovered Event */
    270                         case hciState_Select:
    271                         /* Occurence of the Target Activated Event */
    272                         case hciState_Listen:
    273                         /* Specifies the Starting of the Release Sequence */
    274                         case hciState_Release:
    275                         {
    276                             status = NFCSTATUS_SUCCESS;
    277                             break;
    278                         }
    279                         default:
    280                             break;
    281                     }
    282                     break;
    283                 }
    284                 case hciState_Test:
    285                 {
    286                     if ((hciState_Test == next_state )
    287                         || (hciState_IO == next_state)
    288                         || (hciState_Release == next_state))
    289                     {
    290                         /*  Next Test/Reset Sequence */
    291                         status = NFCSTATUS_SUCCESS;
    292                     }
    293                     break;
    294                 }
    295                 case hciState_Select:
    296                 {
    297                     switch(next_state)
    298                     {
    299                         /* Restart the Wheel */
    300                         case hciState_Initialise:
    301                             /* Select the next Tag in the Field or
    302                              * already Selected Tag Again
    303                              */
    304                         /* Configuring the Memory */
    305                         case hciState_IO:
    306                         case hciState_Select:
    307                         /* Configuring the Discovery/Emulation */
    308                         case hciState_Config:
    309                             /* Re-Activate the Target or
    310                              * Discover the next target
    311                              */
    312                         case hciState_Reactivate:
    313                         /* Connect the Discovered Target */
    314                         case hciState_Connect:
    315                         /* Specifies the Starting of the Release Sequence */
    316                         case hciState_Release:
    317                         {
    318                             status = NFCSTATUS_SUCCESS;
    319                             break;
    320                         }
    321                         default:
    322                             break;
    323                     }
    324                     break;
    325                 }
    326                 case hciState_Connect:
    327                 {
    328                     switch(next_state)
    329                     {
    330                         /* Disabling the Tag Discovery */
    331                         case hciState_Initialise:
    332                             /* Configuring the Discovery/Emulation */
    333                             /* This should not be allowed if the target
    334                             * is connected.
    335                             */
    336                         /* Configuring the Memory */
    337                         case hciState_IO:
    338                         case hciState_Config:
    339                             /* Re-Activate the Target or
    340                              * Discover the next target
    341                              */
    342                         case hciState_Reactivate:
    343                         /* Intermediate Transceive State */
    344                         case hciState_Transact:
    345                         /* Intermediate Presence Check State */
    346                         case hciState_Presence:
    347                         /* Disconnect the Target Connected */
    348                         case hciState_Disconnect:
    349                         /* Specifies the Starting of the Release Sequence */
    350                         case hciState_Release:
    351                         {
    352                             status = NFCSTATUS_SUCCESS;
    353                             break;
    354                         }
    355                         default:
    356                             break;
    357                     }
    358                     break;
    359                 }
    360                 case hciState_Listen:
    361                 {
    362                     switch(next_state)
    363                     {
    364                         /* Releasing from the Emulation/Target Mode */
    365                         case hciState_Initialise:
    366                         /* Occurence of the Tag Discovered Event
    367                         * after the Disconnect Operation
    368                         */
    369                         case hciState_Select:
    370                         /* Configuring the Memory */
    371                         case hciState_IO:
    372                         /* Configuring the Discovery/Emulation */
    373                         case hciState_Config:
    374                         /* Intermediate Transceive State */
    375                         case hciState_Transact:
    376                         /* Specifies the Starting of the Release Sequence */
    377                         case hciState_Release:
    378                         {
    379                             status = NFCSTATUS_SUCCESS;
    380                             break;
    381                         }
    382                         default:
    383                             break;
    384                     }
    385                     break;
    386                 }
    387                 case hciState_Reactivate:
    388                 {
    389                     switch(next_state)
    390                     {
    391                         /* Restart/Discovery after the Target is removed
    392                          * after Reactivation.
    393                         */
    394                         /* case hciState_Initialise: */
    395                         /* Re-Connect the Re-Activated Target */
    396                         case hciState_Connect:
    397                         /* Configuring the Memory */
    398                         case hciState_IO:
    399                         /* Configuring the Discovery/Emulation */
    400                         case hciState_Config:
    401                         /* Specifies the Starting of the Release Sequence */
    402                         case hciState_Release:
    403                         {
    404                             status = NFCSTATUS_SUCCESS;
    405                             break;
    406                         }
    407                         default:
    408                             break;
    409                     }
    410                     break;
    411                 }
    412                 case hciState_Disconnect:
    413                 {
    414                     switch(next_state)
    415                     {
    416                         /* Discovery Resume after connect failure
    417                            after the disconnect */
    418                         case hciState_Initialise:
    419                         /* Configuring the Memory */
    420                         case hciState_IO:
    421                         /* Configuring the Discovery/Emulation */
    422                         case hciState_Config:
    423                         /* Occurence of the Tag Discovered Event
    424                         * after the Disconnect Operation
    425                         */
    426                         case hciState_Select:
    427                         /* Occurence of the Target Activated Event */
    428                         case hciState_Listen:
    429                         /* Specifies the Starting of the Release Sequence */
    430                         case hciState_Release:
    431                         {
    432                             status = NFCSTATUS_SUCCESS;
    433                             break;
    434                         }
    435                         default:
    436                         {
    437                             break;
    438                     }
    439                     }
    440                     break;
    441                 }
    442 #ifdef USE_M5
    443                 case hciState_Presence:
    444                 case hciState_Transact:
    445                 case hciState_Release:
    446                 {
    447                     break;
    448                 }
    449 #endif
    450                 /* case phHciNfc_Unknown: */
    451                 default:
    452                 {
    453                     /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); */
    454                     break;
    455                 }
    456             } /* End of State Validation Switch */
    457             if( NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition )
    458             {
    459                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
    460             }
    461             break;
    462         }
    463         default:
    464         {
    465             HCI_DEBUG("State Validate Type:%x is Unknown/Incorrect \n",
    466                                                             validate_type);
    467             break;
    468         }
    469     }
    470     return status;
    471 }
    472 
    473 NFCSTATUS
    474 phHciNfc_FSM_Update(
    475                     phHciNfc_sContext_t *psHciContext,
    476                     phHciNfc_eState_t   next_state
    477                     )
    478 {
    479     NFCSTATUS       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
    480 
    481     HCI_DEBUG(" HCI: Current State --> %02u \n",
    482                             psHciContext->hci_state.cur_state );
    483     HCI_DEBUG(" HCI: Transition Before FSM Update --> %02u \n",
    484                     psHciContext->hci_state.transition );
    485     HCI_DEBUG(" HCI: Next State Before FSM Update --> %02u \n",
    486                             psHciContext->hci_state.next_state );
    487 
    488     status = phHciNfc_FSM_Validate(psHciContext, next_state, NFC_FSM_NEXT );
    489     if(NFCSTATUS_SUCCESS == status)
    490     {
    491         psHciContext->hci_state.next_state = (uint8_t) next_state;
    492         psHciContext->hci_state.transition = NFC_FSM_IN_PROGRESS;
    493         psHciContext->response_pending = FALSE;
    494         HCI_DEBUG(" HCI: Next State After FSM Update --> %02u \n",
    495                                 psHciContext->hci_state.next_state );
    496     }
    497     else
    498     {
    499         HCI_DEBUG(" HCI: FSM - Invalid next state --> %02u \n",
    500                                 next_state );
    501     }
    502 
    503     return status;
    504 }
    505 
    506 
    507 NFCSTATUS
    508 phHciNfc_FSM_Complete(
    509                         phHciNfc_sContext_t *psHciContext
    510                     )
    511 {
    512     NFCSTATUS       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
    513 
    514     HCI_DEBUG("HCI: In Function: %s \n", __FUNCTION__);
    515 
    516     HCI_DEBUG(" HCI: Transition Before FSM Complete --> %02u \n",
    517                     psHciContext->hci_state.transition );
    518 
    519     HCI_DEBUG(" HCI: Current State Before FSM Complete --> %02u \n",
    520                             psHciContext->hci_state.cur_state );
    521 
    522     HCI_DEBUG(" HCI: Next State Before FSM Complete  --> %02u \n",
    523                             psHciContext->hci_state.next_state );
    524 
    525     if( (NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition)
    526       )
    527     {
    528         psHciContext->hci_state.cur_state =
    529                                     psHciContext->hci_state.next_state ;
    530         psHciContext->hci_state.transition = NFC_FSM_COMPLETE ;
    531         psHciContext->hci_state.next_state = (uint8_t) hciState_Unknown ;
    532         /* Reset the HCI Sequence */
    533         psHciContext->response_pending = FALSE;
    534         psHciContext->hci_seq = HCI_INVALID_SEQ;
    535         status = NFCSTATUS_SUCCESS;
    536     }
    537 
    538     HCI_DEBUG(" HCI: Current State After FSM Complete --> %02u \n",
    539                             psHciContext->hci_state.cur_state );
    540 
    541     return status;
    542 }
    543 
    544 void
    545 phHciNfc_FSM_Rollback(
    546                         phHciNfc_sContext_t *psHciContext
    547                     )
    548 {
    549 
    550     HCI_DEBUG("HCI: %s: transition=%02u, cur_state=%02u, next_state=%02u\n",
    551             __func__,
    552             psHciContext->hci_state.transition,
    553             psHciContext->hci_state.cur_state,
    554             psHciContext->hci_state.next_state);
    555 
    556 
    557 
    558 
    559 
    560 
    561     if( (NFC_FSM_IN_PROGRESS  == psHciContext->hci_state.transition)
    562       )
    563     {
    564         psHciContext->hci_state.transition = NFC_FSM_COMPLETE ;
    565         psHciContext->hci_state.next_state = (uint8_t) hciState_Unknown ;
    566         /* Reset the HCI Sequence */
    567         psHciContext->hci_seq = HCI_INVALID_SEQ;
    568         psHciContext->response_pending = FALSE;
    569     }
    570 }
    571 
    572 #ifdef HCI_FSM_RESET
    573 static
    574 void
    575 phHciNfc_FSM_Reset(
    576                         phHciNfc_sContext_t *psHciContext
    577                     )
    578 {
    579 
    580     if( (hciState_Reset  != psHciContext->hci_state.cur_state )
    581       )
    582     {
    583         psHciContext->hci_state.cur_state = (uint8_t) hciState_Initialise ;
    584         psHciContext->hci_state.transition = NFC_FSM_COMPLETE ;
    585         psHciContext->hci_state.next_state = (uint8_t) hciState_Unknown ;
    586         /* Reset the HCI Sequence */
    587         psHciContext->hci_seq = HCI_INVALID_SEQ;
    588     }
    589 
    590 }
    591 #endif
    592 
    593 
    594 
    595 static
    596 NFCSTATUS
    597 phHciNfc_Pending_Sequence(
    598                                 phHciNfc_sContext_t     *psHciContext,
    599                                 void                    *pHwRef
    600                           )
    601 {
    602     NFCSTATUS           status = NFCSTATUS_SUCCESS;
    603 
    604     PHNFC_UNUSED_VARIABLE(status);
    605 
    606     HCI_DEBUG("HCI: psHciContext->target_release --> %s \n",
    607             (psHciContext->target_release)?"TRUE":"FALSE");
    608     if(TRUE == psHciContext->target_release)
    609     {
    610 #ifdef SW_RELEASE_TARGET
    611         status = phHciNfc_ReaderMgmt_Deselect(
    612             psHciContext, pHwRef, phHal_eISO14443_A_PICC, TRUE);
    613         if(NFCSTATUS_PENDING == status )
    614         {
    615             psHciContext->target_release = FALSE ;
    616         }
    617     }
    618     else
    619     {
    620         status = psHciContext->error_status;
    621 #else
    622       psHciContext->target_release = FALSE ;
    623 #endif
    624     }
    625 
    626     return status;
    627 }
    628 
    629 
    630 void
    631 phHciNfc_Error_Sequence(
    632                                 void            *psContext,
    633                                 void            *pHwRef,
    634                                 NFCSTATUS       error_status,
    635                                 void            *pdata,
    636                                 uint8_t         length
    637                         )
    638 {
    639     NFCSTATUS           status = NFCSTATUS_SUCCESS;
    640     phHciNfc_sContext_t *psHciContext = (phHciNfc_sContext_t *)psContext;
    641 
    642     PHNFC_UNUSED_VARIABLE(status);
    643 
    644     HCI_DEBUG("HCI: In Function: %s \n",
    645         __FUNCTION__);
    646 
    647     HCI_DEBUG ("HCI : Error Status : %04X\n", error_status);
    648 
    649     HCI_DEBUG(" HCI: Current HCI State --> %02u \n",
    650                             psHciContext->hci_state.cur_state );
    651     HCI_DEBUG(" HCI: Next HCI State --> %02u \n",
    652                             psHciContext->hci_state.next_state );
    653 
    654 
    655     if ( NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition )
    656     {
    657         switch(psHciContext->hci_state.next_state)
    658         {
    659             case hciState_Initialise:
    660             {
    661                 if (hciState_Reset == psHciContext->hci_state.cur_state)
    662                 {
    663                     phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    664 
    665                     phHciNfc_Release_Lower( psHciContext, pHwRef );
    666                     /* Release all the resources and
    667                     * Notify the Receive Error Scenario to the Upper Layer
    668                     */
    669                     comp_info.status = error_status ;
    670                     phHciNfc_Release_Notify (psHciContext, pHwRef,
    671                         NFC_NOTIFY_INIT_FAILED, &comp_info);
    672                 }
    673                 else if (hciState_Config == psHciContext->hci_state.cur_state)
    674                 {
    675                     /* Notify the Poll/Emulation Configure failure to the upper layer */
    676 
    677                     phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    678 
    679                     comp_info.status = error_status ;
    680 
    681                     psHciContext->error_status = error_status;
    682                     status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
    683                     /* Rollback the FSM as the Poll/Emulation configuration Failed */
    684                     phHciNfc_FSM_Rollback(psHciContext);
    685                     psHciContext->error_status = NFCSTATUS_SUCCESS;
    686                     phHciNfc_Notify(psHciContext->p_upper_notify,
    687                         psHciContext->p_upper_context, pHwRef,
    688                         NFC_NOTIFY_CONFIG_ERROR, &comp_info);
    689                 }
    690                 else
    691                 {
    692 
    693                     /* Notify the Poll Configure failure to the upper layer */
    694                     phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    695 
    696 
    697                     psHciContext->error_status = error_status;
    698                     status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
    699                     /* Rollback the FSM as the Poll Disable Failed */
    700                     phHciNfc_FSM_Rollback(psHciContext);
    701                     comp_info.status = error_status ;
    702                     psHciContext->error_status = NFCSTATUS_SUCCESS;
    703                     phHciNfc_Notify(psHciContext->p_upper_notify,
    704                         psHciContext->p_upper_context, pHwRef,
    705                         NFC_NOTIFY_ERROR, &comp_info);
    706                 }
    707                 break;
    708             }
    709             case hciState_Test:
    710             {
    711                 status = phHciNfc_Test_Sequence( psHciContext, pHwRef , error_status,
    712                                                             (uint8_t *)pdata, length );
    713                 break;
    714             }
    715             case hciState_IO:
    716             {
    717                 status = phHciNfc_IO_Sequence( psHciContext, pHwRef , error_status,
    718                                                             (uint8_t *)pdata, length );
    719                 break;
    720             }
    721             case hciState_Config:
    722             {
    723                 /* Notify the Configure failure to the upper layer */
    724                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    725 
    726                 psHciContext->error_status = error_status;
    727                 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
    728                 /* Rollback the FSM as the Poll Failed */
    729                 phHciNfc_FSM_Rollback(psHciContext);
    730                 comp_info.status = psHciContext->error_status ;
    731                 psHciContext->error_status = NFCSTATUS_SUCCESS;
    732                 phHciNfc_Notify(psHciContext->p_upper_notify,
    733                     psHciContext->p_upper_context, pHwRef,
    734                     NFC_NOTIFY_CONFIG_ERROR, &comp_info);
    735                 break;
    736             }
    737             case hciState_Select:
    738             {
    739                 /* Notify the Configure failure to the upper layer */
    740                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    741 
    742                 /* Rollback the FSM as the Target Discovery Failed */
    743                 phHciNfc_FSM_Rollback(psHciContext);
    744                 status = phHciNfc_ReaderMgmt_Update_Sequence(
    745                                                 psHciContext, INFO_SEQ );
    746                 comp_info.status = error_status ;
    747                 phHciNfc_Notify(psHciContext->p_upper_notify,
    748                     psHciContext->p_upper_context, pHwRef,
    749                     NFC_NOTIFY_DISCOVERY_ERROR, &comp_info);
    750 
    751 #if 0
    752                 /* Polling Wheel will be restarted by the upper layer
    753                  * to Rediscover again */
    754                 if(NFCSTATUS_SUCCESS == status)
    755                 {
    756                     status = phHciNfc_ReaderMgmt_Deselect(
    757                         psHciContext, pHwRef, phHal_eISO14443_A_PICC, FALSE);
    758                 }
    759                 phHciNfc_FSM_Rollback(psHciContext);
    760 #endif
    761                 break;
    762             }
    763             case hciState_Transact:
    764                 /* Notify the Transceive failure to the upper layer */
    765             {
    766                 phNfc_sTransactionInfo_t        transact_info={FALSE,0,NULL,NULL,0};
    767 
    768                 /* Rollback the FSM as the Transceive Failed */
    769                 phHciNfc_FSM_Rollback(psHciContext);
    770                 transact_info.status = error_status;
    771                 transact_info.buffer = NULL;
    772                 transact_info.length = FALSE;
    773                 psHciContext->p_xchg_info = NULL ;
    774                 phHciNfc_Notify(psHciContext->p_upper_notify,
    775                     psHciContext->p_upper_context, pHwRef,
    776                     NFC_NOTIFY_TRANSCEIVE_ERROR, &transact_info);
    777                 break;
    778 
    779             }
    780             case hciState_Connect:
    781             {
    782                 /* Notify the General failure to the upper layer */
    783                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    784 
    785                 /* psHciContext->host_rf_type = phHal_eUnknown_DevType; */
    786                 status = phHciNfc_ReaderMgmt_Update_Sequence(
    787                                                 psHciContext, INFO_SEQ );
    788                 psHciContext->p_target_info = NULL;
    789                 psHciContext->hci_state.cur_state = hciState_Select;
    790                 phHciNfc_FSM_Rollback(psHciContext);
    791                 comp_info.status = error_status ;
    792                 phHciNfc_Notify(psHciContext->p_upper_notify,
    793                     psHciContext->p_upper_context, pHwRef,
    794                     NFC_NOTIFY_CONNECT_FAILED, &comp_info);
    795                 break;
    796             }
    797             case hciState_Reactivate:
    798             {
    799                 /* Notify the General failure to the upper layer */
    800                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    801 
    802                 /* psHciContext->host_rf_type = phHal_eUnknown_DevType;
    803                 status = phHciNfc_ReaderMgmt_Update_Sequence(
    804                                                 psHciContext, INFO_SEQ );
    805                 psHciContext->p_target_info = NULL;
    806                 psHciContext->hci_state.cur_state = hciState_Select;  */
    807                 phHciNfc_FSM_Rollback(psHciContext);
    808                 comp_info.status = error_status ;
    809                 phHciNfc_Notify(psHciContext->p_upper_notify,
    810                     psHciContext->p_upper_context, pHwRef,
    811                     NFC_NOTIFY_CONNECT_FAILED, &comp_info);
    812                 break;
    813             }
    814             case hciState_Presence:
    815             {
    816                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    817 
    818                 /* Roll Back to Connect State as Presence Check is Complete */
    819                 phHciNfc_FSM_Rollback(psHciContext);
    820 
    821                 /* Initialisation Complete Notification to the Upper Layer */
    822                 comp_info.status = error_status;
    823                 phHciNfc_Notify(psHciContext->p_upper_notify,
    824                             psHciContext->p_upper_context, pHwRef,
    825                              NFC_NOTIFY_ERROR, &comp_info);
    826                 HCI_PRINT(" HCI Remote Target Removed from the Field. \n");
    827                 break;
    828             }
    829             /* Notify the Connect or Disconnect failure to the upper layer */
    830             case hciState_Disconnect:
    831             {
    832                 /* Notify the General failure to the upper layer */
    833                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    834 
    835                 phHciNfc_FSM_Rollback(psHciContext);
    836                 comp_info.status = error_status ;
    837                 phHciNfc_Notify(psHciContext->p_upper_notify,
    838                     psHciContext->p_upper_context, pHwRef,
    839                     NFC_NOTIFY_DISCONNECT_FAILED, &comp_info);
    840                 break;
    841             }
    842             case hciState_Release:
    843             {
    844 #ifdef NXP_HCI_SHUTDOWN_OVERRIDE
    845                 status = phHciNfc_Release_Sequence(psHciContext ,pHwRef);
    846 #else
    847                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    848 
    849                 phHciNfc_Release_Lower( psHciContext, pHwRef );
    850                 /* Release all the resources and
    851                 * Notify the Receive Error Scenario to the Upper Layer
    852                 */
    853                 comp_info.status = error_status ;
    854                 phHciNfc_Release_Notify (psHciContext, pHwRef,
    855                     NFC_NOTIFY_DEINIT_FAILED, &comp_info);
    856 #endif
    857                 break;
    858             }
    859             default:
    860             {
    861                 /* Notify the General failure to the upper layer */
    862                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    863 
    864                 phHciNfc_FSM_Rollback(psHciContext);
    865                 comp_info.status = error_status ;
    866                 psHciContext->error_status = error_status;
    867                 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
    868                 if (NFCSTATUS_PENDING != status)
    869                 {
    870                     psHciContext->error_status = NFCSTATUS_SUCCESS;
    871                     phHciNfc_Notify(psHciContext->p_upper_notify,
    872                         psHciContext->p_upper_context, pHwRef,
    873                         NFC_NOTIFY_ERROR, &comp_info);
    874                 }
    875                 break;
    876             }
    877 
    878         } /* End of the Processing of HCI State*/
    879     }
    880     else
    881     {
    882         /* Notify the General failure to the upper layer */
    883         phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    884         phHciNfc_FSM_Rollback(psHciContext);
    885         comp_info.status = error_status ;
    886         /* Disable the Notification to the Upper Layer */
    887         if(NFCSTATUS_BOARD_COMMUNICATION_ERROR
    888                             == PHNFCSTATUS(error_status))
    889         {
    890             phHciNfc_Notify(psHciContext->p_upper_notify,
    891                         psHciContext->p_upper_context, pHwRef,
    892                             NFC_NOTIFY_ERROR, &comp_info);
    893         }
    894         else
    895         {
    896             psHciContext->error_status = error_status;
    897             status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
    898             if (NFCSTATUS_PENDING != status)
    899             {
    900                 psHciContext->error_status = NFCSTATUS_SUCCESS;
    901             }
    902         }
    903     }
    904     return;
    905 }
    906 
    907 
    908 
    909 NFCSTATUS
    910 phHciNfc_Resume_Sequence(
    911                                 phHciNfc_sContext_t     *psHciContext,
    912                                 void                    *pHwRef
    913                           )
    914 {
    915     NFCSTATUS           status = NFCSTATUS_SUCCESS;
    916 
    917     HCI_DEBUG("HCI: %s: cur_state=%02u, next_state=%02u",
    918         __FUNCTION__,
    919         psHciContext->hci_state.cur_state,
    920         psHciContext->hci_state.next_state);
    921 
    922 
    923 
    924 
    925     switch(psHciContext->hci_state.next_state)
    926     {
    927         /* Process the Admin Gate Response based on the HCI State */
    928         case hciState_Initialise:
    929         {
    930             switch (psHciContext->hci_state.cur_state)
    931             {
    932                 /* Initialise State after Power on */
    933                 case hciState_Reset:
    934                 {
    935                     status = phHciNfc_Initialise_Sequence(psHciContext ,pHwRef);
    936                     break;
    937                 }
    938                 /* Initialise State after Power on */
    939                 case hciState_Config:
    940                 {
    941                     status = phHciNfc_Config_Sequence(psHciContext ,pHwRef);
    942                     break;
    943                 }
    944                 /* Discovery Resume after connect failure */
    945                 case hciState_Initialise:
    946                 case hciState_Select:
    947                 case hciState_Connect:
    948                 {
    949                     phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
    950 
    951                     /* Update to the Intialise state as the discovery wheel is
    952                      * restarted.
    953                      */
    954                     status = phHciNfc_FSM_Complete(psHciContext);
    955 
    956                     psHciContext->host_rf_type = phHal_eUnknown_DevType;
    957                     psHciContext->p_target_info = NULL;
    958                     psHciContext->p_xchg_info = NULL;
    959 
    960                     /* Initialisation Complete Notification to the Upper Layer */
    961                     comp_info.status = status;
    962                     phHciNfc_Notify(psHciContext->p_upper_notify,
    963                                 psHciContext->p_upper_context, pHwRef,
    964                                 NFC_NOTIFY_POLL_RESTARTED , &comp_info);
    965                     HCI_PRINT(" HCI Remote Target Still Present in the Field. \n");
    966                     break;
    967                 }
    968                 default:
    969                 {
    970                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
    971                     break;
    972                 }
    973             }
    974             break;
    975         }
    976         case hciState_Release:
    977         {
    978             status = phHciNfc_Release_Sequence(psHciContext ,pHwRef);
    979             break;
    980         }
    981         case hciState_Config:
    982         {
    983             status = phHciNfc_Config_Sequence(psHciContext ,pHwRef);
    984             break;
    985         }
    986         case hciState_Listen:
    987         case hciState_Select:
    988         {
    989             status = phHciNfc_Info_Sequence( psHciContext, pHwRef );
    990             break;
    991         }
    992         case hciState_Reactivate:
    993         case hciState_Connect:
    994         {
    995             status = phHciNfc_Connect_Sequence( psHciContext, pHwRef );
    996             break;
    997         }
    998         case hciState_Transact:
    999         {
   1000             status = phHciNfc_Transact_Sequence(
   1001                                             psHciContext, pHwRef );
   1002             break;
   1003         }
   1004         case hciState_Presence:
   1005         {
   1006             phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
   1007 
   1008             /* Roll Back to Connect State as Presence Check is Complete */
   1009             phHciNfc_FSM_Rollback(psHciContext);
   1010 
   1011             /* Initialisation Complete Notification to the Upper Layer */
   1012             comp_info.status = NFCSTATUS_SUCCESS;
   1013             phHciNfc_Notify(psHciContext->p_upper_notify,
   1014                         psHciContext->p_upper_context, pHwRef,
   1015                         NFC_NOTIFY_TARGET_PRESENT , &comp_info);
   1016             HCI_PRINT(" HCI Remote Target Still Present in the Field. \n");
   1017             break;
   1018         }
   1019         case hciState_Disconnect:
   1020         {
   1021             status = phHciNfc_Disconnect_Sequence( psHciContext, pHwRef );
   1022             break;
   1023         }
   1024         case hciState_Test:
   1025         {
   1026             status = phHciNfc_Test_Sequence( psHciContext, pHwRef , status, NULL, 0 );
   1027             break;
   1028         }
   1029         case hciState_IO:
   1030         {
   1031             status = phHciNfc_IO_Sequence( psHciContext, pHwRef , status, NULL, 0 );
   1032             break;
   1033         }
   1034         case hciState_Unknown:
   1035         {
   1036             break;
   1037         }
   1038         default:
   1039         {
   1040             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
   1041             break;
   1042         }
   1043     } /* End of the Processing of HCI State*/
   1044 
   1045     return status;
   1046 }
   1047 
   1048 
   1049 NFCSTATUS
   1050 phHciNfc_Initialise_Sequence(
   1051                                 phHciNfc_sContext_t     *psHciContext,
   1052                                 void                    *pHwRef
   1053                              )
   1054 {
   1055     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1056     static  uint8_t             config = 0;
   1057 
   1058     PHNFC_UNUSED_VARIABLE(config);
   1059 
   1060     switch(psHciContext->hci_seq)
   1061     {
   1062         case ADMIN_INIT_SEQ:
   1063         {
   1064             status = phHciNfc_Admin_Initialise( psHciContext,pHwRef );
   1065             if(NFCSTATUS_SUCCESS == status)
   1066             {
   1067 #ifdef ESTABLISH_SESSION
   1068                 if( hciMode_Session == psHciContext->hci_mode)
   1069                 {
   1070                     /* TODO: Initialise Link Management
   1071                             Gate Resources */
   1072                     NFCSTATUS info_status = NFCSTATUS_SUCCESS;
   1073                     PHNFC_UNUSED_VARIABLE(info_status);
   1074                     info_status = phHciNfc_IDMgmt_Update_Sequence(
   1075                                                 psHciContext, INFO_SEQ );
   1076 
   1077                     if(NFCSTATUS_SUCCESS == info_status)
   1078                     {
   1079                         psHciContext->hci_seq = PL_STOP_SEQ;
   1080                     }
   1081                     else
   1082                     {
   1083                         psHciContext->hci_seq = HCI_END_SEQ;
   1084                         status = PHNFCSTVAL(CID_NFC_HCI,
   1085                                     NFCSTATUS_INVALID_HCI_SEQUENCE);
   1086                     }
   1087                 }
   1088                 else
   1089 #endif
   1090                 {
   1091                     psHciContext->hci_seq = LINK_MGMT_INIT_SEQ;
   1092                 }
   1093             }
   1094             break;
   1095         }
   1096         case LINK_MGMT_INIT_SEQ:
   1097         {
   1098             status = phHciNfc_LinkMgmt_Initialise( psHciContext,pHwRef );
   1099             if(NFCSTATUS_SUCCESS == status)
   1100             {
   1101                 psHciContext->hci_seq = IDENTITY_INIT_SEQ;
   1102             }
   1103             break;
   1104         }
   1105         case IDENTITY_INIT_SEQ:
   1106         {
   1107             status = phHciNfc_IDMgmt_Initialise( psHciContext,pHwRef );
   1108             if(NFCSTATUS_SUCCESS == status)
   1109             {
   1110                 psHciContext->hci_seq = DEV_INIT_SEQ;
   1111             }
   1112             break;
   1113         }
   1114         case DEV_INIT_SEQ:
   1115         {
   1116             status = phHciNfc_DevMgmt_Initialise( psHciContext,pHwRef );
   1117             if(NFCSTATUS_SUCCESS == status)
   1118             {
   1119                 if (HCI_SELF_TEST != psHciContext->init_mode)
   1120                 {
   1121                     psHciContext->hci_seq = PL_INIT_SEQ;
   1122                 }
   1123                 else
   1124                 {
   1125 #if defined( ESTABLISH_SESSION )
   1126                     NFCSTATUS info_status = NFCSTATUS_SUCCESS;
   1127                     PHNFC_UNUSED_VARIABLE(info_status);
   1128                     info_status = phHciNfc_IDMgmt_Update_Sequence(
   1129                                                 psHciContext, INFO_SEQ );
   1130 
   1131                     if(NFCSTATUS_SUCCESS == info_status)
   1132                     {
   1133 #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U )
   1134                         psHciContext->hci_seq = DEV_HAL_INFO_SEQ;
   1135 #else
   1136                         psHciContext->hci_seq = IDENTITY_INFO_SEQ;
   1137 #endif /* #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U ) */
   1138                     }
   1139                     else
   1140                     {
   1141                         psHciContext->hci_seq = HCI_END_SEQ;
   1142                         status = PHNFCSTVAL(CID_NFC_HCI,
   1143                                     NFCSTATUS_INVALID_HCI_SEQUENCE);
   1144                     }
   1145 #elif ( NXP_HAL_MEM_INFO_SIZE > 0x00U )
   1146                     psHciContext->hci_seq = DEV_HAL_INFO_SEQ;
   1147 #else
   1148                     psHciContext->hci_seq = HCI_END_SEQ;
   1149 #endif /* #ifdef ESTABLISH_SESSION */
   1150                 }
   1151 
   1152             }
   1153             break;
   1154         }
   1155         case PL_INIT_SEQ:
   1156         {
   1157             status = phHciNfc_PollLoop_Initialise( psHciContext,pHwRef );
   1158             if(NFCSTATUS_SUCCESS == status)
   1159             {
   1160                 NFCSTATUS reset_status = NFCSTATUS_SUCCESS;
   1161                 PHNFC_UNUSED_VARIABLE(reset_status);
   1162                 reset_status = phHciNfc_ReaderMgmt_Update_Sequence(
   1163                                                     psHciContext, RESET_SEQ );
   1164                 psHciContext->hci_seq = READER_MGMT_INIT_SEQ;
   1165             }
   1166             break;
   1167         }
   1168         case READER_MGMT_INIT_SEQ:
   1169         {
   1170             status = phHciNfc_ReaderMgmt_Initialise( psHciContext,pHwRef );
   1171             if(NFCSTATUS_SUCCESS == status)
   1172             {
   1173                 NFCSTATUS reset_status = NFCSTATUS_SUCCESS;
   1174                 PHNFC_UNUSED_VARIABLE(reset_status);
   1175                 reset_status =  phHciNfc_EmuMgmt_Update_Seq(
   1176                                                 psHciContext, RESET_SEQ );
   1177                 psHciContext->hci_seq = EMULATION_INIT_SEQ;
   1178             }
   1179             break;
   1180         }
   1181         case EMULATION_INIT_SEQ:
   1182         {
   1183             status = phHciNfc_EmuMgmt_Initialise( psHciContext,pHwRef );
   1184             if(NFCSTATUS_SUCCESS == status)
   1185             {
   1186 #if defined( ESTABLISH_SESSION )
   1187                 psHciContext->hci_seq = ADMIN_SESSION_SEQ;
   1188 #elif ( NXP_HAL_MEM_INFO_SIZE > 0x00U )
   1189                 psHciContext->hci_seq = DEV_HAL_INFO_SEQ;
   1190 #else
   1191                 psHciContext->hci_seq = HCI_END_SEQ;
   1192 #endif
   1193             }
   1194             break;
   1195         }
   1196 #ifdef ESTABLISH_SESSION
   1197         case ADMIN_SESSION_SEQ:
   1198         {
   1199             status = phHciNfc_Admin_Initialise( psHciContext,pHwRef );
   1200             if(NFCSTATUS_SUCCESS == status)
   1201             {
   1202 #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U )
   1203                 psHciContext->hci_seq = DEV_HAL_INFO_SEQ;
   1204 #else
   1205                 psHciContext->hci_seq = IDENTITY_INFO_SEQ;
   1206 #endif /* #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U ) */
   1207             }
   1208             break;
   1209         }
   1210         case PL_STOP_SEQ:
   1211         {
   1212             status = phHciNfc_ReaderMgmt_Disable_Discovery(
   1213                                                 psHciContext, pHwRef );
   1214             if(NFCSTATUS_SUCCESS == status)
   1215             {
   1216 #if defined( SW_AUTO_ACTIVATION )
   1217                 psHciContext->hci_seq = READER_SW_AUTO_SEQ;
   1218 #elif ( NXP_HAL_MEM_INFO_SIZE > 0x00U )
   1219                 psHciContext->hci_seq = DEV_HAL_INFO_SEQ;
   1220 #else
   1221                 psHciContext->hci_seq = IDENTITY_INFO_SEQ;
   1222 #endif /* #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U ) */
   1223             }
   1224             break;
   1225         }
   1226 #ifdef SW_AUTO_ACTIVATION
   1227         case READER_SW_AUTO_SEQ:
   1228         {
   1229             uint8_t     activate_enable = FALSE;
   1230             uint8_t     rdr_enable = TRUE;
   1231 
   1232             status = phHciNfc_ReaderA_Update_Info(
   1233                     psHciContext, HCI_READER_A_ENABLE,
   1234                                             &rdr_enable);
   1235             if(status == NFCSTATUS_SUCCESS)
   1236             {
   1237                 status = phHciNfc_ReaderA_Auto_Activate( psHciContext,
   1238                                                 pHwRef, activate_enable );
   1239                 if(status == NFCSTATUS_SUCCESS)
   1240                 {
   1241                     psHciContext->hci_seq = IDENTITY_INFO_SEQ;
   1242                 }
   1243             }
   1244             break;
   1245         }
   1246 #endif
   1247         /* fall through */
   1248         case IDENTITY_INFO_SEQ:
   1249         {
   1250             status = phHciNfc_IDMgmt_Info_Sequence( psHciContext,pHwRef );
   1251             if(NFCSTATUS_SUCCESS == status)
   1252             {
   1253                 if ((HCI_SELF_TEST != psHciContext->init_mode)
   1254                     /* && ( TRUE == ((phHal_sHwReference_t *)pHwRef)->se_detect ) */
   1255                     && (HCI_CUSTOM_INIT != psHciContext->init_mode)
   1256                     && (HCI_NFC_DEVICE_TEST != psHciContext->init_mode))
   1257                 {
   1258                     NFCSTATUS info_status = NFCSTATUS_SUCCESS;
   1259                     PHNFC_UNUSED_VARIABLE(info_status);
   1260                     info_status = phHciNfc_EmuMgmt_Update_Seq(
   1261                                                 psHciContext, INFO_SEQ );
   1262 
   1263                     if(NFCSTATUS_SUCCESS == info_status)
   1264                     {
   1265                         psHciContext->hci_seq = EMULATION_SWP_SEQ;
   1266                     }
   1267                 }
   1268                 else
   1269                 {
   1270                     psHciContext->hci_seq = HCI_END_SEQ;
   1271                 }
   1272             }
   1273             break;
   1274         }
   1275         case EMULATION_SWP_SEQ:
   1276         {
   1277             status = phHciNfc_EmuMgmt_Initialise( psHciContext,pHwRef );
   1278             if(NFCSTATUS_SUCCESS == status)
   1279             {
   1280                 psHciContext->hci_seq = HCI_END_SEQ;
   1281             }
   1282             break;
   1283         }
   1284 #endif /* #ifdef ESTABLISH_SESSION */
   1285 
   1286 #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U )
   1287         case DEV_HAL_INFO_SEQ:
   1288         {
   1289             static uint8_t      mem_index = 0;
   1290             status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef,
   1291                         (NFC_ADDRESS_HAL_CONF + mem_index),
   1292                             (psHciContext->hal_mem_info + mem_index));
   1293             if(NFCSTATUS_PENDING == status)
   1294             {
   1295                 mem_index++;
   1296                 if (NXP_HAL_MEM_INFO_SIZE <= mem_index )
   1297                 {
   1298                     NFCSTATUS info_status = NFCSTATUS_SUCCESS;
   1299                     PHNFC_UNUSED_VARIABLE(info_status);
   1300                     info_status = phHciNfc_IDMgmt_Update_Sequence(
   1301                                                 psHciContext, INFO_SEQ );
   1302                     mem_index = 0;
   1303                     psHciContext->hci_seq = IDENTITY_INFO_SEQ;
   1304                     /* psHciContext->hci_seq =
   1305                             (HCI_SELF_TEST != psHciContext->init_mode)?
   1306                                     IDENTITY_INFO_SEQ : HCI_END_SEQ; */
   1307                 }
   1308             }
   1309             break;
   1310         }
   1311 #endif /* #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U ) */
   1312         case HCI_END_SEQ:
   1313         {
   1314             phHal_sMemInfo_t    *p_mem_info =
   1315                     (phHal_sMemInfo_t *) ( psHciContext->hal_mem_info );
   1316             if (
   1317                 (HCI_SELF_TEST == psHciContext->init_mode )
   1318                 || (HCI_NFC_DEVICE_TEST == psHciContext->init_mode )
   1319                 )
   1320             {
   1321                 psHciContext->hci_state.next_state
   1322                     = (uint8_t) hciState_Test;
   1323             }
   1324             status = phHciNfc_FSM_Complete ( psHciContext );
   1325 #ifdef UICC_CONNECTIVITY_PATCH
   1326             phHciNfc_Uicc_Connectivity( psHciContext, pHwRef );
   1327 #endif /* #ifdef UICC_CONNECTIVITY_PATCH */
   1328 
   1329 #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U )
   1330             if(NXP_FW_UPLOAD_SUCCESS != p_mem_info->fw_magic )
   1331             {
   1332                 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FAILED );
   1333             }
   1334 #endif /* #if ( NXP_HAL_MEM_INFO_SIZE > 0x00U ) */
   1335 
   1336             /* Initialisation Complete Notification to the Upper Layer */
   1337             if(NFCSTATUS_SUCCESS == status)
   1338             {
   1339                 phNfc_sCompletionInfo_t     comp_info={FALSE,0, NULL};
   1340 
   1341                 comp_info.status = status;
   1342                 phHciNfc_Notify(psHciContext->p_upper_notify,
   1343                         psHciContext->p_upper_context, pHwRef,
   1344                                 NFC_NOTIFY_INIT_COMPLETED, &comp_info);
   1345                 HCI_PRINT("HCI Initialisation Completed \n");
   1346             }
   1347             else
   1348             {
   1349                 pphNfcIF_Notification_CB_t  p_upper_notify = psHciContext->p_upper_notify;
   1350                 void                        *pcontext = psHciContext->p_upper_context;
   1351                 phNfc_sCompletionInfo_t     comp_info;
   1352 
   1353 
   1354                 phHciNfc_Release_Lower( psHciContext, pHwRef );
   1355                 phHciNfc_Release_Resources( &psHciContext );
   1356                  /* Notify the Failure to the Upper Layer */
   1357                 comp_info.status = status;
   1358                 phHciNfc_Notify( p_upper_notify, pcontext, pHwRef,
   1359                                 NFC_NOTIFY_INIT_FAILED, &comp_info);
   1360                 HCI_PRINT("HCI FSM Initialisation Error \n");
   1361             }
   1362             break;
   1363         }
   1364         default:
   1365             break;
   1366     }
   1367 
   1368     return status;
   1369 }
   1370 
   1371 
   1372 NFCSTATUS
   1373 phHciNfc_Release_Sequence(
   1374                             phHciNfc_sContext_t     *psHciContext,
   1375                             void                    *pHwRef
   1376                          )
   1377 {
   1378     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   1379 
   1380     switch(psHciContext->hci_seq)
   1381     {
   1382         case PL_STOP_SEQ:
   1383         {
   1384             status = phHciNfc_ReaderMgmt_Disable_Discovery(
   1385                                                 psHciContext, pHwRef );
   1386             if(NFCSTATUS_SUCCESS == status)
   1387             {
   1388                 (void)phHciNfc_EmuMgmt_Update_Seq(
   1389                                     psHciContext, REL_SEQ );
   1390                 psHciContext->hci_seq = EMULATION_REL_SEQ;
   1391                 status = NFCSTATUS_PENDING;
   1392             }
   1393             break;
   1394         }
   1395         case EMULATION_REL_SEQ:
   1396         {
   1397             status = phHciNfc_EmuMgmt_Release( psHciContext,pHwRef );
   1398             if(NFCSTATUS_SUCCESS == status)
   1399             {
   1400                 (void)phHciNfc_DevMgmt_Update_Sequence(
   1401                                     psHciContext, REL_SEQ );
   1402                 psHciContext->hci_seq = ADMIN_REL_SEQ;
   1403                 status = NFCSTATUS_PENDING;
   1404             }
   1405             break;
   1406         }
   1407         case DEV_REL_SEQ:
   1408         {
   1409             NFCSTATUS info_status = NFCSTATUS_SUCCESS;
   1410             PHNFC_UNUSED_VARIABLE(info_status);
   1411             info_status = phHciNfc_DevMgmt_Update_Sequence(
   1412                                             psHciContext, REL_SEQ );
   1413             status = phHciNfc_DevMgmt_Release( psHciContext, pHwRef );
   1414             if(NFCSTATUS_SUCCESS == status)
   1415             {
   1416                 psHciContext->hci_seq = HCI_END_SEQ;
   1417                 status = NFCSTATUS_PENDING;
   1418             }
   1419             break;
   1420         }
   1421         case READER_MGMT_REL_SEQ:
   1422         {
   1423             status = phHciNfc_ReaderMgmt_Release( psHciContext,pHwRef );
   1424             if(NFCSTATUS_SUCCESS == status)
   1425             {
   1426                 psHciContext->hci_seq = PL_REL_SEQ;
   1427                 status = NFCSTATUS_PENDING;
   1428             }
   1429             break;
   1430         }
   1431         case PL_REL_SEQ:
   1432         {
   1433             status = phHciNfc_PollLoop_Release( psHciContext,pHwRef );
   1434             if(NFCSTATUS_SUCCESS == status)
   1435             {
   1436                 psHciContext->hci_seq = IDENTITY_REL_SEQ;
   1437                 status = NFCSTATUS_PENDING;
   1438             }
   1439             break;
   1440         }
   1441         case IDENTITY_REL_SEQ:
   1442         {
   1443             status = phHciNfc_IDMgmt_Release( psHciContext,pHwRef );
   1444             if(NFCSTATUS_SUCCESS == status)
   1445             {
   1446                 psHciContext->hci_seq = LINK_MGMT_REL_SEQ;
   1447                 status = NFCSTATUS_PENDING;
   1448             }
   1449             break;
   1450         }
   1451         case LINK_MGMT_REL_SEQ:
   1452         {
   1453             status = phHciNfc_LinkMgmt_Release( psHciContext,pHwRef );
   1454             if(NFCSTATUS_SUCCESS == status)
   1455             {
   1456                 psHciContext->hci_seq = ADMIN_REL_SEQ;
   1457                 status = NFCSTATUS_PENDING;
   1458             }
   1459             break;
   1460         }
   1461         case ADMIN_REL_SEQ:
   1462         {
   1463             /*  Admin Management Release Sequence */
   1464             status = phHciNfc_Admin_Release( psHciContext,pHwRef, phHciNfc_TerminalHostID );
   1465             if(NFCSTATUS_SUCCESS == status)
   1466             {
   1467                 psHciContext->hci_seq = DEV_REL_SEQ;
   1468                 status = NFCSTATUS_PENDING;
   1469             }
   1470             break;
   1471         }
   1472         case HCI_END_SEQ:
   1473         {
   1474             pphNfcIF_Notification_CB_t  p_upper_notify =
   1475                                             psHciContext->p_upper_notify;
   1476             phNfc_sLowerIF_t            *plower_if =
   1477                                             &(psHciContext->lower_interface);
   1478             void                        *pcontext =
   1479                                                 psHciContext->p_upper_context;
   1480             phNfc_sCompletionInfo_t     comp_info;
   1481 
   1482 
   1483             status = plower_if->release((void *)plower_if->pcontext,
   1484                                             (void *)pHwRef);
   1485 
   1486             phHciNfc_Release_Resources( &psHciContext );
   1487             /* De-Initialisation Complete Notification to the Upper Layer */
   1488             comp_info.status = status;
   1489             phHciNfc_Notify(p_upper_notify, pcontext, pHwRef,
   1490                                     NFC_NOTIFY_DEINIT_COMPLETED, &comp_info);
   1491 
   1492             HCI_PRINT("HCI Release Completed \n");
   1493             break;
   1494         }
   1495         default:
   1496         {
   1497             /* psHciContext->hci_seq = HCI_END_SEQ; */
   1498             break;
   1499         }
   1500     }
   1501 
   1502     return status;
   1503 }
   1504 
   1505 
   1506 static
   1507 NFCSTATUS
   1508 phHciNfc_Config_Sequence(
   1509                            phHciNfc_sContext_t      *psHciContext,
   1510                            void                 *pHwRef
   1511                         )
   1512 {
   1513     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1514     phNfc_sCompletionInfo_t     comp_info = {FALSE,0,NULL};
   1515 
   1516     switch(psHciContext->config_type)
   1517     {
   1518         case POLL_LOOP_CFG:
   1519         {
   1520             status = phHciNfc_PollLoop_Sequence( psHciContext, pHwRef );
   1521             break;
   1522         }
   1523         case SMX_WI_MODE:
   1524         {
   1525             status = phHciNfc_SmartMx_Mode_Sequence( psHciContext, pHwRef );
   1526             break;
   1527         }
   1528 #ifdef ENABLE_P2P
   1529         case NFC_GENERAL_CFG:
   1530         {
   1531             if(TARGET_GENERAL_SEQ == psHciContext->hci_seq)
   1532             {
   1533                 status = phHciNfc_NfcIP_SetATRInfo( psHciContext,
   1534                                         pHwRef, NFCIP_TARGET,
   1535                                         psHciContext->p_config_params);
   1536                     if( NFCSTATUS_PENDING != status )
   1537                     {
   1538                         /* Roll Back the State Machine to its Original State */
   1539                         phHciNfc_FSM_Rollback ( psHciContext );
   1540                     }
   1541                     else
   1542                     {
   1543                         psHciContext->hci_seq = HCI_END_SEQ;
   1544                     }
   1545             }
   1546             else
   1547             {
   1548                 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
   1549                 if (NFCSTATUS_PENDING != status)
   1550                 {
   1551                     /* Roll Back to its Current State as Configuration is Complete */
   1552                     phHciNfc_FSM_Rollback(psHciContext);
   1553 
   1554                     HCI_PRINT(" NFC-IP(P2P) Configuration Completed. \n");
   1555                     comp_info.status = status;
   1556                     psHciContext->error_status = NFCSTATUS_SUCCESS;
   1557                     phHciNfc_Notify(psHciContext->p_upper_notify,
   1558                                     psHciContext->p_upper_context, pHwRef,
   1559                                         NFC_NOTIFY_CONFIG_SUCCESS , &comp_info);
   1560                 }
   1561             }
   1562             break;
   1563         }
   1564 #endif
   1565         case SWP_PROTECT_CFG:
   1566         case SWP_EVT_CFG:
   1567         case SMX_WI_CFG:
   1568         {
   1569             /* Roll Back to its Current State as Configuration is Complete */
   1570             phHciNfc_FSM_Rollback(psHciContext);
   1571 
   1572             HCI_DEBUG(" %s Configuration Completed. \n",
   1573                   ((SMX_WI_CFG == psHciContext->config_type)?
   1574                         "SmartMX" : "SWP Event/Protection"));
   1575 
   1576             comp_info.status = status;
   1577             phHciNfc_Notify(psHciContext->p_upper_notify,
   1578                                 psHciContext->p_upper_context, pHwRef,
   1579                                 NFC_NOTIFY_CONFIG_SUCCESS, &comp_info);
   1580             break;
   1581         }
   1582         case NFC_TARGET_CFG:
   1583         {
   1584             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1585             break;
   1586         }
   1587         case UICC_SWP_CFG:
   1588 #if 0
   1589         {
   1590             phHal_sEmulationCfg_t   *p_emulation_cfg =
   1591                                         (phHal_sEmulationCfg_t * )
   1592                                                 psHciContext->p_config_params;
   1593             if (NULL != p_emulation_cfg)
   1594             {
   1595                 phHal_sUiccEmuCfg_t   *uicc_config =
   1596                                     &p_emulation_cfg->config.uiccEmuCfg;
   1597                 if( TRUE == uicc_config->enableUicc )
   1598                 {
   1599                     status = phHciNfc_Uicc_Connect_Status(psHciContext,pHwRef);
   1600                     if( NFCSTATUS_PENDING == status )
   1601                     {
   1602                         break;
   1603                     } /* Or Else Fall through to notify the above layer */
   1604                 }
   1605             }
   1606         }
   1607 #endif
   1608         /* fall through */
   1609         case NFC_CE_A_CFG:
   1610         case NFC_CE_B_CFG:
   1611         {
   1612             status = phHciNfc_EmulationCfg_Sequence( psHciContext, pHwRef );
   1613             break;
   1614         }
   1615         default:
   1616         {
   1617             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
   1618             break;
   1619         }
   1620     }
   1621 
   1622     return status;
   1623 }
   1624 
   1625 
   1626 NFCSTATUS
   1627 phHciNfc_PollLoop_Sequence(
   1628                            phHciNfc_sContext_t      *psHciContext,
   1629                            void                 *pHwRef
   1630                            )
   1631 {
   1632     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   1633     phHal_sADD_Cfg_t    *p_poll_config = (phHal_sADD_Cfg_t * )
   1634         psHciContext->p_config_params;
   1635     if (NULL != p_poll_config)
   1636     {
   1637         uint8_t speed =
   1638                 p_poll_config->NfcIP_Mode;
   1639         uint8_t targetSpeed =
   1640                 p_poll_config->NfcIP_Target_Mode;
   1641         switch(psHciContext->hci_seq)
   1642         {
   1643             case PL_DURATION_SEQ:
   1644             {
   1645                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   1646                     (uint8_t)PL_DURATION , NULL);
   1647                 if(NFCSTATUS_SUCCESS == status)
   1648                 {
   1649 #if defined (ENABLE_P2P) && defined (TARGET_SPEED)
   1650                     psHciContext->hci_seq = TARGET_SPEED_SEQ;
   1651 #elif defined (ENABLE_P2P) && defined (INITIATOR_SPEED)
   1652                     psHciContext->hci_seq = INITIATOR_SPEED_SEQ;
   1653 #elif defined (ENABLE_P2P) &&  defined (NFCIP_TGT_DISABLE_CFG)
   1654                     psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1655 #else
   1656                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1657 #endif
   1658 
   1659                     status = NFCSTATUS_PENDING;
   1660                 }
   1661                 break;
   1662             }
   1663 #if defined (ENABLE_P2P) && defined (TARGET_SPEED)
   1664             case TARGET_SPEED_SEQ:
   1665             {
   1666 #define NFCIP_ACTIVE_SHIFT	0x03U
   1667 #define NFCIP_PASSIVE_MASK	0x07U
   1668                 uint8_t mode = targetSpeed;
   1669                 HCI_DEBUG("Setting target mode to 0x%02X", mode);
   1670                 status =
   1671                     phHciNfc_NfcIP_SetMode( psHciContext, pHwRef, NFCIP_TARGET,
   1672                      (uint8_t) mode );
   1673                 if(NFCSTATUS_PENDING == status)
   1674                 {
   1675 #if defined (INITIATOR_SPEED)
   1676                     psHciContext->hci_seq = INITIATOR_SPEED_SEQ;
   1677 #elif defined (NFCIP_TGT_DISABLE_CFG)
   1678                     psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1679 #else
   1680                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1681 #endif
   1682                     status = NFCSTATUS_PENDING;
   1683                 }
   1684                 break;
   1685             }
   1686 #endif
   1687 #if defined (ENABLE_P2P) && defined (INITIATOR_SPEED)
   1688             case INITIATOR_SPEED_SEQ:
   1689             {
   1690                 HCI_DEBUG("Setting initiator mode to 0x%02X", speed);
   1691                 status =
   1692                     phHciNfc_NfcIP_SetMode( psHciContext, pHwRef, NFCIP_INITIATOR,
   1693                      (uint8_t) (speed & DEFAULT_NFCIP_INITIATOR_MODE_SUPPORT));
   1694                 if(NFCSTATUS_PENDING == status)
   1695                 {
   1696 #if defined (NFCIP_TGT_DISABLE_CFG)
   1697                     psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1698 #else
   1699                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1700 #endif
   1701                     status = NFCSTATUS_PENDING;
   1702                 }
   1703                 break;
   1704             }
   1705 #endif
   1706 #if defined (ENABLE_P2P) && defined (NFCIP_TGT_DISABLE_CFG)
   1707             case PL_TGT_DISABLE_SEQ:
   1708             {
   1709                 /* Configure the Polling Loop Target Disable Parameter */
   1710                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   1711                 (uint8_t)PL_DISABLE_TARGET, &p_poll_config->NfcIP_Tgt_Disable );
   1712                 if(NFCSTATUS_SUCCESS == status)
   1713                 {
   1714                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1715                     status = NFCSTATUS_PENDING;
   1716                 }
   1717                 break;
   1718             }
   1719 #endif
   1720             case PL_CONFIG_PHASE_SEQ:
   1721             {
   1722                 phHal_sPollDevInfo_t *p_poll_info =
   1723                                 &(p_poll_config->PollDevInfo.PollCfgInfo);
   1724 
   1725                 p_poll_info->EnableIso14443A =
   1726                     ( (p_poll_info->EnableIso14443A)
   1727                                     || ( speed & (uint8_t)phHal_ePassive106 )
   1728                                     );
   1729                 p_poll_info->EnableFelica212 =
   1730                             ( (p_poll_info->EnableFelica212)
   1731                                     || ( speed & (uint8_t)phHal_ePassive212 )
   1732                                     );
   1733                 p_poll_info->EnableFelica424 =
   1734                             ( (p_poll_info->EnableFelica424)
   1735                                     || ( speed & (uint8_t)phHal_ePassive424 )
   1736                                     );
   1737                 /* Configure the Polling Loop Gate Parameters */
   1738                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   1739                     (uint8_t)PL_RD_PHASES, NULL );
   1740                 if(NFCSTATUS_SUCCESS == status)
   1741                 {
   1742                     if(((~(PL_RD_PHASES_DISABLE)) &
   1743                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   1744                     {
   1745                         psHciContext->hci_seq = READER_ENABLE_SEQ;
   1746                     }
   1747                     else
   1748                     {
   1749                         /* psHciContext->hci_seq = READER_DISABLE_SEQ; */
   1750                         psHciContext->hci_seq = HCI_END_SEQ;
   1751                     }
   1752                     status = NFCSTATUS_PENDING;
   1753                 }
   1754                 break;
   1755             }
   1756             case READER_ENABLE_SEQ:
   1757             {
   1758                 status =
   1759                     phHciNfc_ReaderMgmt_Enable_Discovery(
   1760                     psHciContext, pHwRef );
   1761                 if(NFCSTATUS_SUCCESS == status)
   1762                 {
   1763                     /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */
   1764                     psHciContext->hci_seq = HCI_END_SEQ;
   1765                     status = NFCSTATUS_PENDING;
   1766                 }
   1767                 break;
   1768             }
   1769             case READER_DISABLE_SEQ:
   1770             {
   1771                 status = phHciNfc_ReaderMgmt_Disable_Discovery(
   1772                     psHciContext, pHwRef );
   1773 
   1774                 if(NFCSTATUS_SUCCESS == status)
   1775                 {
   1776                     if((~(PL_RD_PHASES_DISABLE) &
   1777                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   1778                     {
   1779                         psHciContext->hci_seq = PL_DURATION_SEQ;
   1780                     }
   1781                     else
   1782                     {
   1783 #if defined (ENABLE_P2P) && defined (INITIATOR_SPEED)
   1784                         psHciContext->hci_seq = INITIATOR_SPEED_SEQ;
   1785 #elif defined (ENABLE_P2P) &&  defined (NFCIP_TGT_DISABLE_CFG)
   1786                         psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1787 #else
   1788                         psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1789 #endif
   1790                         /* psHciContext->hci_seq = HCI_END_SEQ; */
   1791                     }
   1792                     status = NFCSTATUS_PENDING;
   1793                 }
   1794                 break;
   1795             }
   1796             case HCI_END_SEQ:
   1797             {
   1798                 phNfc_sCompletionInfo_t     comp_info;
   1799                 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
   1800                 if (NFCSTATUS_PENDING != status)
   1801                 {
   1802                     /* status = phHciNfc_FSM_Complete ( psHciContext );*/
   1803                     phHciNfc_FSM_Rollback ( psHciContext );
   1804                     /* Poll Configuration Notification to the Upper Layer */
   1805                     if((~(PL_RD_PHASES_DISABLE) &
   1806                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   1807                     {
   1808                         comp_info.status = status;
   1809                         phHciNfc_Notify(psHciContext->p_upper_notify,
   1810                             psHciContext->p_upper_context, pHwRef,
   1811                             NFC_NOTIFY_POLL_ENABLED, &comp_info);
   1812                     }
   1813                     else
   1814                     {
   1815                         comp_info.status = status;
   1816                         phHciNfc_Notify(psHciContext->p_upper_notify,
   1817                             psHciContext->p_upper_context, pHwRef,
   1818                             NFC_NOTIFY_POLL_DISABLED, &comp_info);
   1819                     }
   1820                     HCI_PRINT("HCI Discovery Configuration Completed \n");
   1821                 }
   1822                 break;
   1823             }
   1824             default:
   1825             {
   1826                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   1827                 break;
   1828             }
   1829         }/* End of the Poll Sequence Switch */
   1830     }/* End of the Poll Config info Check */
   1831 
   1832     return status;
   1833 }
   1834 
   1835 
   1836 NFCSTATUS
   1837 phHciNfc_EmulationCfg_Sequence(
   1838                             phHciNfc_sContext_t     *psHciContext,
   1839                             void                    *pHwRef
   1840                          )
   1841 {
   1842     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   1843     static phNfc_sCompletionInfo_t      comp_info = {FALSE,0,NULL};
   1844 #if defined(HOST_EMULATION)
   1845     phHciNfc_GateID_t       ce_gate = phHciNfc_UnknownGate;
   1846 #endif  /* #ifdef HOST_EMULATION */
   1847     phHal_sEmulationCfg_t   *p_emulation_cfg = (phHal_sEmulationCfg_t * )
   1848                                         psHciContext->p_config_params;
   1849 #ifdef UICC_SESSION_RESET
   1850     uint8_t                 uicc_clear_pipes = FALSE;
   1851 #endif
   1852 
   1853 
   1854     if (NULL != p_emulation_cfg)
   1855     {
   1856 #if defined(HOST_EMULATION)
   1857         if(NFC_HOST_CE_A_EMULATION == p_emulation_cfg->emuType)
   1858         {
   1859             psHciContext->config_type = NFC_CE_A_CFG;
   1860             if (NULL == psHciContext->p_ce_a_info)
   1861             {
   1862                 ce_gate = phHciNfc_CETypeAGate;
   1863             }
   1864         }
   1865         else if (NFC_HOST_CE_B_EMULATION == p_emulation_cfg->emuType)
   1866         {
   1867             psHciContext->config_type = NFC_CE_B_CFG;
   1868             if (NULL == psHciContext->p_ce_b_info)
   1869             {
   1870                 ce_gate = phHciNfc_CETypeBGate;
   1871             }
   1872         }
   1873 #ifdef UICC_SESSION_RESET
   1874         else if ((NFC_UICC_EMULATION == p_emulation_cfg->emuType)
   1875             &&(FALSE == p_emulation_cfg->config.uiccEmuCfg.enableUicc)
   1876             )
   1877         {
   1878             uicc_clear_pipes = TRUE;
   1879         }
   1880 #endif
   1881         else
   1882         {
   1883             ;
   1884         }
   1885 #endif  /* #ifdef HOST_EMULATION */
   1886 
   1887         switch(psHciContext->hci_seq)
   1888         {
   1889 #if defined(HOST_EMULATION)
   1890             case ADMIN_CE_SEQ:
   1891             {
   1892                 if(phHciNfc_UnknownGate != ce_gate)
   1893                 {
   1894                     status = phHciNfc_Admin_CE_Init(psHciContext, pHwRef, ce_gate);
   1895                 }
   1896                 else
   1897                 {
   1898                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_NOT_ALLOWED);
   1899                 }
   1900 
   1901                 if(NFCSTATUS_SUCCESS == status)
   1902                 {
   1903                     psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
   1904                     /* psHciContext->hci_seq = HCI_END_SEQ; */
   1905                     status = NFCSTATUS_PENDING;
   1906                 }
   1907                 break;
   1908             }
   1909 #endif
   1910             case EMULATION_CONFIG_SEQ:
   1911             {
   1912                 status = phHciNfc_Emulation_Cfg(psHciContext, pHwRef,
   1913                                                 psHciContext->config_type);
   1914                 if(NFCSTATUS_SUCCESS == status)
   1915                 {
   1916                     /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */
   1917 #ifdef UICC_SESSION_RESET
   1918                     if(UICC_SWP_CFG == psHciContext->config_type)
   1919                     {
   1920                         psHciContext->hci_seq = ADMIN_REL_SEQ;
   1921                     }
   1922                     else
   1923 #endif /* UICC_SESSION_RESET */
   1924                     {
   1925                         psHciContext->hci_seq = HCI_END_SEQ;
   1926                     }
   1927                     status = NFCSTATUS_PENDING;
   1928                 }
   1929                 break;
   1930             }
   1931 #ifdef UICC_SESSION_RESET
   1932             case ADMIN_REL_SEQ:
   1933             {
   1934                 if (TRUE == uicc_clear_pipes)
   1935                 {
   1936                     /*  Admin Management UICC Release Sequence */
   1937                     status = phHciNfc_Admin_Release( psHciContext,pHwRef, phHciNfc_UICCHostID );
   1938                     if(NFCSTATUS_SUCCESS == status)
   1939                     {
   1940                         psHciContext->hci_seq = HCI_END_SEQ;
   1941                         if (UICC_SWP_CFG == psHciContext->config_type)
   1942                         {
   1943                             (void)phHciNfc_SWP_Update_Sequence(psHciContext,
   1944                                                                         CONFIG_SEQ );
   1945                         }
   1946                         status = NFCSTATUS_PENDING;
   1947                     }
   1948                     break;
   1949                 }
   1950             }
   1951 #endif /* UICC_SESSION_RESET */
   1952             /* fall through */
   1953             case HCI_END_SEQ:
   1954             {
   1955                 phHciNfc_FSM_Rollback(psHciContext);
   1956 
   1957                 HCI_PRINT(" Emulation Configuration Completed. \n");
   1958 
   1959                 comp_info.status = status;
   1960                 phHciNfc_Notify(psHciContext->p_upper_notify,
   1961                                  psHciContext->p_upper_context, pHwRef,
   1962                                    NFC_NOTIFY_CONFIG_SUCCESS, &comp_info);
   1963                 break;
   1964             }
   1965             default:
   1966             {
   1967                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   1968                 break;
   1969             }
   1970         }
   1971         /*
   1972             NFC_CE_A_CFG;
   1973             NFC_CE_B_CFG; */
   1974 
   1975     }/* End of the Emulation Config info Check */
   1976 
   1977     return status;
   1978 }
   1979 
   1980 
   1981 NFCSTATUS
   1982 phHciNfc_SmartMx_Mode_Sequence(
   1983                            phHciNfc_sContext_t      *psHciContext,
   1984                            void                     *pHwRef
   1985                           )
   1986 {
   1987     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   1988     phHal_sADD_Cfg_t    *p_poll_config = (phHal_sADD_Cfg_t * )
   1989         psHciContext->p_config_params;
   1990     phNfc_sCompletionInfo_t     comp_info = {FALSE,0,NULL};
   1991     if (NULL != p_poll_config)
   1992     {
   1993         switch(psHciContext->hci_seq)
   1994         {
   1995             case READER_DISABLE_SEQ:
   1996             {
   1997                 status = phHciNfc_ReaderMgmt_Disable_Discovery(
   1998                     psHciContext, pHwRef );
   1999                 if(NFCSTATUS_SUCCESS == status)
   2000                 {
   2001                     psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
   2002                     /* psHciContext->hci_seq = HCI_END_SEQ; */
   2003                     status = NFCSTATUS_PENDING;
   2004                 }
   2005                 break;
   2006             }
   2007             case EMULATION_CONFIG_SEQ:
   2008             {
   2009                 status = phHciNfc_WI_Configure_Mode(
   2010                     psHciContext, pHwRef,psHciContext->smx_mode );
   2011                 if(NFCSTATUS_SUCCESS == status)
   2012                 {
   2013                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   2014                     /* psHciContext->hci_seq = HCI_END_SEQ; */
   2015                     status = NFCSTATUS_PENDING;
   2016                 }
   2017                 break;
   2018             }
   2019             case PL_CONFIG_PHASE_SEQ:
   2020             {
   2021                 /* Configure the Polling Loop Gate Parameters */
   2022                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   2023                     (uint8_t)PL_RD_PHASES, NULL );
   2024                 if(NFCSTATUS_SUCCESS == status)
   2025                 {
   2026                     psHciContext->hci_seq = READER_ENABLE_SEQ;
   2027                     status = NFCSTATUS_PENDING;
   2028                 }
   2029                 break;
   2030             }
   2031             case READER_ENABLE_SEQ:
   2032             {
   2033                 status =
   2034                     phHciNfc_ReaderMgmt_Enable_Discovery(
   2035                     psHciContext, pHwRef );
   2036                 if(NFCSTATUS_SUCCESS == status)
   2037                 {
   2038                     /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */
   2039                     psHciContext->hci_seq = HCI_END_SEQ;
   2040                     status = NFCSTATUS_PENDING;
   2041                 }
   2042                 break;
   2043             }
   2044             case HCI_END_SEQ:
   2045             {
   2046                 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
   2047                 if (NFCSTATUS_PENDING != status)
   2048                 {
   2049                     /* status = phHciNfc_FSM_Complete ( psHciContext );*/
   2050                     phHciNfc_FSM_Rollback ( psHciContext );
   2051                     if( hciState_Disconnect == psHciContext->hci_state.cur_state)
   2052                     {
   2053                         psHciContext->host_rf_type = phHal_eUnknown_DevType;
   2054                         psHciContext->p_target_info = NULL;
   2055                         psHciContext->p_xchg_info = NULL;
   2056                     }
   2057                     /* Poll Configuration Notification to the Upper Layer */
   2058                     if((~(PL_RD_PHASES_DISABLE) &
   2059                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   2060                     {
   2061                         comp_info.status = status;
   2062                         phHciNfc_Notify(psHciContext->p_upper_notify,
   2063                             psHciContext->p_upper_context, pHwRef,
   2064                             NFC_NOTIFY_POLL_ENABLED, &comp_info);
   2065                     }
   2066                     else
   2067                     {
   2068                         comp_info.status = status;
   2069                         phHciNfc_Notify(psHciContext->p_upper_notify,
   2070                             psHciContext->p_upper_context, pHwRef,
   2071                             NFC_NOTIFY_POLL_DISABLED, &comp_info);
   2072                     }
   2073                     HCI_PRINT("HCI Discovery Configuration Completed \n");
   2074                 }
   2075                 break;
   2076             }
   2077             default:
   2078             {
   2079                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   2080                 break;
   2081             }
   2082         }/* End of the Poll Sequence Switch */
   2083     }/* End of the Poll Config info Check */
   2084 
   2085     return status;
   2086 }
   2087 
   2088 
   2089 NFCSTATUS
   2090 phHciNfc_Connect_Sequence(
   2091                             phHciNfc_sContext_t     *psHciContext,
   2092                             void                    *pHwRef
   2093                          )
   2094 {
   2095     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2096     static phNfc_sCompletionInfo_t      comp_info = {FALSE,0,NULL};
   2097     phHal_eRemDevType_t         target_type = phHal_eUnknown_DevType;
   2098 
   2099     if( NULL != psHciContext->p_target_info )
   2100     {
   2101 
   2102         target_type = psHciContext->p_target_info->RemDevType;
   2103         switch(psHciContext->hci_seq)
   2104         {
   2105             case READER_REACTIVATE_SEQ:
   2106             {
   2107                 /* Complete the Reactivate Sequence and notify the HAL */
   2108                 status = phHciNfc_FSM_Complete ( psHciContext );
   2109                 /* Reactivate Complete Notification to the Upper Layer */
   2110                 if(NFCSTATUS_SUCCESS == status)
   2111                 {
   2112                     comp_info.status = status;
   2113                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2114                                     psHciContext->p_upper_context, pHwRef,
   2115                                     NFC_NOTIFY_TARGET_REACTIVATED , &comp_info);
   2116                     HCI_PRINT(" HCI Remote Target Reactivated. \n");
   2117                 }
   2118                 else
   2119                 {
   2120                     comp_info.status = status;
   2121                     phHciNfc_FSM_Rollback ( psHciContext );
   2122                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2123                         psHciContext->p_upper_context, pHwRef,
   2124                         NFC_NOTIFY_ERROR , &comp_info);
   2125                     HCI_PRINT("HCI FSM Invalid Selection State \n");
   2126                     HCI_PRINT("HCI Remote Target Reactivation Failed \n");
   2127                 }
   2128                 break;
   2129             }
   2130             case READER_SELECT_SEQ:
   2131             {
   2132                 /* If the Target is Mifare then it should fall through */
   2133                 if(( phHal_eMifare_PICC != target_type )
   2134                     &&(phHal_eISO14443_3A_PICC != target_type)
   2135 #ifdef TYPE_B
   2136                     &&  ( phHal_eISO14443_B_PICC != target_type )
   2137                     &&  ( phHal_eISO14443_4B_PICC != target_type )
   2138 #endif
   2139 #ifdef TYPE_FELICA
   2140                     &&  ( phHal_eFelica_PICC != target_type )
   2141 #endif
   2142 #ifdef TYPE_JEWEL
   2143                     &&  ( phHal_eJewel_PICC != target_type )
   2144 #endif /* #ifdef TYPE_JEWEL */
   2145 #ifdef TYPE_ISO15693
   2146                     &&  ( phHal_eISO15693_PICC != target_type )
   2147 #endif /* #ifdef TYPE_ISO15693 */
   2148 
   2149                     )
   2150                 {
   2151                     status = phHciNfc_ReaderMgmt_Info_Sequence( psHciContext, pHwRef );
   2152                     if(NFCSTATUS_SUCCESS == status)
   2153                     {
   2154                         psHciContext->hci_seq = HCI_END_SEQ;
   2155                         status = NFCSTATUS_PENDING;
   2156                     }
   2157                     break;
   2158                 }
   2159             }
   2160             /* fall through */
   2161             case HCI_END_SEQ:
   2162             {
   2163                 /* Complete the Connect Sequence and notify the HAL */
   2164                 status = phHciNfc_FSM_Complete ( psHciContext );
   2165                 /* Connection Complete Notification to the Upper Layer */
   2166                 if(NFCSTATUS_SUCCESS == status)
   2167                 {
   2168                     /* Invalidate the previously polled RF Reader Type */
   2169                     /* psHciContext->host_rf_type = phHal_eInvalidRFType;*/
   2170                     comp_info.status = status;
   2171                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2172                                     psHciContext->p_upper_context, pHwRef,
   2173                                     NFC_NOTIFY_TARGET_CONNECTED , &comp_info);
   2174                     HCI_PRINT(" HCI Remote Target Selected for Transaction. \n");
   2175                 }
   2176                 else
   2177                 {
   2178                     comp_info.status = status;
   2179                     /* phHciNfc_FSM_Rollback ( psHciContext ); */
   2180                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2181                         psHciContext->p_upper_context, pHwRef,
   2182                         NFC_NOTIFY_ERROR , &comp_info);
   2183                     HCI_PRINT("HCI FSM Invalid Selection State \n");
   2184                     HCI_PRINT("HCI Remote Target Selection Failed \n");
   2185                 }
   2186                 break;
   2187             }
   2188             default:
   2189             {
   2190                 HCI_PRINT("\t Invalid HCI Connect Sequence \n");
   2191                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   2192                 break;
   2193             }
   2194         }/* End of the Connect Sequence Switch */
   2195     }
   2196 
   2197     return status;
   2198 }
   2199 
   2200 
   2201 NFCSTATUS
   2202 phHciNfc_Disconnect_Sequence(
   2203                             phHciNfc_sContext_t     *psHciContext,
   2204                             void                    *pHwRef
   2205                          )
   2206 {
   2207     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2208     static phNfc_sCompletionInfo_t      comp_info = {FALSE, 0 , NULL};
   2209     phHal_eRemDevType_t         target_type = phHal_eUnknown_DevType;
   2210     uint8_t             re_poll = 0;
   2211 
   2212     if( NULL != psHciContext->p_target_info )
   2213     {
   2214 
   2215         target_type = psHciContext->p_target_info->RemDevType;
   2216         switch(psHciContext->hci_seq)
   2217         {
   2218             case READER_UICC_DISPATCH_SEQ:
   2219             {
   2220                 status = phHciNfc_ReaderMgmt_UICC_Dispatch(
   2221                                 psHciContext, pHwRef, target_type );
   2222                 psHciContext->hci_seq = READER_DESELECT_SEQ;
   2223                 if(NFCSTATUS_PENDING == status)
   2224                 {
   2225                     break;
   2226                 }
   2227             }
   2228             /* fall through */
   2229             case READER_DESELECT_SEQ:
   2230             {
   2231                 re_poll = (uint8_t) ( NULL != psHciContext->p_config_params )?
   2232                                 *((uint8_t *)psHciContext->p_config_params):FALSE;
   2233                 status = phHciNfc_ReaderMgmt_Deselect(
   2234                                 psHciContext, pHwRef, target_type, re_poll);
   2235                 if(NFCSTATUS_PENDING == status)
   2236                 {
   2237                     psHciContext->hci_seq = HCI_END_SEQ;
   2238                     psHciContext->p_config_params = NULL;
   2239                 }
   2240                 break;
   2241             }
   2242             case HCI_END_SEQ:
   2243             {
   2244                 /* Complete the Disconnect Sequence and notify the HAL */
   2245                 status = phHciNfc_FSM_Complete ( psHciContext );
   2246                 /* Disconnect Notification to the Upper Layer */
   2247                 if(NFCSTATUS_SUCCESS == status)
   2248                 {
   2249                     /* Invalidate the previously polled RF Reader Type */
   2250                     psHciContext->host_rf_type = phHal_eUnknown_DevType;
   2251                     psHciContext->p_target_info = NULL;
   2252                     psHciContext->p_xchg_info = NULL;
   2253                     comp_info.status = status;
   2254                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2255                                     psHciContext->p_upper_context, pHwRef,
   2256                                     NFC_NOTIFY_TARGET_DISCONNECTED , &comp_info);
   2257                     HCI_PRINT(" HCI Remote Target De-Selected. \n");
   2258                 }
   2259                 else
   2260                 {
   2261                     comp_info.status = status;
   2262                     /* phHciNfc_FSM_Rollback ( psHciContext ); */
   2263                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2264                         psHciContext->p_upper_context, pHwRef,
   2265                         NFC_NOTIFY_ERROR , &comp_info);
   2266                     HCI_PRINT("HCI FSM Invalid De-Selection State \n");
   2267                     HCI_PRINT("HCI Remote Target De-Selection Failed \n");
   2268                 }
   2269 
   2270                 break;
   2271             }
   2272             default:
   2273             {
   2274                 HCI_PRINT("\t Invalid HCI Connect Sequence \n");
   2275                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   2276                 break;
   2277             }
   2278         }/* End of the Connect Sequence Switch */
   2279     }
   2280 
   2281     return status;
   2282 }
   2283 
   2284 
   2285 static
   2286 NFCSTATUS
   2287 phHciNfc_Transact_Sequence(
   2288                             phHciNfc_sContext_t     *psHciContext,
   2289                             void                    *pHwRef
   2290                          )
   2291 {
   2292     static phNfc_sTransactionInfo_t transact_info = {FALSE,0,NULL,NULL,0};
   2293 
   2294     pphNfcIF_Notification_CB_t  p_upper_notify = psHciContext->p_upper_notify;
   2295     void                        *pcontext = psHciContext->p_upper_context;
   2296     uint8_t                     transact_result = NFC_NOTIFY_ERROR;
   2297 
   2298     /* Roll Back to Connect State as Transceive is Complete */
   2299     phHciNfc_FSM_Rollback(psHciContext);
   2300 
   2301     switch (psHciContext->host_rf_type)
   2302     {
   2303         case phHal_eISO14443_A_PCD:
   2304 #ifdef TYPE_B
   2305         case phHal_eISO14443_B_PCD:
   2306 #endif
   2307         case phHal_eISO14443_BPrime_PCD:
   2308 #ifdef TYPE_FELICA
   2309         case phHal_eFelica_PCD:
   2310 #endif
   2311 #ifdef TYPE_ISO15693
   2312         case phHal_eISO15693_PCD:
   2313 #endif
   2314         {
   2315             if(ZERO != psHciContext->rx_index)
   2316             {
   2317                 transact_info.status = NFCSTATUS_SUCCESS;
   2318                 transact_info.buffer =
   2319                                 &psHciContext->recv_buffer[psHciContext->rx_index];
   2320                 transact_info.length =
   2321                                 psHciContext->rx_total - psHciContext->rx_index;
   2322                 transact_result = NFC_NOTIFY_TRANSCEIVE_COMPLETED;
   2323             }
   2324             else
   2325             {
   2326                 transact_info.status = NFCSTATUS_FAILED;
   2327                 transact_result = NFC_NOTIFY_TRANSCEIVE_ERROR;
   2328             }
   2329             HCI_PRINT(" HCI Transceive operation Completed. \n");
   2330             psHciContext->p_xchg_info = NULL ;
   2331             break;
   2332         }
   2333 #ifdef TYPE_JEWEL
   2334         /* fall through */
   2335         case phHal_eJewel_PCD:
   2336 #endif
   2337         {
   2338             transact_info.status = NFCSTATUS_SUCCESS;
   2339             transact_info.buffer =
   2340                             &psHciContext->recv_buffer[psHciContext->rx_index];
   2341             transact_info.length =
   2342                             psHciContext->rx_total - psHciContext->rx_index;
   2343             transact_result = NFC_NOTIFY_TRANSCEIVE_COMPLETED;
   2344             HCI_PRINT(" HCI Transceive operation Completed. \n");
   2345             psHciContext->p_xchg_info = NULL ;
   2346             break;
   2347         }
   2348 #if defined(ENABLE_P2P)
   2349         case phHal_eNfcIP1_Initiator:
   2350         case phHal_eNfcIP1_Target:
   2351 #endif
   2352         {
   2353             HCI_PRINT(" HCI Send operation Completed. \n");
   2354             transact_info.status = NFCSTATUS_SUCCESS;
   2355             transact_result = NFC_NOTIFY_SEND_COMPLETED;
   2356             break;
   2357         }
   2358         case phHal_eUnknown_DevType:
   2359         default:
   2360         {
   2361             transact_info.status  =
   2362                         PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   2363             break;
   2364         }
   2365 
   2366     }
   2367     /* Notify the Transceive Completion to the Upper layer */
   2368     phHciNfc_Notify( p_upper_notify, pcontext , pHwRef,
   2369                     transact_result, &transact_info);
   2370 
   2371     return (NFCSTATUS)NFCSTATUS_SUCCESS;
   2372 }
   2373 
   2374 static
   2375 NFCSTATUS
   2376 phHciNfc_Info_Sequence(
   2377                             phHciNfc_sContext_t     *psHciContext,
   2378                             void                    *pHwRef
   2379                          )
   2380 {
   2381     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2382 
   2383     HCI_DEBUG(" HCI: Info Sequence Entry --> Reader Type : %02X \n",
   2384                                             psHciContext->host_rf_type);
   2385     switch (psHciContext->host_rf_type)
   2386     {
   2387         case phHal_eISO14443_A_PCD:
   2388 #ifdef TYPE_B
   2389         case phHal_eISO14443_B_PCD:
   2390 #endif
   2391         case phHal_eISO14443_BPrime_PCD:
   2392 #ifdef TYPE_FELICA
   2393         case phHal_eFelica_PCD:
   2394 #endif
   2395 #ifdef TYPE_JEWEL
   2396         case phHal_eJewel_PCD:
   2397 #endif
   2398 #ifdef TYPE_ISO15693
   2399         case phHal_eISO15693_PCD:
   2400 #endif
   2401         {
   2402             /* To update the select sequence to retrieve
   2403             * the target information using the reader type.
   2404             */
   2405             status = phHciNfc_ReaderMgmt_Info_Sequence( psHciContext, pHwRef );
   2406             break;
   2407         }
   2408 #if defined(ENABLE_P2P)
   2409         case phHal_eNfcIP1_Initiator:
   2410         case phHal_eNfcIP1_Target:
   2411         {
   2412             status = phHciNfc_NfcIP_Info_Sequence( psHciContext, pHwRef );
   2413             break;
   2414         }
   2415 #endif
   2416         case phHal_eUnknown_DevType:
   2417         default:
   2418         {
   2419             status  =
   2420                     PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   2421             break;
   2422         }
   2423 
   2424     }
   2425     return status;
   2426 }
   2427 
   2428 static
   2429 NFCSTATUS
   2430 phHciNfc_Test_Sequence(
   2431                             phHciNfc_sContext_t     *psHciContext,
   2432                             void                    *pHwRef,
   2433                             NFCSTATUS               test_status,
   2434                             uint8_t                 *pdata,
   2435                             uint8_t                 length
   2436                          )
   2437 {
   2438     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2439     static phNfc_sCompletionInfo_t      comp_info = {0};
   2440     static phNfc_sData_t test_result= {NULL,0};
   2441 
   2442     /* Complete the Test Sequence and notify the HAL */
   2443     status = phHciNfc_FSM_Complete ( psHciContext );
   2444     /* Test Results to the Upper Layer */
   2445     if(NFCSTATUS_SUCCESS == status)
   2446     {
   2447         comp_info.status = test_status;
   2448         if ( (NULL != pdata) && (length >= HCP_HEADER_LEN) )
   2449         {
   2450             test_result.buffer = ( pdata + HCP_HEADER_LEN);
   2451             test_result.length = length - HCP_HEADER_LEN;
   2452         }
   2453         else
   2454         {
   2455             status = phHciNfc_DevMgmt_Get_Test_Result(
   2456                                         psHciContext, &test_result );
   2457         }
   2458         comp_info.info = &test_result;
   2459         phHciNfc_Notify(psHciContext->p_upper_notify,
   2460                         psHciContext->p_upper_context, pHwRef,
   2461                         NFC_NOTIFY_RESULT , &comp_info);
   2462         HCI_DEBUG(" HCI System Test Completed : Status = %u\n", test_status);
   2463     }
   2464     else
   2465     {
   2466         comp_info.status = status;
   2467         phHciNfc_FSM_Rollback ( psHciContext );
   2468         phHciNfc_Notify(psHciContext->p_upper_notify,
   2469             psHciContext->p_upper_context, pHwRef,
   2470             NFC_NOTIFY_ERROR , &comp_info);
   2471         HCI_PRINT("HCI FSM Invalid Test State \n");
   2472     }
   2473 
   2474     return status;
   2475 }
   2476 
   2477 static
   2478 NFCSTATUS
   2479 phHciNfc_IO_Sequence(
   2480                             phHciNfc_sContext_t     *psHciContext,
   2481                             void                    *pHwRef,
   2482                             NFCSTATUS               io_status,
   2483                             uint8_t                 *pdata,
   2484                             uint8_t                 length
   2485                          )
   2486 {
   2487     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2488     static phNfc_sCompletionInfo_t      comp_info = {0};
   2489 
   2490     /* To remove "warning (VS 4100) : unreferenced formal parameter" */
   2491     PHNFC_UNUSED_VARIABLE(pdata);
   2492     PHNFC_UNUSED_VARIABLE(length);
   2493     /* Complete the Test Sequence and notify the HAL */
   2494     phHciNfc_FSM_Rollback ( psHciContext );
   2495     /* Test Results to the Upper Layer */
   2496     comp_info.status = io_status;
   2497     status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
   2498     if(NFCSTATUS_SUCCESS == io_status)
   2499     {
   2500         phHciNfc_Notify(psHciContext->p_upper_notify,
   2501                         psHciContext->p_upper_context, pHwRef,
   2502                         NFC_IO_SUCCESS , &comp_info);
   2503         HCI_PRINT(" HCI System IO Successful. \n");
   2504     }
   2505     else
   2506     {
   2507         phHciNfc_Notify(psHciContext->p_upper_notify,
   2508             psHciContext->p_upper_context, pHwRef,
   2509             NFC_IO_ERROR , &comp_info);
   2510         HCI_PRINT("HCI IO Error \n");
   2511     }
   2512     return status;
   2513 }
   2514 
   2515 
   2516 
   2517 #ifdef OTHER_TAGS
   2518 
   2519 NFCSTATUS
   2520 phHciNfc_Activate_Sequence(
   2521                             phHciNfc_sContext_t     *psHciContext,
   2522                             void                    *pHwRef
   2523                          )
   2524 {
   2525     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2526 
   2527     return status;
   2528 }
   2529 
   2530 
   2531 #endif
   2532 
   2533 
   2534