diff options
author | Nick Pelly <npelly@google.com> | 2010-09-23 12:47:58 -0700 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2010-09-23 13:53:18 -0700 |
commit | 5d9927ba30ba449badb9f6df0fbeb4d6aedc6e2a (patch) | |
tree | 190f9251c6db03d3550ec7f30b51a2561c01d9cf /src/phLibNfc_llcp.c | |
parent | 4ff7c86a2c706b150078274455406f1b04966e1a (diff) | |
download | external_libnfc-nxp-5d9927ba30ba449badb9f6df0fbeb4d6aedc6e2a.zip external_libnfc-nxp-5d9927ba30ba449badb9f6df0fbeb4d6aedc6e2a.tar.gz external_libnfc-nxp-5d9927ba30ba449badb9f6df0fbeb4d6aedc6e2a.tar.bz2 |
Initial libnfc checkin
Source: Trusted_NFC_Device_Host_AA03.01e02_google.zip code drop (23-Sep-2010)
Change-Id: Ie47f18423f949a8d3e0815d13f55c814312add24
Signed-off-by: Nick Pelly <npelly@google.com>
Diffstat (limited to 'src/phLibNfc_llcp.c')
-rw-r--r-- | src/phLibNfc_llcp.c | 922 |
1 files changed, 922 insertions, 0 deletions
diff --git a/src/phLibNfc_llcp.c b/src/phLibNfc_llcp.c new file mode 100644 index 0000000..c72e1b7 --- /dev/null +++ b/src/phLibNfc_llcp.c @@ -0,0 +1,922 @@ +/* + * Copyright (C) 2010 NXP Semiconductors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <phNfcTypes.h> +#include <phLibNfc.h> +#include <phLibNfc_Internal.h> +#include <phFriNfc_Llcp.h> +#include <phFriNfc_LlcpTransport.h> + +/* ---------------------------- Internal macros -------------------------------- */ + +#ifndef STATIC_DISABLE +#define STATIC static +#else +#define STATIC +#endif + +/* ----------------------- Internal functions headers -------------------------- */ + +STATIC +NFCSTATUS static_CheckState(); + +STATIC +NFCSTATUS static_CheckDevice(phLibNfc_Handle hRemoteDevice); + +STATIC +void phLibNfc_Llcp_CheckLlcp_Cb(void *pContext,NFCSTATUS status); + +/* --------------------------- Internal functions ------------------------------ */ + +STATIC NFCSTATUS static_CheckState() +{ + /* Check if the global context is set */ + if(gpphLibContext == NULL) + { + return NFCSTATUS_NOT_INITIALISED; + } + + /* Check if initialized */ + if(gpphLibContext->LibNfcState.cur_state == eLibNfcHalStateShutdown) + { + return NFCSTATUS_NOT_INITIALISED; + } + + /* Check if shutting down */ + if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown) + { + return NFCSTATUS_SHUTDOWN; + } + + return NFCSTATUS_SUCCESS; +} + +STATIC NFCSTATUS static_CheckDevice(phLibNfc_Handle hRemoteDevice) +{ + phLibNfc_sRemoteDevInformation_t* psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice; + + /* If local device is the Initiator (remote is Target), + * check if connection is correct + */ + if (psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Target) + { + /* Check if any device connected */ + if(gpphLibContext->Connected_handle == 0) + { + return NFCSTATUS_TARGET_NOT_CONNECTED; + } + + /* Check if handle corresponds to connected one */ + if(hRemoteDevice != gpphLibContext->Connected_handle) + { + return NFCSTATUS_INVALID_HANDLE; + } + } + + /* Check if previous callback is pending or if remote peer is not LLCP compliant */ + if ((gpphLibContext->status.GenCb_pending_status == TRUE) || + (gpphLibContext->llcp_cntx.bIsLlcp == FALSE)) + { + return NFCSTATUS_REJECTED; + } + + return NFCSTATUS_SUCCESS; +} + +/* ---------------------------- Public functions ------------------------------- */ + +NFCSTATUS phLibNfc_Mgt_SetLlcp_ConfigParams( phLibNfc_Llcp_sLinkParameters_t* pConfigInfo, + pphLibNfc_RspCb_t pConfigRspCb, + void* pContext + ) +{ + NFCSTATUS result; + phNfc_sData_t sGeneralBytesBuffer; + phLibNfc_sNfcIPCfg_t sNfcIPCfg; + const uint8_t pMagicBuffer[] = { 0x46, 0x66, 0x6D }; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((pConfigInfo == NULL) || (pConfigRspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Save the config for later use */ + memcpy( &gpphLibContext->llcp_cntx.sLocalParams, + pConfigInfo, + sizeof(phLibNfc_Llcp_sLinkParameters_t) ); + + /* Copy magic number in NFCIP General Bytes */ + memcpy(sNfcIPCfg.generalBytes, pMagicBuffer, sizeof(pMagicBuffer)); + sNfcIPCfg.generalBytesLength = sizeof(pMagicBuffer); + + /* Encode link parameters in TLV to configure P2P General Bytes */ + sGeneralBytesBuffer.buffer = sNfcIPCfg.generalBytes + sizeof(pMagicBuffer); + sGeneralBytesBuffer.length = sizeof(sNfcIPCfg.generalBytes) - sizeof(pMagicBuffer); + result = phFriNfc_Llcp_EncodeLinkParams( &sGeneralBytesBuffer, + pConfigInfo, + PHFRINFC_LLCP_VERSION); + if (result != NFCSTATUS_SUCCESS) + { + return PHNFCSTATUS(result); + } + sNfcIPCfg.generalBytesLength += (uint8_t)sGeneralBytesBuffer.length; + + /* Set the P2P general bytes */ + result = phLibNfc_Mgt_SetP2P_ConfigParams(&sNfcIPCfg, pConfigRspCb, pContext); + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_CheckLlcp( phLibNfc_Handle hRemoteDevice, + pphLibNfc_ChkLlcpRspCb_t pCheckLlcp_RspCb, + pphLibNfc_LlcpLinkStatusCb_t pLink_Cb, + void* pContext + ) +{ + NFCSTATUS result; + phLibNfc_sRemoteDevInformation_t* psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t*)hRemoteDevice; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hRemoteDevice == 0) || + (pCheckLlcp_RspCb == NULL) || + (pLink_Cb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* If local device is the Initiator (remote is Target), + * check if connection is correct + */ + if (psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Target) + { + /* Check if any device connected */ + if(gpphLibContext->Connected_handle == 0) + { + return NFCSTATUS_TARGET_NOT_CONNECTED; + } + + /* Check if handle corresponds to connected one */ + if(hRemoteDevice != gpphLibContext->Connected_handle) + { + return NFCSTATUS_INVALID_HANDLE; + } + } + + /* Resets the LLCP LLC component */ + result = phFriNfc_Llcp_Reset( &gpphLibContext->llcp_cntx.sLlcpContext, + gpphLibContext->psOverHalCtxt, + &gpphLibContext->llcp_cntx.sLocalParams, + gpphLibContext->llcp_cntx.pRxBuffer, + sizeof(gpphLibContext->llcp_cntx.pRxBuffer), + gpphLibContext->llcp_cntx.pTxBuffer, + sizeof(gpphLibContext->llcp_cntx.pTxBuffer), + pLink_Cb, + pContext); + if (result != NFCSTATUS_SUCCESS) + { + return PHNFCSTATUS(result); + } + + /* Resets the LLCP Transport component */ + result = phFriNfc_LlcpTransport_Reset( &gpphLibContext->llcp_cntx.sLlcpTransportContext, + &gpphLibContext->llcp_cntx.sLlcpContext ); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Prepare callback */ + gpphLibContext->CBInfo.pClientLlcpCheckRespCb = pCheckLlcp_RspCb; + gpphLibContext->CBInfo.pClientLlcpCheckRespCntx = pContext; + + /* Update state */ + result = phLibNfc_UpdateNextState(gpphLibContext, eLibNfcHalStateTransaction); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Call the component function */ + result = phFriNfc_Llcp_ChkLlcp( &gpphLibContext->llcp_cntx.sLlcpContext, + psRemoteDevInfo, + phLibNfc_Llcp_CheckLlcp_Cb, + gpphLibContext + ); + result = PHNFCSTATUS(result); + if (result == NFCSTATUS_PENDING) + { + gpphLibContext->status.GenCb_pending_status = TRUE; + } + else if (result == NFCSTATUS_SUCCESS) + { + /* Nothing to do */ + } + else if (result != NFCSTATUS_FAILED) + { + result = NFCSTATUS_TARGET_LOST; + } + + return result; +} + +/* Response callback for phLibNfc_Ndef_CheckNdef */ +STATIC +void phLibNfc_Llcp_CheckLlcp_Cb(void *pContext, NFCSTATUS status) +{ + phLibNfc_LibContext_t *pLibNfc_Ctxt = (phLibNfc_LibContext_t *)pContext; + NFCSTATUS RetStatus = NFCSTATUS_SUCCESS; + pphLibNfc_ChkLlcpRspCb_t pClientCb = NULL; + void *pClientContext = NULL; + + if(pLibNfc_Ctxt != gpphLibContext) + { + /*wrong context returned from below layer*/ + phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1); + } + else + { + if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateShutdown) + { + /*shutdown called before completion of check Ndef, allow shutdown to happen */ + phLibNfc_Pending_Shutdown(); + RetStatus = NFCSTATUS_SHUTDOWN; + } + else if(gpphLibContext->LibNfcState.next_state == eLibNfcHalStateRelease) + { + RetStatus = NFCSTATUS_ABORTED; + } + else + { + if(status == NFCSTATUS_SUCCESS) + { + /* Remote peer is LLCP compliant */ + gpphLibContext->llcp_cntx.bIsLlcp = TRUE; + } + else if(PHNFCSTATUS(status)== NFCSTATUS_FAILED) + { + RetStatus = NFCSTATUS_FAILED; + gpphLibContext->llcp_cntx.bIsLlcp = FALSE; + } + else + { + RetStatus = NFCSTATUS_TARGET_LOST; + } + } + + /* Update the current state */ + gpphLibContext->status.GenCb_pending_status = FALSE; + phLibNfc_UpdateCurState(RetStatus,gpphLibContext); + + /* Copy callback details */ + pClientCb = gpphLibContext->CBInfo.pClientLlcpCheckRespCb; + pClientContext = gpphLibContext->CBInfo.pClientLlcpCheckRespCntx; + + /* Reset saved callback */ + gpphLibContext->CBInfo.pClientCkNdefCb = NULL; + gpphLibContext->CBInfo.pClientCkNdefCntx = NULL; + + /* Trigger the callback */ + if(pClientCb != NULL) + { + pClientCb(pClientContext,RetStatus); + } + } +} + +NFCSTATUS phLibNfc_Llcp_Activate( phLibNfc_Handle hRemoteDevice ) +{ + NFCSTATUS result; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if (hRemoteDevice == 0) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Check device */ + result = static_CheckDevice(hRemoteDevice); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Start activation */ + result = phFriNfc_Llcp_Activate(&gpphLibContext->llcp_cntx.sLlcpContext); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Deactivate( phLibNfc_Handle hRemoteDevice ) +{ + NFCSTATUS result; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if (hRemoteDevice == 0) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Check device */ + result = static_CheckDevice(hRemoteDevice); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Start deactivation */ + result = phFriNfc_Llcp_Deactivate(&gpphLibContext->llcp_cntx.sLlcpContext); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_GetLocalInfo( phLibNfc_Handle hRemoteDevice, + phLibNfc_Llcp_sLinkParameters_t* pConfigInfo + ) +{ + NFCSTATUS result; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hRemoteDevice == 0) || + (pConfigInfo == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Check device */ + result = static_CheckDevice(hRemoteDevice); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Get local infos */ + result = phFriNfc_Llcp_GetLocalInfo(&gpphLibContext->llcp_cntx.sLlcpContext, pConfigInfo); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_GetRemoteInfo( phLibNfc_Handle hRemoteDevice, + phLibNfc_Llcp_sLinkParameters_t* pConfigInfo + ) +{ + NFCSTATUS result; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hRemoteDevice == 0) || + (pConfigInfo == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Check device */ + result = static_CheckDevice(hRemoteDevice); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Get local infos */ + result = phFriNfc_Llcp_GetRemoteInfo(&gpphLibContext->llcp_cntx.sLlcpContext, pConfigInfo); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Socket( phLibNfc_Handle hRemoteDevice, + phLibNfc_Llcp_eSocketType_t eType, + phLibNfc_Llcp_sSocketOptions_t* psOptions, + phNfc_sData_t* psWorkingBuffer, + phLibNfc_Handle* phSocket, + pphLibNfc_LlcpSocketErrCb_t pErr_Cb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + /* NOTE: Transport Layer test psOption and psWorkingBuffer value */ + if ((hRemoteDevice == 0) || + (phSocket == NULL) || + (pErr_Cb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Check device */ + result = static_CheckDevice(hRemoteDevice); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Get local infos */ + result = phFriNfc_LlcpTransport_Socket(&gpphLibContext->llcp_cntx.sLlcpTransportContext, + eType, + psOptions, + psWorkingBuffer, + &psSocket, + pErr_Cb, + pContext); + + /* Send back the socket handle */ + *phSocket = (phLibNfc_Handle)psSocket; + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Close( phLibNfc_Handle hSocket ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if (hSocket == 0) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Get local infos */ + result = phFriNfc_LlcpTransport_Close(psSocket); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_SocketGetLocalOptions( phLibNfc_Handle hSocket, + phLibNfc_Llcp_sSocketOptions_t* psLocalOptions + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psLocalOptions == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Get local options */ + result = phFriNfc_LlcpTransport_SocketGetLocalOptions(psSocket, psLocalOptions); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_SocketGetRemoteOptions( phLibNfc_Handle hSocket, + phLibNfc_Llcp_sSocketOptions_t* psRemoteOptions + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psRemoteOptions == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Get remote infos */ + result = phFriNfc_LlcpTransport_SocketGetRemoteOptions(psSocket, psRemoteOptions); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Bind( phLibNfc_Handle hSocket, + uint8_t nSap + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if (hSocket == 0) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Bind the socket to the designated port */ + result = phFriNfc_LlcpTransport_Bind(psSocket, nSap); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Listen( phLibNfc_Handle hSocket, + phNfc_sData_t *psServiceName, + pphLibNfc_LlcpSocketListenCb_t pListen_Cb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + /* NOTE : psServiceName may be NULL, do not test it ! */ + if ((hSocket == 0) || + (pListen_Cb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Start listening for incoming connections */ + result = phFriNfc_LlcpTransport_Listen( psSocket, + psServiceName, + (pphFriNfc_LlcpTransportSocketListenCb_t)pListen_Cb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Accept( phLibNfc_Handle hSocket, + phLibNfc_Llcp_sSocketOptions_t* psOptions, + phNfc_sData_t* psWorkingBuffer, + pphLibNfc_LlcpSocketErrCb_t pErr_Cb, + pphLibNfc_LlcpSocketAcceptCb_t pAccept_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psOptions == NULL) || + (psWorkingBuffer == NULL) || + (pErr_Cb == NULL) || + (pAccept_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Accept incoming connection */ + result = phFriNfc_LlcpTransport_Accept( psSocket, + psOptions, + psWorkingBuffer, + pErr_Cb, + pAccept_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Reject( phLibNfc_Handle hSocket, + pphLibNfc_LlcpSocketRejectCb_t pReject_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (pReject_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Reject incoming connection */ + result = phFriNfc_LlcpTransport_Reject( psSocket, + pReject_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Connect( phLibNfc_Handle hSocket, + uint8_t nSap, + pphLibNfc_LlcpSocketConnectCb_t pConnect_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (pConnect_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Try to connect on a remote service, given its SAP */ + result = phFriNfc_LlcpTransport_Connect( psSocket, + nSap, + pConnect_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_ConnectByUri( phLibNfc_Handle hSocket, + phNfc_sData_t* psUri, + pphLibNfc_LlcpSocketConnectCb_t pConnect_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psUri == NULL) || + (pConnect_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Try to connect on a remote service, using SDP */ + result = phFriNfc_LlcpTransport_ConnectByUri( psSocket, + psUri, + pConnect_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Disconnect( phLibNfc_Handle hSocket, + pphLibNfc_LlcpSocketDisconnectCb_t pDisconnect_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (pDisconnect_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Disconnect a logical link */ + result = phFriNfc_LlcpTransport_Disconnect( psSocket, + pDisconnect_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Recv( phLibNfc_Handle hSocket, + phNfc_sData_t* psBuffer, + pphLibNfc_LlcpSocketRecvCb_t pRecv_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psBuffer == NULL) || + (pRecv_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Receive data from the logical link */ + result = phFriNfc_LlcpTransport_Recv( psSocket, + psBuffer, + pRecv_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_RecvFrom( phLibNfc_Handle hSocket, + phNfc_sData_t* psBuffer, + pphLibNfc_LlcpSocketRecvFromCb_t pRecv_Cb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psBuffer == NULL) || + (pRecv_Cb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Receive data from the logical link */ + result = phFriNfc_LlcpTransport_RecvFrom( psSocket, + psBuffer, + pRecv_Cb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_Send( phLibNfc_Handle hSocket, + phNfc_sData_t* psBuffer, + pphLibNfc_LlcpSocketSendCb_t pSend_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psBuffer == NULL) || + (pSend_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Send data to the logical link */ + result = phFriNfc_LlcpTransport_Send( psSocket, + psBuffer, + pSend_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} + +NFCSTATUS phLibNfc_Llcp_SendTo( phLibNfc_Handle hSocket, + uint8_t nSap, + phNfc_sData_t* psBuffer, + pphLibNfc_LlcpSocketSendCb_t pSend_RspCb, + void* pContext + ) +{ + NFCSTATUS result; + phFriNfc_LlcpTransport_Socket_t *psSocket = (phFriNfc_LlcpTransport_Socket_t*)hSocket; + + /* State checking */ + result = static_CheckState(); + if (result != NFCSTATUS_SUCCESS) + { + return result; + } + + /* Parameters checking */ + if ((hSocket == 0) || + (psBuffer == NULL) || + (pSend_RspCb == NULL)) + { + return NFCSTATUS_INVALID_PARAMETER; + } + + /* Send data to the logical link */ + result = phFriNfc_LlcpTransport_SendTo( psSocket, + nSap, + psBuffer, + pSend_RspCb, + pContext ); + + return PHNFCSTATUS(result); +} |