diff options
author | Sylvain Fonteneau <sylvain.fonteneau@trusted-logic.com> | 2010-10-28 04:00:23 +0200 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2010-10-28 10:13:06 -0700 |
commit | cf5cd1520ea32d2b65712a36a105f396df07345c (patch) | |
tree | 6047e8487d8e95e087c8c106364faacf52f8f11d /src | |
parent | 99eeb8ab747ce32a0b99a9abfe1c06eb6d583abc (diff) | |
download | external_libnfc-nxp-cf5cd1520ea32d2b65712a36a105f396df07345c.zip external_libnfc-nxp-cf5cd1520ea32d2b65712a36a105f396df07345c.tar.gz external_libnfc-nxp-cf5cd1520ea32d2b65712a36a105f396df07345c.tar.bz2 |
Fixed LLCP Service Name matching failure.
Service Name is now copied in the libnfc to avoid referencing a pointer that
may not be valid during the whole socket life.
Change-Id: I6572366ac51502d189cc8f1350fa089c11cc2bea
Diffstat (limited to 'src')
-rw-r--r-- | src/phFriNfc_LlcpTransport.c | 8 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport.h | 2 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport_Connection.c | 33 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport_Connectionless.c | 8 |
4 files changed, 40 insertions, 11 deletions
diff --git a/src/phFriNfc_LlcpTransport.c b/src/phFriNfc_LlcpTransport.c index 55a3f15..523a6bd 100644 --- a/src/phFriNfc_LlcpTransport.c +++ b/src/phFriNfc_LlcpTransport.c @@ -23,6 +23,7 @@ */ /*include files*/ +#include <phOsalNfc.h> #include <phLibNfcStatus.h> #include <phLibNfc.h> #include <phNfcLlcpTypes.h> @@ -171,7 +172,6 @@ NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpTran pLlcpTransport->pSocketTable[i].pfSocketListen_Cb = NULL; pLlcpTransport->pSocketTable[i].pfSocketConnect_Cb = NULL; pLlcpTransport->pSocketTable[i].pfSocketDisconnect_Cb = NULL; - pLlcpTransport->pSocketTable[i].pServiceName = NULL; pLlcpTransport->pSocketTable[i].socket_VS = 0; pLlcpTransport->pSocketTable[i].socket_VSA = 0; pLlcpTransport->pSocketTable[i].socket_VR = 0; @@ -183,6 +183,12 @@ NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpTran pLlcpTransport->pSocketTable[i].index = 0; pLlcpTransport->pSocketTable[i].indexRwRead = 0; pLlcpTransport->pSocketTable[i].indexRwWrite = 0; + + if (pLlcpTransport->pSocketTable[i].sServiceName.buffer != NULL) { + phOsalNfc_FreeMemory(pLlcpTransport->pSocketTable[i].sServiceName.buffer); + } + pLlcpTransport->pSocketTable[i].sServiceName.buffer = NULL; + pLlcpTransport->pSocketTable[i].sServiceName.length = 0; } /* Start The Receive Loop */ diff --git a/src/phFriNfc_LlcpTransport.h b/src/phFriNfc_LlcpTransport.h index b07fbe5..27fda96 100644 --- a/src/phFriNfc_LlcpTransport.h +++ b/src/phFriNfc_LlcpTransport.h @@ -161,7 +161,7 @@ struct phFriNfc_LlcpTransport_Socket /* Remote and local socket info */ uint8_t socket_sSap; uint8_t socket_dSap; - phNfc_sData_t *pServiceName; + phNfc_sData_t sServiceName; uint8_t remoteRW; uint8_t localRW; uint16_t remoteMIU; diff --git a/src/phFriNfc_LlcpTransport_Connection.c b/src/phFriNfc_LlcpTransport_Connection.c index 314204c..5b114c2 100644 --- a/src/phFriNfc_LlcpTransport_Connection.c +++ b/src/phFriNfc_LlcpTransport_Connection.c @@ -22,6 +22,7 @@ * */ /*include files*/ +#include <phOsalNfc.h> #include <phLibNfcStatus.h> #include <phLibNfc.h> #include <phNfcLlcpTypes.h> @@ -671,8 +672,8 @@ static void Handle_ConnectionFrame(phFriNfc_LlcpTransport_t *psTransport, { /* Test if the socket is in Listen state and if its SN is the good one */ if(psTransport->pSocketTable[index].bSocketListenPending - && (sServiceName.length == psTransport->pSocketTable[index].pServiceName->length) - && !memcmp(sServiceName.buffer,psTransport->pSocketTable[index].pServiceName->buffer,sServiceName.length)) + && (sServiceName.length == psTransport->pSocketTable[index].sServiceName.length) + && !memcmp(sServiceName.buffer,psTransport->pSocketTable[index].sServiceName.buffer,sServiceName.length)) { /* socket with the SN found */ socketFound = TRUE; @@ -1896,17 +1897,17 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Listen(phFriNfc_LlcpTranspor { phFriNfc_LlcpTransport_Socket_t* pCurrentSocket = &pLlcpSocket->psTransport->pSocketTable[index]; - if((pCurrentSocket->pServiceName == NULL) || + if((pCurrentSocket->sServiceName.length == 0) || (pCurrentSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketRegistered)) { /* Do not check inactive or non-SDP registered sockets */ continue; } - if(pCurrentSocket->pServiceName->length != psServiceName->length) { + if(pCurrentSocket->sServiceName.length != psServiceName->length) { /* Service name do not match, check next */ continue; } - if(memcmp(pCurrentSocket->pServiceName->buffer, psServiceName->buffer, psServiceName->length) == 0) + if(memcmp(pCurrentSocket->sServiceName.buffer, psServiceName->buffer, psServiceName->length) == 0) { /* Service name already in use */ return NFCSTATUS_INVALID_PARAMETER; @@ -1924,7 +1925,13 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Listen(phFriNfc_LlcpTranspor pLlcpSocket->bSocketListenPending = TRUE; /* Store the listen socket SN */ - pLlcpSocket->pServiceName = psServiceName; + pLlcpSocket->sServiceName.length = psServiceName->length; + pLlcpSocket->sServiceName.buffer = phOsalNfc_GetMemory(psServiceName->length); + if (pLlcpSocket->sServiceName.buffer == NULL) + { + return NFCSTATUS_NOT_ENOUGH_MEMORY; + } + memcpy(pLlcpSocket->sServiceName.buffer, psServiceName->buffer, psServiceName->length); /* Set the socket state*/ pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketRegistered; @@ -2404,11 +2411,16 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_DisconnectClose_CB(void* 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; + + if (pLlcpSocket->sServiceName.buffer != NULL) { + phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer); + } + pLlcpSocket->sServiceName.buffer = NULL; + pLlcpSocket->sServiceName.length = 0; } else { @@ -2462,11 +2474,16 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Close(phFriNfc_LlcpTransport 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; + + if (pLlcpSocket->sServiceName.buffer != NULL) { + phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer); + } + pLlcpSocket->sServiceName.buffer = NULL; + pLlcpSocket->sServiceName.length = 0; } return NFCSTATUS_SUCCESS; } diff --git a/src/phFriNfc_LlcpTransport_Connectionless.c b/src/phFriNfc_LlcpTransport_Connectionless.c index 67591ad..60c8d49 100644 --- a/src/phFriNfc_LlcpTransport_Connectionless.c +++ b/src/phFriNfc_LlcpTransport_Connectionless.c @@ -22,6 +22,7 @@ * */ /*include files*/ +#include <phOsalNfc.h> #include <phLibNfcStatus.h> #include <phLibNfc.h> #include <phNfcLlcpTypes.h> @@ -105,12 +106,17 @@ NFCSTATUS phFriNfc_LlcpTransport_Connectionless_Close(phFriNfc_LlcpTransport_Soc 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; + if (pLlcpSocket->sServiceName.buffer != NULL) { + phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer); + } + pLlcpSocket->sServiceName.buffer = NULL; + pLlcpSocket->sServiceName.length = 0; + return NFCSTATUS_SUCCESS; } |