Commit Graph

410 Commits

Author SHA1 Message Date
Paulo Borges
a5c67459d8 gatt: Improve characteristics discovery
In the Discover Characteristics by UUID sub-procedure, if a fetched
characteristic doesn't matches with the target UUID, all others
characteristics in that response were discarded.

Because of this, the procedure will make a new request to possibly
rediscover the characteristics in the range beyond this last
characteristic.

At present, this procedure works because the gatt library will send a
Read by Type Request starting at the first attribute after the non
matching characteristic.

This commit makes the rest of the characteristics to be checked for a
matching type, which should reduce the number of requests sent during
the discovery of characteristics.
2012-12-01 11:11:26 +02:00
Paulo Borges
d07b735117 gatt: Fix memory leak in characteristic discovery
If the Discover Characteristics by UUID sub-procedure has been
executed and the first characteristic is not the target, a memory
leak occurs.

This commit fixes this leak by postponing the allocation to after
the UUID verification.
2012-12-01 11:11:16 +02:00
Andrzej Kaczmarek
8a6bf096de gatt: Update characteristic names translation table 2012-11-13 10:12:15 +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
f8619bef34 attrib: Fix not checking if att_data_list_alloc fails
Now that this function may fail in more usual situations (invalid
input), we have to check its return value.
2012-10-11 08:48:22 +02:00
Vinicius Costa Gomes
a48a3bac3a att: Fix sending pdu's with invalid data
When encoding an att_data_list we need to make sure that each element
lenght of the data list will not exceed 255, because that information
will be encoded as a octet later.
2012-10-11 08:48:09 +02:00
Vinicius Costa Gomes
9111ffe1c0 att: Replace ATT_MAX_MTU with ATT_MAX_VALUE_LEN
ATT has the concept that an attribute value has a maximum length and we
weren't keeping track of this.
2012-10-11 08:46:33 +02:00
Vinicius Costa Gomes
a2e4b27451 attrib: Remove all the usages of ATT_MAX_MTU
This "define" was bogus for two reasons: 1. There's no concept
of maximum MTU in the ATT level; 2. It was used as a maximum attribute
value length.
2012-10-11 08:35:06 +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
Jefferson Delfes
6e5c2bf7ae gatttool: Add "included" command
New command to find included services in interactive mode.
2012-10-09 10:56:12 +02:00
Vinicius Costa Gomes
ed3344c96b gatt: Add support for find included services
Some services like HID over LE can reference another service using
included services.

See Vol 3, Part G, section 2.6.3 of Core specification for more
details.
2012-10-09 10:54:49 +02:00
Szymon Janc
ed6a8af4a3 device: Convert device_get_address into simple getter
This allow to remove number of local variables used only to get device
address and pass it as pointer later on.

bdaddr_type parameter is also removed as there is device_get_addr_type
already present which can be used to get it if needed.
2012-10-05 11:27:45 +03:00
Szymon Janc
899e6561d2 adapter: Convert adapter_get_address into simple getter
Most uses of adapter_get_address were in form of:

bdaddr_t addr;
adapter_get_address(adapter, &addr);
foo(&addr);

Changing it to getter makes code simpler and avoid number of not
needed memcpy.
2012-10-05 11:20:18 +03:00
Anderson Lizardo
fa14609c89 attrib: Get address type using gatt_get_address()
This avoids a separate call to device_get_addr_type().
2012-10-02 16:45:07 +03:00
Jefferson Delfes
3d0e48b334 gatt: Remove offset parameter from gatt_read_char
The Core spec allows to implement Read Long Characteristic Value as a
Read Request, followed by zero or more Read Blob Requests, therefore the
offset parameter is unnecessary and is always 0 for normal use.
2012-10-01 12:54:51 +03:00
Andrzej Kaczmarek
3e0595f2e9 attrib: Simplify DBusConnection object handling
This patch removes redundant references and function parameters for
DBusConnection object and uses btd_get_dbus_connection() call wherever
such object is needed instead.

Pointer returned by this call is guaranteed to be valid for entire
bluetoothd lifetime and thus do not need to be refcounted.
2012-09-21 13:52:21 +03:00
Claudio Takahasi
ea4ff5109b gatttool: Fix Characteristic descriptor discovery
This patch fixes end condition for Characteristic Descriptor Discovery.
This sub-procedure is complete when the Error Response is received and
the Error Code is set to Attribute Not Found or the Find Information
Response has an Attribute Handle that is equal to the Ending Handle of
the request.
2012-09-20 14:10:54 +03:00
Chen Ganir
beecc51461 gatt: Translate Characteristic names
Translate Characteristic UUID's to name. This list was taken from
the Bluetooth SIG developer site.
2012-09-04 10:46:36 +03:00
Andrzej Kaczmarek
6de2e1e106 gatt: Fix whitespace in UUID definitions 2012-09-03 14:56:23 +03:00
Johan Hedberg
813b674bce Add profile abstraction (replaces btd_device drivers)
This patch removes the btd_device_driver concept and replaces it with
btd_profile. The new construct also contains the necessary parts for
adapter drivers, so btd_adapter_driver is only needed for non-profile
related functionality (most of which is in plugins/*).

The main purpose of this new construct is to facilitate a centralized
connection creation mechanism for profiles, ultimately enabling the
addition of a Device.Connect() method instead of requiring a UI to know
to call e.g. Input.Connect or Audio.Connect.

This feature will also be extended to externally implemented profiles
once the internal implementation gets more stable, such as OBEX (obexd)
and HFP (oFono). The new D-Bus interface will also partially restore
functionality which was previously available through the Serial
interface.
2012-09-03 14:16:15 +03:00
Johan Hedberg
5dd93fc16a Update code base to use the new BtIO API 2012-08-28 17:18:28 -07:00
Claudio Takahasi
8ff63e2707 gatt: Don't raise error if declaration was found
This patch avoids raising errors to the upper layer if at least one
characteristic declaration has been found. According to the Core SPEC
Characteristic declarations shall be read without authentication or
authorization.
2012-08-20 20:45:25 +03:00
Claudio Takahasi
221fd83c2c gatt: Return not found if characteritics is empty
This patch changes the behaviour of Discover All Characteristics and
Discover Characteristics by UUID returning <<Attribute Not Found>> when
Characteristic list that matches the defined criteria is empty. This
scenario can happen when the GATT client avoids extra iteraction with
the remote attribute server if the last received handle(or handle + 1)
is equal to the end handle of the primary service.
2012-08-20 20:45:23 +03:00
Claudio Takahasi
fc6f87d8f9 att: Add Find Info Response Format constants
This patch adds constants declarations for Find Information Response
Format field. The format means that information data constains a list
of 1 or more handles with their 16-bit or 128-bit Bluetooth UUIDs
2012-08-20 20:45:18 +03:00
Claudio Takahasi
31706d23e5 gatt: Primary service interval may not change
This patch address the "Service Changed" scenario on which the start
and end Primary Service attribute handle interval doesn't change.
2012-08-20 20:40:47 +03:00
Johan Hedberg
46c59677c2 attrib: Fix naming and variable types of security requirements
There's a single read/write requirement value so the variables should be
named in singular form. Also, until there's e.g. an enum typedef for
them a simple int shall do.
2012-08-15 18:20:09 +03: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
Eder Ruiz Maria
7040dc92fc gatt: Add support to GATT Write Long Characteristic
Extending the function gatt_write_char for support GATT Write Long
Characteristics. MTU is checked and if the payload does not fit,
the prepare and execute write are used to do the transaction.
2012-08-15 11:58:43 +03:00
Eder Ruiz Maria
f5cf20bb06 att: Add encode/decode execute write support
Add functions for encoding/decoding Execute Write Request and
Response PDUs.
2012-08-15 11:58:43 +03:00
Eder Ruiz Maria
3be0d8feef att: Add prepare write support
Add functions for encoding/decoding Prepare Write Request and
Response PDUs.
2012-08-15 11:58:43 +03:00
João Paulo Rechi Vita
9734131cf5 gatt: Add a new descriptor UUID
Add the UUID of the External Report Reference descriptor.
2012-08-14 12:43:05 +03:00
Claudio Takahasi
501a2e8ff7 gatt: add Report Reference descriptor UUID 2012-07-09 10:58:04 -03:00
Claudio Takahasi
c902816cc2 generic attribute: Use GAttrib buffer
This patch replaces the static local buffer by the GAttrib internal
buffer to temporarily store the output ATT PDU.
2012-06-27 15:49:19 +03:00
Claudio Takahasi
cb6db2386b gatttool: Use GAttrib buffer
This patch replaces the static local buffer by the GAttrib internal
buffer to store temporarly the output ATT PDU.
2012-06-27 15:49:18 +03:00
Claudio Takahasi
2f8cd0cb7e ATT: Avoid invalid memory access for large PDU
This patch avoids invalid memory access when decoding ATT read response
PDUs. The ATT_MTU value is a per ATT Bearer value defined by the higher
layer specification.
2012-06-27 15:49:18 +03:00
Lucas De Marchi
a66a557038 Fix GDBus flags after conversion to macros
Commit "aa3b9016bf444b60e1b7e1804dfc323a23a93c5a Convert GDBus methods
to use macro helpers" converted the previous tables to use the new
macros but some flags were lost.
2012-06-27 10:33:53 +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
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