Commit Graph

467 Commits

Author SHA1 Message Date
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
Dirk-Jan C. Binnema
fabd565565 attrib: Add support for 128-bit characteristic UUIDs in gatt_service_add
Custom GATT services typically use 128-bits UUIDs; this patch allows for
using gatt_service_add to define such services by adding a new option
GATT_OPT_CHR_UUID, which allows for passing bt_uuid_t* values. Note, a
previous patch renamed the old GATT_OPT_CHR_UUID into
GATT_OPT_CHR_UUID16.
2013-07-30 12:59:15 +03:00
Dirk-Jan C. Binnema
1208266dcc attrib: Rename GATT_OPT_CHR_UUID into GATT_OPT_CHR_UUID16
Rename the option for all in-tree users. This frees up GATT_OPT_CHR_UUID to be used
for UUIDs of type bt_uuid_t* (in a next patch).
2013-07-30 12:59:12 +03:00
Dirk-Jan C. Binnema
f3e175bd78 attrib: Update gatt_service_add size assert for dealing with 128-bit UUIDs
To paraphrase Anderson Lizardo: "h" was overflowing for 128-bit services
because the handle is incremented after each attribute is added so at
the end we had: 0xffff + 1 == 0 (h is uint16_t).

As it seems more complex to try to remove the overflow without affecting
the logic too much, we update the assertion.
2013-07-30 12:59:12 +03:00
Anderson Lizardo
d1abf2b7d8 attrib: Reduce scope of variable declarations in char_discovered_cb()
This makes it easy to identify where variables are being used.
2013-07-24 08:44:07 -07:00
Anderson Lizardo
638790716f attrib: Allow dec_read_resp() to just check if PDU is valid
If a NULL "value" parameter is given, only check whether PDU is valid,
without copying attribute value to a buffer.
2013-07-24 08:43:17 -07:00
Alvaro Silva
1ed64821ac attrib: Add encode/decode execute write support
Add functions for encoding/decoding Execute Write Request PDUs.
2013-07-24 08:43:05 -07:00
Alvaro Silva
38487a9915 attrib: Add encode/decode prepare write support
Add functions for encoding/decoding Prepare Write Request PDUs.
2013-07-24 08:42:43 -07:00
Alvaro Silva
9abeec8c11 attrib: Remove unused parameter from enc_write_resp() 2013-07-24 08:42:32 -07:00
Eder Ruiz Maria
969906d6aa attrib: Fix coding style for various enc_*/dec_* functions
Fix coding style for enc_read_blob(), enc_read_blob_resp(),
dec_read_resp(), enc_error_resp(), enc_find_info_req(),
enc_find_info_resp() and enc_prep_write().
2013-07-24 08:42:22 -07:00
Anderson Lizardo
910beb706c attrib: Simplify prepare_write()
All parameters can be retrieved from struct write_long_data fields,
therefore there is no need to pass them separately.
2013-07-24 08:42:05 -07:00
Anderson Lizardo
9b1e7de26c attrib: Fix coding style in prepare_write_cb() 2013-07-24 08:41:58 -07:00
Anderson Lizardo
ccd0e3783d attrib: Do not use Write Command in gatt_write_char()
Previously, if no callback was given to gatt_write_char(), it was
assumed that a "Write Without Response" (which uses Write Command)
should be used instead of Write Request.

This "shortcut" is unnecessary (there is gatt_write_cmd() for the
situations where Write Without Response is required) and just duplicates
code.

This commit also fixes the few places where gatt_write_cmd() should be
used.
2013-07-24 08:41:47 -07:00
Anderson Lizardo
1d4f111fae attrib: Rename gatt_find_info() to gatt_discover_char_desc()
The old name referred to the underlying ATT PDU (Find Information
Request and Find Information Response) and not to the actual GATT
procedure (Discover All Characteristic Descriptors).
2013-07-24 08:41:32 -07:00
Eder Ruiz Maria
613cc886ed gatttool: Remove unused code
Since commit 6a3a89774c the code
removed here has no sense.
2013-07-24 08:41:25 -07:00
Sathish Narasimman
03375be73a attrib: Fix interactive gatttool segfault
Passing the special character single quote:

$gatttool -I
[   ][                 ][LE]> '
Segmentation fault (core dumped)

Checking g_shell_parse_argv fail status (return FALSE on failure), works
fine.
2013-07-19 14:24:55 +03:00
Johan Hedberg
88f7ecd64d attrib: Use GAttrib destroy callback for included search 2013-06-07 14:20:19 +03:00
Johan Hedberg
ba7a863aba core: Always specify local LE address type with btio 2013-05-17 11:08:56 +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
Alvaro Silva
1ed57cae60 gatttool: Use error message prefixes consistently
Replace rl_printf() calls with macros that add appropriate prefixes.
2013-04-17 11:23:58 +03:00
Eder Ruiz Maria
64868f234b gatttool: Show info message when no primary service is found 2013-04-17 11:23:50 +03:00
Eder Ruiz Maria
165803d4e0 gatttool: Use bluetoothctl strategy for unix signal handling
Now to exit from gatttool at interactive mode, user must use SIGTERM(15)
or press Ctrl+D. SIGINT(2) or Ctrl+C just flushes typed characters and
breaks line.
2013-04-17 11:23:39 +03:00
Eder Ruiz Maria
46b9b1345e gatttool: Use bluetoothctl strategy to handle standard input
Use GSource id returned by g_io_add_watch() instead of raw GIOChannel to
handle stdin and glib main loop.
2013-04-17 11:23:07 +03:00
Alvaro Silva
4fe7426176 gatttool: Remove connecting message from prompt
When trying to connect, the "connecting" message is not set as prompt
anymore. Instead, it is printed just like other status messages and the
prompt is kept, allowing the user to send commands while connection is
being established.
2013-04-17 11:22:55 +03:00
Alvaro Silva
e80e4bd1ec gatttool: Show connection state using color
When device is connected, the Bluetooth address is shown in blue color.
2013-04-17 11:22:44 +03:00
Eder Ruiz Maria
f952820eb6 gatttool: Use bluetoothctl behavior when pressing Enter on empty prompt 2013-04-17 11:22:34 +03:00
Eder Ruiz Maria
cf192c494f gatttool: Replace more usages of printf() with rl_printf()
rl_printf() works better with readline than plain printf(), specially on
asynchronous callbacks.
2013-04-17 11:22:25 +03:00
Eder Ruiz Maria
6a287262f0 gatttool: Fix issues with printf() and readline prompt
Use rl_printf() from bluetoothctl to consistently display messages. This
is specially important for asynchronous callbacks, where using printf()
may mess up the prompt created by readline.
2013-04-17 11:22:00 +03:00
Eder Ruiz Maria
3dacf2769d gatttool: Use GError to propage error messages to caller
Handle runtime errors outside gatt_connect(), using GError to propagate
error messages to caller.
2013-04-17 11:21:29 +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
Eder Ruiz Maria
189cc8203e gatttool: Remove check for bluetooth address parameter on gatt_connect()
This check is more appropriate to be done by callers of gatt_connect().
This is already done on interactive mode in attrib/interactive.c and is
now also done in non-interactive mode.
2013-04-07 18:11:03 +03:00
Eder Ruiz Maria
8f84a47e8d gatttool: Remote address is mandatory for non-interactive gatttool
For gatttool non-interactive mode, command line parameter with
bluetooth remote address is mandatory.
2013-04-07 18:10:53 +03:00
Jefferson Delfes
58123ad784 gatttool: Fix memory leak after parsing input line
The callback is responsible for freeing input line buffer that comes
from rl_callback_handler_install().
2013-04-07 18:09:58 +03:00
Anderson Lizardo
8c8cc51b18 attrib: Fix status on memory allocation failure
If memory allocation fails, ATT_ECODE_INSUFF_RESOURCES should be
reported to the callback.
2013-04-04 14:51:21 +03:00
Anderson Lizardo
8b61564c4d attrib: Fix coding style in read_char_helper() 2013-04-04 14:51:08 +03:00
Anderson Lizardo
03f2256f6a attrib: Fix memory leak on low memory condition
If g_try_new0() fails due to low memory condition, "list" should be
freed before returning from primary_all_cb().
2013-04-04 14:50:59 +03: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
Jefferson Delfes
789f7e7bc3 gatttool: fix parameter type/name from le to psm
The parameter le was changed to psm and its type was modified from
boolean to int, but header was unmodified. That change occurred in commit
0cc2459963.
2013-03-25 14:26:22 +02:00
Vinicius Costa Gomes
99f609241c device: Fix invalid memory access during Find Included
When doing the Find Included Services GATT procedure, the status of the ATT
procedure was being ignored, and in the case of a timeout it is possible to
crash bluetooth with an invalid memory access.

Valgrind log:

==1755== Invalid read of size 8
==1755==    at 0x46971A: find_included_cb (device.c:2964)
==1755==    by 0x4465AE: isd_unref (gatt.c:92)
==1755==    by 0x446885: find_included_cb (gatt.c:425)
==1755==    by 0x448266: disconnect_timeout (gattrib.c:269)
==1755==    by 0x4E76BCA: g_timeout_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76044: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76377: g_main_context_iterate.isra.24 (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76771: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x40A2EE: main (main.c:583)
==1755==  Address 0x69530a8 is 8 bytes inside a block of size 64 free'd
==1755==    at 0x4C2874F: free (vg_replace_malloc.c:446)
==1755==    by 0x40BFA6: service_filter (watch.c:486)
==1755==    by 0x40BC6A: message_filter (watch.c:554)
==1755==    by 0x5160A1D: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.7.2)
==1755==    by 0x40AAB7: message_dispatch (mainloop.c:76)
==1755==    by 0x4E76BCA: g_timeout_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76044: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76377: g_main_context_iterate.isra.24 (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76771: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x40A2EE: main (main.c:583)
==1755==
==1755== Invalid read of size 8
==1755==    at 0x4486D5: g_attrib_get_buffer (gattrib.c:657)
==1755==    by 0x4467C5: find_included (gatt.c:363)
==1755==    by 0x4465AE: isd_unref (gatt.c:92)
==1755==    by 0x446885: find_included_cb (gatt.c:425)
==1755==    by 0x448266: disconnect_timeout (gattrib.c:269)
==1755==    by 0x4E76BCA: g_timeout_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76044: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76377: g_main_context_iterate.isra.24 (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76771: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x40A2EE: main (main.c:583)
==1755==  Address 0x18 is not stack'd, malloc'd or (recently) free'd
==1755==
==1755==
==1755== Process terminating with default action of signal 11 (SIGSEGV)
==1755==  Access not within mapped region at address 0x18
==1755==    at 0x4486D5: g_attrib_get_buffer (gattrib.c:657)
==1755==    by 0x4467C5: find_included (gatt.c:363)
==1755==    by 0x4465AE: isd_unref (gatt.c:92)
==1755==    by 0x446885: find_included_cb (gatt.c:425)
==1755==    by 0x448266: disconnect_timeout (gattrib.c:269)
==1755==    by 0x4E76BCA: g_timeout_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76044: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76377: g_main_context_iterate.isra.24 (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x4E76771: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3400.2)
==1755==    by 0x40A2EE: main (main.c:583)
2013-01-29 15:57:36 -06: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
e654bdfa9a attrib: Fix compilation errors when compiled without optimization
Fix these build errors:

attrib/att.c: In function ‘dec_read_by_grp_req’:
attrib/att.c:165:10: error: comparison between signed and unsigned
integer expressions [-Werror=sign-compare]
attrib/att.c:170:10: error: comparison between signed and unsigned
integer expressions [-Werror=sign-compare]
attrib/att.c: In function ‘dec_read_by_type_req’:
attrib/att.c:393:10: error: comparison between signed and unsigned
integer expressions [-Werror=sign-compare]
attrib/att.c:402:10: error: comparison between signed and unsigned
integer expressions [-Werror=sign-compare]
2013-01-10 16:06:22 -08: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