void phNxpNciHal_TestMode_close ()
{

    NFCSTATUS status = NFCSTATUS_SUCCESS;

    CONCURRENCY_LOCK();

    if (NULL != gpphTmlNfc_Context->pDevHandle)
    {
        /* Abort any pending read and write */
        status = phTmlNfc_ReadAbort();
        status = phTmlNfc_WriteAbort();

        phOsalNfc_Timer_Cleanup();

        status = phTmlNfc_Shutdown();

        NXPLOG_NCIHAL_D("phNxpNciHal_close return status = %d", status);

        thread_running = 0;

        phDal4Nfc_msgrelease(gDrvCfg.nClientId);

        status = phOsalNfc_Timer_Delete(timeoutTimerId);
    }

    CONCURRENCY_UNLOCK();

    phNxpNciHal_cleanup_monitor();

    /* Return success always */
    return;
}
/*******************************************************************************
**
** Function         custom_poll_timer_handler
**
** Description      Callback function for custom poll timer.
**
** Returns          None
**
*******************************************************************************/
static void custom_poll_timer_handler(uint32_t timerId, void *pContext)
{
    NXPLOG_NCIHAL_D(">> custom_poll_timer_handler.");

    NXPLOG_NCIHAL_D(">> custom_poll_timer_handler. NFC_DEP not detected. so giving early chance to ISO_DEP.");

    phOsalNfc_Timer_Delete(custom_poll_timer);

    if (iso_dep_detected == 0x01)
    {
        poll_timer_fired = 0x01;

        /*
         * Restart polling loop.
         * When the polling loop is stopped, polling will be restarted.
         */
        NXPLOG_NCIHAL_D(">> custom_poll_timer_handler - restart polling loop.");

        phNxpNciHal_stop_polling_loop();
    }
    else
    {
        NXPLOG_NCIHAL_E(">> custom_poll_timer_handler - invalid flag state (iso_dep_detected)");
    }

    return;
}
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;
}
/*******************************************************************************
**
** Function         cleanup_timer_handler
**
** Description      Callback function for cleanup timer.
**
** Returns          None
**
*******************************************************************************/
static void cleanup_timer_handler(uint32_t timerId, void *pContext)
{
    NXPLOG_NCIHAL_D(">> cleanup_timer_handler.");

    NXPLOG_NCIHAL_D(">> cleanup_timer_handler. ISO_DEP not detected second time.");

    phOsalNfc_Timer_Delete(cleanup_timer);
    cleanup_timer=0;
    iso_dep_detected = 0x00;
    EnableP2P_PrioLogic = FALSE;
    return;
}
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));
}
Esempio n. 6
0
void 
phLlcNfc_DeleteTimer (void)
{
    uint8_t     index = 0;
    while (index < PH_LLCNFC_MAX_TIMER_USED)
    {
#ifdef LLC_TIMER_ENABLE
        phOsalNfc_Timer_Delete(
            gpphLlcNfc_Ctxt->s_timerinfo.timer_id[index]);
        gpphLlcNfc_Ctxt->s_timerinfo.timer_id[index] = 
                            PH_OSALNFC_INVALID_TIMER_ID;                            
#endif /* #ifdef LLC_TIMER_ENABLE */
        index++;
    }
}
Esempio n. 7
0
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;
}
void phOsalNfc_Timer_DeInit(void)
{
    uint32_t i = 0;

    if (gpphOsalNfc_Context != NULL)
    {
        EnterCriticalSection(&gpphOsalNfc_Context->TimerLock);

        while (i < PH_MAX_OSAL_NUM_TIMERS) 
        {
            if(gpphOsalNfc_Context->TimerList[i].pTimer != NULL)
            {
                PH_LOG_OSAL_INFO_STR("TimerId=%d forced cleanup", i);
                phOsalNfc_Timer_Delete(i + PH_OSAL_TIMER_BASE_ADDRESS);
            }

            i++;
        }

        LeaveCriticalSection(&gpphOsalNfc_Context->TimerLock);
        DeleteCriticalSection(&gpphOsalNfc_Context->TimerLock);
    }
}
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;
}
/*******************************************************************************
**
** 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;
}
/*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);
      }
    }
}
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;
}
NFCSTATUS phNciNfc_RegForConnCredits(
                                     uint8_t bConnId,
                                     pphNciNfc_ConnCreditsNtf_t pNotify,
                                     void *pContext,
                                     uint32_t CreditTo
                                     )
{
    NFCSTATUS wStatus = NFCSTATUS_SUCCESS;
    uint8_t     bConnListIdx;
    uint32_t TimerId;

    PH_LOG_NCI_FUNC_ENTRY();

    if((NULL == pNotify) || (NULL == pContext))
    {
        wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER);
        PH_LOG_NCI_INFO_STR(" Invalid Caller Layer Param(s) received ..");
    }
    else
    {
        for(bConnListIdx = 0; bConnListIdx < (MAX_LOGICAL_CONNS+1) ; bConnListIdx++)
        {
            if(bConnId == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId)
            {
                if((TRUE == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].bIfActive) ||
                    (CONNTYPE_STATIC == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId))
                {
                    wStatus = NFCSTATUS_SUCCESS;
                }
                else
                {
                    PH_LOG_NCI_CRIT_STR(" Interface not active for this connection");
                    wStatus = NFCSTATUS_FAILED;
                }
                break;
            }
        }

        if(NFCSTATUS_SUCCESS == wStatus)
        {
            gphNciNfc_ConnMgmtInt.bConnId = bConnId;
            gphNciNfc_ConnMgmtInt.pCrdtsNotify = pNotify;
            gphNciNfc_ConnMgmtInt.pContext = pContext;

            TimerId = phOsalNfc_Timer_Create();

            if (0 == TimerId)
            {
                PH_LOG_NCI_WARN_STR("Credit wait Timer Create failed!!");
                wStatus = NFCSTATUS_INSUFFICIENT_RESOURCES;
            }
            else
            {
                PH_LOG_NCI_INFO_STR("Credit wait Timer Created Successfully");

                gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId = TimerId;
                gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus = 0;

                PH_LOG_NCI_INFO_STR("Credit timeout set to %d, for ConnId 0x%x",CreditTo, bConnId);

                wStatus = phOsalNfc_Timer_Start(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId,
                                                CreditTo,
                                                &phNciNfc_WaitCreditTimerCb,
                                                &gphNciNfc_ConnMgmtInt);

                if (NFCSTATUS_SUCCESS == wStatus)
                {
                    PH_LOG_NCI_INFO_STR("Credit wait timer started..");
                    gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus = 1;
                    /* Set the CreditsAwaited flag to indicate credit notif function to call the registered CB */
                    gphNciNfc_ConnMgmtInt.bCreditsAwaited = TRUE;
                }
                else
                {
                     PH_LOG_NCI_WARN_STR("Failed to start credit ntf wait timer!");
                     (void )phOsalNfc_Timer_Delete(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId);
                     gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId = 0;
                     wStatus = NFCSTATUS_FAILED;
                }
            }
        }
    }

    PH_LOG_NCI_FUNC_EXIT();

    return wStatus;
}
Esempio n. 15
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
                );
        }
    }
}