summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSylvain Fonteneau <sylvain.fonteneau@trusted-logic.com>2011-05-12 16:21:52 +0200
committerMartijn Coenen <maco@google.com>2011-07-25 19:49:05 -0500
commit379262748505107b88ec92675529063789e44da6 (patch)
tree0f7c649fee4cd635b3e2c40840f5add0ff958223 /src
parent45101265f65461385bd7c81db0bfc84b334df8e0 (diff)
downloadexternal_libnfc-nxp-379262748505107b88ec92675529063789e44da6.zip
external_libnfc-nxp-379262748505107b88ec92675529063789e44da6.tar.gz
external_libnfc-nxp-379262748505107b88ec92675529063789e44da6.tar.bz2
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
Diffstat (limited to 'src')
-rw-r--r--src/phFriNfc_LlcpTransport_Connection.c41
1 files changed, 20 insertions, 21 deletions
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 */