/*!
 * \brief System timer callback.
 *        This callback is called by Linux whenever one the timers expires.  It
 *        calls the corresponding registered callback.
 *
 * \param sv structure storing the expired timer ID.
 */
static void phOsalNfc_Timer_Expired(union sigval sv)
{
   uint32_t timerid = (uint32_t)(sv.sival_int);

   if((timerid < MAX_NO_TIMERS)&&(timers[timerid].nIsStopped == 1))
   {
      //printf("phOsalNfc_Timer_Expired : Expired but already stopped TimerId=%d\n", timerid);
      return;
   }

   if(timerid < MAX_NO_TIMERS)
   {
#ifndef CYCLIC_TIMER
      phOsalNfc_Timer_Stop(timerid);
#else

#endif
#ifdef NXP_MESSAGING
      phOsalNfc_Timer_Msg_t *timer_msg;
      phOsalNfc_DeferedCalldInfo_t *osal_defer_msg;
      phDal4Nfc_Message_Wrapper_t wrapper;

      timer_msg = phOsalNfc_GetMemory(sizeof(phOsalNfc_Timer_Msg_t));
      if(timer_msg == NULL)
      {
         phOsalNfc_RaiseException(phOsalNfc_e_NoMemory, 0);
	  return;
      }

      osal_defer_msg = phOsalNfc_GetMemory(sizeof(phOsalNfc_DeferedCalldInfo_t));
      if(osal_defer_msg == NULL)
      {
         phOsalNfc_FreeMemory(timer_msg);
         phOsalNfc_RaiseException(phOsalNfc_e_NoMemory, 0);
	  return;
      }

      timer_msg->TimerId = timerid;
      timer_msg->pCallBck = timers[timerid].callback;
      timer_msg->pContext = timers[timerid].pContext;

      osal_defer_msg->pCallback = phOsalNfc_Timer_DeferredCall;
      osal_defer_msg->pParameter = timer_msg;

      wrapper.mtype = 1;
      wrapper.msg.eMsgType = PH_OSALNFC_TIMER_MSG;
      wrapper.msg.pMsgData = osal_defer_msg;
      wrapper.msg.Size = sizeof(phOsalNfc_DeferedCalldInfo_t);

      timers[timerid].ptr = osal_defer_msg;
#ifndef G_IDLE_ADD_MSGQ
      phDal4Nfc_msgsnd(nDeferedCallMessageQueueId, (void *)&wrapper, sizeof(phOsalNfc_Message_t), 0);
#else
      PostMessage((void *)&wrapper, sizeof(phOsalNfc_Message_t), 0);
#endif
      //(timers[timerid].callback)(timerid, timers[timerid].pContext);
#endif
   }
}
extern NFCSTATUS phNxpNciHal_clean_P2P_Prio()
{
    NFCSTATUS status = NFCSTATUS_SUCCESS;

    iso_dep_detected = 0x00;
    EnableP2P_PrioLogic = FALSE;
    poll_timer_fired = 0x00;
    bIgnorep2plogic = 0x00;
    bIgnoreIsoDep = 0x00;

    status = phOsalNfc_Timer_Stop(cleanup_timer);
    status |= phOsalNfc_Timer_Delete(cleanup_timer);

    status |= phOsalNfc_Timer_Stop(custom_poll_timer);
    status |= phOsalNfc_Timer_Delete(custom_poll_timer);
    cleanup_timer=0;
    return status;
}
void
phNciNfc_LogConnMgmtDeInit()
{
    if(gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus == 1)
    {
        PH_LOG_NCI_INFO_STR("Stopping Credit await timer..");
        (void)phOsalNfc_Timer_Stop(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId);
        (void)phOsalNfc_Timer_Delete(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId);
    }

    phOsalNfc_SetMemory(&gphNciNfc_ConnMgmtInt, 0x00, sizeof(phNciNfc_LogConnMgmt_Int_t));
}
void 
phLlcNfc_URSET_Delay_Notify (
    uint32_t            delay_id,
    void                *pContext)
{
    phLlcNfc_Frame_t            *ps_frame_info = NULL;
    phNfc_sCompletionInfo_t     notifyinfo = {0};
    
    if (NULL != gpphLlcNfc_Ctxt)
    {
        ps_frame_info = &(gpphLlcNfc_Ctxt->s_frameinfo);

        phOsalNfc_Timer_Stop (delay_id);
        phOsalNfc_Timer_Delete (delay_id);
        if (ps_frame_info->s_send_store.winsize_cnt > 0)
        {
#if 0

            /* Resend I frame */
            (void)phLlcNfc_H_SendTimedOutIFrame (gpphLlcNfc_Ctxt, 
                                        &(ps_frame_info->s_send_store), 0);

#else

            (void)phLlcNfc_H_SendUserIFrame (gpphLlcNfc_Ctxt, 
                                        &(ps_frame_info->s_send_store));

#endif /* #if 0 */
            gpphLlcNfc_Ctxt->state = phLlcNfc_Resend_State;
        }
        else 
        {
            if ((init_u_rset_frame == ps_frame_info->sent_frame_type) && 
                (NULL != gpphLlcNfc_Ctxt->cb_for_if.notify))
            {
                ps_frame_info->sent_frame_type = write_resp_received;
                notifyinfo.status = NFCSTATUS_SUCCESS;
                /* Send the notification to the upper layer */
                gpphLlcNfc_Ctxt->cb_for_if.notify (
                            gpphLlcNfc_Ctxt->cb_for_if.pif_ctxt, 
                            gpphLlcNfc_Ctxt->phwinfo, 
                            NFC_NOTIFY_INIT_COMPLETED, 
                            &notifyinfo);
            }
        }
    }
}
/*Timer callback for recv data timer for CE.This timer is used for creating
  Asynchronous behavior in the scenario where the data is received even before
  the upper layer calls the phHal4Nfc_receive().*/
void phHal4Nfc_CE_RecvTimerCb(uint32_t CERecvTimerId, void *pContext)
{
    phHal4Nfc_Hal4Ctxt_t *Hal4Ctxt = (phHal4Nfc_Hal4Ctxt_t *)(
                                            gpphHal4Nfc_Hwref->hal_context);
    pphLibNfc_TransceiveCallback_t pUpperRecvCb = NULL;
    NFCSTATUS RecvDataBufferStatus = NFCSTATUS_PENDING;
    PHNFC_UNUSED_VARIABLE(pContext);

    phOsalNfc_Timer_Stop(CERecvTimerId);
    phOsalNfc_Timer_Delete(CERecvTimerId);
    if(NULL != Hal4Ctxt->psTrcvCtxtInfo)
    {
        RecvDataBufferStatus = Hal4Ctxt->psTrcvCtxtInfo->RecvDataBufferStatus;
        Hal4Ctxt->psTrcvCtxtInfo->RecvDataBufferStatus = NFCSTATUS_PENDING;

        Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId
            = PH_OSALNFC_INVALID_TIMER_ID;
        /*Update state*/
        Hal4Ctxt->Hal4NextState = (eHal4StateTransaction
             == Hal4Ctxt->Hal4NextState?eHal4StateInvalid:Hal4Ctxt->Hal4NextState);
        /*Provide address of received data to upper layer data pointer*/
        Hal4Ctxt->psTrcvCtxtInfo->psUpperRecvData
            = &(Hal4Ctxt->psTrcvCtxtInfo->sLowerRecvData);
        /*Chk NULL and call recv callback*/
        if(Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb != NULL)
        {
            pUpperRecvCb = (pphLibNfc_TransceiveCallback_t)Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb;
            Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb = NULL;
            (*pUpperRecvCb)(
                Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
                Hal4Ctxt->sTgtConnectInfo.psConnectedDevice,
                Hal4Ctxt->psTrcvCtxtInfo->psUpperRecvData,
                RecvDataBufferStatus
                );
        }
    }
    return;
}
static void phNciNfc_WaitCreditTimerCb(uint32_t TimerId, void *pContext)
{
    NFCSTATUS wStatus = NFCSTATUS_RF_TIMEOUT;
    phNciNfc_LogConnMgmt_Int_t *pConnMgmtCtxt = (phNciNfc_LogConnMgmt_Int_t *)pContext;

    PH_LOG_NCI_FUNC_ENTRY();

    if(NULL != pConnMgmtCtxt)
    {
        if(TimerId == pConnMgmtCtxt->tCWTimerIf.dwTimerId)
        {
            pConnMgmtCtxt->tCWTimerIf.TimerStatus = 0; /* Reset timer status flag */

            (void)phOsalNfc_Timer_Stop(pConnMgmtCtxt->tCWTimerIf.dwTimerId);
            (void)phOsalNfc_Timer_Delete(pConnMgmtCtxt->tCWTimerIf.dwTimerId);
            pConnMgmtCtxt->tCWTimerIf.dwTimerId = 0;
        }
        else
        {
            PH_LOG_NCI_CRIT_STR("Invalid wait credit timer ID");
            phOsalNfc_RaiseException(phOsalNfc_e_InternalErr, 1);
        }

        if(TRUE == pConnMgmtCtxt->bCreditsAwaited)
        {
            pConnMgmtCtxt->bCreditsAwaited = FALSE;
        }

        if (NULL != pConnMgmtCtxt->pCrdtsNotify)
        {
            (void)(pConnMgmtCtxt->pCrdtsNotify)(pConnMgmtCtxt->pContext,0,wStatus);
        }
    }
    PH_LOG_NCI_FUNC_EXIT();
    return;
}
NFCSTATUS
phNciNfc_ProcessGenericErrNtf(void *pContext, void *pInfo, NFCSTATUS wStatus)
{
    NFCSTATUS wRetStatus = NFCSTATUS_SUCCESS;
    pphNciNfc_Context_t pNciCtx = (pphNciNfc_Context_t )pContext;
    pphNciNfc_CoreContext_t pCtx = NULL;
    pphNciNfc_TransactInfo_t pTransInfo = pInfo;
    phNciNfc_NotificationInfo_t tNtfInfo;

    PH_LOG_NCI_FUNC_ENTRY();
    if((NULL != pNciCtx) && (NULL != pTransInfo))
    {
        /* Stop Notification timer */
        (void)phOsalNfc_Timer_Stop(pNciCtx->dwNtfTimerId);

        pCtx = (pphNciNfc_CoreContext_t)&pNciCtx->NciCoreContext;

        if((NULL == pTransInfo->pbuffer) ||(1 != pTransInfo->wLength)
            || (NFCSTATUS_SUCCESS != wStatus))
        {
            wRetStatus = NFCSTATUS_FAILED;
            PH_LOG_NCI_CRIT_STR("Invalid buffer or incorrect payload length or \
                                 Tml receive failed receive failed");
        }
void 
phLlcNfc_StopTimers (
    uint8_t             TimerType, 
    uint8_t             no_of_guard_to_del
)
{
    NFCSTATUS               result = NFCSTATUS_SUCCESS;
#ifdef LLC_TIMER_ENABLE

    uint32_t                timerid = 0,
                            timerflag = FALSE;
    uint8_t                 timer_count = 0;
    phLlcNfc_Timerinfo_t    *ps_timer_info = NULL;
    

    ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);
    timerflag = ps_timer_info->timer_flag;

    PHNFC_UNUSED_VARIABLE (result);
    PH_LLCNFC_PRINT("\n\nLLC : STOP TIMER CALLED\n\n");
    switch(TimerType)
    {
        case PH_LLCNFC_CONNECTIONTIMER:
        {           
            ps_timer_info->timer_flag = (uint8_t)
                        SET_BITS8(ps_timer_info->timer_flag, 
                                PH_LLCNFC_CON_TO_BIT, 
                                PH_LLCNFC_TO_NOOFBITS, 0);
            timerid = ps_timer_info->timer_id
                                [PH_LLCNFC_CONNECTION_TO_INDEX];
            break;
        }

        case PH_LLCNFC_GUARDTIMER:
        {
            uint8_t             start_index = 0;

            timer_count = ps_timer_info->guard_to_count;

            PH_LLCNFC_DEBUG("GUARD TIMER COUNT BEFORE DELETE: 0x%02X\n", timer_count);
            PH_LLCNFC_DEBUG("GUARD TIMER TO DELETE: 0x%02X\n", no_of_guard_to_del);

            if (timer_count > no_of_guard_to_del)
            {
                /* The number of guard timer count is more than the 
                    guard timer to delete  */
                while (start_index < no_of_guard_to_del)
                {
                    /* Copy the previous stored timer values to the present */
                    ps_timer_info->guard_to_value[start_index] = (uint16_t)
                                (ps_timer_info->guard_to_value[
                                (no_of_guard_to_del + start_index)]);

                    ps_timer_info->iframe_send_count[start_index] = (uint8_t)
                                (ps_timer_info->iframe_send_count[
                                (no_of_guard_to_del + start_index)]);

                    PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX DELETED : 0x%02X\n", ps_timer_info->timer_ns_value[start_index]);

                    ps_timer_info->timer_ns_value[start_index] = (uint8_t)
                                (ps_timer_info->timer_ns_value[
                                (no_of_guard_to_del + start_index)]);

                    ps_timer_info->frame_type[start_index] = (uint8_t)
                                (ps_timer_info->frame_type[
                                (no_of_guard_to_del + start_index)]);

                    start_index = (uint8_t)(start_index + 1);
                }
            }
            else
            {
                while (start_index < no_of_guard_to_del)
                {
                    ps_timer_info->guard_to_value[start_index] = 0;

                    ps_timer_info->iframe_send_count[start_index] = 0;

                    PH_LLCNFC_DEBUG("GUARD TIMER NS INDEX DELETED ELSE : 0x%02X\n", ps_timer_info->timer_ns_value[start_index]);

                    ps_timer_info->timer_ns_value[start_index] = 0;

                    ps_timer_info->frame_type[start_index] = 0;

                    start_index = (uint8_t)(start_index + 1);
                }
            }

            if (timer_count >= no_of_guard_to_del)
            {
                timer_count = (uint8_t)(timer_count - no_of_guard_to_del);
            }
            else
            {
                if (0 != no_of_guard_to_del)
                {
                    timer_count = 0;
                }
            }

            timerid = ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER];
            ps_timer_info->guard_to_count = timer_count;
            PH_LLCNFC_DEBUG("GUARD TIMER COUNT AFTER DELETE: 0x%02X\n", timer_count);

            if (0 == ps_timer_info->guard_to_count)
            {
                /* This means that there are no frames to run guard 
                    timer, so set the timer flag to 0 */
                ps_timer_info->timer_flag = (uint8_t)
                        SET_BITS8 (ps_timer_info->timer_flag, 
                                    PH_LLCNFC_GUARD_TO_BIT, 
                                    PH_LLCNFC_TO_NOOFBITS, 0);
            }
            else
            {
                timerflag = 0;
            }
            break;
        }  

#ifdef PIGGY_BACK
        case PH_LLCNFC_ACKTIMER:
        {
            ps_timer_info->timer_flag = (uint8_t)
                                SET_BITS8 (ps_timer_info->timer_flag, 
                                        PH_LLCNFC_GUARD_TO_BIT, 
                                        PH_LLCNFC_TO_NOOFBITS, 0);
            timerid = ps_timer_info->timer_id[PH_LLCNFC_ACKTIMER];
            break;
        }
#endif /* #ifdef PIGGY_BACK */

        default:
        {
            result = PHNFCSTVAL(CID_NFC_LLC, 
                                NFCSTATUS_INVALID_PARAMETER);
            break;
        }
    }

    if ((NFCSTATUS_SUCCESS == result) && (timerflag > 0))
    {
        PH_LLCNFC_DEBUG("OSAL STOP TIMER CALLED TIMER ID : 0x%02X\n", timerid);
        phOsalNfc_Timer_Stop (timerid);
    }

    PH_LLCNFC_PRINT("\n\nLLC : STOP TIMER END\n\n");

#else /* #ifdef LLC_TIMER_ENABLE */

    PHNFC_UNUSED_VARIABLE (result);
    PHNFC_UNUSED_VARIABLE (TimerType);
    PHNFC_UNUSED_VARIABLE (no_of_gaurd_to_del);

#endif /* #ifdef LLC_TIMER_ENABLE */
}
Example #9
0
/*Deactivation complete handler*/
void phHal4Nfc_HandleP2PDeActivate(
                               phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
                               void *pInfo
                               )
{
    pphHal4Nfc_ReceiveCallback_t pUpperRecvCb = NULL;
    pphHal4Nfc_SendCallback_t pUpperSendCb = NULL;
    phHal4Nfc_NotificationInfo_t uNotificationInfo;
    uNotificationInfo.psEventInfo = (phHal_sEventInfo_t *)pInfo;
    /*session is closed*/
    if(NULL != Hal4Ctxt->rem_dev_list[0])
    {
        Hal4Ctxt->rem_dev_list[0]->SessionOpened = FALSE;
        Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
    }
    Hal4Ctxt->sTgtConnectInfo.psConnectedDevice = NULL;
    /*Update state*/
    Hal4Ctxt->Hal4CurrentState = eHal4StateOpenAndReady;
    Hal4Ctxt->Hal4NextState  = eHal4StateInvalid;
    Hal4Ctxt->sTgtConnectInfo.EmulationState = NFC_EVT_DEACTIVATED;
    /*If Trcv ctxt info is allocated ,free it here*/
    if(NULL != Hal4Ctxt->psTrcvCtxtInfo)
    {
        if(PH_OSALNFC_INVALID_TIMER_ID != 
            Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId)
        {
            phOsalNfc_Timer_Stop(Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId);
            phOsalNfc_Timer_Delete(Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId);
        }
        pUpperRecvCb = Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb;
        pUpperSendCb = Hal4Ctxt->psTrcvCtxtInfo->pP2PSendCb;
        /*Free Hal4 resources used by Target*/
        if (NULL != Hal4Ctxt->psTrcvCtxtInfo->sLowerRecvData.buffer)
        {
            phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo->
                sLowerRecvData.buffer);
        }
        if((NULL == Hal4Ctxt->sTgtConnectInfo.psConnectedDevice) 
            && (NULL != Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData))
        {
            phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData);
        }  
        phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo);
        Hal4Ctxt->psTrcvCtxtInfo = NULL;
    }
    /*if recv callback is pending*/
    if(NULL != pUpperRecvCb)
    {
        (*pUpperRecvCb)(
                        Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
                        NULL,
                        NFCSTATUS_DESELECTED
                        );
    }  
    /*if send callback is pending*/
    else if(NULL != pUpperSendCb)
    {
        (*pUpperSendCb)(
                        Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
                        NFCSTATUS_DESELECTED
                        );
    }  
    /*if pP2PNotification is registered*/
    else if(NULL != Hal4Ctxt->sUpperLayerInfo.pP2PNotification)
    {
        (*Hal4Ctxt->sUpperLayerInfo.pP2PNotification)(
                                Hal4Ctxt->sUpperLayerInfo.P2PDiscoveryCtxt,
                                NFC_EVENT_NOTIFICATION,
                                uNotificationInfo,
                                NFCSTATUS_DESELECTED
                                );
    }
    else/*Call Default event handler*/
    {
        if(NULL != Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler)
        {
            Hal4Ctxt->sUpperLayerInfo.pDefaultEventHandler(
                Hal4Ctxt->sUpperLayerInfo.DefaultListenerCtxt,
                NFC_EVENT_NOTIFICATION,
                uNotificationInfo,
                NFCSTATUS_DESELECTED
                );
        }
    }
}
/*******************************************************************************
**
** Function         hal_read_cb
**
** Description      Callback function for hal read.
**
** Returns          None
**
*******************************************************************************/
static void hal_read_cb(void *pContext, phTmlNfc_TransactInfo_t *pInfo)
{
    phNxpNciHal_Sem_t *p_cb_data = (phNxpNciHal_Sem_t*) pContext;

    if(hal_write_timer_fired == 1)
    {
        NXPLOG_NCIHAL_D("hal_read_cb - response timeout occurred");

        hal_write_timer_fired = 0;
        p_cb_data->status = NFCSTATUS_RESPONSE_TIMEOUT;
    }
    else
    {
        NFCSTATUS status = phOsalNfc_Timer_Stop(timeoutTimerId);

        if (NFCSTATUS_SUCCESS == status)
        {
            NXPLOG_NCIHAL_D("Response timer stopped");
        }
        else
        {
            NXPLOG_NCIHAL_E("Response timer stop ERROR!!!");
            p_cb_data->status  = NFCSTATUS_FAILED;
        }

        if (pInfo->wStatus == NFCSTATUS_SUCCESS)
        {
            NXPLOG_NCIHAL_D("hal_read_cb successful status = 0x%x", pInfo->wStatus);
            p_cb_data->status = NFCSTATUS_SUCCESS;
        }
        else
        {
            NXPLOG_NCIHAL_E("hal_read_cb error status = 0x%x", pInfo->wStatus);
            p_cb_data->status = NFCSTATUS_FAILED;
        }

        p_cb_data->status = pInfo->wStatus;

        nci_test_data_t *test_data = (nci_test_data_t*) p_cb_data->pContext;

        if(test_data->exp_rsp.len == 0)
        {
            /* Compare the actual notification with expected notification.*/
            if( test_data->ntf_validator(&(test_data->exp_ntf),pInfo) == 1 )
            {
                p_cb_data->status = NFCSTATUS_SUCCESS;
            }
            else
            {
                p_cb_data->status = NFCSTATUS_FAILED;

            }
        }

        /* Compare the actual response with expected response.*/
        else if( test_data->rsp_validator(&(test_data->exp_rsp),pInfo) == 1)
        {
            p_cb_data->status = NFCSTATUS_SUCCESS;
        }
        else
        {
            p_cb_data->status = NFCSTATUS_FAILED;
        }
        test_data->exp_rsp.len = 0;
    }

    SEM_POST(p_cb_data);

    return;
}
NFCSTATUS
phNciNfc_ProcessConnCreditNtf(
                        void               *psContext,
                        void               *pInfo,
                        NFCSTATUS          wStatus
                    )
{
    NFCSTATUS                           status = NFCSTATUS_SUCCESS;
    pphNciNfc_CoreContext_t             pCoreCtx = (pphNciNfc_CoreContext_t)psContext;
    pphNciNfc_TransactInfo_t            pTransInfo = (pphNciNfc_TransactInfo_t)pInfo;
    phNciNfc_CoreGid_t                  tNtfGid;
    phNciNfc_CoreNciCoreNtfOid_t        tNtfOid;
    uint8_t                             bConnIdx;
    uint8_t                             bNewCredits = 0;
    uint8_t                             bNumOfEntries;
    uint8_t                             bEntrIdx;

    UNUSED(psContext);

    PH_LOG_NCI_FUNC_ENTRY();

    if( (NULL == pTransInfo) || (NULL == pCoreCtx) ||
        (NULL == pTransInfo->pbuffer) ||(0 == pTransInfo->wLength)
        || (PH_NCINFC_STATUS_OK != wStatus)
        )
    {
        status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_FAILED);
        PH_LOG_NCI_INFO_STR(" Conn Notification invalid..");
    }
    else
    {
        tNtfGid = pCoreCtx->tReceiveInfo.HeaderInfo.Group_ID;
        tNtfOid = pCoreCtx->tReceiveInfo.HeaderInfo.Opcode_ID.OidType.NciCoreNtfOid;

        if(phNciNfc_e_CoreNciCoreGid == tNtfGid)
        {
            if(phNciNfc_e_NciCoreConnCreditNtfOid == tNtfOid)
            {
                PH_LOG_NCI_INFO_STR(" Core ConnCredits Notification received..");
                bNumOfEntries = pTransInfo->pbuffer[0];

                for(bEntrIdx = 0; bEntrIdx < bNumOfEntries; bEntrIdx++)
                {
                    status = phNciNfc_GetConnIndex(pTransInfo->pbuffer[1], &bConnIdx);

                    if(NFCSTATUS_SUCCESS == status)
                    {
                        gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnIdx].tConn.bNumCredits += pTransInfo->pbuffer[2];

                        if(gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnIdx].tConn.bNumCredits > MAX_CREDITS_LIMIT)
                        {
                            gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnIdx].tConn.bNumCredits = MAX_CREDITS_LIMIT;
                            PH_LOG_NCI_INFO_STR(" Credits Limit xceeded for this Conn, Ignoring notif value ..");
                        }
                        else
                        {
                            PH_LOG_NCI_INFO_STR(" Credits updated for ConnId: 0x%x to 0x%x",
                                gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnIdx].tConn.bConnId,
                                gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnIdx].tConn.bNumCredits);
                        }

                        bNewCredits = gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnIdx].tConn.bNumCredits;
                    }
                    else
                    {
                        PH_LOG_NCI_INFO_X32MSG( " Failed to get Conn details for index..",bConnIdx);
                    }
                }
            }
            else
            {
                status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER);
                PH_LOG_NCI_INFO_STR(" Invalid Oid received..");
            }
        }
        else
        {
            status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER);
            PH_LOG_NCI_INFO_STR(" Invalid Gid received..");
        }
    }

    PH_LOG_NCI_INFO_STR("Credits awaited: %d, timerstatus: %d",
                        gphNciNfc_ConnMgmtInt.bCreditsAwaited,
                        gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus);

    /* Invoke the registered CB function if waiting for credits */
    if(TRUE == gphNciNfc_ConnMgmtInt.bCreditsAwaited)
    {
        if(gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus == 1)
        {
            PH_LOG_NCI_INFO_STR("Stopping Credit await timer..");

            (void)phOsalNfc_Timer_Stop(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId);
            (void)phOsalNfc_Timer_Delete(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId);

            gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus = 0;
            gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId = 0;
        }
        gphNciNfc_ConnMgmtInt.bCreditsAwaited = FALSE;

        if(NULL != gphNciNfc_ConnMgmtInt.pCrdtsNotify)
        {
            (void)(gphNciNfc_ConnMgmtInt.pCrdtsNotify)((gphNciNfc_ConnMgmtInt.pContext),bNewCredits,status);
        }
        else
        {
            PH_LOG_NCI_WARN_STR("No CB registered for credits availability!!");
        }
    }

    PH_LOG_NCI_FUNC_EXIT();

    return status;
}
/*******************************************************************************
**
** Function         phNxpNciHal_NfcDep_rsp_ext
**
** Description      Implements algorithm for NFC-DEP protocol priority over
**                  ISO-DEP protocol.
**                  Following the algorithm:
**                  IF ISO-DEP detected first time,set the ISO-DEP detected flag
**                  and resume polling loop with 60ms timeout value.
**                      a) if than NFC-DEP detected than send the response to
**                       libnfc-nci stack and stop the timer.
**                      b) if NFC-DEP not detected with in 60ms, than restart the
**                          polling loop to give early chance to ISO-DEP with a
**                          cleanup timer.
**                      c) if ISO-DEP detected second time send the response to
**                          libnfc-nci stack and stop the cleanup timer.
**                      d) if ISO-DEP not detected with in cleanup timeout, than
**                          clear the ISO-DEP detection flag.
**
** Returns          NFCSTATUS_SUCCESS if successful,otherwise NFCSTATUS_FAILED
**
*******************************************************************************/
NFCSTATUS phNxpNciHal_NfcDep_rsp_ext(uint8_t *p_ntf, uint16_t *p_len)
{
    NFCSTATUS status = NFCSTATUS_INVALID_PARAMETER;

    NXPLOG_NCIHAL_D(">> p_ntf[0]=%02x , p_ntf[1]=%02x",p_ntf[0],p_ntf[1]);

    if(p_ntf[0] == 0x41 && p_ntf[1] == 0x04)
    {
        //Tag selected, Disable P2P Prio logic.
        bIgnoreIsoDep = 1;
        NXPLOG_NCIHAL_D(">> Tag selected, Disable P2P Prio logic.");

    }
    else if( ((p_ntf[0] == 0x61 && p_ntf[1] == 0x06) ||
            (p_ntf[0] == 0x41 && p_ntf[1] == 0x06) ) && bIgnoreIsoDep == 1
            )
    {
        //Tag deselected, enable P2P Prio logic.
        bIgnoreIsoDep = 0x00;
        NXPLOG_NCIHAL_D(">> Tag deselected, enable P2P Prio logic.");

    }
    if (bIgnoreIsoDep == 0x00 &&
            p_ntf[0] == 0x61 &&
            p_ntf[1] == 0x05 && *p_len > 5)
    {
        if (p_ntf[5] == 0x04 && p_ntf[6] < 0x80)
        {
            NXPLOG_NCIHAL_D(">> ISO DEP detected.");

            if (iso_dep_detected == 0x00)
            {
                NXPLOG_NCIHAL_D(
                        ">> ISO DEP detected first time. Resume polling loop");

                iso_dep_detected = 0x01;
                status = phNxpNciHal_resume_polling_loop();

                custom_poll_timer = phOsalNfc_Timer_Create();
                NXPLOG_NCIHAL_D("custom poll timer started - %d", custom_poll_timer);

                status = phOsalNfc_Timer_Start(custom_poll_timer,
                        CUSTOM_POLL_TIMEOUT,
                        &custom_poll_timer_handler,
                        NULL);

                if (NFCSTATUS_SUCCESS == status)
                {
                    NXPLOG_NCIHAL_D("custom poll timer started");
                }
                else
                {
                    NXPLOG_NCIHAL_E("custom poll timer not started!!!");
                    status  = NFCSTATUS_FAILED;
                }

                status = NFCSTATUS_FAILED;
            }
            else
            {
                NXPLOG_NCIHAL_D(">> ISO DEP detected second time.");
                /* Store notification */
                phNxpNciHal_NfcDep_store_ntf(p_ntf, *p_len);

                /* Stop Cleanup_timer */
                phOsalNfc_Timer_Stop(cleanup_timer);
                phOsalNfc_Timer_Delete(cleanup_timer);
                cleanup_timer=0;
                EnableP2P_PrioLogic = FALSE;
                iso_dep_detected = 0;
                status = NFCSTATUS_SUCCESS;
            }
        }
        else if (p_ntf[5] == 0x05)
        {
            NXPLOG_NCIHAL_D(">> NFC-DEP Detected - stopping the custom poll timer");

            phOsalNfc_Timer_Stop(custom_poll_timer);
            phOsalNfc_Timer_Delete(custom_poll_timer);
            EnableP2P_PrioLogic = FALSE;
            iso_dep_detected = 0;
            status = NFCSTATUS_SUCCESS;
        }
        else
        {
            NXPLOG_NCIHAL_D(">>  detected other technology- stopping the custom poll timer");
            phOsalNfc_Timer_Stop(custom_poll_timer);
            phOsalNfc_Timer_Delete(custom_poll_timer);
            EnableP2P_PrioLogic = FALSE;
            iso_dep_detected = 0;
            status = NFCSTATUS_INVALID_PARAMETER;
        }
    }
    else if( bIgnoreIsoDep == 0x00 &&
            ((p_ntf[0] == 0x41 && p_ntf[1] == 0x06) || (p_ntf[0] == 0x61
            && p_ntf[1] == 0x06))
            )
    {
        NXPLOG_NCIHAL_D(">> RF disabled");
        if (poll_timer_fired == 0x01)
        {
            poll_timer_fired = 0x00;

            NXPLOG_NCIHAL_D(">>restarting polling loop.");

            /* start polling loop */
            phNxpNciHal_start_polling_loop();
            EnableP2P_PrioLogic = FALSE;
            NXPLOG_NCIHAL_D (">> NFC DEP NOT  detected - custom poll timer expired - RF disabled");

            cleanup_timer = phOsalNfc_Timer_Create();

            /* Start cleanup_timer */
            NFCSTATUS status = phOsalNfc_Timer_Start(cleanup_timer,
                    CLEAN_UP_TIMEOUT,
                    &cleanup_timer_handler,
                    NULL);

            if (NFCSTATUS_SUCCESS == status)
            {
                NXPLOG_NCIHAL_D("cleanup timer started");
            }
            else
            {
                NXPLOG_NCIHAL_E("cleanup timer not started!!!");
                status  = NFCSTATUS_FAILED;
            }

            status = NFCSTATUS_FAILED;
        }
        else
        {
            status = NFCSTATUS_SUCCESS;
        }
    }
    if (bIgnoreIsoDep == 0x00 &&
            iso_dep_detected == 1)
    {
        if ((p_ntf[0] == 0x41 && p_ntf[1] == 0x06) || (p_ntf[0] == 0x61
                && p_ntf[1] == 0x06))
        {
            NXPLOG_NCIHAL_D(">>iso_dep_detected Disconnect related notification");
            status = NFCSTATUS_FAILED;
        }
        else
        {
            NXPLOG_NCIHAL_W("Never come here");
        }
    }

    return status;
}
Example #13
0
static 
void 
phLlcNfc_ConnectionTimeoutCb (
    uint32_t TimerId,
    void *pContext
)
{
    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
    phNfc_sCompletionInfo_t     notifyinfo = {0};
    pphNfcIF_Notification_CB_t  notifyul = NULL;
    void                        *p_upperctxt = NULL;
    phLlcNfc_Frame_t            *ps_frame_info = NULL;
    phLlcNfc_Timerinfo_t        *ps_timer_info = NULL;
    PHNFC_UNUSED_VARIABLE(pContext);
    
    PH_LLCNFC_PRINT("\n\nLLC : CONNECTION TIMEOUT CB CALLED\n\n");
    if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == 
        gpphLlcNfc_Ctxt->s_timerinfo.timer_id[PH_LLCNFC_CONNECTIONTIMER]) 
        && (PH_LLCNFC_CON_TO_BIT_VAL == 
        (gpphLlcNfc_Ctxt->s_timerinfo.timer_flag & 
        PH_LLCNFC_CON_TO_BIT_VAL)))
    {
        ps_frame_info = &(gpphLlcNfc_Ctxt->s_frameinfo);
        ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);
        if (ps_timer_info->con_to_value > 0)
        {
#if !defined (CYCLIC_TIMER)
            phOsalNfc_Timer_Stop(
                    ps_timer_info->timer_id[PH_LLCNFC_CONNECTIONTIMER]);
            /* phLlcNfc_StopTimers(PH_LLCNFC_CONNECTIONTIMER, 0); */
#endif
            ps_timer_info->con_to_value = 0;
        
            if (0 == ps_timer_info->con_to_value)
            {
                PH_LLCNFC_DEBUG("TIMER EXPIRED RETRY COUNT : %02X\n", ps_frame_info->retry_cnt);
                phLlcNfc_StopTimers (PH_LLCNFC_CONNECTIONTIMER, 0);
                
                if (ps_frame_info->retry_cnt < PH_LLCNFC_MAX_RETRY_COUNT)
                {
                    /* Create a U frame */
                    result = phLlcNfc_H_CreateUFramePayload(gpphLlcNfc_Ctxt, 
                                        &(ps_frame_info->s_llcpacket),
                                        &(ps_frame_info->s_llcpacket.llcbuf_len), 
                                        phLlcNfc_e_rset);

                    if (NFCSTATUS_SUCCESS == result)
                    {
                        /* Call DAL write */
                        result = phLlcNfc_Interface_Write (gpphLlcNfc_Ctxt, 
                                (uint8_t*)&(ps_frame_info->s_llcpacket.s_llcbuf), 
                                (uint32_t)(ps_frame_info->s_llcpacket.llcbuf_len));
                    }
                    if (NFCSTATUS_PENDING == result)
                    {
                        /* Start the timer */
                        result = phLlcNfc_StartTimers(PH_LLCNFC_CONNECTIONTIMER, 0);
                        if (NFCSTATUS_SUCCESS == result)
                        {
                            ps_frame_info->retry_cnt++;
                            result = NFCSTATUS_PENDING;
                        }
                    }
                    else
                    {
                        if (NFCSTATUS_BUSY == PHNFCSTATUS(result))
                        {
                            result = NFCSTATUS_PENDING;
                        }
                    }
                }
                else
                {
                    PH_LLCNFC_PRINT("RETRY COUNT LIMIT REACHED \n");
                    if ((ps_frame_info->retry_cnt == PH_LLCNFC_MAX_RETRY_COUNT) 
                        && (NULL != gpphLlcNfc_Ctxt->cb_for_if.notify))
                    {
                        void            *p_hw_info = NULL;
                        uint8_t         type = 0;
                        
                        p_hw_info = gpphLlcNfc_Ctxt->phwinfo;
                        notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC, 
                                            NFCSTATUS_BOARD_COMMUNICATION_ERROR);
                        
                        notifyul = gpphLlcNfc_Ctxt->cb_for_if.notify;
                        p_upperctxt = gpphLlcNfc_Ctxt->cb_for_if.pif_ctxt;
                        type = NFC_NOTIFY_ERROR;
                        if (init_u_rset_frame == ps_frame_info->sent_frame_type)
                        {
                            type = NFC_NOTIFY_INIT_FAILED;
                            /* Release if, the initialisation is not complete */
                            result = phLlcNfc_Release(gpphLlcNfc_Ctxt, p_hw_info);
                            gpphLlcNfc_Ctxt = NULL;
                        }
                        else
                        {
                            type = NFC_NOTIFY_DEVICE_ERROR;
                            notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC, 
                                            NFCSTATUS_BOARD_COMMUNICATION_ERROR);
#if 0
                            phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); 
#endif /* #if 0 */
                        }
                        /* Notify the upper layer */
                        notifyul(p_upperctxt, p_hw_info, type, &notifyinfo);
                    }
                }
            }
#if !defined (CYCLIC_TIMER)
            else
            {
                /* Start the timer again */
                phOsalNfc_Timer_Start(
                            ps_timer_info->timer_id[PH_LLCNFC_CONNECTIONTIMER], 
                            ps_timer_info->con_to_value, phLlcNfc_ConnectionTimeoutCb, NULL);
            }
#endif
        }
    }
    PH_LLCNFC_PRINT("\n\nLLC : CONNECTION TIMEOUT CB END\n\n");
}
Example #14
0
static 
void 
phLlcNfc_GuardTimeoutCb (
    uint32_t TimerId,
    void *pContext
)
{
    NFCSTATUS                   result = NFCSTATUS_SUCCESS;
    phLlcNfc_Timerinfo_t        *ps_timer_info = NULL;
    phLlcNfc_Frame_t            *ps_frame_info = NULL;
    phLlcNfc_LlcPacket_t        *ps_packet_info = NULL;
    uint8_t                     index = 0;
    uint8_t                     zero_to_index = 0;
#if defined (GUARD_TO_ERROR)
    phNfc_sCompletionInfo_t     notifyinfo = {0};
#endif /* #if defined (GUARD_TO_ERROR) */
    PHNFC_UNUSED_VARIABLE(pContext);

    PH_LLCNFC_PRINT("\n\nLLC : GUARD TIMEOUT CB CALLED \n\n");

    if ((NULL != gpphLlcNfc_Ctxt) && (TimerId == 
        gpphLlcNfc_Ctxt->s_timerinfo.timer_id[PH_LLCNFC_GUARDTIMER]) && 
        (PH_LLCNFC_GUARD_TO_BIT_VAL == 
        (gpphLlcNfc_Ctxt->s_timerinfo.timer_flag & 
        PH_LLCNFC_GUARD_TO_BIT_VAL)))
    {
        uint8_t                 timer_expired = FALSE;
        ps_frame_info = &(gpphLlcNfc_Ctxt->s_frameinfo);
        ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);

#if !defined (CYCLIC_TIMER)
        phOsalNfc_Timer_Stop(
                    ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER]);
#endif

        PH_LLCNFC_DEBUG("NO OF TIMEOUT COUNT : 0x%02X\n", ps_timer_info->guard_to_count);
        /* Loop is completely depending on the number of different LLC  
           send called */
        while (index < ps_timer_info->guard_to_count) 
        {
            if (0 != ps_timer_info->guard_to_value[index])
            {
                if (ps_timer_info->guard_to_value[index] > 0)
                {
                    if (ps_timer_info->guard_to_value[index] >= 
                        PH_LLCNFC_RESOLUTION)
                    {
                        ps_timer_info->guard_to_value[index] = (uint16_t)
                            (ps_timer_info->guard_to_value[index] - 
                            PH_LLCNFC_RESOLUTION);
                    }
                    else
                    {
                        ps_timer_info->guard_to_value[index] = 0;
                    }
                }

                if (0 == ps_timer_info->guard_to_value[index])
                {
                    zero_to_index = index;
                    timer_expired = TRUE;
                }
            }
            index = (uint8_t)(index + 1);
        }

#if !defined (CYCLIC_TIMER)        
        /* Start the timer again */
        phOsalNfc_Timer_Start(
                    ps_timer_info->timer_id[PH_LLCNFC_GUARDTIMER], 
                    PH_LLCNFC_RESOLUTION, phLlcNfc_GuardTimeoutCb, NULL);
#endif
        PH_LLCNFC_DEBUG("TIMER EXPIRED : 0x%02X\n", timer_expired);        

        if (TRUE == timer_expired)
        {
            PH_LLCNFC_DEBUG("TIMER EXPIRED INDEX: 0x%02X\n", zero_to_index);
            PH_LLCNFC_DEBUG("TIMER EXPIRED NS INDEX: 0x%02X\n", ps_timer_info->timer_ns_value[zero_to_index]);
            PH_LLCNFC_DEBUG("TIMER EXPIRED RETRIES : 0x%02X\n", ps_timer_info->iframe_send_count[zero_to_index]);

            PH_LLCNFC_DEBUG("TIMER EXPIRED GUARD TIME-OUT COUNT: 0x%02X\n", ps_timer_info->guard_to_value[zero_to_index]);

            if ((0 == ps_timer_info->guard_to_value[zero_to_index]) && 
                (ps_timer_info->iframe_send_count[zero_to_index] < 
                LLC_GUARD_TIMER_RETRIES))
            {
                if (ps_frame_info->s_send_store.winsize_cnt > 0)
                {
                    uint8_t             start_index = 0;
                    uint8_t             timer_count = 0;
                    uint8_t             while_exit = FALSE;

                    timer_count = ps_timer_info->guard_to_count;

                    
                    /* Check before changing the index to resend, if index 
                        already exist then dont set the index */
                    while ((FALSE == while_exit) && (start_index < timer_count))
                    {
                        if (resend_i_frame == 
                            ps_timer_info->frame_type[start_index])
                        {
                            while_exit = TRUE;
                        }
                        else
                        {                     
                            start_index = (uint8_t)(start_index + 1);
                        }
                    }

                    if (TRUE == while_exit)
                    {
                        ps_timer_info->index_to_send = zero_to_index;
                    }

                    ps_timer_info->frame_type[zero_to_index] = (uint8_t)
                                                            resend_i_frame;
                    /* Now resend the frame stored */
                    result = phLlcNfc_H_SendTimedOutIFrame (gpphLlcNfc_Ctxt, 
                                            &(ps_frame_info->s_send_store), 
                                            0);
                }
            }
            else
            {
                if ((LLC_GUARD_TIMER_RETRIES == 
                    ps_timer_info->iframe_send_count[zero_to_index]) && 
                    (NULL != gpphLlcNfc_Ctxt->cb_for_if.notify))
                {
                    phLlcNfc_StopAllTimers ();
#if defined (GUARD_TO_ERROR)
                    
                    notifyinfo.status = PHNFCSTVAL(CID_NFC_LLC, 
                                        NFCSTATUS_BOARD_COMMUNICATION_ERROR);
#if 0
                    phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1); 
#endif /* #if 0 */
                    /* Resend done, no answer from the device */
                    gpphLlcNfc_Ctxt->cb_for_if.notify (
                                    gpphLlcNfc_Ctxt->cb_for_if.pif_ctxt,
                                    gpphLlcNfc_Ctxt->phwinfo, 
                                    NFC_NOTIFY_DEVICE_ERROR, 
                                    &notifyinfo);

#endif /* #if defined (GUARD_TO_ERROR) */

#if (!defined (GUARD_TO_ERROR) && defined (GUARD_TO_URSET))

                    PH_LLCNFC_PRINT("U-RSET IS SENT \n");
                    ps_packet_info = &(gpphLlcNfc_Ctxt->s_frameinfo.s_llcpacket);

                    result = phLlcNfc_H_CreateUFramePayload(gpphLlcNfc_Ctxt, 
                                        ps_packet_info, 
                                        &(ps_packet_info->llcbuf_len), 
                                        phLlcNfc_e_rset);

                    result = phLlcNfc_Interface_Write(gpphLlcNfc_Ctxt, 
                                    (uint8_t*)&(ps_packet_info->s_llcbuf), 
                                    (uint32_t)ps_packet_info->llcbuf_len);

                    ps_frame_info->write_status = result;
                    if (NFCSTATUS_PENDING == result)
                    {
                        /* Start the timer */
                        result = phLlcNfc_StartTimers (PH_LLCNFC_CONNECTIONTIMER, 0);
                        if (NFCSTATUS_SUCCESS == result)
                        {
                            ps_frame_info->retry_cnt = 0;
                            gpphLlcNfc_Ctxt->s_frameinfo.sent_frame_type = 
                                                                    u_rset_frame;
                            result = NFCSTATUS_PENDING;
                        }
                    }
                    else
                    {
                        if (NFCSTATUS_BUSY == PHNFCSTATUS (result))
                        {                        
                            ps_frame_info->write_wait_call = u_rset_frame;
                        }
                    }

#endif /* #if defined (GUARD_TO_ERROR) */
                }
            }
        }
    }
    PH_LLCNFC_PRINT("\n\nLLC : GUARD TIMEOUT CB END\n\n");
}
Example #15
0
void 
phLlcNfc_StopAllTimers (void)
{

#ifdef LLC_TIMER_ENABLE

    phLlcNfc_Timerinfo_t    *ps_timer_info = NULL;
    uint8_t                 timer_started = 0;
    uint32_t                timerid = 0;
    uint8_t                 timer_index = 0;
    

    ps_timer_info = &(gpphLlcNfc_Ctxt->s_timerinfo);

    PH_LLCNFC_PRINT("\n\nLLC : STOP ALL TIMERS CALLED \n\n");

    timerid = ps_timer_info->timer_id[timer_index];
    timer_started = (uint8_t)
                GET_BITS8(ps_timer_info->timer_flag, 
                        PH_LLCNFC_CON_TO_BIT, 
                        PH_LLCNFC_TO_NOOFBITS);

    PH_LLCNFC_DEBUG("CONNECTION TIMER ID: 0x%02X\n", timerid);

    if (0 != timer_started)
    {
        /* Connection timer is started, so now stop it */
        ps_timer_info->timer_flag = (uint8_t)
                        SET_BITS8 (ps_timer_info->timer_flag, 
                                    PH_LLCNFC_CON_TO_BIT, 
                                    PH_LLCNFC_TO_NOOFBITS, 0);
#if 0

        ps_timer_info->con_to_value = 0;

#endif /* #if 0 */

        phOsalNfc_Timer_Stop (timerid);
    }

    timer_index = (uint8_t)(timer_index + 1);
    timerid = ps_timer_info->timer_id[timer_index];
    timer_started = (uint8_t)GET_BITS8 (ps_timer_info->timer_flag, 
                                        PH_LLCNFC_GUARD_TO_BIT, 
                                        PH_LLCNFC_TO_NOOFBITS);

    if (0 != timer_started)
    {
        /* Guard timer is already started */
        ps_timer_info->timer_flag = (uint8_t)
                        SET_BITS8 (ps_timer_info->timer_flag, 
                                    PH_LLCNFC_GUARD_TO_BIT, 
                                    PH_LLCNFC_TO_NOOFBITS, 0);

        timer_index = 0;
        ps_timer_info->guard_to_count = 0;

#if 0

        /* Reset all the guard timer related variables */
        while (timer_index < ps_timer_info->guard_to_count)
        {            
            ps_timer_info->guard_to_value[timer_index] = 0;
            ps_timer_info->iframe_send_count[timer_index] = 0;

            timer_index = (uint8_t)(timer_index + 1);
        }        

#endif /* #if 0 */

        PH_LLCNFC_DEBUG("GUARD TIMER ID: 0x%02X\n", timerid);

        /* Stop the timer */
        phOsalNfc_Timer_Stop (timerid);

        PH_LLCNFC_PRINT("\n\nLLC : STOP ALL TIMERS END \n\n");
    }

#endif /* #ifdef LLC_TIMER_ENABLE */
}
/*******************************************************************************
**
** Function         phTmlNfc_TmlThread
**
** Description      Read the data from the lower layer driver
**
** Parameters       pParam  - parameters for Writer thread function
**
** Returns          None
**
*******************************************************************************/
static void phTmlNfc_TmlThread(void *pParam)
{
    NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
    int32_t dwNoBytesWrRd = PH_TMLNFC_RESET_VALUE;
    uint8_t temp[260];
    /* Transaction info buffer to be passed to Callback Thread */
    static phTmlNfc_TransactInfo_t tTransactionInfo;
    /* Structure containing Tml callback function and parameters to be invoked
       by the callback thread */
    static phLibNfc_DeferredCall_t tDeferredInfo;
    /* Initialize Message structure to post message onto Callback Thread */
    static phLibNfc_Message_t tMsg;
    UNUSED(pParam);
    NXPLOG_TML_D("PN54X - Tml Reader Thread Started................\n");

    /* Writer thread loop shall be running till shutdown is invoked */
    while (gpphTmlNfc_Context->bThreadDone)
    {
        /* If Tml write is requested */
        /* Set the variable to success initially */
        wStatus = NFCSTATUS_SUCCESS;
        sem_wait(&gpphTmlNfc_Context->rxSemaphore);

        /* If Tml read is requested */
        if (1 == gpphTmlNfc_Context->tReadInfo.bEnable)
        {
            NXPLOG_TML_D("PN54X - Read requested.....\n");
            /* Set the variable to success initially */
            wStatus = NFCSTATUS_SUCCESS;

            /* Variable to fetch the actual number of bytes read */
            dwNoBytesWrRd = PH_TMLNFC_RESET_VALUE;

            /* Read the data from the file onto the buffer */
            if (NFCSTATUS_INVALID_DEVICE != (uintptr_t)gpphTmlNfc_Context->pDevHandle)
            {
                NXPLOG_TML_D("PN54X - Invoking I2C Read.....\n");
                dwNoBytesWrRd = phTmlNfc_i2c_read(gpphTmlNfc_Context->pDevHandle, temp, 260);

                if (-1 == dwNoBytesWrRd)
                {
                    NXPLOG_TML_E("PN54X - Error in I2C Read.....\n");
                    sem_post(&gpphTmlNfc_Context->rxSemaphore);
                }
                else if(dwNoBytesWrRd > 260)
                {
                    NXPLOG_TML_E("Numer of bytes read exceeds the limit 260.....\n");
                    sem_post(&gpphTmlNfc_Context->rxSemaphore);
                }
                else
                {
                    memcpy(gpphTmlNfc_Context->tReadInfo.pBuffer, temp, dwNoBytesWrRd);

                    NXPLOG_TML_D("PN54X - I2C Read successful.....\n");
                    /* This has to be reset only after a successful read */
                    gpphTmlNfc_Context->tReadInfo.bEnable = 0;
                    if ((phTmlNfc_e_EnableRetrans == gpphTmlNfc_Context->eConfig) &&
                            (0x00 != (gpphTmlNfc_Context->tReadInfo.pBuffer[0] & 0xE0)))
                    {

                        NXPLOG_TML_D("PN54X - Retransmission timer stopped.....\n");
                        /* Stop Timer to prevent Retransmission */
                        uint32_t timerStatus = phOsalNfc_Timer_Stop(gpphTmlNfc_Context->dwTimerId);
                        if (NFCSTATUS_SUCCESS != timerStatus)
                        {
                            NXPLOG_TML_E("PN54X - timer stopped returned failure.....\n");
                        }
                        else
                        {
                            gpphTmlNfc_Context->bWriteCbInvoked = FALSE;
                        }
                    }
                    /* Update the actual number of bytes read including header */
                    gpphTmlNfc_Context->tReadInfo.wLength = (uint16_t) (dwNoBytesWrRd);
                    phNxpNciHal_print_packet("RECV", gpphTmlNfc_Context->tReadInfo.pBuffer,
                            gpphTmlNfc_Context->tReadInfo.wLength);

                    dwNoBytesWrRd = PH_TMLNFC_RESET_VALUE;

                    /* Fill the Transaction info structure to be passed to Callback Function */
                    tTransactionInfo.wStatus = wStatus;
                    tTransactionInfo.pBuff = gpphTmlNfc_Context->tReadInfo.pBuffer;
                    /* Actual number of bytes read is filled in the structure */
                    tTransactionInfo.wLength = gpphTmlNfc_Context->tReadInfo.wLength;

                    /* Read operation completed successfully. Post a Message onto Callback Thread*/
                    /* Prepare the message to be posted on User thread */
                    tDeferredInfo.pCallback = &phTmlNfc_ReadDeferredCb;
                    tDeferredInfo.pParameter = &tTransactionInfo;
                    tMsg.eMsgType = PH_LIBNFC_DEFERREDCALL_MSG;
                    tMsg.pMsgData = &tDeferredInfo;
                    tMsg.Size = sizeof(tDeferredInfo);
                    NXPLOG_TML_D("PN54X - Posting read message.....\n");
                    phTmlNfc_DeferredCall(gpphTmlNfc_Context->dwCallbackThreadId, &tMsg);

                }
            }
            else
            {
                NXPLOG_TML_D("PN54X - NFCSTATUS_INVALID_DEVICE == gpphTmlNfc_Context->pDevHandle");
            }
        }
        else
        {
            NXPLOG_TML_D("PN54X - read request NOT enabled");
            usleep(10*1000);
        }
    }/* End of While loop */

    return;
}
/*Deactivation complete handler*/
void phHal4Nfc_HandleCEDeActivate(
                               phHal4Nfc_Hal4Ctxt_t  *Hal4Ctxt,
                               void *pInfo
                               )
{
    pphLibNfc_LibContext_t pLibContext=(pphLibNfc_LibContext_t)Hal4Ctxt->sUpperLayerInfo.HCEEventNotificationCtxt;

    pphHal4Nfc_TransceiveCallback_t pUpperRecvCb = NULL;
    pphHal4Nfc_SendCallback_t pUpperSendCb = NULL;
    phHal4Nfc_NotificationInfo_t uNotificationInfo;
    uNotificationInfo.psEventInfo = (phHal_sEventInfo_t *)pInfo;
    uint32_t handle=0;
    /*session is closed*/
    if(NULL != Hal4Ctxt->rem_dev_list[0])
    {
        if(Hal4Ctxt->rem_dev_list[0]->RemoteDevInfo.Iso14443_4_PCD_Info.buffer != NULL)
        {
          phOsalNfc_FreeMemory((void *)(Hal4Ctxt->rem_dev_list[0]->RemoteDevInfo.Iso14443_4_PCD_Info.buffer));
          Hal4Ctxt->rem_dev_list[0]->RemoteDevInfo.Iso14443_4_PCD_Info.buffer = NULL;
        }
        Hal4Ctxt->rem_dev_list[0]->RemoteDevInfo.Iso14443_4_PCD_Info.length = 0;
        Hal4Ctxt->rem_dev_list[0]->SessionOpened = FALSE;
        handle = (uint32_t)Hal4Ctxt->rem_dev_list[0];
        Hal4Ctxt->rem_dev_list[0] = NULL;
        Hal4Ctxt->psADDCtxtInfo->nbr_of_devices = 0;
    }
    Hal4Ctxt->sTgtConnectInfo.psConnectedDevice = NULL;
    gpphLibContext->Connected_handle = 0x0000;
    /*Update state*/
    Hal4Ctxt->Hal4CurrentState = eHal4StateOpenAndReady;
    Hal4Ctxt->Hal4NextState  = eHal4StateInvalid;
    Hal4Ctxt->sTgtConnectInfo.EmulationState = NFC_EVT_DEACTIVATED;
    /*If Trcv ctxt info is allocated ,free it here*/
    if(NULL != Hal4Ctxt->psTrcvCtxtInfo)
    {
        if(PH_OSALNFC_INVALID_TIMER_ID !=
            Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId)
        {
            phOsalNfc_Timer_Stop(Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId);
            phOsalNfc_Timer_Delete(Hal4Ctxt->psTrcvCtxtInfo->TransactionTimerId);
        }
        pUpperRecvCb = (pphHal4Nfc_TransceiveCallback_t)Hal4Ctxt->psTrcvCtxtInfo->pP2PRecvCb;
        pUpperSendCb = Hal4Ctxt->psTrcvCtxtInfo->pP2PSendCb;
        /*Free Hal4 resources used by Target*/
        if (NULL != Hal4Ctxt->psTrcvCtxtInfo->sLowerRecvData.buffer)
        {
            phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo->
                sLowerRecvData.buffer);
        }
        if((NULL == Hal4Ctxt->sTgtConnectInfo.psConnectedDevice)
            && (NULL != Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData))
        {
            phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo->psUpperSendData);
        }
        phOsalNfc_FreeMemory(Hal4Ctxt->psTrcvCtxtInfo);
        Hal4Ctxt->psTrcvCtxtInfo = NULL;
    }
    /*if recv callback is pending*/
    if(NULL != pUpperRecvCb)
    {
        (*pUpperRecvCb)(
                        Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
                        Hal4Ctxt->sTgtConnectInfo.psConnectedDevice,
                        NULL,
                        NFCSTATUS_DESELECTED
                        );
    }
    /*if send callback is pending*/
    else if(NULL != pUpperSendCb)
    {
        (*pUpperSendCb)(
                        Hal4Ctxt->sUpperLayerInfo.psUpperLayerCtxt,
                        NFCSTATUS_DESELECTED
                        );
    }
    /*if CENotification is registered*/
    else if(NULL != pLibContext->sCeContext.pCeListenerNtfCb)
    {
      if(uNotificationInfo.psEventInfo->eventSource==phHal_eISO14443_A_PICC)
      {
        (*pLibContext->sCeContext.pCeListenerNtfCb)(
                            pLibContext->sCeContext.pCeListenerCtxt,
                            phLibNfc_eCE_A_EvtDeActivated,
                            handle,
                            NFCSTATUS_SUCCESS);
      }
      else
      {
        (*pLibContext->sCeContext.pCeListenerNtfCb)(
                            pLibContext->sCeContext.pCeListenerCtxt,
                            phLibNfc_eCE_B_EvtDeActivated,
                            handle,
                            NFCSTATUS_SUCCESS);
      }
    }
}