summaryrefslogtreecommitdiffstats
path: root/src/phFriNfc_LlcpTransport_Connectionless.c
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2010-09-23 12:47:58 -0700
committerNick Pelly <npelly@google.com>2010-09-23 13:53:18 -0700
commit5d9927ba30ba449badb9f6df0fbeb4d6aedc6e2a (patch)
tree190f9251c6db03d3550ec7f30b51a2561c01d9cf /src/phFriNfc_LlcpTransport_Connectionless.c
parent4ff7c86a2c706b150078274455406f1b04966e1a (diff)
downloadexternal_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/phFriNfc_LlcpTransport_Connectionless.c')
-rw-r--r--src/phFriNfc_LlcpTransport_Connectionless.c235
1 files changed, 235 insertions, 0 deletions
diff --git a/src/phFriNfc_LlcpTransport_Connectionless.c b/src/phFriNfc_LlcpTransport_Connectionless.c
new file mode 100644
index 0000000..67591ad
--- /dev/null
+++ b/src/phFriNfc_LlcpTransport_Connectionless.c
@@ -0,0 +1,235 @@
+/*
+ * 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.
+ */
+
+/**
+ * \file phFriNfc_LlcpTransport_Connectionless.c
+ * \brief
+ *
+ * Project: NFC-FRI
+ *
+ */
+/*include files*/
+#include <phLibNfcStatus.h>
+#include <phLibNfc.h>
+#include <phNfcLlcpTypes.h>
+#include <phFriNfc_LlcpTransport.h>
+#include <phFriNfc_Llcp.h>
+
+/* TODO: comment function Handle_Connectionless_IncommingFrame */
+void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTransport,
+ phNfc_sData_t *psData,
+ uint8_t dsap,
+ uint8_t ssap)
+{
+ uint8_t i=0;
+
+ for(i=0;i<PHFRINFC_LLCP_NB_SOCKET_MAX;i++)
+ {
+ /* Test if a socket is registered to get this packet */
+ if(pLlcpTransport->pSocketTable[i].socket_sSap == dsap && pLlcpTransport->pSocketTable[i].bSocketRecvPending == TRUE)
+ {
+ /* Reset the RecvPending variable */
+ pLlcpTransport->pSocketTable[i].bSocketRecvPending = FALSE;
+
+ /* Copy the received buffer into the receive buffer */
+ memcpy(pLlcpTransport->pSocketTable[i].sSocketRecvBuffer->buffer,psData->buffer,psData->length);
+
+ /* Update the received length */
+ *pLlcpTransport->pSocketTable[i].receivedLength = psData->length;
+
+ /* call the Recv callback */
+ pLlcpTransport->pSocketTable[i].pfSocketRecvFrom_Cb(pLlcpTransport->pSocketTable[i].pRecvContext,ssap,NFCSTATUS_SUCCESS);
+ break;
+ }
+ }
+}
+
+/* TODO: comment function phFriNfc_LlcpTransport_Connectionless_SendTo_CB */
+static void phFriNfc_LlcpTransport_Connectionless_SendTo_CB(void* pContext,
+ NFCSTATUS status)
+{
+ phFriNfc_LlcpTransport_Socket_t *pLlcpSocket = (phFriNfc_LlcpTransport_Socket_t*)pContext;
+
+ /* Reset the SendPending variable */
+ pLlcpSocket->bSocketSendPending = FALSE;
+
+ /* Call the send callback */
+ pLlcpSocket->pfSocketSend_Cb(pLlcpSocket->pSendContext,status);
+
+}
+
+/**
+* \ingroup grp_fri_nfc
+* \brief <b>Close a socket on a LLCP-connectionless device</b>.
+*
+* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
+*
+* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
+
+* \retval NFCSTATUS_SUCCESS Operation successful.
+* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
+* could not be properly interpreted.
+* \retval NFCSTATUS_FAILED Operation failed.
+*/
+NFCSTATUS phFriNfc_LlcpTransport_Connectionless_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket)
+{
+ /* Reset the pointer to the socket closed */
+ pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault;
+ pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType;
+ pLlcpSocket->pContext = NULL;
+ pLlcpSocket->pSocketErrCb = NULL;
+ pLlcpSocket->psSocketOption = NULL;
+ pLlcpSocket->socket_sSap = PHFRINFC_LLCP_SAP_DEFAULT;
+ pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_DEFAULT;
+ pLlcpSocket->bSocketRecvPending = FALSE;
+ pLlcpSocket->bSocketSendPending = FALSE;
+ pLlcpSocket->bSocketListenPending = FALSE;
+ pLlcpSocket->bSocketDiscPending = FALSE;
+ pLlcpSocket->RemoteBusyConditionInfo = FALSE;
+ pLlcpSocket->ReceiverBusyCondition = FALSE;
+ pLlcpSocket->pfSocketSend_Cb = NULL;
+ pLlcpSocket->pfSocketRecv_Cb = NULL;
+ pLlcpSocket->pfSocketListen_Cb = NULL;
+ pLlcpSocket->pfSocketConnect_Cb = NULL;
+ pLlcpSocket->pfSocketDisconnect_Cb = NULL;
+ pLlcpSocket->pServiceName = NULL;
+ pLlcpSocket->socket_VS = 0;
+ pLlcpSocket->socket_VSA = 0;
+ pLlcpSocket->socket_VR = 0;
+ pLlcpSocket->socket_VRA = 0;
+
+ return NFCSTATUS_SUCCESS;
+}
+
+/**
+* \ingroup grp_fri_nfc
+* \brief <b>Send data on a socket to a given destination SAP</b>.
+*
+* This function is used to write data on a socket to a given destination SAP.
+* This function can only be called on a connectionless socket.
+*
+*
+* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
+* \param[in] nSap The destination SAP.
+* \param[in] psBuffer The buffer containing the data to send.
+* \param[in] pSend_RspCb The callback to be called when the
+* operation is completed.
+* \param[in] pContext Upper layer context to be returned in
+* the callback.
+*
+* \retval NFCSTATUS_SUCCESS Operation successful.
+* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
+* could not be properly interpreted.
+* \retval NFCSTATUS_PENDING Reception operation is in progress,
+* pSend_RspCb will be called upon completion.
+* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
+* a valid type to perform the requsted operation.
+* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
+* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
+* \retval NFCSTATUS_FAILED Operation failed.
+*/
+NFCSTATUS phFriNfc_LlcpTransport_Connectionless_SendTo(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
+ uint8_t nSap,
+ phNfc_sData_t* psBuffer,
+ pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
+ void* pContext)
+{
+ NFCSTATUS status = NFCSTATUS_SUCCESS;
+
+ /* Store send callback and context*/
+ pLlcpSocket->pfSocketSend_Cb = pSend_RspCb;
+ pLlcpSocket->pSendContext = pContext;
+
+ /* Test if a send is pending with this socket */
+ if(pLlcpSocket->bSocketSendPending == TRUE)
+ {
+ status = NFCSTATUS_FAILED;
+ pLlcpSocket->pfSocketSend_Cb(pLlcpSocket->pSendContext,status);
+ }
+ else
+ {
+ /* Fill the psLlcpHeader stuture with the DSAP,PTYPE and the SSAP */
+ pLlcpSocket->sLlcpHeader.dsap = nSap;
+ pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_UI;
+ pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
+
+ pLlcpSocket->bSocketSendPending = TRUE;
+
+ /* Send to data to the approiate socket */
+ status = phFriNfc_Llcp_Send(pLlcpSocket->psTransport->pLlcp,
+ &pLlcpSocket->sLlcpHeader,
+ NULL,
+ psBuffer,
+ phFriNfc_LlcpTransport_Connectionless_SendTo_CB,
+ pLlcpSocket);
+ }
+
+ return status;
+}
+
+
+ /**
+* \ingroup grp_lib_nfc
+* \brief <b>Read data on a socket and get the source SAP</b>.
+*
+* This function is the same as phLibNfc_Llcp_Recv, except that the callback includes
+* the source SAP. This functions can only be called on a connectionless socket.
+*
+*
+* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
+* \param[in] psBuffer The buffer receiving the data.
+* \param[in] pRecv_RspCb The callback to be called when the
+* operation is completed.
+* \param[in] pContext Upper layer context to be returned in
+* the callback.
+*
+* \retval NFCSTATUS_SUCCESS Operation successful.
+* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
+* could not be properly interpreted.
+* \retval NFCSTATUS_PENDING Reception operation is in progress,
+* pRecv_RspCb will be called upon completion.
+* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
+* a valid type to perform the requsted operation.
+* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
+* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
+* \retval NFCSTATUS_FAILED Operation failed.
+*/
+NFCSTATUS phLibNfc_LlcpTransport_Connectionless_RecvFrom(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
+ phNfc_sData_t* psBuffer,
+ pphFriNfc_LlcpTransportSocketRecvFromCb_t pRecv_Cb,
+ void *pContext)
+{
+ NFCSTATUS status = NFCSTATUS_PENDING;
+
+ if(pLlcpSocket->bSocketRecvPending)
+ {
+ status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
+ }
+ else
+ {
+ /* Store the callback and context*/
+ pLlcpSocket->pfSocketRecvFrom_Cb = pRecv_Cb;
+ pLlcpSocket->pRecvContext = pContext;
+
+ /* Store the pointer to the receive buffer */
+ pLlcpSocket->sSocketRecvBuffer = psBuffer;
+ pLlcpSocket->receivedLength = &psBuffer->length;
+
+ /* Set RecvPending to TRUE */
+ pLlcpSocket->bSocketRecvPending = TRUE;
+ }
+ return status;
+}