Commit Graph

73 Commits

Author SHA1 Message Date
Marcel Holtmann
6648e011a3 attrib: Make btio/btio.h include local 2014-01-25 20:32:57 -08:00
Marcel Holtmann
cf458ad28f attrib: Use full include path for header files 2014-01-25 20:10:00 -08:00
Andrei Emeltchenko
c64fd37802 codingstyle: Change __FUNCTION__ to __func__
The __func__ macro is part of the C99 standard whereas __FUNCTION__ is a
legacy gcc specific alias for it:

	http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html

Additionally, checkpatch.pl that's commonly used to verify coding style
also recommends to use __func__ instead of __FUNCTION__.
2013-09-11 13:22:08 +03:00
Lucas De Marchi
eee0adcf7b attrib: Get rid of gchar
Use plain char instead of gchar.
2013-05-02 09:02:25 +03:00
Lucas De Marchi
45abbe7b9a attrib: Get rid of gint
Use plain int instead of gint. In glib gint is always a typedef to int,
so it's safe to use it even for callbacks with glib.
2013-05-01 09:04:16 +03:00
Jefferson Delfes
620987bc86 attrib: Change match_event return type from gboolean
There is no reason to use gboolean as return type of match_event.
2013-04-24 17:00:09 +03:00
Jefferson Delfes
facc83cce6 attrib: Change is_response return type from gboolean
There is no reason to use gboolean as return type of is_response.
2013-04-24 16:59:55 +03:00
Jefferson Delfes
36b5001b12 attrib: Change command->sent type from gboolean
There is no reason to command->sent be gboolean.
2013-04-24 16:59:44 +03:00
Jefferson Delfes
ba9b8d1743 attrib: Change GAttrib->stale type from gboolean
There is no reason to GAttrib->stale be gboolean.
2013-04-24 16:59:23 +03:00
Jefferson Delfes
9b90cc2eed attrib: Simplify boolean tests
Remove unnecessary TRUE/FALSE in boolean tests.
2013-04-24 16:59:14 +03:00
Lucas De Marchi
1bd26421ce attrib: Use gcc builtin instead of g_atomic
g_atomic_* end up using G_STATIC_ASSERT, causing gcc 4.8 to yell due to
-Wunused-local-typedefs.

/usr/include/glib-2.0/glib/gmacros.h:162:53: error: typedef ‘_GStaticAssertCompileTimeAssertion_2’ locally defined but not used [-Werror=unused-local-typedefs]
 #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]

Most of the uses of atomic operations were wrong. They were fixed as
well. If we are using atomic operations, reading the variable again
later for logging is not an option, we should use the return of the
atomic function used to fetch the variable.
2013-04-09 07:01:36 +09:00
Jaganath Kanakkassery
693f759cc2 attrib: Fix use after free of attrib
If attrib is freed in cmd->func(), then it will be used if either
request or response queue has some data to send.

This patch moves calling wake_up_sender() which increases the ref
count of attrib so that it wont get freed in cmd->func().
2013-04-02 09:47:14 +03:00
Jaganath Kanakkassery
f59bdb51b1 attrib: Remove norequests and noresponses variables
Passing NULL is fine to g_queue_is_empty(), so removing these
variables makes the code more readable
2013-04-02 09:47:12 +03:00
Luiz Augusto von Dentz
667cb4c469 attrib: Don't attempt to unregister event id 0
Id 0 is considered invalid so the code should not even try to lookup for
it in the event list instead print a warning and return FALSE
immediatelly.
2013-01-28 16:02:11 -06:00
Anderson Lizardo
5434627c4c attrib: Fix remaining references to bluetooth/uuid.h
These headers are not public anymore, so need to use "lib/uuid.h".
2013-01-10 15:11:53 +02:00
Cristian Rodríguez
2604776e91 attrib: Fix missing config.h includes 2012-12-23 18:59:48 -08:00
Lucas De Marchi
5714b14bce Reorder btio.h includes
Let "#include <btio/btio.h>" together with other includes using '<'
rather than '"'.
2012-12-05 17:23:04 +02:00
Lucas De Marchi
49b5612042 Use the entire include path for btio.h 2012-12-05 17:23:04 +02:00
Vinicius Costa Gomes
0f92869a3b gattrib: Add support for listening for events for specific handles
We want only the profile that implements a service to be notified of
changes on that service. Before this patch, all the registered event
notifiers are being called.
2012-10-11 08:55:50 +02:00
Vinicius Costa Gomes
4c3dec8abf gattrib: Fix ignoring the error message when write fails
If an error happens during writing to the socket, we should complain
that it failed.
2012-10-11 08:34:34 +02:00
Vinicius Costa Gomes
8a39d6ed2d attrib: Remove opcode parameter from g_attrib_send()
In all uses of g_attrib_send() the opcode of the command/event is
already clear because of the att.h functions used to build the ATT
PDU.
2012-10-09 10:56:52 +02:00
Johan Hedberg
5dd93fc16a Update code base to use the new BtIO API 2012-08-28 17:18:28 -07:00
Johan Hedberg
04be4fe0c0 attrib: Use proper types for size variables
size_t/ssize_t/off_t/etc are more appropriate for variables denoting
some kind of size than simply using int.

This patch includes a couple of other related changes to avoid gcc
signedness errors resulting from it treating (for whatever reason) const
variables and integer literals as signed.
2012-08-15 12:20:51 +03:00
Johan Hedberg
18ffa5c18b gattrib: Make event callback identifiers globally unique
The attrib server code relies on these id's to be unique globally and
not just per GAttrib instance. As an easy fix make them global by adding
a static guint to g_attrib_register.
2012-06-08 23:37:33 +08:00
Johan Hedberg
283b4b7d69 gattrib: Fix protection of GAttrib while calling callbacks
The callbacks could result with the reference count dropping to 0 and
the object being freed. This patch fixes the issue by adding one extra
reference for the duration of the timeout function.
2012-06-07 09:41:50 +03:00
Andre Guedes
ea2718060e gattrib: Fix g_attrib_set_mtu
23 octets is the default (and minimum) ATT_MTU value. If someone tries
to set ATT_MTU less than 23 octets g_attrib_set_mtu should fail (return
FALSE). Additionally, there is no constraint regarding the maximum value
of ATT_MTU, so we should not check for it.

Also, we should not change the L2CAP ATT fixed channel MTU. bt_io_set
call will always fail since we are not supposed to change L2CAP MTU
after connection is established.
2012-06-07 04:27:24 +03:00
Andre Guedes
185c7ce8a4 gattrib: Fix GAttrib buffer allocation
GAttrib buffer should be allocated according to ATT_MTU value. Over
BR/EDR, ATT_MTU should be set to the L2CAP imtu negotiated during
L2CAP configuration phase. Over LE, ATT_MTU should be 23 octets.
2012-06-07 04:27:19 +03:00
Ido Yariv
33523ab31c gattrib: Fix a premature response timer removal
A timer is set when a response is expected. The timer is removed when
data is received, regardless of whether or not the data is a response.
As a result, the timer may be cleared even though a response was not
received and there would be no way to detect a command timeout.

Fix this by clearing the timer only after verifying a response was
received.
2012-06-07 04:25:06 +03:00
Johan Hedberg
3b3e88678a gattrib: Fix command timeout handling
This patch fixes command timeout handling. Previously attrib_destroy was
explicitly called which ignored any reference holders. This patch fixes
the issue by first passing errors to command callbacks and after that
marking the GAttrib object as stale so no further operations can be
done.
2012-06-05 15:11:50 +03:00
Ido Yariv
a49ba8abd9 gattrib: Fix a request/response command deadlock
New requests and responses are never sent if a request was sent and the
response for it hasn't been received yet. As a result, if both end
points send requests at the same time, a deadlock could occur. This
could happen, for instance, if the client sends a read request and the
server sends an indication before responding to the read request.

Fix this by introducing an additional queue for responses. Responses may
be sent while there's still a pending request/indication.
2012-05-30 10:39:52 +03:00
Claudio Takahasi
0949326f92 gattrib: Protect GAttrib when there is a pending write 2012-04-03 14:19:03 +03:00
Claudio Takahasi
9e6a11719f GAttrib: Remove unused function
GAttrib disconnection tracking is being moved to device.c
2012-02-14 14:11:54 +02:00
Claudio Takahasi
e8f0a6c315 GAttrib: Fix leak when remote disconnects 2012-02-09 17:53:50 +02:00
Claudio Takahasi
e05011b3f3 GAttrib: Add debug message for GAttrib references 2012-02-09 17:53:46 +02:00
Vinicius Costa Gomes
eb41b504d0 Fix the attrib server trying to handle responses
The attribute server should only try to handle ATT requests, responses
and events should be handled by the client.
2011-09-22 20:25:25 +09:00
Claudio Takahasi
4b7da0b91d Add workaround to skip wrong OMTU for basic rate
This patch is required until the MTU kernel patch is integrated. Without
it the kernel returns zero for basic rate OMTU.
2011-04-09 10:46:06 -07:00
Bruna Moreira
68887c2133 Add internal buffer to GAttrib struct
The new buffer is allocated in g_attrib_new() and it will be used to
send/receive PDUs. The buffer size is the MTU read from L2CAP channel
limited to ATT_MAX_MTU. Functions to handle the buffer size were also
created.
2011-03-18 11:14:35 +02:00
Elvis Pfützenreuter
a278db781a Use new UUID functions in GATT
This patch puts the new UUID functions into use for GATT-related
code, and adds some convenience functions to ATT API (att.h).
Example GATT server is also changed.
2011-03-15 19:36:48 +02:00
Bruna Moreira
bd32dd623d Remove unused MTU variable in GAttrib struct
The MTU variable in GAttrib struct was not being used for any operation
so it should be removed.
2011-02-24 18:37:26 -03:00
Vinicius Costa Gomes
6682df6dae Add support for GATT client timeouts
This patch adds support to destroying the GATT connection
when a GATT server doesn't respond for more than 30 seconds.

A function to destroy the GAttrib is introduced and it is used
in the timeout case and when the last GAttrib reference is
dropped.
2011-02-24 17:43:16 -03:00
Vinicius Costa Gomes
33e09781d7 Fix gattrib.c coding style
Just remove an extra empty line.
2011-02-24 17:41:23 -03:00
Brian Gix
7f0b31cbb4 Fix g_attrib_send() to include a new ID parameter
Overall purpose of change is to enable a GATT procedure to be
executed atomically, even if it requires multiple ATT
request/response transactions.

Fix g_attrib_send() to include an ID parameter, if the pkt to
be sent should be added to the Head of the pkt queue.  If the
ID is Zero, legacy functionality is maintained, and the pkt will
be added at the tail of the queuer, and a new ID will be generated,
and returned to the caller. If ID is non-zero, the pkt will be
added to the head of the queue, with the ID value requested, which
will also be returned to the caller.

Fix received_data() to not service the send queue until after the
received data has been processed by calling the cmd->func()
callback, to allow the callback to insert another pkt on the head
of the queue.

Fix all callers of g_attrib_send() to include new parameter.
2011-01-07 21:31:31 +02:00
Claudio Takahasi
41d3eb82b8 Change security level on demand when reading characteristic value
If a characteristic requires a higher security level, change it on
demand and re-send the GATT Charateristic Value Read. Request will not
be sent until the SMP negotiation finishes. This change doesn't affect
GATT over BR/EDR, since encryption is mandatory for BR/EDR.
2011-01-05 14:04:51 +02:00
Sheldon Demario
d3cb258b9b Move primary service storage to device.c
Discover All Primary Services has beed moved to device.c in order
to follow a similar approach of BR/EDR service records.
2010-12-23 00:34:04 +02:00
Claudio Takahasi
70ceea2eb9 Fix memory leak of gattrib commands queue 2010-12-16 11:25:02 +02:00
Bruna Moreira
d599b9e2b8 Check the security level on a per request base
Check security level on attribute server on each request, and update the
"encrypted" flag.
2010-12-09 15:59:46 +02:00
Vinicius Costa Gomes
1e35abda9f Fix writing to GAttrib socket without POLLOUT event
If the GIOChannel is in the buffered state (the default) the watch
function is called without receiving a POLLOUT from the socket. GLib
adds a G_IO_OUT condition just because there is space in the GIOChannel
internal buffer.

The solution is disabling the internal buffer, which in turn, makes the
call of g_io_channel_flush() useless.
2010-12-07 22:57:22 +02:00
Claudio Takahasi
d0bfd6eaa5 Use the destroy function to reset the GAttrib reference
In the client, after local or remote initiated disconnection the GAttrib
reference shall be set to NULL to allow a proper control of references
and further connections.
2010-09-22 15:55:18 -04:00
Claudio Takahasi
8545bdc1ea Add g_attrib_set_destroy_function in gattrib
Add a new function to notify the GAttrib "users" when the GAttrib has
beed destroyed. The disconnect function is called only for remote initiated
disconnections or external events(not unref).
2010-09-22 15:55:18 -04:00
Claudio Takahasi
27be80c804 Remove forward declaration on gattrib source 2010-09-22 22:34:27 +03:00