Commit Graph

422 Commits

Author SHA1 Message Date
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
7dc92fb807 Remove workaround in gatt_connect
This workaround is not necessary anymore since setsockopt is now
checking for minimum MTU.
2012-06-07 04:27:46 +03:00
Andre Guedes
7125410781 Fix gatt_connect for BR/EDR
Use BT_IO_OPT_IMTU instead of BT_IO_OPT_OMTU in bt_io_connect.
We cannot control omtu value since it is negotiated during L2CAP
configuration phase.
2012-06-07 04:27:43 +03:00
Andre Guedes
ece3234da6 Remove omtu parameter from LE bt_io_connect calls
There is no need to set the omtu of L2CAP ATT fixed channel. We
use the default value.
2012-06-07 04:27:39 +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
fec848dba7 att: Start application error codes from the beginning of the range
Application error codes start off with 0x80 onwards. In CSSv2 the range
0xE0-0xFF is reserved for "Common Profile Error Codes" so we should
ensure not to mix that with our own definitions.
2012-06-06 16:05:30 +08:00
Johan Hedberg
5232f76214 attrib: Fix always requiring high security
If we get an insufficient encryption error for ATT it doesn't
necessarily mean that we need to have high secirity. If we have an
unauthenticated key and are unencrypted it could also mean that we just
need to encrypt the link (medium security). Always requiring high
security would make the connection fail for unauthenticated keys.
2012-06-06 09:02:23 +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
Claudio Takahasi
d65ee066a1 GATT: Avoid unneeded discover transaction
This patch fix unneeded discover characteristics transaction when the
last characteristic declaration contains the handle number equals to the
end handle of the primary service.
2012-05-30 10:42:43 +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
932bc368ef GATT: Move GATT assigned numbers to GATT header 2012-05-30 10:39:03 +03:00
Claudio Takahasi
66a0ce723b GATT: Rename Characteristic Configuration constants
This patch renames the constants related to Client Characteristic
Configuration bit field to use a proper name since it is related to
GATT instead of ATT.
2012-05-30 10:37:24 +03:00
Paulo Alcantara
a6b75b0383 storage: Store address type in "attributes" file
Addressing types can be either BR/EDR, BLE public or BLE random so the
entries in the "attributes" file did not contain enough information to
distinguish which addressing type it's supposed to be. Entries will now
contain both address number and address type as a single key in every
entry in the file.
2012-05-27 22:31:48 +03:00
Paulo Alcantara
0185e5d4d6 storage: Store address type in "characteristics"
GATT can use BR/EDR or BLE as transport. Addressing types can be either
BR/EDR, BLE public or BLE random so the entries in the "characteristics"
file did not contain enough information to distinguish which addressing
type it's supposed to be. Entries will now contain both address number
and address type as a single key in every entry in the file.
2012-05-27 22:20:33 +03:00
Lucas De Marchi
7eebe7fb41 Do not set signature and reply in GDBus tables
Use GDBUS_* macros, so signature and reply fields are not set in each
method/signal.
2012-05-17 20:32:21 -07:00
Lucas De Marchi
aa3b9016bf Convert GDBus methods to use macro helpers
With these macro helpers we can separate in/out arguments and use their
own vector.
2012-05-17 20:32:20 -07:00
Lucas De Marchi
665014ce89 Constify GDBus method tables
Constify method tables with the following command:

find . -name '*.[ch]' -exec \
	     sed -i 's/\(GDBusMethodTable .* =\)/const \1/g' {} \;
2012-05-17 20:32:20 -07:00
Andrzej Kaczmarek
2118c00409 gatttool: Add option to specify LE address type
This patch makes possible to specify LE address type.

After advertising cache was removed from kernel we should always specify
address type for LE link when calling bt_io_connect() as otherwise random
will always be used.

LE address type can be specified either by 'addr-type' or 't' command line
parameter or as additional parameter to 'connect' command in interactive mode.

Possible values are 'public' (default) and 'random'.
2012-05-07 11:29:42 -07:00
Andrzej Kaczmarek
dbe0ed14d5 gatttool: Fix handle parsing in cmd_char_write()
errno is not set to 0 before call to strtoll() so cmd_char_write() can fail
even with proper data. Use strtohandle() helper function instead.
2012-04-26 12:12:18 +03:00
Marcel Holtmann
84156dadb2 build: Remove glib-compat.h support 2012-04-16 18:23:02 +02:00
Anderson Lizardo
098de49acf attrib: Fix D-Bus service disconnect watch removal
watcher_free() will be automatically called when removing the D-Bus
watch (it was set as the destroy callback when adding the watch),
therefore it is only necessary to remove the watch.
2012-04-04 13:00:14 +03:00
Claudio Takahasi
0949326f92 gattrib: Protect GAttrib when there is a pending write 2012-04-03 14:19:03 +03:00
Claudio Takahasi
bd37938445 attrib: Fix missing Discovery reply when disconnected
This patch fixes missing reply for DiscoverCharacteristics method on
Generic Attribute. If link is disconnected reply message is not sent.
2012-04-03 14:18:47 +03:00
Arik Nemtsov
3374e0ca32 att: add remote btd_device to ATT read/write callbacks
This allows us to identify the remote device that made the ATT
read/write.
2012-04-03 12:58:12 +03:00
Anderson Lizardo
c6fc73e1fa attrib: Attempt to remove attio callback on watcher exit
When registering a watcher, it is attempted to add an attio callback.
Therefore, when the watcher is unregistered or exits, this attio should
be removed if there are no other users.

This is already done when unregistering a watcher, it just missed when
it exits without unregistering.
2012-03-30 13:23:27 +03:00
Claudio Takahasi
1413167550 attrib: Fix missing D-Bus message unref on DiscoverCharacteristics
This patch fixes a missing message unref when DiscoverCharacteristics on
Generic Attribute finishes.
2012-03-30 13:23:20 +03:00
Claudio Takahasi
140e2169dd attrib: Register only new characteristics found
This avoids duplicating registration for previously found
characteristics.
2012-03-30 13:18:21 +03:00
Claudio Takahasi
9f264f5606 attrib: Move Characteristic Discovery reply to a new function
Minor cleanup patch moving the creation of the reply for Discover
All Characteristics call to a new local function in the Generic
Attribute.
2012-03-30 13:18:05 +03:00
Claudio Takahasi
7126f14569 attrib: Discover Characteristics if already connected
On Generic Attribute, Discover All Characteristics of a Service can be
started immediately if already connected, without registering a ATTIO
connection callback.
2012-03-30 13:17:32 +03:00
Claudio Takahasi
4e4ead44d1 attrib: Centralize ATTIO connection management
On Generic Attribute, register only one ATTIO connection callback to
centralize the connection management.

Also make sure the connection reference is properly dropped only if
there is no pending operation.
2012-03-30 13:16:57 +03:00
Jefferson Delfes
28f7993c17 gatttool: Update interactive prompt if connection is lost
In interactive mode, when connection is lost, the prompt used to remain
in "connected" state. This patch fixes that case, by always showing the
actual connection state.
2012-03-28 12:40:28 +03:00
Chen Ganir
1e064929b3 GATT: Replace start/end with att_range
Use att_range struct instead of individual start/end handles in
gatt_primary structure
2012-03-26 12:18:00 +03:00
Chen Ganir
48c82115a2 GATT: Rename service and char structs
Rename the att_primary to gatt_primary and att_char to gatt_char.
Characteristic and Service do not exist in the ATT spec, only in
GATT.
2012-03-26 12:16:44 +03:00
Jefferson Delfes
466360ddc6 gatttool: Add command completion for interactive mode 2012-02-29 20:07:21 -06: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
Santiago Carot-Nemesio
d16b0ead39 gatt-service: Provide service uuid in attrib_db_find_avail function
We need to provide the service uuid because of GATT server should group
16-bit uuid services together and 128-bit uuid services together,
(Bluetooth 4.0, Vol 3, Part G, 3.1).
2012-02-03 10:44:48 -08:00
Santiago Carot-Nemesio
6cc32c8493 gatt-service: Move va_end just after processing the argument list 2012-02-03 10:44:44 -08:00
Santiago Carot-Nemesio
24124f1181 gatt-service: Add support for 128-bit Bluetooth UUIDs
UUID services in GATT should be either 16-bit or 128-bit. Current
GATT interface does not allow to provide 128-bit ones. This patch
enables plugins to register services using 128-bit UUIDs.
2012-02-03 10:44:21 -08:00
Santiago Carot-Nemesio
5da4dd8afa gatt-service: Add missing user_data parameter for callbacks 2012-01-09 14:28:29 +02:00
Santiago Carot-Nemesio
c9548ebacf gatt-service: Delete attributes when service registration fails
Whenever a regitration operation fails, the attributes stored in the
data base of handles remain. This patches removes all attributes
registered by a service when the operation is not succesful. In this
way, either all service attributes are registered or none of them are
stored in the data base.
2012-01-09 14:28:29 +02:00
Santiago Carot-Nemesio
7188fe255e gatt-service: Add adapter in gatt_service_add function 2011-12-30 13:00:34 +02:00
Santiago Carot-Nemesio
6a1e46afaf attrib-server: Add adapter in attrib_db_add
Because of there can be many adapters plugged, the GATT servers must
provide the adapter in which the attributes will be registered.
2011-12-30 13:00:00 +02:00
Santiago Carot-Nemesio
bbc34269b0 attrib-server: Add adapter to attrib_db_find_avail function
Adapters manage their own list of handlers so we need to specify the
adapter where the handlers will be registered.
2011-12-30 12:59:09 +02:00
Claudio Takahasi
d6f93380ff attrib-client: Fix consecutive set value when disconnected
SetProperty for "Value" property needs to be queued when disconnected.
Registering ATTIO connection callback does not mean that the link is
established, GAttrib instance is assigned in the connection callback.
2011-12-27 12:05:20 +02:00
Claudio Takahasi
f583bef247 attrib-client: Fix GAttrib reference counting
Although ATT connection callbacks control GAttrib reference, each
entity using GAttrib should be increment the GAttrib reference to
keep the code standard.
2011-12-27 12:04:49 +02:00
Claudio Takahasi
6e4a000cab attrib-client: Remove unused SDP header includes 2011-12-27 12:03:19 +02:00
Johan Hedberg
b06899eace Fix device address type tracking 2011-12-23 13:00:55 +02:00
Santiago Carot-Nemesio
110f1830d7 att.h: Add client characteristic configuration bit fields 2011-12-15 13:16:51 +02:00
Santiago Carot-Nemesio
fc807dd254 Provide return status in gatt_service_add function
Service plugins using the new GATT API may need to know if their
attributes were successfully registered. In this way, plugins might
abort loading operation if they weren't registered.
2011-12-02 13:28:29 +02:00
Santiago Carot-Nemesio
9c535867ec Fix coding style issue regarding with pointer checks 2011-11-17 13:59:01 +02:00
Vinicius Costa Gomes
fffffad4b8 Add support for getting the handle of the CCC attribute 2011-11-14 21:09:36 +02:00
Anderson Lizardo
cdb0f1e52a Add GATT_OPT_CHR_VALUE_GET_HANDLE to gatt_service_add()
This new parameter accepts a pointer to a variable where the attribute
handle for the characteristic value is stored.
2011-11-14 21:09:22 +02:00
Anderson Lizardo
67cd2b0922 Implement high level GATT API for service registration
This new internal API can be used for implementing GATT services (server
role). It is built around the current attribute API (attrib_db_add() and
others).
2011-11-14 21:08:23 +02:00
Johan Hedberg
9b98a6c764 Add glib-compat.h to deal with issues in old GLib versions 2011-10-18 10:57:06 +03:00
Vinicius Costa Gomes
253f8a7c68 Fix using the attribute struct for encoding ATT pdus
The enconding and decoding of ATT pdus should be kept as much
free of dependences from other parts of the code as possible, so
it can be used in many contexts.

In this case, for encoding and decoding notifications and indications
we did have to pass an instance of an attribute instead of direct
values.
2011-10-07 19:52:32 +03: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
Anderson Lizardo
71d994a129 Refactor value assignments of bt_uuid_t variables
Prior to this commit, the assignments were made with memcpy(). This can
be unsafe and less readable, therefore it was replaced with code like:

<dst> = *src;

This also allows more compiler safety checks.
2011-09-22 20:01:30 +09:00
Anderson Lizardo
2acb6b1a3a Fix memory allocation of struct attribute
On commit 6a6da5de10 the struct
attribute "data[0]" member was replaced with a dynamically allocated
"data" pointer. This commit fixes remaining places where the old
allocation scheme was still assumed.
2011-09-22 20:01:28 +09:00
Anderson Lizardo
fef3e7c002 Remove empty line before declaration 2011-09-22 20:01:26 +09:00
Santiago Carot-Nemesio
3c4e447bdf Add valid range descriptor uuid 2011-09-16 11:34:04 +03:00
Vinicius Costa Gomes
6a6da5de10 Fix allocation of attribute values
Now that pointers to attribute are passed as reference to functions
we cannot have they change during run time, what g_try_realloc()
could do.
2011-09-16 11:32:40 +03:00
Claudio Takahasi
b3eea75304 Add on demand characteristic write
Changes the Generic Attribute registering a callback to request ATT
connection(if necessary) and write the characteristic value.
2011-07-27 10:32:40 +03:00
Claudio Takahasi
a0988557ea On demand connection for characteristics discovery
In the Generic Attribute API, when DiscoverCharacteristics is called
ATT connection should be requested if the link is not up. A query
list is required to control when the link can be disconnected since
the discover finishes after receiving all caracteristic declarations.
2011-07-27 10:32:17 +03:00
Claudio Takahasi
3177d97eed Register ATT connection callback based on watchers
In the Generic Attribute API, the ATT connection should be requested
on demand. In the case of watchers, the connection doesn't need to be
stay up if there isn't watcher registered.
2011-07-27 10:32:01 +03:00
Claudio Takahasi
8fb640ef60 Change GAttrib ref counting in Generic Attribute 2011-07-27 10:31:30 +03:00
Claudio Takahasi
e4a3edb111 Remove implicit connection from generic API
Generic attribute API should not actively manage L2CAP connections.
GAttrib instance is notified through registered callbacks. SetProperty
or DiscoverCharacteristic now returns NotConnected error if the link
is down.
2011-07-27 10:31:15 +03:00
Claudio Takahasi
95bf1f076a Register the ATT connection callbacks
Registers the ATT connection and disconnection callbacks in the generic
attribute API. First commit to remove implicit L2CAP connection
establishment.
2011-07-27 10:30:55 +03:00
Claudio Takahasi
3b010c0a14 Cleanup of primary service structs
Get rid of local structure to store all GATT primary services of a
given device. "primary" struct has been renamed to "gatt_service"
to avoid misinterpretation or confusion with "att_primary".
2011-07-27 10:30:25 +03:00
Claudio Takahasi
27347f58bd Cleanup of primary service registration 2011-07-27 10:30:13 +03:00
Claudio Takahasi
cdeb4dab7d Remove leftover D-Bus message in gatt_service 2011-07-27 10:29:58 +03:00
Claudio Takahasi
c34ccee6b8 Remove storing device path in gatt_service 2011-07-27 10:29:29 +03:00
Claudio Takahasi
c7b1f0bb28 Remove not necessary data from gatt_service
Bluetooth source and destination address can be obtained from the
device object. GATT service doesn't need to keep these addresses.
2011-07-27 10:28:47 +03:00
Marcel Holtmann
3f553a30ad Allow building with GLib 2.16 for now 2011-07-04 11:09:55 +02:00
Lucas De Marchi
fcb426c76a Fix common misspelled words
Accounting of misspelled words, as detected by codespell:

acording      2
ancilliary    1
appropiate    1
atribute      1
cant          1
comming       2
gracefull     1
lenght        1
mispelled     1
occured       1
occurences    1
ocurred       3
prefered      1
presense      1
reponse       1
seperate      1
succesful     1
successully   1
sucessfull    1
sucessfully   1
2011-07-03 14:36:14 +03:00
Luiz Augusto von Dentz
05cb01fc32 Make use of g_slist_free_full on attrib 2011-06-30 12:32:19 +03:00
Johan Hedberg
4b609b812f Add "quit" to gatttool supported commands 2011-06-08 09:59:20 +09:00
Szymon Janc
0c5f016867 Remove unused op variable from encode_discover_primary 2011-05-15 01:47:09 +03:00
Johan Hedberg
1f8969c043 Clean up ATT CID & PSM magic values & definititions
Use proper defines for the ATT CID and PSM. The values are really ATT
and not GATT specific so move them from gatt.h to att.h.
2011-04-26 21:13:49 +01:00
Claudio Takahasi
8447ce5c94 Remove btd_device_add_service function
btd_device_add_service is no longer necessary if the object paths for
the primary services can be returned during the registration.
2011-04-14 20:10:15 +03:00
Claudio Takahasi
612d020764 Register primary services exported over basic rate
This patch registers the object paths for primary services exported
through SDP. PSM, start and end handle information are available in
the Protocol Descriptor List.
2011-04-14 20:09:21 +03:00
Sheldon Demario
839adcd63d Fix race condition on gatttool
When the connect_cb() takes too long to be called the event_loop goes to
idle state and executes the callback too early
2011-04-14 20:05:23 +03: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
Sheldon Demario
6a3a89774c Fix Characteristic read by UUID on gatttool
The Characteristic read by UUID GATT procedure is not incremental, i.e.
it returns the entire list in a single Read By Type request. Therefore
it should not be called recursively.
2011-04-09 10:25:56 -07:00
Bruna Moreira
d0b675088a Remove deprecated attrib plugin
The attrib plugin is deprecated and it is not used anymore. Remove it
and all related configuration. Note that GATT utility (gatttool)
configuration item was moved to Makefile.tools and it is compiled when
--enable-tools is used in configure.
2011-04-01 16:43:11 +03:00
Claudio Takahasi
52727904b6 Remove "authen" and "autho" short versions for ATT constants 2011-03-30 19:38:46 +03:00
Anderson Lizardo
a3e9d397f0 Move GATT example server to a standalone plugin
The GATT example server was in the same plugin as the GATT client.
Moving it to a separate plugin will allow to easily disable it.
2011-03-30 19:19:29 +03:00
Vinicius Costa Gomes
a0b6c596e9 Add support for re-using the attrib channel
In some cases, when the device is already connected there's no need
to create another GAttrib instance.

This will allow the Attrib client to use the connection already
estabilished, this will be very useful when we support more
LE profiles.
2011-03-30 19:15:54 +03:00
Vinicius Costa Gomes
fc19dbe0d0 Remove _init and _exit methods from Attrib client
Now that Attrib client is being moved to the core, there's no
need to have explicit _init and _exit methods.

This also means that we need to pass the DBusConnection explicitly
to the registration method.
2011-03-30 19:15:52 +03:00
Vinicius Costa Gomes
279a538273 Register Attrib interface when loading device from storage
Now that the GATT client functionality is being moved to the
core we need to register the interface when the device is created.
2011-03-30 19:15:46 +03:00
Vinicius Costa Gomes
c6477c3ccc Move Attrib client to the core 2011-03-30 19:15:43 +03:00
Bruna Moreira
6fc92a5341 Add Exchange MTU in interactive gatttool 2011-03-18 11:22:45 +02:00
Bruna Moreira
1b07befa15 Add Exchange MTU operation in GATT library 2011-03-18 11:17:58 +02:00
Bruna Moreira
efcef2bd79 Use GAttrib buffer for ATT protocol PDUs
Prior to this commit, there were local buffers inside GATT functions.
Now, a single buffer is used, to make sure the MTU limit is respected.
2011-03-18 11:15:07 +02: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
Sheldon Demario
922c5feb93 Add discover characteristics by UUID to gatttool
According to the specification the characteristics discover and
characteristics discover by UUID use the same opcode and the result
should be filtered by callback.
2011-03-17 14:50:59 +02:00
Johan Hedberg
c620d295f7 Remove redundant return statements from interactive gatttool 2011-03-15 22:27:00 +02:00