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         switch(psHciContext->hci_seq)
   1640         {
   1641             case PL_DURATION_SEQ:
   1642             {
   1643                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   1644                     (uint8_t)PL_DURATION , NULL);
   1645                 if(NFCSTATUS_SUCCESS == status)
   1646                 {
   1647 #if defined (ENABLE_P2P) && defined (TARGET_SPEED)
   1648                     psHciContext->hci_seq = TARGET_SPEED_SEQ;
   1649 #elif defined (ENABLE_P2P) && defined (INITIATOR_SPEED)
   1650                     psHciContext->hci_seq = INITIATOR_SPEED_SEQ;
   1651 #elif defined (ENABLE_P2P) &&  defined (NFCIP_TGT_DISABLE_CFG)
   1652                     psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1653 #else
   1654                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1655 #endif
   1656 
   1657                     status = NFCSTATUS_PENDING;
   1658                 }
   1659                 break;
   1660             }
   1661 #if defined (ENABLE_P2P) && defined (TARGET_SPEED)
   1662             case TARGET_SPEED_SEQ:
   1663             {
   1664 #define NFCIP_ACTIVE_SHIFT	0x03U
   1665 #define NFCIP_PASSIVE_MASK	0x07U
   1666                 uint8_t mode = ( NXP_NFCIP_ACTIVE_DEFAULT << NFCIP_ACTIVE_SHIFT ) |
   1667 									( DEFAULT_NFCIP_TARGET_MODE_SUPPORT & NFCIP_PASSIVE_MASK );
   1668                 status =
   1669                     phHciNfc_NfcIP_SetMode( psHciContext, pHwRef, NFCIP_TARGET,
   1670                      (uint8_t) mode );
   1671                 if(NFCSTATUS_PENDING == status)
   1672                 {
   1673 #if defined (INITIATOR_SPEED)
   1674                     psHciContext->hci_seq = INITIATOR_SPEED_SEQ;
   1675 #elif defined (NFCIP_TGT_DISABLE_CFG)
   1676                     psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1677 #else
   1678                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1679 #endif
   1680                     status = NFCSTATUS_PENDING;
   1681                 }
   1682                 break;
   1683             }
   1684 #endif
   1685 #if defined (ENABLE_P2P) && defined (INITIATOR_SPEED)
   1686             case INITIATOR_SPEED_SEQ:
   1687             {
   1688                 status =
   1689                     phHciNfc_NfcIP_SetMode( psHciContext, pHwRef, NFCIP_INITIATOR,
   1690                      (uint8_t) (speed & DEFAULT_NFCIP_INITIATOR_MODE_SUPPORT));
   1691                 if(NFCSTATUS_PENDING == status)
   1692                 {
   1693 #if defined (NFCIP_TGT_DISABLE_CFG)
   1694                     psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1695 #else
   1696                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1697 #endif
   1698                     status = NFCSTATUS_PENDING;
   1699                 }
   1700                 break;
   1701             }
   1702 #endif
   1703 #if defined (ENABLE_P2P) && defined (NFCIP_TGT_DISABLE_CFG)
   1704             case PL_TGT_DISABLE_SEQ:
   1705             {
   1706                 /* Configure the Polling Loop Target Disable Parameter */
   1707                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   1708                 (uint8_t)PL_DISABLE_TARGET, &p_poll_config->NfcIP_Tgt_Disable );
   1709                 if(NFCSTATUS_SUCCESS == status)
   1710                 {
   1711                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1712                     status = NFCSTATUS_PENDING;
   1713                 }
   1714                 break;
   1715             }
   1716 #endif
   1717             case PL_CONFIG_PHASE_SEQ:
   1718             {
   1719                 phHal_sPollDevInfo_t *p_poll_info =
   1720                                 &(p_poll_config->PollDevInfo.PollCfgInfo);
   1721 
   1722                 p_poll_info->EnableIso14443A =
   1723                     ( (p_poll_info->EnableIso14443A)
   1724                                     || ( speed & (uint8_t)phHal_ePassive106 )
   1725                                     );
   1726                 p_poll_info->EnableFelica212 =
   1727                             ( (p_poll_info->EnableFelica212)
   1728                                     || ( speed & (uint8_t)phHal_ePassive212 )
   1729                                     );
   1730                 p_poll_info->EnableFelica424 =
   1731                             ( (p_poll_info->EnableFelica424)
   1732                                     || ( speed & (uint8_t)phHal_ePassive424 )
   1733                                     );
   1734                 /* Configure the Polling Loop Gate Parameters */
   1735                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   1736                     (uint8_t)PL_RD_PHASES, NULL );
   1737                 if(NFCSTATUS_SUCCESS == status)
   1738                 {
   1739                     if(((~(PL_RD_PHASES_DISABLE)) &
   1740                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   1741                     {
   1742                         psHciContext->hci_seq = READER_ENABLE_SEQ;
   1743                     }
   1744                     else
   1745                     {
   1746                         /* psHciContext->hci_seq = READER_DISABLE_SEQ; */
   1747                         psHciContext->hci_seq = HCI_END_SEQ;
   1748                     }
   1749                     status = NFCSTATUS_PENDING;
   1750                 }
   1751                 break;
   1752             }
   1753             case READER_ENABLE_SEQ:
   1754             {
   1755                 status =
   1756                     phHciNfc_ReaderMgmt_Enable_Discovery(
   1757                     psHciContext, pHwRef );
   1758                 if(NFCSTATUS_SUCCESS == status)
   1759                 {
   1760                     /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */
   1761                     psHciContext->hci_seq = HCI_END_SEQ;
   1762                     status = NFCSTATUS_PENDING;
   1763                 }
   1764                 break;
   1765             }
   1766             case READER_DISABLE_SEQ:
   1767             {
   1768                 status = phHciNfc_ReaderMgmt_Disable_Discovery(
   1769                     psHciContext, pHwRef );
   1770 
   1771                 if(NFCSTATUS_SUCCESS == status)
   1772                 {
   1773                     if((~(PL_RD_PHASES_DISABLE) &
   1774                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   1775                     {
   1776                         psHciContext->hci_seq = PL_DURATION_SEQ;
   1777                     }
   1778                     else
   1779                     {
   1780 #if defined (ENABLE_P2P) && defined (INITIATOR_SPEED)
   1781                         psHciContext->hci_seq = INITIATOR_SPEED_SEQ;
   1782 #elif defined (ENABLE_P2P) &&  defined (NFCIP_TGT_DISABLE_CFG)
   1783                         psHciContext->hci_seq = PL_TGT_DISABLE_SEQ;
   1784 #else
   1785                         psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   1786 #endif
   1787                         /* psHciContext->hci_seq = HCI_END_SEQ; */
   1788                     }
   1789                     status = NFCSTATUS_PENDING;
   1790                 }
   1791                 break;
   1792             }
   1793             case HCI_END_SEQ:
   1794             {
   1795                 phNfc_sCompletionInfo_t     comp_info;
   1796                 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
   1797                 if (NFCSTATUS_PENDING != status)
   1798                 {
   1799                     /* status = phHciNfc_FSM_Complete ( psHciContext );*/
   1800                     phHciNfc_FSM_Rollback ( psHciContext );
   1801                     /* Poll Configuration Notification to the Upper Layer */
   1802                     if((~(PL_RD_PHASES_DISABLE) &
   1803                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   1804                     {
   1805                         comp_info.status = status;
   1806                         phHciNfc_Notify(psHciContext->p_upper_notify,
   1807                             psHciContext->p_upper_context, pHwRef,
   1808                             NFC_NOTIFY_POLL_ENABLED, &comp_info);
   1809                     }
   1810                     else
   1811                     {
   1812                         comp_info.status = status;
   1813                         phHciNfc_Notify(psHciContext->p_upper_notify,
   1814                             psHciContext->p_upper_context, pHwRef,
   1815                             NFC_NOTIFY_POLL_DISABLED, &comp_info);
   1816                     }
   1817                     HCI_PRINT("HCI Discovery Configuration Completed \n");
   1818                 }
   1819                 break;
   1820             }
   1821             default:
   1822             {
   1823                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   1824                 break;
   1825             }
   1826         }/* End of the Poll Sequence Switch */
   1827     }/* End of the Poll Config info Check */
   1828 
   1829     return status;
   1830 }
   1831 
   1832 
   1833 NFCSTATUS
   1834 phHciNfc_EmulationCfg_Sequence(
   1835                             phHciNfc_sContext_t     *psHciContext,
   1836                             void                    *pHwRef
   1837                          )
   1838 {
   1839     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   1840     static phNfc_sCompletionInfo_t      comp_info = {FALSE,0,NULL};
   1841 #if defined(HOST_EMULATION)
   1842     phHciNfc_GateID_t       ce_gate = phHciNfc_UnknownGate;
   1843 #endif  /* #ifdef HOST_EMULATION */
   1844     phHal_sEmulationCfg_t   *p_emulation_cfg = (phHal_sEmulationCfg_t * )
   1845                                         psHciContext->p_config_params;
   1846 #ifdef UICC_SESSION_RESET
   1847     uint8_t                 uicc_clear_pipes = FALSE;
   1848 #endif
   1849 
   1850 
   1851     if (NULL != p_emulation_cfg)
   1852     {
   1853 #if defined(HOST_EMULATION)
   1854         if(NFC_HOST_CE_A_EMULATION == p_emulation_cfg->emuType)
   1855         {
   1856             psHciContext->config_type = NFC_CE_A_CFG;
   1857             if (NULL == psHciContext->p_ce_a_info)
   1858             {
   1859                 ce_gate = phHciNfc_CETypeAGate;
   1860             }
   1861         }
   1862         else if (NFC_HOST_CE_B_EMULATION == p_emulation_cfg->emuType)
   1863         {
   1864             psHciContext->config_type = NFC_CE_B_CFG;
   1865             if (NULL == psHciContext->p_ce_b_info)
   1866             {
   1867                 ce_gate = phHciNfc_CETypeBGate;
   1868             }
   1869         }
   1870 #ifdef UICC_SESSION_RESET
   1871         else if ((NFC_UICC_EMULATION == p_emulation_cfg->emuType)
   1872             &&(FALSE == p_emulation_cfg->config.uiccEmuCfg.enableUicc)
   1873             )
   1874         {
   1875             uicc_clear_pipes = TRUE;
   1876         }
   1877 #endif
   1878         else
   1879         {
   1880             ;
   1881         }
   1882 #endif  /* #ifdef HOST_EMULATION */
   1883 
   1884         switch(psHciContext->hci_seq)
   1885         {
   1886 #if defined(HOST_EMULATION)
   1887             case ADMIN_CE_SEQ:
   1888             {
   1889                 if(phHciNfc_UnknownGate != ce_gate)
   1890                 {
   1891                     status = phHciNfc_Admin_CE_Init(psHciContext, pHwRef, ce_gate);
   1892                 }
   1893                 else
   1894                 {
   1895                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_NOT_ALLOWED);
   1896                 }
   1897 
   1898                 if(NFCSTATUS_SUCCESS == status)
   1899                 {
   1900                     psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
   1901                     /* psHciContext->hci_seq = HCI_END_SEQ; */
   1902                     status = NFCSTATUS_PENDING;
   1903                 }
   1904                 break;
   1905             }
   1906 #endif
   1907             case EMULATION_CONFIG_SEQ:
   1908             {
   1909                 status = phHciNfc_Emulation_Cfg(psHciContext, pHwRef,
   1910                                                 psHciContext->config_type);
   1911                 if(NFCSTATUS_SUCCESS == status)
   1912                 {
   1913                     /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */
   1914 #ifdef UICC_SESSION_RESET
   1915                     if(UICC_SWP_CFG == psHciContext->config_type)
   1916                     {
   1917                         psHciContext->hci_seq = ADMIN_REL_SEQ;
   1918                     }
   1919                     else
   1920 #endif /* UICC_SESSION_RESET */
   1921                     {
   1922                         psHciContext->hci_seq = HCI_END_SEQ;
   1923                     }
   1924                     status = NFCSTATUS_PENDING;
   1925                 }
   1926                 break;
   1927             }
   1928 #ifdef UICC_SESSION_RESET
   1929             case ADMIN_REL_SEQ:
   1930             {
   1931                 if (TRUE == uicc_clear_pipes)
   1932                 {
   1933                     /*  Admin Management UICC Release Sequence */
   1934                     status = phHciNfc_Admin_Release( psHciContext,pHwRef, phHciNfc_UICCHostID );
   1935                     if(NFCSTATUS_SUCCESS == status)
   1936                     {
   1937                         psHciContext->hci_seq = HCI_END_SEQ;
   1938                         if (UICC_SWP_CFG == psHciContext->config_type)
   1939                         {
   1940                             (void)phHciNfc_SWP_Update_Sequence(psHciContext,
   1941                                                                         CONFIG_SEQ );
   1942                         }
   1943                         status = NFCSTATUS_PENDING;
   1944                     }
   1945                     break;
   1946                 }
   1947             }
   1948 #endif /* UICC_SESSION_RESET */
   1949             /* fall through */
   1950             case HCI_END_SEQ:
   1951             {
   1952                 phHciNfc_FSM_Rollback(psHciContext);
   1953 
   1954                 HCI_PRINT(" Emulation Configuration Completed. \n");
   1955 
   1956                 comp_info.status = status;
   1957                 phHciNfc_Notify(psHciContext->p_upper_notify,
   1958                                  psHciContext->p_upper_context, pHwRef,
   1959                                    NFC_NOTIFY_CONFIG_SUCCESS, &comp_info);
   1960                 break;
   1961             }
   1962             default:
   1963             {
   1964                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   1965                 break;
   1966             }
   1967         }
   1968         /*
   1969             NFC_CE_A_CFG;
   1970             NFC_CE_B_CFG; */
   1971 
   1972     }/* End of the Emulation Config info Check */
   1973 
   1974     return status;
   1975 }
   1976 
   1977 
   1978 NFCSTATUS
   1979 phHciNfc_SmartMx_Mode_Sequence(
   1980                            phHciNfc_sContext_t      *psHciContext,
   1981                            void                     *pHwRef
   1982                           )
   1983 {
   1984     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   1985     phHal_sADD_Cfg_t    *p_poll_config = (phHal_sADD_Cfg_t * )
   1986         psHciContext->p_config_params;
   1987     phNfc_sCompletionInfo_t     comp_info = {FALSE,0,NULL};
   1988     if (NULL != p_poll_config)
   1989     {
   1990         switch(psHciContext->hci_seq)
   1991         {
   1992             case READER_DISABLE_SEQ:
   1993             {
   1994                 status = phHciNfc_ReaderMgmt_Disable_Discovery(
   1995                     psHciContext, pHwRef );
   1996                 if(NFCSTATUS_SUCCESS == status)
   1997                 {
   1998                     psHciContext->hci_seq = EMULATION_CONFIG_SEQ;
   1999                     /* psHciContext->hci_seq = HCI_END_SEQ; */
   2000                     status = NFCSTATUS_PENDING;
   2001                 }
   2002                 break;
   2003             }
   2004             case EMULATION_CONFIG_SEQ:
   2005             {
   2006                 status = phHciNfc_WI_Configure_Mode(
   2007                     psHciContext, pHwRef,psHciContext->smx_mode );
   2008                 if(NFCSTATUS_SUCCESS == status)
   2009                 {
   2010                     psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ;
   2011                     /* psHciContext->hci_seq = HCI_END_SEQ; */
   2012                     status = NFCSTATUS_PENDING;
   2013                 }
   2014                 break;
   2015             }
   2016             case PL_CONFIG_PHASE_SEQ:
   2017             {
   2018                 /* Configure the Polling Loop Gate Parameters */
   2019                 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef,
   2020                     (uint8_t)PL_RD_PHASES, NULL );
   2021                 if(NFCSTATUS_SUCCESS == status)
   2022                 {
   2023                     psHciContext->hci_seq = READER_ENABLE_SEQ;
   2024                     status = NFCSTATUS_PENDING;
   2025                 }
   2026                 break;
   2027             }
   2028             case READER_ENABLE_SEQ:
   2029             {
   2030                 status =
   2031                     phHciNfc_ReaderMgmt_Enable_Discovery(
   2032                     psHciContext, pHwRef );
   2033                 if(NFCSTATUS_SUCCESS == status)
   2034                 {
   2035                     /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */
   2036                     psHciContext->hci_seq = HCI_END_SEQ;
   2037                     status = NFCSTATUS_PENDING;
   2038                 }
   2039                 break;
   2040             }
   2041             case HCI_END_SEQ:
   2042             {
   2043                 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
   2044                 if (NFCSTATUS_PENDING != status)
   2045                 {
   2046                     /* status = phHciNfc_FSM_Complete ( psHciContext );*/
   2047                     phHciNfc_FSM_Rollback ( psHciContext );
   2048                     if( hciState_Disconnect == psHciContext->hci_state.cur_state)
   2049                     {
   2050                         psHciContext->host_rf_type = phHal_eUnknown_DevType;
   2051                         psHciContext->p_target_info = NULL;
   2052                         psHciContext->p_xchg_info = NULL;
   2053                     }
   2054                     /* Poll Configuration Notification to the Upper Layer */
   2055                     if((~(PL_RD_PHASES_DISABLE) &
   2056                             p_poll_config->PollDevInfo.PollEnabled)!= 0)
   2057                     {
   2058                         comp_info.status = status;
   2059                         phHciNfc_Notify(psHciContext->p_upper_notify,
   2060                             psHciContext->p_upper_context, pHwRef,
   2061                             NFC_NOTIFY_POLL_ENABLED, &comp_info);
   2062                     }
   2063                     else
   2064                     {
   2065                         comp_info.status = status;
   2066                         phHciNfc_Notify(psHciContext->p_upper_notify,
   2067                             psHciContext->p_upper_context, pHwRef,
   2068                             NFC_NOTIFY_POLL_DISABLED, &comp_info);
   2069                     }
   2070                     HCI_PRINT("HCI Discovery Configuration Completed \n");
   2071                 }
   2072                 break;
   2073             }
   2074             default:
   2075             {
   2076                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   2077                 break;
   2078             }
   2079         }/* End of the Poll Sequence Switch */
   2080     }/* End of the Poll Config info Check */
   2081 
   2082     return status;
   2083 }
   2084 
   2085 
   2086 NFCSTATUS
   2087 phHciNfc_Connect_Sequence(
   2088                             phHciNfc_sContext_t     *psHciContext,
   2089                             void                    *pHwRef
   2090                          )
   2091 {
   2092     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2093     static phNfc_sCompletionInfo_t      comp_info = {FALSE,0,NULL};
   2094     phHal_eRemDevType_t         target_type = phHal_eUnknown_DevType;
   2095 
   2096     if( NULL != psHciContext->p_target_info )
   2097     {
   2098 
   2099         target_type = psHciContext->p_target_info->RemDevType;
   2100         switch(psHciContext->hci_seq)
   2101         {
   2102             case READER_REACTIVATE_SEQ:
   2103             {
   2104                 /* Complete the Reactivate Sequence and notify the HAL */
   2105                 status = phHciNfc_FSM_Complete ( psHciContext );
   2106                 /* Reactivate Complete Notification to the Upper Layer */
   2107                 if(NFCSTATUS_SUCCESS == status)
   2108                 {
   2109                     comp_info.status = status;
   2110                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2111                                     psHciContext->p_upper_context, pHwRef,
   2112                                     NFC_NOTIFY_TARGET_REACTIVATED , &comp_info);
   2113                     HCI_PRINT(" HCI Remote Target Reactivated. \n");
   2114                 }
   2115                 else
   2116                 {
   2117                     comp_info.status = status;
   2118                     phHciNfc_FSM_Rollback ( psHciContext );
   2119                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2120                         psHciContext->p_upper_context, pHwRef,
   2121                         NFC_NOTIFY_ERROR , &comp_info);
   2122                     HCI_PRINT("HCI FSM Invalid Selection State \n");
   2123                     HCI_PRINT("HCI Remote Target Reactivation Failed \n");
   2124                 }
   2125                 break;
   2126             }
   2127             case READER_SELECT_SEQ:
   2128             {
   2129                 /* If the Target is Mifare then it should fall through */
   2130                 if(( phHal_eMifare_PICC != target_type )
   2131                     &&(phHal_eISO14443_3A_PICC != target_type)
   2132 #ifdef TYPE_B
   2133                     &&  ( phHal_eISO14443_B_PICC != target_type )
   2134                     &&  ( phHal_eISO14443_4B_PICC != target_type )
   2135 #endif
   2136 #ifdef TYPE_FELICA
   2137                     &&  ( phHal_eFelica_PICC != target_type )
   2138 #endif
   2139 #ifdef TYPE_JEWEL
   2140                     &&  ( phHal_eJewel_PICC != target_type )
   2141 #endif /* #ifdef TYPE_JEWEL */
   2142 #ifdef TYPE_ISO15693
   2143                     &&  ( phHal_eISO15693_PICC != target_type )
   2144 #endif /* #ifdef TYPE_ISO15693 */
   2145 
   2146                     )
   2147                 {
   2148                     status = phHciNfc_ReaderMgmt_Info_Sequence( psHciContext, pHwRef );
   2149                     if(NFCSTATUS_SUCCESS == status)
   2150                     {
   2151                         psHciContext->hci_seq = HCI_END_SEQ;
   2152                         status = NFCSTATUS_PENDING;
   2153                     }
   2154                     break;
   2155                 }
   2156             }
   2157             /* fall through */
   2158             case HCI_END_SEQ:
   2159             {
   2160                 /* Complete the Connect Sequence and notify the HAL */
   2161                 status = phHciNfc_FSM_Complete ( psHciContext );
   2162                 /* Connection Complete Notification to the Upper Layer */
   2163                 if(NFCSTATUS_SUCCESS == status)
   2164                 {
   2165                     /* Invalidate the previously polled RF Reader Type */
   2166                     /* psHciContext->host_rf_type = phHal_eInvalidRFType;*/
   2167                     comp_info.status = status;
   2168                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2169                                     psHciContext->p_upper_context, pHwRef,
   2170                                     NFC_NOTIFY_TARGET_CONNECTED , &comp_info);
   2171                     HCI_PRINT(" HCI Remote Target Selected for Transaction. \n");
   2172                 }
   2173                 else
   2174                 {
   2175                     comp_info.status = status;
   2176                     /* phHciNfc_FSM_Rollback ( psHciContext ); */
   2177                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2178                         psHciContext->p_upper_context, pHwRef,
   2179                         NFC_NOTIFY_ERROR , &comp_info);
   2180                     HCI_PRINT("HCI FSM Invalid Selection State \n");
   2181                     HCI_PRINT("HCI Remote Target Selection Failed \n");
   2182                 }
   2183                 break;
   2184             }
   2185             default:
   2186             {
   2187                 HCI_PRINT("\t Invalid HCI Connect Sequence \n");
   2188                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   2189                 break;
   2190             }
   2191         }/* End of the Connect Sequence Switch */
   2192     }
   2193 
   2194     return status;
   2195 }
   2196 
   2197 
   2198 NFCSTATUS
   2199 phHciNfc_Disconnect_Sequence(
   2200                             phHciNfc_sContext_t     *psHciContext,
   2201                             void                    *pHwRef
   2202                          )
   2203 {
   2204     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2205     static phNfc_sCompletionInfo_t      comp_info = {FALSE, 0 , NULL};
   2206     phHal_eRemDevType_t         target_type = phHal_eUnknown_DevType;
   2207     uint8_t             re_poll = 0;
   2208 
   2209     if( NULL != psHciContext->p_target_info )
   2210     {
   2211 
   2212         target_type = psHciContext->p_target_info->RemDevType;
   2213         switch(psHciContext->hci_seq)
   2214         {
   2215             case READER_UICC_DISPATCH_SEQ:
   2216             {
   2217                 status = phHciNfc_ReaderMgmt_UICC_Dispatch(
   2218                                 psHciContext, pHwRef, target_type );
   2219                 psHciContext->hci_seq = READER_DESELECT_SEQ;
   2220                 if(NFCSTATUS_PENDING == status)
   2221                 {
   2222                     break;
   2223                 }
   2224             }
   2225             /* fall through */
   2226             case READER_DESELECT_SEQ:
   2227             {
   2228                 re_poll = (uint8_t) ( NULL != psHciContext->p_config_params )?
   2229                                 *((uint8_t *)psHciContext->p_config_params):FALSE;
   2230                 status = phHciNfc_ReaderMgmt_Deselect(
   2231                                 psHciContext, pHwRef, target_type, re_poll);
   2232                 if(NFCSTATUS_PENDING == status)
   2233                 {
   2234                     psHciContext->hci_seq = HCI_END_SEQ;
   2235                     psHciContext->p_config_params = NULL;
   2236                 }
   2237                 break;
   2238             }
   2239             case HCI_END_SEQ:
   2240             {
   2241                 /* Complete the Disconnect Sequence and notify the HAL */
   2242                 status = phHciNfc_FSM_Complete ( psHciContext );
   2243                 /* Disconnect Notification to the Upper Layer */
   2244                 if(NFCSTATUS_SUCCESS == status)
   2245                 {
   2246                     /* Invalidate the previously polled RF Reader Type */
   2247                     psHciContext->host_rf_type = phHal_eUnknown_DevType;
   2248                     psHciContext->p_target_info = NULL;
   2249                     psHciContext->p_xchg_info = NULL;
   2250                     comp_info.status = status;
   2251                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2252                                     psHciContext->p_upper_context, pHwRef,
   2253                                     NFC_NOTIFY_TARGET_DISCONNECTED , &comp_info);
   2254                     HCI_PRINT(" HCI Remote Target De-Selected. \n");
   2255                 }
   2256                 else
   2257                 {
   2258                     comp_info.status = status;
   2259                     /* phHciNfc_FSM_Rollback ( psHciContext ); */
   2260                     phHciNfc_Notify(psHciContext->p_upper_notify,
   2261                         psHciContext->p_upper_context, pHwRef,
   2262                         NFC_NOTIFY_ERROR , &comp_info);
   2263                     HCI_PRINT("HCI FSM Invalid De-Selection State \n");
   2264                     HCI_PRINT("HCI Remote Target De-Selection Failed \n");
   2265                 }
   2266 
   2267                 break;
   2268             }
   2269             default:
   2270             {
   2271                 HCI_PRINT("\t Invalid HCI Connect Sequence \n");
   2272                 /* psHciContext->hci_seq = HCI_END_SEQ; */
   2273                 break;
   2274             }
   2275         }/* End of the Connect Sequence Switch */
   2276     }
   2277 
   2278     return status;
   2279 }
   2280 
   2281 
   2282 static
   2283 NFCSTATUS
   2284 phHciNfc_Transact_Sequence(
   2285                             phHciNfc_sContext_t     *psHciContext,
   2286                             void                    *pHwRef
   2287                          )
   2288 {
   2289     static phNfc_sTransactionInfo_t transact_info = {FALSE,0,NULL,NULL,0};
   2290 
   2291     pphNfcIF_Notification_CB_t  p_upper_notify = psHciContext->p_upper_notify;
   2292     void                        *pcontext = psHciContext->p_upper_context;
   2293     uint8_t                     transact_result = NFC_NOTIFY_ERROR;
   2294 
   2295     /* Roll Back to Connect State as Transceive is Complete */
   2296     phHciNfc_FSM_Rollback(psHciContext);
   2297 
   2298     switch (psHciContext->host_rf_type)
   2299     {
   2300         case phHal_eISO14443_A_PCD:
   2301 #ifdef TYPE_B
   2302         case phHal_eISO14443_B_PCD:
   2303 #endif
   2304         case phHal_eISO14443_BPrime_PCD:
   2305 #ifdef TYPE_FELICA
   2306         case phHal_eFelica_PCD:
   2307 #endif
   2308 #ifdef TYPE_ISO15693
   2309         case phHal_eISO15693_PCD:
   2310 #endif
   2311         {
   2312             if(ZERO != psHciContext->rx_index)
   2313             {
   2314                 transact_info.status = NFCSTATUS_SUCCESS;
   2315                 transact_info.buffer =
   2316                                 &psHciContext->recv_buffer[psHciContext->rx_index];
   2317                 transact_info.length =
   2318                                 psHciContext->rx_total - psHciContext->rx_index;
   2319                 transact_result = NFC_NOTIFY_TRANSCEIVE_COMPLETED;
   2320             }
   2321             else
   2322             {
   2323                 transact_info.status = NFCSTATUS_FAILED;
   2324                 transact_result = NFC_NOTIFY_TRANSCEIVE_ERROR;
   2325             }
   2326             HCI_PRINT(" HCI Transceive operation Completed. \n");
   2327             psHciContext->p_xchg_info = NULL ;
   2328             break;
   2329         }
   2330 #ifdef TYPE_JEWEL
   2331         /* fall through */
   2332         case phHal_eJewel_PCD:
   2333 #endif
   2334         {
   2335             transact_info.status = NFCSTATUS_SUCCESS;
   2336             transact_info.buffer =
   2337                             &psHciContext->recv_buffer[psHciContext->rx_index];
   2338             transact_info.length =
   2339                             psHciContext->rx_total - psHciContext->rx_index;
   2340             transact_result = NFC_NOTIFY_TRANSCEIVE_COMPLETED;
   2341             HCI_PRINT(" HCI Transceive operation Completed. \n");
   2342             psHciContext->p_xchg_info = NULL ;
   2343             break;
   2344         }
   2345 #if defined(ENABLE_P2P)
   2346         case phHal_eNfcIP1_Initiator:
   2347         case phHal_eNfcIP1_Target:
   2348 #endif
   2349         {
   2350             HCI_PRINT(" HCI Send operation Completed. \n");
   2351             transact_info.status = NFCSTATUS_SUCCESS;
   2352             transact_result = NFC_NOTIFY_SEND_COMPLETED;
   2353             break;
   2354         }
   2355         case phHal_eUnknown_DevType:
   2356         default:
   2357         {
   2358             transact_info.status  =
   2359                         PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   2360             break;
   2361         }
   2362 
   2363     }
   2364     /* Notify the Transceive Completion to the Upper layer */
   2365     phHciNfc_Notify( p_upper_notify, pcontext , pHwRef,
   2366                     transact_result, &transact_info);
   2367 
   2368     return (NFCSTATUS)NFCSTATUS_SUCCESS;
   2369 }
   2370 
   2371 static
   2372 NFCSTATUS
   2373 phHciNfc_Info_Sequence(
   2374                             phHciNfc_sContext_t     *psHciContext,
   2375                             void                    *pHwRef
   2376                          )
   2377 {
   2378     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2379 
   2380     HCI_DEBUG(" HCI: Info Sequence Entry --> Reader Type : %02X \n",
   2381                                             psHciContext->host_rf_type);
   2382     switch (psHciContext->host_rf_type)
   2383     {
   2384         case phHal_eISO14443_A_PCD:
   2385 #ifdef TYPE_B
   2386         case phHal_eISO14443_B_PCD:
   2387 #endif
   2388         case phHal_eISO14443_BPrime_PCD:
   2389 #ifdef TYPE_FELICA
   2390         case phHal_eFelica_PCD:
   2391 #endif
   2392 #ifdef TYPE_JEWEL
   2393         case phHal_eJewel_PCD:
   2394 #endif
   2395 #ifdef TYPE_ISO15693
   2396         case phHal_eISO15693_PCD:
   2397 #endif
   2398         {
   2399             /* To update the select sequence to retrieve
   2400             * the target information using the reader type.
   2401             */
   2402             status = phHciNfc_ReaderMgmt_Info_Sequence( psHciContext, pHwRef );
   2403             break;
   2404         }
   2405 #if defined(ENABLE_P2P)
   2406         case phHal_eNfcIP1_Initiator:
   2407         case phHal_eNfcIP1_Target:
   2408         {
   2409             status = phHciNfc_NfcIP_Info_Sequence( psHciContext, pHwRef );
   2410             break;
   2411         }
   2412 #endif
   2413         case phHal_eUnknown_DevType:
   2414         default:
   2415         {
   2416             status  =
   2417                     PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   2418             break;
   2419         }
   2420 
   2421     }
   2422     return status;
   2423 }
   2424 
   2425 static
   2426 NFCSTATUS
   2427 phHciNfc_Test_Sequence(
   2428                             phHciNfc_sContext_t     *psHciContext,
   2429                             void                    *pHwRef,
   2430                             NFCSTATUS               test_status,
   2431                             uint8_t                 *pdata,
   2432                             uint8_t                 length
   2433                          )
   2434 {
   2435     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2436     static phNfc_sCompletionInfo_t      comp_info = {0};
   2437     static phNfc_sData_t test_result= {NULL,0};
   2438 
   2439     /* Complete the Test Sequence and notify the HAL */
   2440     status = phHciNfc_FSM_Complete ( psHciContext );
   2441     /* Test Results to the Upper Layer */
   2442     if(NFCSTATUS_SUCCESS == status)
   2443     {
   2444         comp_info.status = test_status;
   2445         if ( (NULL != pdata) && (length >= HCP_HEADER_LEN) )
   2446         {
   2447             test_result.buffer = ( pdata + HCP_HEADER_LEN);
   2448             test_result.length = length - HCP_HEADER_LEN;
   2449         }
   2450         else
   2451         {
   2452             status = phHciNfc_DevMgmt_Get_Test_Result(
   2453                                         psHciContext, &test_result );
   2454         }
   2455         comp_info.info = &test_result;
   2456         phHciNfc_Notify(psHciContext->p_upper_notify,
   2457                         psHciContext->p_upper_context, pHwRef,
   2458                         NFC_NOTIFY_RESULT , &comp_info);
   2459         HCI_DEBUG(" HCI System Test Completed : Status = %u\n", test_status);
   2460     }
   2461     else
   2462     {
   2463         comp_info.status = status;
   2464         phHciNfc_FSM_Rollback ( psHciContext );
   2465         phHciNfc_Notify(psHciContext->p_upper_notify,
   2466             psHciContext->p_upper_context, pHwRef,
   2467             NFC_NOTIFY_ERROR , &comp_info);
   2468         HCI_PRINT("HCI FSM Invalid Test State \n");
   2469     }
   2470 
   2471     return status;
   2472 }
   2473 
   2474 static
   2475 NFCSTATUS
   2476 phHciNfc_IO_Sequence(
   2477                             phHciNfc_sContext_t     *psHciContext,
   2478                             void                    *pHwRef,
   2479                             NFCSTATUS               io_status,
   2480                             uint8_t                 *pdata,
   2481                             uint8_t                 length
   2482                          )
   2483 {
   2484     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2485     static phNfc_sCompletionInfo_t      comp_info = {0};
   2486 
   2487     /* To remove "warning (VS 4100) : unreferenced formal parameter" */
   2488     PHNFC_UNUSED_VARIABLE(pdata);
   2489     PHNFC_UNUSED_VARIABLE(length);
   2490     /* Complete the Test Sequence and notify the HAL */
   2491     phHciNfc_FSM_Rollback ( psHciContext );
   2492     /* Test Results to the Upper Layer */
   2493     comp_info.status = io_status;
   2494     status = phHciNfc_Pending_Sequence(psHciContext, pHwRef );
   2495     if(NFCSTATUS_SUCCESS == io_status)
   2496     {
   2497         phHciNfc_Notify(psHciContext->p_upper_notify,
   2498                         psHciContext->p_upper_context, pHwRef,
   2499                         NFC_IO_SUCCESS , &comp_info);
   2500         HCI_PRINT(" HCI System IO Successful. \n");
   2501     }
   2502     else
   2503     {
   2504         phHciNfc_Notify(psHciContext->p_upper_notify,
   2505             psHciContext->p_upper_context, pHwRef,
   2506             NFC_IO_ERROR , &comp_info);
   2507         HCI_PRINT("HCI IO Error \n");
   2508     }
   2509     return status;
   2510 }
   2511 
   2512 
   2513 
   2514 #ifdef OTHER_TAGS
   2515 
   2516 NFCSTATUS
   2517 phHciNfc_Activate_Sequence(
   2518                             phHciNfc_sContext_t     *psHciContext,
   2519                             void                    *pHwRef
   2520                          )
   2521 {
   2522     NFCSTATUS           status = NFCSTATUS_SUCCESS;
   2523 
   2524     return status;
   2525 }
   2526 
   2527 
   2528 #endif
   2529 
   2530 
   2531