Commit graph

98 commits

Author SHA1 Message Date
Luiz Augusto von Dentz 0028559860 Bluetooth: ATT: Fix using of k_fifo_{put,get}
These functions don't work with buffers that do have fragments, instead
this replaces their usage with net_buf_{put,get}.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz 5aac983419 Bluetooth: ATT: Fix low throughput
ATT_PENDING_SENT does severely impact the throughput since multiple
packets no longer can be scheduled at same time, so instead of always
setting it regardless of the bearer/channel it is now only used for
EATT since that cannot set its own callbacks.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz 3ae926c0f1 Bluetooth: ATT: Fix not returning error
bt_l2cap_send_cb may fail if there are no context available which means
that the request would not be sent, also due to the use of custom
callback it cannot be queued either so the only option is to return the
error and let the application handle it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz bc7ce86ac5 Bluetooth: ATT: Fix not processing pending requests
Since the TX semaphore is used for all types of PDUs a request may have
to be put on the request list while there is no pending request pending
which means no response will be generated to trigger att_process,
previously this condition was handled by setting the request as
currently pending and append its buffer to tx_queue but this is no
longer efficient since there could be more than one channel active the
code should try all of them before queueing back to request list.

To fix this the request list will now be processed each time a PDU has
been sent.

Fixes #26070

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Luiz Augusto von Dentz 4418ba76a5 Bluetooth: ATT: Fix overwritting sent callback
ATT channel sent callback shall not be overwritting until the
operation completes as it can result in breaking flow control when
CONFIG_BT_ATT_ENFORCE_FLOW is enabled.

Fixes #25964
Fixes #26071

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-06-18 21:35:12 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Luiz Augusto von Dentz e0cbdf3b87 Bluetooth: GATT: Add support for new PDUs
This adds support for ATT_MULTIPLE_HANDLE_VALUE_NTF,
ATT_READ_MULTIPLE_VARIABLE_REQ and ATT_READ_MULTIPLE_VARIABLE_RSP.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz f4192bda26 Bluetooth: ATT: Add support EATT bearer
This adds support for EATT bearer which was introduced in 5.2, they work
as extra channels to have GATT traffic, at the moment it is completely
transparent to application when they are in use since the allocation
happens automatically.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Joakim Andersson d858264d9e Bluetooth: host: Convert bluetooth host to using k_timeout_t struct
Convert bluetooth host to using k_timeout_struct for the timeout values.
This is mostly replacing s32_t with k_timeout_t.
In l2cap the handling of no timeout in send channel request was removed
since the timeout is both documented as minimum of 1 second and never
given any no timeout value.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-30 13:46:48 +03:00
Luiz Augusto von Dentz 8863b72b05 Bluetooth: ATT: Fix passing wrong pointer when disconnecting
When disconnecting att_reset is called and all requests are notified
but instead of passing req->user_data like it should it pass the req
itself which nowdays comes from a k_mem_slab, rather than being a
contiguous memory that would contain the request and its user data,
which would likely cause invalid access.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-04-15 11:38:41 +03:00
Joakim Andersson d84528edb1 Bluetooth: ATT: Fix ATT corrupting mem_slab structure after free
Fix ATT releasing the att structure back to the memory slab allocator
before the structure is actually ready to be released. The memory slab
allocator will write context data inside the freed slab which is
currently being overwritten by l2cap during channel teardown.

This manifests as an "Unable to allocate ATT context for conn" when
reconnecting with multiple connections.

Since the l2cap channel is embedded inside of the ATT context and l2cap
still has a valid referenc to the l2cap channel we need to release the
ATT context at a later time.
This should be fixed by implementing the channel destroy function and
releasing the channel there.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-28 17:55:38 +02:00
Joakim Andersson 83f108afd1 Bluetooth: L2CAP: Add destroy callback to fixed L2CAP channels
Add the option to provide the destroy callback to the fixed channels.
This can be used to free the memory for the L2CAP channel context which
is provided by the fixed channel in the accept callback.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-28 17:55:38 +02:00
Marek Pieta bce335458b Bluetooth: ATT: Fix handling ATT response
The callback function may modify the att->req and it has to be
called after the att_process. The att_process does not re-check
if att->req is still NULL.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2020-01-25 22:39:45 +01:00
Joakim Andersson bf33338652 Bluetooth: host: Fix net buf assert on att encrypt change event
Fix assert in net_buf triggered on att encrypt change event.

	ASSERTION FAIL [net_buf_simple_headroom(buf) >= len] @
	  ZEPHYR_BASE/subsys/net/buf.c:881

This happens because when the att request was allocated, it was not
properly initialized and req->retrying was left as true.
This caused the att encrypt change handling to assume an att request
needed to be resent, starting resending with an invalid request and
request buffer.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-01-23 18:08:24 +02:00
Carles Cufi 6cf7ac77bf Bluetooth: Always use full path to hci_driver.h
The path to include/drivers should not be in the compiler include path
list, only include/. In order to make this possible, always explictly
refer to hci_driver.h via the drivers/bluetooth/ path and not only
bluetooth/.

Fixes #21974.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-01-16 19:20:39 -05:00
Luiz Augusto von Dentz 708c8bae54 Bluetooth: ATT: Use k_mem_slab for connection context
This uses k_mem_slab APIs to allocate/free ATT context instead of custom
array.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-09 19:20:21 +01:00
Luiz Augusto von Dentz d278cdc3d7 Bluetooth: GATT: Allocate request from a memory slab
This should reduce the footprint on applications that do a lot of
requests i.e have a lot of subscriptions.

Fixes #21103

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-01-09 19:20:21 +01:00
Johan Hedberg 0e91493ab4 Bluetooth: L2CAP: Make channel ops const
Make the channel ops struct const since there really isn't anything
there that needs to change at runtime. The only exception is the L2CAP
shell which was playing with the recv callback, however that can be
fixed by introducing a simple bool variable.

With tests/bluetooth/shell this reduces RAM consumption by 112 bytes
while adding only 16 bytes to flash consumption.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-12-19 11:28:24 +02:00
Joakim Andersson afe088247d Bluetooth: ATT: Fix ATT MTU support for larger MTUs
Fix ATT MTU size of length variables resulting in wrong length values
reported to the user. Communicating with an Android device using an MTU
of 517 resulted in write commands reported as length 2 instead.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-12-04 19:08:10 +01:00
Luiz Augusto von Dentz 5beb5b5992 Bluetooth: ATT: Fix not handling errors properly
Since bt_conn_send_cb can fail to send buffer causing it to unref this
may cause buffer leaks as the caller is not aware of the error assuming
the buffer could be sent.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-12-03 19:44:51 +01:00
Luiz Augusto von Dentz 1ef9b20f61 Bluetooth: ATT: Replace checks for CONFIG_BT_ATT_ENFORCE_FLOW
Make use of IS_ENABLED so the compiler do its job to remove any dead
code.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-10-04 20:57:13 +03:00
Joakim Andersson 4bca0f3d33 Bluetooth: ATT: Fix disconnected ATT not releasing buffers
Fix bug in ATT reset handling, not releasing queued notification
buffers when the connection is terminated.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-10-04 10:33:55 +03:00
Luiz Augusto von Dentz 4f3892c0eb Bluetooth: GATT: Use check_perm to check CCC permission
This moves check_perm code under GAT and make use of it to check if CCC
write permission can be attended by the connection security level or if
it needs to be increased.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-09-19 21:12:39 +03:00
Luiz Augusto von Dentz 03b9ce487c Bluetooth: GATT: Add support to setting permission on CCCD
This adds support to set different permissions to CCCD so security can
be checked when enabling notification which conforms to:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2360:

  '3.3.3.3 Client Characteristic Configuration

   Authentication and authorization may be required by the server to
   write the configuration descriptor.'

In addition to that also ensure that notification are not re-enabled
until the proper security level is reached to conform to the following
statement:

  '10.3.1.1 Handling of GATT indications and notifications

   A client “requests” a server to send indications and notifications
   by appropriately configuring the server via a Client Characteristic
   Configuration Descriptor. Since the configuration is persistent
   across a disconnection and reconnection, security requirements must
   be checked against the configuration upon a reconnection before
   sending indications or notifications. When a server reconnects to a
   client to send an indication or notification for which security is
   required, the server shall initiate or request encryption with the
   client prior to sending an indication or notification. If the client
   does not have an LTK indicating that the client has lost the bond,
   enabling encryption will fail.'

Fixes #17983

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-09-19 21:12:39 +03:00
Mariusz Skamra ac7f81314e Bluetooth: ATT: Fix responding to unknown ATT command
Host shall ignore the unknown ATT PDU that has Command Flag set.
Fixes regression introduced in 3b271b8455.

Fixes: GATT/SR/UNS/BI-02-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2019-09-10 12:26:11 +03:00
Akshatha Harishchandra 613655e91b bluetooth: host: Replaced bt_uuid_create_le with bt_uuid_create
Endianness bug fix in bt_uuid_create function.
Replaced bt_uuid_create_le with bt_uuid_create which
handles both UUID from air and internal varaiable.
Fixed bug with endianess in case of big endian targets.

Signed-off-by: Akshatha Harishchandra <akhr@oticon.com>
2019-08-30 12:42:24 +02:00
Luiz Augusto von Dentz 5ac014aac6 Bluetooth: ATT: Fix misleading warning
When an opcode doesn't have a handle that doesn't mean it is unknown
just that it will not be handle as it could have been disabled.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz 5d0c6fe562 Bluetooth: ATT: Use timeout when allocating a buffer
Whenever responding or confirming use the ATT timeout to allocate a
buffer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Luiz Augusto von Dentz 3b271b8455 Bluetooth: ATT: Fix att_op_get_type when client is disabled
When CONFIG_BT_GATT_CLIENT is not set att_op_get_type would return
unkown operation instead of properly return the opcode.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-30 09:52:01 +02:00
Joakim Andersson 3e9888105e Bluetooth: Host: Rename API function to initiate bluetooth security.
Rename bt_conn_security to bt_conn_set_security, this makes the API
naming more consistent.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-27 15:13:25 +02:00
Joakim Andersson 1c48757d94 Bluetooth: Host: Rename security level enum
Rename security level enum, using level and number instead of low,
medium, high and fips.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-27 15:13:25 +02:00
Luiz Augusto von Dentz b563f4440a Bluetooth: Dispatch internal callbacks using RX thread
This is safer now that bt_conn_create_pdu can return NULL when using
syswq which can prevent things like signalling of L2CAP and ATT layers.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-08-09 21:01:59 +02:00
Kim Sekkelund 87c3db9e0b Bluetooth: Host: Find by type should accept 128bit UUIDs
Find by type does only accept a UUID with the same length as the UUID
which is stored in the internal list. If a UUID is stored in the short
16 bit format then a request with 128 bit UUID will fail.
Add support for the missing formats.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2019-08-07 15:39:11 +02:00
Joakim Andersson c1a754f665 Bluetooth: Host: Print error codes in hex
Error codes are listed in header files and in the core spec as hex
values. Always print them in hex in debug for easier error code
checking.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-08-05 12:18:17 +02:00
Luiz Augusto von Dentz 662a519a17 Bluetooth: ATT: Fix bt_att_req_cancel clearing outstanding request
This adds a dummy cancel request which is used instead of NULL when
clearing and outstanding request thus prevent new request to take
place before a response is received while allowing the original request
to be reused.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-07-29 12:26:18 +02:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Luiz Augusto von Dentz a788ce23da Bluetooth: ATT: Fix unbalanced use of k_sem_give
k_sem_give shall only be used if no callback has been set otherwise
k_sem_take was not called which can break the flow control.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-14 15:55:07 +03:00
Luiz Augusto von Dentz ec89ae6ff4 Bluetooth: ATT: Queue buffers on bt_att_send
This prevents threads to block which may deadlock when system wq is
used.

Fixes #16803

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-06-14 15:55:07 +03:00
Luiz Augusto von Dentz b65fe62719 Bluetooth: Add possibility to pass a user_data to conn_tx_cb_t
This allows setting a custom pointer to be passed back to the complete
callback at expense of increasing the buffers in 4 bytes.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Luiz Augusto von Dentz a3bea8872b Bluetooth: L2CAP: Move fixed channels to its own section in ROM
This changes the declaration of fixed channels to be statically defined
with use of BT_L2CAP_CHANNEL_DEFINE since fixed channels are never
unregistered.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-29 16:31:03 +03:00
Kamil Piszczek 6bb75a53d1 Bluetooth: gatt: ccc changed cb after connection cb
Changed the order of Bluetooth callbacks. Now the connected callback is
received before CCC changed callbacks.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2019-02-18 15:13:25 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Luiz Augusto von Dentz daac1fa77a Bluetooth: GATT: Implement Robust Caching
This implement Robust Caching which is mandatory when Database Hash and
Service changed Characteristics are supported.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-02-08 18:07:34 +02:00
Wolfgang Puffitsch aed74024b5 bluetooth: host: Fix endianness issue for group end_handle.
Convert end_handle to native endianness before comparison.

Signed-off-by: Wolfgang Puffitsch <wopu@oticon.com>
2019-02-07 21:00:42 +02:00
Johan Hedberg fe7f1e17de Bluetooth: Take advantage of net_buf_pull_mem()
Convert the remaining places of the host stack where
net_buf_pull_mem() makes more sense than net_buf_pull().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-28 15:21:23 +02:00
Luiz Augusto von Dentz a779705f16 Bluetooth: GATT: Add bt_gatt_write_response_cb
This adds bt_gatt_write_response_cb works similarly to
bt_gatt_notify_cb which can take a callback to be called when the PDU
is considered transmitted over the air.

Note: This can also be used to disable the ATT flow control which would
blocks sending multiple commands without wainting their transmissions.

Fixes #11558

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-01-16 21:43:53 -05:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00