Commit graph

1495 commits

Author SHA1 Message Date
Joakim Andersson c3308275f6 Bluetooth: GATT: Turn GATT notify multiple feature default off
Turn the GATT notify multiple feature off as default value.
This feature changes the behavior of the bt_gatt_notify API in a way
that might not be backwards-compatible.
This is because the notify multiple header is larger, and therefore
limits the amount of bytes that could otherwise have been sent in a
normal notify PDU for a given ATT MTU.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 16:50:36 +02:00
Joakim Andersson 1d27450954 Bluetooth: host: Fix conn_handle in LE Advertising Set Terminated evt
Fix use of conn_handle in LE Advertising Set Terminated event not
converting from serial Little Endian to native CPU endianness.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 16:49:28 +02:00
Joakim Andersson 4f7505cb10 Bluetooth: host: Unspecified disconnect reason for no pending conn
Use an unspecified reason when disconnecting a connection that did not
have a pending connection in the host.
We don't allocate connection objects in the connection complete anymore
so using memory-capacity-exceeded is misleading.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 14:39:30 +02:00
Joakim Andersson 52f9c0dd46 Bluetooth: host: Fix resume advertiser race condition
This patch fixes an issue with the advertiser not resuming connectable
advertiser if the last bt_conn_unref happens from something other
than the disconnected callback.
In this case this last bt_conn_unref was from gatt.c notify_cb called
from application main thread.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 11:15:39 +02:00
Joakim Andersson 4be66bd33d Bluetooth: Fix host RX thread deadlock
Fix host RX thread being deadlocked. The deadlock occurs because the
RX thread is stuck waiting in conn_tx_alloc with K_FOREVER but if the
connection is disconnected only the RX thread can unblock it in the
handling of the disconnect event.

This commit fixes this deadlock by splitting the processing of the
disconnected event into two parts.
The part needed to unblock the RX is to release resources held by
unack'ed TX packets and mark the connection state as not connected
anymore.
The RX thread waiting for free_tx fifo and the TX thread waiting for
the bt_dev.le.pkts semaphore will both check the connected state after
having acquired them and will abort if disconnected.
The rest of the processing will be handled at normal RX thread
priority like normal.

Move the bt_recv_prio handling to the Bluetooth host when the host
has defined its own RX thread (CONFIG_BT_RECV_IS_RX_THREAD=n).
If the HCI driver has the RX thread (CONFIG_BT_RECV_IS_RX_THREAD=y),
then the responsibility to call bt_recv and bt_recv_prio correctly
falls to the HCI driver.
The helper function bt_hci_evt_is_prio() is replaced with
bt_hci_evt_get_flags() so that the HCI driver can do this correctly.
This decision to replace was made so that existing HCI drivers
maintained out-of-tree will fail at compile time with the new system.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>

Bluetooth: host: Move bt_recv_prio to host when RX thread is defined

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-07-06 11:15:39 +02:00
ZhongYao Luo ddf5152bb8 Bluetooth: br/edr: store link key
Save link key to settings_subsys, no need to re-pair after restart.
Overwrite old pairing records with aging counts.

Signed-off-by: ZhongYao Luo <LuoZhongYao@gmail.com>
2020-07-02 16:32:41 +03:00
Joakim Andersson 16763ff9b6 Bluetooth: host: Fix adv object not released on directed adv timeout
Fix the advertise object not release when a high-duty cycle directed
advertiser timeout happens. If the extended advertising feature has been
enabled in the host, but not supported by the controller then the
advertising object must be released in the connection complete event
since there will not be a advertising set terminated event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-25 19:34:16 +02:00
Joakim Andersson 1d0b03bb37 Bluetooth: host: Add phy update procedure options
Add options for phy update procedure. User can now set no preference
option for a particular PHY as well as preference for LE Coded PHY
coding scheme.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-06-19 13:42:29 +02:00
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
Carles Cufi 88f25df9ac Bluetooth: smp: Warn on enabling several Bluetooth options
Add warning about enabling the options below so that users are
aware that this is a security risk.

- CONFIG_BT_DEBUG_SMP
- CONFIG_BT_DEBUG_KEYS
- CONFIG_BT_OOB_DATA_FIXED
- CONFIG_BT_USE_DEBUG_KEYS
- CONFIG_BT_STORE_DEBUG_KEYS

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-06-17 17:14:33 +03: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
Jim Luther ffd15131d2 bluetooth: host: fix unpacked l2cap struct
The bt_l2cap_le_conn_rsp struct in l2cap_internal.h has not been
declared __packed. This can cause alignment problems on some
platforms if the struct is placed on an unaligned address.

A __packed declaration solves this issue by forcing the compiler to
use store instructions that do not required alignment.

Signed-off-by: Jim Luther <jilu@oticon.com>
2020-05-29 17:43:32 +02:00
Erwan Gouriou 2716cbcaa6 drivers: susbsys: Check errors on devices selected using dt macro
Some Kconfig defined devices may be defined using dt_chosen_label
function. Since there is no way to ensure a device enabled in dts
is also defined in Kconfig, it may happen that instance is not
actually defined.
In this case device_get_binding might return 0, leading to undefined
behavior in the function that calls it.
When not already done, systematically check return of function
device_get_binding on devices defined through dt_chosen_label macro.
Trigger ASSERT when required and return error when possible.

Fixes #20068

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-05-25 11:43:14 +02:00
François Delawarde 24729bb7c6 bluetooth: host: fix wrong bt/cf settings loading
This commits fixes the loading of bt/cf settings into memory. Only data
was loaded and not the address.

Signed-off-by: François Delawarde <fnde@demant.com>
2020-05-23 22:42:25 +02:00
chao an 32e6347f42 Bluetooth: host: foreach bond only SMP is enabled
build breakage if SMP is disabled

In function `bt_unpair':
bluetooth/host/hci_core.c:2640: undefined reference to `bt_foreach_bond'

Signed-off-by: chao an <anchao@xiaomi.com>
2020-05-20 15:36:10 +02:00
Luiz Augusto von Dentz ef25b864e2 Bluetooth: hci_core: Fix invalid if LE Read PHY
If LE Read PHY fails the code was still trying to parse the buffer as a
valid response.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-15 11:29:41 +03:00
Joakim Andersson a1b8cc2671 Bluetooth: host: Fix extended advertiser address with privacy disabled
Fix extended advertiser not using correct set random address command
to set private (NRPA) address when privacy feature has been disabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-13 21:23:20 +02:00
Joakim Andersson 831ffcd4c2 Bluetooth: host: Fix Service Changed not cleared from flash
Fix Service Changed configuration stored in flash not deleted in flash
when calling bt_gatt_clear from bt_unpair.
When clearing the check for "is bonded" should not be made. If the
bond information is already removed this check will fail.
When clearing the check for "modified" should not be made, clearing
is in itself a modification, and should always be made.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-12 21:00:58 +03:00
Joakim Andersson 6de4294aed Bluetooth: host: Fix CCC cfg not cleared when overwriting oldest bond
Fix CCC cfg not cleared when overwriting oldest bond. Calling
bt_unpair with a pointer to the key will result in the key addr being
memset to zero and bt_gatt_clear is called with an zero-set address.
This happens because unpair (hci_core.c) calls bt_keys_clear before
calling bt_gatt_clear.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-12 21:00:58 +03:00
Peter A. Bigot cca0b79c27 Bluetooth: host: fix warning on unused function
get_phy is referenced by BT_EXT_ADV only when BT_OBSERVER is also
selected.  Avoid defined-but-not-used warnings in that situation.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2020-05-10 11:07:35 +03:00
Carles Cufi b67a31e411 Bluetooth: controller: Remove legacy LL
Remove the legacy Link Layer implementation.

Closes #24187.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-08 15:07:00 +02:00
Joakim Andersson 0ccee9ba60 Bluetooth: host: Read current PHY when using extended advertising
When using extended advertising the connection can be established on
different PHY. In order to have an updated value of the current PHY
we need to read the PHY of the connection in the connection complete
event.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson 6f0b8c1421 Bluetooth: host: Add application control of PHY change procedure
Add application control of initiating phy change procedure and it's
parameters.
The reasons for allowing the application control over the PHY:
 - Allow changing to Coded PHY.
 - Application may change PHY to react to changes in environment
   to balance throughput and range.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson d9e228a4b0 Bluetooth: host: Add application control of data length procedure
Add application control of initiating data length procedure and it's
parameters.
The reasons for allowing the application control over the data length:
 - Bandwidth control adjusted based on number of active connections.
 - Changing data length before switching to coded phy.
 - Applying workarounds for interoperability problems.
 - Controlling order of ATT MTU and data length procedures.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson 69dfcc6fca Bluetooth: host: Add Kconfig option for auto data length procedure
Add Kconfig option so that the application can disable automatic
initiation of the data length procedure. This is symmetric with the
PHY auto initiation kconfig option.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Joakim Andersson f85433c4a9 Bluetooth: host: Refactor setting maximum data length
Refactor setting the maximum data length parameters supported on in
auto data length procedure. This makes setting the data length of the
connection a re-usable function.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-07 20:12:29 +02:00
Luiz Augusto von Dentz 1c35cc18fe Bluetooth: hci_raw: Split TX into ACL and CMD pools
This might reduce the footprint if the supported sizes are different.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-07 10:31:36 +03:00
Luiz Augusto von Dentz f9d1b7ed63 Bluetooth: hci_raw: Fix number of TX buffers
The numbers should have been the sum of HCI commands count and ACL TX
buffers but instead the buffer size was used which makes the pool holds
substatially more buffer than necessary.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-07 10:31:36 +03:00
Joakim Andersson 4592cb64ea Bluetooth: host: Add BT_LE_ADV_OPT_USE_NAME for new advertising API
Implement the BT_LE_ADV_OPT_USE_NAME when using bt_le_ext_adv_* APIs
to start the advertiser.
When starting an extended connectable advertiser the name must be
included in the advertising data, since scan response data is
not allowed in this configuration.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson e9002a4fb4 Bluetooth: host: remove duplicate flags set.
Remove setting state flags in bt_le_adv_start_ext since they are set
by le_ext_adv_param_set, except for BT_ADV_PERSIST flag.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson a2a7cc9fe6 Bluetooth: host: Only persist advertising with bt_le_adv_start API
Only persist advertising when the bt_le_adv_start API is used to start
the advertiser. For multiple advertising set a connectable advertiser
can only be started if there is a connection object available for the
advertiser. Leave the decision on which advertising set should be
advertising up to the application instead of suspending advertising
when no connection object is available.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-06 17:08:49 +03:00
Joakim Andersson fdb3da8aff Bluetooth: host: Rename BT_LE_CONN_OPT to BT_CONN_LE_OPT
Rename connection options to be consistent with the rest of the API
names in conn.h

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-04 17:48:22 +03:00
Joakim Andersson 8b70079ebe Bluetooth: host: Remove BT_LE_CONN_OPT_2M option
Remove the BT_LE_CONN_OPT_2M option and update documentation.
This was a misunderstand about the init PHY HCI parameter.
The init PHY in the extended connection create command does not
determine which PHYs are accepted as the initial PHY of the
connection. This is instead determined by the secondary PHY of the
extended advertiser.
The init PHY parameter only specifies which conn parameters are
provided, and since we only provide one conn parameter this option
has no effect.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-05-04 17:48:22 +03:00
Johan Hedberg e1dddf7bef Bluetooth: Fix NULL pointer dereference when bt_send() fails
The last parameter to hci_cmd_done() is expected to be a valid net_buf
since the function immediately tries to dereference it. Fix this by
passing the appropriate buffer reference to the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2020-05-04 10:59:39 +03:00
Luiz Augusto von Dentz ec5603da8d Bluetooth: L2CAP: Add status flag to track encrypt pending
This adds a new flag to track if the L2CAP channel is pending waiting
for encryption to be changed to resume connecting.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03: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
Luiz Augusto von Dentz d148f8648b Bluetooth: ATT: Add definitions from 5.2
This adds the definitions for Enhanced ATT along with new PDUs and UUIDs
introduced in 5.2.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz 14d6c00b9b Bluetooth: L2CAP: Add released callback
This adds a callback to indicate when the stack has released all
references to a given channel so the owner free up any resources
associated with that.

This is requires since EATT channels cannot rely on the destroy callback
as it does not use a fixed channel like ATT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz 0473b436b5 Bluetooth: L2CAP: Process channel with fixed PSM on RX thread
This leaves only channels on the dynamic range to be offloaded to the
system queue so ATT and EATT handling are handling in the same context.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz f7586b0b04 Bluetooth: L2CAP: Add initial implementation of ECRED mode
This adds the initial implementation of ECRED mode which can connect up
to 5 channels simultaneously and is required by EATT.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz 72d4f06bf0 Bluetooth: L2CAP: Use spaces to align defines
This replaces the use of tabs with spaces to align defines.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-05-02 15:59:14 +03:00
Luiz Augusto von Dentz 95e109bc8e Bluetooth: L2CAP: Add definitions introduced in 5.2
This introduces new Enhanced Credit Based Flow Control PDUs and related
definitions which were introduced in 5.2.

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
Joakim Andersson e9375a2814 Bluetooth: Remove bluetooth thread stack size analysis
Remove logging of individual threads spread out throughout the
bluetooth subsystem. The stacks can be analysed by enabling the
following options.

CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_AUTO=y
CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y
Optional:
CONFIG_THREAD_NAME=y

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-28 09:11:13 -04:00
Joakim Andersson 3230a85590 Bluetooth: host: Include RPAs in enhanced conn complete logging
Include the RPA addresses in the enhanced connection complete debug
log. This makes it easier to debug privacy failures.
Use a new debug statement so that the debug print will work correctly
when log_strdup does not copy the string.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-04-27 19:02:48 +02:00