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_DevMgmt.c                                                   *
     23 * \brief HCI PN544 Device Management Gate Routines.                           *
     24 *                                                                             *
     25 *                                                                             *
     26 * Project: NFC-FRI-1.1                                                        *
     27 *                                                                             *
     28 * $Date: Fri Mar 12 10:21:54 2010 $                                           *
     29 * $Author: ing04880 $                                                         *
     30 * $Revision: 1.29 $                                                            *
     31 * $Aliases: NFC_FRI1.1_WK1007_R33_3,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 $                                                                *
     32 *                                                                             *
     33 * =========================================================================== *
     34 */
     35 
     36 /*
     37 ***************************** Header File Inclusion ****************************
     38 */
     39 #include <phNfcConfig.h>
     40 #include <phNfcCompId.h>
     41 #include <phHciNfc_Pipe.h>
     42 #include <phHciNfc_DevMgmt.h>
     43 #include <phHciNfc_Emulation.h>
     44 #include <phOsalNfc.h>
     45 
     46 /*
     47 ****************************** Macro Definitions *******************************
     48 */
     49 
     50 /*  Commands for System Management module */
     51 #define NXP_RF_CHECK_SETTINGS   0x10U
     52 #define NXP_RF_UPDATE_SETTINGS  0x11U
     53 
     54 /* Self Test Commands */
     55 #define NXP_SELF_TEST_ANTENNA   0x20U
     56 #define NXP_SELF_TEST_SWP       0x21U
     57 #define NXP_SELF_TEST_NFCWI     0x22U
     58 #define NXP_SELF_TEST_PRBS      0x25U
     59 
     60 /* System Management propreitary control */
     61 #define NXP_DBG_READ            0x3EU
     62 #define NXP_DBG_WRITE           0x3FU
     63 
     64 /* System Management Events */
     65 #define NXP_EVT_SET_AUTONOMOUS   0x01U
     66 #define NXP_EVT_CLF_WAKEUP       0x02U
     67 
     68 /* System Management Information Events */
     69 #define NXP_EVT_INFO_TXLDO_OVERCUR   0x10U
     70 #define NXP_EVT_INFO_PMUVCC          0x11U
     71 #define NXP_EVT_INFO_EXT_RF_FIELD    0x12U
     72 #define NXP_EVT_INFO_MEM_VIOLATION   0x13U
     73 #define NXP_EVT_INFO_TEMP_OVERHEAT   0x14U
     74 #define NXP_EVT_INFO_LLC_ERROR       0x15U
     75 
     76 #define NFC_DEV_TXLDO_MASK           0x03U
     77 
     78 
     79 /*
     80 *************************** Structure and Enumeration ***************************
     81 */
     82 
     83 
     84 /** \defgroup grp_hci_nfc HCI PN544 Device Management Component
     85  *
     86  *
     87  */
     88 
     89 typedef enum phHciNfc_DevMgmt_Seq{
     90     DEV_MGMT_PIPE_OPEN      = 0x00U,
     91     DEV_MGMT_SET_PWR_STATUS,
     92     DEV_MGMT_SET_INFO_EVT,
     93     DEV_MGMT_GET_EEPROM_INFO,
     94     DEV_MGMT_GPIO_PDIR,
     95     DEV_MGMT_GPIO_PEN,
     96     DEV_MGMT_TX_LDO,
     97     DEV_MGMT_IFC_TO_RX_H,
     98     DEV_MGMT_IFC_TO_RX_L,
     99     DEV_MGMT_IFC_TO_TX_H,
    100     DEV_MGMT_IFC_TO_TX_L,
    101     DEV_MGMT_ANAIRQ_CONF,
    102     DEV_MGMT_PMOS_MOD,
    103     DEV_MGMT_CLK_REQ,
    104     DEV_MGMT_INPUT_CLK,
    105     DEV_MGMT_UICC_PWR_REQUEST,
    106     DEV_MGMT_ACTIVE_GUARD_TO,
    107     DEV_MGMT_MAX_ACT_TO_LOW,
    108     DEV_MGMT_MAX_ACT_TO_HIGH,
    109     DEV_MGMT_UICC_CE_A_ACCESS,
    110     DEV_MGMT_UICC_CE_B_ACCESS,
    111     DEV_MGMT_UICC_CE_BP_ACCESS,
    112     DEV_MGMT_UICC_CE_F_ACCESS,
    113     DEV_MGMT_UICC_RD_A_ACCESS,
    114     DEV_MGMT_UICC_RD_B_ACCESS,
    115     DEV_MGMT_UICC_BIT_RATE,
    116     DEV_MGMT_UICC_RX_ERR_CNT,
    117     DEV_MGMT_UICC_TX_ERR_CNT,
    118     DEV_MGMT_LLC_GRD_TO_H,
    119     DEV_MGMT_LLC_GRD_TO_L,
    120     DEV_MGMT_LLC_ACK_TO_H,
    121     DEV_MGMT_LLC_ACK_TO_L,
    122     DEV_MGMT_EVT_AUTONOMOUS,
    123     DEV_MGMT_PIPE_CLOSE
    124 } phHciNfc_DevMgmt_Seq_t;
    125 
    126 
    127 typedef struct phHciNfc_DevMgmt_Info{
    128     phHciNfc_DevMgmt_Seq_t  current_seq;
    129     phHciNfc_DevMgmt_Seq_t  next_seq;
    130     phHciNfc_Pipe_Info_t    *p_pipe_info;
    131     uint8_t                 test_status;
    132     uint8_t                 value;
    133     uint8_t                 rf_status;
    134     uint8_t                 pmuvcc_status;
    135     uint8_t                 overheat_status;
    136     uint8_t                 *p_val;
    137     uint8_t                 eeprom_crc;
    138     phNfc_sData_t           test_result;
    139 
    140 } phHciNfc_DevMgmt_Info_t;
    141 
    142 
    143 /*
    144 *************************** Static Function Declaration **************************
    145 */
    146 
    147 static
    148 NFCSTATUS
    149 phHciNfc_DevMgmt_InfoUpdate(
    150                                 phHciNfc_sContext_t     *psHciContext,
    151                                 phHal_sHwReference_t    *pHwRef,
    152                                 uint8_t                 index,
    153                                 uint8_t                 *reg_value,
    154                                 uint8_t                 reg_length
    155                          );
    156 
    157 static
    158 NFCSTATUS
    159 phHciNfc_Recv_DevMgmt_Response(
    160                         void                *psHciContext,
    161                         void                *pHwRef,
    162                         uint8_t             *pResponse,
    163 #ifdef ONE_BYTE_LEN
    164                         uint8_t             length
    165 #else
    166                         uint16_t            length
    167 #endif
    168                        );
    169 
    170 static
    171 NFCSTATUS
    172 phHciNfc_Recv_DevMgmt_Event(
    173                         void                *psContext,
    174                         void                *pHwRef,
    175                         uint8_t             *pEvent,
    176 #ifdef ONE_BYTE_LEN
    177                         uint8_t             length
    178 #else
    179                         uint16_t            length
    180 #endif
    181                     );
    182 
    183 
    184 static
    185 NFCSTATUS
    186 phHciNfc_Send_DevMgmt_Command (
    187                             phHciNfc_sContext_t *psHciContext,
    188                             void                *pHwRef,
    189                             uint8_t             pipe_id,
    190                             uint8_t             cmd
    191                 );
    192 
    193 static
    194  NFCSTATUS
    195  phHciNfc_Send_DevMgmt_Event (
    196                                 phHciNfc_sContext_t *psHciContext,
    197                                 void                *pHwRef,
    198                                 uint8_t             pipe_id,
    199                                 uint8_t             event
    200                     );
    201 
    202 /*
    203 *************************** Function Definitions ***************************
    204 */
    205 
    206 
    207 NFCSTATUS
    208 phHciNfc_DevMgmt_Init_Resources(
    209                            phHciNfc_sContext_t  *psHciContext
    210                           )
    211 {
    212     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    213     phHciNfc_DevMgmt_Info_t          *p_device_mgmt_info=NULL;
    214 
    215     if( NULL == psHciContext )
    216     {
    217         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    218     }
    219     else
    220     {
    221         if(( NULL == psHciContext->p_device_mgmt_info ) &&
    222              (phHciNfc_Allocate_Resource((void **)(&p_device_mgmt_info),
    223             sizeof(phHciNfc_DevMgmt_Info_t))== NFCSTATUS_SUCCESS))
    224         {
    225             psHciContext->p_device_mgmt_info = p_device_mgmt_info;
    226             p_device_mgmt_info->current_seq = DEV_MGMT_PIPE_OPEN;
    227             p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN;
    228             p_device_mgmt_info->p_pipe_info = NULL;
    229         }
    230         else
    231         {
    232             status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
    233         }
    234     }
    235     return status;
    236 }
    237 
    238 
    239 NFCSTATUS
    240 phHciNfc_DevMgmt_Get_PipeID(
    241                             phHciNfc_sContext_t        *psHciContext,
    242                             uint8_t                    *ppipe_id
    243                             )
    244 {
    245     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    246 
    247     if( (NULL != psHciContext)
    248         && ( NULL != ppipe_id )
    249         && ( NULL != psHciContext->p_device_mgmt_info )
    250         )
    251     {
    252         phHciNfc_Pipe_Info_t     *p_pipe_info = NULL;
    253         p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
    254             psHciContext->p_device_mgmt_info)->p_pipe_info ;
    255         if (NULL != p_pipe_info)
    256         {
    257             *ppipe_id = p_pipe_info->pipe.pipe_id ;
    258         }
    259         else
    260         {
    261             *ppipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
    262         }
    263 
    264     }
    265     else
    266     {
    267         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
    268     }
    269     return status;
    270 }
    271 
    272 
    273 NFCSTATUS
    274 phHciNfc_DevMgmt_Get_Test_Result(
    275                                 phHciNfc_sContext_t        *psHciContext,
    276                                 phNfc_sData_t              *p_test_result
    277                             )
    278 {
    279     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    280 
    281     if( (NULL != psHciContext)
    282         && ( NULL != p_test_result )
    283         && ( NULL != psHciContext->p_device_mgmt_info )
    284         )
    285     {
    286         phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
    287         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
    288                                 psHciContext->p_device_mgmt_info ;
    289         p_test_result->buffer = p_device_mgmt_info->test_result.buffer;
    290         p_test_result->length = p_device_mgmt_info->test_result.length;
    291 
    292     }
    293     else
    294     {
    295         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
    296     }
    297 
    298     return status;
    299 }
    300 
    301 
    302 NFCSTATUS
    303 phHciNfc_DevMgmt_Set_Test_Result(
    304                                 phHciNfc_sContext_t        *psHciContext,
    305                                 uint8_t                    test_status
    306                             )
    307 {
    308     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    309 
    310     if( (NULL != psHciContext)
    311         && ( NULL != psHciContext->p_device_mgmt_info )
    312         )
    313     {
    314         phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
    315         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
    316                                 psHciContext->p_device_mgmt_info ;
    317         p_device_mgmt_info->test_status = test_status;
    318 
    319     }
    320     else
    321     {
    322         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
    323     }
    324 
    325     return status;
    326 }
    327 
    328 
    329 
    330 NFCSTATUS
    331 phHciNfc_DevMgmt_Update_PipeInfo(
    332                                   phHciNfc_sContext_t     *psHciContext,
    333                                   uint8_t                 pipeID,
    334                                   phHciNfc_Pipe_Info_t    *pPipeInfo
    335                            )
    336 {
    337     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    338 
    339     if( NULL == psHciContext )
    340     {
    341         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    342     }
    343     else if(NULL == psHciContext->p_device_mgmt_info)
    344     {
    345         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
    346     }
    347     else
    348     {
    349         phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
    350         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
    351                                 psHciContext->p_device_mgmt_info ;
    352         /* Update the pipe_info of the Device Management Gate obtained
    353          * from HCI Response */
    354         p_device_mgmt_info->p_pipe_info = pPipeInfo;
    355         if (( NULL != pPipeInfo)
    356             && ((uint8_t)HCI_UNKNOWN_PIPE_ID != pipeID)
    357             )
    358         {
    359             /* Update the Response Receive routine of the Device
    360              * Managment Gate */
    361             pPipeInfo->recv_resp = &phHciNfc_Recv_DevMgmt_Response;
    362             pPipeInfo->recv_event = &phHciNfc_Recv_DevMgmt_Event;
    363         }
    364     }
    365 
    366     return status;
    367 }
    368 
    369 
    370  NFCSTATUS
    371  phHciNfc_DevMgmt_Configure (
    372                                 phHciNfc_sContext_t *psHciContext,
    373                                 void                *pHwRef,
    374                                 uint16_t            address,
    375                                 uint8_t             value
    376                     )
    377 {
    378     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    379     phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
    380     uint8_t                     pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
    381     uint8_t                     i=0;
    382     uint8_t                     params[5];
    383 
    384     if( (NULL == psHciContext) || (NULL == pHwRef) )
    385     {
    386       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    387     }
    388     else if(  NULL == psHciContext->p_device_mgmt_info )
    389     {
    390         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
    391     }
    392     else
    393     {
    394         p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
    395                        psHciContext->p_device_mgmt_info)->p_pipe_info ;
    396 
    397         if(NULL == p_pipe_info )
    398         {
    399             status = PHNFCSTVAL(CID_NFC_HCI,
    400                             NFCSTATUS_INVALID_HCI_SEQUENCE);
    401         }
    402         else
    403         {
    404             pipe_id = p_pipe_info->pipe.pipe_id ;
    405             params[i++] = 0x00;
    406             params[i++] = (uint8_t)(address >> BYTE_SIZE);
    407             params[i++] = (uint8_t)address;
    408             params[i++] = value;
    409             p_pipe_info->param_info = &params;
    410             p_pipe_info->param_length = i ;
    411             status = phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef,
    412                                                 pipe_id, (uint8_t)NXP_DBG_WRITE );
    413         }
    414     }
    415     return status;
    416 }
    417 
    418 
    419  NFCSTATUS
    420  phHciNfc_DevMgmt_Get_Info (
    421                                 phHciNfc_sContext_t *psHciContext,
    422                                 void                *pHwRef,
    423                                 uint16_t            address,
    424                                 uint8_t             *p_val
    425                     )
    426 {
    427     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
    428     phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
    429     uint8_t                     pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
    430     uint8_t                     i=0;
    431     uint8_t                     params[5];
    432 
    433     if( (NULL == psHciContext) || (NULL == pHwRef) )
    434     {
    435       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    436     }
    437     else if(  NULL == psHciContext->p_device_mgmt_info )
    438     {
    439         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
    440     }
    441     else
    442     {
    443         p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
    444                        psHciContext->p_device_mgmt_info)->p_pipe_info ;
    445 
    446         if(NULL == p_pipe_info )
    447         {
    448             status = PHNFCSTVAL(CID_NFC_HCI,
    449                             NFCSTATUS_INVALID_HCI_SEQUENCE);
    450         }
    451         else
    452         {
    453             ((phHciNfc_DevMgmt_Info_t *)
    454                     psHciContext->p_device_mgmt_info)->p_val = p_val;
    455             pipe_id = p_pipe_info->pipe.pipe_id ;
    456             params[i++] = 0x00;
    457             params[i++] = (uint8_t)(address >> BYTE_SIZE);
    458             params[i++] = (uint8_t) address;
    459             p_pipe_info->param_info = &params;
    460             p_pipe_info->param_length = i ;
    461             status = phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef,
    462                                             pipe_id, (uint8_t)NXP_DBG_READ );
    463         }
    464     }
    465     return status;
    466 
    467 }
    468 
    469 /*!
    470  * \brief Initialisation of PN544 Device Managment Gate.
    471  *
    472  * This function initialses the PN544 Device Management gate and
    473  * populates the PN544 Device Management Information Structure
    474  *
    475  */
    476 
    477 NFCSTATUS
    478 phHciNfc_DevMgmt_Initialise(
    479                                 phHciNfc_sContext_t     *psHciContext,
    480                                 void                    *pHwRef
    481                          )
    482 {
    483     NFCSTATUS                       status = NFCSTATUS_SUCCESS;
    484     phHciNfc_Pipe_Info_t            *p_pipe_info = NULL;
    485     phHciNfc_DevMgmt_Info_t         *p_device_mgmt_info=NULL;
    486     static uint8_t                   config = 0x10;
    487 
    488     if( ( NULL == psHciContext )
    489         || (NULL == pHwRef )
    490         )
    491     {
    492         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    493     }
    494     else if (NULL == psHciContext->p_device_mgmt_info)
    495     {
    496         status = PHNFCSTVAL(CID_NFC_HCI,
    497                     NFCSTATUS_INVALID_HCI_INFORMATION);
    498     }/* End of the PN544 Device Info Memory Check */
    499     else
    500     {
    501         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
    502                                 psHciContext->p_device_mgmt_info ;
    503         p_pipe_info = p_device_mgmt_info->p_pipe_info;
    504 
    505         if (NULL == p_pipe_info)
    506         {
    507             status = PHNFCSTVAL(CID_NFC_HCI,
    508                             NFCSTATUS_INVALID_HCI_SEQUENCE);
    509         }
    510         else
    511         {
    512             switch(p_device_mgmt_info->current_seq )
    513             {
    514                 /* PN544 Device Mgmt pipe open sequence */
    515                 case DEV_MGMT_PIPE_OPEN:
    516                 {
    517                     status = phHciNfc_Open_Pipe( psHciContext,
    518                                                     pHwRef, p_pipe_info );
    519                     if(status == NFCSTATUS_SUCCESS)
    520                     {
    521 
    522                         if ((HCI_SELF_TEST == psHciContext->init_mode )
    523                             || (HCI_NFC_DEVICE_TEST == psHciContext->init_mode ))
    524                         {
    525                             p_device_mgmt_info->next_seq =
    526                                                 DEV_MGMT_GPIO_PDIR;
    527                         }
    528                         else
    529                         {
    530                             p_device_mgmt_info->next_seq =
    531                                                 DEV_MGMT_GET_EEPROM_INFO;
    532                         }
    533                         status = NFCSTATUS_PENDING;
    534                     }
    535                     break;
    536                 }
    537                 case DEV_MGMT_GET_EEPROM_INFO:
    538                 {
    539                     p_pipe_info->reg_index = DEVICE_INFO_EEPROM_INDEX;
    540                     status = phHciNfc_Send_Generic_Cmd( psHciContext,
    541                             pHwRef, (uint8_t)p_pipe_info->pipe.pipe_id,
    542                                 (uint8_t)ANY_GET_PARAMETER);
    543                     if(NFCSTATUS_PENDING == status )
    544                     {
    545 #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 )
    546                         p_device_mgmt_info->next_seq =
    547                                                 DEV_MGMT_IFC_TO_TX_H;
    548 #else
    549                         p_device_mgmt_info->next_seq =
    550                                         DEV_MGMT_TX_LDO;
    551 #endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */
    552                     }
    553                     break;
    554                 }
    555                 case DEV_MGMT_GPIO_PDIR:
    556                 {
    557                     config = 0x00;
    558                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    559                             NFC_ADDRESS_GPIO_PDIR , config );
    560                     if(NFCSTATUS_PENDING == status )
    561                     {
    562                         p_device_mgmt_info->next_seq =
    563                                                 DEV_MGMT_GPIO_PEN;
    564                     }
    565                     break;
    566                 }
    567                 case DEV_MGMT_GPIO_PEN:
    568                 {
    569                     config = NXP_NFC_GPIO_MASK(NXP_DOWNLOAD_GPIO)| 0x03 ;
    570                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    571                             NFC_ADDRESS_GPIO_PEN , config );
    572                     if(NFCSTATUS_PENDING == status )
    573                     {
    574 #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 )
    575                         p_device_mgmt_info->next_seq =
    576                                                 DEV_MGMT_IFC_TO_TX_H;
    577 #else
    578                         p_device_mgmt_info->next_seq =
    579                                                 DEV_MGMT_TX_LDO;
    580 #endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */
    581                     }
    582                     break;
    583                 }
    584 
    585 #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 )
    586 
    587                 case DEV_MGMT_IFC_TO_TX_H:
    588                 {
    589                     config =  (uint8_t)
    590                         ( NXP_NFC_IFC_CONFIG_DEFAULT >> BYTE_SIZE ) /* 0x03 */;
    591                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    592                         NFC_ADDRESS_IFC_TO_TX_H , config );
    593                     if(NFCSTATUS_PENDING == status )
    594                     {
    595                         p_device_mgmt_info->next_seq =
    596                                                 DEV_MGMT_IFC_TO_TX_L;
    597                     }
    598                     break;
    599                 }
    600                 case DEV_MGMT_IFC_TO_TX_L:
    601                 {
    602                     config = (uint8_t)
    603                         ( NXP_NFC_IFC_CONFIG_DEFAULT & BYTE_MASK ) /* 0xE8 */;
    604                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    605                             NFC_ADDRESS_IFC_TO_TX_L , config );
    606                     if(NFCSTATUS_PENDING == status )
    607                     {
    608 #if  ( NXP_NFC_IFC_TIMEOUT & 0x02 )
    609                         p_device_mgmt_info->next_seq =
    610                                                 DEV_MGMT_IFC_TO_RX_H;
    611 #else
    612                         p_device_mgmt_info->next_seq =
    613                                                 DEV_MGMT_TX_LDO;
    614 #endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x02 ) */
    615                     }
    616                     break;
    617                 }
    618                 case DEV_MGMT_IFC_TO_RX_H:
    619                 {
    620                     config = 0x10;
    621                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    622                             NFC_ADDRESS_IFC_TO_RX_H , config );
    623                     if(NFCSTATUS_PENDING == status )
    624                     {
    625                         p_device_mgmt_info->next_seq =
    626                                                 DEV_MGMT_IFC_TO_RX_L;
    627                     }
    628                     break;
    629                 }
    630                 case DEV_MGMT_IFC_TO_RX_L:
    631                 {
    632                     config = 0x1E;
    633                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    634                             NFC_ADDRESS_IFC_TO_RX_L , config );
    635                     if(NFCSTATUS_PENDING == status )
    636                     {
    637                         p_device_mgmt_info->next_seq =
    638                                                 DEV_MGMT_TX_LDO;
    639                     }
    640                     break;
    641                 }
    642 
    643 #endif /* #if  ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */
    644                 case DEV_MGMT_TX_LDO:
    645                 {
    646 #if ( NXP_HAL_VERIFY_EEPROM_CRC & 0x01U )
    647                     if (0 != p_device_mgmt_info->eeprom_crc)
    648                     {
    649                         status = NFCSTATUS_FAILED;
    650                     }
    651                     else
    652 #endif
    653                     {
    654                        config = (NFC_DEV_HWCONF_DEFAULT |
    655                                     (NXP_DEFAULT_TX_LDO & NFC_DEV_TXLDO_MASK));
    656                        status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    657                             NFC_ADDRESS_HW_CONF , config );
    658                        if(NFCSTATUS_PENDING == status )
    659                        {
    660 #if ( SW_TYPE_RF_TUNING_BF & 0x01)
    661                            p_device_mgmt_info->next_seq = DEV_MGMT_ANAIRQ_CONF;
    662 #else
    663                            p_device_mgmt_info->next_seq = DEV_MGMT_CLK_REQ;
    664 #endif
    665                            /* status = NFCSTATUS_SUCCESS; */
    666                        }
    667                     }
    668                     break;
    669                 }
    670 #if ( SW_TYPE_RF_TUNING_BF & 0x01)
    671                 /* The Analogue IRQ Configuartion */
    672                 case DEV_MGMT_ANAIRQ_CONF:
    673                 {
    674                     config = 0x04;
    675                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    676                             NFC_ADDRESS_ANAIRQ_CONF , config );
    677                     if(NFCSTATUS_PENDING == status )
    678                     {
    679                         p_device_mgmt_info->next_seq =
    680                                                 DEV_MGMT_PMOS_MOD;
    681                         /* status = NFCSTATUS_SUCCESS; */
    682                     }
    683                     break;
    684                 }
    685                 /* The PMOS Modulation Index */
    686                 case DEV_MGMT_PMOS_MOD:
    687                 {
    688                     config = NFC_DEV_PMOS_MOD_DEFAULT;
    689                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    690                             NFC_ADDRESS_PMOS_MOD , config );
    691                     if(NFCSTATUS_PENDING == status )
    692                     {
    693                         p_device_mgmt_info->next_seq =
    694                                                 DEV_MGMT_CLK_REQ;
    695                         /* status = NFCSTATUS_SUCCESS; */
    696                     }
    697                     break;
    698                 }
    699 #endif /* #if ( SW_TYPE_RF_TUNING_BF & 0x01) */
    700                 case DEV_MGMT_CLK_REQ:
    701                 {
    702                     config = ((phHal_sHwConfig_t *)
    703                                     psHciContext->p_config_params)->clk_req ;
    704                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    705                             NFC_ADDRESS_CLK_REQ , config );
    706                     if(NFCSTATUS_PENDING == status )
    707                     {
    708                         p_device_mgmt_info->next_seq =
    709                                                 DEV_MGMT_INPUT_CLK;
    710                         /* status = NFCSTATUS_SUCCESS; */
    711                     }
    712                     break;
    713                 }
    714                 case DEV_MGMT_INPUT_CLK:
    715                 {
    716                     config = ((phHal_sHwConfig_t *)
    717                                     psHciContext->p_config_params)->input_clk;
    718                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    719                             NFC_ADDRESS_CLK_INPUT , config );
    720                     if(NFCSTATUS_PENDING == status )
    721                     {
    722                         p_device_mgmt_info->next_seq =
    723                                                 DEV_MGMT_UICC_PWR_REQUEST;
    724                     }
    725                     break;
    726                 }
    727                 case DEV_MGMT_UICC_PWR_REQUEST:
    728                 {
    729                     config = NXP_UICC_PWR_REQUEST;
    730                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    731                             NFC_ADDRESS_SWP_PWR_REQ , config );
    732                     if(NFCSTATUS_PENDING == status )
    733                     {
    734                         p_device_mgmt_info->next_seq =
    735                                                 DEV_MGMT_UICC_RD_A_ACCESS;
    736                     }
    737                     break;
    738                 }
    739                 case DEV_MGMT_UICC_RD_A_ACCESS:
    740                 {
    741 #if ( NXP_UICC_RD_RIGHTS & 0x01 )
    742                     config = (uint8_t) phHciNfc_RFReaderAGate;
    743 #else
    744                     config = 0xFFU;
    745 #endif /* #if ( NXP_UICC_RD_RIGHTS & 0x01 ) */
    746                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    747                             NFC_ADDRESS_UICC_RD_A_ACCESS , config );
    748                     if(NFCSTATUS_PENDING == status )
    749                     {
    750                         p_device_mgmt_info->next_seq =
    751                                                 DEV_MGMT_UICC_RD_B_ACCESS;
    752                     }
    753                     break;
    754                 }
    755                 case DEV_MGMT_UICC_RD_B_ACCESS:
    756                 {
    757 #if ( NXP_UICC_RD_RIGHTS & 0x02 )
    758                     config = (uint8_t) phHciNfc_RFReaderBGate;
    759 #else
    760                     config = 0xFFU;
    761 #endif /* #if ( NXP_UICC_RD_RIGHTS & 0x02 ) */
    762                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    763                             NFC_ADDRESS_UICC_RD_B_ACCESS , config );
    764                     if(NFCSTATUS_PENDING == status )
    765                     {
    766                         p_device_mgmt_info->next_seq =
    767                                                 DEV_MGMT_UICC_CE_A_ACCESS;
    768                     }
    769                     break;
    770                 }
    771                 case DEV_MGMT_UICC_CE_A_ACCESS:
    772                 {
    773 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x01 )
    774                     config = (uint8_t) phHciNfc_CETypeAGate;
    775 #else
    776                     config = 0xFFU;
    777 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x01 ) */
    778                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    779                             NFC_ADDRESS_UICC_CE_A_ACCESS , config );
    780                     if(NFCSTATUS_PENDING == status )
    781                     {
    782                         p_device_mgmt_info->next_seq =
    783                                                 DEV_MGMT_UICC_CE_B_ACCESS;
    784                     }
    785                     break;
    786                 }
    787                 case DEV_MGMT_UICC_CE_B_ACCESS:
    788                 {
    789 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x02 )
    790                     config = (uint8_t) phHciNfc_CETypeBGate;
    791 #else
    792                     config = 0xFFU;
    793 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x02 ) */
    794                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    795                             NFC_ADDRESS_UICC_CE_B_ACCESS , config );
    796                     if(NFCSTATUS_PENDING == status )
    797                     {
    798                         p_device_mgmt_info->next_seq =
    799                                                 DEV_MGMT_UICC_CE_BP_ACCESS;
    800                     }
    801                     break;
    802                 }
    803                 case DEV_MGMT_UICC_CE_BP_ACCESS:
    804                 {
    805 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x04 )
    806                     config = (uint8_t) phHciNfc_CETypeBPrimeGate;
    807 #else
    808                     config = 0xFFU;
    809 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x04 ) */
    810                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    811                             NFC_ADDRESS_UICC_CE_BP_ACCESS , config );
    812                     if(NFCSTATUS_PENDING == status )
    813                     {
    814                         p_device_mgmt_info->next_seq =
    815                                                 DEV_MGMT_UICC_CE_F_ACCESS;
    816                     }
    817                     break;
    818                 }
    819                 case DEV_MGMT_UICC_CE_F_ACCESS:
    820                 {
    821 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x08 )
    822                     config = (uint8_t) phHciNfc_CETypeFGate;
    823 #else
    824                     config = 0xFFU;
    825 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x08 ) */
    826                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    827                             NFC_ADDRESS_UICC_CE_F_ACCESS , config );
    828                     if(NFCSTATUS_PENDING == status )
    829                     {
    830                         p_device_mgmt_info->next_seq =
    831                                                 DEV_MGMT_UICC_BIT_RATE;
    832                     }
    833                     break;
    834                 }
    835                 case DEV_MGMT_UICC_BIT_RATE:
    836                 {
    837                     config = NXP_UICC_BIT_RATE;
    838                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    839                             NFC_ADDRESS_SWP_BITRATE , config );
    840                     if(NFCSTATUS_PENDING == status )
    841                     {
    842 #if defined (CFG_PWR_STATUS)
    843                         p_device_mgmt_info->next_seq =
    844                                                 DEV_MGMT_SET_PWR_STATUS;
    845 #else
    846                         p_device_mgmt_info->next_seq =
    847                                                 DEV_MGMT_SET_INFO_EVT;
    848 #endif
    849                     }
    850                     break;
    851                 }
    852 #ifdef CFG_PWR_STATUS
    853                 case DEV_MGMT_SET_PWR_STATUS:
    854                 {
    855                     config = NXP_SYSTEM_PWR_STATUS;
    856                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    857                             NFC_ADDRESS_PWR_STATUS , config );
    858                     if(NFCSTATUS_PENDING == status )
    859                     {
    860                         p_device_mgmt_info->next_seq =
    861                                                 DEV_MGMT_SET_INFO_EVT;
    862                     }
    863                     break;
    864                 }
    865 #endif
    866                 case DEV_MGMT_SET_INFO_EVT:
    867                 {
    868                     config = NXP_SYSTEM_EVT_INFO;
    869                     status = phHciNfc_Set_Param(psHciContext, pHwRef,
    870                                     p_pipe_info, DEVICE_INFO_EVT_INDEX,
    871                                     (uint8_t *)&config, sizeof(config) );
    872                     if(NFCSTATUS_PENDING == status )
    873                     {
    874 #if  ( HOST_LINK_TIMEOUT & 0x01 )
    875                         p_device_mgmt_info->next_seq =
    876                                                 DEV_MGMT_LLC_GRD_TO_H;
    877 #else
    878                         p_device_mgmt_info->next_seq =
    879                                                 DEV_MGMT_EVT_AUTONOMOUS;
    880                         status = NFCSTATUS_SUCCESS;
    881 #endif /* #if ( HOST_LINK_TIMEOUT & 0x01 ) */
    882                     }
    883                     break;
    884                 }
    885 #if  ( HOST_LINK_TIMEOUT & 0x01 )
    886 
    887                 case DEV_MGMT_LLC_GRD_TO_H:
    888                 {
    889                     config =(uint8_t)
    890                         ( NXP_NFC_LINK_GRD_CFG_DEFAULT >> BYTE_SIZE ) /* 0x00 */;
    891                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    892                             NFC_ADDRESS_LLC_GRD_TO_H , config );
    893                     if(NFCSTATUS_PENDING == status )
    894                     {
    895                         p_device_mgmt_info->next_seq =
    896                                                 DEV_MGMT_LLC_GRD_TO_L;
    897                     }
    898                     break;
    899                 }
    900                 case DEV_MGMT_LLC_GRD_TO_L:
    901                 {
    902                     config = (uint8_t)
    903                         ( NXP_NFC_LINK_GRD_CFG_DEFAULT & BYTE_MASK ) /* 0x32 */;
    904                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    905                             NFC_ADDRESS_LLC_GRD_TO_L , config );
    906                     if(NFCSTATUS_PENDING == status )
    907                     {
    908 #if  ( HOST_LINK_TIMEOUT & 0x02 )
    909                         p_device_mgmt_info->next_seq =
    910                                                 DEV_MGMT_LLC_ACK_TO_H;
    911 #else
    912                         p_device_mgmt_info->next_seq =
    913                                                 DEV_MGMT_EVT_AUTONOMOUS;
    914                         status = NFCSTATUS_SUCCESS;
    915 #endif /* #if ( HOST_LINK_TIMEOUT & 0x02 ) */
    916                     }
    917                     break;
    918                 }
    919                 case DEV_MGMT_LLC_ACK_TO_H:
    920                 {
    921                     config = (uint8_t)
    922                         ( NXP_NFC_LINK_ACK_CFG_DEFAULT >> BYTE_SIZE )/* 0x00 */;
    923                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    924                             NFC_ADDRESS_LLC_ACK_TO_H , config );
    925                     if(NFCSTATUS_PENDING == status )
    926                     {
    927                         p_device_mgmt_info->next_seq =
    928                                                 DEV_MGMT_LLC_ACK_TO_L;
    929                     }
    930                     break;
    931                 }
    932                 case DEV_MGMT_LLC_ACK_TO_L:
    933                 {
    934                     config = (uint8_t)
    935                         ( NXP_NFC_LINK_ACK_CFG_DEFAULT & BYTE_MASK ) /* 0x00 */;;
    936                     status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef,
    937                             NFC_ADDRESS_LLC_ACK_TO_L , config );
    938                     if(NFCSTATUS_PENDING == status )
    939                     {
    940                         p_device_mgmt_info->next_seq =
    941                                                 DEV_MGMT_EVT_AUTONOMOUS;
    942                         status = NFCSTATUS_SUCCESS;
    943                     }
    944                     break;
    945                 }
    946 
    947 #endif /* #if ( HOST_LINK_TIMEOUT & 0x01 ) */
    948                 default:
    949                 {
    950                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
    951                     break;
    952                 }
    953 
    954             }/* End of the Sequence Switch */
    955         }
    956 
    957     } /* End of Null Context Check */
    958 
    959     return status;
    960 }
    961 
    962 /*!
    963  * \brief Releases the resources allocated the PN544 Device Management.
    964  *
    965  * This function Releases the resources allocated the PN544 Device Management
    966  * and resets the hardware to the reset state.
    967  */
    968 
    969 NFCSTATUS
    970 phHciNfc_DevMgmt_Release(
    971                                 phHciNfc_sContext_t     *psHciContext,
    972                                 void                    *pHwRef
    973                              )
    974 {
    975     NFCSTATUS                           status = NFCSTATUS_SUCCESS;
    976     phHciNfc_Pipe_Info_t                *p_pipe_info = NULL;
    977     phHciNfc_DevMgmt_Info_t         *p_device_mgmt_info=NULL;
    978 
    979     if( (NULL == psHciContext) || (NULL == pHwRef) )
    980     {
    981       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
    982     }
    983     else
    984     {
    985         if( NULL != psHciContext->p_device_mgmt_info )
    986         {
    987             p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
    988                                 psHciContext->p_device_mgmt_info ;
    989             switch(p_device_mgmt_info->current_seq)
    990             {
    991 
    992                 /* PN544 Device pipe close sequence */
    993                 case DEV_MGMT_EVT_AUTONOMOUS:
    994                 {
    995                     p_pipe_info = p_device_mgmt_info->p_pipe_info;
    996 
    997                     p_pipe_info->param_info = NULL;
    998                     p_pipe_info->param_length = HCP_ZERO_LEN;
    999 
   1000                     status = phHciNfc_Send_DevMgmt_Event(psHciContext, pHwRef,
   1001                                 p_pipe_info->pipe.pipe_id, NXP_EVT_SET_AUTONOMOUS);
   1002                     if(status == NFCSTATUS_PENDING)
   1003                     {
   1004                         p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN;
   1005                         status = NFCSTATUS_SUCCESS;
   1006                     }
   1007                     break;
   1008                 }
   1009                 /* PN544 Device pipe close sequence */
   1010                 case DEV_MGMT_PIPE_CLOSE:
   1011                 {
   1012                     p_pipe_info = p_device_mgmt_info->p_pipe_info;
   1013 
   1014                     status = phHciNfc_Close_Pipe( psHciContext,
   1015                                                         pHwRef, p_pipe_info );
   1016                     if(status == NFCSTATUS_SUCCESS)
   1017                     {
   1018                         p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN;
   1019                         /* status = NFCSTATUS_PENDING; */
   1020                     }
   1021                     break;
   1022                 }
   1023                 default:
   1024                 {
   1025                     status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE);
   1026                     break;
   1027                 }
   1028 
   1029             }/* End of the Sequence Switch */
   1030 
   1031         }/* End of the PN544 Device Info Memory Check */
   1032 
   1033     } /* End of Null Context Check */
   1034 
   1035     return status;
   1036 }
   1037 
   1038 NFCSTATUS
   1039 phHciNfc_DevMgmt_Update_Sequence(
   1040                                 phHciNfc_sContext_t     *psHciContext,
   1041                                 phHciNfc_eSeqType_t     DevMgmt_seq
   1042                              )
   1043 {
   1044     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1045     phHciNfc_DevMgmt_Info_t          *p_device_mgmt_info=NULL;
   1046     if( NULL == psHciContext )
   1047     {
   1048         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1049     }
   1050     else if ( NULL == psHciContext->p_device_mgmt_info )
   1051     {
   1052         status = PHNFCSTVAL(CID_NFC_HCI,
   1053                         NFCSTATUS_INVALID_HCI_INFORMATION);
   1054     }
   1055     else
   1056     {
   1057         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
   1058                             psHciContext->p_device_mgmt_info ;
   1059         switch(DevMgmt_seq)
   1060         {
   1061             case RESET_SEQ:
   1062             case INIT_SEQ:
   1063             {
   1064                 p_device_mgmt_info->current_seq = DEV_MGMT_PIPE_OPEN;
   1065                 p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN ;
   1066                 break;
   1067             }
   1068             case UPDATE_SEQ:
   1069             {
   1070                 p_device_mgmt_info->current_seq = p_device_mgmt_info->next_seq;
   1071 
   1072                 break;
   1073             }
   1074             case REL_SEQ:
   1075             {
   1076                 p_device_mgmt_info->current_seq = DEV_MGMT_EVT_AUTONOMOUS;
   1077                 p_device_mgmt_info->next_seq = DEV_MGMT_EVT_AUTONOMOUS ;
   1078                 break;
   1079             }
   1080             default:
   1081             {
   1082                 break;
   1083             }
   1084         }/* End of Update Sequence Switch */
   1085     }
   1086     return status;
   1087 
   1088 }
   1089 
   1090 
   1091 
   1092 /*!
   1093  * \brief Perform the System Management Tests
   1094  * provided by the corresponding peripheral device.
   1095  *
   1096  * This function performs the System Management Tests provided by the NFC
   1097  * Peripheral device.
   1098  */
   1099 
   1100 NFCSTATUS
   1101 phHciNfc_DevMgmt_Test(
   1102                     void                            *psContext,
   1103                     void                            *pHwRef,
   1104                     uint8_t                         test_type,
   1105                     phNfc_sData_t                   *test_param
   1106                  )
   1107 {
   1108     phHciNfc_sContext_t         *psHciContext =
   1109                                     (phHciNfc_sContext_t *)psContext ;
   1110     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1111     phHciNfc_Pipe_Info_t        *p_pipe_info = NULL;
   1112     uint8_t                     pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID;
   1113 
   1114     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1115     {
   1116       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1117     }
   1118     else if(  NULL == psHciContext->p_device_mgmt_info )
   1119     {
   1120         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
   1121     }
   1122     else
   1123     {
   1124         phHciNfc_DevMgmt_Info_t *p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
   1125                                         psHciContext->p_device_mgmt_info ;
   1126         p_pipe_info = ((phHciNfc_DevMgmt_Info_t *)
   1127                        psHciContext->p_device_mgmt_info)->p_pipe_info ;
   1128         switch(test_type)
   1129         {
   1130             case NXP_SELF_TEST_ANTENNA:
   1131             case NXP_SELF_TEST_SWP:
   1132             case NXP_SELF_TEST_PRBS:
   1133             /* case NXP_SELF_TEST_NFCWI: */
   1134             {
   1135                 if (NULL != p_pipe_info)
   1136                 {
   1137                     pipe_id = p_pipe_info->pipe.pipe_id ;
   1138                     if ( NULL != test_param )
   1139                     {
   1140                         p_pipe_info->param_info = test_param->buffer;
   1141                         p_pipe_info->param_length = (uint8_t)test_param->length;
   1142                     }
   1143                     p_device_mgmt_info->test_result.buffer = NULL;
   1144                     p_device_mgmt_info->test_result.length = 0;
   1145                     status =
   1146                         phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef,
   1147                             pipe_id, (uint8_t)test_type );
   1148                 }
   1149                 else
   1150                 {
   1151                     status = PHNFCSTVAL(CID_NFC_HCI,
   1152                                         NFCSTATUS_INVALID_HCI_INFORMATION);
   1153                 }
   1154                 break;
   1155             }
   1156             default:
   1157             {
   1158                 status = PHNFCSTVAL(CID_NFC_HCI,
   1159                             NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1160                 break;
   1161             }
   1162         }
   1163 
   1164     }
   1165     return status;
   1166 }
   1167 
   1168 
   1169 /*!
   1170  * \brief Receives the HCI Response from the corresponding peripheral device.
   1171  *
   1172  * This function receives the HCI Command Response from the connected NFC
   1173  * Peripheral device.
   1174  */
   1175 static
   1176 NFCSTATUS
   1177 phHciNfc_Recv_DevMgmt_Response(
   1178                         void                *psContext,
   1179                         void                *pHwRef,
   1180                         uint8_t             *pResponse,
   1181 #ifdef ONE_BYTE_LEN
   1182                         uint8_t             length
   1183 #else
   1184                         uint16_t            length
   1185 #endif
   1186                     )
   1187 {
   1188     phHciNfc_sContext_t         *psHciContext =
   1189                                     (phHciNfc_sContext_t *)psContext ;
   1190     phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
   1191     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1192     uint8_t                     prev_cmd = ANY_GET_PARAMETER;
   1193 
   1194     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1195     {
   1196       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1197     }
   1198     else if(  NULL == psHciContext->p_device_mgmt_info )
   1199     {
   1200         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1201     }
   1202     else
   1203     {
   1204         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
   1205                             psHciContext->p_device_mgmt_info ;
   1206         prev_cmd = p_device_mgmt_info->p_pipe_info->prev_msg ;
   1207         switch(prev_cmd)
   1208         {
   1209             case ANY_GET_PARAMETER:
   1210             {
   1211                 status = phHciNfc_DevMgmt_InfoUpdate(psHciContext,
   1212                             (phHal_sHwReference_t *)pHwRef,
   1213                             p_device_mgmt_info->p_pipe_info->reg_index,
   1214                             &pResponse[HCP_HEADER_LEN],
   1215                                 (uint8_t)(length - HCP_HEADER_LEN));
   1216                 break;
   1217             }
   1218             case ANY_SET_PARAMETER:
   1219             {
   1220                 break;
   1221             }
   1222             case ANY_OPEN_PIPE:
   1223             {
   1224                 break;
   1225             }
   1226             case ANY_CLOSE_PIPE:
   1227             {
   1228                 phOsalNfc_FreeMemory(p_device_mgmt_info->p_pipe_info);
   1229                 p_device_mgmt_info->p_pipe_info = NULL;
   1230                 psHciContext->p_pipe_list[PIPETYPE_STATIC_LINK] = NULL;
   1231                 break;
   1232             }
   1233             case NXP_DBG_READ:
   1234             /* fall through */
   1235             case NXP_DBG_WRITE:
   1236             {
   1237                 if( NULL != p_device_mgmt_info->p_val )
   1238                 {
   1239                     *p_device_mgmt_info->p_val = (uint8_t)( length > HCP_HEADER_LEN ) ?
   1240                                         pResponse[HCP_HEADER_LEN]: 0;
   1241                     p_device_mgmt_info->p_val = NULL;
   1242                 }
   1243                 break;
   1244             }
   1245             /* Self Test Commands */
   1246             case NXP_SELF_TEST_ANTENNA:
   1247             case NXP_SELF_TEST_SWP:
   1248             case NXP_SELF_TEST_NFCWI:
   1249             case NXP_SELF_TEST_PRBS:
   1250             {
   1251                 p_device_mgmt_info->test_status = (uint8_t) ( length > HCP_HEADER_LEN ) ?
   1252                                     pResponse[HCP_HEADER_LEN]: 0;
   1253                 p_device_mgmt_info->test_result.buffer = (uint8_t)( length > HCP_HEADER_LEN ) ?
   1254                                     &pResponse[HCP_HEADER_LEN]: NULL;
   1255                 p_device_mgmt_info->test_result.length = ( length - HCP_HEADER_LEN );
   1256                 break;
   1257             }
   1258             default:
   1259             {
   1260                 status = PHNFCSTVAL(CID_NFC_HCI,
   1261                                         NFCSTATUS_INVALID_HCI_RESPONSE);
   1262                 break;
   1263             }
   1264         }
   1265         if( NFCSTATUS_SUCCESS == status )
   1266         {
   1267             if( NULL != p_device_mgmt_info->p_pipe_info)
   1268             {
   1269                 p_device_mgmt_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS;
   1270             }
   1271             p_device_mgmt_info->current_seq = p_device_mgmt_info->next_seq;
   1272         }
   1273 
   1274     }
   1275     return status;
   1276 }
   1277 
   1278 /*!
   1279  * \brief Receives the HCI Event from the corresponding peripheral device.
   1280  *
   1281  * This function receives the HCI Event from the connected NFC
   1282  * Peripheral device.
   1283  */
   1284 
   1285 static
   1286 NFCSTATUS
   1287 phHciNfc_Recv_DevMgmt_Event(
   1288                         void                *psContext,
   1289                         void                *pHwRef,
   1290                         uint8_t             *pEvent,
   1291 #ifdef ONE_BYTE_LEN
   1292                         uint8_t             length
   1293 #else
   1294                         uint16_t            length
   1295 #endif
   1296                     )
   1297 {
   1298     phHciNfc_sContext_t         *psHciContext =
   1299                                     (phHciNfc_sContext_t *)psContext ;
   1300     phHciNfc_DevMgmt_Info_t     *p_device_mgmt_info=NULL;
   1301     phHciNfc_HCP_Packet_t       *hcp_packet = NULL;
   1302     phHciNfc_HCP_Message_t      *hcp_message = NULL;
   1303     NFCSTATUS                   status = NFCSTATUS_SUCCESS;
   1304     phHal_sEventInfo_t          event_info;
   1305     uint8_t                     event = (uint8_t) HCP_MSG_INSTRUCTION_INVALID;
   1306 
   1307     if( (NULL == psHciContext) || (NULL == pHwRef) )
   1308     {
   1309       status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1310     }
   1311     else if(  NULL == psHciContext->p_device_mgmt_info )
   1312     {
   1313         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED);
   1314     }
   1315     else
   1316     {
   1317         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
   1318                             psHciContext->p_device_mgmt_info ;
   1319         hcp_packet = (phHciNfc_HCP_Packet_t *)pEvent;
   1320         hcp_message = &hcp_packet->msg.message;
   1321 
   1322         /* Get the Event instruction bits from the Message Header */
   1323         event = (uint8_t) GET_BITS8( hcp_message->msg_header,
   1324             HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN);
   1325         event_info.eventHost = phHal_eHostController ;
   1326         event_info.eventSource = phHal_ePCD_DevType;
   1327 
   1328         switch(event)
   1329         {
   1330             /* Information Events */
   1331             case NXP_EVT_INFO_TXLDO_OVERCUR:
   1332             {
   1333                 event_info.eventType = NFC_INFO_TXLDO_OVERCUR;
   1334                 break;
   1335             }
   1336             case NXP_EVT_INFO_PMUVCC:
   1337             {
   1338                 p_device_mgmt_info->pmuvcc_status = (uint8_t) ( length > HCP_HEADER_LEN ) ?
   1339                                     pEvent[HCP_HEADER_LEN]: 0;
   1340                 break;
   1341             }
   1342             case NXP_EVT_INFO_EXT_RF_FIELD:
   1343             {
   1344                 event_info.eventSource = phHal_ePICC_DevType ;
   1345                 p_device_mgmt_info->rf_status = (uint8_t) ( length > HCP_HEADER_LEN ) ?
   1346                                     pEvent[HCP_HEADER_LEN]: 0;
   1347 #ifdef EVT_INFO_EXT_EVT_DIRECT
   1348                 event_info.eventType = ( CE_EVT_NFC_FIELD_ON ==
   1349                                 (p_device_mgmt_info->rf_status & 0x1FU))?
   1350                                     NFC_EVT_FIELD_ON : NFC_EVT_FIELD_OFF;
   1351 #else
   1352                 event_info.eventType = (TRUE == p_device_mgmt_info->rf_status)?
   1353                                     NFC_EVT_FIELD_ON : NFC_EVT_FIELD_OFF;
   1354 #endif
   1355                 break;
   1356             }
   1357             case NXP_EVT_INFO_MEM_VIOLATION:
   1358             {
   1359                 event_info.eventType = NFC_INFO_MEM_VIOLATION;
   1360                 break;
   1361             }
   1362             case NXP_EVT_INFO_TEMP_OVERHEAT:
   1363             {
   1364                 p_device_mgmt_info->overheat_status = (uint8_t)( length > HCP_HEADER_LEN ) ?
   1365                                     pEvent[HCP_HEADER_LEN]: 0;
   1366                 event_info.eventType = NFC_INFO_TEMP_OVERHEAT;
   1367                 event_info.eventInfo.overheat_status =
   1368                                     p_device_mgmt_info->overheat_status;
   1369                 break;
   1370             }
   1371             case NXP_EVT_INFO_LLC_ERROR:
   1372             {
   1373                 event_info.eventType = NFC_INFO_LLC_ERROR;
   1374                 break;
   1375             }
   1376             default:
   1377             {
   1378                 status = PHNFCSTVAL(CID_NFC_HCI,
   1379                                         NFCSTATUS_INVALID_HCI_RESPONSE);
   1380                 break;
   1381             }
   1382         }
   1383         if( NFCSTATUS_SUCCESS == status )
   1384         {
   1385             if( NULL != p_device_mgmt_info->p_pipe_info)
   1386             {
   1387                 p_device_mgmt_info->p_pipe_info->prev_status =
   1388                                                     NFCSTATUS_SUCCESS;
   1389             }
   1390             p_device_mgmt_info->current_seq =
   1391                                         p_device_mgmt_info->next_seq;
   1392             phHciNfc_Notify_Event(psHciContext, pHwRef,
   1393                                         NFC_NOTIFY_EVENT, &event_info);
   1394         }
   1395     }
   1396     return status;
   1397 }
   1398 
   1399 
   1400 static
   1401 NFCSTATUS
   1402 phHciNfc_DevMgmt_InfoUpdate(
   1403                                 phHciNfc_sContext_t     *psHciContext,
   1404                                 phHal_sHwReference_t    *pHwRef,
   1405                                 uint8_t                 index,
   1406                                 uint8_t                 *reg_value,
   1407                                 uint8_t                 reg_length
   1408                           )
   1409 {
   1410     phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL;
   1411     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   1412     uint8_t                 i=0;
   1413 
   1414     PHNFC_UNUSED_VARIABLE(pHwRef);
   1415     if( (NULL == psHciContext)
   1416         || (NULL == reg_value)
   1417         || (reg_length == 0)
   1418       )
   1419     {
   1420         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1421     }
   1422     else if ( NULL == psHciContext->p_device_mgmt_info )
   1423     {
   1424         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION);
   1425     }
   1426     else
   1427     {
   1428         p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *)
   1429                                 psHciContext->p_device_mgmt_info ;
   1430 
   1431         switch(index)
   1432         {
   1433             case DEVICE_INFO_EEPROM_INDEX:
   1434             {
   1435                 p_device_mgmt_info->eeprom_crc = reg_value[i];
   1436                 break;
   1437             }
   1438             default:
   1439             {
   1440                 break;
   1441             }
   1442         }
   1443 
   1444     } /* End of Context and the PN544 Device information validity check */
   1445 
   1446     return status;
   1447 }
   1448 
   1449 
   1450 
   1451 /*!
   1452  * \brief Sends the RF Settings HCI Additonal Commands to the connected
   1453  * reader device.
   1454  *
   1455  * This function Sends the RF Settings HCI Command frames in the HCP packet
   1456  * format to the connected reader device.
   1457  */
   1458 static
   1459  NFCSTATUS
   1460  phHciNfc_Send_DevMgmt_Command (
   1461                                 phHciNfc_sContext_t *psHciContext,
   1462                                 void                *pHwRef,
   1463                                 uint8_t             pipe_id,
   1464                                 uint8_t             cmd
   1465                     )
   1466  {
   1467     phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
   1468     phHciNfc_HCP_Message_t  *hcp_message = NULL;
   1469     phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
   1470     uint8_t                 length=0;
   1471     uint8_t                 i = 0;
   1472     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   1473 
   1474     if( (NULL == psHciContext)
   1475         || ( pipe_id > PHHCINFC_MAX_PIPE)
   1476         ||(NULL == psHciContext->p_pipe_list[pipe_id])
   1477       )
   1478     {
   1479         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1480         HCI_DEBUG("%s: Invalid Arguments passed \n",
   1481                                                 "phHciNfc_Send_DevMgmt_Command");
   1482     }
   1483     else
   1484     {
   1485         p_pipe_info = (phHciNfc_Pipe_Info_t *)
   1486                                 psHciContext->p_pipe_list[pipe_id];
   1487         psHciContext->tx_total = 0 ;
   1488         length +=  HCP_HEADER_LEN ;
   1489         switch( cmd )
   1490         {
   1491             /* Self Test Commands */
   1492             case NXP_SELF_TEST_ANTENNA:
   1493             case NXP_SELF_TEST_SWP:
   1494             case NXP_SELF_TEST_NFCWI:
   1495             case NXP_SELF_TEST_PRBS:
   1496             /* Internal Properietary Commands */
   1497             case NXP_DBG_READ:
   1498             case NXP_DBG_WRITE:
   1499             {
   1500 
   1501                 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   1502                 /* Construct the HCP Frame */
   1503                 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   1504                                         (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd);
   1505                 hcp_message = &(hcp_packet->msg.message);
   1506                 /* Append the RF Setting Parameter also the optional Value */
   1507                 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
   1508                                             i, p_pipe_info->param_info,
   1509                                             p_pipe_info->param_length);
   1510                 length =(uint8_t)(length + i + p_pipe_info->param_length);
   1511                 break;
   1512             }
   1513             default:
   1514             {
   1515                 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
   1516                 HCI_DEBUG("%s: Statement Should Not Occur \n",
   1517                                                 "phHciNfc_Send_DevMgmt_Command");
   1518                 break;
   1519             }
   1520         }
   1521         if( NFCSTATUS_SUCCESS == status )
   1522         {
   1523             p_pipe_info->sent_msg_type = HCP_MSG_TYPE_COMMAND;
   1524             p_pipe_info->prev_msg = cmd;
   1525             psHciContext->tx_total = length;
   1526             psHciContext->response_pending = TRUE ;
   1527 
   1528             /* Send the Constructed HCP packet to the lower layer */
   1529             status = phHciNfc_Send_HCP( psHciContext, pHwRef );
   1530             p_pipe_info->prev_status = NFCSTATUS_PENDING;
   1531         }
   1532     }
   1533 
   1534     return status;
   1535 }
   1536 
   1537 
   1538 
   1539 /*!
   1540  * \brief Sends the RF Settings HCI Additonal Events to the connected
   1541  * reader device.
   1542  *
   1543  * This function Sends the RF Settings HCI Events frames in the HCP packet
   1544  * format to the connected reader device.
   1545  */
   1546 
   1547 static
   1548  NFCSTATUS
   1549  phHciNfc_Send_DevMgmt_Event (
   1550                                 phHciNfc_sContext_t *psHciContext,
   1551                                 void                *pHwRef,
   1552                                 uint8_t             pipe_id,
   1553                                 uint8_t             event
   1554                     )
   1555  {
   1556     phHciNfc_HCP_Packet_t   *hcp_packet = NULL;
   1557     phHciNfc_HCP_Message_t  *hcp_message = NULL;
   1558     phHciNfc_Pipe_Info_t    *p_pipe_info = NULL;
   1559     uint8_t                 length=0;
   1560     uint8_t                 i = 0;
   1561     NFCSTATUS               status = NFCSTATUS_SUCCESS;
   1562 
   1563     if( (NULL == psHciContext)
   1564         || ( pipe_id > PHHCINFC_MAX_PIPE)
   1565         ||(NULL == psHciContext->p_pipe_list[pipe_id])
   1566       )
   1567     {
   1568         status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER);
   1569         HCI_DEBUG("%s: Invalid Arguments passed \n",
   1570                                                 "phHciNfc_Send_DevMgmt_Event");
   1571     }
   1572     else
   1573     {
   1574         p_pipe_info = (phHciNfc_Pipe_Info_t *)
   1575                                 psHciContext->p_pipe_list[pipe_id];
   1576         psHciContext->tx_total = 0 ;
   1577         length +=  HCP_HEADER_LEN ;
   1578         if( NXP_EVT_SET_AUTONOMOUS == event )
   1579         {
   1580 
   1581             hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer;
   1582             /* Construct the HCP Frame */
   1583             phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT,
   1584                                     (uint8_t) pipe_id, HCP_MSG_TYPE_EVENT, event);
   1585             hcp_message = &(hcp_packet->msg.message);
   1586             /* Append the RF Setting Parameter also the optional Value */
   1587             phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload,
   1588                                         i, p_pipe_info->param_info,
   1589                                         p_pipe_info->param_length);
   1590             length =(uint8_t)(length + i + p_pipe_info->param_length);
   1591         }
   1592         else
   1593         {
   1594             status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED );
   1595             HCI_DEBUG("%s: Statement Should Not Occur \n",
   1596                                             "phHciNfc_Send_DevMgmt_Event");
   1597         }
   1598         if( NFCSTATUS_SUCCESS == status )
   1599         {
   1600             p_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT;
   1601             p_pipe_info->prev_msg = event;
   1602             psHciContext->tx_total = length;
   1603 
   1604             /* Send the Constructed HCP packet to the lower layer */
   1605             status = phHciNfc_Send_HCP( psHciContext, pHwRef );
   1606             p_pipe_info->prev_status = NFCSTATUS_PENDING;
   1607         }
   1608     }
   1609 
   1610     return status;
   1611 }
   1612 
   1613 
   1614 
   1615 
   1616 
   1617