Commit Graph

479 Commits

Author SHA1 Message Date
Marcel Holtmann
6648e011a3 attrib: Make btio/btio.h include local 2014-01-25 20:32:57 -08:00
Marcel Holtmann
cf458ad28f attrib: Use full include path for header files 2014-01-25 20:10:00 -08:00
Anderson Lizardo
a3299e5b1e attrib: Add extra PDU checks when decoding Read by Type Response
These checks are needed to avoid invalid memory access on bogus PDUs.
2014-01-11 18:56:03 +02:00
Anderson Lizardo
cceb59d76b attrib: Fix PDU length check for Read by Type Request
PDU length must be either 7 or 21 octets.
2014-01-11 18:56:03 +02:00
Anderson Lizardo
88cdd5749c attrib: Reject incomplete PDU in dec_find_by_type_resp()
Otherwise, an incomplete PDU may be silently accepted (with any
remaining data discarded).
2014-01-11 18:56:03 +02:00
Anderson Lizardo
a9249eece7 attrib: Remove unnecessary local variables from dec_find_by_type_req()
Use number instead of "min_len", which is easier to review (with help of
the documented parameter sizes).

valuelen is redundant as *vlen can be used directly.
2014-01-11 18:56:03 +02:00
Anderson Lizardo
a8b353da80 attrib: Remove unnecessary NULL checks on dec_find_by_type_req()
Just assume that the caller will pass non-NULL pointers as arguments
(which is true for the only current caller of this function).
2014-01-11 18:56:03 +02:00
Anderson Lizardo
ef97296c20 attrib: Add extra PDU checks when decoding Read by Group Type Response
These checks are needed to avoid invalid memory access on bogus PDUs.
2014-01-11 18:56:03 +02:00
Anderson Lizardo
a5e6aafdf7 attrib: Fix PDU length check for Read by Group Type Request
PDU length must be either 7 or 21 octets.
2014-01-11 18:56:03 +02:00
Anderson Lizardo
22cf3b76d1 attrib: Remove unnecessary checks for PDU length on ATT encoding
Both userspace and kernel enforce a minimum ATT MTU of 23 octets, which
is also used as minimum size for buffers passed to ATT encoding
functions. Therefore, it is unnecessary to perform these checks on ATT
requests that are guaranteed to fit into 23 octets.

Also document ATT parameter lengths where a constant is being used for
calculating the PDU length.
2014-01-11 18:56:03 +02:00
Anderson Lizardo
95b8a4ec80 attrib: Use att_put_u16() instead of htobs() + memcpy() 2014-01-11 18:56:03 +02:00
Anderson Lizardo
2704b4c83b attrib: Modify gatt_cb_t signature
Use standard C types instead of GLib ones (which are unnecessary here)
and move the "status" parameter to the first position, so it is
consistent with other callbacks.
2014-01-11 18:56:03 +02:00
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