Home | History | Annotate | Download | only in hal
      1 /*
      2  * Copyright (C) 2012-2014 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 #include <phNxpNciHal_ext.h>
     17 #include <phNxpNciHal.h>
     18 #include <phTmlNfc.h>
     19 #include <phDal4Nfc_messageQueueLib.h>
     20 #include <phNxpNciHal_NfcDepSWPrio.h>
     21 #include <phNxpNciHal_Kovio.h>
     22 #include <phNxpLog.h>
     23 #include <phNxpConfig.h>
     24 
     25 #define HAL_EXTNS_WRITE_RSP_TIMEOUT   (1000)                /* Timeout value to wait for response from PN548AD */
     26 
     27 #undef P2P_PRIO_LOGIC_HAL_IMP
     28 
     29 /******************* Global variables *****************************************/
     30 extern phNxpNciHal_Control_t nxpncihal_ctrl;
     31 extern phNxpNciProfile_Control_t nxpprofile_ctrl;
     32 
     33 extern int kovio_detected;
     34 extern int disable_kovio;
     35 extern int send_to_upper_kovio;
     36 extern uint32_t cleanup_timer;
     37 static uint8_t icode_detected = 0x00;
     38 uint8_t icode_send_eof = 0x00;
     39 static uint8_t ee_disc_done = 0x00;
     40 uint8_t EnableP2P_PrioLogic = FALSE;
     41 static uint32_t RfDiscID = 1;
     42 static uint32_t RfProtocolType = 4;
     43 /* NFCEE Set mode */
     44 static uint8_t setEEModeDone = 0x00;
     45 static uint8_t cmd_nfcee_setmode_enable[] = { 0x22, 0x01, 0x02, 0x01, 0x01 };
     46 
     47 /* External global variable to get FW version from NCI response*/
     48 extern uint32_t wFwVerRsp;
     49 /* External global variable to get FW version from FW file*/
     50 extern uint16_t wFwVer;
     51 
     52 /* local buffer to store CORE_INIT response */
     53 static uint32_t bCoreInitRsp[40];
     54 static uint32_t iCoreInitRspLen;
     55 
     56 extern uint32_t timeoutTimerId;
     57 
     58 extern NFCSTATUS read_retry();
     59 /************** HAL extension functions ***************************************/
     60 static void hal_extns_write_rsp_timeout_cb(uint32_t TimerId, void *pContext);
     61 
     62 /*Proprietary cmd sent to HAL to send reader mode flag
     63  * Last byte of 4 byte proprietary cmd data contains ReaderMode flag
     64  * If this flag is enabled, NFC-DEP protocol is modified to T3T protocol
     65  * if FrameRF interface is selected. This needs to be done as the FW
     66  * always sends Ntf for FrameRF with NFC-DEP even though FrameRF with T3T is
     67  * previously selected with DISCOVER_SELECT_CMD
     68  */
     69 #define PROPRIETARY_CMD_FELICA_READER_MODE 0xFE
     70 static uint8_t gFelicaReaderMode;
     71 
     72 
     73 /*******************************************************************************
     74 **
     75 ** Function         phNxpNciHal_ext_init
     76 **
     77 ** Description      initialize extension function
     78 **
     79 *******************************************************************************/
     80 void phNxpNciHal_ext_init (void)
     81 {
     82     icode_detected = 0x00;
     83     icode_send_eof = 0x00;
     84     setEEModeDone = 0x00;
     85     kovio_detected = 0x00;
     86     disable_kovio = 0x00;
     87     send_to_upper_kovio = 0x01;
     88     EnableP2P_PrioLogic = FALSE;
     89 }
     90 
     91 /*******************************************************************************
     92 **
     93 ** Function         phNxpNciHal_process_ext_rsp
     94 **
     95 ** Description      Process extension function response
     96 **
     97 ** Returns          NFCSTATUS_SUCCESS if success
     98 **
     99 *******************************************************************************/
    100 NFCSTATUS phNxpNciHal_process_ext_rsp (uint8_t *p_ntf, uint16_t *p_len)
    101 {
    102 
    103     NFCSTATUS status = NFCSTATUS_SUCCESS;
    104     uint16_t rf_technology_length_param = 0;
    105 
    106     if (p_ntf[0] == 0x61 &&
    107         p_ntf[1] == 0x05 &&
    108         p_ntf[4] == 0x03 &&
    109         p_ntf[5] == 0x05 &&
    110         nxpprofile_ctrl.profile_type == EMV_CO_PROFILE)
    111     {
    112         p_ntf[4] = 0xFF;
    113         p_ntf[5] = 0xFF;
    114         p_ntf[6] = 0xFF;
    115         NXPLOG_NCIHAL_D("Nfc-Dep Detect in EmvCo profile - Restart polling");
    116     }
    117 
    118     if (p_ntf[0] == 0x61 &&
    119         p_ntf[1] == 0x05 &&
    120         p_ntf[4] == 0x01 &&
    121         p_ntf[5] == 0x05 &&
    122         p_ntf[6] == 0x02 &&
    123         gFelicaReaderMode)
    124     {
    125      /*If FelicaReaderMode is enabled,Change Protocol to T3T from NFC-DEP
    126           * when FrameRF interface is selected*/
    127         p_ntf[5] = 0x03;
    128         NXPLOG_NCIHAL_D("FelicaReaderMode:Activity 1.1");
    129     }
    130 
    131 #ifdef P2P_PRIO_LOGIC_HAL_IMP
    132     if(p_ntf[0] == 0x61 &&
    133        p_ntf[1] == 0x05 &&
    134        p_ntf[4] == 0x02 &&
    135        p_ntf[5] == 0x04 &&
    136        nxpprofile_ctrl.profile_type == NFC_FORUM_PROFILE)
    137     {
    138         EnableP2P_PrioLogic = TRUE;
    139     }
    140 
    141     NXPLOG_NCIHAL_D("Is EnableP2P_PrioLogic: 0x0%X",  EnableP2P_PrioLogic);
    142     if(phNxpDta_IsEnable() == FALSE)
    143     {
    144         if ((icode_detected != 1)&&(kovio_detected != 1) && (EnableP2P_PrioLogic == TRUE))
    145         {
    146             if (phNxpNciHal_NfcDep_comapre_ntf(p_ntf, *p_len) == NFCSTATUS_FAILED)
    147             {
    148                 status = phNxpNciHal_NfcDep_rsp_ext(p_ntf,p_len);
    149                 if(status != NFCSTATUS_INVALID_PARAMETER)
    150                 {
    151                     return status;
    152                 }
    153             }
    154         }
    155     }
    156 #endif
    157 
    158     status = NFCSTATUS_SUCCESS;
    159     status = phNxpNciHal_kovio_rsp_ext(p_ntf,p_len);
    160 
    161     if (p_ntf[0] == 0x61 &&
    162             p_ntf[1] == 0x05)
    163     {
    164         switch (p_ntf[4])
    165         {
    166         case 0x00:
    167             NXPLOG_NCIHAL_D("NxpNci: RF Interface = NFCEE Direct RF");
    168             break;
    169         case 0x01:
    170             NXPLOG_NCIHAL_D("NxpNci: RF Interface = Frame RF");
    171             break;
    172         case 0x02:
    173             NXPLOG_NCIHAL_D("NxpNci: RF Interface = ISO-DEP");
    174             break;
    175         case 0x03:
    176             NXPLOG_NCIHAL_D("NxpNci: RF Interface = NFC-DEP");
    177             break;
    178         case 0x80:
    179             NXPLOG_NCIHAL_D("NxpNci: RF Interface = MIFARE");
    180             break;
    181         default:
    182             NXPLOG_NCIHAL_D("NxpNci: RF Interface = Unknown");
    183             break;
    184         }
    185 
    186         switch (p_ntf[5])
    187         {
    188         case 0x01:
    189             NXPLOG_NCIHAL_D("NxpNci: Protocol = T1T");
    190             phNxpDta_T1TEnable();
    191             break;
    192         case 0x02:
    193             NXPLOG_NCIHAL_D("NxpNci: Protocol = T2T");
    194             break;
    195         case 0x03:
    196             NXPLOG_NCIHAL_D("NxpNci: Protocol = T3T");
    197             break;
    198         case 0x04:
    199             NXPLOG_NCIHAL_D("NxpNci: Protocol = ISO-DEP");
    200             break;
    201         case 0x05:
    202             NXPLOG_NCIHAL_D("NxpNci: Protocol = NFC-DEP");
    203             break;
    204         case 0x06:
    205             NXPLOG_NCIHAL_D("NxpNci: Protocol = 15693");
    206             break;
    207         case 0x80:
    208             NXPLOG_NCIHAL_D("NxpNci: Protocol = MIFARE");
    209             break;
    210 #if(NFC_NXP_CHIP_TYPE != PN547C2)
    211         case 0x81:
    212 #else
    213         case 0x8A:
    214 #endif
    215             NXPLOG_NCIHAL_D("NxpNci: Protocol = Kovio");
    216             break;
    217         default:
    218             NXPLOG_NCIHAL_D("NxpNci: Protocol = Unknown");
    219             break;
    220         }
    221 
    222         switch (p_ntf[6])
    223         {
    224         case 0x00:
    225             NXPLOG_NCIHAL_D("NxpNci: Mode = A Passive Poll");
    226             break;
    227         case 0x01:
    228             NXPLOG_NCIHAL_D("NxpNci: Mode = B Passive Poll");
    229             break;
    230         case 0x02:
    231             NXPLOG_NCIHAL_D("NxpNci: Mode = F Passive Poll");
    232             break;
    233         case 0x03:
    234             NXPLOG_NCIHAL_D("NxpNci: Mode = A Active Poll");
    235             break;
    236         case 0x05:
    237             NXPLOG_NCIHAL_D("NxpNci: Mode = F Active Poll");
    238             break;
    239         case 0x06:
    240             NXPLOG_NCIHAL_D("NxpNci: Mode = 15693 Passive Poll");
    241             break;
    242 #if(NFC_NXP_CHIP_TYPE != PN547C2)
    243         case 0x70:
    244 #else
    245         case 0x77:
    246 #endif
    247             NXPLOG_NCIHAL_D("NxpNci: Mode = Kovio");
    248             break;
    249         case 0x80:
    250             NXPLOG_NCIHAL_D("NxpNci: Mode = A Passive Listen");
    251             break;
    252         case 0x81:
    253             NXPLOG_NCIHAL_D("NxpNci: Mode = B Passive Listen");
    254             break;
    255         case 0x82:
    256             NXPLOG_NCIHAL_D("NxpNci: Mode = F Passive Listen");
    257             break;
    258         case 0x83:
    259             NXPLOG_NCIHAL_D("NxpNci: Mode = A Active Listen");
    260             break;
    261         case 0x85:
    262             NXPLOG_NCIHAL_D("NxpNci: Mode = F Active Listen");
    263             break;
    264         case 0x86:
    265             NXPLOG_NCIHAL_D("NxpNci: Mode = 15693 Passive Listen");
    266             break;
    267         default:
    268             NXPLOG_NCIHAL_D("NxpNci: Mode = Unknown");
    269             break;
    270         }
    271     }
    272 
    273     if (p_ntf[0] == 0x61 &&
    274             p_ntf[1] == 0x05 &&
    275             p_ntf[2] == 0x15 &&
    276             p_ntf[4] == 0x01 &&
    277             p_ntf[5] == 0x06 &&
    278             p_ntf[6] == 0x06)
    279     {
    280         NXPLOG_NCIHAL_D ("> Going through workaround - notification of ISO 15693");
    281         icode_detected = 0x01;
    282         p_ntf[21] = 0x01;
    283         p_ntf[22] = 0x01;
    284     }
    285     else if (icode_detected == 1 &&
    286             icode_send_eof == 2)
    287     {
    288         icode_send_eof = 3;
    289         status = NFCSTATUS_FAILED;
    290         return status;
    291     }
    292     else if (p_ntf[0] == 0x00 &&
    293                 p_ntf[1] == 0x00 &&
    294                 icode_detected == 1)
    295     {
    296         if (icode_send_eof == 3)
    297         {
    298             icode_send_eof = 0;
    299         }
    300         if (p_ntf[p_ntf[2]+ 2] == 0x00)
    301         {
    302             NXPLOG_NCIHAL_D ("> Going through workaround - data of ISO 15693");
    303             p_ntf[2]--;
    304             (*p_len)--;
    305         }
    306     }
    307     else if (p_ntf[2] == 0x02 &&
    308             p_ntf[1] == 0x00 && icode_detected == 1)
    309     {
    310         NXPLOG_NCIHAL_D ("> ICODE EOF response do not send to upper layer");
    311     }
    312     else if(p_ntf[0] == 0x61 &&
    313             p_ntf[1] == 0x06 && icode_detected == 1)
    314     {
    315         NXPLOG_NCIHAL_D ("> Polling Loop Re-Started");
    316         icode_detected = 0;
    317         icode_send_eof = 0;
    318     }
    319     else if(*p_len == 4 &&
    320                 p_ntf[0] == 0x40 &&
    321                 p_ntf[1] == 0x02 &&
    322                 p_ntf[2] == 0x01 &&
    323                 p_ntf[3] == 0x06 )
    324     {
    325         NXPLOG_NCIHAL_D ("> Deinit workaround for LLCP set_config 0x%x 0x%x 0x%x", p_ntf[21], p_ntf[22], p_ntf[23]);
    326         p_ntf[0] = 0x40;
    327         p_ntf[1] = 0x02;
    328         p_ntf[2] = 0x02;
    329         p_ntf[3] = 0x00;
    330         p_ntf[4] = 0x00;
    331         *p_len = 5;
    332     }
    333     else if ((p_ntf[0] == 0x40) && (p_ntf[1] == 0x01))
    334     {
    335         int len = p_ntf[2] + 2; /*include 2 byte header*/
    336         wFwVerRsp= (((uint32_t)p_ntf[len - 2])<< 16U)|(((uint32_t)p_ntf[len - 1])<< 8U)|p_ntf[len];
    337         if(wFwVerRsp == 0)
    338             status = NFCSTATUS_FAILED;
    339         iCoreInitRspLen = *p_len;
    340         memcpy(bCoreInitRsp, p_ntf, *p_len);
    341         NXPLOG_NCIHAL_D ("NxpNci> FW Version: %x.%x.%x", p_ntf[len-2], p_ntf[len-1], p_ntf[len]);
    342     }
    343     //4200 02 00 01
    344     else if(p_ntf[0] == 0x42 && p_ntf[1] == 0x00 && ee_disc_done == 0x01)
    345     {
    346         NXPLOG_NCIHAL_D("Going through workaround - NFCEE_DISCOVER_RSP");
    347         if(p_ntf[4] == 0x01)
    348         {
    349             p_ntf[4] = 0x00;
    350 
    351             ee_disc_done = 0x00;
    352         }
    353         NXPLOG_NCIHAL_D("Going through workaround - NFCEE_DISCOVER_RSP - END");
    354 
    355     }
    356     else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x03 /*&& cleanup_timer!=0*/)
    357     {
    358         if(cleanup_timer!=0)
    359         {
    360             /* if RF Notification Type of RF_DISCOVER_NTF is Last Notification */
    361             if(0== (*(p_ntf + 2 + (*(p_ntf+2)))))
    362             {
    363                 phNxpNciHal_select_RF_Discovery(RfDiscID,RfProtocolType);
    364                 status = NFCSTATUS_FAILED;
    365                 return status;
    366             }
    367             else
    368             {
    369                 RfDiscID=p_ntf[3];
    370                 RfProtocolType=p_ntf[4];
    371             }
    372             status = NFCSTATUS_FAILED;
    373             return status;
    374 
    375         }
    376 
    377     }
    378     else if(p_ntf[0] == 0x41 && p_ntf[1] == 0x04 && cleanup_timer!=0)
    379     {
    380         status = NFCSTATUS_FAILED;
    381         return status;
    382     }
    383     else if(p_ntf[0] == 0x60 && p_ntf[1] == 0x00)
    384     {
    385         NXPLOG_NCIHAL_E("CORE_RESET_NTF received!");
    386         phNxpNciHal_emergency_recovery();
    387     }
    388 #if(NFC_NXP_CHIP_TYPE == PN547C2)
    389     else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x05
    390             && p_ntf[4] == 0x02 && p_ntf[5] == 0x80
    391             && p_ntf[6] == 0x00 )
    392     {
    393         NXPLOG_NCIHAL_D("Going through workaround - iso-dep  interface  mifare protocol with sak value not equal to 0x20");
    394         rf_technology_length_param = p_ntf[9];
    395         if((p_ntf[ 9 + rf_technology_length_param] & 0x20) != 0x20)
    396         {
    397             p_ntf[4] = 0x80;
    398         }
    399     }
    400 #endif
    401     /*
    402     else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[4] == 0x01 && p_ntf[5] == 0x00 && p_ntf[6] == 0x01)
    403     {
    404         NXPLOG_NCIHAL_D("Picopass type 3-B with undefined protocol is not supported, disabling");
    405         p_ntf[4] = 0xFF;
    406         p_ntf[5] = 0xFF;
    407         p_ntf[6] = 0xFF;
    408     }*/
    409 
    410     return status;
    411 }
    412 
    413 /******************************************************************************
    414  * Function         phNxpNciHal_process_ext_cmd_rsp
    415  *
    416  * Description      This function process the extension command response. It
    417  *                  also checks the received response to expected response.
    418  *
    419  * Returns          returns NFCSTATUS_SUCCESS if response is as expected else
    420  *                  returns failure.
    421  *
    422  ******************************************************************************/
    423 static NFCSTATUS phNxpNciHal_process_ext_cmd_rsp(uint16_t cmd_len, uint8_t *p_cmd)
    424 {
    425     NFCSTATUS status = NFCSTATUS_FAILED;
    426     uint16_t data_written = 0;
    427 
    428     /* Create the local semaphore */
    429     if (phNxpNciHal_init_cb_data(&nxpncihal_ctrl.ext_cb_data, NULL)
    430             != NFCSTATUS_SUCCESS)
    431     {
    432         NXPLOG_NCIHAL_D("Create ext_cb_data failed");
    433         return NFCSTATUS_FAILED;
    434     }
    435 
    436     nxpncihal_ctrl.ext_cb_data.status = NFCSTATUS_SUCCESS;
    437 
    438     /* Send ext command */
    439     data_written = phNxpNciHal_write_unlocked(cmd_len, p_cmd);
    440     if (data_written != cmd_len)
    441     {
    442         NXPLOG_NCIHAL_D("phNxpNciHal_write failed for hal ext");
    443         goto clean_and_return;
    444     }
    445 
    446     /* Start timer */
    447     status = phOsalNfc_Timer_Start(timeoutTimerId,
    448             HAL_EXTNS_WRITE_RSP_TIMEOUT,
    449             &hal_extns_write_rsp_timeout_cb,
    450             NULL);
    451     if (NFCSTATUS_SUCCESS == status)
    452     {
    453         NXPLOG_NCIHAL_D("Response timer started");
    454     }
    455     else
    456     {
    457         NXPLOG_NCIHAL_E("Response timer not started!!!");
    458         status  = NFCSTATUS_FAILED;
    459         goto clean_and_return;
    460     }
    461 
    462     /* Wait for rsp */
    463     NXPLOG_NCIHAL_D("Waiting after ext cmd sent");
    464     if (SEM_WAIT(nxpncihal_ctrl.ext_cb_data))
    465     {
    466         NXPLOG_NCIHAL_E("p_hal_ext->ext_cb_data.sem semaphore error");
    467         goto clean_and_return;
    468     }
    469 
    470     /* Stop Timer */
    471     status = phOsalNfc_Timer_Stop(timeoutTimerId);
    472 
    473     if (NFCSTATUS_SUCCESS == status)
    474     {
    475         NXPLOG_NCIHAL_D("Response timer stopped");
    476     }
    477     else
    478     {
    479         NXPLOG_NCIHAL_E("Response timer stop ERROR!!!");
    480         status  = NFCSTATUS_FAILED;
    481         goto clean_and_return;
    482     }
    483 
    484     if(nxpncihal_ctrl.ext_cb_data.status != NFCSTATUS_SUCCESS)
    485     {
    486         NXPLOG_NCIHAL_E("Callback Status is failed!! Timer Expired!! Couldn't read it! 0x%x", nxpncihal_ctrl.ext_cb_data.status);
    487         status  = NFCSTATUS_FAILED;
    488         goto clean_and_return;
    489     }
    490 
    491     NXPLOG_NCIHAL_D("Checking response");
    492     status = NFCSTATUS_SUCCESS;
    493 
    494 clean_and_return:
    495     phNxpNciHal_cleanup_cb_data(&nxpncihal_ctrl.ext_cb_data);
    496 
    497     return status;
    498 }
    499 
    500 /******************************************************************************
    501  * Function         phNxpNciHal_write_ext
    502  *
    503  * Description      This function inform the status of phNxpNciHal_open
    504  *                  function to libnfc-nci.
    505  *
    506  * Returns          It return NFCSTATUS_SUCCESS then continue with send else
    507  *                  sends NFCSTATUS_FAILED direct response is prepared and
    508  *                  do not send anything to NFCC.
    509  *
    510  ******************************************************************************/
    511 
    512 NFCSTATUS phNxpNciHal_write_ext(uint16_t *cmd_len, uint8_t *p_cmd_data,
    513         uint16_t *rsp_len, uint8_t *p_rsp_data)
    514 {
    515     NFCSTATUS status = NFCSTATUS_SUCCESS;
    516 
    517     unsigned long retval = 0;
    518     int isfound =  GetNxpNumValue(NAME_MIFARE_READER_ENABLE, &retval, sizeof(unsigned long));
    519 
    520     phNxpNciHal_NfcDep_cmd_ext(p_cmd_data, cmd_len);
    521 
    522     if(phNxpDta_IsEnable() == TRUE)
    523     {
    524         status = phNxpNHal_DtaUpdate(cmd_len, p_cmd_data,rsp_len, p_rsp_data);
    525     }
    526 
    527     if (p_cmd_data[0] == PROPRIETARY_CMD_FELICA_READER_MODE &&
    528         p_cmd_data[1] == PROPRIETARY_CMD_FELICA_READER_MODE &&
    529         p_cmd_data[2] == PROPRIETARY_CMD_FELICA_READER_MODE)
    530     {
    531         NXPLOG_NCIHAL_D ("Received proprietary command to set Felica Reader mode:%d",p_cmd_data[3]);
    532         gFelicaReaderMode = p_cmd_data[3];
    533         /* frame the dummy response */
    534         *rsp_len = 4;
    535         p_rsp_data[0] = 0x00;
    536         p_rsp_data[1] = 0x00;
    537         p_rsp_data[2] = 0x00;
    538         p_rsp_data[3] = 0x00;
    539         status = NFCSTATUS_FAILED;
    540     }
    541     else if (p_cmd_data[0] == 0x20 &&
    542             p_cmd_data[1] == 0x02 &&
    543             p_cmd_data[2] == 0x05 &&
    544             p_cmd_data[3] == 0x01 &&
    545             p_cmd_data[4] == 0xA0 &&
    546             p_cmd_data[5] == 0x44 &&
    547             p_cmd_data[6] == 0x01 &&
    548             p_cmd_data[7] == 0x01)
    549     {
    550         nxpprofile_ctrl.profile_type = EMV_CO_PROFILE;
    551         NXPLOG_NCIHAL_D ("EMV_CO_PROFILE mode - Enabled");
    552         status = NFCSTATUS_SUCCESS;
    553     }
    554     else if (p_cmd_data[0] == 0x20 &&
    555             p_cmd_data[1] == 0x02 &&
    556             p_cmd_data[2] == 0x05 &&
    557             p_cmd_data[3] == 0x01 &&
    558             p_cmd_data[4] == 0xA0 &&
    559             p_cmd_data[5] == 0x44 &&
    560             p_cmd_data[6] == 0x01 &&
    561             p_cmd_data[7] == 0x00)
    562     {
    563         NXPLOG_NCIHAL_D ("NFC_FORUM_PROFILE mode - Enabled");
    564         nxpprofile_ctrl.profile_type = NFC_FORUM_PROFILE;
    565         status = NFCSTATUS_SUCCESS;
    566     }
    567 
    568     if (nxpprofile_ctrl.profile_type == EMV_CO_PROFILE)
    569     {
    570         if (p_cmd_data[0] == 0x21 &&
    571                 p_cmd_data[1] == 0x06 &&
    572                 p_cmd_data[2] == 0x01 &&
    573                 p_cmd_data[3] == 0x03)
    574         {
    575 #if 0
    576             //Needs clarification whether to keep it or not
    577             NXPLOG_NCIHAL_D ("EmvCo Poll mode - RF Deactivate discard");
    578             phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    579             *rsp_len = 4;
    580             p_rsp_data[0] = 0x41;
    581             p_rsp_data[1] = 0x06;
    582             p_rsp_data[2] = 0x01;
    583             p_rsp_data[3] = 0x00;
    584             phNxpNciHal_print_packet("RECV", p_rsp_data, 4);
    585             status = NFCSTATUS_FAILED;
    586 #endif
    587         }
    588         else if(p_cmd_data[0] == 0x21 &&
    589                 p_cmd_data[1] == 0x03 )
    590         {
    591             NXPLOG_NCIHAL_D ("EmvCo Poll mode - Discover map only for A and B");
    592             p_cmd_data[2] = 0x05;
    593             p_cmd_data[3] = 0x02;
    594             p_cmd_data[4] = 0x00;
    595             p_cmd_data[5] = 0x01;
    596             p_cmd_data[6] = 0x01;
    597             p_cmd_data[7] = 0x01;
    598             *cmd_len = 8;
    599         }
    600     }
    601 #if(NFC_NXP_CHIP_TYPE == PN547C2)
    602     if (retval == 0x01 &&
    603         p_cmd_data[0] == 0x21 &&
    604         p_cmd_data[1] == 0x00)
    605     {
    606         NXPLOG_NCIHAL_D ("Going through extns - Adding Mifare in RF Discovery");
    607         p_cmd_data[2] += 3;
    608         p_cmd_data[3] += 1;
    609         p_cmd_data[*cmd_len] = 0x80;
    610         p_cmd_data[*cmd_len + 1] = 0x01;
    611         p_cmd_data[*cmd_len + 2] = 0x80;
    612         *cmd_len += 3;
    613         status = NFCSTATUS_SUCCESS;
    614         NXPLOG_NCIHAL_D ("Going through extns - Adding Mifare in RF Discovery - END");
    615     }
    616     else
    617 #endif
    618     if (p_cmd_data[3] == 0x81 &&
    619             p_cmd_data[4] == 0x01 &&
    620             p_cmd_data[5] == 0x03)
    621     {
    622         NXPLOG_NCIHAL_D("> Going through workaround - set host list");
    623 
    624 #if(NFC_NXP_CHIP_TYPE != PN547C2)
    625         *cmd_len = 8;
    626 
    627         p_cmd_data[2] = 0x05;
    628         p_cmd_data[6] = 0x02;
    629         p_cmd_data[7] = 0xC0;
    630 #else
    631         *cmd_len = 7;
    632 
    633         p_cmd_data[2] = 0x04;
    634         p_cmd_data[6] = 0xC0;
    635 #endif
    636 
    637         NXPLOG_NCIHAL_D("> Going through workaround - set host list - END");
    638         status = NFCSTATUS_SUCCESS;
    639     }
    640     else if(icode_detected)
    641     {
    642         if ((p_cmd_data[3] & 0x40) == 0x40 &&
    643             (p_cmd_data[4] == 0x21 ||
    644              p_cmd_data[4] == 0x22 ||
    645              p_cmd_data[4] == 0x24 ||
    646              p_cmd_data[4] == 0x27 ||
    647              p_cmd_data[4] == 0x28 ||
    648              p_cmd_data[4] == 0x29 ||
    649              p_cmd_data[4] == 0x2a))
    650         {
    651             NXPLOG_NCIHAL_D ("> Send EOF set");
    652             icode_send_eof = 1;
    653         }
    654 
    655         if(p_cmd_data[3]  == 0x20 || p_cmd_data[3]  == 0x24 ||
    656            p_cmd_data[3]  == 0x60)
    657         {
    658             NXPLOG_NCIHAL_D ("> NFC ISO_15693 Proprietary CMD ");
    659             p_cmd_data[3] += 0x02;
    660         }
    661     }
    662     else if(p_cmd_data[0] == 0x21 &&
    663             p_cmd_data[1] == 0x03 )
    664     {
    665         NXPLOG_NCIHAL_D ("> Polling Loop Started");
    666         icode_detected = 0;
    667         icode_send_eof = 0;
    668     }
    669     //22000100
    670     else if (p_cmd_data[0] == 0x22 &&
    671             p_cmd_data[1] == 0x00 &&
    672             p_cmd_data[2] == 0x01 &&
    673             p_cmd_data[3] == 0x00
    674             )
    675     {
    676         //ee_disc_done = 0x01;//Reader Over SWP event getting
    677         *rsp_len = 0x05;
    678         p_rsp_data[0] = 0x42;
    679         p_rsp_data[1] = 0x00;
    680         p_rsp_data[2] = 0x02;
    681         p_rsp_data[3] = 0x00;
    682         p_rsp_data[4] = 0x00;
    683         phNxpNciHal_print_packet("RECV", p_rsp_data,5);
    684         status = NFCSTATUS_FAILED;
    685     }
    686     //2002 0904 3000 3100 3200 5000
    687     else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) &&
    688             ( (p_cmd_data[2] == 0x09 && p_cmd_data[3] == 0x04) /*||
    689               (p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04)*/
    690             )
    691     )
    692     {
    693         *cmd_len += 0x01;
    694         p_cmd_data[2] += 0x01;
    695         p_cmd_data[9] = 0x01;
    696         p_cmd_data[10] = 0x40;
    697         p_cmd_data[11] = 0x50;
    698         p_cmd_data[12] = 0x00;
    699 
    700         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
    701 //        phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    702         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
    703     }
    704 //    20020703300031003200
    705 //    2002 0301 3200
    706     else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) &&
    707             (
    708               (p_cmd_data[2] == 0x07 && p_cmd_data[3] == 0x03) ||
    709               (p_cmd_data[2] == 0x03 && p_cmd_data[3] == 0x01 && p_cmd_data[4] == 0x32)
    710             )
    711     )
    712     {
    713         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
    714         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    715         *rsp_len = 5;
    716         p_rsp_data[0] = 0x40;
    717         p_rsp_data[1] = 0x02;
    718         p_rsp_data[2] = 0x02;
    719         p_rsp_data[3] = 0x00;
    720         p_rsp_data[4] = 0x00;
    721 
    722         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
    723         status = NFCSTATUS_FAILED;
    724         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
    725     }
    726 
    727     //2002 0D04 300104 310100 320100 500100
    728     //2002 0401 320100
    729     else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) &&
    730             (
    731               /*(p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04)*/
    732                 (p_cmd_data[2] == 0x04 && p_cmd_data[3] == 0x01 && p_cmd_data[4] == 0x32 && p_cmd_data[5] == 0x00)
    733             )
    734     )
    735     {
    736 //        p_cmd_data[12] = 0x40;
    737 
    738         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
    739         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    740         p_cmd_data[6] = 0x60;
    741 
    742         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
    743 //        status = NFCSTATUS_FAILED;
    744         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
    745     }
    746 
    747 #if 0
    748     else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) &&
    749                  ((p_cmd_data[2] == 0x09 && p_cmd_data[3] == 0x04) ||
    750                      (p_cmd_data[2] == 0x0B && p_cmd_data[3] == 0x05) ||
    751                      (p_cmd_data[2] == 0x07 && p_cmd_data[3] == 0x02) ||
    752                      (p_cmd_data[2] == 0x0A && p_cmd_data[3] == 0x03) ||
    753                      (p_cmd_data[2] == 0x0A && p_cmd_data[3] == 0x04) ||
    754                      (p_cmd_data[2] == 0x05 && p_cmd_data[3] == 0x02))
    755              )
    756     {
    757         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
    758         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    759         *rsp_len = 5;
    760         p_rsp_data[0] = 0x40;
    761         p_rsp_data[1] = 0x02;
    762         p_rsp_data[2] = 0x02;
    763         p_rsp_data[3] = 0x00;
    764         p_rsp_data[4] = 0x00;
    765 
    766         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
    767         status = NFCSTATUS_FAILED;
    768         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
    769     }
    770 
    771     else if((p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) &&
    772            ((p_cmd_data[3] == 0x00) ||
    773            ((*cmd_len >= 0x06) && (p_cmd_data[5] == 0x00)))) /*If the length of the first param id is zero don't allow*/
    774     {
    775         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config ");
    776         phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len);
    777         *rsp_len = 5;
    778         p_rsp_data[0] = 0x40;
    779         p_rsp_data[1] = 0x02;
    780         p_rsp_data[2] = 0x02;
    781         p_rsp_data[3] = 0x00;
    782         p_rsp_data[4] = 0x00;
    783 
    784         phNxpNciHal_print_packet("RECV", p_rsp_data, 5);
    785         status = NFCSTATUS_FAILED;
    786         NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End ");
    787     }
    788 #endif
    789     else if ((wFwVerRsp & 0x0000FFFF) == wFwVer)
    790     {
    791         /* skip CORE_RESET and CORE_INIT from Brcm */
    792         if (p_cmd_data[0] == 0x20 &&
    793             p_cmd_data[1] == 0x00 &&
    794             p_cmd_data[2] == 0x01 &&
    795             p_cmd_data[3] == 0x01
    796             )
    797         {
    798 //            *rsp_len = 6;
    799 //
    800 //            NXPLOG_NCIHAL_D("> Going - core reset optimization");
    801 //
    802 //            p_rsp_data[0] = 0x40;
    803 //            p_rsp_data[1] = 0x00;
    804 //            p_rsp_data[2] = 0x03;
    805 //            p_rsp_data[3] = 0x00;
    806 //            p_rsp_data[4] = 0x10;
    807 //            p_rsp_data[5] = 0x01;
    808 //
    809 //            status = NFCSTATUS_FAILED;
    810 //            NXPLOG_NCIHAL_D("> Going - core reset optimization - END");
    811         }
    812         /* CORE_INIT */
    813         else if (
    814             p_cmd_data[0] == 0x20 &&
    815             p_cmd_data[1] == 0x01 &&
    816             p_cmd_data[2] == 0x00
    817             )
    818         {
    819 //            NXPLOG_NCIHAL_D("> Going - core init optimization");
    820 //            *rsp_len = iCoreInitRspLen;
    821 //            memcpy(p_rsp_data, bCoreInitRsp, iCoreInitRspLen);
    822 //            status = NFCSTATUS_FAILED;
    823 //            NXPLOG_NCIHAL_D("> Going - core init optimization - END");
    824         }
    825     }
    826     return status;
    827 }
    828 
    829 /******************************************************************************
    830  * Function         phNxpNciHal_send_ext_cmd
    831  *
    832  * Description      This function send the extension command to NFCC. No
    833  *                  response is checked by this function but it waits for
    834  *                  the response to come.
    835  *
    836  * Returns          Returns NFCSTATUS_SUCCESS if sending cmd is successful and
    837  *                  response is received.
    838  *
    839  ******************************************************************************/
    840 NFCSTATUS phNxpNciHal_send_ext_cmd(uint16_t cmd_len, uint8_t *p_cmd)
    841 {
    842     NFCSTATUS status = NFCSTATUS_FAILED;
    843 
    844     HAL_ENABLE_EXT();
    845     nxpncihal_ctrl.cmd_len = cmd_len;
    846     memcpy(nxpncihal_ctrl.p_cmd_data, p_cmd, cmd_len);
    847     status = phNxpNciHal_process_ext_cmd_rsp(nxpncihal_ctrl.cmd_len, nxpncihal_ctrl.p_cmd_data);
    848     HAL_DISABLE_EXT();
    849 
    850     return status;
    851 }
    852 
    853 /******************************************************************************
    854  * Function         hal_extns_write_rsp_timeout_cb
    855  *
    856  * Description      Timer call back function
    857  *
    858  * Returns          None
    859  *
    860  ******************************************************************************/
    861 static void hal_extns_write_rsp_timeout_cb(uint32_t timerId, void *pContext)
    862 {
    863     UNUSED(timerId);
    864     UNUSED(pContext);
    865     NXPLOG_NCIHAL_E("hal_extns_write_rsp_timeout_cb - write timeout!!!");
    866     nxpncihal_ctrl.ext_cb_data.status = NFCSTATUS_FAILED;
    867     usleep(1);
    868     SEM_POST(&(nxpncihal_ctrl.ext_cb_data));
    869 
    870     return;
    871 }
    872