Commit Graph

467 Commits

Author SHA1 Message Date
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
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
Vinicius Costa Gomes
6cb460ab9c Fix not returning an error when DiscoverCharacteristics() fails
When the connection fails an error should be returned to inform
the user.

This adds a field to store the DBusMessage that caused the error,
so we can send the correct reply.
2011-03-15 10:52:56 +02:00
Vinicius Costa Gomes
17c03b0de4 Fix the behaviour of the DiscoverCharacteristics method
The previous behaviour could lead to some problems, as it returned
as soon as possible. To avoid problems we return just after as the
characteristics are discovered, and to save a few round trips we
return the path of all characteristics that belong to this service.

After this method return it will try to read the characteristics
values.
2011-03-15 10:52:37 +02:00
Vinicius Costa Gomes
2663ca4207 Rename the Discover method to DiscoverCharacteristics 2011-03-15 10:52:23 +02:00
Sheldon Demario
cc2d6b4db8 Add indication/notification support to interactive gatttool 2011-03-11 12:55:54 +02:00
Claudio Takahasi
a37a95fe6d gatttool: Add Write Without Response option
Sub-procedure used to write a Characteristic Value to a server when
the client knows the Characteristic Value Handle and the client does
not need acknowledgement.
2011-03-10 11:20:33 +02:00
Claudio Takahasi
4fce91f1cf Extend Characteristic Write to support Write Without Response
If callback is not informed, Write Command will be used to execute
a Write Without Response sub-procedure. Error is not returned by the
server no matter the result of the operation.
2011-03-10 11:20:08 +02:00
Sheldon Demario
e880b7a554 Add option to pass adapter to interactive gatttool 2011-03-04 15:49:57 -03:00
Sheldon Demario
b2bd2cbc2a Add missing const to interactive() parameter in gatttool 2011-03-04 15:49:55 -03:00
Sheldon Demario
ed6e2d24ea Replace all strdup() with g_strdup() in gatttool 2011-03-04 15:49:53 -03:00
Sheldon Demario
adc7ca1ece Add offset option to characteristic read by handle
Some tests require an arbitrary offset.
2011-03-04 15:48:21 -03: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
Claudio Takahasi
448456a19f Coding standard change replacing malloc by glib functions
Use glib memory allocation functions instead of malloc for attribute
data list in ATT protocol utility functions.
2011-02-24 18:35:17 -03:00
Sheldon Demario
28d393d7a2 Add sec-level option to interactive gattool 2011-02-24 18:34:34 -03:00
Bruna Moreira
6904e0f137 Add Write Request in interactive gatttool 2011-02-24 18:34:26 -03:00
Bruna Moreira
d3a5c56882 Move attr_data_from_string() to utils.c
The attr_data_from_string() function will be used in interactive and
usual gatttool so this function was moved to common file utils.c.
2011-02-24 18:33:57 -03:00
Sheldon Demario
607c54cbd9 Add characteristics read options in interactive gatttool 2011-02-24 18:33:48 -03:00
Sheldon Demario
91aed1d751 Add Characteristics Descriptor Discovery option in interactive gatttool 2011-02-24 18:33:40 -03:00
Sheldon Demario
7aff2ceaf7 Create a helper function to deal with handles on interactive gatttool 2011-02-24 18:33:22 -03:00
Vinicius Costa Gomes
a2e3157116 gatttool: Remove extra reference to the connection IO Channel
As we want the connection to be closed when the last GAttrib
reference is dropped, we don't need to keep this reference.
2011-02-24 17:43:35 -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
Anderson Lizardo
c3717e3420 Add read/write callbacks to attribute server
These callbacks will allow profiles to act before an attribute is read
and after it is written, to e.g. update the attribute value to/from an
external source.

Note that by the time the callback is called, the necessary security
checks (attribute permissions, authentication and encryption) were
already performed by the core attribute server.

The callback can optionally return an ATT status code, which will be
sent to the client using an Error Response PDU.
2011-02-24 15:41:47 -03:00
Claudio Takahasi
1847ffb1b6 Don't register GATT related SDP records if attrib server is disabled
GATT related SDP records should not be added if "AttributeServer" option
is false in the configuration file. Problem happens only when attribute
plugin is enabled.
2011-02-24 15:28:30 -03:00
Anderson Lizardo
30b24e4153 Fix typo on DBG() string format 2011-02-23 11:50:18 -03:00
Elvis Pfützenreuter
de9dfe2051 Check malformed notification/indication PDU
This patch implements discard of obviously malformed
GATT notification/indication PDUs.
2011-02-23 11:48:37 -03:00
Sheldon Demario
d576392d03 Add Characteristics Discovery option to interactive gatttool 2011-02-23 00:02:08 -03:00
Sheldon Demario
7877285534 Improve help messages in interactive gatttool
Includes the parameters info on help.
2011-02-23 00:01:24 -03:00
Brian Gix
646cc43be8 Add missing UUID16 field to Included Svc Attribute 2011-02-20 15:26:14 -03:00
Brian Gix
475dd53450 Add SDP registration of Primary GATT services
Add capability to register SDP record for Primary Services.
2011-02-19 12:14:00 -03:00
Elvis Pfützenreuter
74de4d7c6c Add UUID property to GATT service object 2011-02-18 12:09:26 -03:00
Sheldon Demario
78ed16f407 Add Primary Discovery Services option to interactive gatttool 2011-02-18 11:52:44 -03:00
Sheldon Demario
0cc2459963 Use PSM value to select LE or BR/EDR transport on gatttool
Removes "le" parameter of gatt_connect() as well the global variables
used to store the le option. LE is now the default transport, if a PSM
value different than zero is given BR/EDR will be selected
2011-02-17 15:50:15 -03:00
Sheldon Demario
eb4e1d6d4b Move do_connect() to a common file between interactive.c and gatttool.c
Since do_connect() is used in both interactive.c and gatttool.c
files, it was moved to a new file that should hold all common functions
2011-02-17 15:48:43 -03:00
Brian Gix
dba40c880f Fix Min MTU to reflect values for both L2CAP & LE 2011-02-16 18:21:45 -03:00
Claudio Takahasi
0439aea808 Fix wrong header include on interactive gatttool
This wrong include is triggering compiler warning: implicit declaration
of function 'strdup'.
2011-02-16 16:05:14 -03:00
Sheldon Demario
2c8df748ac Add connect/disconnect options on interactive mode of gatttool 2011-02-15 14:19:03 -03:00
Sheldon Demario
a523620a36 Add an initial interactive mode to gatttool
Mode required to allow better GATT procedures control. Some scenarios
require sequential commands without disconnection and delay between
operations. It is also desirable to change some connection parameters
of an active connection.
2011-02-15 14:17:37 -03:00
Bruna Moreira
48f7473068 Add Write Request operation in gatttool
Add option and callbacks for Write Request operation in gatttool.
2011-02-15 11:48:05 -03:00
Bruna Moreira
ec141a423b Add encode/decode for write response
The encode/decode functions for Write Response operations were created
to keep consistency with the rest of GATT API.
2011-02-15 11:47:40 -03:00
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