Commit graph

9523 commits

Author SHA1 Message Date
Emil Gydesen
2c67bafb7b Bluetooth: Audio: Microphone Input Control Service and Client
This commit implements the microphone input  control service
(MICS) and client, The implementation supports and uses the
Audio Input Control Service (AICS) secondary service.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-07 12:04:28 +02:00
Jordan Yates
43b2400688 Bluetooth: gatt: callbacks on ATT MTU update
Adds a new callback structure to `<gatt.h>` for receiving notifications
of ATT MTU updates. This callback is called regardless of whether the
MTU update was initiated locally or remotely.

Fixes #32035.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-06-07 12:03:09 +02:00
Vinayak Kariappa Chettimada
adae515d8d Bluetooth: controller: Fix conn setup regression
Fix incorrect and redundant use of ticker user id ULL_LOW
instead of ULL_HIGH when setting up a connection using a
mayfly to disable LLL context. Also, the LLL context pointer
is invalid, where node rx is passed instead of LLL context.

Use the ULL disabled callback when done event has not yet
been processed, or a direct connection setup in ULL_HIGH
context when ULL is already disabled (reference count is
zero) is sufficient.

Regression introduced in commit 30f260dfaa ("Bluetooth:
controller: Fix adv/scan context access post release").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-04 12:13:34 -05:00
Joakim Andersson
95e359d658 Bluetooth: controller: Check length field of scan response data
Check the length field of the scan response data.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-04 12:51:27 +02:00
Joakim Andersson
4dd49ac746 Bluetooth: host: Fix CCC store on write for multiple connections
Fix CCC store on write feature for multiple connections. CCCs are only
enqueued for storing when going from no connections subscribed to any
connection subscribed.
The CCC should be stored when its value is changed for the specific
connection.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-03 11:36:22 +02:00
Vinayak Kariappa Chettimada
12ba459c92 Bluetooth: controller: Minor improvements to ext header population
Minor refactor and improvement to common extended header
population.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Vinayak Kariappa Chettimada
0de4c30b0f Bluetooth: controller: Fix incorrect prev aux header flag access
Fix Extended Advertising PDU population from incorrectly
populating new PDU when there is no common extended header
flags being set in the previous PDU and or the new PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Vinayak Kariappa Chettimada
cabcae2413 Bluetooth: controller: Fix incorrect prev periodic header flag access
Fix Periodic Advertising PDU population from incorrectly
populating new PDU when there is no common extended header
flags being set in the previous PDU and or the new PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Vinayak Kariappa Chettimada
c877385adb Bluetooth: controller: Fix incorrect ext header flag access
Fix Periodic Advertising data population from corrupting
the PDU by populating fields when there is no flags in the
common extended advertising header.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-01 16:50:41 +02:00
Emil Gydesen
fe1de126fe Bluetooth: Host: Add status check BIG sync/create events
Add a status check for the BIG sync established and
BIG sync created events such that we don't log a warning
of invalid BIS count when it is an error event.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-01 07:31:51 -05:00
Emil Gydesen
4bc5a02d51 Bluetooth: ISO: Fix BIG cleanup
Fix a regression for cleaning up BIGs added by
80c824f18ee80caa5bd162b9d2957dde1639add6 where the way
ISO connections were unref'ed was changed.

bt_iso_cleanup has been changed to only effect CIS
(as the unref from that has been removed), so instead
of calling bt_iso_cleanup we just call
bt_conn_unref directly.

This also removes some unref's from the BIG complete
and BIG Sync complete event handlers as the BIS bt_conns as
they don't increase the ref counter before anymore.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-01 14:03:48 +02:00
Krzysztof Kopyściński
9c4dba12aa Bluetooth: Host: change error returned when ecred_conn_req
BT_L2CAP_LE_ERR_INVALID_PARAMS shall be returned instead of
BT_L2CAP_LE_ERR_UNACCEPT_PARAMS.

This was affecting test case L2CAP/ECFC/BV-26-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-01 14:03:28 +02:00
Krzysztof Kopyściński
975ed76d78 Bluetooth: Host: do not overwrite result in le_ecred_conn_req
For more than one requested channels in le_ecred_conn_req only result is
overwritten in every iteration. This causes an issues if after failed
l2cap_chan_accept occures successful one: returned result will be
BT_L2CAP_LE_SUCCESS, where in reality should be returned error
and non-zero Destination CIDs will signal "Some connections refused".
Now, overwrite error only if the last one failed. If no errors occur,
result will remain BT_L2CAP_LE_SUCCESS.

This was affecting test cases L2CAP/ECFC/BV-20-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-01 14:03:28 +02:00
Krzysztof Kopyściński
3e66dd2054 Bluetooth: Host: add missing zero CIDs in ecred_conn_req
Fix missing 0x0000 CIDs in response for ecred_conn_req. Previously,
when one of "All connections refused" error i variable was set to 0,
thus no CIDs were copied to response.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-06-01 14:03:28 +02:00
Piotr Pryga
1d0de7afc1 Bluetooth: host: Check sync_handle return value when CTE sampl enable
Check correctness of returned sync_handle value while requesting
HCI_LE_Set_Connectionless_IQ_Sampling_Enable in controller.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-31 17:44:29 +02:00
Piotr Pryga
725ceb69b3 Bluetooth: controller: hci: Set correct return params for CTE sampl enable
Fix bug of missing sync_handle parameter in return data in
HCI_LE_Set_Connectionless_IQ_Sampling_Enable commnad
handling function.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2021-05-31 17:44:29 +02:00
Joakim Andersson
b9a586821e Bluetooth: host: Log failure to initiatie security for bonded peer
Log failure to initiatet security for bonded peer when GATT wants to
initiate security for CCCs for the remote.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-31 17:40:36 +02:00
Joakim Andersson
8d53def576 Bluetooth: host: Reject remote public key on same X coordinate.
Reject remote public key when this has the same X coordinate.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-31 17:40:27 +02:00
Joakim Andersson
f5f8eb7263 Bluetooth: host: Notify application about prepare write error
Notify application about prepare write error when continueing the write
procedure fails when RX thread is processing responses. It is possible
that this operation fails, either because of disconnection or ATT
timeout on the ATT bearer. Notify the application in case it needs to
clear up resources, e.g. the write parameters.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-31 17:39:27 +02:00
Krzysztof Kopyściński
a527409011 Bluetooth: host:l2cap: fix sending error in le_ecred_reconf_req
Result to send was overwritten by BT_L2CAP_RECONF_SUCCESS just after
exiting while loop. This caused to send success response even if
reconfiguration failed. Now, result is initialized to success value,
and if reconfiguration fails, this value will be overwritten with
appropriate one. Added BT_L2CAP_RECONF_INVALID_CID (0x0003) for invalid
cid in request. Added BT_L2CAP_RECONF_OTHER_UNACCEPT (0x0004) to return
if MPS is to small. Reordered checks for mps/mtu as
BT_L2CAP_RECONF_OTHER_UNACCEPT is expected to be returned if both mps
and mtu are to small.

This was affecting L2CAP/ECFC/BI-05-C and L2CAP/ECFC/BI-05-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-05-28 10:50:42 -05:00
Luiz Augusto von Dentz
066a7c2de5 Bluetooth: conn: Align cleanup for ISO connections
This makes connections of type BT_CONN_TYPE_ISO use BT_CONN_CLEANUP to
cleanup so the TX and RX queues are properly cleanup.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
2a99d80403 Bluetooth: shell: Add connection type information to connections command
This prints information about the role and id along with connection
parameters in case the connection is of LE type.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
fc9b7e62f0 Bluetooth: conn: Add support for ISO connections to bt_conn_get_info
This enables bt_conn_get_info to be used with connection of type
BT_CONN_TYPE_ISO.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
8b6d3c6c4d Bluetooth: ISO: Fix call order of connected callback
The state shall be set before calling the callback as it could be check
code behind would expect the channel to be in connected state.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
76ad664d4e Bluetooth: ISO: Fix not assigning CIG and CIS IDs
When handling CIS Requested event CIG and CIS IDs must be set in order
for the channel to be properly accepted.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Luiz Augusto von Dentz
21404c4bd0 Bluetooth: ISO: Simplify reference handling
This makes bt_conn_cleanup to be automatically called when the last
reference to a connection of BT_CONN_TYPE_ISO is dropped.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2021-05-28 15:34:20 +03:00
Casper Bonde
3af1f4bac5 Bluetooth: ISO: Make it possible to setup unidirectional CIS
The current iso commands in the shell only supports setting up
a bidirectional stream or unidirectional for central role.
Adding rx/tx/rxtx option to iso listen command to allow for
peripheral side configuration of an iso connection.

Signed-off-by: Casper Bonde <casper_bonde@bose.com>
2021-05-27 13:16:40 +02:00
Casper Bonde
04dfcba792 Bluetooth: ISO: Add sequence number to ISO data packets
The sequence number is needed in the appliaction layer to detect lost
packets in the ISO stream in cases where the timestamp is not included.
(Sequence number is mandatory to include where timestamp is optional).
The API for the public metadata have been moved to a public header file.

As the size of the ISO meta data exceeds the default 4 octets net_buf
user_data the public ISO metadata have been moved into a seperate array.
The internal metadata is still stored in net_buf user_data.

This also fixed the user_data overflow on 32 bit systems, caused by
writing the ts into user_data on index 4 to 7, which is outside the 4
allocated bytes.

Signed-off-by: Casper Bonde <casper_bonde@bose.com>
2021-05-27 13:16:40 +02:00
Joakim Andersson
b6c95edc63 Bluetooth: host: Fix extended advertising feature bit check
Fix CONFIG_BT_EXT_ADV_LEGACY_SUPPORT option which optimizes the host
to skip checking the feature bit of the controller to check for
extended advertising commands.
This was broken because of how this was implented using an undef of the
feature bit, which was not replicated in scan.c, adv.c and id.c once
this was split out from hci_core.

Instead of doing this wierd way of redefining the feature check macro
do it in a proper way by defining a new macro.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-26 16:35:15 +02:00
Joakim Andersson
8a32c2d967 Bluetooth: host: Fix disconnect priority event handling
Fix issue is host handling of connected and disconnected event.
Since the host wants the disconnected event to be processed as a
priority event as well as in reguler event context while the connected
event is always in reguler event context we can end up in a situation
where the disconnected priority event is processed before the connected
event.

Since the disconnected priority event is there to release unack'ed TX
pending on the connection in case the RX thread is blocked waiting
for TX resources, we need to keep this behavior. Otherwise this would
be a potential deadlock of the RX thread waiting for resources that can
only be released by the RX thread.
When this situation happens we know that there cannot be any pending TX
on this connection so we can safely skip releasing of unack'ed TX.

The second thing the disconnected priority event does is marking the TX
path on the connection as disconnected. We need to do the same in this
situation, so we make sure that the TX path is already marked
disconnected when providing the connected callback to the application.

This fixes a regression from 4be66bd33d.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 20:30:48 +03:00
Joakim Andersson
c99b7ba71c Bluetooth: host: Fix L2CAP sent callback on disconnected channel
When receiving the L2CAP sent callbacks the dynamic L2CAP channel may
have been disconnected already. The user of the dynamic channel should
have received the disconnected and released callbacks for this channel
to release any resources for the data being sent, so simply ignoring
this sent callback is enough.

Fix sent callbacks by providing the CID to the callback instead of a
pointer to potentially released memory, and lookup the CID to check that
it is still valid.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 19:26:32 +02:00
Joakim Andersson
c429ffb0ed Bluetooth: host: Add check for already enabled in advertising set start
Add check for the advertising already being enabled when attempting to
start the advertising set.
Document that the advertising set cannot be started from the connection
connected callback, and instead has to be started from the advertising
set connected callback.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 19:26:23 +02:00
Joakim Andersson
3318bd3491 Bluetooth: host: Fix multiple advertisers with different ID support
Fix multiple advertisers with different ID support, this was added
in 98321c61fb but the guard was never
removed.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-25 19:25:05 +02:00
Vinayak Kariappa Chettimada
79f6a63840 Bluetooth: controller: Fix initial empty flag for peripheral
Fix to avoid an assertion when processing an acknowledgment
in the first connection event in peripheral role.

Ensure that empty flag reflects the state of the Tx queue,
as a peripheral the first connection event has no prior PDU
transmitted, an incorrect acknowledgment by peer should
not dequeue a PDU that has not been transmitted on air.

Relates to assert added in commit 2bfaadffb8 ("Bluetooth:
controller: Add Tx fragmentation assertion").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-25 19:24:55 +02:00
Joakim Andersson
7986cae05c Bluetooth: host: Remove cancel sync from database hash commit
Fix deadlock when db_hash_commit has to wait for the delayed work to
finish. This creates a deadlock if the delayed work for database hash
calculation needs to store the hash since the settings API is locked
when calling the commit callback.
Remove call to k_work_cancel_delayable_sync from db_hash_commit in order
to avoid the deadlock. Instead move comparing of the stored hash to the
delayed work and reschedule the work with no wait.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-05-24 23:29:52 -04:00
Carles Cufi
0e26836c8a Bluetooth: controller: Add conn creation param checks
Coverity detected that a zero divisor can be passed to
ll_create_connection() without parameter sanitization. Conditionally
check the connection creation parameters according to spec.

Fixes #35343.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-05-21 18:50:22 +02:00
Krzysztof Kopyściński
58460f9273 Bluetooth: gatt: cancel all prepared writes on invalid write response
On sending write request we should check write response.
If data prepaired to be written by peer or offset are not equal
to the data and offset we sent, we shall send Execute Write
Request with Request Flag set to 0x00 (Cancel All Prepared Writes).

This was affecting GATT/CL/GAW/BI-32-C and GATT/CL/GAW/BI-37-C

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2021-05-21 18:50:26 +03:00
Erik Brockhoff
6ce0f2ee66 Bluetooth: controller: add apto/appto reset for peripheral
For peripheral the apto/appto_expire are now reset on adv start

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2021-05-21 15:17:20 +02:00
Vinayak Kariappa Chettimada
d999d5eb64 Bluetooth: controller: Fix missing HCI event data len limit check
Fix the missing HCI event data len limit check when encoding
incomplete advertising data report.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-21 13:39:22 +02:00
Andrzej Kaczmarek
9835888a91 Bluetooth: controller: Fix data length calculation in adv report
Max data length has to be adjusted for subevent code, otherwise we'll
hit an assert when trying to add data to event due to insufficient
free space.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-05-21 13:39:22 +02:00
Asger Munk Nielsen
38850b4820 Bluetooth: Controller: fix uninitialized variable
Fixes issue #35157
[Coverity CID: 221380]

Signed-off-by: Asger Munk Nielsen <asmk@oticon.com>
2021-05-20 21:27:40 -04:00
Vinayak Kariappa Chettimada
858dc7fab4 Bluetooth: controller: Fix EVENT_OVERHEAD_START_US jitter
As EVENT_OVERHEAD_START_US offset is used in ticks unit in
LLL, ULL scheduling using ticker should also use ticks unit
for EVENT_OVERHEAD_START_US when reducing the first
connection event preparation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-20 15:33:55 +02:00
Vinayak Kariappa Chettimada
8cfbaf5d55 Bluetooth: controller: Revert strict preempt ticker start failure check
Revert the strict preempt ticker start failure check.
Preempt ticker start can fail when enqueuing prepares into
already filled pipeline which has preempt ticker already
started for the first prepare that was added in the
pipeline.

Regression introduced in commit 5b75bdf589 ("Bluetooth:
controller: nRF5: Check preempt event on timeout").

Fixes #35476.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-20 15:33:32 +02:00
Emil Gydesen
01c4d597b3 Bluetooth: Host: Avoid memcpy'ing bt_addr_t to same pointer
From le_ext_adv_param_set we will occasionally attempt
to call bt_addr_copy where the `addr` and &adv->random_addr.a
are the same pointer. Doing a memcpy where source and destination
is the same pointer is undefined behavior and should not be
done.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 13:22:21 +02:00
Emil Gydesen
7d3def3275 Bluetooth: Audio: Fix VCS client shell missing compile
The VCS client shell was never compiled before, and thus
the implementation had a few undetected errors.

This commit adds the VCS client to the shell CMakelists
as well as fixing the issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 13:19:17 +02:00
Emil Gydesen
71c7566b96 Bluetooth: Audio: Move NULL check for conn in bt_vcs_discover
Move the check for the connection pointer before we get the
index.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 13:02:56 +02:00
Emil Gydesen
03a2c291c0 Bluetooth: Audio: Fix dead code issue in VCS
The common API functions in VCS had dead code in specific
configurations, causing coverity issues. Fixed by this
commit.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-05-20 12:00:57 +02:00
Vinayak Kariappa Chettimada
c0a8f38ec6 Bluetooth: controller: Avoid deferencing null return value
Add assert check to avoid deferencing null return value by
ull_adv_set_get() function.

Fixes #35347.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-19 17:10:08 -04:00
Vinayak Kariappa Chettimada
7d1a959d01 Bluetooth: controller: Explicitly ignore return value
Explicitly ignore return value from call to mayfly_enqueue.

Fixes #32917, #32961.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-19 17:10:08 -04:00
Vinayak Kariappa Chettimada
a92f7c6138 Bluetooth: controller: Fix side effect in assertion
Fix side effect in assertion when checking a volatile
variable inside assert check.

Fixes #32904, #32923.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-05-19 17:10:08 -04:00