summaryrefslogtreecommitdiff
path: root/src/phFriNfc_LlcpTransport_Connection.c
AgeCommit message (Collapse)Author
2013-03-06Make sure LLCP header fields are reset.Martijn Coenen
In some conditions these would persist over a link tear-down, causing them to be sent out the next time the link comes up. Also, don't overwrite them if a send is still in progress. Change-Id: I19dec5d79ae4b25f41fb5e8a0514e565ceca7a91
2013-03-05Fix wrong callback being cleared.Martijn Coenen
When a call to disconnect() failed, the connect() callback was cleared, not the disconnect() one. This would cause deadlocks, where JNI threads were forever blocked on doConnect(). Bug: 7324226 Change-Id: I784c8d700c87d643315f2417610ca75ef8f9aa7c
2013-03-05Fix some LLCP threading issues.Martijn Coenen
On Android we now start connecting SNEP/other LLCP services as soon as the link comes up. That means we will have connect requests incoming, accept responses outgoing, connect requests outgoing and accept responses incoming. This lays bare a lot of threading issues in this lib. Since the receives come in serialized, those typically do not cause any issue. However, we may be sending something on a thread coming from the NfcService, while at the same time we'll receive for example a connect frame from the remote, to which the receive thread immediately wants to send a response. This is a first attempt at making sends thread-safe: already there was a lot of logic to deal with the fact that another send was in progress, in the form of the bSendPending variable. That variable was however not checked atomically, and some operations did not even set it correctly. This change tests and sets that variable atomically, more or less implementing a semaphore with try-acquires and fallbacks for the failure case. The generic structure is: if (testAndSetSendPending()) { // Another thread is sending, stash data // and most importantly do *NOT* change shared data } else { // We're now the only one sending, we're free // to change shared data until the callback is // called. } This is just a band-aid fix, but given the fact that this stack will be deprecated it is hopefully enough for our planned usecases. A decent fix would involve switching to a TX-queue per socket, and a generic TX-queue for the whole LLCP link. This allows us to fully decouple the connection layer from the transport layer, as it should be. Change-Id: Ibd8742f7350a58459771f5036a049af3a487f783
2012-02-06Fixed FRMR sending on invalid LLCP frame receivedSunil Jogi
DSAP and SSAP were switched on with the other at multiple location in the code. This patch fix those. Change-Id: Iea8e499049a2cd4a234155a3044b875eb9c6ca7a
2012-01-30Fixed rejected receive request in LLCPSunil Jogi
If phLibNfc_Llcp_Recv() is called in the callback of a previous phLibNfc_Llcp_Recv(), it could be rejected due to the bSocketRecvPending flag which was not properly reset. Change-Id: I6c41469480b50bb7adc9a721ec96f715e5d56a60
2012-01-27Reset LLCP socket internal variables before next use.Sunil Jogi
Some internal variables used in reveive window checkings were not reset on socket closure/re-opening. This was leading to have the send() function waiting forever for remote acknowledgments. Change-Id: Ic7741b004de80af3f851f620842d46c42f654804
2012-01-27Update for LLCP V(SA) internal variableSunil Jogi
The V(SA) is an internal variable used in LLCP connection-oriented data links to check receive window conditions. It corresponds to the last frame number acknowledged by remote peer + 1. The patch makes sure this variable is updated evry time it is needed. Change-Id: Ie5ac925a6f1dfa19b22ac2b6e96659440d5daf21
2012-01-27LLCP 1.1: Fix some bugs.Martijn Coenen
- Clear out send callback if send was not accepted. - Set transport busy status for RR/RNR frames. Change-Id: Idf8986f6b82995644b176247a644e36d2c879ebf
2012-01-27LLCP 1.1 implementation.Sunil Jogi
Previously, in LLCP v1.0, the only way to use the SDP (Service Discovery Protocol) service was to send a CONNECT frame containing the Service Name to the SDP service. This was implicitly preforming a connection request to the requested service. LLCP v1.1 introduced a way to discover services more efficiently and without implicit connection. It also enables connectionless services to have a service name. It is based on a new protocol based on a new SNL frame containing discovery requests and responses. This update comes with new APIs: - phLibNfc_Llcp_DiscoverServices() function can be used to discover remote services. It can take multiple service names and resolve all of them in a single call. - Register service name at bind time. Cache LLCP service name/sap pairs. In LLCP 1.1 specification defines at section 5.9 that any service lookup answer must be valid for the whole LLCP session duration. To enforce this, we cache the SAP/SN pairs locally and make sure that the applications don't break the cache. The stack remains fully retro-compatible with v1.0 devices. Change-Id: I052edd3838013cee65e7415d0ed01fc3e9cad36d
2012-01-27LLCP 1.1: allow pending operations on connectionless.Sunil Jogi
The pending operations were handled at the connection-oriented sockets level, with no possibility for other transport types to handle pending operations. A dispatcher has been added at the generic transport level to remove this limitation. This feature is needed to implement LLCP v1.1. Change-Id: I69e37ba800d1c531396ca97ab0a0480e0f53d63f
2011-07-25Fixed LLCP receive function when accessing RW.Sylvain Fonteneau
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
2011-07-25Deal with LLCP send errors properly (part 1).Martijn Coenen
Send failures on LLCP sockets were not dealt with at all - the transport was just left in a state where it thought there was a pending send and a pending callback. Before we typically only did one send and it didn't bite us so much, but now with multiple sockets we run into this frequently. This really just fixes part of the problem - we should also look if state rollbacks are necessary, as those are not done either on send failures. Change-Id: I484ca598e043ead835251aedaabe47d3a1da7a8f
2011-06-27libnfc spring cleaningNick Pelly
o Fix most libnfc warnings, from 360 to 18 o Make DAL_DEBUG much less verbose and more useful o Clean up Android.mk Done with minimal textual diff to minimize merge conflicts. Change-Id: I918645500723ff7bb092ad9959628fcabac45bec
2011-06-03Update V(RA) counter in LLCP sockets any time it is needed.Sylvain Fonteneau
At some points, the V(RA) socket counter (used for Receive Window checking in connection-oriented sockets) was not properly updated, thus leading to sometimes reject (FRMR) inbound I-frames with valid sequence numbers. This patch factorize the I-frame emission and update V(RA) in the factorized code to ensure this is done at any time. Change-Id: Ic7ef92cb136c32e524a14e31a8d350f7b165c367
2011-04-08Ignore unreadable TLVs during LLCP activation and CONNECT/CC.Sylvain Fonteneau
The LLCP specification defines that if a TLV cannot be interpreted, it shall be ignored rather than generating an error. This patch removed all error reporting on TLV interpretation. The only error that can still happen is length inconsistency in the whole TLV array buffer. Change-Id: Ibf289fceb2283bfddcdc0ddee9e687ece3e90887
2011-01-18Erase callback when function returns immediately.Arnaud Ferir
This should avoid calling a irrelevant callback at abort. Change-Id: Ied8d54268613f248fd505d4b25d0ab8a0905a336
2011-01-18Fixed LLCP send callback triggering.Arnaud Ferir
The phLibNfc_Llcp_Send() function is expected to trigger a callback when the packet is actually sent but, in some situations, the callback was triggered by another frame sending (such as RR or DM frames). This patch fixes the following socket internal flags handling: - pfSocketSend_Cb: set to non-NULL value when a send operation is pending, - bSocketSendPending: set to TRUE if the LLCP link layer is not available for sending and reset to FALSE once the frame is actually forwarded to the LLCP link layer. The send callback triggering has been updated to ensure it is only done for the expected data frame (i.e.: send pending and already forwarded to link layer). Change-Id: Id7410ee4075fbbbc9de382abf54e89a97f6a8b37
2011-01-18Fixed erroneous LLCP frame on socket closure.Sylvain Fonteneau
Moved data allocation from stack memory to heap in order to avoid invalid memory access. Previously, When trying to send a DM (acknowledgment to socket disconnect request), the stack was allocating some frame data on the stack but these data were used after the function returned. Other calls to the same function are already using variables allocated on heap. Change-Id: Id7356a876fdecdd979ed3ddc6dbe100d6e92d43d
2011-01-18Fixed LLCP receive window checkings.Sylvain Fonteneau
Before sending a packet, the LLCP stack have to check if the remote peer is ready to send. To do so, a Receive Window mechanism based on packet numbering and acknowledgment is used. Basically, the sender have to make sure that he must have not sent more than RW-1 unaknowledged frames before sending a new one. This patch is correcting this test which was failing in some situations. Change-Id: I525f6b472a909ce48feb938aa02858b9456edc11
2011-01-18Removed callback in case of immediate end of operation.Arnaud Ferir
The correct behavior of asynchronous functions should be: Immediate operation => function returns with success/error status, callback never invoked Delayed operation => function returns with pending status, callback is invoked at the end of operation Some minor fixes are also included in this commit (code style). Change-Id: Ieb801ab759045c5c5d9fc59b4715f3c142d5b33e
2011-01-18Do not call LLCP socket listen callback on abort.Arnaud Ferir
The listen callback is a notification callback, not an end-of-operation callback so, when the socket is closed, it should not be triggered since there is no connection event. Change-Id: I6e6994f6bcb09f9fadda04800d22528d76aff121
2011-01-18Fixed NULL pointer error when trying to send LLCP REJECT frame.Arnaud Ferir
The sequence value may not be provided in some situations, when rejecting a connection oriented frame. Change-Id: I116179191f9a23072442cf9da7a4c4207128bd32
2011-01-18Call the LLCP send callback in error cases.Arnaud Ferir
This avoids an application to be stuck in a send request while the LLCP link has been lost (i.e. remote peer lost). Change-Id: I74982d497c410ae4bdb466afac013efc9eb17b03
2010-12-13Enable reading a connection-oriented socket even if remotely closed.Sylvain Fonteneau
The receive function was failing when trying to read the data present in the linear buffer after receiving a remote disconnection request (DISC). Change-Id: I48a2aa058e85e265ca53e61dcde281e47a6e187f
2010-12-13Do not clear LLCP listen callback when an incoming socket is detected.Sylvain Fonteneau
This would prohibit detection of multiple incoming socket in a row. Change-Id: I9e3907a92b706de2da7642ccd92668b9868d1996
2010-12-07Avoid multiple callbacks for a single LLCP operation.Sylvain Fonteneau
Change-Id: Ifa17a3a05790fece3f5aee747b186f721c510b7f
2010-12-07Fix to prevent any action on a LLCP socket while disconnecting.Sylvain Fonteneau
Mark a socket as disconnecting as soon as the disconnect request is received instead of waiting for the DISC packet to be sent. Change-Id: I95330b7039c6fa741adc69ab1323852a60b7d49e
2010-12-05Call the callback of any pending action in case of LLCP socket closure.Sylvain Fonteneau
This ensure the lib client not to be stuck waiting for a callback when the socket has been closed meanwhile. Change-Id: I9cdfa3c2cc75ee9451c3ad5b92eb338b5e68f53a
2010-12-05Fixed status handling in LLCP connection-oriented sent callback.Sylvain Fonteneau
The same variable was shared for multiple usages and the status value was overwritten is some situations. One variable is now defined for each usage. Change-Id: I877cc8027a184dfe3b6d8d2832c73417f40c1ba7
2010-11-02Fix the parameters to phFriNfc_Llcp_EncodeMIUX.Jeff Hamilton
Change-Id: Ia0426198d0edd325edcc2bb5a3c6d7d623e28a9f
2010-11-01Fixed LLCP socket options storage.Sylvain Fonteneau
Socket options are now copied in the libnfc to avoid referencing a pointer that may not be valid during the whole socket life cycle. Change-Id: I7266164bf157242df1ce7fb7a0f9cffd52938140 Signed-off-by: Nick Pelly <npelly@google.com>
2010-10-28Fixed LLCP Service Name matching failure.Sylvain Fonteneau
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
2010-09-23Initial libnfc checkinNick Pelly
Source: Trusted_NFC_Device_Host_AA03.01e02_google.zip code drop (23-Sep-2010) Change-Id: Ie47f18423f949a8d3e0815d13f55c814312add24 Signed-off-by: Nick Pelly <npelly@google.com>