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_CE_A.c                                             *
     22 * \brief HCI card emulation A management routines.                              *
     23 *                                                                             *
     24 *                                                                             *
     25 * Project: NFC-FRI-1.1                                                        *
     26 *                                                                             *
     27 * $Date: Fri Aug 21 18:35:05 2009 $                                           *
     28 * $Author: ing04880 $                                                         *
     29 * $Revision: 1.14 $                                                           *
     30 * $Aliases: NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,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 <phNfcHalTypes.h>
     40 #include <phHciNfc_Pipe.h>
     41 #include <phHciNfc_Emulation.h>
     42 #include <phOsalNfc.h>
     43 /*
     44 ****************************** Macro Definitions *******************************
     45 */
     46 #if defined (HOST_EMULATION)
     47 #include <phHciNfc_CE_A.h>
     48 
     49 #define CE_A_EVT_NFC_SEND_DATA               0x10U
     50 #define CE_A_EVT_NFC_FIELD_ON                0x11U
     51 #define CE_A_EVT_NFC_DEACTIVATED             0x12U
     52 #define CE_A_EVT_NFC_ACTIVATED               0x13U
     53 #define CE_A_EVT_NFC_FIELD_OFF               0x14U
     54 
     55 /*
     56 *************************** Structure and Enumeration ***************************
     57 */
     58 
     59 
     60 /*
     61 *************************** Static Function Declaration **************************
     62 */
     63 
     64 static
     65 NFCSTATUS
     66 phHciNfc_Recv_CE_A_Event(
     67                              void               *psContext,
     68                              void               *pHwRef,
     69                              uint8_t            *pEvent,
     70 #ifdef ONE_BYTE_LEN
     71                              uint8_t            length
     72 #else
     73                              uint16_t           length
     74 #endif
     75                        );
     76 
     77 static
     78 NFCSTATUS
     79 phHciNfc_Recv_CE_A_Response(
     80                              void               *psContext,
     81                              void               *pHwRef,
     82                              uint8_t            *pResponse,
     83 #ifdef ONE_BYTE_LEN
     84                              uint8_t            length
     85 #else
     86                              uint16_t           length
     87 #endif
     88                        );
     89 
     90 #if defined (SEND_DATA_EVENT)
     91 static
     92 NFCSTATUS
     93 phHciNfc_CE_A_ProcessData(
     94                             phHciNfc_sContext_t     *psHciContext,
     95                             void                    *pHwRef,
     96                             uint8_t                 *pData,
     97                             uint8_t                 length
     98                        );
     99 #endif /* #if defined (SEND_DATA_EVENT) */
    100 
    101 /*
    102 *************************** Function Definitions ***************************
    103 */
    104 NFCSTATUS
    105 phHciNfc_CE_A_Init_Resources(
    106                                 phHciNfc_sContext_t     *psHciContext
    107                          )
    108 {
    109     NFCSTATUS               status = NFCSTATUS_SUCCESS;
    110     phHciNfc_CE_A_Info_t     *ps_ce_a_info=NULL;
    111     if( NULL == psHciContext )
    112     {
    113         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    114     }
    115     else
    116     {
    117         if(
    118             ( NULL == psHciContext->p_ce_a_info ) &&
    119              (phHciNfc_Allocate_Resource((void **)(&ps_ce_a_info),
    120             sizeof(phHciNfc_CE_A_Info_t))== NFCSTATUS_SUCCESS)
    121           )
    122         {
    123             psHciContext->p_ce_a_info = ps_ce_a_info;
    124             ps_ce_a_info->current_seq = HOST_CE_A_INVALID_SEQ;
    125             ps_ce_a_info->next_seq = HOST_CE_A_INVALID_SEQ;
    126             ps_ce_a_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
    127         }
    128         else
    129         {
    130             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
    131         }
    132 
    133     }
    134     return status;
    135 }
    136 
    137 NFCSTATUS
    138 phHciNfc_CE_A_Initialise(
    139                         phHciNfc_sContext_t     *psHciContext,
    140                         void                    *pHwRef
    141                         )
    142 {
    143     /*
    144         1. Open Pipe,
    145         2. Set all parameters
    146     */
    147     NFCSTATUS           status = NFCSTATUS_SUCCESS;
    148     static uint8_t      sak = HOST_CE_A_SAK_DEFAULT;
    149     static uint8_t      atqa_info[] = { NXP_CE_A_ATQA_HIGH,
    150                                         NXP_CE_A_ATQA_LOW};
    151 
    152     if ((NULL == psHciContext) || (NULL == pHwRef))
    153     {
    154         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    155     }
    156     else if(NULL == psHciContext->p_ce_a_info)
    157     {
    158         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    159     }
    160     else
    161     {
    162         phHciNfc_CE_A_Info_t        *ps_ce_a_info = ((phHciNfc_CE_A_Info_t *)
    163                                                 psHciContext->p_ce_a_info );
    164         phHciNfc_Pipe_Info_t        *ps_pipe_info = NULL;
    165 
    166         ps_pipe_info =  ps_ce_a_info->p_pipe_info;
    167         if(NULL == ps_pipe_info )
    168         {
    169             status = PHNFCSTVAL(CID_NFC_HCI,
    170                                 NFCSTATUS_INVALID_HCI_INFORMATION);
    171         }
    172         else
    173         {
    174             switch(ps_ce_a_info->current_seq)
    175             {
    176                 case HOST_CE_A_PIPE_OPEN:
    177                 {
    178                     status = phHciNfc_Open_Pipe( psHciContext,
    179                                                 pHwRef, ps_pipe_info );
    180                     if(status == NFCSTATUS_SUCCESS)
    181                     {
    182                         ps_ce_a_info->next_seq = HOST_CE_A_SAK_SEQ;
    183                         status = NFCSTATUS_PENDING;
    184                     }
    185                     break;
    186                 }
    187                 case HOST_CE_A_SAK_SEQ:
    188                 {
    189                     /* HOST Card Emulation A SAK Configuration */
    190                     ps_pipe_info->reg_index = HOST_CE_A_SAK_INDEX;
    191                     /* Configure the SAK of Host Card Emulation A */
    192                     sak = (uint8_t)HOST_CE_A_SAK_DEFAULT;
    193                     ps_pipe_info->param_info =(void*)&sak ;
    194                     ps_pipe_info->param_length = sizeof(sak) ;
    195                     status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
    196                                                 ps_pipe_info->pipe.pipe_id,
    197                                                 (uint8_t)ANY_SET_PARAMETER);
    198                     if(status == NFCSTATUS_PENDING)
    199                     {
    200                         ps_ce_a_info->next_seq = HOST_CE_A_ATQA_SEQ;
    201                     }
    202                     break;
    203                 }
    204                 case HOST_CE_A_ATQA_SEQ:
    205                 {
    206                     /* HOST Card Emulation A ATQA Configuration */
    207                     ps_pipe_info->reg_index = HOST_CE_A_ATQA_INDEX;
    208                     /* Configure the ATQA of Host Card Emulation A */
    209                     ps_pipe_info->param_info = (void*)atqa_info ;
    210                     ps_pipe_info->param_length = sizeof(atqa_info) ;
    211                     status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
    212                                                 ps_pipe_info->pipe.pipe_id,
    213                                                 (uint8_t)ANY_SET_PARAMETER);
    214                     if(status == NFCSTATUS_PENDING)
    215                     {
    216                         ps_ce_a_info->next_seq = HOST_CE_A_ENABLE_SEQ;
    217                     }
    218                     break;
    219                 }
    220                 case HOST_CE_A_ENABLE_SEQ:
    221                 {
    222                     status = phHciNfc_CE_A_Mode( psHciContext,
    223                         pHwRef,  HOST_CE_MODE_ENABLE );
    224                     if(status == NFCSTATUS_PENDING)
    225                     {
    226                         ps_ce_a_info->next_seq = HOST_CE_A_DISABLE_SEQ;
    227                         status = NFCSTATUS_SUCCESS;
    228                     }
    229                     break;
    230                 }
    231                 default :
    232                 {
    233                     break;
    234                 }
    235             }
    236         }
    237     }
    238 
    239     return status;
    240 }
    241 
    242 NFCSTATUS
    243 phHciNfc_CE_A_Release(
    244                         phHciNfc_sContext_t     *psHciContext,
    245                         void                    *pHwRef
    246                         )
    247 {
    248     /*
    249         1. Close pipe
    250     */
    251     NFCSTATUS       status = NFCSTATUS_SUCCESS;
    252     if ((NULL == psHciContext) || (NULL == pHwRef))
    253     {
    254         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    255     }
    256     else if(NULL == psHciContext->p_ce_a_info)
    257     {
    258         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    259     }
    260     else
    261     {
    262         phHciNfc_CE_A_Info_t        *ps_ce_a_info = ((phHciNfc_CE_A_Info_t *)
    263                                                 psHciContext->p_ce_a_info );
    264         phHciNfc_Pipe_Info_t        *ps_pipe_info = NULL;
    265 
    266         ps_pipe_info =  ps_ce_a_info->p_pipe_info;
    267         if(NULL == ps_pipe_info )
    268         {
    269             status = PHNFCSTVAL(CID_NFC_HCI,
    270                             NFCSTATUS_NOT_ALLOWED);
    271         }
    272         else
    273         {
    274             switch(ps_ce_a_info->current_seq)
    275             {
    276                 case HOST_CE_A_DISABLE_SEQ:
    277                 {
    278                     status = phHciNfc_CE_A_Mode( psHciContext,
    279                         pHwRef,  HOST_CE_MODE_DISABLE );
    280                     if(status == NFCSTATUS_PENDING)
    281                     {
    282                         ps_ce_a_info->next_seq = HOST_CE_A_PIPE_CLOSE;
    283                     }
    284                     break;
    285                 }
    286                 case HOST_CE_A_PIPE_CLOSE:
    287                 {
    288                     /* HOST Card Emulation A pipe close sequence */
    289                     status = phHciNfc_Close_Pipe( psHciContext,
    290                                                 pHwRef, ps_pipe_info );
    291                     if(status == NFCSTATUS_SUCCESS)
    292                     {
    293                         ps_ce_a_info->next_seq = HOST_CE_A_PIPE_DELETE;
    294                         status = NFCSTATUS_PENDING;
    295                     }
    296                     break;
    297                 }
    298                 case HOST_CE_A_PIPE_DELETE:
    299                 {
    300                     /* HOST Card Emulation A pipe delete sequence */
    301                     status = phHciNfc_Delete_Pipe( psHciContext,
    302                                                 pHwRef, ps_pipe_info );
    303                     if(status == NFCSTATUS_SUCCESS)
    304                     {
    305 #if 0
    306                         ps_ce_a_info->pipe_id = HCI_UNKNOWN_PIPE_ID;
    307                         psHciContext->p_pipe_list[ps_ce_a_info->pipe_id] = NULL;
    308                         phOsalNfc_FreeMemory((void *)ps_ce_a_info->p_pipe_info);
    309                         ps_ce_a_info->p_pipe_info = NULL;
    310 #endif
    311                         ps_ce_a_info->next_seq = HOST_CE_A_PIPE_OPEN;
    312                     }
    313                     break;
    314                 }
    315                 default :
    316                 {
    317                     break;
    318                 }
    319             }
    320         }
    321     }
    322     return status;
    323 }
    324 
    325 NFCSTATUS
    326 phHciNfc_CE_A_Update_PipeInfo(
    327                                   phHciNfc_sContext_t     *psHciContext,
    328                                   uint8_t                 pipeID,
    329                                   phHciNfc_Pipe_Info_t    *pPipeInfo
    330                                   )
    331 {
    332     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    333 
    334     if( NULL == psHciContext )
    335     {
    336         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    337     }
    338     else if(NULL == psHciContext->p_ce_a_info)
    339     {
    340         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    341     }
    342     else
    343     {
    344         phHciNfc_CE_A_Info_t         *ps_ce_a_info=NULL;
    345         ps_ce_a_info = (phHciNfc_CE_A_Info_t *)
    346                         psHciContext->p_ce_a_info ;
    347 
    348         ps_ce_a_info->current_seq = HOST_CE_A_PIPE_OPEN;
    349         ps_ce_a_info->next_seq = HOST_CE_A_PIPE_OPEN;
    350         /* Update the pipe_id of the card emulation A Gate o
    351             btained from the HCI Response */
    352         ps_ce_a_info->pipe_id = pipeID;
    353         if (HCI_UNKNOWN_PIPE_ID != pipeID)
    354         {
    355             ps_ce_a_info->p_pipe_info = pPipeInfo;
    356             if (NULL != pPipeInfo)
    357             {
    358                 /* Update the Response Receive routine of the card
    359                     emulation A Gate */
    360                 pPipeInfo->recv_resp = &phHciNfc_Recv_CE_A_Response;
    361                 /* Update the event Receive routine of the card emulation A Gate */
    362                 pPipeInfo->recv_event = &phHciNfc_Recv_CE_A_Event;
    363             }
    364         }
    365         else
    366         {
    367             ps_ce_a_info->p_pipe_info = NULL;
    368         }
    369     }
    370 
    371     return status;
    372 }
    373 
    374 NFCSTATUS
    375 phHciNfc_CE_A_Get_PipeID(
    376                              phHciNfc_sContext_t        *psHciContext,
    377                              uint8_t                    *ppipe_id
    378                              )
    379 {
    380     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    381 
    382     if( (NULL != psHciContext)
    383         && ( NULL != ppipe_id )
    384         && ( NULL != psHciContext->p_ce_a_info )
    385         )
    386     {
    387         phHciNfc_CE_A_Info_t     *ps_ce_a_info=NULL;
    388         ps_ce_a_info = (phHciNfc_CE_A_Info_t *)
    389                         psHciContext->p_ce_a_info ;
    390         *ppipe_id =  ps_ce_a_info->pipe_id  ;
    391     }
    392     else
    393     {
    394         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    395     }
    396     return status;
    397 }
    398 
    399 #ifdef CE_A_SEND_EVENT
    400 NFCSTATUS
    401 phHciNfc_CE_A_SendData_Event(
    402                              void               *psContext,
    403                              void               *pHwRef,
    404                              uint8_t            *pEvent,
    405                              uint8_t            length
    406                        )
    407 {
    408     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    409     phHciNfc_sContext_t         *psHciContext =
    410                                 (phHciNfc_sContext_t *)psContext ;
    411     return status;
    412 }
    413 #endif /* #ifdef CE_A_SEND_EVENT */
    414 
    415 static
    416 NFCSTATUS
    417 phHciNfc_Recv_CE_A_Response(
    418                              void               *psContext,
    419                              void               *pHwRef,
    420                              uint8_t            *pResponse,
    421 #ifdef ONE_BYTE_LEN
    422                              uint8_t            length
    423 #else
    424                              uint16_t           length
    425 #endif
    426                        )
    427 {
    428     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    429     phHciNfc_sContext_t         *psHciContext =
    430                                 (phHciNfc_sContext_t *)psContext ;
    431     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse)
    432         || (length == 0))
    433     {
    434         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    435     }
    436     else if(NULL == psHciContext->p_ce_a_info)
    437     {
    438         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    439     }
    440     else
    441     {
    442         phHciNfc_CE_A_Info_t         *ps_ce_a_info=NULL;
    443         uint8_t                     prev_cmd = ANY_GET_PARAMETER;
    444         ps_ce_a_info = (phHciNfc_CE_A_Info_t *)
    445                             psHciContext->p_ce_a_info ;
    446         if( NULL == ps_ce_a_info->p_pipe_info)
    447         {
    448             status = PHNFCSTVAL(CID_NFC_HCI,
    449                             NFCSTATUS_INVALID_HCI_SEQUENCE);
    450         }
    451         else
    452         {
    453             prev_cmd = ps_ce_a_info->p_pipe_info->prev_msg ;
    454             switch(prev_cmd)
    455             {
    456                 case ANY_GET_PARAMETER:
    457                 {
    458 #if 0
    459                     status = phHciNfc_CE_A_InfoUpdate(psHciContext,
    460                                     ps_ce_a_info->p_pipe_info->reg_index,
    461                                     &pResponse[HCP_HEADER_LEN],
    462                                     (length - HCP_HEADER_LEN));
    463 #endif /* #if 0 */
    464                     break;
    465                 }
    466                 case ANY_SET_PARAMETER:
    467                 {
    468                     HCI_PRINT("CE A Parameter Set \n");
    469                     break;
    470                 }
    471                 case ANY_OPEN_PIPE:
    472                 {
    473                     HCI_PRINT("CE A open pipe complete\n");
    474                     break;
    475                 }
    476                 case ANY_CLOSE_PIPE:
    477                 {
    478                     HCI_PRINT("CE A close pipe complete\n");
    479                     break;
    480                 }
    481                 default:
    482                 {
    483                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE);
    484                     break;
    485                 }
    486             }
    487             if( NFCSTATUS_SUCCESS == status )
    488             {
    489                 status = phHciNfc_CE_A_Update_Seq(psHciContext,
    490                                                     UPDATE_SEQ);
    491                 ps_ce_a_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
    492             }
    493         }
    494     }
    495     return status;
    496 }
    497 
    498 NFCSTATUS
    499 phHciNfc_CE_A_Update_Seq(
    500                         phHciNfc_sContext_t     *psHciContext,
    501                         phHciNfc_eSeqType_t     seq_type
    502                     )
    503 {
    504     phHciNfc_CE_A_Info_t    *ps_ce_a_info=NULL;
    505     NFCSTATUS               status = NFCSTATUS_SUCCESS;
    506 
    507     if( NULL == psHciContext )
    508     {
    509         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    510     }
    511     else if( NULL == psHciContext->p_ce_a_info )
    512     {
    513         status = PHNFCSTVAL(CID_NFC_HCI,
    514                             NFCSTATUS_FEATURE_NOT_SUPPORTED);
    515     }
    516     else
    517     {
    518         ps_ce_a_info = (phHciNfc_CE_A_Info_t *)
    519                         psHciContext->p_ce_a_info ;
    520         switch(seq_type)
    521         {
    522             case RESET_SEQ:
    523             case INIT_SEQ:
    524             {
    525                 ps_ce_a_info->next_seq = HOST_CE_A_PIPE_OPEN;
    526                 ps_ce_a_info->current_seq = HOST_CE_A_PIPE_OPEN;
    527                 break;
    528             }
    529             case UPDATE_SEQ:
    530             {
    531                 ps_ce_a_info->current_seq = ps_ce_a_info->next_seq;
    532                 break;
    533             }
    534             case INFO_SEQ:
    535             {
    536                 break;
    537             }
    538             case REL_SEQ:
    539             {
    540                 ps_ce_a_info->next_seq = HOST_CE_A_DISABLE_SEQ;
    541                 ps_ce_a_info->current_seq = HOST_CE_A_DISABLE_SEQ;
    542                 break;
    543             }
    544             default:
    545             {
    546                 break;
    547             }
    548         }
    549     }
    550     return status;
    551 }
    552 
    553 
    554 NFCSTATUS
    555 phHciNfc_CE_A_Mode(
    556                             void        *psHciHandle,
    557                             void        *pHwRef,
    558                             uint8_t     enable_type
    559                   )
    560 {
    561     NFCSTATUS               status = NFCSTATUS_SUCCESS;
    562     static uint8_t          param = 0 ;
    563     phHciNfc_sContext_t     *psHciContext = ((phHciNfc_sContext_t *)psHciHandle);
    564 
    565     if((NULL == psHciContext)||(NULL == pHwRef))
    566     {
    567         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    568     }
    569     else if(NULL == psHciContext->p_ce_a_info)
    570     {
    571         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    572     }
    573     else
    574     {
    575         phHciNfc_CE_A_Info_t     *ps_ce_a_info = (phHciNfc_CE_A_Info_t *)
    576                                                 psHciContext->p_ce_a_info ;
    577         phHciNfc_Pipe_Info_t     *p_pipe_info = ps_ce_a_info->p_pipe_info;
    578 
    579         if (NULL != p_pipe_info)
    580         {
    581             p_pipe_info->reg_index = HOST_CE_A_MODE_INDEX;
    582             /* Enable/Disable Host Card Emulation A */
    583             param = (uint8_t)enable_type;
    584             p_pipe_info->param_info =(void*)&param ;
    585             p_pipe_info->param_length = sizeof(param) ;
    586             status = phHciNfc_Send_Generic_Cmd(psHciContext,pHwRef,
    587                                     ps_ce_a_info->pipe_id,(uint8_t)ANY_SET_PARAMETER);
    588         }
    589         else
    590         {
    591             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_HCI_GATE_NOT_SUPPORTED);
    592         }
    593     }
    594     return status;
    595 }
    596 
    597 
    598 
    599 static
    600 NFCSTATUS
    601 phHciNfc_Recv_CE_A_Event(
    602                              void               *psContext,
    603                              void               *pHwRef,
    604                              uint8_t            *pEvent,
    605 #ifdef ONE_BYTE_LEN
    606                              uint8_t            length
    607 #else
    608                              uint16_t           length
    609 #endif
    610                        )
    611 {
    612     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    613     phHciNfc_sContext_t         *psHciContext =
    614                                 (phHciNfc_sContext_t *)psContext ;
    615     if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent)
    616         || (length == 0))
    617     {
    618         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    619     }
    620     else if(NULL == psHciContext->p_ce_a_info)
    621     {
    622         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    623     }
    624     else
    625     {
    626         phHciNfc_HCP_Packet_t       *p_packet = NULL;
    627         phHciNfc_CE_A_Info_t         *ps_ce_a_info=NULL;
    628         phHciNfc_HCP_Message_t      *message = NULL;
    629         static phHal_sEventInfo_t   event_info;
    630         uint8_t                     instruction=0;
    631 
    632         ps_ce_a_info = (phHciNfc_CE_A_Info_t *)
    633                         psHciContext->p_ce_a_info ;
    634 
    635         /* Variable was set but never used (ARM warning) */
    636         PHNFC_UNUSED_VARIABLE(ps_ce_a_info);
    637 
    638         p_packet = (phHciNfc_HCP_Packet_t *)pEvent;
    639         message = &p_packet->msg.message;
    640         /* Get the instruction bits from the Message Header */
    641         instruction = (uint8_t) GET_BITS8( message->msg_header,
    642                                 HCP_MSG_INSTRUCTION_OFFSET,
    643                                 HCP_MSG_INSTRUCTION_LEN);
    644         psHciContext->host_rf_type = phHal_eISO14443_A_PICC;
    645         event_info.eventHost = phHal_eHostController;
    646         event_info.eventSource = phHal_eISO14443_A_PICC;
    647         switch(instruction)
    648         {
    649             case CE_A_EVT_NFC_ACTIVATED:
    650             {
    651                 event_info.eventType = NFC_EVT_ACTIVATED;
    652                 /* Notify to the HCI Generic layer To Update the FSM */
    653                 break;
    654             }
    655             case CE_A_EVT_NFC_DEACTIVATED:
    656             {
    657                 event_info.eventType = NFC_EVT_DEACTIVATED;
    658                 HCI_PRINT("CE A Target Deactivated\n");
    659                 break;
    660             }
    661             case CE_A_EVT_NFC_SEND_DATA:
    662             {
    663                 HCI_PRINT("CE A data is received from the PN544\n");
    664 #if defined (SEND_DATA_EVENT)
    665                 if(length > HCP_HEADER_LEN)
    666                 {
    667                     status = phHciNfc_CE_A_ProcessData(
    668                                             psHciContext, pHwRef,
    669                                             &pEvent[HCP_HEADER_LEN],
    670                                             (length - HCP_HEADER_LEN));
    671                 }
    672                 else
    673                 {
    674                     status = PHNFCSTVAL(CID_NFC_HCI,
    675                                     NFCSTATUS_INVALID_HCI_RESPONSE);
    676                 }
    677 #endif /* #if defined (SEND_DATA_EVENT) */
    678                 break;
    679             }
    680             case CE_A_EVT_NFC_FIELD_ON:
    681             {
    682                 HCI_PRINT("CE A field on\n");
    683                 event_info.eventType = NFC_EVT_FIELD_ON;
    684                 break;
    685             }
    686             case CE_A_EVT_NFC_FIELD_OFF:
    687             {
    688                 HCI_PRINT("CE A field off\n");
    689                 event_info.eventType = NFC_EVT_FIELD_OFF;
    690                 break;
    691             }
    692             default:
    693             {
    694                 status = PHNFCSTVAL(CID_NFC_HCI,
    695                                     NFCSTATUS_INVALID_HCI_INSTRUCTION);
    696                 break;
    697             }
    698         }
    699         if(NFCSTATUS_SUCCESS == status)
    700         {
    701             phHciNfc_Notify_Event(psHciContext, pHwRef,
    702                                     NFC_NOTIFY_EVENT,
    703                                     &event_info);
    704         }
    705     }
    706     return status;
    707 }
    708 
    709 #if defined (SEND_DATA_EVENT)
    710 static
    711 NFCSTATUS
    712 phHciNfc_CE_A_ProcessData(
    713                             phHciNfc_sContext_t     *psHciContext,
    714                             void                    *pHwRef,
    715                             uint8_t                 *pData,
    716                             uint8_t                 length
    717                        )
    718 {
    719     NFCSTATUS       status = NFCSTATUS_SUCCESS;
    720 
    721     static uint8_t  send_data[] = {0x6D, 0x80};
    722     status = phHciNfc_CE_A_SendData_Event(
    723                              (void *)psHciContext, pHwRef,
    724                              send_data, sizeof(send_data));
    725 
    726     return status;
    727 }
    728 #endif /* #if defined (SEND_DATA_EVENT) */
    729 
    730 #endif /* #if defined (HOST_EMULATION) */
    731 
    732 
    733