From 379262748505107b88ec92675529063789e44da6 Mon Sep 17 00:00:00 2001 From: Sylvain Fonteneau Date: Thu, 12 May 2011 16:21:52 +0200 Subject: Fixed LLCP receive function when accessing RW. In some situations, the working buffer may be full and some packets are stored in the receive window when trying to read from upper layer. In this case, the receive function first reads data from the working buffer and if possible, also tries to read data stored in the receive window. The previous receive window data extraction algorithm could lead to an infinite loop. With this fix, we can ensure that this won't happen any more. Change-Id: Iddb412213f4e9cb5fb42691bd282dbf0a21a936e --- src/phFriNfc_LlcpTransport_Connection.c | 41 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/phFriNfc_LlcpTransport_Connection.c b/src/phFriNfc_LlcpTransport_Connection.c index 19c662a..b75406b 100644 --- a/src/phFriNfc_LlcpTransport_Connection.c +++ b/src/phFriNfc_LlcpTransport_Connection.c @@ -2647,33 +2647,32 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Recv( phFriNfc_LlcpTransport if(dataLengthRead != 0) { /* Test If data is present in the RW Buffer */ - if(pLlcpSocket->indexRwRead != pLlcpSocket->indexRwWrite) + while(pLlcpSocket->indexRwRead != pLlcpSocket->indexRwWrite) { - do + /* Get the data length available in the linear buffer */ + dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&pLlcpSocket->sCyclicFifoBuffer); + + /* Exit if not enough memory available in linear buffer */ + if(dataLengthAvailable < pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length) { - /* Get the data length available in the linear buffer */ - dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&pLlcpSocket->sCyclicFifoBuffer); + break; + } - /* Test if enought place is available */ - if(dataLengthAvailable > pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length ) - { - /* Write data into the linear buffer */ - dataLengthWrite = phFriNfc_Llcp_CyclicFifoWrite(&pLlcpSocket->sCyclicFifoBuffer, - pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].buffer, - pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length); - /* Update VR */ - pLlcpSocket->socket_VR = (pLlcpSocket->socket_VR+1)%16; + /* Write data into the linear buffer */ + dataLengthWrite = phFriNfc_Llcp_CyclicFifoWrite(&pLlcpSocket->sCyclicFifoBuffer, + pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].buffer, + pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length); + /* Update VR */ + pLlcpSocket->socket_VR = (pLlcpSocket->socket_VR+1)%16; - /* Set flag bufferized to TRUE */ - dataBufferized = TRUE; + /* Set flag bufferized to TRUE */ + dataBufferized = TRUE; - /* Update RW Buffer length */ - pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length = 0; + /* Update RW Buffer length */ + pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length = 0; - /* Update Value Rw Read Index*/ - pLlcpSocket->indexRwRead++; - } - }while(dataLengthAvailable > pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length); + /* Update Value Rw Read Index*/ + pLlcpSocket->indexRwRead++; } /* Test if data has been bufferized after a read access */ -- cgit v1.1