summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Cerqueira <cyanogenmod@cerqueira.org>2013-07-24 22:00:12 +0100
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2013-07-24 22:00:12 +0100
commitc90b7baf834fcf0b087e20e3b8a9a0fd3531f6cc (patch)
tree23a9a23e949423a3c749d141c7cad0448373725f
parentf64f7e90f9c0dd6f4c52c66a5fd54d9af754c675 (diff)
parent42f5b41d22bbbad1b16b9cd3aba0512a399f32a6 (diff)
downloadandroid_external_libnfc-nxp-cm-10.2.tar.gz
android_external_libnfc-nxp-cm-10.2.tar.bz2
android_external_libnfc-nxp-cm-10.2.zip
Merge tag 'android-4.3_r2.1' into cm-10.2cm-10.2.1cm-10.2.0cm-10.2-M1stable/cm-10.2cm-10.2
Android 4.3 release 2.1
-rwxr-xr-xAndroid.mk4
-rw-r--r--src/phFriNfc_Llcp.c36
-rw-r--r--src/phFriNfc_Llcp.h6
-rw-r--r--src/phFriNfc_LlcpTransport.c87
-rw-r--r--src/phFriNfc_LlcpTransport.h13
-rw-r--r--src/phFriNfc_LlcpTransport_Connection.c253
-rw-r--r--src/phFriNfc_LlcpTransport_Connectionless.c6
-rwxr-xr-xsrc/phHciNfc_Sequence.c2
-rw-r--r--src/phLibNfc_SE.c3
-rw-r--r--src/phLibNfc_discovery.c9
10 files changed, 233 insertions, 186 deletions
diff --git a/Android.mk b/Android.mk
index d566b15..e9fd9e0 100755
--- a/Android.mk
+++ b/Android.mk
@@ -135,7 +135,7 @@ LOCAL_CFLAGS += -I$(LOCAL_PATH)/src
LOCAL_MODULE:= libnfc
LOCAL_MODULE_TAGS := optional
-LOCAL_SHARED_LIBRARIES := libcutils libnfc_ndef libdl libhardware
+LOCAL_SHARED_LIBRARIES := libcutils libnfc_ndef libdl libhardware liblog
include $(BUILD_SHARED_LIBRARY)
@@ -152,6 +152,6 @@ LOCAL_CFLAGS += -I$(LOCAL_PATH)/src
LOCAL_MODULE:= libnfc_ndef
LOCAL_MODULE_TAGS := optional
-LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_SHARED_LIBRARIES := libcutils liblog
include $(BUILD_SHARED_LIBRARY)
diff --git a/src/phFriNfc_Llcp.c b/src/phFriNfc_Llcp.c
index 8138cd3..5b9736b 100644
--- a/src/phFriNfc_Llcp.c
+++ b/src/phFriNfc_Llcp.c
@@ -162,13 +162,13 @@ static NFCSTATUS phFriNfc_Llcp_InternalDeactivate( phFriNfc_Llcp_t *Llcp )
/* Stop timer */
phOsalNfc_Timer_Stop(Llcp->hSymmTimer);
+ Llcp->psSendHeader = NULL;
+ Llcp->psSendSequence = NULL;
/* Return delayed send operation in error, in any */
if (Llcp->psSendInfo != NULL)
{
phFriNfc_Llcp_Deallocate(Llcp->psSendInfo);
Llcp->psSendInfo = NULL;
- Llcp->psSendHeader = NULL;
- Llcp->psSendSequence = NULL;
}
if (Llcp->pfSendCB != NULL)
{
@@ -560,7 +560,6 @@ static NFCSTATUS phFriNfc_Llcp_InternalActivate( phFriNfc_Llcp_t *Llcp,
phFriNfc_Llcp_ResetLTO(Llcp);
}
}
-
/* Notify upper layer, if Activation failed CB called by Deactivate */
if (status == NFCSTATUS_SUCCESS)
{
@@ -702,7 +701,8 @@ static void phFriNfc_Llcp_LinkStatus_CB( void *pCon
static void phFriNfc_Llcp_ResetLTO( phFriNfc_Llcp_t *Llcp )
{
- uint32_t nDuration;
+ uint32_t nDuration = 0;
+ uint8_t bIsReset = 0;
/* Stop timer */
phOsalNfc_Timer_Stop(Llcp->hSymmTimer);
@@ -720,6 +720,7 @@ static void phFriNfc_Llcp_ResetLTO( phFriNfc_Llcp_t *Llcp )
else if (Llcp->state != PHFRINFC_LLCP_STATE_DEACTIVATION &&
Llcp->state != PHFRINFC_LLCP_STATE_RESET_INIT)
{
+ bIsReset = 1;
/* Not yet in OPERATION state, perform first reset */
if (Llcp->eRole == phFriNfc_LlcpMac_ePeerTypeInitiator)
{
@@ -740,11 +741,22 @@ static void phFriNfc_Llcp_ResetLTO( phFriNfc_Llcp_t *Llcp )
}
else
{
- /* Must answer before the local announced LTO */
- /* NOTE: to ensure the answer is completely sent before LTO, the
- timer is triggered _before_ LTO expiration */
- /* TODO: make sure time scope is enough, and avoid use of magic number */
- nDuration = (Llcp->sLocalParams.lto * 10) / 2;
+ if (bIsReset)
+ {
+ /* Immediately bounce SYMM back - it'll take
+ * a while for the host to come up with something,
+ * and maybe the remote is faster.
+ */
+ nDuration = 1;
+ }
+ else
+ {
+ /* Must answer before the local announced LTO */
+ /* NOTE: to ensure the answer is completely sent before LTO, the
+ timer is triggered _before_ LTO expiration */
+ /* TODO: make sure time scope is enough, and avoid use of magic number */
+ nDuration = (Llcp->sLocalParams.lto * 10) / 2;
+ }
}
LLCP_DEBUG("Starting LLCP timer with duration %d", nDuration);
@@ -856,7 +868,6 @@ static bool_t phFriNfc_Llcp_HandlePendingSend ( phFriNfc_Llcp_t *Llcp )
NFCSTATUS result;
uint8_t bDeallocate = FALSE;
uint8_t return_value = FALSE;
-
/* Handle pending disconnection request */
if (Llcp->bDiscPendingFlag == TRUE)
{
@@ -1326,6 +1337,10 @@ NFCSTATUS phFriNfc_Llcp_Activate( phFriNfc_Llcp_t *Llcp )
/* Update state */
Llcp->state = PHFRINFC_LLCP_STATE_ACTIVATION;
+ /* Reset any headers to send */
+ Llcp->psSendHeader = NULL;
+ Llcp->psSendSequence = NULL;
+
/* Forward check request to MAC layer */
return phFriNfc_LlcpMac_Activate(&Llcp->MAC);
}
@@ -1400,7 +1415,6 @@ NFCSTATUS phFriNfc_Llcp_Send( phFriNfc_Llcp_t *Llcp,
void *pContext )
{
NFCSTATUS result;
-
/* Check parameters */
if ((Llcp == NULL) || (psHeader == NULL) || (pfSend_CB == NULL))
{
diff --git a/src/phFriNfc_Llcp.h b/src/phFriNfc_Llcp.h
index fb26d6a..728697f 100644
--- a/src/phFriNfc_Llcp.h
+++ b/src/phFriNfc_Llcp.h
@@ -221,6 +221,12 @@ typedef void (*phFriNfc_Llcp_LinkStatus_CB_t) (
phFriNfc_Llcp_eLinkStatus_t eLinkStatus
);
+typedef void (*phFriNfc_Llcp_LinkSend_CB_t) (
+ void *pContext,
+ uint8_t socketIndex,
+ NFCSTATUS status
+);
+
typedef void (*phFriNfc_Llcp_Send_CB_t) (
void *pContext,
NFCSTATUS status
diff --git a/src/phFriNfc_LlcpTransport.c b/src/phFriNfc_LlcpTransport.c
index 870aeb4..447eae6 100644
--- a/src/phFriNfc_LlcpTransport.c
+++ b/src/phFriNfc_LlcpTransport.c
@@ -23,6 +23,7 @@
*/
/*include files*/
+#include <cutils/log.h>
#include <phOsalNfc.h>
#include <phLibNfcStatus.h>
#include <phLibNfc.h>
@@ -256,7 +257,7 @@ static NFCSTATUS phFriNfc_LlcpTransport_DiscoveryAnswer(phFriNfc_LlcpTransport_t
uint8_t nTid, nSap;
/* Test if a send is pending */
- if(!psTransport->bSendPending)
+ if(!testAndSetSendPending(psTransport))
{
/* Set the header */
psTransport->sLlcpHeader.dsap = PHFRINFC_LLCP_SAP_SDP;
@@ -293,9 +294,6 @@ static NFCSTATUS phFriNfc_LlcpTransport_DiscoveryAnswer(phFriNfc_LlcpTransport_t
/* Update buffer length to match real TLV size */
sInfoBuffer.length = nTlvOffset;
- /* Send Pending */
- psTransport->bSendPending = TRUE;
-
/* Send SNL frame */
result = phFriNfc_Llcp_Send(psTransport->pLlcp,
&psTransport->sLlcpHeader,
@@ -530,6 +528,20 @@ static void phFriNfc_LlcpTransport__Recv_CB(void *pContext,
}
}
+bool_t testAndSetSendPending(phFriNfc_LlcpTransport_t* transport) {
+ bool_t currentValue;
+ pthread_mutex_lock(&transport->mutex);
+ currentValue = transport->bSendPending;
+ transport->bSendPending = TRUE;
+ pthread_mutex_unlock(&transport->mutex);
+ return currentValue;
+}
+
+void clearSendPending(phFriNfc_LlcpTransport_t* transport) {
+ pthread_mutex_lock(&transport->mutex);
+ transport->bSendPending = FALSE;
+ pthread_mutex_unlock(&transport->mutex);
+}
/* TODO: comment function Transport recv CB */
static void phFriNfc_LlcpTransport_Send_CB(void *pContext,
@@ -538,35 +550,40 @@ static void phFriNfc_LlcpTransport_Send_CB(void *pContext,
phFriNfc_LlcpTransport_t *psTransport = (phFriNfc_LlcpTransport_t*)pContext;
NFCSTATUS result = NFCSTATUS_FAILED;
phNfc_sData_t sFrmrBuffer;
- phFriNfc_Llcp_Send_CB_t pfSavedCb;
+ phFriNfc_Llcp_LinkSend_CB_t pfSavedCb;
void *pSavedContext;
phFriNfc_LlcpTransport_Socket_t *pCurrentSocket = NULL;
uint8_t index;
+ // Store callbacks and socket index, so they can safely be
+ // overwritten by any code in the callback itself.
+ pfSavedCb = psTransport->pfLinkSendCb;
+ pSavedContext = psTransport->pLinkSendContext;
+ psTransport->pfLinkSendCb = NULL;
+ psTransport->pLinkSendContext = NULL;
+ index = psTransport->socketIndex;
+
/* 1 - Reset the FLAG send pending*/
- psTransport->bSendPending = FALSE;
+ clearSendPending(psTransport);
/* 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 */
+ if (!testAndSetSendPending(psTransport)) {
+ /* Reset FRMR pending */
+ psTransport->bFrmrPending = FALSE;
- /* Send Pending */
- psTransport->bSendPending = TRUE;
+ /* Send Frmr */
+ sFrmrBuffer.buffer = psTransport->FrmrInfoBuffer;
+ sFrmrBuffer.length = 0x04; /* Size of FRMR Information field */
- result = phFriNfc_Llcp_Send(psTransport->pLlcp,
+ result = phFriNfc_Llcp_Send(psTransport->pLlcp,
&psTransport->sLlcpHeader,
NULL,
&sFrmrBuffer,
phFriNfc_LlcpTransport_Send_CB,
psTransport);
-
+ }
}
else if(psTransport->bDmPending)
{
@@ -581,18 +598,12 @@ static void phFriNfc_LlcpTransport_Send_CB(void *pContext,
}
/* 3 - Call the original callback */
-
- if (psTransport->pfLinkSendCb != NULL)
+ if (pfSavedCb != NULL)
{
- pfSavedCb = psTransport->pfLinkSendCb;
- pSavedContext = psTransport->pLinkSendContext;
-
- psTransport->pfLinkSendCb = NULL;
- psTransport->pLinkSendContext = NULL;
-
- (*pfSavedCb)(pSavedContext, status);
+ (*pfSavedCb)(pSavedContext, index, status);
}
+
/* 4 - Handle pending send operations */
/* Check for pending discovery requests/responses */
@@ -634,9 +645,6 @@ static void phFriNfc_LlcpTransport_Send_CB(void *pContext,
}
} while(index != psTransport->socketIndex);
-
- /* Save the new index */
- psTransport->socketIndex = index;
}
@@ -679,7 +687,7 @@ NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpTran
pLlcpTransport->pSocketTable[i].pAcceptContext = NULL;
pLlcpTransport->pSocketTable[i].pRejectContext = NULL;
pLlcpTransport->pSocketTable[i].pConnectContext = NULL;
- pLlcpTransport->pSocketTable[i].pDisonnectContext = NULL;
+ pLlcpTransport->pSocketTable[i].pDisconnectContext = NULL;
pLlcpTransport->pSocketTable[i].pSendContext = NULL;
pLlcpTransport->pSocketTable[i].pRecvContext = NULL;
pLlcpTransport->pSocketTable[i].pSocketErrCb = NULL;
@@ -796,7 +804,8 @@ NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t *Llc
phFriNfc_Llcp_sPacketHeader_t *psHeader,
phFriNfc_Llcp_sPacketSequence_t *psSequence,
phNfc_sData_t *psInfo,
- phFriNfc_Llcp_Send_CB_t pfSend_CB,
+ phFriNfc_Llcp_LinkSend_CB_t pfSend_CB,
+ uint8_t socketIndex,
void *pContext )
{
NFCSTATUS status;
@@ -808,6 +817,7 @@ NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t *Llc
/* Save callback details */
LlcpTransport->pfLinkSendCb = pfSend_CB;
LlcpTransport->pLinkSendContext = pContext;
+ LlcpTransport->socketIndex = socketIndex;
/* Call the link-level send function */
status = phFriNfc_Llcp_Send(LlcpTransport->pLlcp, psHeader, psSequence, psInfo, phFriNfc_LlcpTransport_Send_CB, (void*)LlcpTransport);
@@ -885,7 +895,7 @@ NFCSTATUS phFriNfc_LlcpTransport_SendFrameReject(phFriNfc_LlcpTransport_t
psTransport->FrmrInfoBuffer[3] = (vsa<<4)|vra ;
/* Test if a send is pending */
- if(psTransport->bSendPending)
+ if(testAndSetSendPending(psTransport))
{
psTransport->bFrmrPending = TRUE;
status = NFCSTATUS_PENDING;
@@ -895,9 +905,6 @@ NFCSTATUS phFriNfc_LlcpTransport_SendFrameReject(phFriNfc_LlcpTransport_t
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,
@@ -927,7 +934,7 @@ NFCSTATUS phFriNfc_LlcpTransport_SendDisconnectMode(phFriNfc_LlcpTransport_t* ps
NFCSTATUS status = NFCSTATUS_SUCCESS;
/* Test if a send is pending */
- if(psTransport->bSendPending)
+ if(testAndSetSendPending(psTransport))
{
/* DM pending */
psTransport->bDmPending = TRUE;
@@ -951,9 +958,6 @@ NFCSTATUS phFriNfc_LlcpTransport_SendDisconnectMode(phFriNfc_LlcpTransport_t* ps
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,
@@ -1075,7 +1079,7 @@ static NFCSTATUS phFriNfc_LlcpTransport_DiscoverServicesEx(phFriNfc_LlcpTranspor
uint32_t nTlvOffset;
/* Test if a send is pending */
- if(!psTransport->bSendPending)
+ if(!testAndSetSendPending(psTransport))
{
/* Set the header */
psTransport->sLlcpHeader.dsap = PHFRINFC_LLCP_SAP_SDP;
@@ -1111,9 +1115,6 @@ static NFCSTATUS phFriNfc_LlcpTransport_DiscoverServicesEx(phFriNfc_LlcpTranspor
/* Update buffer length to match real TLV size */
sInfoBuffer.length = nTlvOffset;
- /* Send Pending */
- psTransport->bSendPending = TRUE;
-
/* Send SNL frame */
result = phFriNfc_Llcp_Send(psTransport->pLlcp,
&psTransport->sLlcpHeader,
diff --git a/src/phFriNfc_LlcpTransport.h b/src/phFriNfc_LlcpTransport.h
index adcab9e..2f83439 100644
--- a/src/phFriNfc_LlcpTransport.h
+++ b/src/phFriNfc_LlcpTransport.h
@@ -32,6 +32,7 @@
#include <phFriNfc_LlcpUtils.h>
#ifdef ANDROID
#include <string.h>
+#include <pthread.h>
#endif
@@ -224,7 +225,7 @@ struct phFriNfc_LlcpTransport_Socket
void *pAcceptContext;
void *pRejectContext;
void *pConnectContext;
- void *pDisonnectContext;
+ void *pDisconnectContext;
void *pSendContext;
void *pRecvContext;
void *pContext;
@@ -251,12 +252,13 @@ struct phFriNfc_LlcpTransport
phFriNfc_LlcpTransport_Socket_t pSocketTable[PHFRINFC_LLCP_NB_SOCKET_MAX];
phFriNfc_Llcp_CachedServiceName_t pCachedServiceNames[PHFRINFC_LLCP_SDP_ADVERTISED_NB];
phFriNfc_Llcp_t *pLlcp;
+ pthread_mutex_t mutex;
bool_t bSendPending;
bool_t bRecvPending;
bool_t bDmPending;
bool_t bFrmrPending;
- phFriNfc_Llcp_Send_CB_t pfLinkSendCb;
+ phFriNfc_Llcp_LinkSend_CB_t pfLinkSendCb;
void *pLinkSendContext;
uint8_t socketIndex;
@@ -296,6 +298,10 @@ struct phFriNfc_LlcpTransport
################################################################################
*/
+bool_t testAndSetSendPending(phFriNfc_LlcpTransport_t* transport);
+
+void clearSendPending(phFriNfc_LlcpTransport_t* transport);
+
/**
* \ingroup grp_fri_nfc
* \brief <b>Create a socket on a LLCP-connected device</b>.
@@ -322,7 +328,8 @@ NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t *Llc
phFriNfc_Llcp_sPacketHeader_t *psHeader,
phFriNfc_Llcp_sPacketSequence_t *psSequence,
phNfc_sData_t *psInfo,
- phFriNfc_Llcp_Send_CB_t pfSend_CB,
+ phFriNfc_Llcp_LinkSend_CB_t pfSend_CB,
+ uint8_t socketIndex,
void *pContext );
diff --git a/src/phFriNfc_LlcpTransport_Connection.c b/src/phFriNfc_LlcpTransport_Connection.c
index 63e2ff5..f4be919 100644
--- a/src/phFriNfc_LlcpTransport_Connection.c
+++ b/src/phFriNfc_LlcpTransport_Connection.c
@@ -22,6 +22,8 @@
*
*/
/*include files*/
+#define LOG_TAG "NFC"
+#include <cutils/log.h>
#include <phOsalNfc.h>
#include <phLibNfcStatus.h>
#include <phLibNfc.h>
@@ -36,25 +38,11 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_So
static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket);
static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcpSocket);
-
/********** End Function definition ***********/
-NFCSTATUS phFriNfc_LlcpConnTransport_Send( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sPacketHeader_t *psHeader,
- phFriNfc_Llcp_sPacketSequence_t *psSequence,
- phNfc_sData_t *psInfo,
- phFriNfc_Llcp_Send_CB_t pfSend_CB,
- phFriNfc_LlcpTransport_t* psTransport ) {
- NFCSTATUS result = phFriNfc_Llcp_Send(Llcp, psHeader, psSequence, psInfo,
- pfSend_CB, psTransport);
- if (result == NFCSTATUS_PENDING) {
- psTransport->bSendPending = TRUE;
- }
- return result;
-}
-
/* TODO: comment functionphFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB */
static void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* pContext,
+ uint8_t socketIndex,
NFCSTATUS status)
{
phFriNfc_LlcpTransport_t *psTransport;
@@ -64,32 +52,31 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* p
uint8_t index;
uint8_t socketFound = FALSE;
NFCSTATUS result;
-
/* Get Send CB context */
psTransport = (phFriNfc_LlcpTransport_t*)pContext;
if(status == NFCSTATUS_SUCCESS)
{
/* Test the socket */
- switch(psTransport->pSocketTable[psTransport->socketIndex].eSocket_State)
+ switch(psTransport->pSocketTable[socketIndex].eSocket_State)
{
case phFriNfc_LlcpTransportSocket_eSocketAccepted:
{
/* Set socket state to Connected */
- psTransport->pSocketTable[psTransport->socketIndex].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnected;
+ psTransport->pSocketTable[socketIndex].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnected;
/* Call the Accept Callback */
- psTransport->pSocketTable[psTransport->socketIndex].pfSocketAccept_Cb(psTransport->pSocketTable[psTransport->socketIndex].pAcceptContext,status);
- psTransport->pSocketTable[psTransport->socketIndex].pfSocketAccept_Cb = NULL;
- psTransport->pSocketTable[psTransport->socketIndex].pAcceptContext = NULL;
+ psTransport->pSocketTable[socketIndex].pfSocketAccept_Cb(psTransport->pSocketTable[socketIndex].pAcceptContext,status);
+ psTransport->pSocketTable[socketIndex].pfSocketAccept_Cb = NULL;
+ psTransport->pSocketTable[socketIndex].pAcceptContext = NULL;
}break;
case phFriNfc_LlcpTransportSocket_eSocketRejected:
{
/* Store the Llcp socket in a local Llcp socket */
- psTempLlcpSocket = psTransport->pSocketTable[psTransport->socketIndex];
+ psTempLlcpSocket = psTransport->pSocketTable[socketIndex];
/* Reset the socket and set the socket state to default */
- result = phFriNfc_LlcpTransport_Close(&psTransport->pSocketTable[psTransport->socketIndex]);
+ result = phFriNfc_LlcpTransport_Close(&psTransport->pSocketTable[socketIndex]);
/* Call the Reject Callback */
psTempLlcpSocket.pfSocketSend_Cb(psTempLlcpSocket.pRejectContext,status);
@@ -98,10 +85,10 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* p
case phFriNfc_LlcpTransportSocket_eSocketConnected:
{
- if(!psTransport->pSocketTable[psTransport->socketIndex].bSocketSendPending && psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb != NULL)
+ if(!psTransport->pSocketTable[socketIndex].bSocketSendPending && psTransport->pSocketTable[socketIndex].pfSocketSend_Cb != NULL)
{
- psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[psTransport->socketIndex].pSendContext,status);
- psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb = NULL;
+ psTransport->pSocketTable[socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[socketIndex].pSendContext,status);
+ psTransport->pSocketTable[socketIndex].pfSocketSend_Cb = NULL;
}
}break;
default:
@@ -112,10 +99,10 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* p
else
{
/* Send CB error */
- if(!psTransport->pSocketTable[psTransport->socketIndex].bSocketSendPending && psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb != NULL)
+ if(!psTransport->pSocketTable[socketIndex].bSocketSendPending && psTransport->pSocketTable[socketIndex].pfSocketSend_Cb != NULL)
{
- psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[psTransport->socketIndex].pSendContext,status);
- psTransport->pSocketTable[psTransport->socketIndex].pfSocketSend_Cb = NULL;
+ psTransport->pSocketTable[socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[socketIndex].pSendContext,status);
+ psTransport->pSocketTable[socketIndex].pfSocketSend_Cb = NULL;
}
}
}
@@ -125,14 +112,18 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(phFr
{
NFCSTATUS result = NFCSTATUS_FAILED;
phFriNfc_LlcpTransport_t *psTransport = pSocket->psTransport;
-
/* I FRAME */
if(pSocket->bSocketSendPending == TRUE)
{
/* Test the RW window */
if(CHECK_SEND_RW(pSocket))
{
- result = static_performSendInfo(pSocket);
+ if (!testAndSetSendPending(psTransport)) {
+ result = static_performSendInfo(pSocket);
+ if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
+ }
}
}
/* RR FRAME */
@@ -156,72 +147,85 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(phFr
/* CC Frame */
else if(pSocket->bSocketAcceptPending == TRUE)
{
- /* Reset Accept pending */
- pSocket->bSocketAcceptPending = FALSE;
-
- /* 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;
+ if (!testAndSetSendPending(psTransport))
+ {
+ /* Reset Accept pending */
+ pSocket->bSocketAcceptPending = FALSE;
- /* Send Pending */
- pSocket->psTransport->bSendPending = TRUE;
+ /* 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;
- /* Set the socket state to accepted */
- pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted;
+ /* Set the socket state to accepted */
+ pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted;
- /* Send a CC Frame */
- result = phFriNfc_LlcpTransport_LinkSend(psTransport,
+ /* Send a CC Frame */
+ result = phFriNfc_LlcpTransport_LinkSend(psTransport,
&pSocket->sLlcpHeader,
NULL,
&pSocket->sSocketSendBuffer,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pSocket->index,
psTransport);
+
+ if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
+ }
}
/* CONNECT FRAME */
else if(pSocket->bSocketConnectPending == TRUE)
{
- /* Reset Accept pending */
- pSocket->bSocketConnectPending = FALSE;
-
- /* Send Pending */
- pSocket->psTransport->bSendPending = TRUE;
+ if (!testAndSetSendPending(psTransport))
+ {
+ /* Reset Accept pending */
+ pSocket->bSocketConnectPending = FALSE;
- /* Set the socket in connecting state */
- pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting;
+ /* Set the socket in connecting state */
+ pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting;
- /* send CONNECT */
- result = phFriNfc_LlcpTransport_LinkSend(psTransport,
+ /* send CONNECT */
+ result = phFriNfc_LlcpTransport_LinkSend(psTransport,
&pSocket->sLlcpHeader,
NULL,
&pSocket->sSocketSendBuffer,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pSocket->index,
psTransport);
+
+ if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
+ }
}
/* DISC FRAME */
else if(pSocket->bSocketDiscPending == TRUE)
{
- /* Reset Disc Pending */
- pSocket->bSocketDiscPending = FALSE;
-
- /* Send Pending */
- pSocket->psTransport->bSendPending = TRUE;
+ if (!testAndSetSendPending(psTransport))
+ {
+ /* Reset Disc Pending */
+ pSocket->bSocketDiscPending = FALSE;
- /* Set the socket in connecting state */
- pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting;
+ /* Set the socket in connecting state */
+ pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting;
- /* Send DISC */
- result = phFriNfc_LlcpTransport_LinkSend(psTransport,
+ /* Send DISC */
+ result = phFriNfc_LlcpTransport_LinkSend(psTransport,
&pSocket->sLlcpHeader,
NULL,
&pSocket->sSocketSendBuffer,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pSocket->index,
psTransport);
- /* Call ErrCB due to a DISC */
- pSocket->pSocketErrCb(pSocket->pContext, PHFRINFC_LLCP_ERR_DISCONNECTED);
+ if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
+ /* Call ErrCB due to a DISC */
+ pSocket->pSocketErrCb(pSocket->pContext, PHFRINFC_LLCP_ERR_DISCONNECTED);
+ }
}
-
return result;
}
@@ -230,9 +234,6 @@ static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcp
phFriNfc_LlcpTransport_t *psTransport = psLlcpSocket->psTransport;
NFCSTATUS status;
- /* Set transport send pending */
- psTransport->bSendPending = TRUE;
-
/* Set the Header */
psLlcpSocket->sLlcpHeader.dsap = psLlcpSocket->socket_dSap;
psLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_I;
@@ -245,8 +246,6 @@ static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcp
/* Update the VRA */
psLlcpSocket->socket_VRA = psLlcpSocket->socket_VR;
- /* Store the index of the socket */
- psTransport->socketIndex = psLlcpSocket->index;
/* Send I_PDU */
status = phFriNfc_LlcpTransport_LinkSend(psTransport,
@@ -254,13 +253,15 @@ static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcp
&psLlcpSocket->sSequence,
&psLlcpSocket->sSocketSendBuffer,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ psLlcpSocket->index,
psLlcpSocket->psTransport);
+ if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING) {
+ /* Update VS */
+ psLlcpSocket->socket_VS = (psLlcpSocket->socket_VS+1)%16;
- /* Update VS */
- psLlcpSocket->socket_VS = (psLlcpSocket->socket_VS+1)%16;
-
- /* Reset Send Pending */
- psLlcpSocket->bSocketSendPending = FALSE;
+ /* Reset Send Pending */
+ psLlcpSocket->bSocketSendPending = FALSE;
+ }
return status;
}
@@ -293,10 +294,10 @@ static void phFriNfc_LlcpTransport_ConnectionOriented_Abort(phFriNfc_LlcpTranspo
pLlcpSocket->pConnectContext = NULL;
if (pLlcpSocket->pfSocketDisconnect_Cb != NULL)
{
- pLlcpSocket->pfSocketDisconnect_Cb(pLlcpSocket->pDisonnectContext, NFCSTATUS_ABORTED);
+ pLlcpSocket->pfSocketDisconnect_Cb(pLlcpSocket->pDisconnectContext, NFCSTATUS_ABORTED);
pLlcpSocket->pfSocketDisconnect_Cb = NULL;
}
- pLlcpSocket->pDisonnectContext = NULL;
+ pLlcpSocket->pDisconnectContext = NULL;
pLlcpSocket->pfSocketRecvFrom_Cb = NULL;
pLlcpSocket->pfSocketListen_Cb = NULL;
@@ -309,16 +310,13 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_So
NFCSTATUS status = NFCSTATUS_SUCCESS;
/* Test if a send is pending */
- if(pLlcpSocket->psTransport->bSendPending == TRUE)
+ if(testAndSetSendPending(pLlcpSocket->psTransport))
{
pLlcpSocket->bSocketRRPending = TRUE;
status = NFCSTATUS_PENDING;
}
else
{
- /* Set transport to pending */
- pLlcpSocket->psTransport->bSendPending = TRUE;
-
/* Set the header of the RR frame */
pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_RR;
@@ -331,16 +329,17 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_So
/* Update VRA */
pLlcpSocket->socket_VRA = (uint8_t)pLlcpSocket->sSequence.nr;
- /* Store the index of the socket */
- pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
-
/* Send RR frame */
status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
&pLlcpSocket->sLlcpHeader,
&pLlcpSocket->sSequence,
NULL,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pLlcpSocket->index,
pLlcpSocket->psTransport);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(pLlcpSocket->psTransport);
+ }
}
return status;
@@ -352,16 +351,13 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport
/* Test if a send is pending */
- if(pLlcpSocket->psTransport->bSendPending == TRUE)
+ if(testAndSetSendPending(pLlcpSocket->psTransport))
{
pLlcpSocket->bSocketRNRPending = TRUE;
status = NFCSTATUS_PENDING;
}
else
{
- /* Set transport to pending */
- pLlcpSocket->psTransport->bSendPending = TRUE;
-
/* Set the header of the RNR frame */
pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_RNR;
@@ -374,16 +370,17 @@ static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport
/* Update VRA */
pLlcpSocket->socket_VRA = (uint8_t)pLlcpSocket->sSequence.nr;
- /* Store the index of the socket */
- pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
-
/* Send RNR frame */
status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
&pLlcpSocket->sLlcpHeader,
&pLlcpSocket->sSequence,
NULL,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pLlcpSocket->index,
pLlcpSocket->psTransport);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(pLlcpSocket->psTransport);
+ }
}
return status;
}
@@ -566,7 +563,6 @@ static void Handle_ConnectionFrame(phFriNfc_LlcpTransport_t *psTransport,
socketFound = TRUE;
psTransport->pSocketTable[index].index = index;
- psTransport->socketIndex = psTransport->pSocketTable[index].index;
/* Create a communication socket */
pLlcpSocket = &psTransport->pSocketTable[index];
@@ -868,7 +864,7 @@ static void Handle_DisconnetModeFrame(phFriNfc_LlcpTransport_t *psTransport
/* Call Disconnect CB */
if (psLocalLlcpSocket->pfSocketDisconnect_Cb != NULL)
{
- psLocalLlcpSocket->pfSocketDisconnect_Cb(psLocalLlcpSocket->pDisonnectContext,NFCSTATUS_SUCCESS);
+ psLocalLlcpSocket->pfSocketDisconnect_Cb(psLocalLlcpSocket->pDisconnectContext,NFCSTATUS_SUCCESS);
psLocalLlcpSocket->pfSocketDisconnect_Cb = NULL;
}
@@ -1043,9 +1039,12 @@ static void Handle_Receive_IFrame(phFriNfc_LlcpTransport_t *psTransport,
if(psLocalLlcpSocket->bSocketSendPending == TRUE && CHECK_SEND_RW(psLocalLlcpSocket))
{
/* Test if a send is pending at LLC layer */
- if(psTransport->bSendPending != TRUE)
+ if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
{
status = static_performSendInfo(psLocalLlcpSocket);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
}
}
else
@@ -1119,9 +1118,12 @@ static void Handle_Receive_IFrame(phFriNfc_LlcpTransport_t *psTransport,
if((psLocalLlcpSocket->bSocketSendPending == TRUE) && CHECK_SEND_RW(psLocalLlcpSocket))
{
/* Test if a send is pending at LLC layer */
- if(psTransport->bSendPending != TRUE)
+ if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
{
status = static_performSendInfo(psLocalLlcpSocket);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
}
}
else
@@ -1254,9 +1256,12 @@ static void Handle_ReceiveReady_Frame(phFriNfc_LlcpTransport_t *psTransport
if(CHECK_SEND_RW(psLocalLlcpSocket))
{
/* Test if a send is pending at LLC layer */
- if(psTransport->bSendPending != TRUE)
+ if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
{
status = static_performSendInfo(psLocalLlcpSocket);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
}
}
}
@@ -1363,9 +1368,12 @@ static void Handle_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_t *psTransp
if(psLocalLlcpSocket->bSocketSendPending == TRUE && CHECK_SEND_RW(psLocalLlcpSocket))
{
/* Test if a send is pending at LLC layer */
- if(psTransport->bSendPending != TRUE)
+ if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
{
status = static_performSendInfo(psLocalLlcpSocket);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(psTransport);
+ }
}
}
}
@@ -1654,7 +1662,6 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTranspor
uint32_t offset = 0;
uint8_t miux[2];
uint8_t i;
-
/* Store the options in the socket */
memcpy(&pLlcpSocket->sSocketOption, psOptions, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
@@ -1741,7 +1748,7 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTranspor
/* Test if a send is pending */
- if(pLlcpSocket->psTransport->bSendPending == TRUE)
+ if(testAndSetSendPending(pLlcpSocket->psTransport))
{
pLlcpSocket->bSocketAcceptPending = TRUE;
@@ -1763,16 +1770,17 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTranspor
/* Update Send Buffer length value */
pLlcpSocket->sSocketSendBuffer.length = offset;
- /* Store the index of the socket */
- pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
-
/* Send a CC Frame */
status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
&pLlcpSocket->sLlcpHeader,
NULL,
&pLlcpSocket->sSocketSendBuffer,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pLlcpSocket->index,
pLlcpSocket->psTransport);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(pLlcpSocket->psTransport);
+ }
}
clean_and_return:
@@ -1814,9 +1822,6 @@ NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Reject( phFriNfc_LlcpTranspo
pLlcpSocket->pfSocketSend_Cb = pReject_RspCb;
pLlcpSocket->pRejectContext = pContext;
- /* Store the index of the socket */
- pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
-
/* Send a DM*/
status = phFriNfc_LlcpTransport_SendDisconnectMode(pLlcpSocket->psTransport,
pLlcpSocket->socket_dSap,
@@ -1857,7 +1862,6 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransp
void* pContext)
{
NFCSTATUS status = NFCSTATUS_SUCCESS;
-
uint32_t offset = 0;
uint8_t miux[2];
@@ -1938,7 +1942,7 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransp
}
/* Test if a send is pending */
- if(pLlcpSocket->psTransport->bSendPending == TRUE)
+ if(testAndSetSendPending(pLlcpSocket->psTransport))
{
pLlcpSocket->bSocketConnectPending = TRUE;
@@ -1955,15 +1959,16 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransp
/* Set the socket in connecting state */
pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting;
- /* Store the index of the socket */
- pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
-
status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
&pLlcpSocket->sLlcpHeader,
NULL,
&pLlcpSocket->sSocketSendBuffer,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pLlcpSocket->index,
pLlcpSocket->psTransport);
+ if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
+ clearSendPending(pLlcpSocket->psTransport);
+ }
}
clean_and_return:
@@ -2009,7 +2014,7 @@ NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(phFriNfc_LlcpTran
/* Store the Disconnect callback and context*/
pLlcpSocket->pfSocketDisconnect_Cb = pDisconnect_RspCb;
- pLlcpSocket->pDisonnectContext = pContext;
+ pLlcpSocket->pDisconnectContext = pContext;
/* Set the socket in connecting state */
pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting;
@@ -2046,33 +2051,32 @@ NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(phFriNfc_LlcpTran
}
}
- /* Set the socket Header */
- pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
- pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_DISC;
- pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
-
/* Test if a send is pending */
- if( pLlcpSocket->psTransport->bSendPending == TRUE)
+ if( testAndSetSendPending(pLlcpSocket->psTransport))
{
pLlcpSocket->bSocketDiscPending = TRUE;
status = NFCSTATUS_PENDING;
}
else
{
- /* Store the index of the socket */
- pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
+ /* Set the socket Header */
+ pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
+ pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_DISC;
+ pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
&pLlcpSocket->sLlcpHeader,
NULL,
NULL,
phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
+ pLlcpSocket->index,
pLlcpSocket->psTransport);
- if(status != NFCSTATUS_PENDING)
+ if(status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
{
+ clearSendPending(pLlcpSocket->psTransport);
LLCP_PRINT("Release Disconnect callback");
- pLlcpSocket->pfSocketConnect_Cb = NULL;
- pLlcpSocket->pConnectContext = NULL;
+ pLlcpSocket->pfSocketDisconnect_Cb = NULL;
+ pLlcpSocket->pDisconnectContext = NULL;
}
}
@@ -2243,7 +2247,7 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Send(phFriNfc_LlcpTransport_
pLlcpSocket->pSendContext = pContext;
/* Test if a send is pending */
- if(pLlcpSocket->psTransport->bSendPending == TRUE)
+ if(testAndSetSendPending(pLlcpSocket->psTransport))
{
/* Set Send pending */
pLlcpSocket->bSocketSendPending = TRUE;
@@ -2259,8 +2263,9 @@ NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Send(phFriNfc_LlcpTransport_
status = static_performSendInfo(pLlcpSocket);
- if(status != NFCSTATUS_PENDING)
+ if(status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
{
+ clearSendPending(pLlcpSocket->psTransport);
LLCP_PRINT("Release Send callback");
pLlcpSocket->pfSocketSend_Cb = NULL;
pLlcpSocket->pSendContext = NULL;
diff --git a/src/phFriNfc_LlcpTransport_Connectionless.c b/src/phFriNfc_LlcpTransport_Connectionless.c
index b27f6de..4b084a8 100644
--- a/src/phFriNfc_LlcpTransport_Connectionless.c
+++ b/src/phFriNfc_LlcpTransport_Connectionless.c
@@ -30,6 +30,7 @@
#include <phFriNfc_Llcp.h>
static void phFriNfc_LlcpTransport_Connectionless_SendTo_CB(void* pContext,
+ uint8_t socketIndex,
NFCSTATUS status);
NFCSTATUS phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket)
@@ -51,6 +52,7 @@ NFCSTATUS phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(phFriNfc
NULL,
&pSocket->sSocketSendBuffer,
phFriNfc_LlcpTransport_Connectionless_SendTo_CB,
+ pSocket->index,
pSocket);
}
else
@@ -125,6 +127,7 @@ void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTr
/* TODO: comment function phFriNfc_LlcpTransport_Connectionless_SendTo_CB */
static void phFriNfc_LlcpTransport_Connectionless_SendTo_CB(void* pContext,
+ uint8_t socketIndex,
NFCSTATUS status)
{
phFriNfc_LlcpTransport_Socket_t * pLlcpSocket = (phFriNfc_LlcpTransport_Socket_t*)pContext;
@@ -161,7 +164,7 @@ static void phFriNfc_LlcpTransport_Connectionless_Abort(phFriNfc_LlcpTransport_S
pLlcpSocket->pfSocketListen_Cb = NULL;
pLlcpSocket->pConnectContext = NULL;
pLlcpSocket->pfSocketConnect_Cb = NULL;
- pLlcpSocket->pDisonnectContext = NULL;
+ pLlcpSocket->pDisconnectContext = NULL;
pLlcpSocket->pfSocketDisconnect_Cb = NULL;
}
@@ -271,6 +274,7 @@ NFCSTATUS phFriNfc_LlcpTransport_Connectionless_SendTo(phFriNfc_LlcpTransport_So
NULL,
psBuffer,
phFriNfc_LlcpTransport_Connectionless_SendTo_CB,
+ pLlcpSocket->index,
pLlcpSocket);
}
diff --git a/src/phHciNfc_Sequence.c b/src/phHciNfc_Sequence.c
index 604f9bc..d86150d 100755
--- a/src/phHciNfc_Sequence.c
+++ b/src/phHciNfc_Sequence.c
@@ -458,7 +458,7 @@ phHciNfc_FSM_Validate(
} /* End of State Validation Switch */
if( NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition )
{
- status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE);
+ status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_BUSY);
}
break;
}
diff --git a/src/phLibNfc_SE.c b/src/phLibNfc_SE.c
index 2cdb24e..0ccfce6 100644
--- a/src/phLibNfc_SE.c
+++ b/src/phLibNfc_SE.c
@@ -470,6 +470,7 @@ NFCSTATUS phLibNfc_SE_SetMode ( phLibNfc_Handle hSE_Handle,
}
else
{
+ phLibNfc_eSE_ActivationMode originalMode = pLibContext->sSeContext.eActivatedMode;
switch(eActivation_mode)
{
case phLibNfc_SE_ActModeVirtual:
@@ -655,6 +656,8 @@ NFCSTATUS phLibNfc_SE_SetMode ( phLibNfc_Handle hSE_Handle,
}
else
{
+ // Restore original mode
+ pLibContext->sSeContext.eActivatedMode = originalMode;
Status = NFCSTATUS_FAILED;
}
}
diff --git a/src/phLibNfc_discovery.c b/src/phLibNfc_discovery.c
index 1fe4d8f..c512f73 100644
--- a/src/phLibNfc_discovery.c
+++ b/src/phLibNfc_discovery.c
@@ -194,7 +194,14 @@ NFCSTATUS phLibNfc_Mgt_ConfigureDiscovery (
}
else
{
- RetVal=NFCSTATUS_FAILED;
+ if (PHNFCSTATUS(RetVal) == NFCSTATUS_BUSY)
+ {
+ RetVal = NFCSTATUS_BUSY;
+ }
+ else
+ {
+ RetVal=NFCSTATUS_FAILED;
+ }
}
}