Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 NXP Semiconductors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*!
     18 * =========================================================================== *
     19 *                                                                             *
     20 *                                                                             *
     21 * \file  phHciNfc_Felica.c                                                 *
     22 * \brief HCI Felica Management Routines.                                    *
     23 *                                                                             *
     24 *                                                                             *
     25 * Project: NFC-FRI-1.1                                                        *
     26 *                                                                             *
     27 * $Date: Wed Feb 17 16:19:04 2010 $                                           *
     28 * $Author: ing02260 $                                                         *
     29 * $Revision: 1.11 $                                                           *
     30 * $Aliases: NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
     31 *                                                                             *
     32 * =========================================================================== *
     33 */
     34 
     35 /*
     36 ***************************** Header File Inclusion ****************************
     37 */
     38 #include <phNfcCompId.h>
     39 #include <phHciNfc_Pipe.h>
     40 #include <phHciNfc_RFReader.h>
     41 #include <phOsalNfc.h>
     42 
     43 #if defined(TYPE_FELICA)
     44 #include <phHciNfc_Felica.h>
     45 /*
     46 ****************************** Macro Definitions *******************************
     47 */
     48 
     49 #define FEL_SINGLE_TAG_FOUND                0x00U
     50 #define FEL_MULTIPLE_TAGS_FOUND             0x03U
     51 #define NXP_WRA_CONTINUE_ACTIVATION         0x12U
     52 
     53 #define NXP_FEL_SYS_CODE                    0x01U
     54 #define NXP_FEL_CURRENTIDM                  0x04U
     55 #define NXP_FEL_CURRENTPMM                  0x05U
     56 
     57 #define NXP_FEL_SYS_CODE_LEN                0x02U
     58 #define NXP_FEL_CUR_IDM_PMM_LEN             0x08U
     59 
     60 #define FELICA_STATUS                       0x00U
     61 #define FELICA_TIMEOUT                      NXP_FELICA_XCHG_TIMEOUT
     62 
     63 /* Presence check command for felica tag */
     64 #define FELICA_REQ_MODE                     0x04U
     65 /*
     66 *************************** Structure and Enumeration ***************************
     67 */
     68 
     69 
     70 /*
     71 *************************** Static Function Declaration **************************
     72 */
     73 static
     74 NFCSTATUS
     75 phHciNfc_Recv_Felica_Response(
     76                                void                *psContext,
     77                                void                *pHwRef,
     78                                uint8_t             *pResponse,
     79 #ifdef ONE_BYTE_LEN
     80                                uint8_t              length
     81 #else
     82                                uint16_t             length
     83 #endif
     84                                );
     85 
     86 static
     87 NFCSTATUS
     88 phHciNfc_Recv_Felica_Event(
     89                             void               *psContext,
     90                             void               *pHwRef,
     91                             uint8_t            *pEvent,
     92 #ifdef ONE_BYTE_LEN
     93                             uint8_t            length
     94 #else
     95                             uint16_t           length
     96 #endif
     97                             );
     98 
     99 static
    100 NFCSTATUS
    101 phHciNfc_Felica_InfoUpdate(
    102                             phHciNfc_sContext_t     *psHciContext,
    103                             uint8_t                 index,
    104                             uint8_t                 *reg_value,
    105                             uint8_t                 reg_length
    106                             );
    107 
    108 static
    109 NFCSTATUS
    110 phHciNfc_Recv_Felica_Packet(
    111                            phHciNfc_sContext_t  *psHciContext,
    112                            uint8_t              cmd,
    113                            uint8_t              *pResponse,
    114 #ifdef ONE_BYTE_LEN
    115                            uint8_t              length
    116 #else
    117                            uint16_t             length
    118 #endif
    119                            );
    120 /*
    121 *************************** Function Definitions ***************************
    122 */
    123 
    124 NFCSTATUS
    125 phHciNfc_Felica_Get_PipeID(
    126                            phHciNfc_sContext_t     *psHciContext,
    127                            uint8_t                 *ppipe_id
    128                            )
    129 {
    130     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    131 
    132     if( (NULL != psHciContext)
    133         && ( NULL != ppipe_id )
    134         && ( NULL != psHciContext->p_felica_info )
    135         )
    136     {
    137         phHciNfc_Felica_Info_t     *p_fel_info = NULL;
    138         p_fel_info = (phHciNfc_Felica_Info_t *)psHciContext->p_felica_info ;
    139         *ppipe_id =  p_fel_info->pipe_id  ;
    140     }
    141     else
    142     {
    143         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    144     }
    145     return status;
    146 }
    147 
    148 
    149 NFCSTATUS
    150 phHciNfc_Felica_Init_Resources(
    151                                phHciNfc_sContext_t     *psHciContext
    152                                )
    153 {
    154     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    155     phHciNfc_Felica_Info_t      *p_fel_info = NULL;
    156     if( NULL == psHciContext )
    157     {
    158         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    159     }
    160     else
    161     {
    162         if(
    163             ( NULL == psHciContext->p_felica_info ) &&
    164             (phHciNfc_Allocate_Resource((void **)(&p_fel_info),
    165             sizeof(phHciNfc_Felica_Info_t))== NFCSTATUS_SUCCESS)
    166             )
    167         {
    168             psHciContext->p_felica_info = p_fel_info;
    169             p_fel_info->current_seq = FELICA_INVALID_SEQ;
    170             p_fel_info->next_seq = FELICA_INVALID_SEQ;
    171             p_fel_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
    172         }
    173         else
    174         {
    175             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
    176         }
    177 
    178     }
    179     return status;
    180 }
    181 
    182 NFCSTATUS
    183 phHciNfc_Felica_Update_PipeInfo(
    184                                 phHciNfc_sContext_t     *psHciContext,
    185                                 uint8_t                 pipeID,
    186                                 phHciNfc_Pipe_Info_t    *pPipeInfo
    187                                 )
    188 {
    189     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    190 
    191     if( NULL == psHciContext )
    192     {
    193         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    194     }
    195     else if(NULL == psHciContext->p_felica_info)
    196     {
    197         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    198     }
    199     else
    200     {
    201         phHciNfc_Felica_Info_t *p_fel_info=NULL;
    202         p_fel_info = (phHciNfc_Felica_Info_t *)psHciContext->p_felica_info ;
    203 
    204         /* Update the pipe_id of the Felica Gate obtained from the HCI
    205         Response */
    206         p_fel_info->pipe_id = pipeID;
    207         p_fel_info->p_pipe_info = pPipeInfo;
    208         /* Update the Response Receive routine of the Felica Gate */
    209         pPipeInfo->recv_resp = phHciNfc_Recv_Felica_Response;
    210         /* Update the event Receive routine of the Felica Gate */
    211         pPipeInfo->recv_event = phHciNfc_Recv_Felica_Event;
    212     }
    213 
    214     return status;
    215 }
    216 
    217 NFCSTATUS
    218 phHciNfc_Felica_Update_Info(
    219                              phHciNfc_sContext_t        *psHciContext,
    220                              uint8_t                    infotype,
    221                              void                       *fel_info
    222                              )
    223 {
    224     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    225 
    226     if (NULL == psHciContext)
    227     {
    228         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    229     }
    230     else if(NULL == psHciContext->p_felica_info)
    231     {
    232         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    233     }
    234     else
    235     {
    236         phHciNfc_Felica_Info_t     *p_fel_info=NULL;
    237         p_fel_info = (phHciNfc_Felica_Info_t *)
    238                         psHciContext->p_felica_info ;
    239 
    240         switch(infotype)
    241         {
    242             case HCI_FELICA_ENABLE:
    243             {
    244                 if (NULL != fel_info)
    245                 {
    246                     p_fel_info->enable_felica_gate =
    247                                         *((uint8_t *)fel_info);
    248                 }
    249                 break;
    250             }
    251             case HCI_FELICA_INFO_SEQ:
    252             {
    253                 p_fel_info->current_seq = FELICA_SYSTEMCODE;
    254                 p_fel_info->next_seq = FELICA_SYSTEMCODE;
    255                 break;
    256             }
    257             default:
    258             {
    259                 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    260                 break;
    261             }
    262         }
    263     }
    264     return status;
    265 }
    266 
    267 NFCSTATUS
    268 phHciNfc_Felica_Info_Sequence (
    269                                void             *psHciHandle,
    270                                void             *pHwRef
    271                                )
    272 {
    273     NFCSTATUS               status = NFCSTATUS_SUCCESS;
    274     phHciNfc_sContext_t     *psHciContext =
    275                             ((phHciNfc_sContext_t *)psHciHandle);
    276 
    277     HCI_PRINT ("HCI : phHciNfc_Felica_Info_Sequence called... \n");
    278     if( (NULL == psHciContext)
    279         || (NULL == pHwRef)
    280         )
    281     {
    282         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    283     }
    284     else if((NULL == psHciContext->p_felica_info) ||
    285         (HCI_FELICA_ENABLE !=
    286         ((phHciNfc_Felica_Info_t *)(psHciContext->p_felica_info))->
    287         enable_felica_gate))
    288     {
    289         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    290     }
    291     else
    292     {
    293         phHciNfc_Felica_Info_t      *p_fel_info=NULL;
    294         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
    295         uint8_t                     pipeid = 0;
    296 
    297         p_fel_info = (phHciNfc_Felica_Info_t *)
    298                         psHciContext->p_felica_info ;
    299         p_pipe_info = p_fel_info->p_pipe_info;
    300         if(NULL == p_pipe_info )
    301         {
    302             status = PHNFCSTVAL(CID_NFC_HCI,
    303                 NFCSTATUS_INVALID_HCI_SEQUENCE);
    304         }
    305         else
    306         {
    307             HCI_DEBUG ("HCI : p_fel_info->current_seq : %02X\n", p_fel_info->current_seq);
    308             switch(p_fel_info->current_seq)
    309             {
    310                 case FELICA_SYSTEMCODE:
    311                 {
    312                     p_pipe_info->reg_index = NXP_FEL_SYS_CODE;
    313                     pipeid = p_fel_info->pipe_id ;
    314                     /* Fill the data buffer and send the command to the
    315                         device */
    316                     status =
    317                         phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    318                         pipeid, (uint8_t)ANY_GET_PARAMETER);
    319                     if(NFCSTATUS_PENDING == status )
    320                     {
    321                         p_fel_info->next_seq = FELICA_CURRENTIDM;
    322                     }
    323                     break;
    324                 }
    325                 case FELICA_CURRENTIDM:
    326                 {
    327                     p_pipe_info->reg_index = NXP_FEL_CURRENTIDM;
    328                     pipeid = p_fel_info->pipe_id ;
    329                     /* Fill the data buffer and send the command to the
    330                         device */
    331                     status =
    332                         phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    333                         pipeid, (uint8_t)ANY_GET_PARAMETER);
    334                     if(NFCSTATUS_PENDING == status )
    335                     {
    336                         p_fel_info->next_seq = FELICA_CURRENTPMM;
    337                     }
    338                     break;
    339                 }
    340                 case FELICA_CURRENTPMM:
    341                 {
    342                     p_pipe_info->reg_index = NXP_FEL_CURRENTPMM;
    343                     pipeid = p_fel_info->pipe_id ;
    344                     /* Fill the data buffer and send the command to the
    345                         device */
    346                     status =
    347                         phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef,
    348                         pipeid, (uint8_t)ANY_GET_PARAMETER);
    349                     if(NFCSTATUS_PENDING == status )
    350                     {
    351                         p_fel_info->next_seq = FELICA_END_SEQUENCE;
    352                     }
    353                     break;
    354                 }
    355                 case FELICA_END_SEQUENCE:
    356                 {
    357                     phNfc_sCompletionInfo_t     CompInfo;
    358                     if (FEL_MULTIPLE_TAGS_FOUND ==
    359                         p_fel_info->multiple_tgts_found)
    360                     {
    361                         CompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
    362                     }
    363                     else
    364                     {
    365                         CompInfo.status = NFCSTATUS_SUCCESS;
    366                     }
    367 
    368                     CompInfo.info = &(p_fel_info->felica_info);
    369 
    370                     p_fel_info->felica_info.RemDevType = phHal_eFelica_PICC;
    371                     p_fel_info->current_seq = FELICA_SYSTEMCODE;
    372                     p_fel_info->next_seq = FELICA_SYSTEMCODE;
    373                     status = NFCSTATUS_SUCCESS;
    374                     HCI_DEBUG ("HCI : p_fel_info->felica_info.RemDevType : %02X\n", p_fel_info->felica_info.RemDevType);
    375                     HCI_DEBUG ("HCI : status notified: %02X\n", CompInfo.status);
    376                     /* Notify to the upper layer */
    377                     phHciNfc_Tag_Notify(psHciContext,
    378                                         pHwRef,
    379                                         NFC_NOTIFY_TARGET_DISCOVERED,
    380                                         &CompInfo);
    381                     break;
    382                 }
    383                 default:
    384                 {
    385                     status = PHNFCSTVAL(CID_NFC_HCI,
    386                         NFCSTATUS_INVALID_HCI_RESPONSE);
    387                     break;
    388                 }
    389             }
    390             HCI_DEBUG ("HCI : p_fel_info->current_seq after : %02X\n", p_fel_info->current_seq);
    391             HCI_DEBUG ("HCI : p_fel_info->next_seq : %02X\n", p_fel_info->next_seq);
    392         }
    393     }
    394     HCI_PRINT ("HCI : phHciNfc_Felica_Info_Sequence end\n");
    395     return status;
    396 }
    397 
    398 static
    399 NFCSTATUS
    400 phHciNfc_Felica_InfoUpdate(
    401                             phHciNfc_sContext_t     *psHciContext,
    402                             uint8_t                 index,
    403                             uint8_t                 *reg_value,
    404                             uint8_t                 reg_length
    405                             )
    406 {
    407     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    408     phHciNfc_Felica_Info_t     *p_fel_info=NULL;
    409     phHal_sFelicaInfo_t        *p_fel_tag_info = NULL;
    410 
    411     p_fel_info = (phHciNfc_Felica_Info_t *)(psHciContext->p_felica_info );
    412     p_fel_tag_info = &(p_fel_info->felica_info.RemoteDevInfo.Felica_Info);
    413 
    414     switch(index)
    415     {
    416         case NXP_FEL_SYS_CODE:
    417         {
    418             if (NXP_FEL_SYS_CODE_LEN == reg_length)
    419             {
    420                 HCI_PRINT_BUFFER("\tFelica system code data", reg_value, reg_length);
    421                 /* Update current system code values */
    422                 (void)memcpy(p_fel_tag_info->SystemCode, reg_value,
    423                             reg_length);
    424             }
    425             else
    426             {
    427                 status = PHNFCSTVAL(CID_NFC_HCI,
    428                                     NFCSTATUS_INVALID_HCI_RESPONSE);
    429             }
    430             break;
    431         }
    432         case NXP_FEL_CURRENTIDM:
    433         {
    434             if (NXP_FEL_CUR_IDM_PMM_LEN == reg_length)
    435             {
    436                 HCI_PRINT_BUFFER("\tFelica ID data", reg_value, reg_length);
    437                 /* Update current PM values */
    438                 (void)memcpy(p_fel_tag_info->IDm, reg_value,
    439                             reg_length);
    440                 p_fel_tag_info->IDmLength = reg_length;
    441             }
    442             else
    443             {
    444                 status = PHNFCSTVAL(CID_NFC_HCI,
    445                                     NFCSTATUS_INVALID_HCI_RESPONSE);
    446             }
    447             break;
    448         }
    449         case NXP_FEL_CURRENTPMM:
    450         {
    451             if (NXP_FEL_CUR_IDM_PMM_LEN == reg_length)
    452             {
    453                 HCI_PRINT_BUFFER("\tFelica PM data", reg_value, reg_length);
    454                 /* Update current PM values */
    455                 (void)memcpy(p_fel_tag_info->PMm, reg_value,
    456                             reg_length);
    457             }
    458             else
    459             {
    460                 status = PHNFCSTVAL(CID_NFC_HCI,
    461                                     NFCSTATUS_INVALID_HCI_RESPONSE);
    462             }
    463             break;
    464         }
    465         default:
    466         {
    467             status = PHNFCSTVAL(CID_NFC_HCI,
    468                                 NFCSTATUS_INVALID_HCI_RESPONSE);
    469             break;
    470         }
    471     }
    472     return status;
    473 }
    474 
    475 
    476 static
    477 NFCSTATUS
    478 phHciNfc_Recv_Felica_Packet(
    479                             phHciNfc_sContext_t  *psHciContext,
    480                             uint8_t              cmd,
    481                             uint8_t              *pResponse,
    482 #ifdef ONE_BYTE_LEN
    483                             uint8_t             length
    484 #else
    485                             uint16_t            length
    486 #endif
    487                             )
    488 {
    489     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    490     uint8_t                     index = 0;
    491 
    492     /* To remove "warning (VS C4100) : unreferenced formal parameter" */
    493 
    494     PHNFC_UNUSED_VARIABLE(length);
    495 
    496     if (NXP_FELICA_RAW == cmd)
    497     {
    498         if (FELICA_STATUS == pResponse[index])  /* Status byte */
    499         {
    500             index = (index + 1);
    501             psHciContext->rx_index = (HCP_HEADER_LEN + 1);
    502             HCI_PRINT_BUFFER("Felica Bytes received", &pResponse[index], (length - index));
    503         }
    504         else
    505         {
    506             status = PHNFCSTVAL(CID_NFC_HCI,
    507                                 NFCSTATUS_INVALID_HCI_RESPONSE);
    508         }
    509     }
    510     else
    511     {
    512         psHciContext->rx_index = HCP_HEADER_LEN;
    513 
    514         /* command NXP_FELICA_CMD: so give Felica data to the upper layer */
    515         HCI_PRINT_BUFFER("Felica Bytes received", pResponse, length);
    516     }
    517 
    518     return status;
    519 }
    520 
    521 
    522 static
    523 NFCSTATUS
    524 phHciNfc_Recv_Felica_Response(
    525                                void                *psContext,
    526                                void                *pHwRef,
    527                                uint8_t             *pResponse,
    528 #ifdef ONE_BYTE_LEN
    529                                uint8_t          length
    530 #else
    531                                uint16_t             length
    532 #endif
    533                                )
    534 {
    535     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    536     phHciNfc_sContext_t         *psHciContext =
    537                                     (phHciNfc_sContext_t *)psContext ;
    538 
    539 
    540     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
    541         || (0 == length))
    542     {
    543         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    544     }
    545     else if(NULL == psHciContext->p_felica_info)
    546     {
    547         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    548     }
    549     else
    550     {
    551         phHciNfc_Felica_Info_t     *p_fel_info=NULL;
    552         uint8_t                     prev_cmd = ANY_GET_PARAMETER;
    553         p_fel_info = (phHciNfc_Felica_Info_t *)
    554                         psHciContext->p_felica_info ;
    555         if( NULL == p_fel_info->p_pipe_info)
    556         {
    557             status = PHNFCSTVAL(CID_NFC_HCI,
    558                                 NFCSTATUS_INVALID_HCI_SEQUENCE);
    559         }
    560         else
    561         {
    562             prev_cmd = p_fel_info->p_pipe_info->prev_msg ;
    563             switch(prev_cmd)
    564             {
    565                 case ANY_GET_PARAMETER:
    566                 {
    567                     status = phHciNfc_Felica_InfoUpdate(psHciContext,
    568                                         p_fel_info->p_pipe_info->reg_index,
    569                                         &pResponse[HCP_HEADER_LEN],
    570                                         (uint8_t)(length - HCP_HEADER_LEN));
    571                     break;
    572                 }
    573                 case ANY_SET_PARAMETER:
    574                 {
    575                     HCI_PRINT("Felica Parameter Set \n");
    576                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    577                                                                 UPDATE_SEQ);
    578                     p_fel_info->next_seq = FELICA_SYSTEMCODE;
    579                     break;
    580                 }
    581                 case ANY_OPEN_PIPE:
    582                 {
    583                     HCI_PRINT("Felica open pipe complete\n");
    584                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    585                                                                 UPDATE_SEQ);
    586                     p_fel_info->next_seq = FELICA_SYSTEMCODE;
    587                     break;
    588                 }
    589                 case ANY_CLOSE_PIPE:
    590                 {
    591                     HCI_PRINT("Felica close pipe complete\n");
    592                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    593                                                                 UPDATE_SEQ);
    594                     break;
    595                 }
    596 
    597                 case NXP_FELICA_RAW:
    598                 case NXP_FELICA_CMD:
    599                 case WR_XCHGDATA:
    600                 {
    601                     HCI_PRINT("Felica packet received \n");
    602                     if (length >= HCP_HEADER_LEN)
    603                     {
    604                         phHciNfc_Append_HCPFrame(psHciContext->recv_buffer,
    605                                                     0, pResponse, length);
    606                         psHciContext->rx_total = length;
    607                         status = phHciNfc_Recv_Felica_Packet(psHciContext,
    608                                                     prev_cmd,
    609                                                     &pResponse[HCP_HEADER_LEN],
    610                                                     (length - HCP_HEADER_LEN));
    611                     }
    612                     else
    613                     {
    614                         status = PHNFCSTVAL(CID_NFC_HCI,
    615                                             NFCSTATUS_INVALID_HCI_RESPONSE);
    616                     }
    617                     break;
    618                 }
    619                 case NXP_WRA_CONTINUE_ACTIVATION:
    620                 case NXP_WR_ACTIVATE_ID:
    621                 {
    622                     HCI_PRINT("Felica continue activation or ");
    623                     HCI_PRINT("reactivation completed \n");
    624                     status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    625                                                     UPDATE_SEQ);
    626                     break;
    627                 }
    628                 case NXP_WR_PRESCHECK:
    629                 {
    630                     HCI_PRINT("Presence check completed \n");
    631                     break;
    632                 }
    633                 case NXP_WR_ACTIVATE_NEXT:
    634                 {
    635                     HCI_PRINT("Activate next completed \n");
    636                     if (length > HCP_HEADER_LEN)
    637                     {
    638                         if (FEL_MULTIPLE_TAGS_FOUND == pResponse[HCP_HEADER_LEN])
    639                         {
    640                             p_fel_info->multiple_tgts_found =
    641                                             FEL_MULTIPLE_TAGS_FOUND;
    642                         }
    643                         else
    644                         {
    645                             p_fel_info->multiple_tgts_found = FALSE;
    646                         }
    647                     }
    648                     else
    649                     {
    650                         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
    651                     }
    652                     break;
    653                 }
    654                 case NXP_WR_DISPATCH_TO_UICC:
    655                 {
    656                     switch(length)
    657                     {
    658                         case HCP_HEADER_LEN:
    659                         {
    660                             /* Optional error code, if no error code field
    661                                 in the response, then this command is
    662                                 successfully completed */
    663                             p_fel_info->uicc_activation =
    664                                         UICC_CARD_ACTIVATION_SUCCESS;
    665                             break;
    666                         }
    667                         case (HCP_HEADER_LEN + 1):
    668                         {
    669                             p_fel_info->uicc_activation =
    670                                         pResponse[HCP_HEADER_LEN];
    671                             break;
    672                         } /* End of case (HCP_HEADER_LEN + index) */
    673                         default:
    674                         {
    675                             status = PHNFCSTVAL(CID_NFC_HCI,
    676                                                 NFCSTATUS_INVALID_HCI_RESPONSE);
    677                             break;
    678                         }
    679                     }
    680                     if (NFCSTATUS_SUCCESS == status)
    681                     {
    682                         status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext,
    683                                                                     UPDATE_SEQ);
    684                     }
    685                     break;
    686                 }
    687                 default:
    688                 {
    689                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
    690                     break;
    691                 }
    692             }
    693             if( NFCSTATUS_SUCCESS == status )
    694             {
    695                 p_fel_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
    696                 p_fel_info->current_seq = p_fel_info->next_seq;
    697             }
    698         }
    699     }
    700     return status;
    701 }
    702 
    703 
    704 static
    705 NFCSTATUS
    706 phHciNfc_Recv_Felica_Event(
    707                             void               *psContext,
    708                             void               *pHwRef,
    709                             uint8_t            *pEvent,
    710 #ifdef ONE_BYTE_LEN
    711                             uint8_t             length
    712 #else
    713                             uint16_t            length
    714 #endif
    715                             )
    716 {
    717     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    718     phHciNfc_sContext_t         *psHciContext =
    719                                 (phHciNfc_sContext_t *)psContext ;
    720 
    721     HCI_PRINT ("HCI : phHciNfc_Recv_Felica_Event called...\n");
    722     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
    723         || (0 == length))
    724     {
    725         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    726     }
    727     else if((NULL == psHciContext->p_felica_info) ||
    728         (HCI_FELICA_ENABLE !=
    729         ((phHciNfc_Felica_Info_t *)(psHciContext->p_felica_info))->
    730         enable_felica_gate))
    731     {
    732         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    733     }
    734     else
    735     {
    736         phHciNfc_HCP_Packet_t       *p_packet = NULL;
    737         phHciNfc_Felica_Info_t      *p_fel_info = NULL;
    738         phHciNfc_HCP_Message_t      *message = NULL;
    739         uint8_t                     instruction=0,
    740                                     i = 0;
    741 
    742         p_fel_info = (phHciNfc_Felica_Info_t *)
    743                                 psHciContext->p_felica_info ;
    744         p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
    745         message = &p_packet->msg.message;
    746         /* Get the instruction bits from the Message Header */
    747         instruction = (uint8_t) GET_BITS8( message->msg_header,
    748                     HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
    749 
    750         HCI_DEBUG ("HCI : instruction : %02X\n", instruction);
    751         HCI_DEBUG ("HCI : Multiple tag found : %02X\n", message->payload[i]);
    752         if ((EVT_TARGET_DISCOVERED == instruction)
    753             && ((FEL_MULTIPLE_TAGS_FOUND == message->payload[i] )
    754             || (FEL_SINGLE_TAG_FOUND == message->payload[i]))
    755             )
    756         {
    757             static phNfc_sCompletionInfo_t      pCompInfo;
    758 
    759             if (FEL_MULTIPLE_TAGS_FOUND == message->payload[i])
    760             {
    761                 p_fel_info->multiple_tgts_found = FEL_MULTIPLE_TAGS_FOUND;
    762                 pCompInfo.status = NFCSTATUS_MULTIPLE_TAGS;
    763             }
    764             else
    765             {
    766                 p_fel_info->multiple_tgts_found = FALSE;
    767                 pCompInfo.status = NFCSTATUS_SUCCESS;
    768             }
    769 
    770             HCI_DEBUG ("HCI : psHciContext->host_rf_type : %02X\n", psHciContext->host_rf_type);
    771             HCI_DEBUG ("HCI : p_fel_info->felica_info.RemDevType : %02X\n", p_fel_info->felica_info.RemDevType);
    772             HCI_DEBUG ("HCI : p_fel_info->current_seq : %02X\n", p_fel_info->current_seq);
    773 
    774             psHciContext->host_rf_type = phHal_eFelica_PCD;
    775             p_fel_info->felica_info.RemDevType = phHal_eFelica_PICC;
    776             p_fel_info->current_seq = FELICA_SYSTEMCODE;
    777 
    778             /* Notify to the HCI Generic layer To Update the FSM */
    779             phHciNfc_Notify_Event(psHciContext, pHwRef,
    780                                 NFC_NOTIFY_TARGET_DISCOVERED,
    781                                 &pCompInfo);
    782 
    783         }
    784         else
    785         {
    786             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
    787         }
    788     }
    789     HCI_PRINT ("HCI : phHciNfc_Recv_Felica_Event end\n");
    790     return status;
    791 }
    792 
    793 
    794 NFCSTATUS
    795 phHciNfc_Felica_Request_Mode(
    796                               phHciNfc_sContext_t   *psHciContext,
    797                               void                  *pHwRef)
    798 {
    799     NFCSTATUS           status = NFCSTATUS_SUCCESS;
    800     static uint8_t      pres_chk_data[6] = {0};
    801 
    802     if( (NULL == psHciContext) || (NULL == pHwRef) )
    803     {
    804         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    805     }
    806     else
    807     {
    808         phHciNfc_Felica_Info_t          *ps_fel_info = NULL;
    809         phHciNfc_Pipe_Info_t            *ps_pipe_info = NULL;
    810         phHal_sFelicaInfo_t             *ps_rem_fel_info = NULL;
    811 
    812         ps_fel_info = (phHciNfc_Felica_Info_t *)
    813                             psHciContext->p_felica_info ;
    814         ps_pipe_info = ps_fel_info->p_pipe_info;
    815 
    816         if(NULL == ps_pipe_info )
    817         {
    818             status = PHNFCSTVAL(CID_NFC_HCI,
    819                                 NFCSTATUS_INVALID_HCI_SEQUENCE);
    820         }
    821         else
    822         {
    823             ps_rem_fel_info =
    824                 &(ps_fel_info->felica_info.RemoteDevInfo.Felica_Info);
    825 
    826             pres_chk_data[0] = sizeof(pres_chk_data);
    827             pres_chk_data[1] = 0x00; // Felica poll
    828             pres_chk_data[2] = 0xFF;
    829             pres_chk_data[3] = 0xFF;
    830             pres_chk_data[4] = 0x00;
    831             pres_chk_data[5] = 0x00;
    832 
    833             ps_pipe_info->param_info = pres_chk_data;
    834             ps_pipe_info->param_length = sizeof(pres_chk_data);
    835             status = phHciNfc_Send_Felica_Command(
    836                                         psHciContext, pHwRef,
    837                                         ps_pipe_info->pipe.pipe_id,
    838                                         NXP_FELICA_RAW);
    839         }
    840     }
    841 
    842     return status;
    843 }
    844 
    845 
    846 NFCSTATUS
    847 phHciNfc_Send_Felica_Command(
    848                               phHciNfc_sContext_t   *psContext,
    849                               void                  *pHwRef,
    850                               uint8_t               pipe_id,
    851                               uint8_t               cmd
    852                               )
    853 {
    854     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    855     phHciNfc_sContext_t         *psHciContext =
    856                                 (phHciNfc_sContext_t *)psContext ;
    857     if( (NULL == psHciContext) || (NULL == pHwRef) )
    858     {
    859         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    860     }
    861     else if((NULL == psHciContext->p_felica_info) ||
    862         (HCI_FELICA_ENABLE !=
    863         ((phHciNfc_Felica_Info_t *)(psHciContext->p_felica_info))->
    864         enable_felica_gate) ||
    865         (HCI_UNKNOWN_PIPE_ID ==
    866         ((phHciNfc_Felica_Info_t *)(psHciContext->p_felica_info))->
    867         pipe_id) ||
    868         (pipe_id !=
    869         ((phHciNfc_Felica_Info_t *)(psHciContext->p_felica_info))->
    870         pipe_id))
    871     {
    872         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    873     }
    874     else
    875     {
    876         phHciNfc_Felica_Info_t     *p_fel_info=NULL;
    877         phHciNfc_Pipe_Info_t        *p_pipe_info=NULL;
    878         phHciNfc_HCP_Packet_t       *hcp_packet = NULL;
    879         phHciNfc_HCP_Message_t      *hcp_message = NULL;
    880         uint8_t                     i = 0,
    881                                     length = HCP_HEADER_LEN;
    882 
    883         p_fel_info = (phHciNfc_Felica_Info_t *)
    884                             psHciContext->p_felica_info ;
    885         p_pipe_info = p_fel_info->p_pipe_info;
    886         if(NULL == p_pipe_info )
    887         {
    888             status = PHNFCSTVAL(CID_NFC_HCI,
    889                                 NFCSTATUS_INVALID_HCI_SEQUENCE);
    890         }
    891         else
    892         {
    893             psHciContext->tx_total = 0 ;
    894             hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
    895             /* Construct the HCP Frame */
    896             phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
    897                             (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
    898             switch(cmd)
    899             {
    900                 case NXP_FELICA_RAW:
    901                 {
    902                     /*
    903                     Buffer shall be updated with
    904                     TO -              Time out (1 byte)
    905                     Status -          b0 to b2 indicate valid bits (1 byte)
    906                     Data  -           params received from this function
    907                     */
    908                     hcp_message = &(hcp_packet->msg.message);
    909 
    910                     /* Time out */
    911                     hcp_message->payload[i++] = FELICA_TIMEOUT ;
    912                     /* Status */
    913                     hcp_message->payload[i++] = FELICA_STATUS;
    914 
    915                     phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
    916                                         i, (uint8_t *)p_pipe_info->param_info,
    917                                         p_pipe_info->param_length);
    918                     length =(uint8_t)(length + i + p_pipe_info->param_length);
    919                     break;
    920                 }
    921                 case NXP_FELICA_CMD:
    922                 {
    923                     /*
    924                     Buffer shall be updated with
    925                     Cmd -               Authentication A/B, read/write
    926                     (1 byte)
    927                     Data  -             params received from this function
    928                     */
    929                     hcp_message = &(hcp_packet->msg.message);
    930 
    931                     /* Command */
    932                     hcp_message->payload[i++] =
    933                                  psHciContext->p_xchg_info->params.tag_info.cmd_type ;
    934                     phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
    935                                         i, (uint8_t *)p_pipe_info->param_info,
    936                                         p_pipe_info->param_length);
    937                     length =(uint8_t)(length + i + p_pipe_info->param_length);
    938                     break;
    939                 }
    940                 default:
    941                 {
    942                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_COMMAND);
    943                     break;
    944                 }
    945             }
    946             if (NFCSTATUS_SUCCESS == status)
    947             {
    948                 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND;
    949                 p_pipe_info->prev_msg = cmd;
    950                 psHciContext->tx_total = length;
    951                 psHciContext->response_pending = TRUE;
    952 
    953                 /* Send the Constructed HCP packet to the lower layer */
    954                 status = phHciNfc_Send_HCP( psHciContext, pHwRef);
    955                 p_pipe_info->prev_status = status;
    956             }
    957         }
    958     }
    959     return status;
    960 }
    961 
    962 #endif /* #if defined(TYPE_FELICA) */
    963