NFCSTATUS
phNciNfc_SeSendData(void* pNciCtx,
                    void* pSeHandle,
                    pphNciNfc_IfNotificationCb_t pSendCb,
                    void* pContext,
                    phNfc_sData_t *pSendData)
{
    NFCSTATUS               wStatus = NFCSTATUS_SUCCESS;
    phNciNfc_CoreTxInfo_t   TxInfo;
    uint16_t                wPldDataSize;
    phNciNfc_Context_t* pNciContext = (phNciNfc_Context_t *)pNciCtx;

    PH_LOG_NCI_FUNC_ENTRY();
    if((NULL == pNciContext) || (pNciContext != phNciNfc_GetContext()))
    {
        PH_LOG_NCI_CRIT_STR("Stack not initialized");
        wStatus = NFCSTATUS_NOT_INITIALISED;
    }
    else if((NULL == pSendData) || (NULL == pSendCb))
    {
        wStatus = NFCSTATUS_INVALID_PARAMETER;
        PH_LOG_NCI_CRIT_STR("Invalid input parameter!");
    }
    else
    {
        if((0 == pSendData->length) || (NULL == pSendData->buffer))
        {
            PH_LOG_NCI_CRIT_STR("Invalid Send buffer!");
            wStatus = NFCSTATUS_FAILED;
        }
        else
        {
            /* Fill the data packet details into TxInfo */
            TxInfo.tHeaderInfo.eMsgType = phNciNfc_e_NciCoreMsgTypeData;
            if (!phNciNfc_IsVersion1x(pNciContext))
            {
                TxInfo.tHeaderInfo.bConn_ID = CONNHCITYPE_STATIC;
            }
            else
            {
                wStatus = phNciNfc_GetConnId(pSeHandle, &(TxInfo.tHeaderInfo.bConn_ID));
            }

            if(NFCSTATUS_SUCCESS == wStatus)
            {
                wPldDataSize = (uint16_t)pSendData->length;

                (pNciContext->tTranscvCtxt.tSendPld.wLen) = 0;
                (pNciContext->tTranscvCtxt.tSendPld.pBuff) = (uint8_t *)phOsalNfc_GetMemory(wPldDataSize);

                if(NULL != (pNciContext->tTranscvCtxt.tSendPld.pBuff))
                {
                    (pNciContext->tTranscvCtxt.tSendPld.wLen) = (wPldDataSize);
                    phOsalNfc_SetMemory((pNciContext->tTranscvCtxt.tSendPld.pBuff),0,
                        (pNciContext->tTranscvCtxt.tSendPld.wLen));

                    /* Copy data to be sent to the local buffer */
                    phOsalNfc_MemCopy((pNciContext->tTranscvCtxt.tSendPld.pBuff),
                        (pSendData->buffer),wPldDataSize);

                    TxInfo.Buff = (pNciContext->tTranscvCtxt.tSendPld.pBuff);
                    TxInfo.wLen = (pNciContext->tTranscvCtxt.tSendPld.wLen);

                    /* Send data */
                    wStatus = phNciNfc_CoreIfTxOnly(&(pNciContext->NciCoreContext), &TxInfo,
                                (pphNciNfc_CoreIfNtf_t)&phNciNfc_SeSendCb, pNciContext);
                    if(NFCSTATUS_PENDING == wStatus)
                    {
                        /* Store upper layer call back function and upper layer context */
                        phNciNfc_SetUpperLayerCallback(pNciContext, pSendCb, pContext);
                    }
                    else
                    {
                        /* Deallocate memory allcoated for send buffer */
                        phOsalNfc_FreeMemory(pNciContext->tTranscvCtxt.tSendPld.pBuff);
                        pNciContext->tTranscvCtxt.tSendPld.pBuff = NULL;
                        pNciContext->tTranscvCtxt.tSendPld.wLen = 0;
                    }
                }
                else
                {
                    wStatus = NFCSTATUS_INSUFFICIENT_RESOURCES;
                    PH_LOG_NCI_CRIT_STR("Payload MemAlloc for Send request Failed!");
                }
            }
            else
            {
                wStatus = NFCSTATUS_FAILED;
                PH_LOG_NCI_CRIT_STR(" Couldn't Get ConnId!");
            }
        }
    }
    PH_LOG_NCI_FUNC_EXIT();
    return wStatus;
}
NFCSTATUS
phNciNfc_Send4BData(
                    void   *psContext
                    )
{
    NFCSTATUS               status = NFCSTATUS_SUCCESS;
    phNciNfc_CoreTxInfo_t   TxInfo;
    uint16_t                wPldDataSize = 0;

    phNciNfc_Context_t *psNciContext = (phNciNfc_Context_t *)psContext;

    PH_LOG_NCI_FUNC_ENTRY();

    if( (NULL == psNciContext) )
    {
        status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER);
        PH_LOG_NCI_INFO_STR(" Invalid Context Param..");
    }
    else if(NULL == (psNciContext->tActvDevIf.pDevInfo))
    {
        status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_DEVICE);
        PH_LOG_NCI_INFO_STR(" Invalid Device..");
    }
    else
    {
        pphNciNfc_RemoteDevInformation_t  pActivDev = NULL;

        pActivDev = (psNciContext->tActvDevIf.pDevInfo);

        if(0 != (psNciContext->tTranscvCtxt.tTranscvInfo.tSendData.wLen))
        {
            /* Fill the data packet details into TxInfo */
            TxInfo.tHeaderInfo.eMsgType = phNciNfc_e_NciCoreMsgTypeData;
            status = phNciNfc_GetConnId(pActivDev, &(TxInfo.tHeaderInfo.bConn_ID));

            if(NFCSTATUS_SUCCESS == status)
            {
                wPldDataSize = (psNciContext->tTranscvCtxt.tTranscvInfo.tSendData.wLen);

                (psNciContext->tTranscvCtxt.tSendPld.wLen) = 0;
                (psNciContext->tTranscvCtxt.tSendPld.pBuff) = (uint8_t *)phOsalNfc_GetMemory(wPldDataSize);

                if(NULL != (psNciContext->tTranscvCtxt.tSendPld.pBuff))
                {
                    (psNciContext->tTranscvCtxt.tSendPld.wLen) = (wPldDataSize);
                    phOsalNfc_SetMemory((psNciContext->tTranscvCtxt.tSendPld.pBuff),0,
                        (psNciContext->tTranscvCtxt.tSendPld.wLen));

                    if(0 != wPldDataSize)
                    {
                        phOsalNfc_MemCopy((psNciContext->tTranscvCtxt.tSendPld.pBuff),
                            (psNciContext->tTranscvCtxt.tTranscvInfo.tSendData.pBuff),wPldDataSize);
                    }
                    PH_LOG_NCI_INFO_STR(" 4B Payload created successfully..");

                    TxInfo.Buff = (psNciContext->tTranscvCtxt.tSendPld.pBuff);
                    TxInfo.wLen = (psNciContext->tTranscvCtxt.tSendPld.wLen);
                    status = phNciNfc_CoreIfTxRx(&(psNciContext->NciCoreContext), &TxInfo,
                        &(psNciContext->RspBuffInfo), psNciContext->tTranscvCtxt.tTranscvInfo.wTimeout,
                        (pphNciNfc_CoreIfNtf_t)&phNciNfc_RdrDataXchgSequence, psContext);
                    /* Clear the timeout value so that it wont be used mistakenly in subsequent transceive */
                    psNciContext->tTranscvCtxt.tTranscvInfo.wTimeout = 0;
                }
                else
                {
                    status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INSUFFICIENT_RESOURCES);
                    PH_LOG_NCI_INFO_STR(" Payload MemAlloc for Send request Failed..");
                }
            }
            else
            {
                status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_FAILED);
                PH_LOG_NCI_INFO_STR(" Couldn't Get ConnId..");
            }
        }
        else
        {
            status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_FAILED);
            PH_LOG_NCI_INFO_STR(" Send Data Buff not valid..");
        }
    }
    PH_LOG_NCI_FUNC_EXIT();

    return status;
}
NFCSTATUS
phNciNfc_ReceiveData(void *pNciCtx,
                     pphNciNfc_IfNotificationCb_t pReceiveCb,
                     void* pContext)
{
    NFCSTATUS wStatus = NFCSTATUS_NOT_INITIALISED;
    phNciNfc_Context_t *pNciContext = (phNciNfc_Context_t *)pNciCtx;
    pphNciNfc_ActiveDeviceInfo_t  pActivDev = NULL;
    phNciNfc_sCoreHeaderInfo_t tRegInfo;
    uint8_t                 bConnId;
    uint8_t bFreeTempBuff = 0;

    PH_LOG_NCI_FUNC_ENTRY();
    if((NULL == pNciContext) || (pNciContext != phNciNfc_GetContext()))
    {
        PH_LOG_NCI_CRIT_STR("Stack not initialized");
    }
    else if(NULL == pReceiveCb)
    {
        wStatus = NFCSTATUS_INVALID_PARAMETER;
        PH_LOG_NCI_CRIT_STR("Invalid input parameter (Nci Context)!");
    }
    else
    {
        /* Store upper layer call back function and upper layer context */
        phNciNfc_SetUpperLayerCallback(pNciContext, pReceiveCb, pContext);

        /* Check whether data has been received from remote device already */
        if(1 == pNciContext->tLstnModeRecvInfo.bDataBuffEnable)
        {
            /* Data has already been received and stored in temporary buffer.
            Instead of registering for the data message which has already been received,
            queue a deferred callback */

            wStatus = phOsalNfc_QueueDeferredCallback(phNciNfc_TempReceiveCb,
                                                      pNciContext);
            if(NFCSTATUS_SUCCESS == wStatus)
            {
                wStatus = NFCSTATUS_PENDING;
            }
            else
            {
                bFreeTempBuff = 1;
            }

            pNciContext->tLstnModeRecvInfo.bDataBuffEnable = 0;

            if(1 == bFreeTempBuff)
            {
                pNciContext->IfNtf = NULL;
                pNciContext->IfNtfCtx = NULL;
                if(NULL != pNciContext->tLstnModeRecvInfo.pBuff)
                {
                    phOsalNfc_FreeMemory(pNciContext->tLstnModeRecvInfo.pBuff);
                    pNciContext->tLstnModeRecvInfo.pBuff = NULL;
                }
                pNciContext->tLstnModeRecvInfo.wBuffSize = 0;
                pNciContext->tLstnModeRecvInfo.wLstnCbStatus = NFCSTATUS_FAILED;
            }
        }
        else
        {
            pActivDev = (pphNciNfc_ActiveDeviceInfo_t)&pNciContext->tActvDevIf;

            wStatus = phNciNfc_GetConnId(pActivDev->pDevInfo,&bConnId);
            /* If dummy data receive call back function is still registered, unregister the same first*/
            if(NFCSTATUS_SUCCESS == wStatus)
            {
                tRegInfo.bConn_ID = bConnId;
                tRegInfo.eMsgType = phNciNfc_e_NciCoreMsgTypeData;
                /* UnRegister for Data message (with auto de-register enabled) */
                (void)phNciNfc_CoreIfUnRegRspNtf(&(pNciContext->NciCoreContext),
                    &(tRegInfo),&phNciNfc_ReceiveDataBufferCb);
            }
            /*Now register for the data message */
            if(NFCSTATUS_SUCCESS == wStatus)
            {
                tRegInfo.bEnabled = (uint8_t)PHNCINFC_ENABLE_AUTO_DEREG;
                tRegInfo.eMsgType = phNciNfc_e_NciCoreMsgTypeData;
                tRegInfo.bConn_ID= bConnId;

                /* Register for Data message (with auto de-register enabled) */
                wStatus = phNciNfc_CoreIfRegRspNtf((void *)&pNciContext->NciCoreContext,
                                         &tRegInfo,
                                         &phNciNfc_ReceiveCb,
                                         pNciContext);
                if(NFCSTATUS_SUCCESS == wStatus)
                {
                   /* Data message call back registered successfully, send pending status to upper layer */
                   wStatus = NFCSTATUS_PENDING;
                }
                else
                {
                    pNciContext->IfNtf = NULL;
                    pNciContext->IfNtfCtx = NULL;
                    PH_LOG_NCI_CRIT_STR("Data message call back registration failed!");
                    wStatus = NFCSTATUS_FAILED;
                }
            }
            else
            {
                pNciContext->IfNtf = NULL;
                pNciContext->IfNtfCtx = NULL;
                PH_LOG_NCI_CRIT_STR("Couldn't Get ConnId!");
                wStatus = NFCSTATUS_FAILED;
            }
        }
    }
    PH_LOG_NCI_FUNC_EXIT();
    return wStatus;
}