Commit Graph

232 Commits

Author SHA1 Message Date
Andre Dieb Martins
2fab731d89 Fix GATT listen mode updating
Update gatt's listen-mode flag whenever connect_cb() is called again.
2011-02-08 15:07:23 -08:00
Bruna Moreira
240fcdb006 Fix invalid read after list concatenation
g_slist_concat uses the items from second list directly so they should
not be freed.
2011-02-04 06:55:02 +02:00
Elvis Pfützenreuter
05133a40fd Fix parameter type in att_put_u32 2011-02-04 06:53:35 +02:00
Brian Gix
8865beb9a3 Fix incoming attrib-server connection MTUs
It is important for the Attribute Server to be aware of and completely
fill response packets up to the full MTU when reading long attributes.
Some remote devices will only request additional (READ_BLOB) data if the
preceding read sent the maximum amount of data.

Incoming connections are identified as L2CAP or LE by pointers to the
Service IO channel the incoming connection was recieved on in the
user_data parameter. L2CAP channels are set to the BR/EDR minimum MTU of
48, and LE channels to the LE payload size of 23.
2011-01-21 12:19:12 +05:30
Bruna Moreira
4ca8ed4d50 Fix duplicate characteristics
The Discover() operation (from DBus API) was registering the same
characteristics after running several times. This can be checked using
test-attrib.
2011-01-21 12:15:17 +05:30
Brian Gix
8648c3b198 Add READ_BLOB_REQUEST support to attribute server 2011-01-20 15:04:15 +05:30
Bruna Moreira
46be88cb8b Move common code from Discover all Characteristics to GATT library
The attribute client (attrib/client.c) and gatttool share similar code
to parse the PDU coming from server. This commit moves this common code
to attrib/gatt.c, and simplifies the callbacks implemented by the
clients. The client callbacks are now called just once and get a GSList
of characteristics, instead of the raw PDU.
2011-01-19 20:41:11 +05:30
Bruna Moreira
e04efbaddf Rename gatt_primary_t to more generic name
The gatt_primary_t typedef was renamed to gatt_cb_t because it will be
used for primary and characteristic callbacks.
2011-01-19 20:40:56 +05:30
Claudio Takahasi
5399423bd6 Move interactive code of Discover Primary to gatt.c
Initial patch to move the shared code related to Discover All Primary
Services and Discover Primary Services by UUID to gatt.c.
2011-01-08 11:02:38 +02:00
Anderson Lizardo
952b5ca7d3 Move GATT service to attribute server core
GATT service (like GAP one) should be moved to the core attribute server
because there can be only one instance of it.

There was a "Attribute Opcodes Supported" characteristic inside the GATT
service in attrib/example.c which is not defined by the Core
specification and was removed before moving the code.
2011-01-07 22:28:26 +02:00
Anderson Lizardo
8a07d7e4d1 Move GAP service registration to src/attrib-server.c
GAP service shall be registered only once, so it makes sense to move it
to the core attribute server code.

The GAP "Device Name" characteristic was always "Example Device" on the
example server. This has been changed to use the Name attribute from
main.conf.
2011-01-07 22:28:24 +02:00
Anderson Lizardo
a5797b18a3 Refactor example server to use att_put_u16()
The original code was written before att_put_u16() was implemented.
2011-01-07 22:28:21 +02:00
Brian Gix
acdc181a5d Fix gatt_read_char() to support long Attrib Values
Fix gatt_read_char() to support long Attribute Values by recognizing
that results longer that 21 octets may include data beyond
what has been returned with the first read. Extra data is
obtained by issuing READ_BLOB requests until either a
result is returned shorter than 22 octets, or an error
is recieved indicating that no further data is available.
The API for this function has not changed.
2011-01-07 21:31:34 +02: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
08a9c3ce7d Change security level on demand when reading characteristic descriptor 2011-01-05 14:04:56 +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
Vinicius Costa Gomes
adbfb31ab2 Add GetProperties method the Service Interface
For now this interface just includes the path that each characteristic
is registered at.
2010-12-23 10:32:25 +02:00
Vinicius Costa Gomes
87b140440a Add support for adding services to the Services property
We need to fill the devices property as each service path gets
registered in the DBus system bus.
2010-12-23 10:32:11 +02:00
Vinicius Costa Gomes
b33922d99e Remove GetCharacteristics DBus method
This method was not documented in the API, and it has the same
functionality as getting the Characteristics property.
2010-12-23 10:31:42 +02:00
Vinicius Costa Gomes
a1b0fda9a0 Add a Discover method to the GATT Client
This methods allows users to actively start the discovery of characteristics
presents in a service.
2010-12-23 10:31:05 +02:00
Vinicius Costa Gomes
463dbe1bea Add support for making LE connections to GATT client
Now GATT client should be able to make LE connections. The information
used to determine if we should make a LE connection is the psm stored
in the gatt_service structure.
2010-12-23 10:30:45 +02:00
Vinicius Costa Gomes
60987f4afa Clean up the primary service D-Bus registration
Now, that much of this funcionality was moved to the core, we can go
straight to the registration of D-Bus interfaces.
2010-12-23 10:30:27 +02:00
Vinicius Costa Gomes
5418e09a27 Remove duplicated code for discovering GATT services
Most of this functionality was moved to src/device.c. Since that move
this code doesn't work. Some ugly hack were added to avoid breaking
the build.
2010-12-23 10:29:22 +02:00
Vinicius Costa Gomes
ed2fd82805 Add the btd_ prefix to device_add_service
This is needed to keep consistency, as device_add_service would be used
from outside the core bluetoothd.
2010-12-23 10:28:48 +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
Vinicius Costa Gomes
5ffd0e6374 Fix attrib plugin deregistration
As the comparison method used for find what to de-register was
wrong, it was causing the btd_device reference that the attrib
plugin was keeping never to be dropped.
2010-12-22 13:50:17 +02:00
Brian Gix
7749241702 Add enc_read_blob_req() as defined in BT Core Spec v4.0 2010-12-19 14:10:40 +02:00
Claudio Takahasi
70ceea2eb9 Fix memory leak of gattrib commands queue 2010-12-16 11:25:02 +02:00
Gustavo F. Padovan
b684996b93 attrib: use btd_error_failed() 2010-12-14 10:31:17 +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
Claudio Takahasi
85d0be87c9 Remove automatic battery state change on attribute example
Legacy code implemented to test Indication and Notification
2010-12-07 23:53:17 +02:00
Gustavo F. Padovan
b7d1fc1f39 Add btd_error_not_authorized() 2010-12-07 23:13:16 +02:00
Gustavo F. Padovan
696c18c48f Create btd_error_invalid_args()
DBus error handling in BlueZ is a mess. This is the first patch to unify
all DBus error handling like in ConnMan and oFono. This unifies all
.InvalidArguments errors.
2010-12-07 22:58:32 +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
Bruna Moreira
dd7a2acf88 Initial attribute permission implementation
Add enums for attribute read/write requirements, which may be "none",
"authentication required" or "authorization required". Additionally, a
"not permitted" requirement means that operation is not permitted,
allowing read-only or write-only attributes.

The attrib_db_add() API was changed to allow setting these requirements,
and the example server was changed to set requirements for its
attributes.
2010-12-07 22:52:25 +02:00
Sheldon Demario
90dec87b5c Attrib server should truncate attribute value to pdu length
When the size of attribute value is greater than pdu size, it should be
truncated to the pdu length - 2
2010-11-29 19:24:07 +02:00
Claudio Takahasi
f68cb33e96 Don't trigger the discovering when registering the client
Discover All Primary Services should not be trigged by the attribute
client when a given device is registered. Discover services is now done
by the device entity.
2010-11-29 19:21:00 +02:00
Claudio Takahasi
dbe7a78109 Fix memory leak of sdp list in the attribute client 2010-11-29 19:20:45 +02:00
Claudio Takahasi
d49c4e8457 Implement primary service search when creating a device
Discover primary services implemented inside the device entity to allow
proper integration of attribute plugin. Implements a single entry point
to the attribute plugin no matter the transport(BR/EDR or LE), the device
probe callback is called for both types.

Add a new function to discover all primary services without additional
calls to fetch the remaining primary services, sub-procedure iterations
is handled inside this function.

The next action are: clean the attribute client removing implicity service
and characteristics discovery, issue the Discover Primary Service based on
the remote properties and fetch the characteristic on demand.
2010-11-29 19:18:33 +02:00
Johan Hedberg
20ccc578c8 Remove unused includes 2010-11-28 13:41:35 +02:00
Sheldon Demario
63beb887a6 Extend discover characteristic by UUID in gatttool to fetch all values
If the number of characteristics returned exceeds the MTU size, it will
be needed to ask for more data until the handle range is entirely
searched.
2010-11-25 14:19:41 +02:00
Sheldon Demario
ad0e7f2c5a Implement Characteristic Value Read using UUID in the gatttool
Sub-procedure used to read a Characteristic Value when the client
only knows the characteristic UUID and doesn't know the handle.
More than one handle and attribute value pair can be returned,
it is up to the user define the handles range based on the service
handles range.

Usage example:
$gatttool --char-read --uuid=2a00 -i hcix -b xx:xx:xx:xx:xx:xx
2010-11-19 17:25:30 +02:00
Claudio Takahasi
f9523a9bf5 Implement Discover Primary Service by Service UUID in the gatttool
Implement only the first interaction of the discovery procedure. If the
response doesn't fit in the MTU, "start" and "end" options can be used
to discover the handles ranges of the remaining primary service instances.
UUID16 and UUID128 are supported in the uuid option.

Usage example:
$gatttool -i hcix -b xx:xx:xx:xx:xx:xx --uuid=1801 --primary
2010-11-18 22:00:02 +02:00
Claudio Takahasi
8022b94b05 Add an extra parameter in the discovery primary to specify the UUID
Extends discover primary function to perform discover by UUID. UUID
parameter defines which procedure will be executed: Discover All
Primary Services or Discover Primary Service by Service UUID.
2010-11-18 21:58:22 +02:00
Claudio Takahasi
2b3f200f29 Add Find By Type Value Response encoding/decoding functions
Find by type operation is used by Discover Primary Service by Service
UUID. Find By Type Value Response shall contain one or more group handles.
2010-11-18 21:53:54 +02:00
Bruna Moreira
b0d8865493 Implement Find by Type request encode/decoding 2010-11-18 16:44:19 +02:00
Sheldon Demario
e55509e013 Adding a new option to specify security level for gatttool 2010-11-18 14:20:11 +02:00
Claudio Takahasi
34d052348e Use reference counting of the device object while discovering services 2010-11-11 12:08:24 +02:00
Claudio Takahasi
1d723ac244 Fix invalid reference to GATT service structure 2010-11-05 07:00:44 +02:00
Claudio Takahasi
b9b0e471f2 Enable GATT over LE link on the attribute client 2010-11-05 07:00:42 +02:00