diff options
author | Sylvain Fonteneau <sylvain.fonteneau@trusted-logic.com> | 2010-11-29 10:54:08 +0100 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2010-12-05 13:15:11 -0800 |
commit | c56a3c7bc332a6656bedf342236267b636051170 (patch) | |
tree | fd0979de60362a95cbdcf27b4b7d0746f8ac68f5 | |
parent | 1c75e8952d88d81c5f04826f69ca22d14bb5683b (diff) | |
download | external_libnfc-nxp-c56a3c7bc332a6656bedf342236267b636051170.zip external_libnfc-nxp-c56a3c7bc332a6656bedf342236267b636051170.tar.gz external_libnfc-nxp-c56a3c7bc332a6656bedf342236267b636051170.tar.bz2 |
Close all LLCP sockets when the link goes down.
The LLCP link status callback is now handled first in LIB layer
before being forwarded to the client. This is needed to enable the LIB layer
to detect the link status change and close the sockets accordingly.
Change-Id: I607aaebb4c0c8f2da09c81d4d43b4c705ebfcb13
-rw-r--r-- | src/phFriNfc_LlcpTransport.c | 22 | ||||
-rw-r--r-- | src/phFriNfc_LlcpTransport.h | 8 | ||||
-rw-r--r-- | src/phLibNfc_Internal.h | 4 | ||||
-rw-r--r-- | src/phLibNfc_llcp.c | 41 |
4 files changed, 73 insertions, 2 deletions
diff --git a/src/phFriNfc_LlcpTransport.c b/src/phFriNfc_LlcpTransport.c index 408f058..ddc8c6a 100644 --- a/src/phFriNfc_LlcpTransport.c +++ b/src/phFriNfc_LlcpTransport.c @@ -200,6 +200,28 @@ NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpTran return status; } +/* TODO: comment function Transport CloseAll */ +NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t *pLlcpTransport) +{ + NFCSTATUS status = NFCSTATUS_SUCCESS; + uint8_t i; + + /* Check for NULL pointers */ + if(pLlcpTransport == NULL) + { + status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER); + } + + /* Close all sockets */ + for(i=0;i<PHFRINFC_LLCP_NB_SOCKET_MAX;i++) + { + phFriNfc_LlcpTransport_Close(&pLlcpTransport->pSocketTable[i]); + } + + return status; +} + + /** * \ingroup grp_lib_nfc * \brief <b>Get the local options of a socket</b>. diff --git a/src/phFriNfc_LlcpTransport.h b/src/phFriNfc_LlcpTransport.h index 0cc3721..7d77634 100644 --- a/src/phFriNfc_LlcpTransport.h +++ b/src/phFriNfc_LlcpTransport.h @@ -269,6 +269,14 @@ NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpSock /** +* \ingroup grp_fri_nfc +* \brief <b>Close all existing sockets</b>. +* +*/ +NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t *pLlcpSocketTable); + + +/** * \ingroup grp_lib_nfc * \brief <b>Get the local options of a socket</b>. * diff --git a/src/phLibNfc_Internal.h b/src/phLibNfc_Internal.h index 0803101..10018ec 100644 --- a/src/phLibNfc_Internal.h +++ b/src/phLibNfc_Internal.h @@ -130,6 +130,10 @@ typedef struct phLibNfc_Hal_CB_Info pphLibNfc_ChkLlcpRspCb_t pClientLlcpCheckRespCb; void *pClientLlcpCheckRespCntx; + /*LLCP Link CB*/ + pphLibNfc_LlcpLinkStatusCb_t pClientLlcpLinkCb; + void *pClientLlcpLinkCntx; + }phLibNfc_Hal_CB_Info_t; typedef struct phLibNfc_NdefInfo diff --git a/src/phLibNfc_llcp.c b/src/phLibNfc_llcp.c index c72e1b7..86b15cf 100644 --- a/src/phLibNfc_llcp.c +++ b/src/phLibNfc_llcp.c @@ -39,6 +39,9 @@ NFCSTATUS static_CheckDevice(phLibNfc_Handle hRemoteDevice); STATIC void phLibNfc_Llcp_CheckLlcp_Cb(void *pContext,NFCSTATUS status); +STATIC +void phLibNfc_Llcp_Link_Cb(void *pContext,phLibNfc_Llcp_eLinkStatus_t status); + /* --------------------------- Internal functions ------------------------------ */ STATIC NFCSTATUS static_CheckState() @@ -189,6 +192,10 @@ NFCSTATUS phLibNfc_Llcp_CheckLlcp( phLibNfc_Handle hRemoteDevice, } } + /* Prepare callback */ + gpphLibContext->CBInfo.pClientLlcpLinkCb = pLink_Cb; + gpphLibContext->CBInfo.pClientLlcpLinkCntx = pContext; + /* Resets the LLCP LLC component */ result = phFriNfc_Llcp_Reset( &gpphLibContext->llcp_cntx.sLlcpContext, gpphLibContext->psOverHalCtxt, @@ -197,8 +204,8 @@ NFCSTATUS phLibNfc_Llcp_CheckLlcp( phLibNfc_Handle hRemoteDevice, sizeof(gpphLibContext->llcp_cntx.pRxBuffer), gpphLibContext->llcp_cntx.pTxBuffer, sizeof(gpphLibContext->llcp_cntx.pTxBuffer), - pLink_Cb, - pContext); + phLibNfc_Llcp_Link_Cb, + gpphLibContext); if (result != NFCSTATUS_SUCCESS) { return PHNFCSTATUS(result); @@ -246,6 +253,36 @@ NFCSTATUS phLibNfc_Llcp_CheckLlcp( phLibNfc_Handle hRemoteDevice, return result; } +/* LLCP link callback */ +STATIC +void phLibNfc_Llcp_Link_Cb(void *pContext, phLibNfc_Llcp_eLinkStatus_t status) +{ + phLibNfc_LibContext_t *pLibNfc_Ctxt = (phLibNfc_LibContext_t *)pContext; + pphLibNfc_LlcpLinkStatusCb_t pClientCb = NULL; + void *pClientContext = NULL; + + if(pLibNfc_Ctxt != gpphLibContext) + { + /*wrong context returned from below layer*/ + phOsalNfc_RaiseException(phOsalNfc_e_InternalErr,1); + } + else + { + /* Close all sockets */ + phFriNfc_LlcpTransport_CloseAll(&gpphLibContext->llcp_cntx.sLlcpTransportContext); + + /* Copy callback details */ + pClientCb = gpphLibContext->CBInfo.pClientLlcpLinkCb; + pClientContext = gpphLibContext->CBInfo.pClientLlcpLinkCntx; + + /* Trigger the callback */ + if(pClientCb != NULL) + { + pClientCb(pClientContext, status); + } + } +} + /* Response callback for phLibNfc_Ndef_CheckNdef */ STATIC void phLibNfc_Llcp_CheckLlcp_Cb(void *pContext, NFCSTATUS status) |