diff options
author | Sunil Jogi <sunil.jogi@nxp.com> | 2012-01-16 11:47:16 -0800 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2012-01-27 12:14:48 -0800 |
commit | 955a8efe369ece977e4757f0ae37b3931169125b (patch) | |
tree | 580470fedd4f2f55dc5f8f97a556a58a9b00d69e | |
parent | 3a53a1e3754df0e5d77a6549a620d570acacbae4 (diff) | |
download | external_libnfc-nxp-955a8efe369ece977e4757f0ae37b3931169125b.zip external_libnfc-nxp-955a8efe369ece977e4757f0ae37b3931169125b.tar.gz external_libnfc-nxp-955a8efe369ece977e4757f0ae37b3931169125b.tar.bz2 |
LLCP 1.1: allow pending operations on connectionless.
The pending operations were handled at the connection-oriented sockets
level, with no possibility for other transport types to handle
pending operations.
A dispatcher has been added at the generic transport level to
remove this limitation.
This feature is needed to implement LLCP v1.1.
Change-Id: I69e37ba800d1c531396ca97ab0a0480e0f53d63f
-rw-r--r-- | src/phFriNfc_LlcpTransport.c | 278 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport.h | 47 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport_Connection.c | 659 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport_Connection.h | 5 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport_Connectionless.c | 71 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport_Connectionless.h | 4 |
6 files changed, 595 insertions, 469 deletions
diff --git a/src/phFriNfc_LlcpTransport.c b/src/phFriNfc_LlcpTransport.c index 960a33a..a7e195b 100644 --- a/src/phFriNfc_LlcpTransport.c +++ b/src/phFriNfc_LlcpTransport.c @@ -147,6 +147,105 @@ static void phFriNfc_LlcpTransport__Recv_CB(void *pContext, } +/* TODO: comment function Transport recv CB */ +static void phFriNfc_LlcpTransport_Send_CB(void *pContext, + NFCSTATUS status) +{ + phFriNfc_LlcpTransport_t *psTransport = (phFriNfc_LlcpTransport_t*)pContext; + NFCSTATUS result = NFCSTATUS_FAILED; + phNfc_sData_t sFrmrBuffer; + phFriNfc_Llcp_Send_CB_t pfSavedCb; + void *pSavedContext; + phFriNfc_LlcpTransport_Socket_t *pCurrentSocket = NULL; + uint8_t index; + + /* 1 - Reset the FLAG send pending*/ + + psTransport->bSendPending = FALSE; + + /* 2 - Handle pending error responses */ + + if(psTransport->bFrmrPending) + { + /* Reset FRMR pending */ + psTransport->bFrmrPending = FALSE; + + /* Send Frmr */ + sFrmrBuffer.buffer = psTransport->FrmrInfoBuffer; + sFrmrBuffer.length = 0x04; /* Size of FRMR Information field */ + + /* Send Pending */ + psTransport->bSendPending = TRUE; + + result = phFriNfc_Llcp_Send(psTransport->pLlcp, + &psTransport->sLlcpHeader, + NULL, + &sFrmrBuffer, + phFriNfc_LlcpTransport_Send_CB, + psTransport); + + } + else if(psTransport->bDmPending) + { + /* Reset DM pending */ + psTransport->bDmPending = FALSE; + + /* Send DM pending */ + result = phFriNfc_LlcpTransport_SendDisconnectMode(psTransport, + psTransport->DmInfoBuffer[0], + psTransport->DmInfoBuffer[1], + psTransport->DmInfoBuffer[2]); + } + + /* 3 - Call the original callback */ + + if (psTransport->pfLinkSendCb != NULL) + { + pfSavedCb = psTransport->pfLinkSendCb; + pSavedContext = psTransport->pLinkSendContext; + + psTransport->pfLinkSendCb = NULL; + psTransport->pLinkSendContext = NULL; + + (*pfSavedCb)(pSavedContext, status); + } + + /* 4 - Handle pending send operations */ + + /* Init index */ + index = psTransport->socketIndex; + + /* Check all sockets for pending operation */ + do + { + /* Modulo-increment index */ + index = (index + 1) % PHFRINFC_LLCP_NB_SOCKET_MAX; + + pCurrentSocket = &psTransport->pSocketTable[index]; + + /* Dispatch to the corresponding transport layer */ + if (pCurrentSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionOriented) + { + result = phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(pCurrentSocket); + } + else if (pCurrentSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionLess) + { + result = phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(pCurrentSocket); + } + + if (result != NFCSTATUS_FAILED) + { + /* Stop looping if pending operation has been found */ + break; + } + + } while(index != psTransport->socketIndex); + + /* Save the new index */ + psTransport->socketIndex = index; +} + + /* TODO: comment function Transport reset */ NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpTransport, phFriNfc_Llcp_t *pLlcp) @@ -265,7 +364,9 @@ NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t *pLlcpTransp case phFriNfc_LlcpTransportSocket_eSocketRejected: phFriNfc_LlcpTransport_Close(&pLlcpTransport->pSocketTable[i]); break; - default: break; + default: + /* Do nothing */ + break; } } else @@ -277,6 +378,176 @@ NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t *pLlcpTransp } +/* TODO: comment function Transport LinkSend */ +NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t *LlcpTransport, + phFriNfc_Llcp_sPacketHeader_t *psHeader, + phFriNfc_Llcp_sPacketSequence_t *psSequence, + phNfc_sData_t *psInfo, + phFriNfc_Llcp_Send_CB_t pfSend_CB, + void *pContext ) +{ + /* Check if a send is already ongoing */ + if (LlcpTransport->pfLinkSendCb != NULL) + { + return NFCSTATUS_BUSY; + } + + /* Save callback details */ + LlcpTransport->pfLinkSendCb = pfSend_CB; + LlcpTransport->pLinkSendContext = pContext; + + /* Call the link-level send function */ + return phFriNfc_Llcp_Send(LlcpTransport->pLlcp, psHeader, psSequence, psInfo, phFriNfc_LlcpTransport_Send_CB, (void*)LlcpTransport); +} + + +/* TODO: comment function Transport SendFrameReject */ +NFCSTATUS phFriNfc_LlcpTransport_SendFrameReject(phFriNfc_LlcpTransport_t *psTransport, + uint8_t dsap, + uint8_t rejectedPTYPE, + uint8_t ssap, + phFriNfc_Llcp_sPacketSequence_t* sLlcpSequence, + uint8_t WFlag, + uint8_t IFlag, + uint8_t RFlag, + uint8_t SFlag, + uint8_t vs, + uint8_t vsa, + uint8_t vr, + uint8_t vra) +{ + NFCSTATUS status = NFCSTATUS_SUCCESS; + phNfc_sData_t sFrmrBuffer; + uint8_t flagValue; + uint8_t sequence = 0; + uint8_t index; + uint8_t socketFound = FALSE; + + /* Search a socket waiting for a FRAME */ + for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) + { + /* Test if the socket is in connected state and if its SSAP and DSAP are valid */ + if(psTransport->pSocketTable[index].socket_sSap == dsap + && psTransport->pSocketTable[index].socket_dSap == ssap) + { + /* socket found */ + socketFound = TRUE; + break; + } + } + + /* Test if a socket has been found */ + if(socketFound) + { + /* Set socket state to disconnected */ + psTransport->pSocketTable[index].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault; + + /* Call ErrCB due to a FRMR*/ + psTransport->pSocketTable[index].pSocketErrCb( psTransport->pSocketTable[index].pContext,PHFRINFC_LLCP_ERR_FRAME_REJECTED); + + /* Close the socket */ + status = phFriNfc_LlcpTransport_ConnectionOriented_Close(&psTransport->pSocketTable[index]); + + /* Set FRMR Header */ + psTransport->sLlcpHeader.dsap = dsap; + psTransport->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_FRMR; + psTransport->sLlcpHeader.ssap = ssap; + + /* Set FRMR Information Field */ + flagValue = (WFlag<<7) | (IFlag<<6) | (RFlag<<5) | (SFlag<<4) | rejectedPTYPE; + if (sLlcpSequence != NULL) + { + sequence = (uint8_t)((sLlcpSequence->ns<<4)|(sLlcpSequence->nr)); + } + + psTransport->FrmrInfoBuffer[0] = flagValue; + psTransport->FrmrInfoBuffer[1] = sequence; + psTransport->FrmrInfoBuffer[2] = (vs<<4)|vr ; + psTransport->FrmrInfoBuffer[3] = (vsa<<4)|vra ; + + /* Test if a send is pending */ + if(psTransport->bSendPending) + { + psTransport->bFrmrPending = TRUE; + status = NFCSTATUS_PENDING; + } + else + { + sFrmrBuffer.buffer = psTransport->FrmrInfoBuffer; + sFrmrBuffer.length = 0x04; /* Size of FRMR Information field */ + + /* Send Pending */ + psTransport->bSendPending = TRUE; + + /* Send FRMR frame */ + status = phFriNfc_Llcp_Send(psTransport->pLlcp, + &psTransport->sLlcpHeader, + NULL, + &sFrmrBuffer, + phFriNfc_LlcpTransport_Send_CB, + psTransport); + } + } + else + { + /* No active socket*/ + /* FRMR Frame not handled*/ + } + return status; +} + + +/* TODO: comment function Transport SendDisconnectMode (NOTE: used only + * for requests not bound to a socket, like "service not found") + */ +NFCSTATUS phFriNfc_LlcpTransport_SendDisconnectMode(phFriNfc_LlcpTransport_t* psTransport, + uint8_t dsap, + uint8_t ssap, + uint8_t dmOpCode) +{ + NFCSTATUS status = NFCSTATUS_SUCCESS; + + /* Test if a send is pending */ + if(psTransport->bSendPending) + { + /* DM pending */ + psTransport->bDmPending = TRUE; + + /* Store DM Info */ + psTransport->DmInfoBuffer[0] = dsap; + psTransport->DmInfoBuffer[1] = ssap; + psTransport->DmInfoBuffer[2] = dmOpCode; + + status = NFCSTATUS_PENDING; + } + else + { + /* Set the header */ + psTransport->sDmHeader.dsap = dsap; + psTransport->sDmHeader.ptype = PHFRINFC_LLCP_PTYPE_DM; + psTransport->sDmHeader.ssap = ssap; + + /* Save Operation Code to be provided in DM frame payload */ + psTransport->DmInfoBuffer[2] = dmOpCode; + psTransport->sDmPayload.buffer = &psTransport->DmInfoBuffer[2]; + psTransport->sDmPayload.length = PHFRINFC_LLCP_DM_LENGTH; + + /* Send Pending */ + psTransport->bSendPending = TRUE; + + /* Send DM frame */ + status = phFriNfc_Llcp_Send(psTransport->pLlcp, + &psTransport->sDmHeader, + NULL, + &psTransport->sDmPayload, + phFriNfc_LlcpTransport_Send_CB, + psTransport); + } + + return status; +} + + /** * \ingroup grp_lib_nfc * \brief <b>Get the local options of a socket</b>. @@ -1242,6 +1513,11 @@ NFCSTATUS phFriNfc_LlcpTransport_SendTo( phFriNfc_LlcpTransport_Socket_t { status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE); } + /* Test if a send is pending */ + else if(pLlcpSocket->pfSocketSend_Cb != NULL) + { + status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED); + } else { /* Get the local parameters of the LLCP Link */ diff --git a/src/phFriNfc_LlcpTransport.h b/src/phFriNfc_LlcpTransport.h index 2aff8ea..2fbabf6 100644 --- a/src/phFriNfc_LlcpTransport.h +++ b/src/phFriNfc_LlcpTransport.h @@ -238,6 +238,9 @@ struct phFriNfc_LlcpTransport bool_t bDmPending; bool_t bFrmrPending; + phFriNfc_Llcp_Send_CB_t pfLinkSendCb; + void *pLinkSendContext; + uint8_t socketIndex; /**< Info field of pending FRMR packet*/ @@ -277,6 +280,50 @@ NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t *pLlcpSocke /** +* \ingroup grp_fri_nfc +* \brief <b>Used by transport layers to request a send on link layer</b>. +* +*/ +NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t *LlcpTransport, + phFriNfc_Llcp_sPacketHeader_t *psHeader, + phFriNfc_Llcp_sPacketSequence_t *psSequence, + phNfc_sData_t *psInfo, + phFriNfc_Llcp_Send_CB_t pfSend_CB, + void *pContext ); + + +/** +* \ingroup grp_fri_nfc +* \brief <b>Used by transport layers to send a DM frame</b>. +* +* This function is only used when the DM is not related to a DISC on a socket. +*/ +NFCSTATUS phFriNfc_LlcpTransport_SendDisconnectMode(phFriNfc_LlcpTransport_t* psTransport, + uint8_t dsap, + uint8_t ssap, + uint8_t dmOpCode); + +/** +* \ingroup grp_fri_nfc +* \brief <b>Used by transport layers to send a FRMR frame</b>. +* +*/ +NFCSTATUS phFriNfc_LlcpTransport_SendFrameReject(phFriNfc_LlcpTransport_t *psTransport, + uint8_t dsap, + uint8_t rejectedPTYPE, + uint8_t ssap, + phFriNfc_Llcp_sPacketSequence_t* sLlcpSequence, + uint8_t WFlag, + uint8_t IFlag, + uint8_t RFlag, + uint8_t SFlag, + uint8_t vs, + uint8_t vsa, + uint8_t vr, + uint8_t vra); + + +/** * \ingroup grp_lib_nfc * \brief <b>Get the local options of a socket</b>. * diff --git a/src/phFriNfc_LlcpTransport_Connection.c b/src/phFriNfc_LlcpTransport_Connection.c index b75406b..f58b33f 100644 --- a/src/phFriNfc_LlcpTransport_Connection.c +++ b/src/phFriNfc_LlcpTransport_Connection.c @@ -32,13 +32,7 @@ #include <phFriNfc_LlcpUtils.h> /* Function definition */ -static NFCSTATUS phFriNfc_Llcp_Send_DisconnectMode_Frame(phFriNfc_LlcpTransport_t* psTransport, - uint8_t dsap, - uint8_t ssap, - uint8_t dmOpCode); - static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket); - static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket); static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcpSocket); @@ -74,40 +68,8 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* p /* Get Send CB context */ psTransport = (phFriNfc_LlcpTransport_t*)pContext; - /* Reset the FLAG send pending*/ - psTransport->bSendPending = FALSE; - if(status == NFCSTATUS_SUCCESS) { - if(psTransport->bFrmrPending) - { - /* Reset FRMR pending */ - psTransport->bFrmrPending = FALSE; - - /* Send Frmr */ - sFrmrBuffer.buffer = psTransport->FrmrInfoBuffer; - sFrmrBuffer.length = 0x04; /* Size of FRMR Information field */ - - result = phFriNfc_LlcpConnTransport_Send(psTransport->pLlcp, - &psTransport->sLlcpHeader, - NULL, - &sFrmrBuffer, - phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, - psTransport); - } - else if(psTransport->bDmPending) - { - /* Reset DM pending */ - psTransport->bDmPending = FALSE; - - /* Send DM pending */ - result = phFriNfc_Llcp_Send_DisconnectMode_Frame(psTransport, - psTransport->DmInfoBuffer[0], - psTransport->DmInfoBuffer[1], - psTransport->DmInfoBuffer[2]); - } - - /* Test the socket */ switch(psTransport->pSocketTable[psTransport->socketIndex].eSocket_State) { @@ -142,170 +104,125 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* p psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb = NULL; } }break; - default: break; + default: + /* Nothing to do */ + break; } - - /* Update Index value with the next socket */ - index = psTransport->socketIndex+1; - - /* Search for a socket with a flag Pending */ - do + } + else + { + /* Send CB error */ + if(!psTransport->pSocketTable[psTransport->socketIndex].bSocketSendPending && psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb != NULL) { - if(index >= PHFRINFC_LLCP_NB_SOCKET_MAX) - { - index = 0; - } + psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[psTransport->socketIndex].pSendContext,status); + psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb = NULL; + } + } +} - if(psTransport->pSocketTable[index].bSocketAcceptPending == TRUE - || psTransport->pSocketTable[index].bSocketConnectPending == TRUE - || psTransport->pSocketTable[index].bSocketDiscPending == TRUE - || psTransport->pSocketTable[index].bSocketRNRPending == TRUE - || psTransport->pSocketTable[index].bSocketRRPending == TRUE - || psTransport->pSocketTable[index].bSocketSendPending == TRUE - || psTransport->pSocketTable[index].pfSocketSend_Cb != NULL) - { - /* socket found */ - socketFound = TRUE; - psLocalLlcpSocket = &psTransport->pSocketTable[index]; - break; - } - else - { - if(index == psTransport->socketIndex) - { - break; - } - else - { - index ++; - } - } - }while(index != ((psTransport->socketIndex+1)%PHFRINFC_LLCP_NB_SOCKET_MAX)); +NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket) +{ + NFCSTATUS result = NFCSTATUS_FAILED; + phFriNfc_LlcpTransport_t *psTransport = pSocket->psTransport; - if(socketFound == TRUE) + /* I FRAME */ + if(pSocket->bSocketSendPending == TRUE) + { + /* Test the RW window */ + if(CHECK_SEND_RW(pSocket)) { - socketFound = FALSE; - /* perform the command pending */ + result = static_performSendInfo(pSocket); + } + } + /* RR FRAME */ + else if(pSocket->bSocketRRPending == TRUE) + { + /* Reset RR pending */ + pSocket->bSocketRRPending = FALSE; - /* I FRAME */ - if(psLocalLlcpSocket->bSocketSendPending == TRUE) - { - /* Test the RW window */ - if(CHECK_SEND_RW(psLocalLlcpSocket)) - { - result = static_performSendInfo(psLocalLlcpSocket); + /* Send RR Frame */ + result = phFriNfc_Llcp_Send_ReceiveReady_Frame(pSocket); + } + /* RNR Frame */ + else if(pSocket->bSocketRNRPending == TRUE) + { + /* Reset RNR pending */ + pSocket->bSocketRNRPending = FALSE; - /* Reset Send Pending Flag */ - psLocalLlcpSocket->bSocketSendPending = FALSE; - } - } - /* RR FRAME */ - else if(psLocalLlcpSocket->bSocketRRPending == TRUE) - { - /* Reset RR pending */ - psLocalLlcpSocket->bSocketRRPending = FALSE; + /* Send RNR Frame */ + result = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(pSocket); + } + /* CC Frame */ + else if(pSocket->bSocketAcceptPending == TRUE) + { + /* Reset Accept pending */ + pSocket->bSocketAcceptPending = FALSE; - /* Send RR Frame */ - result = phFriNfc_Llcp_Send_ReceiveReady_Frame(psLocalLlcpSocket); - } + /* Fill the psLlcpHeader stuture with the DSAP,CC PTYPE and the SSAP */ + pSocket->sLlcpHeader.dsap = pSocket->socket_dSap; + pSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CC; + pSocket->sLlcpHeader.ssap = pSocket->socket_sSap; - /* RNR Frame */ - else if(psLocalLlcpSocket->bSocketRNRPending == TRUE) - { - /* Reset RNR pending */ - psLocalLlcpSocket->bSocketRNRPending = FALSE; + /* Send Pending */ + pSocket->psTransport->bSendPending = TRUE; - /* Send RNR Frame */ - result = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(psLocalLlcpSocket); - } - /* CC Frame */ - else if(psLocalLlcpSocket->bSocketAcceptPending == TRUE) - { - /* Reset Accept pending */ - psLocalLlcpSocket->bSocketAcceptPending = FALSE; - - /* Fill the psLlcpHeader stuture with the DSAP,CC PTYPE and the SSAP */ - psLocalLlcpSocket->sLlcpHeader.dsap = psLocalLlcpSocket->socket_dSap; - psLocalLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CC; - psLocalLlcpSocket->sLlcpHeader.ssap = psLocalLlcpSocket->socket_sSap; - - /* Set the socket state to accepted */ - psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted; - - /* Store the index of the socket */ - psTransport->socketIndex = psLocalLlcpSocket->index; - - /* Send a CC Frame */ - result = phFriNfc_LlcpConnTransport_Send(psTransport->pLlcp, - &psLocalLlcpSocket->sLlcpHeader, - NULL, - &psLocalLlcpSocket->sSocketSendBuffer, - phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, - psTransport); - } - /* CONNECT FRAME */ - else if(psLocalLlcpSocket->bSocketConnectPending == TRUE) - { - /* Reset Accept pending */ - psLocalLlcpSocket->bSocketConnectPending = FALSE; - - /* Store the index of the socket */ - psTransport->socketIndex = psLocalLlcpSocket->index; - - /* Set the socket in connecting state */ - psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting; - - /* send CONNECT */ - result = phFriNfc_LlcpConnTransport_Send(psTransport->pLlcp, - &psLocalLlcpSocket->sLlcpHeader, - NULL, - &psLocalLlcpSocket->sSocketSendBuffer, - phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, - psTransport); - } - /* DISC FRAME */ - else if(psLocalLlcpSocket->bSocketDiscPending == TRUE) - { - /* Reset Disc Pending */ - psLocalLlcpSocket->bSocketDiscPending = FALSE; + /* Set the socket state to accepted */ + pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted; - /* Set the socket in connecting state */ - psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting; + /* Send a CC Frame */ + result = phFriNfc_LlcpTransport_LinkSend(psTransport, + &pSocket->sLlcpHeader, + NULL, + &pSocket->sSocketSendBuffer, + phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, + psTransport); + } + /* CONNECT FRAME */ + else if(pSocket->bSocketConnectPending == TRUE) + { + /* Reset Accept pending */ + pSocket->bSocketConnectPending = FALSE; - /* Store the index of the socket */ - psTransport->socketIndex = psLocalLlcpSocket->index; + /* Send Pending */ + pSocket->psTransport->bSendPending = TRUE; - /* Send DISC */ - result = phFriNfc_LlcpConnTransport_Send(psTransport->pLlcp, - &psLocalLlcpSocket->sLlcpHeader, - NULL, - &psLocalLlcpSocket->sSocketSendBuffer, - phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, - psTransport); + /* Set the socket in connecting state */ + pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting; - /* Call ErrCB due to a DISC */ - psLocalLlcpSocket->pSocketErrCb(psLocalLlcpSocket->pContext, PHFRINFC_LLCP_ERR_DISCONNECTED); - } - /* Call SEND IFRAME CB */ - else if((psLocalLlcpSocket->pfSocketSend_Cb != NULL) && !psLocalLlcpSocket->bSocketSendPending) - { - psLocalLlcpSocket->pfSocketSend_Cb(psLocalLlcpSocket->pSendContext,status); - psLocalLlcpSocket->pfSocketSend_Cb = NULL; - } - } - /* Reset the current length of the send buffer */ - //psTransport->pSocketTable[psTransport->socketIndex].sSocketSendBuffer.length = psTransport->pSocketTable[psTransport->socketIndex].bufferSendMaxLength; + /* send CONNECT */ + result = phFriNfc_LlcpTransport_LinkSend(psTransport, + &pSocket->sLlcpHeader, + NULL, + &pSocket->sSocketSendBuffer, + phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, + psTransport); } - else + /* DISC FRAME */ + else if(pSocket->bSocketDiscPending == TRUE) { - /* Send CB error */ - if(!psTransport->pSocketTable[psTransport->socketIndex].bSocketSendPending && psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb != NULL) - { - psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[psTransport->socketIndex].pSendContext,status); - psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb = NULL; - } + /* Reset Disc Pending */ + pSocket->bSocketDiscPending = FALSE; + + /* Send Pending */ + pSocket->psTransport->bSendPending = TRUE; + + /* Set the socket in connecting state */ + pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting; + + /* Send DISC */ + result = phFriNfc_LlcpTransport_LinkSend(psTransport, + &pSocket->sLlcpHeader, + NULL, + &pSocket->sSocketSendBuffer, + phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, + psTransport); + + /* Call ErrCB due to a DISC */ + pSocket->pSocketErrCb(pSocket->pContext, PHFRINFC_LLCP_ERR_DISCONNECTED); } + + return result; } static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcpSocket) @@ -313,8 +230,8 @@ static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcp phFriNfc_LlcpTransport_t *psTransport = psLlcpSocket->psTransport; NFCSTATUS status; - /* Reset Send Pending */ - psLlcpSocket->bSocketSendPending = FALSE; + /* Set transport send pending */ + psTransport->bSendPending = TRUE; /* Set the Header */ psLlcpSocket->sLlcpHeader.dsap = psLlcpSocket->socket_dSap; @@ -332,16 +249,19 @@ static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcp psTransport->socketIndex = psLlcpSocket->index; /* Send I_PDU */ - status = phFriNfc_LlcpConnTransport_Send(psTransport->pLlcp, + status = phFriNfc_LlcpTransport_LinkSend(psTransport, &psLlcpSocket->sLlcpHeader, &psLlcpSocket->sSequence, &psLlcpSocket->sSocketSendBuffer, phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, - psTransport); + psLlcpSocket->psTransport); /* Update VS */ psLlcpSocket->socket_VS = (psLlcpSocket->socket_VS+1)%16; + /* Reset Send Pending */ + psLlcpSocket->bSocketSendPending = FALSE; + return status; } @@ -383,49 +303,6 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_Abort(phFriNfc_LlcpTranspo pLlcpSocket->pListenContext = NULL; } -static NFCSTATUS phFriNfc_Llcp_Send_DisconnectMode_Frame(phFriNfc_LlcpTransport_t* psTransport, - uint8_t dsap, - uint8_t ssap, - uint8_t dmOpCode) -{ - NFCSTATUS status = NFCSTATUS_SUCCESS; - - /* Test if a send is pending */ - if(psTransport->bSendPending) - { - /* DM pending */ - psTransport->bDmPending = TRUE; - - /* Store DM Info */ - psTransport->DmInfoBuffer[0] = dsap; - psTransport->DmInfoBuffer[1] = ssap; - psTransport->DmInfoBuffer[2] = dmOpCode; - - status = NFCSTATUS_PENDING; - } - else - { - /* Set the header */ - psTransport->sDmHeader.dsap = dsap; - psTransport->sDmHeader.ptype = PHFRINFC_LLCP_PTYPE_DM; - psTransport->sDmHeader.ssap = ssap; - - /* Save Operation Code to be provided in DM frame payload */ - psTransport->DmInfoBuffer[2] = dmOpCode; - psTransport->sDmPayload.buffer = &psTransport->DmInfoBuffer[2]; - psTransport->sDmPayload.length = PHFRINFC_LLCP_DM_LENGTH; - - /* Send DM frame */ - status = phFriNfc_LlcpConnTransport_Send(psTransport->pLlcp, - &psTransport->sDmHeader, - NULL, - &psTransport->sDmPayload, - phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, - psTransport); - } - - return status; -} static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket) { @@ -455,7 +332,7 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_So pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index; /* Send RR frame */ - status = phFriNfc_LlcpConnTransport_Send(pLlcpSocket->psTransport->pLlcp, + status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, &pLlcpSocket->sLlcpHeader, &pLlcpSocket->sSequence, NULL, @@ -495,7 +372,7 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index; /* Send RNR frame */ - status = phFriNfc_LlcpConnTransport_Send(pLlcpSocket->psTransport->pLlcp, + status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, &pLlcpSocket->sLlcpHeader, &pLlcpSocket->sSequence, NULL, @@ -505,97 +382,6 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport return status; } -static NFCSTATUS phFriNfc_Llcp_Send_FrameReject_Frame(phFriNfc_LlcpTransport_t *psTransport, - uint8_t dsap, - uint8_t rejectedPTYPE, - uint8_t ssap, - phFriNfc_Llcp_sPacketSequence_t* sLlcpSequence, - uint8_t WFlag, - uint8_t IFlag, - uint8_t RFlag, - uint8_t SFlag, - uint8_t vs, - uint8_t vsa, - uint8_t vr, - uint8_t vra) -{ - NFCSTATUS status = NFCSTATUS_SUCCESS; - phNfc_sData_t sFrmrBuffer; - uint8_t flagValue; - uint8_t sequence = 0; - uint8_t index; - uint8_t socketFound = FALSE; - - /* Search a socket waiting for a FRAME */ - for(index=0;index<PHFRINFC_LLCP_NB_SOCKET_MAX;index++) - { - /* Test if the socket is in connected state and if its SSAP and DSAP are valid */ - if(psTransport->pSocketTable[index].socket_sSap == dsap - && psTransport->pSocketTable[index].socket_dSap == ssap) - { - /* socket found */ - socketFound = TRUE; - break; - } - } - - /* Test if a socket has been found */ - if(socketFound) - { - /* Set socket state to disconnected */ - psTransport->pSocketTable[index].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault; - - /* Call ErrCB due to a FRMR*/ - psTransport->pSocketTable[index].pSocketErrCb( psTransport->pSocketTable[index].pContext,PHFRINFC_LLCP_ERR_FRAME_REJECTED); - - /* Close the socket */ - status = phFriNfc_LlcpTransport_ConnectionOriented_Close(&psTransport->pSocketTable[index]); - - /* Set FRMR Header */ - psTransport->sLlcpHeader.dsap = dsap; - psTransport->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_FRMR; - psTransport->sLlcpHeader.ssap = ssap; - - /* Set FRMR Information Field */ - flagValue = (WFlag<<7) | (IFlag<<6) | (RFlag<<5) | (SFlag<<4) | rejectedPTYPE; - if (sLlcpSequence != NULL) - { - sequence = (uint8_t)((sLlcpSequence->ns<<4)|(sLlcpSequence->nr)); - } - - psTransport->FrmrInfoBuffer[0] = flagValue; - psTransport->FrmrInfoBuffer[1] = sequence; - psTransport->FrmrInfoBuffer[2] = (vs<<4)|vr ; - psTransport->FrmrInfoBuffer[3] = (vsa<<4)|vra ; - - /* Test if a send is pending */ - if(psTransport->bSendPending) - { - psTransport->bFrmrPending = TRUE; - status = NFCSTATUS_PENDING; - } - else - { - sFrmrBuffer.buffer = psTransport->FrmrInfoBuffer; - sFrmrBuffer.length = 0x04; /* Size of FRMR Information field */ - - /* Send FRMR frame */ - status = phFriNfc_LlcpConnTransport_Send(psTransport->pLlcp, - &psTransport->sLlcpHeader, - NULL, - &sFrmrBuffer, - phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB, - psTransport); - } - } - else - { - /* No active socket*/ - /* FRMR Frame not handled*/ - } - return status; -} - static NFCSTATUS phFriNfc_Llcp_GetSocket_Params(phNfc_sData_t *psParamsTLV, phNfc_sData_t *psServiceName, uint8_t *pRemoteRW_Size, @@ -698,19 +484,19 @@ static void Handle_ConnectionFrame(phFriNfc_LlcpTransport_t *psTransport, { /* Incorrect TLV */ /* send FRMR */ - status = phFriNfc_Llcp_Send_FrameReject_Frame(psTransport, - ssap, - PHFRINFC_LLCP_PTYPE_CONNECT, - dsap, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00); + status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, + ssap, + PHFRINFC_LLCP_PTYPE_CONNECT, + dsap, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00); } else { @@ -829,20 +615,20 @@ static void Handle_ConnectionFrame(phFriNfc_LlcpTransport_t *psTransport, { /* No more socket are available */ /* Send a DM (0x21) */ - status = phFriNfc_Llcp_Send_DisconnectMode_Frame (psTransport, - ssap, - dsap, - PHFRINFC_LLCP_DM_OPCODE_SOCKET_NOT_AVAILABLE); + status = phFriNfc_LlcpTransport_SendDisconnectMode (psTransport, + ssap, + dsap, + PHFRINFC_LLCP_DM_OPCODE_SOCKET_NOT_AVAILABLE); } } else { /* Service Name not found or Port number not found */ /* Send a DM (0x02) */ - status = phFriNfc_Llcp_Send_DisconnectMode_Frame (psTransport, - ssap, - dsap, - PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_FOUND); + status = phFriNfc_LlcpTransport_SendDisconnectMode (psTransport, + ssap, + dsap, + PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_FOUND); } } @@ -868,19 +654,19 @@ static void Handle_ConnectionCompleteFrame(phFriNfc_LlcpTransport_t *psTran { /* Incorrect TLV */ /* send FRMR */ - status = phFriNfc_Llcp_Send_FrameReject_Frame(psTransport, - ssap, - PHFRINFC_LLCP_PTYPE_CC, - dsap, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00); + status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, + ssap, + PHFRINFC_LLCP_PTYPE_CC, + dsap, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00); } else { @@ -991,37 +777,18 @@ static void Handle_DisconnectFrame(phFriNfc_LlcpTransport_t *psTransport, psLocalLlcpSocket->bSocketSendPending = FALSE; } - /* Test if a send is pending with this scoket */ - if(psTransport->bSendPending) - { - /* Set DM pending */ - psTransport->bDmPending = TRUE; - - /* Set the socket disconnecting */ - psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting; - - /* Send pending, store the DISC request */ - psTransport->DmInfoBuffer[0] = ssap; - psTransport->DmInfoBuffer[1] = dsap; - psTransport->DmInfoBuffer[2] = PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED; - } - else - { - /* Set the socket disconnected */ - psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketCreated; - - /* Store the index of the socket */ - psTransport->socketIndex = psLocalLlcpSocket->index; + /* Update the socket state */ + psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting; - /* Send a DM*/ - status = phFriNfc_Llcp_Send_DisconnectMode_Frame(psTransport, - ssap, - dsap, - PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED); + /* Send a DM*/ + /* TODO: use a socket internal flag to save */ + status = phFriNfc_LlcpTransport_SendDisconnectMode(psTransport, + ssap, + dsap, + PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED); - /* Call ErrCB due to a DISC */ - psTransport->pSocketTable[index].pSocketErrCb(psTransport->pSocketTable[index].pContext, PHFRINFC_LLCP_ERR_DISCONNECTED); - } + /* Call ErrCB due to a DISC */ + psTransport->pSocketTable[index].pSocketErrCb(psTransport->pSocketTable[index].pContext, PHFRINFC_LLCP_ERR_DISCONNECTED); } else { @@ -1046,19 +813,19 @@ static void Handle_DisconnetModeFrame(phFriNfc_LlcpTransport_t *psTransport if(psData->length != PHFRINFC_LLCP_DM_LENGTH) { /* send FRMR */ - status = phFriNfc_Llcp_Send_FrameReject_Frame(psTransport, - ssap, - PHFRINFC_LLCP_PTYPE_DM, - dsap, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00); + status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, + ssap, + PHFRINFC_LLCP_PTYPE_DM, + dsap, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00); } else { @@ -1132,7 +899,7 @@ static void Handle_Receive_IFrame(phFriNfc_LlcpTransport_t *psTransport, phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL; phFriNfc_Llcp_sPacketSequence_t sLlcpLocalSequence; - uint32_t dataLengthAvailable = 0; + uint32_t dataLengthAvailable = 0; uint32_t dataLengthWrite = 0; uint8_t index; uint8_t socketFound = FALSE; @@ -1226,19 +993,19 @@ static void Handle_Receive_IFrame(phFriNfc_LlcpTransport_t *psTransport, if( WFlag != 0 || IFlag != 0 || RFlag != 0 || SFlag != 0) { /* Send FRMR */ - status = phFriNfc_Llcp_Send_FrameReject_Frame(psTransport, - ssap, - PHFRINFC_LLCP_PTYPE_I, - dsap, - &sLlcpLocalSequence, - WFlag, - IFlag, - RFlag, - SFlag, - psLocalLlcpSocket->socket_VS, - psLocalLlcpSocket->socket_VSA, - psLocalLlcpSocket->socket_VR, - psLocalLlcpSocket->socket_VRA); + status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, + ssap, + PHFRINFC_LLCP_PTYPE_I, + dsap, + &sLlcpLocalSequence, + WFlag, + IFlag, + RFlag, + SFlag, + psLocalLlcpSocket->socket_VS, + psLocalLlcpSocket->socket_VSA, + psLocalLlcpSocket->socket_VR, + psLocalLlcpSocket->socket_VRA); } else @@ -1456,14 +1223,14 @@ static void Handle_ReceiveReady_Frame(phFriNfc_LlcpTransport_t *psTransport if (WFlag || IFlag || RFlag || SFlag) { /* Send FRMR */ - status = phFriNfc_Llcp_Send_FrameReject_Frame(psTransport, - ssap, PHFRINFC_LLCP_PTYPE_RR, dsap, - &sLlcpLocalSequence, - WFlag, IFlag, RFlag, SFlag, - psLocalLlcpSocket->socket_VS, - psLocalLlcpSocket->socket_VSA, - psLocalLlcpSocket->socket_VR, - psLocalLlcpSocket->socket_VRA); + status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, + ssap, PHFRINFC_LLCP_PTYPE_RR, dsap, + &sLlcpLocalSequence, + WFlag, IFlag, RFlag, SFlag, + psLocalLlcpSocket->socket_VS, + psLocalLlcpSocket->socket_VSA, + psLocalLlcpSocket->socket_VR, + psLocalLlcpSocket->socket_VRA); } else { @@ -1571,14 +1338,14 @@ static void Handle_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_t *psTransp if( bWFlag != 0 || bIFlag != 0 || bRFlag != 0 || bSFlag != 0) { /* Send FRMR */ - status = phFriNfc_Llcp_Send_FrameReject_Frame(psTransport, - ssap, PHFRINFC_LLCP_PTYPE_RNR, dsap, - &sLlcpLocalSequence, - bWFlag, bIFlag, bRFlag, bSFlag, - psLocalLlcpSocket->socket_VS, - psLocalLlcpSocket->socket_VSA, - psLocalLlcpSocket->socket_VR, - psLocalLlcpSocket->socket_VRA); + status = phFriNfc_LlcpTransport_SendFrameReject(psTransport, + ssap, PHFRINFC_LLCP_PTYPE_RNR, dsap, + &sLlcpLocalSequence, + bWFlag, bIFlag, bRFlag, bSFlag, + psLocalLlcpSocket->socket_VS, + psLocalLlcpSocket->socket_VSA, + psLocalLlcpSocket->socket_VR, + psLocalLlcpSocket->socket_VRA); } else { @@ -1723,13 +1490,12 @@ void Handle_ConnectionOriented_IncommingFrame(phFriNfc_LlcpTransport_t case PHFRINFC_LLCP_PTYPE_RESERVED1: case PHFRINFC_LLCP_PTYPE_RESERVED2: case PHFRINFC_LLCP_PTYPE_RESERVED3: - case PHFRINFC_LLCP_PTYPE_RESERVED4: { - phFriNfc_Llcp_Send_FrameReject_Frame( psTransport, - dsap, ptype, ssap, - &sSequence, - TRUE, FALSE, FALSE, FALSE, - 0, 0, 0, 0); + phFriNfc_LlcpTransport_SendFrameReject( psTransport, + dsap, ptype, ssap, + &sSequence, + TRUE, FALSE, FALSE, FALSE, + 0, 0, 0, 0); }break; } } @@ -2034,7 +1800,7 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTranspor pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index; /* Send a CC Frame */ - status = phFriNfc_LlcpConnTransport_Send(pLlcpSocket->psTransport->pLlcp, + status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, &pLlcpSocket->sLlcpHeader, NULL, &pLlcpSocket->sSocketSendBuffer, @@ -2085,10 +1851,10 @@ NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Reject( phFriNfc_LlcpTranspo pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index; /* Send a DM*/ - status = phFriNfc_Llcp_Send_DisconnectMode_Frame(pLlcpSocket->psTransport, - pLlcpSocket->socket_dSap, - pLlcpSocket->socket_sSap, - PHFRINFC_LLCP_DM_OPCODE_CONNECT_REJECTED); + status = phFriNfc_LlcpTransport_SendDisconnectMode(pLlcpSocket->psTransport, + pLlcpSocket->socket_dSap, + pLlcpSocket->socket_sSap, + PHFRINFC_LLCP_DM_OPCODE_CONNECT_REJECTED); return status; } @@ -2224,7 +1990,8 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransp /* Store the index of the socket */ pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index; - status = phFriNfc_LlcpConnTransport_Send(pLlcpSocket->psTransport->pLlcp, + + status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, &pLlcpSocket->sLlcpHeader, NULL, &pLlcpSocket->sSocketSendBuffer, @@ -2328,7 +2095,7 @@ NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(phFriNfc_LlcpTran /* Store the index of the socket */ pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index; - status = phFriNfc_LlcpConnTransport_Send(pLlcpSocket->psTransport->pLlcp, + status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, &pLlcpSocket->sLlcpHeader, NULL, NULL, @@ -2513,8 +2280,12 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Send(phFriNfc_LlcpTransport_ } else { - /* Perform I-Frame send */ + /* Store the Send CB and context */ + pLlcpSocket->pfSocketSend_Cb = pSend_RspCb; + pLlcpSocket->pSendContext = pContext; + status = static_performSendInfo(pLlcpSocket); + if(status != NFCSTATUS_PENDING) { LLCP_PRINT("Release Send callback"); diff --git a/src/phFriNfc_LlcpTransport_Connection.h b/src/phFriNfc_LlcpTransport_Connection.h index 6b8dbc4..4a15821 100644 --- a/src/phFriNfc_LlcpTransport_Connection.h +++ b/src/phFriNfc_LlcpTransport_Connection.h @@ -30,13 +30,14 @@ #include <phFriNfc_Llcp.h> - void Handle_ConnectionOriented_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTransport, phNfc_sData_t *psData, uint8_t dsap, uint8_t ptype, uint8_t ssap); +NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket); + /** * \ingroup grp_lib_nfc * \brief <b>Get the local options of a socket</b>. @@ -300,4 +301,4 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Recv( phFriNfc_LlcpTransport phNfc_sData_t* psBuffer, pphFriNfc_LlcpTransportSocketRecvCb_t pRecv_RspCb, void* pContext); -#endif /* PHFRINFC_LLCP_TRANSPORT_CONNECTION_H */
\ No newline at end of file +#endif /* PHFRINFC_LLCP_TRANSPORT_CONNECTION_H */ diff --git a/src/phFriNfc_LlcpTransport_Connectionless.c b/src/phFriNfc_LlcpTransport_Connectionless.c index 941c267..8d26d98 100644 --- a/src/phFriNfc_LlcpTransport_Connectionless.c +++ b/src/phFriNfc_LlcpTransport_Connectionless.c @@ -29,6 +29,39 @@ #include <phFriNfc_LlcpTransport.h> #include <phFriNfc_Llcp.h> +static void phFriNfc_LlcpTransport_Connectionless_SendTo_CB(void* pContext, + NFCSTATUS status); + +NFCSTATUS phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket) +{ + NFCSTATUS status = NFCSTATUS_FAILED; + + /* Check if something is pending and if transport layer is ready to send */ + if ((pSocket->pfSocketSend_Cb != NULL) && + (pSocket->psTransport->bSendPending == FALSE)) + { + /* Fill the psLlcpHeader stuture with the DSAP,PTYPE and the SSAP */ + pSocket->sLlcpHeader.dsap = pSocket->socket_dSap; + pSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_UI; + pSocket->sLlcpHeader.ssap = pSocket->socket_sSap; + + /* Send to data to the approiate socket */ + status = phFriNfc_LlcpTransport_LinkSend(pSocket->psTransport, + &pSocket->sLlcpHeader, + NULL, + &pSocket->sSocketSendBuffer, + phFriNfc_LlcpTransport_Connectionless_SendTo_CB, + pSocket); + } + else + { + /* Cannot send now, retry later */ + } + + return status; +} + + /* TODO: comment function Handle_Connectionless_IncommingFrame */ void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTransport, phNfc_sData_t *psData, @@ -66,19 +99,17 @@ void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTr static void phFriNfc_LlcpTransport_Connectionless_SendTo_CB(void* pContext, NFCSTATUS status) { - phFriNfc_LlcpTransport_Socket_t *pLlcpSocket = (phFriNfc_LlcpTransport_Socket_t*)pContext; - pphFriNfc_LlcpTransportSocketSendCb_t pfSendCallback = pLlcpSocket->pfSocketSend_Cb; - - /* Reset the SendPending variable */ - pLlcpSocket->bSocketSendPending = FALSE; - - /* Clear out the callback */ - pLlcpSocket->pfSocketSend_Cb = NULL; + phFriNfc_LlcpTransport_Socket_t * pLlcpSocket = (phFriNfc_LlcpTransport_Socket_t*)pContext; + pphFriNfc_LlcpTransportSocketSendCb_t pfSavedCallback; + void * pSavedContext; /* Call the send callback */ - pfSendCallback(pLlcpSocket->pSendContext,status); - - + pfSavedCallback = pLlcpSocket->pfSocketSend_Cb; + if (pfSavedCallback != NULL) + { + pLlcpSocket->pfSocketSend_Cb = NULL; + pfSavedCallback(pLlcpSocket->pSendContext, status); + } } static void phFriNfc_LlcpTransport_Connectionless_Abort(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket) @@ -185,19 +216,19 @@ NFCSTATUS phFriNfc_LlcpTransport_Connectionless_SendTo(phFriNfc_LlcpTransport_So pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb, void* pContext) { - NFCSTATUS status = NFCSTATUS_SUCCESS; + NFCSTATUS status = NFCSTATUS_FAILED; /* 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) + /* Test if a send is already pending at transport level */ + if(pLlcpSocket->psTransport->bSendPending == TRUE) { - pphFriNfc_LlcpTransportSocketSendCb_t pfSendCallback = pLlcpSocket->pfSocketSend_Cb; - status = NFCSTATUS_FAILED; - pLlcpSocket->pfSocketSend_Cb = NULL; - pfSendCallback(pLlcpSocket->pSendContext,status); + /* Save the request so it can be handled in phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations() */ + pLlcpSocket->sSocketSendBuffer = *psBuffer; + pLlcpSocket->socket_dSap = nSap; + status = NFCSTATUS_PENDING; } else { @@ -206,10 +237,8 @@ NFCSTATUS phFriNfc_LlcpTransport_Connectionless_SendTo(phFriNfc_LlcpTransport_So 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, + status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport, &pLlcpSocket->sLlcpHeader, NULL, psBuffer, diff --git a/src/phFriNfc_LlcpTransport_Connectionless.h b/src/phFriNfc_LlcpTransport_Connectionless.h index b502069..2fa263e 100644 --- a/src/phFriNfc_LlcpTransport_Connectionless.h +++ b/src/phFriNfc_LlcpTransport_Connectionless.h @@ -36,6 +36,8 @@ void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTr uint8_t dsap, uint8_t ssap); +NFCSTATUS phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket); + /** * \ingroup grp_fri_nfc * \brief <b>Close a socket on a LLCP-connectionless device</b>. @@ -115,4 +117,4 @@ NFCSTATUS phLibNfc_LlcpTransport_Connectionless_RecvFrom(phFriNfc_LlcpTransport_ pphFriNfc_LlcpTransportSocketRecvFromCb_t pRecv_Cb, void* pContext); -#endif /* PHFRINFC_LLCP_TRANSPORT_CONNECTIONLESS_H */
\ No newline at end of file +#endif /* PHFRINFC_LLCP_TRANSPORT_CONNECTIONLESS_H */ |