Commit graph

8508 commits

Author SHA1 Message Date
Silviu Petria
5096aa1c00 Bluetooth: Audio: Add TMAS and two TMAP samples
Add implementation of the Telephony and Media Audio Service, as well as
two sample applications.

tmap_central reflects a smartphone implementing the Unicast Media Sender
and Call Gateway TMAP roles.

tmap_peripheral reflects an earbud implementing the Unicast Media
Receiver and Call Terminal TMAP roles.

Upon connection, tmap_central starts an audio stream using CAP Initiator
APIs.

CCP, MCP and VCP are discovered and used to send example commands.

Future improvements: 2-earbud support, add TMAP Broadcast roles,
update with new CAP Acceptor/Commander APIs as they become available

Signed-off-by: Silviu Petria <silviu.petria@nxp.com>
2023-05-24 16:39:38 +02:00
Pavel Vasilyev
e51a909343 Bluetooth: Mesh: Shell: fix vnd model pub command
The command at most takes 11 args. argc = num of args + 1 (command
name) => 12. We substruct 3 from argc (cmd name, mod id, addr). This
gives argc = 9 when all args are provided for vendor model.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-05-23 13:03:18 +02:00
Andries Kruithof
253818ebea Bluetooth: controller: move bn scope from filescope to lll-scope
The scope for the burst number for tx and rx is currently at module
level in both lll_central_iso.c and lll_peripheral_iso.c
 This PR puts the scope to the lll level

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-05-23 12:56:07 +02:00
Jonathan Rico
202d2ed005 Bluetooth: host: clarify the behavior of BT_PRIVACY
This makes it explicit that enabling `BT_PRIVACY` will make the device
_use_ private addresses.

The device can still resolve RPAs when `BT_PRIVACY=n`.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-05-22 15:26:55 +02:00
Krzysztof Kopyściński
61cf1bb9e4 Bluetooth: Mesh: fix SRPL clearing
If len=0 then `primary` address should be cleared.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-05-22 15:26:17 +02:00
Krzysztof Kopyściński
38c925308b Bluetooth: Mesh: fix Proxy Solicitation build without CONFIG_BT_SETTINGS
`bt_mesh_settings_store_schedule` should be called only when
CONFIG_BT_SETTINGS is enabled.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-05-22 15:26:07 +02:00
Emil Gydesen
d770e2af13 Bluetooth: Audio: Remove BT_CODEC_MAX_DATA_LEN > 0 checks
The minimal value of BT_CODEC_MAX_DATA_LEN is 1, so it
is always > 0.

Includes to audio.h in shell bt.c was removed as audio.h
should only be included if BT_AUDIO=y.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:25:54 +02:00
Emil Gydesen
71af6c0c6b Bluetooth: Audio: Remove CONFIG_BT_CODEC_MAX_METADATA_LEN
The Kconfig option was not used anywhere besides some checks
that should have checked against CONFIG_BT_CODEC_MAX_DATA_LEN
instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:25:54 +02:00
Emil Gydesen
37aad05883 Bluetooth: BAP: Shell: Remove superfluous call to discover_cb
The call to discover_cb did not add any value as we already
print the error.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
3074c72d79 Bluetooth: BAP: Move endpoint discovery to new callback
Add a new endpoint callback that is used to report the found
ASEs during BAP discovery, rather than calling
the discovery callback with optional values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
1c304d9d23 Bluetooth: BAP: Move pac record discovery to new callback
Add a new pac_record callback that is used to report the found
PAC records during BAP discovery, rather than calling
the discovery callback with optional values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
5d498d78ad Bluetooth: BAP: Remove bt_bap_unicast_client_discover_params
Remove the BAP unicast client specific discover parameter struct.
This make the BAP discover work more similar to the other
profiles.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
ffca5f9b2f Bluetooth: BAP: Remove dir from BAP discovery parameters
The direction has been moved to a function parameter instead,
and we keep a local copy of the value in the stack instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
1199e46e0b Bluetooth: BAP: Remove num_eps from BAP discover params
The field is not required and is no longer used.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
0b10498fb1 Bluetooth: BAP: Remove num_caps from BAP discover params
The field is not needed and no longer used.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
11f5f3b080 Bluetooth: BAP: Move uni cli discov err to callback
Move the err field from the discover parameters to
the callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Emil Gydesen
39406a4843 Bluetooth: BAP: Move uni cli discover callback
Move the unicast client discover callback from the
parameters to the callback structure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-22 15:24:28 +02:00
Vinayak Kariappa Chettimada
b726b5e62a Bluetooth: Controller: Fix BT_CTLR_SW_SWITCH_SINGLE_TIMER feature
Fix BT_CTLR_SW_SWITCH_SINGLE_TIMER to correctly disable the
PPI group used to switch radio Tx/Rx. The issue was
uncovered when adding coverage in BabbleSim test.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-22 12:02:02 +02:00
Vinayak Kariappa Chettimada
9eb931836b Bluetooth: Controller: Prepare to replace HAL_RADIO_ENABLE_ON_TICK_PPI
Prepare to replace HAL_RADIO_ENABLE_ON_TICK_PPI with
independent use of HAL_RADIO_ENABLE_TX_ON_TICK_PPI and
HAL_RADIO_ENABLE_RX_ON_TICK_PPI.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-22 12:02:02 +02:00
Vinayak Kariappa Chettimada
f8f01a07ff Bluetooth: Controller: Use NRF_RADIO_TXRX_END_EVENT
Use NRF_RADIO_TXRX_END_EVENT instead of EVENTS_END in the
Controller HAL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-22 12:02:02 +02:00
Gerard Marull-Paretas
dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Mariusz Skamra
f5d4e9e0db Bluetooth: audio: ascs: Fix conn object being unreferenced prematurely
This fixes invalid conn unref that happens in ACL disconnected callback
context. When the ACL disconnects, the implementation waits for CIS to
be disconnected if connected. If the client won't disconnect the
CIS, the implementation initiates the disconnection by itself, from
delayed work context. Thus the ACL conn object has to be remained at
that time because it indicates whether the ASE object is in use or not.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-05-22 10:16:02 +02:00
Mariusz Skamra
3aea893ca5 Bluetooth: audio: ascs: Fix repeated ops->released callback call
Once the ACL disconnects, the implementation releases the related
endpoints. The ops->released callback is called once ASE enters IDLE
state, thus there is no need to call it explicitly.
This fixes repeated ops->released callback call.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-05-22 10:16:02 +02:00
Mariusz Skamra
8c3568f213 Bluetooth: audio: mcs: Fix endianess issues
This fixes missing endianess conversions in mcs.c.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-05-19 19:53:02 +00:00
Mateusz Kapala
15bd8b256f bluetooth: host: Fix NULL pointer dereference in bt_conn_auth_cb_overlay
There is a check in bt_conn_auth_cb_overlay function which validates
if content of the callback structure is correct, but there is no
NULL-check on the structure pointer itself, which could result in
NULL pointer dereference.

It should be possible to set the callback structure pointer to `NULL`
using bt_conn_auth_cb_overlay function if the application requires
ex. Just Works pairing for one Bluetooth identity and global
callbacks are configured for advanced pairing scheme (like Passkey
Display) for other Bluetooth identity.

Signed-off-by: Mateusz Kapala <mateusz.kapala@nordicsemi.no>
2023-05-19 09:40:21 +02:00
Mariusz Skamra
84fd596062 Bluetooth: audio: mcs: Offload notifications to system work queue
This implements the deferring of characteristic value notifications to
be sent from system work queue thread context. Notifications issued from
Bluetooth Rx thread might not be sent if there are no L2CAP Tx buffers
available, as the operation is non-blocking to prevent deadlock while
waiting for free buffers.
The same operation issued from other thread context is blocking,
meaning that the thread waits until L2CAP Tx buffers become available.
Thus it's guaranteed the notifications will be sent.

With this patch, the control point operations become blocking until the
control point response is sent. Meaning there might be only one
pending operation waiting for completition. This might be further
improved by queuing the operations if needed.

Fixes: #57444
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-05-18 13:35:57 +00:00
Mariusz Skamra
94853e310a Bluetooth: audio: mcs: Fix unused functions warning
This guards functions called only if CONFIG_BT_OTS is enabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-05-18 13:35:57 +00:00
Fredrik Danebjer
f3fdb1f96f Bluetooth: Audio: Make VCS optional notify characteristics optional
This change makes VCS Volume Flag characteristic Notify property
optional and selectable through Kconfig.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
2023-05-17 19:26:54 +02:00
Vinayak Kariappa Chettimada
9ff23ed029 Bluetooth: Controller: Fix Central CIS SN/NESN for skipped events
Fix Central CIS SN and NESN for skipped events during CIS
setup. It is possible that CIG event may overlap the ACL or
other events at the CIS create instant, and hence have non
zero lazy value during the CIS setup events until CIS is
established.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-16 13:20:15 +02:00
Vinayak Kariappa Chettimada
3b3d53f09e Bluetooth: Controller: Fix CIS offset_min for dissimilar interval
Fix CIS offset_min calculation to consider that ACL interval
and ISO interval can be dissimilar and the offset value has
to be compensated for the latency until the instant at which
the offset is used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-16 13:20:15 +02:00
Vinayak Kariappa Chettimada
22e67eac6e Bluetooth: Controller: Fix sn on Peripheral CIS event abort
Fix SN value on Peripheral CIS event abort. Adjust the SN
value based on the burst number such that the ISO data where
transmitted as normal.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-16 13:20:15 +02:00
Andrei Emeltchenko
2c0fcdf22b bluetooth: shell: Add missing return
Avoid invalid bit shift by adding return.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-05-16 12:08:06 +02:00
Emil Gydesen
c66f210f6b Bluetooth: BAP: Broadcast source fix idle state
The idle state was never set, thus providing a poorly
implemented state machine. Updated the code so that unused
code was removed and so that the idle state is properly set.

Optimized the way that a state is set for all endpoints
for a broadcast source with a new function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-15 15:26:14 +02:00
Vinayak Kariappa Chettimada
354226022e Bluetooth: Controller: Fix peer ISO feature support check
Fix peer ISO feature support check, by using feature support
bit instead of whether locally supported bit value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-15 13:38:38 +02:00
Vinayak Kariappa Chettimada
0249006813 Bluetooth: Controller: Use swapped role specific features bit
Use swapped role specific features bit to calculate features
usable by local device, on feature exchange procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-15 13:38:38 +02:00
Vinayak Kariappa Chettimada
fe53891788 Bluetooth: Controller: Fix Central ISO establish assertion failure
Fix Central ISO assetion failure on being established due to
regression in commit a53d89450a ("Bluetooth: controller:
fixing CIS establish flow for refactored LLCP") that
required changes due to Create CIS LLCP being refactored.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-15 13:38:38 +02:00
Herman Berget
93f36d4bff Bluetooth: Host: Fix double conversion of phy
The phy was converted both when reading from the event
and when reading from the sync, leading to incorrect
value in the synced callback.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-05-15 13:10:29 +02:00
Emil Gydesen
6862884f87 Bluetooth: BAP: Broadcast sink fix interval to timeout calc
The calculation in interval_to_sync_timeout did not take into
account that the periodic advertising sync interval was in units
of 1.25ms, and not ms.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-15 10:53:54 +00:00
Gerard Marull-Paretas
a8b36ffb4d bluetooth: mesh: use STRUCT_SECTION_ITERABLE_ARRAY
STRUCT_SECTION_ITERABLE cannot be used with arrays, because of
preprocessor tokenization issues.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-15 18:52:07 +09:00
Emil Gydesen
07f32b732a Bluetooth: ASCS: Add support for long writes
Add support for long writes to the control point
to handle e.g. metadata that's larger than the MTU.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
8c4908b3f2 Bluetooth: ASCS: Add support for long read
Increase the size of the ase_buf to support
the maximum size of the Codec Configuration
and Metadata.

The ase_buf is not also guarded by a semaphore, so no
more than one thread will use it at any time. This is
needed as ase_status_changed can be called from multiple
threads.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
572055e205 Bluetooth: Audio: Add long read support to BAP unicast client
Add support for long read by adding a read_buf and store
the data when long data is being read.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
892819ede8 Bluetooth: Audio: ASCS ASE discover by UUID added
Instead of using the read by UUID, we do a "proper"
discover by UUID. The reason for this is that read by
UUID is not mandatory in the BAP specs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
be781b2a56 Bluetooth: Audio: PACS context discover by UUID added
Instead of using the read by UUID, we do a "proper"
discover by UUID. The reason for this is that read by
UUID is not mandatory in the BAP specs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
ec1b2a1844 Bluetooth: Audio: PAC discover by UUID added
Instead of using the read by UUID, we do a "proper"
discover by UUID. The reason for this is that read by
UUID is not mandatory in the BAP specs, and that we need
to do a long read on the PAC records anyhow, and that
cannot be done with the read by type/UUID.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
ba19bf3d96 Bluetooth: Audio: Add unicast_client struct
Add a new struct unicast_client to hold all the conn-specific
data for the Unicast Client implementation.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
3ff3d8db2c Bluetooth: PACS: Set PACS read_buf size to BT_ATT_MAX_ATTRIBUTE_LEN
The maximum size of the characteristic is BT_ATT_MAX_ATTRIBUTE_LEN.
The previous size limited the size of the characteristic to
the maximum possible MTU, thus not utlizing support for the
Read Long procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
3d4622b4d4 Bluetooth: PACS: Fix bad __ASSERT condition
__ASSERT(true will never be triggered.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
5a28d80893 Bluetooth: PACS: Removed unused conn arg from get_pac_records
The `conn` argument was not used.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Emil Gydesen
98adaf0811 Bluetooth: PACS: Add read_buf_sem
Add a semaphore to guard the read buf. The reason for this
is that the read buf is populated from either the BT RX
thread, or the workqueue thread. The semaphore ensures
that both threads will never have attempted to
add any data to the buffer at the same time.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-12 15:29:17 +02:00
Erik Brockhoff
5ca6724664 Bluetooth: controller: adding release of rx/tx nodes retained in LLCP
On connection clean-up release nodes held by LLCP. These are released
in two steps, first on LLCP terminate (in local/remote) by moving
to rx/tx_node_release chains, and then on conn_cleanup_finalize
nodes are released back to appropriate mem-pool/queue.
Rename abort functions to refer to terminate.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-12 12:53:16 +02:00
Erik Brockhoff
eece00e4b0 Bluetooth: controller: updating TX node pre-alloc store mechanism
Instead of using the node ref used for TX ack for storing a TX node
pre-allocated in case of NTF RX node availability delay, introduce a
separate store to TX node. This to avoid misunderstanding on clean-up
in terminate flow.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-12 12:53:16 +02:00
Erik Brockhoff
a53d89450a Bluetooth: controller: fixing CIS establish flow for refactored LLCP
Latest modification to LLCP removed 'monitoring' of cis->established
flag in LLCP, relying instead on signal through ULL.

For this to work properly the signal must also be generated, so this is
introduced. Note - checking of cis->established flag could be removed
if caller ensures only calling once (on establish condition)

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-12 12:53:16 +02:00
Erik Brockhoff
998512f59b Bluetooth: controller: use RX node piggy-back for NTF when possible
When possible re-use the already allocated RX node for notifications.
Store (retain) RX node and Link element on RX if NTF could occur.
Pass link element to LLCP (ull_cp_rx()) together with RX node.
New RX node type RETAIN introduced to signal retention

When no RX node is available allocate one and hold off TX on procedures
until such time that a node is available for NTF.

In case waiting for NTF buffer avail is needed, allocate and store TX
node to use for TX once NTF becomes available.

CIS Established (incl. timeout handling) is now handled entirely as a
specific event driven by ull_conn_iso - ie removal of procedure check
of cis->established and cis->expire, as this is doubling mechanism
in the conn_iso context.

Unit test and helpers updated to handle new node type.
Function ull_cp_release_ntf() was used only in unit test, so moved to
helper context.
Updating release_ntf to handle the fact that with piggy-backing in test
context the node used for NTF can be from two different memory pools

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-12 12:53:16 +02:00
Mariusz Skamra
12d8a0d178 Bluetooth: id: Keep RPA as bt_addr_t
There is no need to store the RPA in bt_addr_le_t structure, as the
bt_addr_le_t.type is unused anyway. Both bt_rpa_create and
bt_id_set_adv_random_addr take bt_addr_t as parameter.
Saves 1 byte of address type.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-05-12 10:55:50 +03:00
Mariusz Skamra
88c20b9cdd Bluetooth: id: Fix uninitialized RPA
This fixes uninitialized RPA value for BT_ID_DEFAULT.
The regression has been introduced in
8d6b206064.
As the result, the private address was not created and the advertising
was started with 00:00:00:00:00:00 address.
In case of the other advertising ID's, those are initialized
from id_create context.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-05-12 10:55:50 +03:00
Balaji Srinivasan
491628ae06 Bluetooth: host: Fix dangling reference in service changed
The bt_gatt_indicate() expects its parameters to remain valid while the
indicate procedure is active. But the `sc_range` variable was local to
the function. It is assigned to the `data` field and passed on to
bt_gatt_indicate(). The memory associated with `sc_range` goes out of
scope as soon as the function returns thereby breaking the contract of
the API. This dangling reference will lead to undefined behavior.
This is now fixed by making the `sc_range` array static and further
making it an array of arrays, as the sc_range may have different values
for each connection.

Found as violation of MISRA C:2012 and CERT DCL30-C by sonarcloud.

Signed-off-by: Balaji Srinivasan <balaji.srinivasan@nordicsemi.no>
2023-05-12 09:55:53 +03:00
Erik Brockhoff
b49ce8febe Bluetooth: controller: fixup HCI LE Create CIS 'parameter' checks
BT Core Spec states that feature exchange should be initiated if
not already performed. So in this case initiate feature exchange
and 'abort' enqueued CIS create if peer doesn't support CIS peripheral
feature

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-12 08:43:46 +02:00
Erik Brockhoff
105621bdce Bluetooth: controller: Only generate ntf on host initiated feature exch
Only generate notification when feature exchange was initiated by host

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-12 08:43:46 +02:00
Erik Brockhoff
c1b5aaecf8 Bluetooth: controller: confirm central role on CIS Create
Confirm that the 'requesting connection' is acting as central

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-12 08:43:46 +02:00
Andrei Emeltchenko
a4341bbc2c bluetooth: audio: Fix logical check
I imagine that expression (req != 0 || req != 1) is always true. Fix
it changing '||' to '&&'.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-05-11 13:29:46 +02:00
Vinayak Kariappa Chettimada
7eaf577772 Bluetooth: Controller: Fix Peripheral CIS supervision timeout
Fix premature Peripheral CIS supervision timeout due to
corrupted trx_performed_bitmask value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-11 12:03:41 +02:00
Vinayak Kariappa Chettimada
875349047e Bluetooth: Controller: Fix Peripheral CIS receive window size
Fix peripheral CIS receive window to consider that the
peripheral ACL could drift at the instant the CIS is being
established.

Hence add additional EVENT_TICKER_RES_MARGIN_US as receive
window length.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-11 12:03:41 +02:00
Vinayak Kariappa Chettimada
9338ecc5b8 Bluetooth: Controller: Fix Central CIS scheduling precision
Fix Central CIS offset scheduling to microsecond resolution
precision. CIS offset calculation was missing the ACL event
remainder value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-11 12:03:41 +02:00
Nithin Ramesh Myliattil
8d6b206064 subsys/bluetooth/host: Make rpa same for adv sets with same id
Add check to see if RPA is already generated for adv sets
with same id. If generated use the same address for all adv sets
with same id else create new RPA.

Signed-off-by: Nithin Ramesh Myliattil <niym@demant.com>
2023-05-11 08:31:24 +00:00
Emil Gydesen
563b66bc29 Bluetooth: BAP: Shell: Broadcast assistant compiler warning fixes
Fixes a few compiler warnings from the BAP Broadcast Assistant
shell modules.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-11 10:15:10 +02:00
Vinayak Kariappa Chettimada
a2a2b86665 Bluetooth: Controller: Fix uninitialized CIG num_bis member variable
Fix uninitialized CIG num_bis member variable on CIG Remove.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-11 10:05:55 +02:00
Emil Gydesen
117f6295d1 Bluetooth: BAP: Broadcast source validate subgroup count in create
Add proper validation check for the number of subgroups
attempted to be added to the broadcast source.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-11 10:05:41 +02:00
Emil Gydesen
afd4161a84 Bluetooth: BAP: Broadcast start add missing NULL check for adv
Added missing NULL check for the advertising set pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 17:54:12 +02:00
Emil Gydesen
926219156b Bluetooth: Audio: Shell: Add preset copy functions
Add common preset copy functions for unicast streams and
broadcast sources.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 15:27:46 +02:00
Emil Gydesen
4d43101fa7 Bluetooth: Audio: Shell: Make broadcast source generic
Implement profile-agnostic broadcast source and broadcast
stream structs, similar to the unicast stream struct.

The purpose of these are to be able to use the same structs
for multiple profiles such as BAP, CAP and TMAP.

Since only the BAP shell implements broadcast support at this
moment, the changes are minimal, but makes it easier to implement
broadcast support for other profile shells.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 15:27:46 +02:00
Emil Gydesen
5ce5940ac5 Bluetooth: CSIP: Fix issue with ordered access without lock char
Fixed issue when performing the ordered access procedure on
a set of devices where none had the lock characteristics.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 10:14:56 +02:00
Emil Gydesen
41fd5b80df Bluetooth: CSIP: Add missing and fix Set Coordinator set info
The set info returned by the Set Coordinator did not contain
information about the lockable state. Furthermore the
set info was not properly initiated, as it was missing the
rank, which was set somewhere else.

This commit adds the lockable state to the set info.
This commit removes the rank from internal structure,
and uses a reference to the set info instead, and only
store the rank there.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 10:14:56 +02:00
Emil Gydesen
f3259daa8a Bluetooth: CSIP: Fix Set Member set size and rank param validation
The set size and rank validation did not allow setting e.g.
rank = 2 and set_size = 0, which should be allowed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 10:14:56 +02:00
Emil Gydesen
3f8daa6762 Bluetooth: CSIP: Add support for optional characteristics
Whenever a CSIS instance is registered with
bt_csip_set_member_register we now properly check if the
set size, rank and lock characteristics should be present.
If not, then remove them from the service declaration.

It is done this way, as it is easier (read: possible) to
remove characteristics from the service declarations,
than it is to add the optional characteristics, as the
optional characteristics may be present in some CSIS
instances, but not in others.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 10:14:56 +02:00
Emil Gydesen
8ae46910c8 Bluetooth: CSIP: Avoid multiple conn CBs registers
The bt_csip_set_member_register function would register
the connection, and connection auth info, callbacks for
each CSIS instance, which could give errors when/if the
callbacks are called too many times. In any case, they
should not be registered multiple times.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 10:14:56 +02:00
Emil Gydesen
8c2df1bfd5 Bluetooth: BAP: Add return error for sink cb register
Since the provided callback can be NULL which would
break things, add a check and a return value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 16:54:10 +09:00
Emil Gydesen
70b88378f9 Bluetooth: BAP: Limit broadcast sink streams to proper max value
The number of streams for a broadcast sink is maximum 31,
or the maixmum number of BIS we support.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-10 16:53:56 +09:00
Vinayak Kariappa Chettimada
92f0b5490c Bluetooth: Controller: Fix uninitialized ticks_slot in CIS create
Fix use of uninitialized ticks_slot value in calculation of
cis_offset_min when creating CIS. Calculate the ticks_slot
value earlier when committing the CIG parameters.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-09 17:25:31 +02:00
Vinayak Kariappa Chettimada
9c95dce9a4 Bluetooth: Controller: Fix incorrect use of rx buffer in Tx ISR
Do not enqueue node rx buffers for generating invalid ISO
data from Tx ISR while supplying the node rx buffer to
Radio. This causes node rx pool corruption and also MIC
failures in the central ISO LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-09 17:25:14 +02:00
Vinayak Kariappa Chettimada
038c89b2c9 Bluetooth: Controller: Remove redundant CIS encryption code
Remove redundant unused CIS encryption related code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-09 17:25:14 +02:00
Vinayak Kariappa Chettimada
0777583ca1 Bluetooth: Controller: Fix peripheral ISO data ack mechanism
Fix peripheral ISO data ack mechanism to correctly update
the SN when PDUs fail to be received.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-09 17:25:14 +02:00
Vinayak Kariappa Chettimada
0b27981f94 Bluetooth: Controller: Do not disconnect all CIS on MIC failure
Fix implementation to not disconnect all CIS when one
connection has MIC failure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-09 17:25:14 +02:00
Vinayak Kariappa Chettimada
8a376a747e Bluetooth: Controller: Use strict cis_offset_min when CIG is active
When there is an active CIG for a new CIS create, then use
strict cis_offset_min/cis_offset_max so that the new CIS
is scheduled inside the active CIG event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-09 15:04:32 +02:00
Herman Berget
688f5baded Bluetooth: Host: Fix warning from the logging subsystem
Cast `dhkey` to `void*` to avoid a warning from the logging subsystem:
```
<wrn> cbprintf_package: (unsigned) char * used for %p argument.
It's recommended to cast it to void * because it may cause misbehavior
in certain configurations
```

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-05-09 14:28:49 +02:00
Pavel Vasilyev
1fdf283531 Bluetooth: Mesh: Remove outdated RPL entries in settings work item
This allows to move flash operations from the context that triggered
IVI update to the mesh settings work item that runs on the system
workqueue. After this change, the outdated RPL entries will be removed
in the setting work item triggered by store_pending function in
mesh/settings.c. This is required to for a case where the mesh settings
work item is running on a separate thread instead of the system
workqueue to unblock the system workqueue eventually.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-05-09 13:03:38 +02:00
Troels Nilsson
c743edaaa6 Bluetooth: Controller: Fix endianness handling for DID/SID struct
Bitsets across byte boundaries does not work properly for big-endian;
Converted to use two uint8's instead

Signed-off-by: Troels Nilsson <trnn@demant.com>
2023-05-09 13:03:28 +02:00
Vinayak Kariappa Chettimada
81c9795023 Bluetooth: Controller: Set Broadcast ISO related supported cmd bits
Set Broadcast ISO related HCI Read Supported Commands bits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-09 11:30:41 +02:00
Aleksander Wasaznik
bb1ede6a9b Bluetooth: Use bt_addr_eq
Refactor. Using `bt_addr_eq` instead of `bt_addr_cmp`.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-05-09 09:23:52 +02:00
Emil Gydesen
68d1d7d1b4 Bluetooth: Audio: Shell: Add broadcast assistant add broadcast_id
Add command to add a source by the broadcast ID. This will
initiate scanning for the broadcast ID, making it unnecessary
for the user to keep track of both the broadcast ID, the SID
and the address, and just focus on the (properly) known
broadcast ID.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
d97b0e1ea9 Bluetooth: Audio: Shell: fix missing opt arg for assistant scan_start
The command has an optional parameter that could not be used.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
ed2d30e382 Bluetooth: Audio: Shell: cmd_bap_broadcast_assistant_broadcast_code use hex
The cmd_bap_broadcast_assistant_broadcast_code used decimal, instead
of hex, for the broadcast code, making it a lot harder to use.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
f24e9d9fcd Bluetooth: Audio: Shell: Print BIS Sync as hex
Since the value is a bitfield, printing it as hex makes it easier
to use.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
8a3aa4c289 Bluetooth: Audio: Shell: Remove name from bap_broadcast_assistant_scan_cb
The callback does not have the advertising data, so the name
would always just be empty.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
1ef2ce40d6 Bluetooth: Audio: Add PA sync broadcast shell commands
Add shell commands to add a PA sync as a broadcast source.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
a180c013db Bluetooth: Audio: Modify broadcast_id prints/logs to use 24-bit
Always print/log the 24-bits (as hex) of the broadcast ID to better
use it with e.g. the shell.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
f2ce934209 Bluetooth: Audio: Add additional logging to broadcast assistant
Adds additional logging, as well as making the API param checks
more similar.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
043241d6fa Bluetooth: Audio: Broadcast Assistant: Fix subscribe issue
If starting the discovery procedure multiple times, the
subscribe function returns -EALREADY which needs to be handled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
fa70c86cd6 Bluetooth: Audio: Add common audio shell print commands to audio.h
Move common audio shell print functions into audio.h.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
a431f5235b Bluetooth: Audio: Move the decode_base functionality to a public function
Moved the implementation of the pa_decode_base to a public
function, and modified it to return better error codes.

The implementation was moved to be publically
accessible, rather than internal in the Broadcast Sink,
as e.g. a Broadcast Assistant need to be able to decode the
BASE too. This wil also allow an application to decode it
itself, if it so wanted to.

This also adds a log module for the audio.c file, as logging
would otherwise not be supported.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
e23a5234a1 Bluetooth: Audio: Make broadcast assistant params const
Make the add and mod source parameters `const`, as well
as the broadcast code.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
4e5a3b9e79 Bluetooth: Audio: Broadcast Assistant: Verify PAST support
Verify that PAST would be possible before providing
BT_BAP_BASS_PA_REQ_SYNC_PAST as the PA sync value to the
Scan Delegator.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Emil Gydesen
a6bd893d55 Bluetooth: Audio: Make pa_sync boolean
Make the `pa_sync` field of the
bt_bap_broadcast_assistant_add_src_param and
bt_bap_broadcast_assistant_mod_src_param to boolean
instead of uint8_t, as it represents a boolean value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 13:27:33 +02:00
Herman Berget
1f43e126a8 Bluetooth: Host: Fix setting missing params in create connection v2.
The adv_handle and subevent were always set to 0.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-05-08 11:24:25 +02:00
Fredrik Danebjer
da25ed53d0 Bluetooth: audio: Add paired_ep to endpoint info
Added paired_ep to bt_bap_ep_get_info, which would allow to check
whether an endpoint is paired with another endpoint, this would
indicate that its coupled to a bidirectional iso.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
2023-05-08 10:25:07 +02:00
Emil Gydesen
4421b80dd1 Bluetooth: ASCS: Fix receiver_ready on state change
The receiver_ready field can only be set while in the enabling
state, and is a requirement to go into the streaming state.

If for any reason we go into a state that is not enabling
or streaming, then the receiver_ready field should be
cleared, as the circumstances are changed.

This also fixes an issue where if the CIS disconnects,
then we go from the streaming state to the
qos configured state, without clearing it, causing
incorrect behavior if we attempt to connect the streams
again.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-08 09:59:44 +02:00
Pavel Vasilyev
177e9b93bf Bluetooth: Mesh: Add API to store model's user data in settings work
Mesh models may have a data that needs to be stored persistently.
Currently, the models should call bt_mesh_model_data_store and the store
will happen in the calling context. Most likely that it will be called
in BT RX thread as this is the context from which model's opcodes
handlers are called. Thus, the thread will be blocked until the store is
finished.

Another issues is that some models may have states that changes
frequently. Triggering the store on every state change may wear out
flash. Therefore, the models need to implement some postpone mechanism
to reduce the flash wear out.

The mesh stack has already implemented the mechanism of deferred store
with its own settings. The models could use it instead of implementing
their own mechanism.

In combination with the mesh settings workqueue, the models can store
their data without blocking the stack work.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-05-08 09:58:21 +02:00
Pavel Vasilyev
e33a4ace0f Bluetooth: Mesh: Use separate workq for storing mesh settings
Currently mesh settings are stored in the system workqueue context.
Most of other stack functionality, such that advertisements (incl
relay), loopback, transport sar, beacons transmission, etc. is also
processed in the system workqueue context. When a massive amount of
data needs to be stored and in particularly when page erase needs to
be triggered by GC of NVS subsystem to allocate flash pages, the
execution of the stack (and other functionality that uses the system
workqueue) will be blocked until storing is finished. For example,
right after the provisioning of a erased device, a node may not be
responsive for up to 400ms before it can continue sending messages.
The waiting time may increase if there is a GATT connection in the
mean time.

When write or erase operation is triggered, the flash driver waits for
Bluetooth controller to allocate a time needed to perform the operation.
During the whole operation, the context from which the operation was
triggered is put to sleep. This allows other threads to run until
Bluetooth controller finds the time for the flash driver. In other words,
every settings_save_one or settings_delete should be considered as
rescheduling points.

Considering this, Bluetooth mesh can use another thread to store its
settings, thus releasing the system workqueue for other tasks including
the operation of the stack itself.

The consistency of the data to be stored is guaranteed by the current
implementation where the data is copied to another struct before calling
settings_save_one. The pending flag of a particular module is dropped in
settings.c before starting to store the corresponding data. Thus, if
during the sleep the node receives a message that triggers a change in a
module which data is currently being stored, the pending flag will be
restored and the new change will be stored eventually.

Having this option enabled including with the partial erase, will make
the node more responsive in the described situations.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-05-08 09:58:21 +02:00
Emil Gydesen
8d24d506b3 Bluetooth: Audio: Shell: Move audio defines to audio.h
The generic BT shell header, bt.h, contained quite a few things
related to audio, which should be put in the audio.h shell header
file.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-05 16:17:59 +02:00
Vinayak Kariappa Chettimada
c01cd1c482 Bluetooth: Controller: Review rework changes for multiple CIS support
Assorted review rework changes for multiple CIS support
implementation commits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
94821ef04c Bluetooth: Controller: Preliminary multiple peripheral CIS support
Updated nRF5 Series LLL implementation to support multiple
peripheral CIS establishment from peer central devices.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
3306f3160f Bluetooth: Controller: Central multiple CIS using advanced scheduling
Central multiple CIS create implementation using advanced
scheduling to find the active CIG events and calculate the
CIS offset to be used in the LL_CIS_REQ PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
2007967553 Bluetooth: Controller: Use Conn ISO prepare latency to check timeout
Use accumulated connected ISO LLL prepare callback latencies
to check supervision timeout.

Also use the accumulated connected ISO LLL prepare callback
latencies to adjust SN and NESN values.

Connection establishment can cause short prepare callbacks
inserted before Connected ISO group prepare callbacks, that
cause the Connected ISO group prepare callbacks being
cancelled while being in prepare pipeline. Hence, it is
necessary to accumulate prepare callback latencies wherein
ticker callbacks are executed but prepare callbacks are
cancelled in the prepare pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
ef8b05e83a Bluetooth: Controller: Preliminary Central multiple CIS support
Implementation of preliminary Central with multiple CIS
create support in Lower Link Layer. Uses a simple CIS
offset calculation that works when ACL are created with
connection interval that is multiple of CIG ISO interval.
Each ACLs are offset using BT_CTLR_CENTRAL_SPACING hence
having the same CIG sync delay values for all the ACLs.
Advanced Scheduling to setup CIS in any order of ACL and
CIS combination, ACL placed anywhere in timeline and CIS
creation will come therein will be implemented in later
Pull Requests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
5152672d06 Bluetooth: Controller: Include remainder when calculating cis_offset
Include ticker expire remainder value when calculating the
cis_offset to acheive fine timing in scheduling the CIG
radio events relative to its associated ACL radio events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
e09c2ddf7a Bluetooth: Controller: Use ticker_start_us for Central and ISO setup
Use the ticker_start_us() interface for Central and Central
ISO setup to acheive fine timing for the first expire
timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
4e65cae32a Bluetooth: Controller: Ticker first expire with remainder
To acheive microsecond or fine timing for first expire
timeout, pass remainder value of the coarse tick to a new
ticker_start_us() interface. The new interface is available
with BT_TICKER_EXT feature enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
285649c894 Bluetooth: Controller: Fix implementation of CIS Null PDU Indicator use
Fix implementation of CIS Null PDU Indicator use to meet the
BT Specification statement, that, if the source of the data
fails to provide a payload in time for a CIS subevent, then
the link layer shall transmit a CIS Null PDU instead.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
9ccf70fd27 Bluetooth: Controller: Extended Advertising using ticker expire info
This is re-introduction of Extended, Periodic Advertising
and Broadcast ISO using ticker expire info feature to get
the aux, sync and BIG offsets.

Relates to commit 714d74b77b ("Bluetooth: controller: Use
new ticker feature to get offsets").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
6a1a93e587 Revert "Bluetooth: controller: Use new ticker feature to get offsets"
This reverts commit 714d74b77b.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
9cada37d9b Bluetooth: Controller: Add BT_TICKER_EXT_EXPIRE_INFO Kconfig
Add BT_TICKER_EXT_EXPIRE_INFO Kconfig.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
52615afcf1 Bluetooth: Controller: Remainder and Lazy depends on match get
Ticker remainder and lazy get depends on match get interface
provided by BT_TICKER_NEXT_SLOT_GET_MATCH.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
e912a6589a Bluetooth: Controller: Remove redundant Kconfig range and default
Remove redundant range and default for BT_CTLR_ADV_AUX_SET
when supporting BT_CTLR_ADV_PERIODIC.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
08c1b1749a Bluetooth: Controller: Fix BT_TICKER_NEXT_SLOT_GET select
Fix BT_TICKER_NEXT_SLOT_GET select, to depend on
BT_CTLR_SCHED_ADVANCED.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
9600c94c4b Bluetooth: Controller: Fix BT_TICKER_EXT BT_TICKER_LOW_LAT dependency
BT_TICKER_EXT is not supported with BT_TICKER_LOW_LAT.
Remove redundant select of BT_TICKER_EXT for
BT_CTLR_ADV_EXT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Vinayak Kariappa Chettimada
3fb90bb601 Bluetooth: Controller: Group depends on together in Kconfig file
Group depends on clauses together in the Kconfig.ll_sw_split
file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-05 12:26:31 +02:00
Emil Gydesen
2a2f067333 Bluetooth: HAS: Add missing memset of read params
The missing memset caused invalid chan_opt when EATT was
enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-05 11:26:11 +02:00
Herman Berget
a947af8ac3 Bluetooth: Host: Fix PHY translation from HCI
HCI events use different values for the PHYs than the GAP macros.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-05-04 20:50:58 +02:00
Erik Brockhoff
44df982d0b Bluetooth: controller: disallow enc start/pause when CIS established
Start/pause encryption should not be initiated on ACL with CIS
established (BT Core Spec 5.4, Vol 6, Part B, Sect. 5.1.3)
Adding test for the added procedure peek function

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-05-04 10:47:37 +02:00
Jonathan Rico
7d1a5f5554 Bluetooth: iso: use BT_ISO_SDU_BUF_SIZE()
Use BT_ISO_SDU_BUF_SIZE() instead of calculating manually.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-05-03 10:02:44 +02:00
Jonathan Rico
fb10381328 Bluetooth: iso: use kconfig for userdata size
Use BT_CONN_TX_USER_DATA_SIZE when defining pools of buffers that will go
through `bt_conn_send_cb()`.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-05-03 10:02:44 +02:00
Jonathan Rico
e460847b60 Bluetooth: host: don't fragment ISO if len <= MTU
MTU doesn't count against the ISO and ISO data headers.

Then a config with CONFIG_BT_ISO_TX_MTU ==
CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE should not fragment SDUs over HCI.

Also set the TS_Flag bit if a timestamp is present.

Fixes #56749

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-05-03 10:02:44 +02:00
Herman Berget
bf4e3fe2a4 Bluetooth: Host: Fix sync subevent cmd length
The subevents were not considered in the length of the command.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-05-02 16:56:01 +02:00
Emil Gydesen
66f8ab5a28 Bluetooth: BAP: Add specific error code for stopping stopped sink
If the broadcast sink is already stopped (i.e. the streams have
all been disconnected), then we can return a more useful
error code than EINVAL.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-02 09:35:11 -05:00
Jordan Yates
8e603d091c Bluetooth: controller: Kconfig TX power dBm
Adds a Kconfig symbol which contains the default controller TX power
directly in dBm. This allows code to directly display/use the configured
power, instead of having to manually iterate over all the
`BT_CTLR_TX_PWR` options.

```
  LOG_INF("BT controller configured for %ddBm TX power",
          CONFIG_BT_CTLR_TX_PWR_DBM);
```

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-05-02 10:12:23 +02:00
Pavel Vasilyev
1113c2efd4 Bluetooth: Mesh: Store device key candidate asynchronously
This allows to move flash operations from the context that triggered
storing device key candidate to the mesh settings work item that runs
on the system workqueue. This is required to for a case where the mesh
settings work item is running on a separate thread instead of the system
workqueue to unblock the system workqueue eventually.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-29 12:24:28 +02:00
Pavel Vasilyev
f3085ab95d Bluetooth: Mesh: Move storing of new prov data to settings work item
This allows to move flash operations from the context that triggered
bt_mesh_provision or bt_mesh_reprovision to the mesh settings work item
that runs on the system workqueue. This is required to for a case where
the mesh settings work item is running on a separate thread instead of
the system workqueue to unblock the system workqueue eventually.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-29 12:24:28 +02:00
Stine Åkredalen
80158c1428 doc: Bluetooth: Mesh: update proxy solicitation docs
Updated related docs. Small fix in mesh/Kconfig and shell.rst.

Signed-off-by: Stine Åkredalen <stine.akredalen@nordicsemi.no>
2023-04-28 20:37:45 +02:00
Aleksander Wasaznik
67d6011851 Bluetooth: hci_raw: Fix a LOG_ERR message
The LOG_ERR was printing the wrong variable. `type` always has the value
`BT_BUF_H4` here, so there is no point in printing it.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-28 10:33:18 -05:00
Herman Berget
5893606187 Bluetooth: Host: Use a valid disconnect reason
"Unspecified Error" is not a disconnect reason allowed by spec.

Fixes #56989

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-04-28 14:50:11 +02:00
Mariusz Skamra
292bf966be Bluetooth: audio: ascs: Make use of bt_bap_stream_reset
This deduplicates a code a bit by reusing existing bt_bap_stream_reset
function to unbind and detach the stream object.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-28 14:49:25 +02:00
Mariusz Skamra
197e20e3c2 Bluetooth: audio: ascs: Remove redundant sessions pool
This removes redundant bt_ascs structure pool that held the list of
ases per connection. The memory usage can be reduced by moving the conn
reference to bt_ascs_ase structure. This change reduces flash and RAM
memory usage.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-28 14:49:16 +02:00
Herman Berget
d7218fe359 Bluetooth: Host: Add support for receiving connections while synced
The PAwR sync can receive a connection request from the PAwR
advertiser and become peripheral.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-04-28 11:00:48 +02:00
Herman Berget
c961e2c212 Bluetooth: Host: Add support for initiating connections from PAwR
This is known as the Periodic Advertising Connection Procedure.

The PAwR advertiser can initiate a connection to a synced device and
become the central.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-04-28 11:00:48 +02:00
Morten Priess
5b6198403c Bluetooth: controller: Fixes for CIG with two CISes and separate ACLs
Prevent referencing inactive CISes by clearing state variables
after teardown. This was seen as necessary when having CISes on
different ACLs, and disconnecting ACLs in random order.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-04-28 10:07:46 +02:00
Emil Gydesen
5076476cf5 Bluetooth: BAP: Fix missing remove of streams from slist
In the broadcast sink when the streams disconnected (without
the PA disconnecting), the streams were not properly
removed from the sink's list of streams. This allowed
the same stream to be added to the list twice, which
would cause a infinite loop as the stream would
point to itself as the next.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-27 20:19:58 +09:00
Jacob Siverskog
6cefad338b Bluetooth: BAP: Shell: Fix NULL pointer dereference
Make sure 'state' is valid.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2023-04-27 20:18:55 +09:00
Herman Berget
e745439c40 Bluetooth: Host: Fix periodic sync reassembly
The reassembly buffer for periodic sync was not initialized
if the sync was established via PAST.

Move the initialization of the reassembly buffer to a common place.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-04-26 20:08:16 +02:00
Herman Berget
95bc5cf8e5 Bluetooth: Host: Add support for PAwR Sync
Adds API for Periodic Advertising with Responses - Scanner:
 - Synchronize to a PAwR train
 - Choose which subevents to synchronize to
 - Receive advertising reports from subevents
 - Send responses

The support is enabled by CONFIG_BT_PER_ADV_SYNC_RSP, and requires
a controller that selects CONFIG_BT_CTLR_SYNC_PERIODIC_RSP_SUPPORT.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-04-26 20:08:16 +02:00
Herman Berget
9021e2f438 Bluetooth: Host: Add support for PAwR Advertiser
Adds API for Periodic Advertising with Responses - Advertiser:
 - Configure parameters
 - Receive subevent data requests
 - Set subevent data
 - Receive response reports

The support is enabled by CONFIG_BT_PER_ADV_RSP, and requires
a controller that selects CONFIG_BT_CTLR_ADV_PERIODIC_RSP_SUPPORT.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-04-26 20:08:16 +02:00
Jonathan Rico
ece481d560 Bluetooth: host: att: clear ATT_PENDING_SENT
The ATT_PENDING_SENT flag was still not being cleared in all cases.

Also reset `data->att_chan` when not able to send on a given channel.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-04-26 13:53:08 +02:00
Jonathan Rico
2809bace65 Bluetooth: host: l2cap: send only 1 credit
The API doesn't allow the stack to make any guarantees about the number of
available buffers that the app has.

Only send 1 credit at a time, as that is the only guarantee the stack can
give to the peer.

We can send MTU/MPS's worth of credits once we have acquired an SDU buffer
from the application (that is, on the first PDU of the SDU). Though we
still have to cap that to the buffer size we have just acquired.

------

The testcase added here shows a scenario where the relationship
between the number of credits and the number of available buffers does not
hold true any more:

In this test, the app only has one buffer in its pool.

The central will queue SDUs that are bigger than the stack's
buffers (so the user allocator is necessary) but lower than the
channel's MTU.

The device receiving the SDU keeps a reference to the buffer before
returning from the `recv` callback. It releases that reference after a
small delay.

The central will still have credits, so it will queue another SDU, but the
peripheral will not be able to receive the next SDU (as the allocator will
fail) and will close the channel.

To see the test fail, just revert the `l2cap.{c,h}` changes.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-04-26 13:53:08 +02:00
Jonathan Rico
6cdb82cb59 Bluetooth: host: l2cap: trigger SDUs that get lost in limbo
Turns out the [first bugfix] was too naive: there is a case where resuming
all channels will not work on all queued SDUs, and the work handler will
give up and wait for the next sent SDU instead of trying to resume again.

This happens when the number of credits and conn contexts is very low for
the amount of data to send.

Always reschedule with a delay to avoid that situation.

[first bugfix]: https://github.com/zephyrproject-rtos/zephyr/pull/50476

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-04-26 13:53:08 +02:00
Mariusz Skamra
d384ef4e57 Bluetooth: audio: ascs: Fix handling arrayed parameters
This fixes loop over arrayed metadata/cc parameters. The paramaters have to
be pulled from the buffer, because in case the ASE_ID is invalid or in
invalid state, the next loop iteration would read invalid data.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-25 12:21:23 +02:00
Emil Gydesen
303bcfdcb7 Bluetooth: Shell: Add testcases for AUDIO_RX and TX disabled
Add configurations where CONFIG_BT_AUDIO_TX and CONFIG_BT_AUDIO_RX
are disabled.

Fixes issues found in the BT shell implemented caused by these
configurations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-25 12:20:38 +02:00
Emil Gydesen
2c5a249fdd Bluetooth: BAP: Add guard before accessing qos->latency
The qos->latency is not available for broadcast sink-only
builds.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-25 12:20:38 +02:00
Emil Gydesen
32e8392400 Bluetooth: BAP: Move TX guard to not cover verify funcs
Move the BT_AUDIO_TX guard so that it does not cover the
verification functions for valid_codec and qos, as they
are also relevant for receivers to verify what remote
devices send.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-25 12:20:38 +02:00
Krzysztof Kopyściński
0a55ec8d52 Bluetooth: Mesh: Add callback for received beacons
This adds callbacks for Secure and Private Network Beacons.
SNB callbacks are called after `secure_beacon_authenticate` ends
with success, and Private Beacon callback after Private Beacon
payload is decrypted succsessfully.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-04-24 13:36:12 +02:00
Mariusz Skamra
81532bf5f0 Bluetooth: audio: ascs: Remove ascs_cp_rsp_add function redundant param
This removes opcode from ascs_cp_rsp_add function parameters and moves
response buffer initialization to be done in Control Point write
function context.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-24 13:34:59 +02:00
Mariusz Skamra
9ec93b5bd5 Bluetooth: audio: ascs: Fix using magic numbers
Use defined values instead.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-24 13:34:59 +02:00
Pavel Vasilyev
c4fa085ec4 Bluetooth: Mesh: Add async API for Large Comp Data Client
Add asynchronous API for Large Composition Data Client.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-24 13:31:27 +02:00
Pavel Vasilyev
b99d4dbce2 Bluetooth: Mesh: Use bt_mesh_msg_ackd_send API in LCD Client
Use bt_mesh_msg_ackd_send API in LCD Client.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-24 13:31:27 +02:00
Pavel Vasilyev
60e874472c Bluetooth: Mesh: Use BT_MESH_MSG_CTX_INIT_DEV macro in LCD Client
Use BT_MESH_MSG_CTX_INIT_DEV macro in LCD Client.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-24 13:31:27 +02:00
Aleksander Wasaznik
2091144c51 Host: ATT: Use bt_att_is_enhanced everywhere
Refactoring. All occurences of `atomic_test_bit((.*)->flags,
ATT_ENHANCED)` are replaced with `bt_att_is_enhanced($1)`.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Aleksander Wasaznik
af5103bdc3 Bluetooth: ATT: Set correct MTU for EATT L2CAP channel
The EATT MTU in Zephyr is static. We know it at channel creation time,
so we should communicate the MTU as part of channel creation.

Side note: With this approach, it should no longer be neccessary or
useful to do a channel reconfigure.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Aleksander Wasaznik
3de6f7c99d Bluetooth: ATT: Move setting of initial MTU to att_chan_new
The L2CAP MTU can and should be set already during the channel setup.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Aleksander Wasaznik
a2dc61a465 Bluetooth: ATT: MTU min instead of cap
The previous approach with `cap_eatt` was flawed. It would overwrite
`le_chan->tx.mtu`, losing its true value. (It is supposed to be the
L2CAP MTU as reported by the remote side.)

The previous approach worked out for UATT because the locally triggered
exchange always carries the remote MTU in the response, so we did not
need to keep track of the remote MTU.

But, unlike the UATT MTU exchange, the L2CAP reconfigure only exchanges
the MTU in one direction. If the remote does the first reconfigure, we
would correctly cap the ATT MTU to our local MTU. But, we would
incorrectly store this as the remote's MTU. When we then increase our
local MTU using `bt_eatt_reconfigure`, we correctly set and send our
MTU.  But we have an incorrect notion that the remote MTU is the value
that we ourselves limited. And mistake would incorrectly limit the
negotiated ATT MTU locally.

The simplest solution is to not mess with `le_chan->tx.mtu` and just
calculate the ATT MTU like Spec intended.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Aleksander Wasaznik
fa9d41f39b Bluetooth: Host: Add helper bt_att_is_enhanced
This is a refactor. Hopefully, it makes the code easier to maintain.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Aleksander Wasaznik
d4d0956516 Bluetooth: ATT: Split BT_ATT_MTU for UATT/EATT
This is a refactor. There is no behavioral change because
`BT_LOCAL_ATT_MTU_UATT` is `BT_LOCAL_ATT_MTU_EATT + 2` is
`BT_ATT_BUF_SIZE` is the old `BT_ATT_MTU`.

The old `BT_ATT_MTU` was wrong for EATT bearers. EATT MTU is two bytes
less because of ECRED overhead.

Instead of the old `BT_ATT_MTU`, we define one for each bearer type. We
also define the max of them to use as a convenience for allocating
buffers that fit either.

To avoid confusion, 'LOCAL' has been added to the name. This is to
differentiate it from what the spec calls 'ATT MTU', which is a
negotiated property. (It is the minimum of the two side's local ATT
MTU.)

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Aleksander Wasaznik
46646452fe Bluetooth: L2CAP: Add missing req_mtu assert in l2cap_ecred_conn_req
There is an assert that `req_psm` is the same for all channels in the
same connection request because HCI requires this. The same is true for
`req_mtu`. This adds the obviously missing assert.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Aleksander Wasaznik
3148389695 Bluetooth: ATT: Introduce bt_att_mtu
This is a refactoring, only visible inside `att.c`.

Give the expression `chan->chan.tx.mtu` the name `bt_att_mtu`. Use it
when the intention is to get the ATT MTU property of a channel.

This is done in preparation a more complex expression for `bt_att_mtu`,
since the expression currently incorrect. The fix will come in a later
commit in the same PR.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-04-24 13:31:18 +02:00
Emil Gydesen
5ab585d1af Bluetooth: ASCS: Log missing fields of qos_pref
Added logging of the pref_pd_min and pref_pd_max field.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-21 16:29:08 +02:00
Emil Gydesen
4b8574d7b1 Bluetooth: BAP: Shell: Fix bad arg to CAP acceptor ad data
The data array was using the wrong index.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-21 16:23:27 +02:00
Mariusz Skamra
f35959a261 Bluetooth: ascs: Fix ASE Control Point PDU length validation
This moves ASE Control PDU length validation before request processing.
If the PDU length is not as expected, the operation shall be considered
as invalid. Thus shall be rejected.

ASCS_v1.0; 5 ASE Control operations
"A client-initiated ASE Control operation shall be defined as an invalid
length operation if the total length of all parameters written by the
client is not equal to the total length of all fixed parameters plus
the length of any variable length parameters for that operation"

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-21 13:01:42 +02:00
Mariusz Skamra
3b57b2014c Bluetooth: audio: ascs: Fix invalid Response_Code in notification
This fixes sending proper Response_Code in ASE Control Point
notification in case the client initiates Receiver Start/Stop Ready
operation on Sink ASE.
The response that shall be sent according to the specification is
"Invalid ASE direction", while the implementation sent "Invalid ASE state"
instead.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-21 12:55:46 +02:00
Emil Gydesen
8e7757275e Bluetooth: BAP: Guard bt_bap_stream_send with CONFIG_BT_AUDIO_TX
Modify the guard of bt_bap_stream_send to use the
CONFIG_BT_AUDIO_TX.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-21 09:40:39 +02:00
Emil Gydesen
3d877338e6 Bluetooth: BAP: Fix missing guards of sent and recv in uni cli
The unicast client did not properly guard the sent and recv
callbacks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-21 09:40:39 +02:00
Theo Gasteiger
ce2ac63953 Bluetooth: Fix CONFIG_BT_CTLR_DEBUG_PINS_CPUAPP compile error
Fix appcore compile error when enabling CONFIG_BT_CTLR_DEBUG_PINS_CPUAPP.

Signed-off-by: Theo Gasteiger <gatcode@wdw.one>
2023-04-20 16:10:42 +02:00
Emil Gydesen
fa95a7add2 Bluetooth: BAP: Add missing Broadcast source param checks
Several input parameter checks were missing in the BAP broadcast
source API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-20 10:47:10 +02:00
Martin Rieva
ddf518e706 Bluetooth: Shell: Extend the shell output of scan data
Add verbose output of scan data to output all received data types as
hex values. This is turned off by default and can be toggled using
the bt scan-verbose-output <on|off> command.

Signed-off-by: Martin Rieva <mrrv@demant.com>
2023-04-20 10:32:55 +02:00
Emil Gydesen
754a5da2ff Bluetooth: MICP: Shell: Add missing "mic_dev" for MICP cmds
The MICP Microphone Device commands were missing the proper
role name.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-19 17:14:30 +02:00
Emil Gydesen
12e82347b4 Bluetooth: BAP: Shell: Scan Delegator prefer past by default
Change the default value of past_preference to true, to prefer
PAST by default when using the scan delegator.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-19 04:55:09 -04:00
Emil Gydesen
66af395726 Bluetooth: BAP: Broadcast source fix invalid data pointer
When copying the stream specific codec configuration data,
the value pointer in the bt_data struct was not properly
updated, causing possible invalid data access.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-19 04:54:53 -04:00
Emil Gydesen
80bf8c0f7d Bluetooth: CAP: Add missing NULL checks for CAP broadcast start
Add missing checks for param and adv.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-19 04:54:37 -04:00
Emil Gydesen
dda3703755 Bluetooth: CAP: Add missing NULL check for unicast_audio_update
The bt_cap_initiator_unicast_audio_update function was missing
NULL and 0 checks for input parameters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-19 10:00:45 +02:00
Vinayak Kariappa Chettimada
4b90d01398 Bluetooth: Controller: Fix cis_offset_min used in CIS Create Response
Use the minimum supported cis_offset_min considering that
ACL radio event does not overlap with CIG event. Use the
calculated maximum of local and remote cis_offset_min in the
Response PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-19 03:47:19 -04:00
Aleksandr Khromykh
e7f1856143 Bluetooth: Mesh: add experimental support mbedtls psa
Commit adds experimental support mbedtls psa as crypto
backend for ble mesh. It were run only on bsim tests.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-04-17 16:31:20 +02:00
Aleksandr Khromykh
77c72aa67b Bluetooth: Mesh: get rid of host dependency for dh key for mesh
Commit gets rid of host dependency to generate DH key.
Mesh uses its own function for it that has synchronous
behavior and correct endianism. It simplifies the provisioning
state machine since it doesn't require waiting for the host HCI
handler.
Also, it removes hidden cross-dependency between BLE Mesh and
SMP in the aspect of competition for the same DH key
(https://github.com/zephyrproject-rtos/zephyr/issues/23292)

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-04-17 16:31:20 +02:00
Aleksandr Khromykh
3f08bd335f Bluetooth: Mesh: split crypto on seclib dependent and independent parts
Commit splits mesh crypto module on security library dependent
and independent parts.
Independent part includes security toolbox implementation.
Dependent part includes security algorithms usage based on
API third party security library.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-04-17 16:31:20 +02:00
Vinayak Kariappa Chettimada
64b4c6ddbd Bluetooth: Controller: Fix Adv PDU RAM usage for direction finding
Fix Advertising PDU size calculation when direction finding
feature is enabled and PDU fragment count includes the
maximum CTE PDU chained. Fix removes redundant PDU count
included for Extended Advertising. Only Periodic advertising
PDUs chain CTE requires number of additional PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-17 11:22:00 +02:00
Rubin Gerritsen
19547e815b Bluetooth: Increase HCI CMD buffer size when ISO Central is used
When ISO Central is enabled it is allowed to configure many CISes at
once. For this a large command buffer is needed. This is also tested
by HCI/CIS/BI-05-C.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-04-17 10:18:27 +02:00
Krzysztof Kopyściński
0d5c33b045 Bluetooth: Mesh: Fix recovery of WAITING_FOR_START BLOB Server state
If device running BLOB Server called `bt_mesh_blob_srv_recv`,
but rebooted before it received `XFER_START` message from BLOB Client,
it was wrongly "recovered" into Suspended phase, which would lead to
Server try to resume transfer on `XFER_START`. It would not be possible,
because `srv->state.xfer` was not set with acual values yet.

Set phase again to BT_MESH_BLOB_XFER_PHASE_WAITING_FOR_START, which will
allow to accept new transfer.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-04-17 10:15:56 +02:00
Erik Brockhoff
3cb42157c4 Bluetooth: controller: removing (invalid) ASSERT on invalid PDU
A case of an invalid PDU was seen leading to a hit on this ASSERT, ie
this COULD happen. Refactoring of the state handling re. expectedness
in remote vs local request machines combined with ensuring the local
request machine ceases to expect PDUs when remote procedure 'takes over'

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-04-14 14:03:55 +02:00
Vinayak Kariappa Chettimada
2579690be7 Bluetooth: Controller: Fix connection update window offset data type
Fix regression in refactored LLCP using uint16_t instead of
uint32_t in storing the win_offset_us value. This caused
connection update to fail with incorrect window offset being
used to schedule the connection radio events.

Regression since commit e1c2c36f56 ("Bluetooth: controller:
llcp: set refactored as default").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-14 12:57:00 +02:00
Gerard Marull-Paretas
667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Kumar Gala
d3b3a4f293 bluetooth: audio: Only build code if BT_CONN is enabled
The audio code utilizes BT_CONN so ensure its only built if
CONFIG_BT_CONN is set.  This is to fix a build issue we see
with arm-clang for:

sample.bluetooth.broadcast_audio_source

which fails to link since bt_conn_get_info is missing.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-13 16:13:52 +02:00
Vinayak Kariappa Chettimada
6551630c2c Bluetooth: Controller: Fix window offset calculation
Fix window offset calculation which is missing the radio
rx ready delay timing be subtracted because the connection
offset from the start of the radio for scan window to the
end of the ADV_IND PDU includes the radio rx ready delay
timing, where as the determined window offset by advanced
scheduling calculates the offset from the ticks_at_expire
of the scan window to an active central connection's
ticks_at_expire.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-13 16:12:58 +02:00
Vinayak Kariappa Chettimada
9d5ecd5bc9 Bluetooth: Controller: Use remainder in win_offset_us calculation
Update Advanced Scheduling implementation to use remainder
value in precisely calculating the connection request window
offset in microseconds.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-13 16:12:58 +02:00
Vinayak Kariappa Chettimada
205406820f Bluetooth: Controller: Move rx chain delay use into prepare_connect_req
Move the use of rx chain delay value used to calculate the
window offset into lll_scan_prepare_connect_req() instead of
current two places, one for legacy and other for extended
connection setup.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-13 16:12:58 +02:00
Vinayak Kariappa Chettimada
d1d58de94c Bluetooth: Controller: Match Central roles for BT_CTLR_CENTRAL_SPACING
Find and match only Central role ticker when applying the
BT_CTLR_CENTRAL_SPACING value.

Use the EVENT_TICKER_RES_MARGIN_US value as +/- jitter
margin when ticker advanced scheduling is used to group
radio events.

When using CONFIG_BT_CTLR_CENTRAL_SPACING, do not add the
+/- jitter to the ticks_slot.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-13 16:12:58 +02:00
Nirosharn Amarasinghe
11ce28f8f7 Bluetooth: controller: Consideration for SDU interval in fragmentation
Included consideration for the packet sequence number and time stamps
together with the SDU interval in matching the event for fragmentation
of SDUs to unframed PDUs.

Implemented:
-- Increase in kconfig limit of BT_CTLR_ISO_TX_BUFFERS to allow full 32
   buffers to be available for LL/CIS/PER/BV-39C
-- ISO-AL microsecond time wrapping exposed to be used externally to
   adjust incoming Group Reference Points and Time-stamps where required
-- Function that handles adjustment of payload number according to
   incoming SDU exposed for external use to allow next payload number to
   be accessed by ISO transmit tests
-- Changed internal fragmentation source identification parameter from
   the source structure pointer to the source handle so that only the
   source handle needs to be used for external calls

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2023-04-13 16:09:39 +02:00
Pavel Vasilyev
8dd24bf9c3 Bluetooth: Mesh: Restore PRB state after reboot
Add missing code for restoring Private Beacon state after reboot.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-13 10:00:16 +02:00
Pavel Vasilyev
95d6e66ec3 Bluetooth: Mesh: Don't process PRB when mesh-1.1 disabled
Private Beacons are mesh-1.1 feature and without mesh-1.1 spec enabled,
the node shall not process such beacons.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-13 10:00:16 +02:00
Pavel Vasilyev
c36fdf251f Bluetooth: Mesh: Allow sending SNB and PRB in parallel
Private Beacons and Secure Network Beacons are not mutually exclusive by
spec. This means both beacons can be sent simultaneously. For both
beacons spec defines their own observation intervals and related
parameters, which means we need to monitor both beacons types
separately.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-13 10:00:16 +02:00
Kumar Gala
0686476310 bluetooth: Fix compiler warning with arm-clang
Since we enable -fshort-enums for arm-clang we get the following
warning:

subsys/bluetooth/mesh/pb_adv.c:139:40: warning: cast to smaller
integer type 'enum prov_bearer_link_status' from
 'void *' [-Wvoid-pointer-to-enum-cast]

Fix this by first casting to an int to grow the size of the type.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-12 16:03:11 -04:00
Fredrik Danebjer
7e416c8ec0 Bluetooth: audio: csis: Fix Big Endianness for RSI generation
This changes so that generation of RSI now uses LE arrays instead of
uint32 words. Both input and output of rsi and sih genration now uses
LE. This also fixes the generation of RSI for BE systems, which
wasn't working.

Signed-off-by: Fredrik Danebjer <fredrik@danebjer.com>
2023-04-12 17:44:29 +02:00
Gerard Marull-Paretas
4863c5f05b sys/util: extend usage of DIV_ROUND_UP
Many areas of Zephyr divide and round up without using the DIV_ROUND_UP
macro. Make use of it, so that we make use of a tested system macro and
at the same time we make code more readable.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 16:42:29 +02:00
Gerard Marull-Paretas
a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Vinayak Kariappa Chettimada
51a7de2beb Bluetooth: Controller: Fix BIG handle when operation cancelled by Host
Fix the BIG handle in the HCI LE BIG Sync Established event
when BIG Create Sync operation is cancelled by Host.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-12 13:10:39 +02:00
Mariusz Skamra
13341a3e7e Bluetooth: audio: ascs: Fix missing ISO state check
This fixes missing ISO connection state check, as there might be no ISO
connection when Receiver Stop Ready has been received. This might happen
on ASE state transition from Enabling to Disabling.
Without this check the code asserts in ascs_disconnect_stream_work_handler.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-12 13:05:20 +02:00
Aleksandr Khromykh
4b5be77531 Bluetooth: Mesh: check buffer tailroom before relaying proxy message
PR adds checking proxy buffer tailroom before adding
a relayed message. That prevents potential proxy trash attacks.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-04-12 13:04:56 +02:00
Anders Storrø
fc49ad3ac6 Bluetooth: Mesh: Shell: Align parameter docs
Aligns Bluetooth mesh shell parameter documentation to use the
same syntax, abbrevations and formating.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2023-04-12 13:04:42 +02:00
Anders Storrø
1026ec5b38 Bluetooth: Mesh: Shell: Change pub cmd period arg
Changes the implementation and documentation in config client shell
command for Config Model Publication Set and Config Model Publication
Virtual Address Set to accept period resolution and period steps as
separate arguments to make it more user friendly.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2023-04-12 13:04:42 +02:00
Théo Battrel
b48a69023a Bluetooth: Logging: Make BT_LOG and BT_LOG_LEGACY hidden symbols
Make `BT_LOG` and `BT_LOG_LEGACY` hidden Kconfig symbols.

They should not be used by the user to configure the Bluetooth logging
system. If the user want to completely disable Bluetooth logging, they
should use `BT_LOG_LEVEL_OFF=y`.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-04-12 10:23:04 +02:00
Krzysztof Kopyściński
1993c5facd Bluetooth: Mesh: Link Close without success should fail NPPI procedure
When we receive `RPR_OP_LINK_CLOSE` message with reason other than
`SUCCESS` we should fail NPPI refresh procedure, not complete it.
Dropping `COMPLETE` flag will result in calling `reprovision_fail`
in `prov_link_closed`, not `reprovision_complete`.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-04-12 10:22:27 +02:00
Johan Hedberg
a6e5755da8 Bluetooth: Fix clearing sent_cmd pointer when allocating event buffer
We should clear the bt_dev.sent_cmd pointer after using it to allocate a
new HCI event buffer in the bt_buf_get_cmd_complete() function.
Otherwise, there is a risk of reusing the same stored net_buf for
multiple consecutive HCI events in case the controller sents duplicate
or invalid event packets.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-04-11 16:57:37 +02:00
Gerard Marull-Paretas
0ebe14beb4 sys: util: migrate all files to DIV_ROUND_UP
ceiling_fraction is deprecated, use DIV_ROUND_UP.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
Emil Gydesen
d2d3c49f39 Bluetooth: Audio: Shell: BAP scan delegator term sync cmd
Added command to terminate the PA sync as the scan delegator.
This can also be used to cancel any pending PA syncs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
65bbc3673e Bluetooth: Audio: Add bis_sync_req scan delegator callback
Add callback to notify the application about which
BIS it should sync to when requested by the Broadcast
Asssitant.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
56d0947c92 Bluetooth: Audio: Add broadsink sink create
Add support to create a broadcast sink from a PA sync, rather
than using the broadcast sink scan functions.

This allows for the scan delegator implementation to
autonoumsly add broadcast sinks.

This refactors how the broadcast sink uses flags, to
ensure thread safetyness.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
7b9ddc24c0 Bluetooth: Audio: Integrate scan deletagor and broadcast sink
This integrates the Scan Delegator functionality with the
Broadcast Sink functionality. The Broadcast Sink will
automatically update the receive state for the PA and BIG
sync values, based on state of the Broadcast Sink.

Similarly, a request to terminate the BIG or PA sync from
a Broadcast Assistant will terminate the Broadcast Sinks'
PA or BIG syncs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
df490ea222 Bluetooth: Audio: Add Scan Delegator receive state iterate functions
Add bt_bap_scan_delegator_foreach_state and
bt_bap_scan_delegator_find_state to support finding
specific receive states.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
fe75a41134 Bluetooth: Audio: Remove enc_state from scan_delegator_set_bis_sync_state
The field is added/modified by bt_bap_scan_delegator_add_src
and bt_bap_scan_delegator_mod_src. This makes it easier
to modify the BIG sync state, without worrying about
the encryption state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
76002eb025 Bluetooth: Audio: Add cmd_bap_scan_delegator_rem_src
Add the cmd_bap_scan_delegator_rem_src to remove
receive state sources locally as the Scan Delegator.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
43dd0f884e Bluetooth: Audio: Add cmd_bap_scan_delegator_mod_src
Add cmd_bap_scan_delegator_mod_src to modify a BASS
receive state source as the scan delegator in the
shell.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
d35c5540c3 Bluetooth: Audio: Add cmd_bap_scan_delegator_add_src
Add command for the scan delegator to add a source
locally based on a PA sync.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
60da9747c8 Bluetooth: Audio: Scan delegator mod source added
Add function for the scan delegator to modify the metadata
of a receive state locally.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
0005b85e16 Bluetooth: Audio: Fix issue with subgroup metadata for scan delegator
The scan delegator attempted to put the subgroup pointer into the
metadata data, instead of the metadata.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
315aa4dcd8 Bluetooth: Audio: Add BASS server sync test case
Add a test case that tests the scan delegator and
broadcast assistant features when the scan delegator
syncs to a PA without being asked to by the
broadcast assistant.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
f0668550b8 Bluetooth: Audio: Fix bug in bis_syncs_unique_or_no_pref
The check did not work when aggregated_bis_syncs
was 0. Also modfied the function to be more readable.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
781e6fc691 Bluetooth: Audio: Support local add_source for scan delegator
Add support for adding a source from the scan delegator itself.
This is useful if e.g. the broadcast sink syncs to a PA.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
c1836e80da Bluetooth: Audio: Fix issue with bt_bap_scan_delegator_remove_source
The bt_bap_scan_delegator_remove_source failed due to invalid length,
as the buffer supplied to scan_delegator_rem_src should not
contain the opcode.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
42f1868189 Bluetooth: Audio: Move requested_bis_sync from recv_state to internal
The requested_bis_sync value is not part of the BASS receive
state. Moving the field makes it possible to use the
recv_state struct in more situations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
32cfcb9257 Bluetooth: Audio: Add scan delegator broadcast code callback
Add a callback that is called when the broadcast
assistant supplies a broadcast code.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
b37985a898 Bluetooth: Audio: Remove PA sync handling from scan_delegator
The scan delegator will no longer be responsible for
handling the actual synchronization of the periodic
advertisers, and will offload this to higher layers.

The reason for this, is that scanning is a global state,
and should be avoided autonousmly by the stack. The
application is much better suited for handling this.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
b99d989420 Bluetooth: Audio: Add receive_state_updated for scan delegator
Add the receive_state_updated callback for the scan delegator.
This callback will be called whenever a receive state is updated
by any means, giving the upper layers the option to always know
the latest changes.

This commit also refactors the name used for the internal
receive state (which contains additional information), for
the sake of readability.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
3348ed76be Bluetooth: Audio: Remove autonomous BIS sync from scan delegator
The Scan delegator will rely on upper layers calling
bt_bap_scan_delegator_set_bis_sync_state instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
ab1fd85c9e Bluetooth: Audio: Refactor scan delegator set sync state
The bt_bap_scan_delegator_set_sync_state has been refactored
to bt_bap_scan_delegator_set_bis_sync_state, as it will,
going forward, only be used to set the BIS sync states,
and not the PA sync state. The PA sync state will, in a future
commit, but autonousmly handled by the scan delegator
based on the PA sync callbacks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
93045467b4 Bluetooth: Audio: Remove testing guard for scan delegator set sync state
The set sync state will be used for upper layers to set the BIS
sync state. This is due to the fact that the scan delegator cannot
automatically get this information from the ISO layer, unlike
the PA sync state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
e275e0f713 Bluetooth: Audio: Make scan delegator recv state const in API
Since the data is informative only, the struct should be
const.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Emil Gydesen
6bbda2cbfd Bluetooth: Audio: Add Scan Delegator dependency for Broadcast Sink
Per the BAP specification, if the Broadcast Sink role is
supported, then the Scan Delegator shall also be supported.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-11 11:26:28 +02:00
Marcin Niestroj
850ed72214 Bluetooth: logging: don't imply LOG_FUNC_NAME_PREFIX_*
By default there is only CONFIG_LOG_FUNC_NAME_PREFIX_DBG=y enabled. When
both Bluetooth (CONFIG_BT=y) and logging (CONFIG_LOG=y) subsystems are
enabled, then other CONFIG_LOG_FUNC_NAME_PREFIX_{INF,WRN,ERR}=y options are
pulled in as well using an 'imply' Kconfig command indirectly from
`CONFIG_BT_LOG`. This behavior was introduced recently as part of
commit af01a0f313 ("Bluetooth: Logging: Move all logging symbols
together") with no explicit reason provided.

Pulling in LOG_FUNC_NAME_PREFIX_* options automatically with (CONFIG_BT=y
&& CONFIG_LOG=y) blows up flash usage. As an example of downstream project
(nRF52840-based, with Bluetooth and WiFi connectivity), it increases flash
usage from 473668 bytes to 487856 bytes. This seems "only" 3% difference,
but this is actually a lot when there is no good reason why this happens.
Downstream users quite often compare flash sizes of subsequent Zephyr
releases and this 3% footprint increase might be a blocker at some point.
Additionally, it is not trivial to find the root cause of footprint
increase for most (non-expert) users.

The reason why there is so much footprint overhead because of
CONFIG_LOG_FUNC_NAME_PREFIX_*=y is because each function in the
codebase (be it Zephyr or downstream application) that contains logging
macros (LOG_{DBG,INF,WRN,ERR}()) is bloated because the function name has
to be included in the output image.

Remove 'imply LOG_FUNC_NAME_PREFIX_*' commands from 'menuconfig BT_LOG'
option, so that flash usage does not increase too much. Those logging
options are not enabled by other subsystems, so Bluetooth should not be an
exception here.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-04-08 12:34:07 +02:00
Pavel Vasilyev
0d7c7eb4c9 Bluetooth: Mesh: Remove incorrect opcode check in RPR Client
RPR Client doesn't send RPR_OP_LINK_REPORT and therefore it can't wait
for it using ack ctx. It should have been RPR_OP_PDU_OUTBOUND_REPORT
to cover a case where Outbound PDU transmission failed. But in this case
the link status will be non equal to BT_MESH_RPR_SUCCESS (see pb_error in
rpr_srv.c) and the link state will be set to idle. And the client will
reset the link together with ack ctx.

When bearer user (provisioner.c) sends an Outbound PDU, it uses the
callback (see bt_mesh_prov_send in provisioner.c) to send a next PDU,
but it doesn't check the error code even though it is provided through
the callback. Therefore calling the callback with error code would
require error handling in provisioner.c.

With ordinary provisioning PB-ADV doesn't call the callback in case of
error, but closes the link by timeout if doesn't receive ACK (see
prov_send_adv in pb_adv.c). PB-GATT always calls the callback with
error code 0 once the PDU is transmitted (see buf_send in pb_gatt.c).

Thus this change aligns RPR Client implementation with other bearers.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-07 13:38:36 +02:00
Szymon Janc
a7eee34339 Bluetooth: Host: Fix legacy OOB pairing as central
When central is sending SMP Pairing Request is it unknown if
pairing will be legacy or LE SC so set OOB flag if any OOB
data is present and assume to peer device provides OOB data
that will match pairing type.

This was affecting following qualification test cases:
SM/CEN/OOB/BI-01-C
SM/CEN/OOB/BV-01-C
SM/CEN/OOB/BV-03-C
SM/CEN/OOB/BV-09-C

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2023-04-07 13:36:41 +02:00
Emil Gydesen
3d3e692190 Bluetooth: Audio: Add missing null checks in mpl
There were a missing NULL check for the track segment in
paused_state_command_handler when performing the segment
operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
695f85e29d Bluetooth: Audio: Add MCC verification of read object IDs
Add check to verify that the object IDs we receive from
the server are valid.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
9c129c5bc7 Bluetooth: Audio: MCC memset discover params for included
The discovery parameters may contain values from previous
discovery calls. The simply and future proof solution to
this is to simply memset it before using it.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
b7c2629a6f Bluetooth: Audio: Add value_handle check to MCC subscribe cb
If the subscribed callback is called with value_handle = 0,
then it should not be treated as a subscription complete.

This will happen when bt_mcc_discover_mcs is called, as
reset_mcs_inst unsubscribed to all characteristics before
discovering again.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
9e823184e2 Bluetooth: Audio: Add value check for bt_mcc_set_playing_order
Add check for the (playing) order value, to verify that is it
a valid value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
9ebad924ac Bluetooth: Audio: Add input validation for bt_mcc_send_search
Add validation of the search pointer and len value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
e7770a6a7e Bluetooth: Audio: Add BT_MCS_VALID_OP
Add the BT_MCS_VALID_OP macro to verify MCS opcodes for
both the MCC and MCS implementations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
32cd16cfac Bluetooth: Audio: Add BT_MCS_VALID_OBJ_ID
Add macro BT_MCS_VALID_OBJ_ID to verify the OTS Object
ID before attempting any OTS operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
67acec1d6f Bluetooth: Services: Add macro for verifying OTS object ID
Add BT_OTS_VALID_OBJ_ID which verifies if an object ID
is valid.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-07 11:29:54 +02:00
Emil Gydesen
4bb8b2523f Bluetooth: shell: Guard adv_opt with CONFIG_BT_BROADCASTER
The advertising options are only valid if we are a
GAP broadcaster.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-06 15:37:30 +02:00
Vinayak Kariappa Chettimada
8c3c33a970 Bluetooth: Controller: Fix compile error due to missing DF include
Fix compile error due to missing Direction Finding header
file include.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-04-06 12:57:20 +00:00
Kumar Gala
804af856f8 bluetooth: Fix linking issues with armclang
Various bluetooth tests fails to link because bt_le_ext_adv_set_data
can't be resolved.  Solve this by adding a check CONFIG_BT_EXT_ADV
around use of bt_le_ext_adv_set_data.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-05 19:32:34 +02:00
Pavel Vasilyev
62191ba8fd Bluetooth: Mesh: Add async API to Private Beacon Client
Add asynchronous API to Private Beacon Client.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-04 14:32:57 +02:00
Pavel Vasilyev
3a2dc591d4 Bluetooth: Mesh: Use bt_mesh_msg_ackd_send API in Private Beacon Cli
Replace duplicate code in Private Beacon client with
bt_mesh_msg_ackd_send API.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-04-04 14:32:57 +02:00
Emil Gydesen
856a20bcc6 Bluetooth: Add missing dependency for PAST feature
The PAST sender needs to support periodic advertising
and the PAST receiver needs to support periodic advertising
sync.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-04 14:31:17 +02:00
Emil Gydesen
f3af19618b Bluetooth: BAP: Shell: Add check for uuid sizes
The check is very unlikely to be needed, but fixing
warning about assigning ARRAY_SIZE to an uint8_t value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-04 14:30:34 +02:00
Emil Gydesen
6dface9947 Bluetooth: Audio: Add select BT_GATT_DYNAMIC_DB for audio services
Many/most LE Audio services are dynamically registered,
but have been enabled without BT_GATT_DYNAMIC_DB.

Add select BT_GATT_DYNAMIC_DB for the services. Select
was used instead of depends on to make it simpler
to enable them.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-04-04 13:36:26 +02:00
Mariusz Skamra
05540b2c4d Bluetooth: audio: iso: Remove code duplicates
This removes duplicated code related to bap iso binding/unbinding.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-04 13:36:17 +02:00
Mariusz Skamra
9cddbabc6f Bluetooth: audio: endpoint: Remove redundant conditional
This fixes redundant check, as CONFIG_BT_BAP_UNICAST_CLIENT
enables CONFIG_BT_BAP_UNICAST.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-04 13:36:08 +02:00
Mariusz Skamra
92d6b78fe6 Bluetooth: audio: Introduce helper BT_AUDIO_RX(TX) flags
This adds new hidden compilation flags that indicate whether the
implementation is configured to be able to receive/transmit audio data.
The flags are profile agnostic to loosen dependencies between
modules/services.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-04-04 13:35:56 +02:00
Théo Battrel
ff10a9cf23 Bluetooth: Host: Remove unnecessary guarding
Remove unnecessary guarding. With `BT_DEBUG` removed, those conditions
were not needed anymore.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-03-31 14:01:33 +02:00
Szymon Czapracki
33bf1fa0c6 Bluetooth: audio: Expand AICS API
This commit adds new API functions for AICS
Setting automatic/manual only gain modes
Setting mute disabled
Use new functions in btp.vcp

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2023-03-31 09:20:15 +02:00
Kumar Gala
b4d4e30e9b bluetooth: fix armclang compiler warnings with is*() functions
We get compile warnings of the form:

error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-31 09:19:16 +02:00
Mariusz Skamra
fc54859645 Bluetooth: audio: ascs: Handle ascs_ase_read with NULL conn
If the callback is called with NULL conn, just return ASE Idle state
value.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-30 13:48:22 +02:00
Mariusz Skamra
f38c2633e7 Bluetooth: ascs: Remove redundant ase_id check
The ASE_ID is assigned locally via preprocessor macro, thus it's ensured
to be valid.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-30 13:48:22 +02:00
Emil Gydesen
630f6a7d82 Bluetooth: BAP: Store biginfo data in broadcast_sink->codec_qos
Store information from the biginfo in a
broadcast_sink->codec_qos struct, and add a reference to that struct
when syncing, so that the stream->qos contains a valid struct
with properly initialized information.

This also adds a guard for the codec_qos.latency as that
is not set nor used by the broadcast sink (as it is
not available).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-30 10:40:13 +00:00
Emil Gydesen
114e45eb2a Bluetooth: BAP: Broadcast Sink BASE contains presentation delay
The presentation delay is now properly stored in
the BASE struct.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-30 10:40:13 +00:00
Théo Battrel
9b8b58c70b Bluetooth: Logging: Remove BT_DEBUG
Remove Kconfig symbol `BT_DEBUG`. It was not useful anymore with the
previous logging updates.

Replace it, where it was used, by the file local debug symbol.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-03-30 10:40:01 +00:00
Szymon Janc
ee48754af3 bluetooth: host: Fix checking if LTK is present
conn->le.keys are set on-demand when actual security action happens and
it is possible that permission check needs to happen before those.

This fix regression in following qualification test cases:
GAP/SEC/AUT/BV-23-C
L2CAP/LE/CFC/BV-25-C
L2CAP/ECFC/BV-32-C

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2023-03-29 15:54:47 +00:00
Szymon Czapracki
6fd7b3bac6 bluetooth: audio: Fix TBS call stale state
This commits fixes a call staying in dialing state
after originate.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2023-03-29 15:52:32 +00:00
Szymon Janc
8fe734c7ac bluetooth: host: Add common helper for checking LTK presence
Both L2CAP and GATT have same requirements with regards to error code
on no encryption when LTK is or isn't present.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2023-03-28 16:15:58 +00:00
Szymon Janc
dc1ca29ca0 Bluetooth: host: Fix ATT error code on GATT authentication procedure
“Insufficient Encryption” shall be returned only if link is not
encrypted and proper LTK is present, otherwise “Insufficient
Authentication” shall be used.

Core Specification 5.4 Vol. 3 Part C 10.3.1

"If neither an LTK nor an STK is available, the service
request shall be rejected with the error code
“Insufficient Authentication”.
Note: When the link is not encrypted, the error code
“Insufficient Authentication” does not indicate that
MITM protection is required.
If an LTK or an STK is available and encryption is
required (LE security mode 1) but encryption is not
enabled, the service request shall be rejected with
the error code “Insufficient Encryption”."

This was affecting GAP/SEC/AUT/BV-11-C qualification test case.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2023-03-28 16:15:58 +00:00
Mariusz Skamra
6ba2839f6f Bluetooth: audio: ascs: Unbind endpoint in idle state
This moves duplicated bt_bap_iso_unbind_ep function call to
be handled when ASE enters BT_BAP_EP_STATE_IDLE state.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
4d1f9973ed Bluetooth: audio: ascs: Fix double bt_bap_stream_detach call
This fixes possible double bt_bap_stream_detach() function call.
The bt_bap_stream_detach() called from ascs_ep_set_state
state BT_BAP_EP_STATE_IDLE handler.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
a6cdb12572 Bluetooth: audio: bap_stream: Remove reference to conn internals
This removes the usage of conn internal API in bap_stream.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
1abee09a8b Bluetooth: audio: Fix declaring conn type object in header file
The fact of having such extern in iso_internal.h forces the source files
that include this header to include conn_internal.h. This breaks the
encapsulation of conn object.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
43d8e92bdd Bluetooth: audio: ascs: Fix ISO server listen incorrect behavior
This fixes incorrect behavior of ISO server listen that was not handling
the case of two endpoints sharing the same CIS/CIG and the endpoints
belonging to different connections.

Fixes: #51552
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
58de595c70 Bluetooth: audio: ascs: Register ISO server on ASCS init
This moves the ISO server registration to bt_ascs_init.
When the ASCS gets cleaned up (the callbacks are unregistered), the ISO
server gets unregistered.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
08aedc66dd Bluetooth: audio: ascs: Make use of SYS_SLIST_FOR_EACH_CONTAINER_* macros
This cleans up the code a bit by replacing the occurences of
SYS_SLIST_FOR_EACH_NODE with SYS_SLIST_FOR_EACH_CONTAINER(_SAFE)
so that the explicit CONTAINER_OF() usage is not needed.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
710103db1d Bluetooth: iso: Add bt_iso_server_unregister function
This adds function that unregisters previously registered ISO server.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
f5b31c21a9 Bluetooth: audio: ascs: Fix Response_Code for mandatory opcodes
This fixes invalid Unsupported Opcode Response_Code that
happened to be sent in ASE Control Point notification
as the response to operation initiated with Mandatory opcode
to support.
When the Unicast Server callbacks are not registered, every
operation that is initiated by client will fail with
Unspecified Error instead.

Fixes: #56139
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
e9a878c072 Bluetooth: audio: ascs: Fix ASE leak if codec config failed
This fixes ASE that is not returned to pool when Codec Config
operation failed. The ASE is allocated in Codec Config operation
context. With this fix, if the operation failed to complete,
the ASE is returned back to the pool, so that it can be allocated
again by this or other client.

Fixes: #56138
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
5909a00a00 Bluetooth: audio: ascs: Minor refactor of ASE allocation
This removes redundant bt_ascs_ase_get_from_slab function and moves it's
functionality to ase_new(). It's sane, because the ASE shall be
allocated from ase_new() function context only.
bt_ascs_ase_return_to_slab() has been renamed to ase_free() to follow
the naming convention. Furthermore, few logs have been fixed/added.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
ee754fd020 Bluetooth: audio: ascs: Remove redundant check
The ID is ensured to be valid before ase_new() function is called, as
the client request is already validated.
On the other hand, if function is called from server initiated procedure
context, the assert shall occur as it indicates stack issue.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Mariusz Skamra
31aa555890 Bluetooth: audio: ascs: Cleanup ASCS on callback unregister
This adds cleanup of ASCS that is called when upper layer unregisters
it's callbacks. Without callbacks registered, the service is unusable.
The ASE's that were in non-idle state stay in this state, because the
implementation returns an error on every operation that is performed by
the client. The cleanup added moves all the ASE's to idle state.

Fixes: #56111
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-28 15:07:09 +02:00
Krzysztof Kopyściński
3322bdce10 Bluetooth: Mesh: fix blob_cli.c build with Clang
There should be logic OR, not bitwise OR in update_missing_chunks.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-28 15:06:44 +02:00
Krzysztof Kopyściński
fc2dcc4665 Bluetooth: Mesh: save stream mode in io_open()
Mode affects access to flash aread for `block_start`. When mode is set
to `BT_MESH_BLOB_READ` function return early, and because
`BT_MESH_BLOB_READ = 0` this is default behaviour. For write flash area
must be erased to allow driver to write there new data - bits can only
be pulled down, so overwrite will not be permitted.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-28 15:06:44 +02:00
Théo Battrel
9c69f29d0d Bluetooth: Logging: Deprecate BT_DEBUG_LOG
Deprecate Kconfig symbol `BT_DEBUG_LOG`. With the new `BT_LOG` having
the same effect, `BT_DEBUG_LOG` is not useful anymore and shouldn't be
used.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-03-28 10:33:24 +02:00
Théo Battrel
af01a0f313 Bluetooth: Logging: Move all logging symbols together
Move all Kconfig symbols related to Bluetooth logging into the newly
created `Kconfig.logging`. The logging symbols are now grouped by into a
menu "Bluetooth logging". Closely related symbols are grouped with each
others. For example, audio related logging symbol are found behind a
submenu "Audio" inside the "Bluetooth logging".

The deprecated logging symbols have also been moved in a submenu of
"Bluetooth logging", it's easier to avoid them so.

Behavior of the Bluetooth logging system:

When `LOG` symbol is selected, if Bluetooth is enabled (`BT` symbol
selected), the Bluetooth logging is enabled.

If the user does not set any log level, the Bluetooth logging symbols
will inherit the log level of `BT_LOG_LEVEL`. If the user does not set
the level of `BT_LOG_LEVEL`, the default log level will be the one
defined by the logging subsystem. Which currently is `LOG_LEVEL_INF`.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-03-28 10:33:24 +02:00
Aleksandr Khromykh
9011a067f2 Bluetooth: Mesh: split rpr cli ack ctx for provisionning and scanning
PR adds 2 acknowledgment contexts to RPR client to handle
scanning and provisioning in parallel.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-03-27 13:20:33 +00:00
Chris St John
1c0ade0051 Bluetooth: Audio: fix possible overflow in BASE LTV decode
Consistently process BIS data, codec data and codec metadata.
Range check count of data received so that buffer overflow cannot occur.

Signed-off-by: Chris St John <chris_st._john@bose.com>
2023-03-27 09:49:58 +02:00
Vinayak Kariappa Chettimada
ae5b424a2b Bluetooth: Host: Fix handling of incomplete data status adv reports
When receiving extended advertising reports with incomplete
data status, it is not necessary to mark for recovering from
currently assembled fragments, but rather drop them and
start a fresh assembly of subsequently received extended
advertising reports.

Timing changes in the Controller cause Periodic Advertising
PDUs AUX_SYNC_IND + AUX_CHAIN_IND to be placed between
primary channel ADV_EXT_IND and AUX_ADV_IND. This causes the
Controller to generate alternating incomplete and complete
data status reports, exposing the Host bug that is fixed in
this commit.

Relates to commit ba09a252ec ("bluetooth: host: refactor
bt_hci_le_per_adv_report data reassembly").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-24 17:36:32 +00:00
Emil Gydesen
dd5e476f86 Bluetooth: Audio: Shell: Add CAP Acceptor Set Member AD data
Add automatic adding of the CAP Acceptor Set Member AD data.

This also moves the CAP Acceptor service data into the
cap_acceptor.c shell implementation.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-24 17:35:11 +00:00
Vinayak Kariappa Chettimada
b161c7fca4 Bluetooth: Controller: Fix ticker to reduce RTC min compare offset
Fix ticker to explicitly trigger worker when ticks_to_expire
is less than or equal to elapsed time.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-24 12:10:37 +01:00
Vinayak Kariappa Chettimada
925066ae1f Bluetooth: Controller: Continuous scan with ticks_slot_window
Use ticks_slot_window for continuous scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-24 11:32:42 +01:00
Vinayak Kariappa Chettimada
852b3e9e17 Bluetooth: Controller: Reschedule unreserved ticker with slot window
Update ticker implementation to reschedule unreserved ticker
that use ticks_slot_window.

This will avoid unreserved ticker from continuously
overlapping with reserved tickers. And the change is
required to reduce processing overheads before reserve
ticker timeout callback executes.

Unreserved tickers with ticks_slot_window will always yield
to any colliding reserved or unreserved tickers.

The implementation moves unreserved tickers (no ticks_slot
value, in this case continuous scan window) to end of a
colliding reserved/unreserved ticker so that reserved
tickers (like central role) do not have high overheads due
to unreserved ticker's prepare (scanner) be preempted
everytime before reserved ticker's prepare (central).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-24 11:32:42 +01:00
Emil Gydesen
b7e265265d Bluetooth: BAP: Do not allow start op when CIS is connecting
When the CIS is connecting we should not allow sending the
receiver start ready command.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-24 09:17:07 +01:00
Anders Storrø
09a32928aa Bluetooth: Mesh: RPR cli @ mod elem 0 check
Add check to the Remote Provisioning Client model init call
that verifies that the model is located at the root element.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2023-03-23 15:43:29 +01:00
Emil Gydesen
6fc8ca7863 Bluetooth: iso: Add misisng bt_conn_unref in error cases
The ISO hci_le_cis_req event handler was missing
calls to bt_conn_unref and bt_iso_cleanup_acl to properly
clearn up the reference counters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-23 08:56:07 +00:00
Emil Gydesen
7ec4a6a19e Bluetooth: host: df: Add missing bt_conn_unref in error cases
Added missing bt_conn_unref where bt_conn_lookup_handle is
called, but where the function returns without providing the
conn pointer to the caller.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-23 08:56:07 +00:00
Emil Gydesen
317bd5af30 Bluetooth: Host: Missing unref for PAST sync_info
When we supply the conn pointer of the remote device that
provides the PAST information, we do a lookup on the
conn_handle using bt_conn_lookup_handle which takes a
reference count. This count is never dereferenced again.

This commit adds calls to bt_conn_unref to ensure that we
do not keep the reference count after the function
returns.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-23 08:56:07 +00:00
Jonathan Rico
c84fdfe438 Bluetooth: controller: fix kconfig dependency
BT_TICKER_EXT is being selected undiscriminately, but it's a Zephyr
controller feature.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-03-22 21:20:22 +01:00
Szymon Janc
1ebb49eeee bluetooth: ascs: Fix NULL pointer dereference in ascs_ase_read
"The (ATT attribute read) callback can also be used locally to
read the contents of the attribute in which case no connection
will be set."

This means that callback may be called with NULL conn. Since
for ascs_ase_read NULL conn object have no meaning just return
error.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2023-03-22 13:51:58 +01:00
Mariusz Skamra
b8d441842a Bluetooth: audio: ascs: Add cleanup function
This adds ascs_cleanup() function guarded by ZTEST_UNITTEST. The purpose
of it is to clean up the ASCS between the tests.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-22 11:39:18 +01:00
Omkar Kulkarni
a5057e96d1 bluetooth: mesh: Do not skip PDU forwarding on ADV
Fixes a bug where goto statement results into network layer skipping
the forwarding of unicast message on the ADV bearer, if the message
gets succesfully sent on the GATT bearer. This is undesirable. Node
has no knowledge of which external entity has which unicast address.
It may be possible that Proxy node can deliberately add unicast
addresses of other nodes to the whitelist to receive some traffic
for sniffing.

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
2023-03-22 11:38:51 +01:00
Magdalena Kasenberg
57784df5f0 LE Audio: Refactor server ASE callbacks to return rsp object
From now app layer is able to return explicit response code and
reason that will appear in ASE Control Point notification.

Fixes issues of ASCS/SR/SPE/BI-(07/08/09)-C PTS test cases, where
PTS was receiving wrong response codes and reasons.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
2023-03-22 11:38:37 +01:00
Troels Nilsson
714d74b77b Bluetooth: controller: Use new ticker feature to get offsets
Updated the 3 places in extended advertising where the ticker was
previously inquired about the expiration of another ticker ID in a
separate mayfly (adv_aux, adv_sync and adv_iso). It will now use the
new ticker feature where another ticker IDs expiration info will be
added to the callback.

Channel map updates are now handled in ticker_cb and applied immediately
if the ticker is not running

Signed-off-by: Troels Nilsson <trnn@demant.com>
2023-03-22 08:57:37 +00:00
Troels Nilsson
e990ab941d Bluetooth: controller: Add option for ticker to return expiration info
It is now possible (via the extended ticker interface) to ask for
expiration information for another ticker ID to be returned in the
ticker callback. This utilises the extended ticker interface and a
callback function with a different context to keep the current ticker
interface as unchanged as possible.

Signed-off-by: Troels Nilsson <trnn@demant.com>
2023-03-22 08:57:37 +00:00
Pavel Vasilyev
08f4a82038 Bluetooth: Mesh: Remove deprecated health API
Deprecated Health client and server API has been deprecated for two
releases: 3.2.0 and 3.3.0.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-22 09:35:01 +01:00
Ahmed Moheb
fac21b3616 tests: bluetooth: host: Add UT for bt_pub_key_gen()
Unit test project for bt_pub_key_gen().
This is part of subsys/bluetooth/host/ecc.c unit testing.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2023-03-22 09:33:42 +01:00
Ahmed Moheb
3c76bd06e4 tests: bluetooth: host: Add mocks for ecc.c
Add required mocks to be able to compile/test /bluetooth/host/ecc.c

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2023-03-22 09:33:42 +01:00
Théo Battrel
483126f492 Bluetooth: Host: Move new bt_data functions to data.c
Move newly added `bt_data_get_len` and `bt_data_serialize` from `ead.c`
to `data.c`.

Also, removed unnecessary include of `zephyr/kernel.h`.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-03-21 18:17:52 +00:00
Théo Battrel
a693b9b33b Bluetooth: Host: Add Encrypted Advertising Data
Create a new Bluetooth library and add Encrypted Advertising Data to it.

Encrypted Advertising Data is a new feature from the Bluetooth Core
Specification 5.4. It provides a way to communicate encrypted data in
advertising, scan response and EIR packets. To do that it introduce a
new advertising data type called `Encrypted Advertising Data`. Also, it
introduce a new characteristic called `Encrypted Data Key Material`,
this provides a way to share the key material.

The library add two main functions `bt_ead_encrypt` and
`bt_ead_decrypt`.

Two helper functions are added to `bluetooth.h`. `bt_data_get_len` and
`bt_data_serialize`, the first one allow the user to get the total size
of a set of `bt_data` structures; the second one generate a spec
compliant bytes array from a `bt_data` structure. The last one is useful
because `bt_ead_encrypt` take as input those kind of bytes array.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-03-21 13:39:09 +02:00
Vinayak Kariappa Chettimada
643723479f drivers: flash: nRF: Move sync ticker to Subsys Bluetooth Controller
Move the SoC Flash nRF sync ticker implementation into
Bluetooth Controller Subsystem folder, as internal headers
are included.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-21 12:33:32 +01:00
Vinayak Kariappa Chettimada
b9f9f1ba9c Bluetooth: Controller: Refactor CMakelists.txt for consistency
Refactor the Bluetooth Controller's CMakelists.txt to
consistently use zephyr_library_sources_ifdef() and
zephyr_library_include_directories_ifdef().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-21 12:33:32 +01:00
Mariusz Skamra
fef4c4e7ea Bluetooth: audio: ascs: Fix ASE release from QoS configured
This fixes ASE release from QoS configured state.
The `ops->released` callback was not called and the `bt_ascs_ase`
was not returned to the pool, because `stream` object was already
detached.

Fixes: #55900
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-21 09:38:16 +01:00
Mariusz Skamra
1ece7a6779 Bluetooth: audio_ ascs: Fix possible dereference of free'd ASE
This fixes possible dereference of free'd bt_ascs_ase object.
The ASE without ISO connection that goes to Releasing state will be
automously transitioned to Idle state. Thus, the `ase` object might not
be vaild anymore.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-21 09:38:16 +01:00
Mariusz Skamra
14bd189f00 Bluetooth: ascs: Fix ASE Codec Config PDU length validation
This moves ASE Control PDU length validation before request processing.
If the PDU length is not as expected, the operation shall be considered
as invalid. Thus shall be rejected.

ASCS_v1.0; 5 ASE Control operations
"A client-initiated ASE Control operation shall be defined as an invalid
 length operation if the total length of all parameters written by the
 client is not equal to the total length of all fixed parameters plus
 the length of any variable length parameters for that operation"

Fixes: #55747
Fixes: #55748
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-21 09:37:40 +01:00
Emil Gydesen
c97fa8fda3 Bluetooth: Audio: CAP initiator streamline procedure states
Add new helper functions to increase readability and to
ensure correctness when aborting procedures.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
3186fce98e Bluetooth: Audio: Shell: Use same streams and group for BAP and CAP
Use the same unicast streams and group for the BAP and CAP
shell commands. This results in maximum flexibility, as well
as the niceness of use from CAP, as well as less memory usage.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
3ab925ecef Bluetooth: Audio: CAP Initiator handle unexpected ASE changes
When performing the CAP Unicast Start procedure, the remote
server(s) may change the state of the ASE before the procedure
is complete.

If the state change is unexpected, we stop the procedure and
call the callback, and then the caller can decide what to
do after that (presumably call the stop procedure for the
streams that may be setup).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
90537df38a Bluetooth: Audio: Add CAP unicast stop shell command
Add shell command for the CAP unicast stop procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
9ce647ba79 Bluetooth: Audio: Implement CAP unicast stop procedure
Implements the CAP unicast stop procedures, which is used
to stop (either disable or release) multiple streams.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
67925d397a Bluetooth: Audio: Add CAP unicast update shell command
Add shell command for the CAP unicast update procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
f7f69b6ff0 Bluetooth: Audio: Implement CAP unicast metadata update
Implement the CAP unicast metadata update procedure.

The procedure lets an application update the metadata of one
or more CAP streams in a single function call, while also ensuring
that the provided metadata follows the requirement from CAP.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
6866cd30e8 Bluetooth: Audio: Add support for CAP unicast start in shell
This modifies the audio.c shell module to support
multiple connections.

This adds support for the cap_initiator unicast-start command,
which supports multiple endpoints on multiple devices.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Emil Gydesen
b71f9f2702 Bluetooth: Audio: Implement CAP unicast audio start
Implement the CAP unicast start procedure, which
will put one or more CAP streams from the idle state
to the streaming state, across or more ACL connections.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-21 09:35:05 +01:00
Krzysztof Chruscinski
369ffb4929 hal_nordic: Add protection against resource conflict (take 2)
Commit will be squeezed once agreement is reached.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-03-20 16:59:40 +01:00
Krzysztof Chruscinski
5af49c1e35 hal_nordic: Add protection against resource conflict
Add check in CMake files to prevent resource overlap for
TIMER0, TIMER1, RTC0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-03-20 16:59:40 +01:00
Krzysztof Chruscinski
9a73b9c80d hal_nordic: Change scheme for RTC and TIMER reservation
In general, RTC and TIMER driver implements counter API but there
are exception when those peripherals are used in a custom way
(e.g. for system timer or bluetooth). In that case, system must
prevent using counter based on a reserved instance. Previously,
it was managed by Kconfig options but that cannot be maintained
when switching to devicetree configuration of the counter driver.

A new approach removes Kconfig options and instead adds static
asserts in the files which are using direct peripherals. Those
asserts check if given node is not enabled in the device tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-03-20 16:59:40 +01:00
Sebastian Panceac
2e7c02bef6 Bluetooth: pairing: OOB: Separate LE SC OOB from legacy OOB logic
Some systems can support only legacy OOB pairing while others only
LE SC OOB pairing.

The existent API function "bt_set_oob_data_flag" was removed.

Two new API functions were added:

 * "bt_le_oob_set_legacy_flag" to signal that legacy OOB pairing is used
 * "bt_le_oob_set_sc_flag" to signal that LE SC OOB pairing is used

The code will now advertise the presence of OOB flag depending
on the type of pairing method(SC vs legacy)

Signed-off-by: Sebastian Panceac <sebastian.panceac@ext.grandcentrix.net>
2023-03-20 16:13:18 +01:00
Krzysztof Kopyściński
8194c34669 Bluetooth: Mesh: allow user to define BLOB ID for bt_mesh_dfu_cli_send
User can now use self-defined BLOB ID for transfer instead of using
random one each time. This allows to send multiple FW Update Start
messages with same BLOB ID, for example to resume previous one.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-20 13:38:40 +01:00
Krzysztof Kopyściński
b0e91368a2 Bluetooth: Mesh: fix FW Update procedure recovery on on DFU Server side
If device rebooted while in `BT_MESH_DFU_PHASE_TRANSFER_ACTIVE` phase
we should not recover into it, but set `BT_MESH_DFU_PHASE_TRANSFER_ERR`
instead. It's because we no longer remember which block is currently
transfered so new FW Update Start must be received and transfer
restarted.

If device rebooted while in `BT_MESH_DFU_PHASE_VERIFY_OK` it means
we didn't manage to apply image before reboot. We should enter
`BT_MESH_DFU_PHASE_VERIFY_FAIL` phase, which will allow to verify it
again and possibly apply. This is with agreement to specification
regarding receiving FW Update Start when FW is already received.

This commit also alligns handle_start with specification: when
FW is already received, we should set phase to
`BT_MESH_DFU_PHASE_VERIFY`, send Status message, then proceed to Verify.
Previously, `verify` was called before sending status, so status
contained phase set to `BT_MESH_DFU_PHASE_VERIFY_OK` or
`BT_MESH_DFU_PHASE_VERIFY_FAIL`. This would prevent DFU Client
enter refresh procedure.

`blob_recover` also expects BT_MESH_DFU_PHASE_TRANSFER_ERR now.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-20 13:38:40 +01:00
Krzysztof Kopyściński
51ff3e630b Bluetooth: Mesh: Do not transfer FW to targets in Verify Phase in DFU
These targets already received FW so there is no point to transfering
it again. What's more, these targets will not accept transfer and will
be dropped by DFU Client. If FW is already received DFU Client should
skip transfer and proceed to refresh procedure.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-20 13:38:40 +01:00
Emil Gydesen
b011c1e36c Bluetooth: BAP: Add missing Unicast client CB NULL check
Add missing check before calling unicast_client_cbs->release.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-20 13:38:33 +01:00
Emil Gydesen
c8e1b1e264 Bluetooth: Audio: Move audio shell to audio directory
Move all audio related shell implementations to the
audio directory, to use the same structure as Mesh.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-20 09:53:34 +01:00
Aleksander Wasaznik
20d747815d Bluetooth: Shell: Remove ad-hoc CHAR_SIZE_MAX
Remove ad-hoc `CHAR_SIZE_MAX` in favor of `BT_ATT_MAX_ATTRIBUTE_LEN`.
The maximum size of an attribute is the same as the maximum size of a
characteristic.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-03-20 09:51:24 +01:00
Aleksander Wasaznik
6b6178be30 Bluetooth: Shell: Make gatt notify more general
Make `gatt notify` take the source handle and the data to send.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-03-20 09:51:24 +01:00
Vinayak Kariappa Chettimada
de9579f297 Bluetooth: Controller: Implement CIS abort_cb to flush tx/rx
Implement a custom abort_cb callback to perform Tx and Rx
flush and adjust the SN/NESN values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-17 16:07:09 +01:00
Vinayak Kariappa Chettimada
0d54ca8761 Bluetooth: Controller: Fix ull_prepare_dequeue for skipped events
Fix ull_prepare_dequeue to not skip events when preempt
does not match the event in the head of the prepare queue.
The head of the prepare queue does not match when
ull_prepare_dequeue has put the head of the queue to the
last of the queue when it is calling lll_resume interface.
This happens when there is already an active event which
needs a preempt timeout to be setup and there is another
non-resume event in the pipeline which now becomes the
head. The fix ensure to restore the order of the events
if a preempt timeout was to be setup.

Currently ull_prepare_dequeue loops through all events
before stopping at the original way the queue was. This is
not efficient and is a scope for improvement in future.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-17 16:06:54 +01:00
Vinayak Kariappa Chettimada
ceaddc81db Bluetooth: Controller: Fix connected ISO time reservation calculation
Fix Connected ISO time reservation that was missing the
event start and end overhead values.
Fix missing event end overhead values in ACL connection
time reservation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-17 16:06:32 +01:00
Morten Priess
00c9580914 Bluetooth: controller: Fix offset for CIG with CISes in different ACLs
Calculate CIS offset of secondary CIS(es) using CIG reference point.
This fixes issue with e.g. two CISes associated with separate ACL
connections.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-03-17 16:06:18 +01:00
Morten Priess
b8c7506681 Bluetooth: controller: Keep CIS/CIG instances until ll_cig_remove
This commit enables having multiple CIS/CIG setups/connects and
teardowns in sequence.

- For central, cig->lll.num_cis is initialized to cis_count and
  untouched until ll_cig_remove. The value shall indicate number of
  allocated instances, to ensure correct CIG traversal.
- Keep CIG/CIS instances for central until ll_cig_remove
- Initialize CIS instance state vars in ll_cis_create, similar to the
  peripheral flow.
- In ll_cig_remove, always release streams and CIG instance. Do not
  remove paths, as this is done from host at bt_iso_chan_disconnected.
- Remove unsued cis_count member in ll_conn_iso_group.
- Use correct function ull_iso_lll_ack_enqueue at LLL flush to have
  data path respected.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-03-17 16:06:18 +01:00
Andries Kruithof
4215854956 Bluetooth: controller: remove refs to LLCP_LEGACY after rebase
Some recent PRs included conditional compilation for
KCONFIG_BT_LL_SW_LLCP_LEGACY, which must be removed.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-03-17 15:05:05 +01:00
Andries Kruithof
e6a3def17b Bluetooth: controller: remove dependency for slot reservation
The slot reservation code is only valid for the refactored LLCP;
a guard was in place to ensure that it was not compiled in for
legacy controller code. This commit removes this guard

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-03-17 15:05:05 +01:00
Andries Kruithof
729c3e3d83 Bluetooth: controller: remove code related to advanced scheduling
This commit removes the code related to advanced scheduling from
ull_sched.c, since this code only works for the legacy controller.
Implementing advanced scheduling for the refactored LLCP is tracked
in its own issue

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-03-17 15:05:05 +01:00
Andries Kruithof
f6172f3159 Blueotooth: controller: removed delayed notification code
The code that was added for delaying notifications to the host,
which was only implemented for legacy controller, is removed
in this commit

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-03-17 15:05:05 +01:00
Andries Kruithof
2ada005d7c Bluetooth: controller: removing legacy LLCP code
This commit removes the legacy LLCP code including the
Kconfig option
It also updates the babblesim tests, and removes the
tests for the legacy controller

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-03-17 15:05:05 +01:00
Emil Gydesen
70e4e73998 Bluetooth: BAP: Shell: Fix problems with codec and qos config
The copying from the presets to the stream codec and qos
structs were not done in a way that worked. Fixed by doing
a more proper and deeper copy.

This also fixes a small issue with using the wrong
default preset.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-17 14:19:42 +01:00
Pavel Vasilyev
cf5ea49d23 Bluetooth: Mesh: Fix registering GATT Proxy service after reboot
After commit 3486f133e9
GATT Proxy service registration is broken because it is registered from
settings_load() in mesh_commit(). Because mesh_commit() is called before
sc_commit() is called in gatt.c, bt_gatt_service_register() can't be
called yet.

Use k_work to postpone the service registration.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-17 14:19:15 +01:00
Andrei Emeltchenko
e5091db1ad bluetooth: audio: Fix using wrong function check
Correct function check before calling it.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-03-17 14:18:57 +01:00
Emil Gydesen
d0b0bb43d3 Bluetooth: BAP: Remove BT_BAP_UNICAST_CLIENT_PAC_COUNT
The BT_BAP_UNICAST_CLIENT_PAC_COUNT is there due to a merge conflict
gone wrong. Removed again.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-17 14:18:48 +01:00
Vinayak Kariappa Chettimada
1f52e70fe2 Bluetooth: Controller: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values, when computing and comparing
against unsigned variables.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-17 11:48:26 +01:00
Vinayak Kariappa Chettimada
9b3a3ee79b Bluetooth: Controller: Add additional LE Channel Selection tests
Add additional custom LE Channel Selection #2 tests to cover
event and subevent mapping.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-17 11:48:26 +01:00
Vinayak Kariappa Chettimada
c3e6edd402 Bluetooth: Controller: Remove redundant use of local variable
Remove redundant use of local variable chan_idx in the
lll_chan_iso_subevent() function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-17 11:48:26 +01:00
Henrik Møller
86757f5ae5 Bluetooth: controller: Fix channel selection
For ISO-subevents channel selection must use remap table always
-regardless of channel is a mapped or unmapped channel.

Signed-off-by: Henrik Møller <heml@demant.com>
2023-03-17 11:48:26 +01:00
Emil Gydesen
64143fc881 Bluetooth: BAP: unicast released callback only after CIS disconnect
Ensure that the stream released callback is only called after
the CIS has disconnected. Since the ACL disconnect event
may come before the CIS disconnect event, we use the
unicast_client_ep_idle_state in the unicast_client_reset
function to use the existing state verification, and only
after both the ACL and CIS has disconnected, we
finalize the reset of the stream and call the released
callback, assuming that the CIS can be disconnected.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-17 09:31:06 +01:00
Emil Gydesen
bb43c05dc8 Bluetooth: ISO: Set missing CIS disconnecting state
The BT_ISO_STATE_DISCONNECTING was never set when the
CIS was actually in the disconnecting state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-17 09:31:06 +01:00
Emil Gydesen
38095f8818 Bluetooth: BAP: Shell: Delete uni group when all streams released
Previously we assumed only a single stream, and deleted
the unicast group on the first stream released.

Now we wait for all the streams to be released before
deleting the group.

This still assumes that all streams are initiated by us
as the client, and will not work if using the
BAP unicast client and server role concurrently.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-17 09:30:58 +01:00
Emil Gydesen
cf737b510e Bluetooth: BAP: Remove bad LOG_ERR from unicast client
Remove a bad LOG_ERR that should never have been merged.

Added the valuet that was logged to the debug log statement.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-17 09:30:17 +01:00
Emil Gydesen
ed1cc603a7 Bluetooth: BAP: Fix bad ASSERT in ASCS disconn stream handler
The conditions of the assert were incorrect compared to the
text, and caused an assert to happen when it shouldn't.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-17 09:30:09 +01:00
Pavel Vasilyev
3e14c13d8d Bluetooth: Mesh: Use default provisioning protocol timeout in RPR Client
The timeout used upon opening the link with the server relates to the
PB-Remote Link Open procedure, but not to the whole provisioning
procedure. For the provisioning procedure, the timeout should be at
least 60 seconds as explained in section 5.4.4.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-16 16:42:24 +01:00
Pavel Vasilyev
e9a20cc3b6 Bluetooth: Mesh: Restart timer after sending PDU to RPR Server
This commit fixes an issue where the RPR Client gets stuck after sending
PDU to RPR Server (even with segmented flag), but doesn't hear anything
back from the server.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-16 16:42:24 +01:00
Pavel Vasilyev
3a0fa866e4 Bluetooth: Mesh: Fix timeout handling on link opening in RPR Client
This commit fixes an issue, where the RPR Client gets stuck forever
until reboot if it doesn't receive Link Status or Link Report message
when openinig the remote provisioning link.

The RPR_CLI_LINK_OPEN flag was used to control the remote provision link
and protect against receiving an unexpected message, but it didn't cover
a case when neither of messages were received from the RPR Server.
cli->link.state only changes by Link Status or Link Report message and
is set to BT_MESH_RPR_LINK_IDLE when opening the link. Therefore, when
the RPR Client's timer timed out, the client didn't reset its internal
states.

This commit adds an additional state to cover this intermediate state
when the client initiated the link opening but didn't receive any
response.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-16 16:42:24 +01:00
Tomáš Beneš
14138d4a34 Bluetooth: Controller: Add coexistence implementation
To enable Bluetooth controller coexistence feature, there is
implementation of ticker task, which aborts any ongoing radio events
during assertion of the grant pin. This solves the co-existence issue
in the role of the subordinate transceiver.

Signed-off-by: Tomáš Beneš <tomas@dronetag.cz>
2023-03-16 14:37:55 +01:00
Vinayak Kariappa Chettimada
947ef4c96b Bluetooth: Controller: Remove redundant EVENT_IFS_US in BIS timing
Remove redundant EVENT_IFS_US used in Control PDU timing
calculation. The BIG radio event ends with Control Subevent
and hence there is no need to add EVENT_IFS_US at the end
of the BIG event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-16 13:39:03 +01:00
Vinayak Kariappa Chettimada
ca44b34994 Bluetooth: Controller: Fix ISO Sync Receiver reception abort
Fix ISO Sync Receiver PDU reception to enqueue towards ULL
any PDUs that where received before the BIG event in
unreserved timespace is aborted due to overlap with other
radio events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-16 13:38:48 +01:00
Jonathan Rico
169270e911 Bluetooth: host: downgrade select log messages
In the case of a constrained system that uses dynamic channels (ie, not
much initial credits), the user's log would be flooded with those three
messages.

This is not really an error per se as the stack will handle it properly and
reschedule the sending of the buffers as soon as more credits arrive.

Thus downgrading the severity of
- the l2cap messages, as they are only compiled when dynamic channels are
enabled
- the conn message. Reporting the error belongs in the upper layers.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-03-16 12:56:48 +01:00
Emil Gydesen
ac5e4fea90 Bluetooth: Audio: Unicast Client Log more of QoS pref
Add logging of some missing fields of the QoS preference
we receiver from the unicast server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-16 12:55:50 +01:00
Mariusz Skamra
871db2d277 Bluetooth: Move bt_data_parse to dedicated source file
This moves bt_data_parse function outside of hci_core.c.
Having it in separate file makes unit testing easier as the
function do not use kernel objects, thus can be used in unit tests
without a need for adding any mocks.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-16 11:46:36 +01:00
Emil Gydesen
61559bfe3a Bluetooth: Audio: Explicit stream type of unicast client group stream
Make it more explicit that the streams that the value covers are CIS
and not BAP streams.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-16 11:46:20 +01:00
Wolfgang Puffitsch
b525db221c Bluetooth: controller: Avoid the use of weak functions for ISO data path
Avoid the use of weak functions and call the respective functions only
if vendor-specific data path is supported. The weak dummy functions
will not implement the desired behavior anyway. This change makes it
explicit that these functions need to be implemented by the vendor.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2023-03-16 11:46:05 +01:00
Emil Gydesen
f7cf252a8c Bluetooth: Audio: Add special handling of release cp notification
When releasing a stream as the unicast client, we may get
either the ASE state notification with state idle or
the control point notification first. If we get the
ASE state notification first, we pretend we get the
CP notification first, and call the release callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-16 09:18:00 +01:00
Emil Gydesen
88644a775c Bluetooth: Audio: Shell: Add unicast client operation callbacks
Add the unicast client operation callbacks to the shell, simply
printing the values sent by the server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-16 09:18:00 +01:00
Emil Gydesen
68fa04788a Bluetooth: Audio: Add unicast client cp notify callbacks
Add callbacks for control point notifications sent by the
unicast server. These will allow the upper layers to know
if and why a specific operation failed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-16 09:18:00 +01:00
Emil Gydesen
a2057cde3c Bluetooth: Audio: Fixed naming of invalid length ASCS response
The "Invalid Length" response code was called truncated,
which does not match the spec definition.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-16 09:18:00 +01:00
Nirosharn Amarasinghe
b1fe487bb1 Bluetooth: controller: Release of padding PDUs for framed production
Implemented:
-- Released framed padding PDUs when data received in SDUs for a given
   event do not fully utilise BN.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2023-03-16 09:17:19 +01:00
Kumar Gala
0342deb5d9 Bluetooth: Mesh: Fix compiler warning
When building with an LLVM toolchain get the following warning:

bluetooth/mesh/pb_adv.c:774:4: error: expression which evaluates to zero
treated as a null pointer constant of type
'void *' [-Werror,-Wnon-literal-null-conversion]
                        PROV_BEARER_LINK_STATUS_SUCCESS);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix by adding a cast to (void *).

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-16 09:15:38 +01:00
Anders Storrø
ce3557a958 Bluetooth: Mesh: Add SAR srv persistence storage
Adds persistent storage for SAR server RX and TX set cmd parameters.
Also ensures that SAR RX and TX parameters are set back to default values
upon reset of the mesh device.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2023-03-15 15:20:35 +01:00
Andrei Emeltchenko
7e63be14c3 bluetooth: shell: Fix NULL dereference
Fix NULL dereference when dereferencing txing_stream, which was used
instead of default_stream.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-03-15 15:03:12 +01:00
Vinayak Kariappa Chettimada
11ad5bf92c Bluetooth: Controller: Inherit BT_ISO_TX_BUF_COUNT value
Inherit BT_ISO_TX_BUF_COUNT value when BT_ISO is enabled
to set BT_CTLR_ISO_TX_BUFFERS count.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-15 08:49:42 -04:00
Vinayak Kariappa Chettimada
c22f40a358 Bluetooth: Controller: Fix max PDU len radio config for BIS Ctrl PDUs
Fix missing radio configuration that limits the maximum PDU
len on reception to consider that Control PDU can be larger
than the max PDU size in the BIS parameters.
Use dedicated PDU buffer for transmission and reception of
BIG Control PDUs so that it is independent of maximum ISO
PDU length which can be less than BIG Control PDU length.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-15 08:49:42 -04:00
Mariusz Skamra
0b7a335864 Bluetooth: ascs: Fix uninitialized stream object
This fixes "Conditional jump or move depends on uninitialised value(s)"
error seen in valgrind.
The stream object that is allocated by application has to be initialized
as it may contain invalid data.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-15 11:38:11 +01:00
Mariusz Skamra
b5465825f1 Bluetooth: ascs: Remove duplicated logic
The ase_stream_add does the same job as bt_bap_stream_attach that is
called right below.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-15 11:38:11 +01:00
Ludvig Samuelsen Jordet
53091c5056 Bluetooth: Mesh: Fix confusing DFU slot doc
The word "valid" is already in use to mean slots that return true for
`bt_mesh_dfu_slot_is_valid`, whereas `bt_mesh_dfu_slot_foreach` iterates
over all added slots.

Signed-off-by: Ludvig Samuelsen Jordet <ludvig.jordet@nordicsemi.no>
2023-03-15 11:19:18 +01:00
Emil Gydesen
5704b83ea7 Bluetooth: Audio: Shell: Add location to cmd_config
Add support for setting the location value
(BT_CODEC_CONFIG_LC3_CHAN_ALLOC) in the codec configuration.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-15 09:12:33 +01:00
Emil Gydesen
a02a1c19a1 Bluetooth: Audio: Shell: Refactor set_preset
The function is now called get_named_preset and only
returns a named preset. The QoS parameter handling
has been moved to a new function, cmd_stream_qos,
which can be used to set specific QoS for a stream.

The get_named_preset does also no longer set the default
preset, and cmd_preset must be used for that now.

This means that a function like cmd_config no longer
has any side effects, thus making it easier to set up
multiple streams with different presets.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-15 09:12:33 +01:00
Emil Gydesen
b9a4deb429 Bluetooth: Audio: Shell: Replace hacky metadata handling
The hacky handle_metadata_update that copied the metadata to
a variable, since stream->codec->meta could not be modified,
has been replaced with a proper solution now that
stream->codec->meta can be modified.

It still only supports settings the streaming context, but
it is much easier to expand now.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-15 09:12:33 +01:00
Emil Gydesen
2638a04214 Bluetooth: Audio: Shell: Make BAP shell presets constant
Make the BAP shell presets constant. This reflects more
what they represent, and make it not only possible, but also
easier, to modify the individual streams QoS and Codec
configurations, without affecting other streams.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-15 09:12:33 +01:00
Emil Gydesen
3588706d1a Bluetooth: Audio: Shell: Rename streams to unicast_streams
The streams array only contained unicast streams, and
the name should reflect that.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-15 09:12:33 +01:00
Jonathan Rico
b23c330c63 Bluetooth: host: shrink bt_l2cap_le_chan size
Most of this struct is bookkeeping for the dynamic channels.
This isn't needed for e.g., a simple peripheral using GATT.

With a peripheral_hr build for nrf52840dk_nrf52840, we save
280 bytes of RAM.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-03-15 09:11:33 +01:00
Vibhor Meshram
4684006f1b Bluetooth: Audio: Remove "Input" from MICP naming
Removed "Input" from Microphone Input Control Profile.
Release notes kept unchanged.

Signed-off-by: Vibhor Meshram <vibhor69meshram@gmail.com>
2023-03-13 18:34:09 +00:00
Emil Gydesen
e80eca0239 Bluetooth: Audio: Shell: Add automatic receiver ready for server
When a stream for a sink ASE goes into the enabled
state we automatically execute the receiver start ready
operation as the unicast server.

This makes the shell easier to use as the server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-13 14:04:33 +01:00
Aleksander Wasaznik
6648da731b Bluetooth: Host: SMP Keypress Notification
Add experimental support for SMP Keypress Notification.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-03-13 14:04:25 +01:00
Emil Gydesen
4fbabc14c5 Bluetooth: Audio: Shell: Fix bug with txing_stream and bap send
The bap send command would set txing_stream but the
pointer would never be reset.

The txing_stream is mainly to handling the start_sine,
so only {start|stop}_sine commands now sets this.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-13 14:02:41 +01:00
Lingao Meng
81847a57ff Bluetooth: Host: Refine assert message
Add opcode information for cmd timeout assert,
since BT_DBG usually not show in real product,
however we can't see any information just from
assert message.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2023-03-10 11:39:05 +01:00
Andries Kruithof
02eac5cbc2 Bluetooth: controller: fix compile error when VS cmds disabled
When vendor specific commands are disabled by setting
BT_HCI_VS=n the host still calls bt_read_static_addr,
but that function is not compiled in, resulting in a
build error.
Fixed by moving the code in controller/hci/hci.c
outside of the conditional compile

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-03-10 09:39:23 +01:00
Erik Brockhoff
1028cab11e Revert "Bluetooth: controller: use RX node piggy-back for NTF when possible"
This reverts commit 6dbc446342.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-03-10 09:30:23 +01:00
Erik Brockhoff
a40434748c Revert "Bluetooth: controller: fixing CIS establish flow for refactored LLCP"
This reverts commit 1d8acfe5fa.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-03-10 09:30:23 +01:00
Mariusz Skamra
f2d43cf0ac Bluetooth: ascs: Fix missing list initialization
This fixes missing initialization of active ASE list.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-09 17:23:46 +01:00
Pavel Vasilyev
6810e669e1 Bluetooth: Mesh: Reschedule dedicated relay adv sets immediately
Reschedule dedicated relay adv sets immediatey after finishing
advertising of the previous relay message. This allows a node to
relay messages as fast as possible when Relay Retransmit Count state
is zero using less relay adv sets.

When Relay Retransmit Count state is non-zero, the delay doesn't do
anything as the time between pushing a relay message to the host and
triggering adv_sent callback will be greater than this delay. In this
case the relay adv set will send a next message immediately.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-09 17:21:39 +01:00
Andrei Emeltchenko
c574bfcfd2 bluetooth: audio: Fix NULL dereference before NULL check
Fixes NULL dereference before NULL check for conn.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-03-09 17:21:26 +01:00
Emil Gydesen
bdbfcb12ca Bluetooth: Audio: Unicast stream start fix
The unicast client would attempt to send the
receiver start ready opcode to the server for
source ASEs before the CIS was connected, which
is a spec violation.

The code has been refactored to set a boolean,
and then send the receiver start ready opcode on
CIS connection instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-09 17:21:14 +01:00
Pavel Vasilyev
4a59107fc7 Bluetooth: Mesh: Fix compilation issue in access.c
This fixes compilation errors of BabbleSim tests generated by gcc-12
when MOD_REL_LIST_SIZE is zero.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-09 16:02:21 +01:00
Jonathan Rico
da97ab6ee8 Bluetooth: host: gatt: respect BT_GATT_ENFORCE_SUBSCRIPTION
A subscription check was still being done in the
gatt_notify_multiple_verify_params() fn, regardless of the value of
CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION.

This could lead to getting this warning if BT_GATT_NOTIFY_MULTIPLE is
enabled, and the notifications not being sent to unsubscribed peers.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-03-09 11:49:34 +01:00
Szymon Janc
6ca2dac6a3 bluetooth: controller: Fix build with BT_HCI_VS_EXT disabled
[216/319] Building C object zephyr/subsys/bluetooth/controller/
  CMakeFiles/subsys__bluetooth__controller.dir/hci/hci.c.obj
zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c:
   In function 'hci_vendor_cmd_handle_common':
zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c:5459:17:
   warning: implicit declaration of function 'vs_set_min_used_chans';
   did you mean 'll_set_min_used_chans'? [-Wimplicit-function-declaration]
 5459 |                 vs_set_min_used_chans(cmd, evt);
      |                 ^~~~~~~~~~~~~~~~~~~~~
      |                 ll_set_min_used_chans
....
zephyr-sdk-0.15.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../
  ../../../arm-zephyr-eabi/bin/ld.exe: zephyr/subsys/bluetooth/controller/
  libsubsys__bluetooth__controller.a(hci.c.obj): in function
   `hci_vendor_cmd_handle_common':
zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c:5459: undefined
   reference to `vs_set_min_used_chans'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2023-03-09 11:49:14 +01:00
Mariusz Skamra
50d21999fe Bluetooth: ascs: Fix bt_ascs_ase missing cleanup
Once the bt_ascs_ase is taken from the mem_slab, it has to be memset to
override the junk data.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-09 09:45:52 +00:00
Emil Gydesen
72d80b74be Bluetooth: Audio: Move stream_reset before released callback
In the unicast client we should reset the stream before calling
the released callback. This is so that we can reuse the stream object
in the released callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-08 11:07:40 +01:00
Emil Gydesen
136191e936 Bluetooth: Audio: Fix return value for VOCS invalid location
If the location was invalid, we return 0 instead of
an error.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-08 11:07:00 +01:00
Mariusz Skamra
cf7bfc406c Bluetooth: audio: Remove redundant forward declaration
This removes redundant bt_bap_ep declaration, as the structure is
defined right below.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-08 11:06:51 +01:00
Mariusz Skamra
cb1d36afca Bluetooth: audio: ascs: Remove unused includes
This removes unused includes.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-08 11:06:36 +01:00
Mariusz Skamra
1a0e7fa57a Bluetooth: audio: ascs: Remove reference to conn internals
This removes using conn internal API in ASCS.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-07 18:19:08 +01:00
Emil Gydesen
e36caf48b7 Bluetooth: Audio: Rename audio shell commands to bap
Change the shell commands from "audio ..." to "bap ...".

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
26f8db4c61 Bluetooth: Audio: Rename stream.h -> bap_stream.h
Renamed the file to better match what it contains.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
099c13846e Bluetooth: Audio: Fix minor bt_audio -> bt_bap issues
Several places used the bt_audio prefix where it shouldn't.
Also moved the BAP documentation to its own file.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
e2765d7bd5 Bluetooth: Audio: Rename bt_audio_iso to bt_bap_iso
Rename the internal bt_audio_iso struct and API to bt_bap_iso

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
271ff1d1a3 Bluetooth: Audio: Add new bap_lc3_preset and move macros
Added a new header file bap_lc3_preset.h which contains
the definitions of the LC3 (pre)sets defined by the
BAP spec.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
3326863267 Bluetooth: Audio: Rename bt_audio_ep to bt_bap_ep
Rename the bt_audio_ep struct and API to bt_bap_ep
and move the API to bap.h

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
4224b45838 Bluetooth: Audio: Rename bt_audio_unicast_group to bt_bap_...
Rename the bt_audio_unicast_group API to bt_bap_unicast_group
and move the API to bap.h

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
77853f43f2 Bluetooth: Audio: Rename bt_audio_stream to bt_bap_stream
Rename the bt_audio_stream API to bt_bap_stream
and move the API to bap.h

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
e0fc612c93 Bluetooth: Audio: Rename bt_audio_unicast_client to bt_bap_...
Rename the bt_audio_unicast_client API to bt_bap_unicast_client
and move the API to bap.h

Also adds the _bap_ infix to the bt_unicast_client functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
be42429f90 Bluetooth: Audio: Rename bt_audio_broadcast_source to bt_bap_...
Rename the bt_audio_broadcast_source API to bt_bap_broadcast_source
and move the API to bap.h

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
06d00ff5f9 Bluetooth: Audio: Rename bt_audio_broadcast_sink to bt_bap_...
Rename the bt_audio_broadcast_sink API to bt_bap_broadcast_sink
and move the API to bap.h

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
eeae1f096a Bluetooth: Audio: Rename bt_audio_unicast_server to bt_bap_...
Rename the bt_audio_audio_server API to bt_bap_unicast_server
and move API to bap.h.

This also adds the _bap_ infix for bt_unicast_server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Emil Gydesen
7fc051967f Bluetooth: Audio: Add bap prefix to BAP internal files
All internal files that implement BAP now has the
bap_ prefix.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 16:21:44 +01:00
Mariusz Skamra
e33705f64c Bluetooth: audio: ascs: Remove unused variable
This fixes compiler unused variable error

warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
  461 |         struct bt_ascs_ase_status *status;

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-03-07 15:54:58 +01:00
Emil Gydesen
736ec47fb3 Bluetooth: Audio: Add ASCS delay for CIS disconnect
While both the server and client are allowed to terminate
the CIS when a stream is released, it is, per the BAP spec,
the client's responsibilty. This commit modifies it so that
the client will actually get a chance to do its responsibilty
by adding a small delay before our ASCS disconnects the CIS.

The CIS disconnection has kept with a delay, rather than
removed, in case that the Unicast Client is not properly
performing it's responsibility.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 11:12:40 +01:00
Vinayak Kariappa Chettimada
c7835e239f Bluetooth: Controller: Remove mesh low lat bsim test workaround
Remove mesh loopback group test workaround introduced in
commit 2a9cd8ffb1 ("Bluetooth: Controller: Add
EVENT_OVERHEAD_START_US when enabling states").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-07 11:12:23 +01:00
Vinayak Kariappa Chettimada
55c4084c8b Bluetooth: Controller: Fix scan window value corruption
Fix scan window value corruption due to modification of
stored ticks_window value when enabling continuous scan.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-07 11:12:23 +01:00
Emil Gydesen
59a9f8a3b0 Bluetooth: Audio: Add reason to BAP stream stopped callback
Forwards the reason parameter from the ISO disconnect to
the stream stopped callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 09:44:20 +01:00
Emil Gydesen
e75fc5e318 Bluetooth: Audio: Remove pac_cache from unicast_client
Removes the unused pac_pache from the unicast_client.

This moves the storing of the PAC records (in the form of
struct bt_codec) from the stack to the upper layers.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-07 09:44:10 +01:00
Erik Brockhoff
1d8acfe5fa Bluetooth: controller: fixing CIS establish flow for refactored LLCP
Latest modification to LLCP removed 'monitoring' of cis->established
flag in LLCP, relying instead on signal through ULL.

For this to work properly the signal must also be generated, so this is
introduced. Note - checking of cis->established flag could be removed
if caller ensures only calling once (on establish condition)

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-03-06 17:08:42 +01:00
Krzysztof Kopyściński
392f95705c tests: bluetooth: mesh: add Proxy Solicitation to shell
This adds commands to advertise Solicitation PDUs, configure
On-Demand Private Proxy and manage Solicitation PDU RPL.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Krzysztof Kopyściński
d0995541fb Bluetooth: Mesh: add implementation for Proxy Solicitation
This is initial implementation of Proxy solicitation procedure.
This includes:
- support for sending and receiving Solicitation PDUs
- On-Demand Private Proxy functionality (Server and Client) controlling
  behaviour of node after receiving Solicitation PDU
- Solicitation PDU RPL Configuration (Server and Client), which manages
  Replay Protection List for Solicitation PDUs.

Proxy Solicitation allows to enable advertising of Proxy service on node
by sending Solicitation PDUs. These PDUs are not part of Mesh messages;
instead, these are non-connectable, undirected advertising PDUs with
their own format, containing Proxy Solicitation UUID.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michal Narajowski
d95fe3f52b Bluetooth: Mesh: Add support for Models Metadata Page 128
This patch adds for handling Models Metadata Get Page 128.

Signed-off-by: Michal Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Krzysztof Kopyściński
007bca7b63 Bluetooth: Mesh: Add Composition Data Page 1 to shell
Add parsing of Composition Data Page 1 and enable it's support.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Krzysztof Kopyściński
29f07abc89 Bluetooth: Mesh: Add Composition Data Page 1
Composition Data Page 1 contains information about relations between
models. Implementation saves relations into array of tuples
{ptr to base, ptr to extension, relation type} on model initialization
and uses this information to construct Composition Data Page 1.

Appropriate structures and methods were added to API, allowing user to
parse all received data into Composition Data Page 1 formats:
Composition Data Page 1 Element, Model Item, Model Extension Item.

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
0bd0071e4a Bluetooth: Mesh: Add Opcodes Aggregator models to shell
- Add entry for client and server in composition data.
- Add Client commands to aggregate and send messages.

MESH/SR/AGG/BV-02-C requires more key slots.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Michał Narajowski
da5195ea97 Bluetooth: Mesh: Add support for Opcodes Aggregator models
Includes Opcodes Aggregator Server and Client. To use Opcodes Aggregator
client features with some client model, that client should support async
API.

Co-authored-by: Ludvig Samuelsen Jordet <ludvig.jordet@nordicsemi.no>
Co-authored-by: Mia Koen <mia.koen@nordicsemi.no>
Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Pavel Vasilyev
d46480c36b Bluetooth: Mesh: Add shell commands for Private Beacon Client
Add shell commands for Private Beacon Client.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
f9b19010ed Bluetooth: Mesh: Private Beacons
Adds support for private beacon sending and receiving.

Co-authored-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Michał Narajowski
b5d6733d53 Bluetooth: Mesh: Add Transport SAR Configuration models to shell
Add Transport SAR Configuration models to shell.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Michał Narajowski
dd59a45c65 Bluetooth: Mesh: Transport SAR Configuration
Add support for:
- SAR Configuration Client and Server models
- Transport SAR configuration states
- Using SAR Transmitter/Receiver states in segmentation
and reassembly process.

Bsim tests fixes:
- Fix failing replay attack test. The replay attack test doesn't
consider retransmission attempts at the transport layer. When
retransmission happens, SeqNums get increased and the test logic
doesn't work anymore. The simplest fix would be to disable
retransmissions at the transport layer.
- Add device synchronization API to synchronize transport va test.
Device configuration may take different time on transmitter and
receiver. Add synchronisation barrier between devices.
- Fix msg_frnd test. Timing in transport sar behavior has been
changed, which affected test_friend_msg test. Now acknowledgments
are sent much faster and this needs to be considered in the test.
- Fix unicast_low_lat test. Increase number of retransmission
attempts when long segmented message is sent.
- Reduce timeout in kr_old_key test.
- Relax SAR RX state configuration in DFU and BLOB tests.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Co-authored-by: Anders Storrø <anders.storro@nordicsemi.no>
Co-authored-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Michał Narajowski
8a60dfcd51 shell: Add Large Composition Data Server
- Adds Large Comp Data Server and Client
- Defines some dummy metadata for Health Server

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Michał Narajowski
df65592d94 Bluetooth: Mesh: Add support for Large Composition Data models
- Adds Large Composition Data Server and Client definitions
- Adds Client API definition
- Adds Health Server Metadata definition
- Refactors Composition Data processing (as a Server) to use common
 methods with Large Comp Data Server

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Co-authored-by: Stine Akredalen <stine.akredalen@nordicsemi.no>
Co-authored-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
f7f3241628 Bluetooth: Mesh: Shell support for remote provisioning
Adds commands in the mesh shell for remote provisioning client
operation, including scanning, provisioning and reprovisioning.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
3c185e1764 Bluetooth: Mesh: Remote provisioning
Adds remote provisioning models rpr_srv and rpr_cli, and exposes them as
a bearer for the provisioning process.

The remote provisioning models provide the following features:
- Remote provisioning of new devices, using a remote provisioning server
  as a proxy.
- Reprovisioning of existing devices, generating a new device key and
  changing addresses and composition data.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Co-authored-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
85431fd69e Bluetooth: Mesh: Add composition data page 128
Composition data page 128 represents the new composition data after a
composition refresh procedure. The implementation stores the old
composition data (before applying a DFU or similar), and uses that as
page 0 if present. As the device has already rebooted by the time page
128 becomes active, its active composition data is page 128, while the
backed up data is the "old" data, which should be shown as page 0.

Co-authored-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
417d328796 Bluetooth: Mesh: DFU and BLOB models in shell
Adds conditional support for the BLOB and DFU models in the mesh shell.
Additionally creates a dummy BLOB stream for testing.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Co-authored-by: Anders Storrø <anders.storro@nordicsemi.no>
Co-authored-by: Ludvig Samuelsen Jordet <ludvig.jordet@nordicsemi.no>
Co-authored-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
Co-authored-by: Mia Koen <mia.koen@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
b054ae364d Bluetooth: Mesh: DFD Server model
Adds support for the Device Firmware Distribution Server model from Mesh
Model specification v1.1.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Co-authored-by: Ludvig Samuelsen Jordet <ludvig.jordet@nordicsemi.no>
Co-authored-by: Anders Storrø <anders.storro@nordicsemi.no>
Co-authored-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
Co-authored-by: Mia Koen <mia.koen@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
529860e72b Bluetooth: Mesh: DFU models
Adds DFU models from the Mesh Model specification v1.1.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Co-authored-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
Co-authored-by: Anders Storrø <anders.storro@nordicsemi.no>
Co-authored-by: Mia Koen <mia.koen@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Trond Einar Snekvik
4302b568cc Bluetooth: Mesh: BLOB models
Adds support for the BLOB Models from Mesh Model specification v1.1.

Co-authored-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
Co-authored-by: Anders Storrø <anders.storro@nordicsemi.no>
Co-authored-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Co-authored-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
Co-authored-by: Ludvig Samuelsen Jordet <ludvig.jordet@nordicsemi.no>
Co-authored-by: Mia Koen <mia.koen@nordicsemi.no>
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Aleksandr Khromykh
ffddd9ffc0 Bluetooth: Mesh: enhanced provisioning authentication
Implementation of the enhanced provisioning authentication (EPA)
that is based on SHA256 and HMAC security algorithms.
OOB authentication mandates EPA usage.

Co-authored-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Aleksandr Khromykh
5ffae6486b Bluetooth: Mesh: add mesh 1.1 global config option
All mesh 1.1 features are gathered behind a KConfig options.
Default is disabled.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Michał Narajowski
1b77e8bbf1 Bluetooth: Mesh: Add Model Receive testing callback
Add a callback similar to net_recv that notifies the application when a
message is received in access layer. This is is useful for testing
purposes (especially automated testing).

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
1c731c714c Bluetooth: Mesh: Refactor bt_mesh_model_recv
Pass only msg context as it is the only thing used from net_rx.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
08f0d1c742 Bluetooth: Mesh: Add a flag for DevKey-only based models
This prevents a Configuration Client from binding an app key to a model
that only supports DevKey-based security.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
7f1b296a0c Bluetooth: Mesh: Do not relay message rejected by Transport layer
Mesh Profile Specification Errata 11341

3.6.4.3 Message error procedure
When the Upper Transport layer receives a message that is not
understood, then the message shall be ignored.
A message that is not understood includes messages that met one or more
conditions listed below:
• The Transport Control message opcode is unknown by the receiving node.
• The Transport Control message size for the Transport Control opcode
is incorrect.
• The Transport Control message parameters contain values that are
Prohibited

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
62aad07968 Bluetooth: Mesh: Check for duplicates in friend queue
Mesh Profile Specification Errata 11302

Section 3.5.5.

When a Friend node receives a message that is destined for a Low Power
node (i.e., the destination of the message is a unicast address of an
element of the Low Power node or in the Friend Subscription List), and
the TTL field has a value of 2 or greater, then the message shall be
processed as follows: If the Friend Queue already contains a message
with the same SEQ and SRC fields as in the received message, or if the
SRC field of the received message is a unicast address of an element of
the Low Power node, then the message shall not be stored in the Friend
Queue. Otherwise, the TTL field value shall be decremented by 1, and
the message shall be stored in the Friend Queue.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
ee3e93148e Bluetooth: Mesh: Change IV Update duration requirement for new nodes
Mesh Profile specification errata 11627

Section 3.10.5:
When a node is added to a network, the node is given an IV Index.
If the node is added to a network when the network is in Normal
operation, then it shall operate in Normal operation for at least
96 hours. If a node is added to a network while the network is in
the IV Update in Progress state, then the node shall be given the
new IV Index value and operate in IV Update in Progress operation
without the restriction of being in this state for at least 96 hours.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
fa107b4b54 Bluetooth: Mesh: Set minimum publish period
Mesh Profile Errata 11392

Section 4.4.3.2.1 Current Fault state:

When the value of a Health FastPublish Period Divisor state is non-zero,
and a Current Fault Fault Array (see Section 4.2.15.1) for at least one
Company ID contains records, an unsolicited Health Current Status
message set to the value of that Company ID and the FaultArray field
containing a sequence of faults representing a sequence of faults in the
Current Fault Fault Array (see Section 4.2.15.1) shall be published
every number of seconds as defined by the value of the Publish Period
divided by the value represented by the Health Fast Period Divisor
state, or every 100 ms (the minimum Publish Period value whichever
is greater.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
2023-03-06 13:52:15 +01:00
Michał Narajowski
91fa9194f0 Bluetooth: Mesh: Fix Heartbeat Pub/Sub Count/Period Log calculation
Mesh Profile Specification Errata 11737 specifies that
Period/Count Log value 0x11 is not defined Log field
transformation in Table 4.1.

Errata 11737 adds value 0x11 to Log field transformation
table with 2-octet value equal to 0x10000 which does not fit into
two octets. This patch changes period calculation to 32-bit precision.
There is also a special case for publication count. If the
log value is equal to 0x11 then the publication count value
should be 0xfffe. When sending Hearbeat Publication Status
message we should return the same value as the one received
in Publication Set so we have to add a case in hb_pub_count_log().

Co-authored-by: Alperen Sener <alperen.sener@nordicsemi.no>
Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-03-06 13:52:15 +01:00
Arkadiusz Kozdra
f5bf1cddda bluetooth: host: Check bounds on num_completed_packets event
If an event with corrupted length arrives, the extra check makes the
handler return early to avoid reading data out of bounds.

Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
2023-03-06 11:16:42 +01:00
Erik Brockhoff
6dbc446342 Bluetooth: controller: use RX node piggy-back for NTF when possible
When possible re-use the already allocated RX node for notifications.
Store (retain) RX node and Link element on RX if NTF could occur.
Pass link element to LLCP (ull_cp_rx()) together with RX node.
New RX node type RETAIN introduced to signal retention

When no RX node is available allocate one and hold off TX on procedures
until such time that a node is available for NTF.

In case waiting for NTF buffer avail is needed, allocate and store TX
node to use for TX once NTF becomes available.

CIS Established (incl. timeout handling) is now handled entirely as a
specific event driven by ull_conn_iso - ie removal of procedure check
of cis->established and cis->expire, as this is doubling mechanism
in the conn_iso context.

Unit test and helpers updated to handle new node type.
Function ull_cp_release_ntf() was used only in unit test, so moved to
helper context.
Updating release_ntf to handle the fact that with piggy-backing in test
context the node used for NTF can be from two different memory pools

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-03-06 09:35:10 +01:00
Erik Brockhoff
80426ddbed Bluetooth: controller: removed unused code
LLCP data struct member fex.sent was set but not used so remove

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-03-06 09:35:10 +01:00
Emil Gydesen
835352c2bb Bluetooth: Shell: Add indication of default_conn in connections cmd
When doing "bt connections" the currently selected ACL (default_conn)
is now indicated with a "*" making it easier to determine which
of the connections is currently selected.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-06 09:34:36 +01:00
Vinayak Kariappa Chettimada
afd4346965 Bluetooth: ISO: Fix BT_ISO_TX_MTU range
In the Bluetooth Core Specification, the minimum
ISO_Data_Packet_Length is 0x0001, hence fix the
BT_ISO_TX_MTU range to allow a minimum value of 1.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-03 09:19:19 +01:00
Aleksander Wasaznik
5233fe5fb9 Bluetooth: Host: Log incomplete adv reports
This gives our users some indication of why they are not receiving
long advertisements.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-03-02 21:19:16 +01:00
Emil Gydesen
8333b12da7 Bluetooth: Host: Add ACL NULL check for ISO conn info
If getting the conn info of an ISO channel, the ISO channel may
not yet have an ACL connection, so we cannot get the
ACL source and destination addresses from the ACL.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-02 17:57:17 +01:00
Vinayak Kariappa Chettimada
afa8e6f23a Bluetooth: Controller: Fix extended scanning for BT_CTLR_LOW_LAT
Fix Extended Scanning support for BT_CTLR_LOW_LAT variant
of the Controller implementation by closing the scan window
for every ADV_EXT_IND PDU received that that ULL_LOW context
is enabled back and ticker job can process the request to
start auxiliary PDU reception. Without the change the
ticker job would only run at the end of the scan window that
caused the auxiliary scan prepare to assert due to delayed
ticker timeout expiry callback.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-03-02 13:46:59 +01:00
Emil Gydesen
6d0c53c959 Bluetooth: Audio: Add addition vol ctlr input checks
Add misisng function parameter input checks to verify
values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-02 10:56:27 +01:00
Arkadiusz Kozdra
1e293a13bc bluetooth: sco: Error out early on null acl
Cleanup unrefs the ACL connection, so ensure it is never null in the
constructor.

Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
2023-03-02 09:59:56 +01:00
Emil Gydesen
f2918b0109 Bluetooth: Audio: Fix MCC discover callback on reconnected issue
With BT_GATT_SUBSCRIBE_FLAG_NO_RESUB the MCC subscriptions would
be resent to the server on reconnection. Since this may trigger an
error, the error will trigger a call to the MCC discover complete
callback.

For MCP We can assume that the server stores the subscriptions if
we are bonded, and thus we can use BT_GATT_SUBSCRIBE_FLAG_NO_RESUB.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-02 09:03:32 +01:00
Emil Gydesen
4b0442ab57 Bluetooth: Audio: Fix missing call to BAP discover cb
If we discover both sink and source ASEs, then we attempt
to subscribe to the ASE CP characteristic twice. However,
if we are already subscribed, then the callback is not called,
and then the 2nd call to discover will not return properly.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-03-01 15:58:15 +01:00
Jonathan Rico
caa88b2cfd Bluetooth: host: gatt: don't use settings API in disconnect cb
When `CONFIG_BT_SETTINGS_DELAYED_STORE` is enabled, reschedule the storage
work immediately instead of processing it in the current context.

When that config is not enabled, process the storage in the current
context.

Processing this work (i.e. using the settings API and its likely
FLASH-based backend) in the current context (cooperative prio) may mess
with the real-time constraints of the application threads.

Fixes #55067.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-03-01 11:10:22 +01:00
Arkadiusz Kozdra
642548daeb bluetooth: host: Check bounds more explicitly
Co-authored-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
2023-02-28 13:23:51 +01:00
Arkadiusz Kozdra
8848380dff bluetooth: host: Check bounds on le_adv_report event
If an event with corrupted length arrives, the extra check makes the
handler return early to avoid reading data out of bounds.

Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
2023-02-28 13:23:51 +01:00
Arkadiusz Kozdra
a000c2e903 bluetooth: host: Check for NULL discovery callbacks
Fixes a segfault if a discovery event happens while discovery is not
active and the discovery callback is null.

Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
2023-02-28 12:48:47 +01:00
Emil Gydesen
838cc543d8 Bluetooth: Services: Set IAS alert level before callback
Fix the order of setting the alert level before the callback.
Without this fix, the alert level would be incorrect if
the upper layers ever tried to perform any other IAS operations
in the callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-27 13:20:33 +01:00
Jonathan Rico
298ae28707 Bluetooth: host: gatt: fix ifdef comment
Forgot to update the ifdef comment when adding another condition.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-27 10:48:15 +01:00
Jonathan Rico
1906b05b10 Bluetooth: host: use ATOMIC_DEFINE for GATT global flags
Use a single bit array instead of multiple atomic_t variables.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-27 10:48:15 +01:00
Jonathan Rico
3486f133e9 Bluetooth: host: prevent registering services in the wrong context
There is a touchy spot where registering a service might result in sending
service changed indications that are not necessary. This is due to a race
condition between the SC work and the GATT DB hash being calculated.

Only allow users to call this API when we know it is safe:
- either before BT is initialized
- or after settings have been loaded (and hash calculated)

Fixes #54047

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-27 10:48:15 +01:00
Jonathan Rico
02edcd6494 Bluetooth: host: calculate GATT DB hash on settings load
Prevent race condtions between the stack and the low-priority thread by
calculating the hash (and acting on it, e.g. for marking peers
change-aware, sending SC indications, etc) in the settings_load() context.

Fixes #54773

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-27 10:48:15 +01:00
Jonathan Rico
b3671666e1 Bluetooth: host: clear ATT pending flag on failure to send
`ATT_PENDING_SENT` wasn't cleared when L2CAP reported an error when sending
the packet. This resulted in the channel being unusable for ever, since we
only clear that bit on a response (that will never be sent).

Found when setting `CONFIG_SYS_CLOCK_TICKS_PER_SEC=32768` in the
`notify_multiple` test. The kicker was the bug didn't manifest when EATT
wasn't enabled:
- we were queuing two unsubscribes back to back in the test
- on UATT we have to wait for a req-rsp pair before enqueuing a new one
- on UATT we only have one channel anyways

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-27 10:32:13 +01:00
Andries Kruithof
226c99b455 tests: bluetooth: add prefix to exposed API
In ull_llcp* some functions used in unittesting did not have
the llcp_ prefix
Although this is not a big issue since they are only used when
testing the module this commit adds the prefix so that we
have a more consistent naming

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-02-24 11:46:39 +01:00
Andries Kruithof
e6ba1eed90 bluetooth: controller: update unittests for LLCP to use proper ZTEST API
Update unittests for the following areas/controll procedures
- API
- collision handling
- invalid PDUs
- unsupported procedures
- buffer allocation
- TX queue
- Data Length Update
- PHY update
- Encryption
- Ping
- Version
- Channel map update
- Min. used channels
- Connection update
- SCA
- Terminate connection
- CTE request
- CIS create
- CIS terminate

Also moved the internal API tests from the ull_llcp* files
to the proper unittest C-file

Unused files  are removed

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-02-24 11:46:39 +01:00
Vinayak Kariappa Chettimada
ade92f4d28 Bluetooth: Controller: Fix mayfly priority check when in ZLI
Fix mayfly_prio_is_equal() function when BT_CTLR_ZLI is
enabled.

When Zero Latency IRQs are used, LLL execution priority
is the Zero Latency IRQ priority and will not be equal
to ULL execution priority.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-24 11:00:43 +01:00
Vinayak Kariappa Chettimada
e409aadf0c Bluetooth: Controller: Fix Peripheral CIS supervision timeout
Fix Peripheral CIS supervision timeout due to missing access
address timestamp capture in subsequent subevents when
anchor point was not sync in the first subevent.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-24 11:00:36 +01:00
Emil Gydesen
5d5dffef76 Bluetooth: Audio: Fix ASCS check for streaming state
Add missing check for receiver_ready in the state
change to enabling state. This change makes the
the check in the state change similar to the check
in ascs_ep_iso_connected

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-24 09:24:34 +01:00
Andries Kruithof
94cfb8dbcf Bluetooth: add decoding for BLE 5.4 version string
The BLE 5.4 specification was recently released. Here the
version strings are updated

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-02-24 09:13:18 +01:00
Andries Kruithof
b02ce97dd0 Bluetooth: controller: update bluetooth version to 5.4
The Bluetooth 5.4 specification was recently released, and has a new
version identifier (0x0D or decimal 13) assigned to it in the
Bluetooth Assigned Numbers.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-02-24 09:13:18 +01:00
Emil Gydesen
300491af34 Bluetooth: Audio: Shell: Audio shell improvements
This commits allows for setting up multiple streams in
a single CIG as the unicast client.

It fixes an issue with the unicast server not using
the configured QoS when transmitting audio data.

Improves upon setting the preset for the different
type of streams.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-23 10:49:53 +01:00
Emil Gydesen
4fcc3f0c1e Bluetooth: Audio: Add guard for bt_audio_codec_qos_to_iso_qos
The function are only used by the broadcast roles and
the unicast client.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-23 08:58:52 +01:00
Emil Gydesen
f5f1664a41 Bluetooth: Audio: Move most of unicast client-only code from stream.c
Some operations such as Config, QoS, Enable and Stop
are only available for the unicast client, but since
they share the bt_audio_stream prefix, we leave the
agnostic part of it in stream.c, and move the actual
implementation to unicast_client.c.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-23 08:58:52 +01:00
Emil Gydesen
6303fa0c18 Bluetooth: Audio: Remove unicast server specific code from stream.c
stream.c had code that was only useful for the unicast server/
ASCS, and have been moved to ascs.c instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-23 08:58:52 +01:00
Emil Gydesen
b46edc7137 Bluetooth: Audio: Fix bad shell string formats
There was a couple of shell prints that was not
formatted correctly.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-22 12:19:04 +01:00
Andries Kruithof
ddd83c3bc0 Bluetooth: controller: correct conditional compile for central FEX
In the switch statement there are two cases guarded by ifdef's.
These cases are not compiled in for the following Kconfig settings:
BT_PERIPHERAL=n
BT_CTRL_PER_INIT_FEAT_XCHG=n
The following function call then becomes dead code
This is fixed here by adding the proper guards around the whole case
statement

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-02-22 12:16:03 +01:00
Emil Gydesen
4f5e113dfd Bluetooth: Audio: Fix bad log statement in cap_initiator
Fix missing argument for a log statement.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-21 11:00:18 +01:00
Marcin Niestroj
830308e00f Bluetooth: host: increase BT_CONN_TX_USER_DATA_SIZE for 64bit platforms
Commit 2c00dd5fec ("Bluetooth: host: check net bufs have enough room in
user_data") added a build time check of user data size. This check does not
pass with default CONFIG_BT_CONN_TX_USER_DATA_SIZE=8 and with
`native_posix_64` platform, as 16 bytes are needed in order to store
`struct tx_meta`.

Select 16 as default value for 64bit platforms, so Bluetooth samples/tests
are buildable for `native_posix_64`.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-02-20 19:44:25 +01:00
Emil Gydesen
928e5bbcf0 Bluetooth: Audio: CAP inittiator broadcast stop procedure
Implemented support for stopping and deleting a
CAP broadcast source.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 13:24:34 +01:00
Emil Gydesen
9d0ec99315 Bluetooth: Audio: CAP initiator broadcast metadata update
Add support for the update metadata for broadcast audio
procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 13:24:34 +01:00
Emil Gydesen
6f1bb59b26 Bluetooth: Audio: Implement bt_cap_initiator_broadcast_audio_start
Implement the CAP initiator broadcast audio start procedure.

This basically just verifies that the stream context
is set in the metadata, and then calls the BAP
procedure.

We define a new opaque struct, bt_cap_broadcast_source,
that is just an abstraction of the bt_audio_broadcast_source
but is used to indicate that these functions require a
broadcast source created by the CAP function (and not the
BAP) function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 13:24:34 +01:00
Emil Gydesen
17b7854961 Bluetooth: Audio: Fix for PA sync in broadcast sink
Fixes a bug where we cleanup the broadcast sink without
properly terminating the BIG sync first.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 13:22:15 +01:00
Vinayak Kariappa Chettimada
659294bc3f Bluetooth: Controller: Fix AUX_ADV_IND AUX_SYNC_IND radio utilization
Fix AUX_ADV_IND AUX_SYNC_IND radio utilization by having a
configurable offset.

Define an offset between AUX_ADV_IND and AUX_SYNC_IND when
using Advertising Interval for the Extended Advertising and
Periodic Advertising that are same or multiple of each
other, respectively.

Note, to get advertising intervals that are same or
multiple, the Periodic Advertising Interval shall be 10
millisecond more than the Extended Advertising Interval;
this is because the AUX_ADV_IND PDUs are scheduled as
periodic events of Extended Advertising Interval plus 10
milliseconds (Advertising Random Delay) as the periodic
interval.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-20 13:18:12 +01:00
Vinayak Kariappa Chettimada
a8862e2adb Bluetooth: Controller: Fix Close Isochronous Event implementation
Fix the Close Isochronous Event (CIE) implementation so that
it follows the Bluetooth Core Specification definition:
Link Layer implementations will normally end a CIS event
early when all scheduled payloads in both directions have
been transmitted and acknowledged.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-20 11:48:56 +01:00
Vinayak Kariappa Chettimada
e0f5675e70 Bluetooth: Controller: Rename lll_df_conf_cte_tx_disable()
Rename lll_df_conf_cte_tx_disable() to lll_df_cte_tx_disable()
so that it can be used as a common function between connection
and connectionless implementations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-20 11:36:58 +01:00
Emil Gydesen
9756aea801 Bluetooth: Audio: Ensure strtoX correctness in vcp_vol_rend.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
fe1d5a8177 Bluetooth: Audio: Ensure strtoX correctness in vcp_vol_ctlr.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
668ed75a22 Bluetooth: Audio: Shell: Fix VCP location check
The location value is a uint32_t, and not uint16_t.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
caf259af65 Bluetooth: Audio: Ensure strtoX correctness in tbs.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
d5e625ce9d Bluetooth: Audio: Ensure strtoX correctness in tbs_client.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
87cd6dd743 Bluetooth: Audio: Ensure strtoX correctness in mpl.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
97f14779a5 Bluetooth: Audio: Ensure strtoX correctness in micp_mic_dev.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
07f4c83610 Bluetooth: Audio: Ensure strtoX correctness in micp_mic_ctlr.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
1bf9aae455 Bluetooth: Audio: Ensure strtoX correctness in media_controller.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
f0ea061b3a Bluetooth: Audio: Ensure strtoX correctness in mcc.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
0c9180ef99 Bluetooth: ISO: Ensure strtoX correctness in iso.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
ab9d2c32c9 Bluetooth: Audio: Ensure strtoX correctness in csip_set_member.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
311476d5ce Bluetooth: Audio: Ensure strtoX correctness in csip_set_coordinator.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
774f607cfe Bluetooth: Audio: Ensure strtoX correctness in cap_acceptor.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
760e987529 Bluetooth: Audio: Ensure strtoX correctness in bap_scan_delegator.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
7bbddc14e3 Bluetooth: Audio: Ensure strtoX correctness in bap_broadcast_assistant.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Emil Gydesen
6fa4b00180 Bluetooth: Audio: Ensure strtoX correctness in audio.c
Verify all values returned by calls to strtoX and convert
to the shell_strtoX functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:29:44 +01:00
Magdalena Kasenberg
e77b571ebd LE Audio: Fix response code expected by ASCS/SR/SPE/BI-18-C
When handling ASE Control operations requested by client,
first verify that the requested ID is within the allowed range.
If it does, lets assume that the NULL returned from ase_find()
means the ASE state is set to idle.

This will fix ASE Notification Response code expected by
the ASCS/SR/SPE/BI-18-C PTS test case.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
2023-02-20 11:26:45 +01:00
Emil Gydesen
c0150c9ce5 Bluetooth: Audio: Ensure stream disconnect correctness for unicast client
Add a new function for the unicast client that verifies whether
or not the unicast client can terminate the CIS given the
state of any paired endpoint and the CIS state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:26:25 +01:00
Emil Gydesen
ad304697ab Bluetooth: Audio: Handle GATT/ISO race condition in unicast client
When releasing a stream causing the CIS to disconnect, there was
a race condition between the CIS disconnect event and the
idle state notification from the unicast server.

This ensures that if we are disconnecting a CIS as part of the
release, then we wait for the CIS disconnect event before calling
the "released" callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:26:25 +01:00
Emil Gydesen
d2dfc3c475 Bluetooth: Audio: Add addition ISO chan state check before disconnect
Add state check for BT_ISO_STATE_CONNECTING before disconnecting
the CIS, else we could end up in a race condition where we
did not disconnect the connecting CIS, and then still have
a CIS afterwards.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:26:25 +01:00
Emil Gydesen
984ce52ddb Bluetooth: ISO: Fix state checks for bt_iso_chan_disconnect
The behavior of bt_iso_chan_disconnect depends on the
state of the ISO channel.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:26:25 +01:00
Emil Gydesen
c67c7728a6 Bluetooth: Audio: Unicast client check ISO state before disconnect
Add a check to see if the ISO is connected before we attempt to
disconnect it. In the case where a stream was not in the streaming
state and was released, the CIS is unlikely to be connected.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:26:25 +01:00
Emil Gydesen
fdc26eee78 Bluetooth: Audio: MCS reject long read if value changed
Add support for reject long read if a long value is
changed during the read.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:25:42 +01:00
Emil Gydesen
281d0a3fc8 Bluetooth: Audio: Add media player icon URL changed callback
Add support for notifying MCS a player icon URL change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:25:42 +01:00
Emil Gydesen
4d595014ab Bluetooth: Audio: Add media player name changed callback
Add support for notifying about a player name change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:25:42 +01:00
Emil Gydesen
89e907cb3d Bluetooth: Audio: Truncate MCS notifications per conn
When notifying a long (string) value in MCS, each
connection's MTU is taken into account when
(potentially) truncating the notification.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:25:42 +01:00
Emil Gydesen
788abf6811 Bluetooth: Audio: Fix truncation of MCS string notifications
The truncation of the MCS string notifications was incorrect.
As per the MCS specification, the MCS shall send ATT_MTU - 3
if the value cannot fit in the notification.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 11:25:42 +01:00
Vinayak Kariappa Chettimada
3c0c9aca40 Bluetooth: Controller: Replace WFE use with k_cpu_atomic_idle()
Replace the use of WFE with Zephyr kernel supplied
k_cpu_atomic_idle() interface.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-20 10:34:27 +01:00
Vinayak Kariappa Chettimada
b46b833a7b Bluetooth: Controller: Reuse cpu_sleep interface
Reuse cpu_sleep() interface consistently in Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-20 10:34:27 +01:00
Vinayak Kariappa Chettimada
67fa62fe22 Bluetooth: Controller: Add a DSB in sleep interface
Add a DSB before doing WFE in cpu_sleep(), to ensure the
memory transactions are complete.

Add a note clarifying a dependency for the existing solution
(dependency is satisfied by ARCH code but is good to state
clearly).

Relates to commit f1264b7e47 ("drivers: entropy: nrf5: add
docs and a DSB in get_entropy_isr").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-20 10:34:27 +01:00
Jonathan Rico
2c00dd5fec Bluetooth: host: check net bufs have enough room in user_data
Since we accept buffers from external sources in L2CAP, we need to make
sure that we have enough room in user data to store the metadata necessary
for fragmentation over the HCI link.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-20 09:53:51 +01:00
Mingjie Shen
25e3f655f0 Bluetooth: L2CAP: Fix use of 'br_chan'
Assignment to br_chan should be placed after the call of server->accept().
Otherwise, br_chan will always be a null pointer.

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2023-02-20 09:53:26 +01:00
Aleksandr Khromykh
dd1fc0dd03 Bluetooth: Mesh: fix access to uninitialized memory
Running bsim with Valgrind highlighted a couple of
places where read access to uninitialized memory happens.
Config client rewrites publication parameters with not
initialized uuid pointer. Bitfields those are allocated on
the stack keeps not used area uninitialized too.
Uninitialized area is stored in the persistent memory.
PR fixes that.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-02-20 09:53:14 +01:00
Aleksandr Khromykh
59edf5cae3 Bluetooth: Mesh: correction lpn rx delay
If extended advertiser is used, then advertiser sends callback
quite close to the real tx end time. No necessity to consider
advertisement time in lpn rx delay. It allows lpn to spend
less time in active scanning and save more power. Unfortunately,
legacy advertiser shows very slow precision. It is mandatory to
consider adv time for it. Additionally, unnecessary considering of
the advertisement duration has been removed for receive window in lpn.
It makes scanner window longer for a couple of milliseconds.
This is the responsibility of friend node to configure window that
it can manage.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-02-20 09:51:53 +01:00
Sean Madigan
e79fee7a2e bluetooth: host: conn: Utilize conn_set_state in conn_destroy
Previously we would call conn_cleanup for all connections,
however this had multiple problems such as:
-Not destroying conn->tx_pending packets and causing an assert
-Calling conn_cleanup for connectable adv, triggering
disconnected callback

Now we will use bt_conn_set_state to manage the teardown of
connections correctly. First, if in connected or disconnecting,
set state to disconnect complete. Then for all states, set
state to disconnected. This will carry out proper cleanup
and teardown when required.

To do this, it was required to keep the tx_thread open as
this is used in disconnecting teardown, so this has been
moved to below the conn_cleanup_all call.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2023-02-20 09:50:48 +01:00
Mariusz Skamra
bfb2625818 Bluetooth: audio: has: Fix client context allocation
The client context shall be allocated once paired i.e. encryption is
enabled. This fixes issue that client context was allocated only for
bonded devices and as a result the ATT Unlikely Error was replied to
Control Point operation that paired remote requested.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-02-20 09:49:15 +01:00
Mariusz Skamra
668b40a5c2 Bluetooth: audio: has: Rename has_client struct member
This renames has_client.ntf_bonded to has_client.ntf_pending as this
field is valid for paired devices an contains the notification state.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-02-20 09:49:15 +01:00
Magdalena Kasenberg
e26e8d1c07 shell: audio: Add print ASE info command
The command prints id, state and dir of all ASEs of default connection.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
2023-02-20 09:49:09 +01:00
Magdalena Kasenberg
90ab1c56f5 LE Audio: Add helper functions to get endpoints info
The functions allow to return structure holding information of audio
stream endpoint.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
2023-02-20 09:49:09 +01:00
Magdalena Kasenberg
5d2fb499af LE Audio: Allow server to initiate Codec Config procedure
Required by ASCS/SR/ACP/BV-07-C PTS test case.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
2023-02-20 09:49:09 +01:00
Paul Adelsbach
4d8160d680 Bluetooth: host: suppress adv timeout warning when successful
The warning was visible even when `bt_le_adv_stop()` was successful, which
is confusing to end-users.

Signed-off-by: Paul Adelsbach <paul@boxsection.org>
Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-20 09:48:17 +01:00
Emil Gydesen
277e162d82 Bluetooth: Audio: Avoid error log for bidirectional CIS
In the case that the CIS has been setup as bidirectional, and
only one of the directions have an ASE configured yet,
we should only care about valid ISO packets when doing this
check. The reason is that some controllers send HCI ISO data
packets to the host, even if no SDU was sent on the remote
side. This basically means that empty PDUs are sent to the
host as HCI ISO data packets, which we should just ignore.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 09:47:49 +01:00
Emil Gydesen
b9882e2368 Bluetooth: Audio: Guard ep status debug with debug stream data
In the unicast audio streams, there can be a mismatch
between the CIS state and the endpoint state. This
was previously logged, but since this would be logged
continously, we guard it with CONFIG_BT_AUDIO_DEBUG_STREAM_DATA.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 09:47:49 +01:00
Emil Gydesen
e71460cdb8 Bluetooth: Audio: Only allow receiver to send start command
Only the receiver of the audio is allowed to send the
receiver start ready command.

Furthermore, this removes the automated transition to the
streaming state on the server, as the server now shall
call bt_audio_stream_start to put the stream into the
streaming state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-20 09:45:18 +01:00
Kumar Gala
5af7ff4558 Bluetooth: Mesh: Cfg_cli: Remove deprecated functions
Remove deprecated functions that have been deprecated for at least
two releases now.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-02-19 20:48:06 -05:00
Théo Battrel
ac3dec5212 Bluetooth: Host: Check returned value by LE_READ_BUFFER_SIZE
`rp->le_max_num` was passed unchecked into `k_sem_init()`, this could
lead to the value being uninitialized and an unknown behavior.

To fix that issue, the `rp->le_max_num` value is checked the same way as
`bt_dev.le.acl_mtu` was already checked. The same things has been done
for `rp->acl_max_num` and `rp->iso_max_num` in
`read_buffer_size_v2_complete()` function.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-02-18 00:09:13 +09:00
Marek Pieta
aed165df61 Bluetooth: host: Fix SC indication on encrypt change
The SC indication can be sent only if the GATT Service Changed is
enabled in the configuration. Change fixes build issues related to
implicit sc_indicate declaration when Service Changed is disabled.

Fixes: #54813

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2023-02-16 00:21:07 +09:00
Marek Pieta
32e534c935 Bluetooth: host: Remove GATT Client dependency for storing CCC and CF
Change removes GATT Client dependency for storing CCC and CF on pairing
complete and identity resolved. These features are needed also if GATT
Client role is disabled.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2023-02-16 00:21:07 +09:00
Jonathan Rico
a0614b6cd1 Bluetooth: host: save CF and CCC values written before bonding
On bond establishment: save the CF and CCC data that have been written
before the peer was bonded.

On identity resolved: update the CF data to use the peer's identity address
instead of its private address (same as is currently done for the CCC).

Fixes #54770.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-16 00:21:07 +09:00
Jonathan Rico
5d46a0c398 Bluetooth: host: fix subtle bug in db_hash_process
Fixes a bug introduced in the previous refactoring: we would always mark
all peers as change-unaware. Now we only do so when the hash has been
recalculated.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-16 00:21:07 +09:00
Jonathan Rico
2a15a63509 Bluetooth: host: don't store hash in db_hash_gen()
Move out the storage of the calculated hash from the fn that calculates
it (db_hash_gen).

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-13 12:55:02 +01:00
Jonathan Rico
b60b0f3505 Bluetooth: host: don't overwrite GATT DB hash before settings_load
Previously, if the app registered a bunch of services at boot before
calling `settings_load()`, then the hash would be silently overwritten.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-13 12:55:02 +01:00
Jonathan Rico
e8f3ef29a4 Bluetooth: host: store GATT change-aware status in settings
The spec says we have to persist the change-aware status of bonded peers
between resets.
This stores it at the end of the CF storage that we currently have.

Fixes #54173

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-13 12:55:02 +01:00
Jonathan Rico
4772e5695f Bluetooth: host: Store Client Supported Features on write
Store the Client supported features value when it is written to, instead of
only on disconnection/identity resolved.

Works around the situation where a user bonds, CF is written and the device
is abruptly powered off, discarding the CF value, but keeping the bond.

Fixes #54172.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-13 12:55:02 +01:00
Magdalena Kasenberg
3c00629bb6 LE Audio: Map EALREADY error of ase_stream_qos()
to send response with code 0x09 = Invalid Configuration Parameter
Value and reason 0x0a = Invalid_ASE_CIS_Mapping.

Previous response code was BT_ASCS_RSP_UNSPECIFIED (0x0e) and
reason BT_ASCS_REASON_NONE (0x00).

Fixes ASCS/SR/SPE/BI-15-C and ASCS/SR/SPE/BI-16-C PTS test cases.

Signed-off-by: Magdalena Kasenberg <magdalena.kasenberg@codecoup.pl>
2023-02-11 08:21:13 +09:00
Morten Priess
3712094417 Bluetooth: controller: Fix CIS establishment procedures
Fixing typo in llcp_lp_cc_established revealed the need for completing
the CIS establishment procedure by additional call to local/remote
check_done function.

Fixed by exposing lr_check_done and rr_check_done with naming update and
calling after injecting the CIS_ESTABLISHED event.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-02-10 15:28:35 +01:00
Morten Priess
98161bd1d3 Bluetooth: controller: Enable CIS establishment in same ACL instant
If CIS offset in LL_CIS_IND is less than EVENT_OVERHEAD_START_US, the
controller is not able to establish the CIS in the ACL connection event
specified, but needs to start setup one connection event earlier.

With this commit, if offset is larger than EVENT_OVERHEAD_START_US the
first CIS event can be prepared in due time immediately.

This enables the controller to setup first CIS, even when instant is
equal to the ACL event_counter.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-02-10 15:28:35 +01:00
Vinayak Kariappa Chettimada
220170a549 Bluetooth: Controller: Fix Periodic Advertising time reservation
Fix Periodic Advertising time reservation when enabling with
ADI support. As the PDU is updated, use the updated PDU to
calculate the time reservation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
1ed9bda92d Bluetooth: Controller: Schedule BIG event after Periodic Advertising
Add implementation to schedule BIG events after Periodic
Advertising when Periodic Advertising is enabled after
Extended Advertising has already been enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
2ae86f4e8d Bluetooth: Controller: Use context specific get interface
As the range of ticker_id has been checked, context specific
get interface be used instead of doing range check again in
ull_hdr_get_cb().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
d93bc9dbd8 Bluetooth: Controller: Fix auxiliary PDU time reservation calculation
Fix auxiliary PDU time reservation calculation to reserve
for possible increase in PDU len due to updates to data in
the Common Extended Header Format of the PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
f4a0543bf4 Bluetooth: Controller: Refactor duplicate aux_time_get implementation
Refactor duplicate aux_time_get() implementation and reuse
the same code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
82ad0777c0 Bluetooth: Controller: Minor rename to sync_time_get()
Minor rename of file static function sync_time_get().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
2fabaf37ef Bluetooth: Controller: Fix assertion scheduling first BIG event
Fix assertion due to delayed prepare of first BIG event when
supporting encryption. Crypto calculation introduce extra
processing delay causing the scheduling of first BIG event
to be delayed. Detect such delay and skip to next ISO
interval.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
6dbe82a7db Bluetooth: Controller: Relax radio_tmr_start_us assert on win widening
Relax radio_tmr_start_us() delayed start assertion when
window widening in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
11cfd8acc3 Bluetooth: Controller: Fix radio_tmr_aa_save() value for ISO receive
Fix the access address and radio ready timestamp to derive
the value of the first subevent, so that correct anchor
point reference is used in scheduling subsequent subevents.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
64979d7b6b Bluetooth: Controller: Fix uninitialized CIS LLL member variables
Fix uninitialized CIS LLL structure member variables,
uninitialised CIS acl_handle causes HCI command disallowed
for acl_handle's other than 0x0000.
Initialize other variables like sn, nesn etc. when create
CIS control procedure is performed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Vinayak Kariappa Chettimada
09897e2c8d Bluetooth: Controller: Fix GPIO debug pins for ISO Central
Fix the GPIO debug pin assignment for ISO central role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-10 15:09:02 +01:00
Herman Berget
cc9d2102f2 Bluetooth: Fix enabling PAST as advertiser
It is possible to do PAST as advertiser without support for periodic sync.

Fixes #54613.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2023-02-09 13:22:57 +01:00
Pierce Lowe
ba09a252ec bluetooth: host: refactor bt_hci_le_per_adv_report data reassembly
Refactoring the periodic advertisment report receive function
to make the handling of data reassembly more readable.

Signed-off-by: Pierce Lowe <pierce.lowe@nordicsemi.no>
2023-02-09 13:12:24 +01:00
Pierce Lowe
a7c1c27e38 bluetooth: host: drop incomplete data in periodic scanner
This changes the periodic scanner to drop periodic adv
reports with incomplete data. This avoids incorrect data
being sent to application in the case where the periodic
adv data is not successfully received by the scanner.

Fixes zephyrproject-rtos#54072

Signed-off-by: Pierce Lowe <pierce.lowe@nordicsemi.no>
2023-02-09 13:12:24 +01:00
Szymon Czapracki
6c374215d0 bluetooth: audio: Fix typo in PACS
A simple typo fix.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2023-02-09 13:09:46 +01:00
Johan Hedberg
9c459b33fb Bluetooth: SMP: Fix setting key distribution bits for no-bonding
9.4.2 section, Part C, Vol 3 of the Bluetooth Core specification v5.3
states the following in the case that the device is in non-bondable
mode:

If Security Manager pairing is supported, the Host shall set the
Bonding_Flags to ‘No Bonding’ as defined in [Vol 3] Part H, Section
3.5.1 and bonding information shall not be exchanged or stored.

Fixes #54104

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-02-08 19:04:51 +09:00
Wolfgang Puffitsch
c8c81d28b7 Bluetooth: controller: Only allow supported feature bits to be set by host
Redefine mask of host-controlled feature bits to include only features
that are supported by the controller. This fixes a conformance test
failure where setting an unsupported host-controlled feature bit was
not rejected as it should.

Set the Connected Isochronous Streams (Host Support) bit from the host
only if unicast support is configured to avoid failures in
broadcast-only configurations.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2023-02-08 01:16:10 +09:00
Théo Battrel
6dfe5b0e9c Bluetooth: Small fixes for some Bluetooth Shell commands
Update help message of some commands of the Bluetooth Shell that were
inconsistent.

Also add the `dir-rpa` parameter to the advertiser parameters to fully
support directed advertisment parameters.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-02-07 11:58:00 +01:00
Vinayak Kariappa Chettimada
3d54d46bbc Bluetooth: Controller: Fix Central from overlapping BIG events
Fix advanced scheduling to consider active BIG events when
establishing new Central connections. This will schedule
AUX_ADV_IND, AUX_SYNC_IND and Central connections of similar
interval to be non-overlapping.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-06 22:06:16 +09:00
Vinayak Kariappa Chettimada
d91b20dd3f Bluetooth: Controller: Fix overlapping multiple BIG events
Update advanced scheduling implementation to consider other
active BIG events when scheduling new BIG instances.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-06 22:05:40 +09:00
Emil Gydesen
9d3e287572 Bluetooth: Audio: Fix ASCS CP subscribe in discovery
During discovery the unicast client subscribes to the
ASCS CP characteristic. However, this was done asynchronously
at the end of the discovery, and the discovery complete
callback was called before the subscription was done.

Since the unicast client relies on the auto CCC discovery,
the actual subscription takes place a few connection intervals
after the unicast_client_ep_set_cp function was called. The
result of this is that the actual subscription was missing
when the unicast client application starts performing
BAP operations.

The change done here postpones the discovery callback
until after the CP subscription has taken place, ensuring
that the unicast client correctly receives the CP notifications
when performing BAP operations. This also allows the unicast
client to use the discovery parameter in the
bt_audio_discover_params struct, rather than yet another
discovery parameter struct, saving some memory.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-06 22:05:15 +09:00
Lingao Meng
b3eeb91869 Bluetooth: Mesh: Remove meaningless condition
Since `schedule_send` always have no-null params.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2023-02-06 10:08:22 +01:00
Emil Gydesen
c4d80f7760 Bluetooth: Audio: Shell: Fix issue with setting contexts
There was a bug where BT_AUDIO_DIR_SINK should have been
BT_AUDIO_DIR_SOURCE when setting supported contexts.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-02-06 10:03:43 +01:00
Vinayak Kariappa Chettimada
f00da4b0d4 Bluetooth: Controller: Fix ISO Data sn nesn on flush
Fix sn and nesn values of ISO data when starting a new burst.
When central retransmitted but did not get an ack, it did
not update the sn correctly causing the peripheral to drop
the next ISO data PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-03 20:54:20 +09:00
Vinayak Kariappa Chettimada
278b07c971 Bluetooth: Controller: Fix addr type in PA sync established event
The address type in the periodic adveritising sync
established event is incorrectly set to 0x01
(BT_ADDR_LE_RANDOM) when the address is a resolved one,
where it should have been BT_ADDR_LE_RANDOM_ID.

The address type has been fixed by offsetting by 2 to get
BT_ADDR_LE_PUBLIC_ID or BT_ADDR_LE_RANDOM_ID when the
address has been resolved.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-03 02:26:42 +09:00
Jonathan Rico
c2e4029aad Bluetooth: host: resume advertising even when BT_EXT_ADV=y
When using extended advertising commands, the advertising set is not
considered to be over until we receive `BT_HCI_EVT_LE_ADV_SET_TERMINATED`
from the controller. Only then do we clear the `BT_ADV_ENABLED` flag.

The problem is that `bt_le_adv_resume` is called on connection established,
which can happen before adv set terminated, and in that case it will
early-return because `BT_ADV_ENABLED` is still set.

This change triggers `bt_le_adv_resume` when we get
`BT_HCI_EVT_LE_ADV_SET_TERMINATED`.

Fixes #53048

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-02 17:05:48 +02:00
Vinayak Kariappa Chettimada
de2029ac58 Bluetooth: Controller: Fix missing DF related radio register reset
Fix missing DF related Radio register reset on radio_reset().

Regression in commit 465a96181d ("Bluetooth: Controller:
Explicitly set all bits of used radio registers") due to the
removal of NRF_RADIO->POWER register use that was used to
reset all Radio registers on every new Radio Event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-02-02 11:15:44 +01:00
Andrei Emeltchenko
f9ced67170 bluetooth: audio: Fix dereference before NULL check
Dereference only after NULL check.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-30 23:47:55 +00:00
Andrei Emeltchenko
2782d6996a bluetooth: Fix duplicated parameter check
Parameter count is checked several lines below this line.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-30 23:47:55 +00:00
Andrei Emeltchenko
dcb199f581 bluetooth: audio: Fix NULL dereference
Fixes NULL dereference right after NULL check.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-30 23:46:25 +00:00
Emil Gydesen
8512bd18c6 Bluetooth: Shell: Fix unintialized ad_len bug
`ad_len` was never initiatialized before we started
incremetenting and using it.

We would also override any user data in ad_init, which
is fixed by using the length of the user data as an
offset into the array.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-30 10:08:00 +00:00
Vinayak Kariappa Chettimada
595860567b Bluetooth: Controller: Workaround sequence number misalignment
Workaround sequence number misalignment to ISO event count
when ISO data is supplied in bursts, example through USB.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
6dfbf7c110 Bluetooth: Remove BT_HCI_DATAPATH_ID_DISABLED define
Remove BT_HCI_DATAPATH_ID_DISABLED define as 0xFF, which is
reserved for future value for Data_Path_Id parameter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
3a37834aa7 Bluetooth: Controller: Add ISO Broadcast and Receive ISR Profiling
Add implementation to generate ISR profiling of Broadcast
ISO and ISO Receive usecase.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Carl Stehle
714f80d225 Bluetooth: Controller: Integrate ISOAL for ISO Broadcast
- Include ISO stream count in ISO streams definitions in
  controller.
- Create ISOAL source on controller when ISO data path is
  setup.
- Send broadcast data buffers transferred from host over
  HCI to ISOAL as ISO SDU fragments.
- Allow bot conn and ISO data to use data_buf_overflow.
- Store ISO interval during BIG create.
- Remove ISO data path for each BIS during BIG terminate
  procedure.
- Set value (temporarily) for ISOAL target_event enabling
  it to Tx data.
- Check status of data fragment sent to ISOAL for memory
  allocation and other errors.
- Destroy ISOAL source when ISO stream released.
- Use ISO Advertising handle, not stream handle to destroy
  ISO data path.
- Remove extra ISOAL sink destroy call when removing ISO
  data path.
- Add FIXME comment as reminder to address LL_ASSERT on
  isoal_status error.

Signed-off-by: Carl Stehle <droid@appception.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
532cf9ba2b Bluetooth: Controller: Fix ISO interval based on Max Transport Latency
Fix calculation of ISO interval such that multiple bursts
can be transmitted per ISO interval. This means we can now
have SDU_Interval < ISO_Interval and more than one SDU will
be transmitted in each ISO_Interval.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
5fbb3bf42b Bluetooth: Controller: Fix BIS Control PDU being dispatched as ISO Data
Fix missing jump to Rx ISR done that caused the Control PDU
to be enqueued as ISO data PDU, causing the ISOAL to assert
on receiving invalid LLID.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
c32ff9608b Bluetooth: Controller: Fix ISO timestamp wrap around
Fix ISO timestamp wrap around which caused ISOAL to assert
checking for valid timestamp.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
27206e17af Bluetooth: Controller: Initial CIG with 1 CIS support in LLL
Add initial support for CIG with 1 CIS in nRF5 SoC's LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
9d01c16c47 Bluetooth: Controller: Define a internal BT_CTLR_ISO_TX_BUFFERS
Define a internal BT_CTLR_ISO_TX_BUFFERS to allocate ISO Tx
buffers used for Broadcast and Connected ISO.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
479ba351d2 Bluetooth: Controller: Fix Ctrl to Host flow control assertion
Fix Controller to Host flow control assertion handling ISO
stream disconnection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
069a7c0cbd Bluetooth: Controller: Fix isoal_tx_pdu_emit/source_deallocate race
Fix race between isoal_source_deallocate() and
isoal_tx_pdu_emit(). Initiating a local initiated terminate
triggers NULL pointer dereference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
cd2796e047 Bluetooth: Controller: Refactor ll_setup_iso_path
Refactor ll_setup_iso_path to support Synchronous Receiver
and Connected ISO to be built together.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
362826ea03 Bluetooth: Controller: Code review rework changes
Assorted code review rework changes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
4f36f95e5f Bluetooth: Controller: Fix uninitialized CIG ULL reference count
Fix uninitialized CIG ULL reference count when creating a
CIG after a previous disconnection.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
ab89f7d1e6 Bluetooth: Controller: Fix CIS and CIG teardown
Fix CIS and CIG teardown in Central and Peripheral Role.
cig->lll.num_cis value is used in peripheral role to count
active CISes, and cig->cis_count is used in central role.
Both central and peripheral will stop ticker for CIG when
num_cis and/or cis_count is zero, respectively, but only
peripheral role will release a CIG context. The Central
will keep the CIG context allocated and only mark it as
not started. Remove CIG command will be used for central
role to release a CIG context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
19c80b1020 Bluetooth: Controller: Fix CIS ISO Tx buffer leak on terminate
Fix CIS ISO Tx buffer leak on terminate when the datapath
has been deallocated.

Add a FIXME comment regarding ll_tx_ack_put() being called
from LLL execution context, while it is a ULL callable used
by ACL connections to dispatch ack.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
c7724f00e5 Bluetooth: Controller: Fix k_is_in_isr() assert calling util_aa_le32()
Do not call util_aa_le32() from ISR context as random number
generation in entropy driver on nRF5x series invokes
k_sem_take.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
93f9d9bc6d Bluetooth: Controller: Fix assertion on link_tx_free on CIS re-create
Fix assertion check on link_tx_free when CIS is created a
second time. The Tx mem queue has to be initialized on every
new CIS create as CIS disconnect does the deinitialization.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
e5d9ad17bb Bluetooth: Controller: Reorder the functions in ull_central_iso file
Reorder the functions in ull_central_iso file to match the
order of HCI commands in the BT Spec.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
00e31f5e65 Bluetooth: Controller: Workaround datapath field access after release
Workaround the access that check if datapath is NULL when
the stream has already been released. Memory Pool overwrites
first 8 bytes to maintain the free list and free count. This
causes the datapath fields if placed in the first 8 bytes to
not be NULL after the memory is freed.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
bb92b018dd Bluetooth: Controller: Code to generate ISO data buffer overflow event
Add code to generate ISO data buffer overflow event if more
than allocated ISO data PDU buffers are tried to be
requested by host or for SDU fragmentation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
8cf58edb8b Bluetooth: Controller: Use instant_latency to detect event skipped
Use instant_latency at the CIG start event count to detect
skipped connection event around the instant. In the future
add implementation to compensate for skipped ACL connection
event and adjust the CIS event count at CIG start.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
149f857f8a Bluetooth: Controller: Reuse ull_conn_event_counter() in LLCP
Reuse ull_conn_event_counter() function in LLCP
implementation to get the current radio event counter value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
aba5176340 Bluetooth: Controller: Fix CIG offset and add time reservations
Fix CIG offset such that it follows after the ACL connection
time reservation to avoid overlapping.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
b16e5baf80 Bluetooth: Controller: Rename to trx_performed_bitmap
Rename trx_performed_mask to trx_performed_bitmap and add
conditional compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
a155b3b37d Bluetooth: Controller: Add LLL required ULL interfaces
Add LLL interfaces implemented by ULL to get group by stream
and to get stream by group iterator functions.
Rename function to set CIS established to reflect that it is
LLL accessible.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
53db4a0b1d Bluetooth: Controller: Fix channel indices calculaton cond compile
Fix channel indices calculation implementations conditional
compile so that it can be reused for Connection ISO events
and subevents.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
6f0b6ec90b Bluetooth: Controller: Fix ISO Buffer allocation for SDU fragmentation
Fix ISO Tx Buffer allocation counts considering required SDU
fragmentations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
a949fa7250 Bluetooth: Controller: Use define for packet timer capture
Use the sample capture index define for capturing packet
timer timestamp.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
9119e817fa Bluetooth: Controller: Separate Tx and Rx packet timer status reset
Add interface to have separate Tx and Rx packet timer status
reset, so that packet timer can be setup ahead in time for
starting the Tx or Rx subevent and status reset only clears
the respective PPI/DPPI that was used when Tx or Rx
completes.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
bcc4fa4f44 Bluetooth: Controller: Use spec. defined abbrev. for nse, bn, and ft
Use BT Spec. defined abbreviations for number of subevents
(nse), burst number (bn), flush timeout (ft) etc.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
9456a0ecd9 Bluetooth: Controller: List Central and Peripheral ISO supported
Update Kconfig to list Central and Peripheral ISO as
supported. Will continue to be listed as Experimental.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
efd80f4ec1 Bluetooth: Controller: Add conditional compiles for Peripheral ISO
Add conditional compilation for Peripheral ISO support,
use CONFIG_BT_CTLR_PERIPHERAL_ISO.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
863fc7373b Bluetooth: Controller: Re-arrange include in ull_peripheral_iso file
Re-arrange include in ull_peripheral_iso file to be
consistent with other similar files (ull_central_iso).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
5398ae0710 Bluetooth: Controller: Add LL_CIS_HANDLE_LAST, IDX_FROM_HANDLE define
Rename LAST_VALID_CIS_HANDLE to LL_CIS_HANDLE_LAST, to be
consistent naming with LL_CIS_HANDLE_BASE.
Add IDX_FROM_HANDLE defines.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
8e48de8f58 Bluetooth: Controller: Minor refactor of Connected ISO group and stream
Refactor the Connected ISO group and Connected ISO stream
context to be consistent in defining the bitfields and also
rearrange structure members.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Vinayak Kariappa Chettimada
66834e9860 Bluetooth: Controller: Fix missing BT_LL_SW_LLCP_LEGACY cond compile
Fix missing BT_LL_SW_LLCP_LEGACY cond compile causing
compile error when building Peripheral ISO samples with
legacy control procedure implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-27 23:04:45 +09:00
Théo Battrel
7f9cd24814 Bluetooth: Stop sending SMP PDUs outside of pairing procedure
Stop sending the unnecessary 'pairing failed' SMP PDUs outside of the
pairing procedure.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-01-27 19:23:03 +09:00
Troels Nilsson
9f92dff354 Bluetooth: controller: Fix issue with duration/max number of adverts
When a maximum duration or number of advertisements has been set for an
advertisement set, we will exceed that limit if the last advertisements
happen to be overlapping (ie. we have two primary advertisements pointing
to the same AUX_ADV_IND).

We now have a check in the ticker_cb that will ignore the callback if the
state is such that advertisement would have been stopped if ull_adv_done()
had been allowed to run in the meantime.

Signed-off-by: Troels Nilsson <trnn@demant.com>
2023-01-27 19:22:30 +09:00
Emil Gydesen
e5890fc779 Bluetooth: Audio: Broadcast source reconfigure missing streaming QoS
When executing the bt_audio_broadcast_source_reconfig the streams
did not get assigned the new QoS, the ISO parameters were not
properly updated and the codec was not set.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-27 18:10:34 +09:00
Emil Gydesen
3ead1cfa2c Bluetooth: Audio: Call stream released on ACL disconnect
If the ACL disconnects, then the unicast server cannot send
a notification to the client about the endpoint and
stream being released. We now call the released callback
if the stream's endpoint was not idle before the disconnection.

Similarly the unicast server (ASCS) did also not call the
released callback if the ACL disconnection causes a endpoint
release.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-27 17:35:51 +09:00
Raphael Treccani-Chinelli
3e937da264 bluetooth: host: Added extra options to PAST subscribe
allow disabling reports (synchronise but don't generate sync reports)
and allows enabling sync reporting with filtering of duplicates.
the default option remains to establish sync, with sync reports,
but without duplicate filtering.

Signed-off-by: Raphael Treccani-Chinelli <raphael.treccani@nordicsemi.no>
2023-01-26 07:29:19 -08:00
Vinayak Kariappa Chettimada
47921588b4 Bluetooth: Controller: Broadcast ISO encryption support
Implementation of Broadcast ISO encryption using crypto
toolbox function h8. And support for encryption in lower
link layer for nRF5x series.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-26 13:25:11 +01:00
Vinayak Kariappa Chettimada
4d3f8697a3 Bluetooth: Controller: Make PDU octet3 vendor specific
Make Data, ISO, BIS and CIS PDU structure's octet 3 vendor
specific.

This will allow vendors not supporting the octet 3 or
CTEInfo (8 bits) to save 1 octet in their PDU structures.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-26 13:25:11 +01:00
Vinayak Kariappa Chettimada
117bdbbf64 Bluetooth: Controller: Use len instead of length in PDU structs
To be consistent in naming as len instead of length in PDU
struct definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-26 13:25:11 +01:00
Vinayak Kariappa Chettimada
f4b4f30596 Bluetooth: Controller: Parse and find BIGInfo to setup ISO sync
Add implementation to parse ACAD and find the BIGInfo before
setting up Broadcast ISO Synchronization.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-26 13:25:11 +01:00
Vinayak Kariappa Chettimada
c8f75de1a5 Bluetooth: Controller: Add packing sequential or interleaved comment
Add code comment related to BIG packing sequential or
interleaved being used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-26 13:25:11 +01:00
Vinayak Kariappa Chettimada
cc1f937d61 Bluetooth: Fix endianness of cryptographic toolbox function h8
Convert endianness of supplied parameters before calculating
the AES-CMAC. Bluetooth stores values in little-endian and
crypto traditionally operates on big-endian storage.

Relates to commit e9c542ab5b ("Bluetooth: Add the
cryptographic toolbox function h8").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-26 13:25:11 +01:00
Jonathan Rico
a7746ad55e Bluetooth: Host: Re-subscribe only after encrypt change
Wait until encrypt change to trigger the re-subscription quirk.
Otherwise it could fail with insufficient security.

Also gate it behind a kconfig to make apparent its dependencies:

If `add_subscriptions()` is executed in the first place, that means that
the device was bonded and thus that it has to encrypt the link eventually.

`BT_GATT_AUTO_SEC_REQ` should take care of that.

Also add a new flag to `bt_gatt_subscribe_params` to not send the same CCC
write multiple times in some cases.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Co-authored-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-01-26 10:05:13 +00:00
Alberto Escolar Piedras
8a5273525e nrf52_bsim: Convert from a nRF52832 to a nRF52833
The nRF HW models have been updated to correspond to a 52833 instead
of a 52832. Let's follow them.

The motivation for the change is to enable proper BIS encryption support
(for BT LE Audio ISO).

Changes:

* Point in manifest to latest HW models

* SOC_COMPATIBLE_NRF52832 has been removed, and SOC_COMPATIBLE_NRF52833
added in its place (with no uses at this point)

* Where SOC_COMPATIBLE_NRF52832 was used to set encryption like for a 52832
(to avoid using the MAXPACKETLENGHT), we set the condition to just
SOC_NRF52832.
Note: The MAXPACKETLENGHT register exists in the new simulated nrf52833,
thought it does nothing.

* In the BLE ctrl LLL radio HAL, all macros are renamed accordingly
(timings are NOT changed).

* Board dts definition now refers to the 52833 soc definition. New 52833
features set as not supported by now.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-01-26 09:29:18 +01:00
Vinayak Kariappa Chettimada
c325347816 Bluetooth: Controller: Fix missing node rx release on legacy CPR reject
Legacy Control Procedure fix. Fix missing release of the
node rx allocation that was reserved at the start of the
LE Connection Parameter Request procedure and the procedure
ends with reject indication transmitted to the initiating
peer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-26 09:07:45 +01:00
Aleksander Wasaznik
4b675f34db Revert "Bluetooth: Host: Disable host-based RPA resolution when !BT_PRIVACY"
This reverts commit 5824ac90ecd8dd06d9ea117d345dbc6b069e5840.

The resulting revert takes into account changes to the predicate that
guards the use of `resp_addr`.

In the resulting revert, the predicate guarding the use of `resp_addr`
is differs from the naive revert because the intention of that predicate
is to know when `conn.c:bt_conn_le_create` decided to use the Host
resolver. And, the logic in `conn.c:bt_conn_le_create` has changed. The
changes to the logic in `conn.c` are in the following commits:

89780d715d
5a09325ba9

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-01-24 15:13:36 +01:00
Vinayak Kariappa Chettimada
c104fda34f Bluetooth: Controller: Fix filter accept list and privacy default
Fix filter accept list and privacy feature Kconfig default
based on whether host has them enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-24 15:13:36 +01:00
Vinayak Kariappa Chettimada
00dbf6188c Revert "Bluetooth: Controller: Fix filter accept list and privacy default"
This reverts commit 59eef60665.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-24 15:13:36 +01:00
Morten Priess
cb7c4d3850 Bluetooth: controller: Fix ll_cig_remove not cleaning up
When removing a CIG, the instance and associated CIS instances were not
always released. This causes repeated Create_CIG/Remove_CIG operations
to fail assertion with resource error.
Enables CONFIG_BT_CTLR_CENTRAL_ISO in bsim_test_audio.

Fixes issue #53301.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-01-24 14:49:43 +01:00
Emil Gydesen
0f394c5958 Bluetooth: Audio: Shell: Add missing metadata type
In handle_metadata_update the metadata type was never copied,
causing it to always be 0.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-24 14:34:25 +01:00
Emil Gydesen
5357bd5d0f Bluetooth: Shell: add pa_ad_init for cmd_per_adv_data
Similar to the ad_init that automatically adds advertising data
from other modules, pa_ad_init has been added to do the same
for periodic advertising.

The only use case so far is the BAP broadcast source
data, if enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-24 14:34:15 +01:00
Emil Gydesen
d115bafd40 Bluetooth: Audio: Shell: Split audio_ad_data_add into two
The call to audio_ad_data_add will now either call
connectable_ad_data_add for connectable advertising, or
unconnectable_ad_data_add for unconnectbale advertising.

Most service UUIDs etc. does not make sense to advertise if
not connectable.

This also adds the BAP broadcast advertising data to
unconnectable.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-24 14:34:15 +01:00
Emil Gydesen
f0b104346a Bluetooth: Audio: Shell: Fix off-by-one issue with the HAS uuid
If the advertising is connectable, and we have privacy,
then according to the HAP spec, we should not advertise
the HAS uuid.

This was done by simply truncating the advertising data, but
it was only truncated by 1, instead of by the size of the
UUID.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-24 14:34:15 +01:00
Morten Priess
60b1f2b36b Bluetooth: controller: Reduce ISO peripheral CIS establishement delay
New LLCP will process the CIS establishement in the TX path, meaning it
will only process once every ACL connection interval.
If ACL connection interval is significantly longer than the ISO
interval, CIS packets corresponding to the ACL connection interval will
be lost. This may cause latency in audio rendition.

By processing the CIS establishment in the RX path, notification will be
sent immediately, and audio path is enabled fast to reduce latency.

When a CIS fails to establish, the controller shall complete the
procedure by sending a CIS_ESTABLISHED event containing the error.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-01-24 11:09:51 +00:00
Morten Priess
90d0d93a9c Bluetooth: controller: Fix missing CIS disconnect on MIC failure
Disconnect CIS immediately if event done extra status indicates MIC
failure. Return reason BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL.

Fixes EBQ test /LL/CIS/PER/BV-27-C.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-01-24 11:09:51 +00:00
Morten Priess
78c3bf569b Bluetooth: controller: Implement CIS offset equivalent calculation
When the 'instant' of a CIS is postponed by increasing the conn_event of
the CIS_RSP compared to CIS_REQ, the CIS offset shall be calculated as
an equivalent window offset by an integer number of ISO intervals.
This is obtained by increasing the CIS_Offset_Min and CIS_Offset_Max by
the modulus of the connection interval delay time.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-01-24 11:09:51 +00:00
Morten Priess
a982c9f9f6 Bluetooth: controller: Start CIG immediately if instant is next event
To be able to timely start the first CIS/CIG, if the requested instant
is the next connection event, call ull_peripheral_iso_start directly
from rp_cc_state_wait_rx_cis_ind instead of waiting for next time
through the state machine.

To enable ULL/LLL to prevent adding latency when LLCP is waiting for
instant, local- and remote procedures with instant now expose a function
for checking this state.

Fixed event_counter function to prevent one-off in RX path. Unified to
use single function ull_conn_event_counter.

Fixed LLCP unit tests and added new mock function.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-01-24 11:09:51 +00:00
Emil Gydesen
728384992f Bluetooth: Audio: Unicast client add disabled callback for sink ASE
The sink ASE does not have a disabling state, but since the
stream callbacks does not necessarily match the ASE states,
we need to do our own check to see if a sink ASE has been
disabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-23 11:55:49 -08:00
Emil Gydesen
13a48de72f Bluetooth: Audio: HAS: Fix notifications/indications
Before this commit we simply always notified/indicated
all presets and active index to any bonded device, even
if they never subscribed to anything, or even if we never
registered HAS.

This commit modifies that, so that only the proper
connected clients will get the notifications/indications,
and that we only send them if something has changed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-23 11:54:21 -08:00
Emil Gydesen
50a0f62df2 Bluetooth: Audio: HAS: Remove unused control_point_work_sync
Remove unused control_point_work_sync field in the has_client
struct.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-23 11:54:21 -08:00
Emil Gydesen
ea858f26c5 Bluetooth: Audio: HAS: Fix active_preset_work initialization
The security_changed callback may be called before
bt_has_register has been called, thus making the active_preset_work
handler uninitailized, causing an ASSERT when the work is submitted
in the security changed callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-23 11:54:21 -08:00
Emil Gydesen
d6055f9938 Bluetooth: Audio: Fix HAS double register
Calling bt_has_register multiple times would cause attempts
to register a HAS multiple times. Fixed by adding a check
and return with EALREADY if it is already registered.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-23 11:54:21 -08:00
Vinayak Kariappa Chettimada
02ee85c893 Bluetooth: Controller: FIXME comment for chain PDU time reservation
Add FIXME comments to handle additional time reservations
required for advertising auxiliary channel chain PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-23 13:08:34 +01:00
Andrei Emeltchenko
270668b752 bluetooth: controller: Prevent Out of band access
Add check preventing Out of band access. There are tests trying to
access out of band handle like:

test_sink_invalid_ref and test_source_invalid_ref trying to access
handle 99.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-23 12:04:25 +00:00
Andrei Emeltchenko
02fa6ba7e6 bluetooth: shell: Correct ad_len type
Fixes warning when comparing that size_t is negative.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-23 13:26:59 +02:00
Szymon Czapracki
77c8cffae0 Bluetooth: Audio: Ignore RFU VOCS location
This commit changes VOCS set location behavior.
When an RFU location is written, VOCS ignores it.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2023-01-20 16:11:31 +01:00
Vinayak Kariappa Chettimada
d6c3e04eb8 Bluetooth: Controller: Central maximum data PDU size time spacing
Use the maximum data PDU size time reservation space
considering the Data length could be updated from default
27 bytes to maximum support size.

If maximum time reservation is disabled then time space
reservation corresponding to the default data length at the
time of the start/enable of Central role is used.

Note, currently this value is only used to space multiple central
connections and not for actual ticker time reservations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-20 12:16:43 +01:00
Vinayak Kariappa Chettimada
680e29dd0e Bluetooth: Controller: legacy: Fix conn param request to be cacheable
Fix connection parameter request  procedure to be cacheable
if a remote control procedure is in progress.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-20 12:16:43 +01:00
Vinayak Kariappa Chettimada
5e848761c5 Bluetooth: Controller: legacy: Fix conn upd instant passed on data tx
Fix legacy control procedure implementation to avoid
connection update procedure with reason instant passed
(0x28).

Connection Update Indication PDU is enqueued after data
enqueue to LLL context is paused and the enqueue resumes
when already enqueued data PDUs are all acknowledged.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-20 12:16:43 +01:00
Emil Gydesen
50446afe6c Bluetooth: Audio: Shell: Remove csip_set_coordinator init command
Remove the init command for teh CSIP Set Coordinator.
The main reason for this is that we want to ensure that we
register the conn callbacks early so that `conns` array is
properly filled.

The other callbacks registered in the init function
can easily be moved to where they are needed, and even
unregistered to avoid parsing more data than we need.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-20 09:03:51 +01:00
Andries Kruithof
584bd4069f Bluetooth: controller: Kconfig for event length update
Since the event length update is not necessarily an improvement
in all situations a Kconfig option is added so that it can
be disabled for the users that do not need it.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-01-19 11:18:51 +01:00
Andries Kruithof
e7d60e3ed6 Bluetooth: controller: fix post DLE/PHY update event length
Fix the controller implementation to perform connection
event length reservation based on the completed Data Length
Update and/or PHY Update Procedure.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-01-19 11:18:51 +01:00
Erik Brockhoff
ad06dfc784 Revert "Bluetooth: controller: Reject CIS_TERMINATE when unsupported for role"
This reverts commit ee2a43b5dc.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-01-18 22:19:57 +00:00
Erik Brockhoff
e096ccca8d Bluetooth: controller: fix UNKNOWN_RSP vs. role re CIS TERMINATE support
Proper handling re. non-supported CIS TERMINATE

This fixes EBQ test LL/PAC/CEN/BV-01-C on the general level.
'Replaces' #ee2a43b5dcf884730130345c402d87b2bce9dba1

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-01-18 22:19:57 +00:00
Andrei Emeltchenko
33b0c0db38 bluetooth: ias: Fix dereferencing before NULL check
It does make sense to dereference after NULL check.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-18 07:27:00 -05:00
Andrei Emeltchenko
1ec44b6160 bluetooth: Fix using size instead of len
Fix using wrong field.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-18 07:27:00 -05:00
Pavel Vasilyev
46b78bb1d5 Bluetooth: Mesh: Stop scanner before resetting mesh
When we receive Node Reset message, we schedule work in the system
workqueue to call bt_mesh_reset(). In bt_mesh_reset() we call
bt_conn_disconnect() to disconnect proxy client. bt_conn_disconnect()
will put a buffer to a pool and call k_sem_take to let BT HCI TX thread
process this buffer. Because we stop scanner after disconnecting the
proxy, we can still receive a message at this point. Since BT RX thread
has higher priority than the system workqueue, if we receive a message
while in bt_mesh_reset(), it will be processed when we call
bt_conn_disconnect().

Stop scanner before resetting the mesh to avoid processing of a received
mesh message while in the process of resetting mesh.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-01-18 10:47:44 +01:00
Pavel Vasilyev
6dfc9ecc03 Bluetooth: Mesh: Invalidate pending entries before calling settings API
If, while storing app or net key, or changing cdb, we receive another
mesh message that affects setting of the same key that the mesh
currently stores, the new change won't be stored.

The settings subsystem API has rescheduling point inside. The mesh
settings are stored in the system workqueue and by default mesh messages
are processed from BT RX thread which has higher priority than the
system workqueue.

When the case above happens, a new change will be written to the same
cache entry. But this cache entry will be invalidated after leaving
settings API, which in turns will invalidate the new change:

- Receive Config AppKey Add message
cfg_srv.c -> app_keys.c: bt_mesh_app_key_add()
app_keys.c: update_app_key_settings()
app_keys.c: bt_mesh_settings_store_schedule()
- store_pending() in settings.c is scheduled
settings.c -> app_keys.c: bt_mesh_app_key_pending_store()
app_keys.c: store_app_key() called to store new app key
app_keys.c: settings_save_one() calls flash driver and sleeps
- Receive Config AppKey Delete message while in sleep,
  which wakes up BT RX thread before returning to the system workqueue
cfg_srv.c -> app_keys.c: bt_mesh_app_key_del()
app_keys.c: update_app_key_settings()
app_keys.c: app_key_update_find() finds entry and returns it
app_keys.c: update->clear = 1
app_keys.c: bt_mesh_settings_store_schedule()
- returning back to bt_mesh_app_key_pending_store() from
  settings_save_one()
app_keys.c: update->valid = 0
- the key won't be deleted next time store_pending() is scheduled.

This change moves entry invalidation before calling settings API so that
after returning from settings API, a new change won't be unintentionally
invalidated.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-01-18 10:47:44 +01:00
Mariusz Skamra
36058480e7 Bluetooth: audio: Improve stream coupling for CIS as the unicast client
Allow  the streams to be paired when creating unicast group. This will
allow to reuse the same ISO for the paired streams.

Fixes: #51796
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-01-18 09:56:52 +01:00
Andrei Emeltchenko
69a9ae61b4 bluetooth: shell: Fix using wrong field
Fix using data instead of meta field.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-17 21:50:16 +00:00
Emil Gydesen
6dc20d5ced Bluetooth: Audio: Add BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED as default ctx
Add BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED as the default supported
context. This is primarily due to the requirement that it
shall always be supported, and the value 0 (previous
default) was invalid.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-17 13:17:03 +01:00
Emil Gydesen
2cc1fe259a Bluetooth: Audio: Fix invalid value for setting src supported ctxs
The call to set_supported_contexts in set_src_supported_contexts
gave the wrong value by reference.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-17 13:17:03 +01:00
Ahmed Moheb
60345c1ddc tests: bluetooth: host: Add UT for bt_keys_update_usage()
Unit test project for bt_keys_update_usage().
This part of subsys/bluetooth/host/keys.c unit testing.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2023-01-17 13:13:02 +01:00
Saleh Mehdikhani
a4890f954a Bluetooth: Controller: Fix slot_plus_us by converting max CTE len to us
Fixes #53786
The variable slot_plus_us is assumed to be a number in us unit.
To assign the maximum possible CTE length to this variable,
BT_HCI_LE_CTE_LEN_MAX has been used while this parameter is defined
in a 8us units (it's 0x14=20 that corresponds to 160us).
To convert this number to us, it's needed to be multiplied by 8.

Signed-off-by: Saleh Mehdikhani <saleh.mehdikhani@unikie.com>
2023-01-17 11:27:36 +01:00
Mariusz Skamra
80f87b9480 Bluetooth: has: Fix HAS features value
The bt_has_register_param's preset_sync_support and independent_presets
make sense only if CONFIG_BT_HAS_PRESET_COUNT is non-zero meaning the
CONFIG_BT_HAS_PRESET_SUPPORT is enabled.
Otherwise, those parameters shall be skipped.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-01-16 16:53:39 +01:00
Emil Gydesen
2971c0a588 Bluetooth: Shell: Add cmd_per_adv_set_info_transfer
Add command to perform the Periodic Advertising Set
Info Transfer procedure, which transfers information
about a periodic advertising set to a connected device.

In essence this is just PAST but from the advertiser
instead of a 3rd device.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-16 16:53:15 +01:00
Emil Gydesen
b43f1351ed Bluetooth: Audio: Fix issue with invalid bt_conn_ref in ASCS
In ascs.c we had a case where we assigned stream->conn
without taking the ref.

In bt_audio_stream_attach we did not check if stream->conn
was NULL before taking a reference, causing multiple calls
to ase_config to take multiple references.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-16 16:53:03 +01:00
Anders Storrø
c819f0f8d6 Bluetooth: Mesh: Separate adv tag/set for friend
The purpose of this commit is to facilitate future improvements to the
LPN and friendship feature. By being able to identify friendship related
messages on the advertising layer, it will be possible to treat these in
a specific manner so that message exchange between LPN and friend
devices can be conducted in a more power efficient manner.

This commit adds the following:
   - A separate tag for friendship related messages
   - A optional separate advertising set for friend related messages

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2023-01-16 14:40:54 +01:00
Anders Storrø
bedace2105 Bluetooth: Mesh: Config opt for friend adv latency
Adds Kconfig option to enable tuning the Friend receive delay window.

Friend poll events can be made more efficient by compensating for the
time the non-ideal advertising latency otherwise would add to the receive
delay.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2023-01-16 14:40:54 +01:00
Szymon Czapracki
35bd427927 Bluetooth: audio: Add configurable PACS supported contexts
Add the ability to change supported contexts in PACS.
Enhance the context command in the shell module to make it configurable.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2023-01-13 13:47:19 +01:00
Andries Kruithof
1200fd9314 Bluetooth: host: fix conditional compile for broadcaster role
The call to bt_adv_reset_adv_pool is only required in the
broadcaster role, and not in the observer role, regardless
of the setting of CONFIG_BT_EXT_ADV
As the code was this call was also made for the observer.

Note: handling of the setting of CONFIG_BT_EXT_ADV
is already handled in the bt_adv_reset_adv_pool function

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2023-01-13 09:43:18 +01:00
Emil Gydesen
baad0c300f BluetootH: Host: add helper functions for resolved addresses
There is special handling done for resolved addresses to convert
them to "regular" addresses for the upper layers.
This commits adds two helper functions to check if they are
resolved, and if so, then properly copied.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-12 13:31:12 +01:00
Emil Gydesen
4af1c99f9d Bluetooth: Host: Translate id addr type for PA sync
We only expose random/public address types to the upper layers.
This is done by checking if the address type of events are
resolved addresses, and if so, then we translate them to
public/random.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-12 13:31:12 +01:00
Emil Gydesen
c8014d181e Bluetooth: Audio: Remove unicast_group_valid_qos
The function checked several value, but the BAP spec does
not specify that these cannot be different from stream to
stream in the CIG. The function thus did nothing but needlessly
restrict the upper layers.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-11 17:07:11 +01:00
Pavel Vasilyev
ffc4e716f0 Bluetooth: Mesh: Add extra flag to control seg msg in frnd queue
This commit fixes issue introduced in
5d059117fd.

Use extra flag stored in user data of net_buf to control segmented
messages in Friend Queue. The initial idea with using fragments didn't
work.

This fixes the following PTS tests:
- MESH/NODE/FRND/FN/BV-08-C
- MESH/NODE/FRND/FN/BV-19-C
- MESH/NODE/CFG/HBS/BV-05-C

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-01-11 10:47:06 +00:00
Pavel Vasilyev
7b4f94220d Revert "bluetooth: mesh: Remove illegal use of NET_BUF_FRAG in friend.c"
This reverts commit 5d059117fd.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-01-11 10:47:06 +00:00
Troels Nilsson
d7acb9355c Bluetooth: controller: Fix JIT rescheduling for ext. advertising
Fixes two issues with the JIT scheduler:

Rescheduling of primary advertising packets for extended advertising
when using the JIT scheduler did not work, since the done events for
the primary events never made it into the reschedule logic

The EVENT_DONE_EXTRA_TYPE_ADV_AUX event (for auxillary packets) could
cause a "reschedule" for a primary event that was actually sent
successfully (causing it to be sent twice)

Signed-off-by: Troels Nilsson <trnn@demant.com>
2023-01-10 14:05:42 +00:00
Pirun Lee
1e6f36cca7 Bluetooth: OTS - Add Calculate Checksum support
OTS add Calculate checksum feature support.
OTS client add object calculate checksum function.

Signed-off-by: Pirun Lee <pirun.lee@nordicsemi.no>
2023-01-10 09:59:36 +01:00
Emil Gydesen
4716438c20 Bluetooth: Audio: Modify the compile guard for audio_iso.c
audio_iso.c should only be compiled if we require any streams,
so it is now guarded by CONFIG_BT_AUDIO_STREAM.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-10 09:58:54 +01:00
Emil Gydesen
ce9385b388 Bluetooth: Audio: Shell: Fix compile warning for 0 client snk/src ASE
In case that CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT or
CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SRC_COUNT is set to NULL, the
unicast client implementation in the shell would have compile
warnings, since the arrays would be 0 and we would attempt to
access it some places (or rather the compiler/linker would
think that, but it would never happen at runtime).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-10 09:25:36 +01:00
Jonathan Rico
e6aba3e9af Bluetooth: host: clear ATT_CONNECTED flag on detach
Clear the `ATT_CONNECTED` flag when a channel is detached (could be after
an ATT timeout).

Also convert the assert checking it in `chan send` to an `if` test, since
the channel could be disconnected from a different thread than the one
triggering `chan_send`.

Fixes #53247.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-01-09 19:19:39 +01:00
Emil Gydesen
d37613d20a Bluetooth: Audio: Audio ISO use log_config_inherit
Change the BT_AUDIO_ISO logging module to use
log_config_inherit to be consistent with the other LE Audio
logging modules.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-09 15:27:28 +00:00
Emil Gydesen
a9071b361f Bluetooth: Audio: Add missing codec debug Kconfig
Add misisng codec debug Kconfig for the codec.c file.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-09 15:27:28 +00:00
Emil Gydesen
6ca40703d1 Bluetooth: Audio: Fix CAP initiator debug level
Add missing debug level Kconfig option and use it.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-09 15:27:28 +00:00
Emil Gydesen
5e49282dab Bluetooth: Audio: Fix CAP Acceptor Debug log level
The implementation did not use the defined log level
Kconfig.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-09 15:27:28 +00:00
Vinayak Kariappa Chettimada
9aa4cdbb67 Bluetooth: Host: Fix access of uninitialized bt_dev.le.acl_pkts
ISO Synchronized Receiver only builds do not transmit and
hence may not have any tx buffers allocated in a
Controller, leaving bt_dev.le.acl_pkts semaphore
uninitialized or bt_conn_get_pkts() returning NULL.
Do not use the semaphore if no Tx buffers allocated in a
Controller.

Regression in commit ef19c64f1b ("Bluetooth: host: poll on
CTLR buffers instead of host TX queue").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-01-09 12:41:33 +01:00
Kim Sekkelund
78999f0db6 Bluetooth: Audio: TBS: Fix read buffer
Add common function to handle large GATT reads of strings.
Initialize the buffer pointers in the net_buf which is used for large
GATT reads by bt_tbs_client_read_call_state() and
bt_tbs_client_read_current_calls().
Define the size of the allocated buffer based on the enabled features.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2023-01-09 12:18:55 +01:00
Emil Gydesen
489e99c091 Bluetooth: ISO: Fix bad handle of data path error for broadcast
The way that the braodcast clause for handling failing
ISO data path would end up in the __ASSERT. It has been
slightly modified to make it use if-else properly.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-09 12:18:11 +01:00
Emil Gydesen
249d4774f3 Bluetooth: Audio: Add bt_audio_dir_str to improve logging of dir
The direction of a stream/endpoint/parameter has just been
logged as a unsigned integer. This commits adds a
value -> string internal function that would log
BT_AUDIO_DIR_SINK as "sink" and BT_AUDIO_DIR_SOURCE
as "source".

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-09 12:18:03 +01:00
Erik Brockhoff
2f61771948 Bluetooth: controller: consider host ctrl feature bits in feat exchange
Host controlled feature bits were not considered in feature exchange
procedure. This is fixed.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2023-01-08 19:48:38 +01:00
Emil Gydesen
57218eee31 Bluetooth: Host: Add BT_CONN_INTERVAL_TO_US
The macro BT_CONN_INTERVAL_TO_MS was used a fair amount
of places, but it often was used with integers. This meant
that sometimes the resulting (integer) value would be
incorrect, as something like 7.5ms interval would not
be properly stored as a integer in millisecond units.

Adding BT_CONN_INTERVAL_TO_US allows users to still use
integers to store the result, but in a more accurate unit.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-08 19:47:03 +01:00
Emil Gydesen
8d86fa0125 Bluetooth: Audio: Add support for encrypted broadcast
Add support for adding a broadcast code to the broadcast
source.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-06 10:35:25 +00:00
Mariusz Skamra
8cd6c55d96 Bluetooth: audio: ascs: Fix possible race condition
This fixes possible ASE state race condition. The notification is sent
immediately once the ASE state changed that eliminates a situation where
the state was changed by user action (API function call) when the state
was not yet notified to the remote Unicast Client.

Fixes: BAP/USR/SCC/BV-158-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-01-05 12:43:32 +01:00
Mariusz Skamra
9148fb65d7 Bluetooth: att: Fix deadlock on meta data context allocation
This fixes deadlock that happened waiting for meta data in system
workqueue.
The meta data always get freed in the system workqueue,
so if we're in the same workqueue but there are no immediate
contexts available, there's no chance we'll get one by waiting.

Fixes: #53455
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-01-04 16:51:05 +01:00
Emil Gydesen
7d410c5cad Bluetooth: Audio: Fix issue with creating unidirectional CIS
As the unicast client, we would always create bidirectional
CIS to ensure that the PHY parameter is correctly set.
We can, however, just set the (required) PHY value and
leave the SDU and RTN values as 0, to avoid
creating bidirectional CIS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-04 10:35:14 +01:00
Emil Gydesen
1e5be3f020 Bluetooth: Audio: Fix issue with unicast client src/snk ASE count
If either the sink or source ASE count was zero, calls to
ARRAY_SIZE(srcs) or ARRAY_SIZE(sinks) would cause a build warning.

The arrays should actually not be there at all if the respective
ASE count was 0, as that is just a waste of memory. The arrays,
and all uses of them, have been properly guarded.

This also adds a build assert to ensure that at least one
of them is non-zero, and that we also test building either
of them with the value 0.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-04 10:35:14 +01:00
Emil Gydesen
b9a6e04cb3 Bluetooth: Audio: Add AUDIO_ISO debug logging
Add a logging module for the audio_iso.c file, to enable
logging for that.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-04 10:35:14 +01:00
Emil Gydesen
32ff1b671b Bluetooth: Audio: Add (un)bind of audio iso for streams
This allows us to allocate and bind the Audio ISO structs
to Audio Streams, thus allowing us to create the unicast group
before they have been configured.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-04 10:35:14 +01:00
Emil Gydesen
4c058402a5 Bluetooth: Audio: Fix issue with deleting unicast groups
There was a bug in bt_audio_iso_unbind_ep that caused an
assert, missing unbinding on stream released callback
and missing state check in bt_audio_unicast_group_delete

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-01-04 10:35:14 +01:00
Hein Wessels
3210541c86 toolchain: gcc: rename popcount to avoid conflict with C++20
The macro conflicts with the C++20 feature std::popcount

fixes zephyrproject-rtos/zephyr#53421

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
2023-01-03 11:06:45 +01:00
Emil Gydesen
4e3205d238 Bluetooth: Audio: Add packing to unicast group create
Add the ISO packing field when creating a unicast group.

This refactors the structure of the unicast group create,
as it now takes both the packing as a group parameter, as well
as an array of stream-specific parameters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-22 10:59:16 +01:00
Emil Gydesen
ba1949759d Bluetooth: Audio: Add packing field to broadcast source
Add support for setting the ISO packing field when
creating a broadcast source.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-22 10:59:16 +01:00
Emil Gydesen
2935cac9d6 Bluetooth: Audio: Fix handling properly deleting endpoints
When there is an ACL disconnect, or the unicast group is otherwise
deleted, the endpoints were not properly handled, causing
incorrect `dir` values and ASSERTs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-21 16:19:35 +01:00
Emil Gydesen
21fd387cab Bluetooth: Audio: Fix unicast group add/free handling of endpoints
When adding or removing a stream from the group, the
endpoint may or may not have been allocated depending
on the state of the endpoint.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-21 16:19:35 +01:00
Emil Gydesen
f1bedd01c1 Bluetooth: ISO: Remove wrong requirement for cc_len
The hci_le_setup_iso_data_path function required that if
the path->cc was set, the length could not be 0.

There is no reason why it should not be allowed to be 0
in that case.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-21 16:19:35 +01:00
Emil Gydesen
a7e7d87912 Bluetooth: Audio: Fix issue with creating the CIG as unicast client
The unicast client could not create a CIG with a unidirectional
CIS, because it would not set the correct values as per the
HCI spec for the unused CIS direction.

Instead of implementating a work around, this commit modifies
it so that for unidirectional CIS, we copy the QoS values
to the unused direction, so that we always set valid values,
but it also allows us to actually use that CIS direction later,
assuming that the QoS settings does not change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-21 16:19:35 +01:00
Emil Gydesen
f239df0ca7 Bluetooth: Audio: Fix audio_iso handling for unicast client
For the unicast client, the direction for the endpoint
is reversed in terms of RX/TX, i.e. a sink endpoint is
RX for the unicast server and broadcast sink, but TX
for the unicast client, and similar for the source endpoint.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-21 16:19:35 +01:00
Erwan Gouriou
66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Pavel Vasilyev
932e57396f Bluetooth: Mesh: Add macros to initialize bt_mesh_msg_ctx struct
The macros are added to make clear which fields of `struct
bt_mesh_msg_ctx` needs to be initialized by an application.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-12-20 17:05:04 +00:00
Lars Knudsen
081b83531b Bluetooth: has: Make HAS registration dynamic
This changes HAS registration to be dynamic and let's the
application set Hearing Aid Type and binaural features.

Often, devices are flashed with generic firmware with some
features stored post factory production, requiring
the settings to be moved from compile time to run-time.

This change will increase the RAM usage as the GATT
service is moved from ROM to RAM.

Signed-off-by: Lars Knudsen <larsgk@gmail.com>
Co-author: Soren Engquist <soren@engquist.dk>
2022-12-20 17:04:45 +00:00
Lingao Meng
f3cea46c75 Bluetooth: Host: Fix missing pull left mem in scan pdu
For num_reports field bigger 1, should pull left mem.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-12-20 10:20:10 +01:00
Emil Gydesen
1424df424c Bluetooth: Audio: Add broadcast source metadata update function
Add API to do the BAP Broadcast Source Metadata update procedure,
which updates the metadata of a broadcast source while
it is streaming.

This is also makes all checks for the "head stream" the same.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-20 09:23:08 +01:00
Emil Gydesen
302ec9fa37 Bluetooth: Audio: Remove const for bt_audio_stream_reconfig codec
The codec is assigned to the stream. However since the metadata,
which is stored in the codec, may be modified by other means,
the stored pointer cannot be const, and thus the
codec argument to bt_audio_stream_reconfig cannot be const
either.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-20 09:23:08 +01:00
Fredrik Danebjer
18a889fb8b Bluetooth: Audio: ASCS: Make ASE Allocation Dynamic
Decoupled the ASEs from the ASCS Session and made them dynamically
allocated instead. A Kconfig option was added to set the maximum
number of active ASEs at a single time. The intent here is to allow
the developer greater control over memory usage; this fix addresses
one of the largest ram usages in le audio.

Signed-off-by: Fredrik Danebjer <fredrik@danebjer.com>
2022-12-20 09:23:00 +01:00
Fredrik Danebjer
15644da0a4 Bluetooth: Audio: Endpoint: Decouple Client and Server
Refactored out the client and server members of the endpoint struct
and placed the relevant members in wrappers in ascs and
unicast_client.

Signed-off-by: Fredrik Danebjer <fredrik@danebjer.com>
2022-12-20 09:23:00 +01:00
Emil Gydesen
32c7b9f46b Bluetooth: Host: Add logging of pairing req/rsp
Add logging of the fields in the sent and received pairing
requests and responses. This makes it easier to debug
why a pairing would be e.g. rejected, or simply to get
more insight in the resulting pairing.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-20 09:22:10 +01:00
Emil Gydesen
a96f8ba9ba Bluetooth: ISO: Fix ISO MTU when CONFIG_BT_BREDR=y
If CONFIG_BT_BREDR=y and bt_dev.le.acl_mtu == 0, then we
would report the bt_dev.br.mtu for ISO channels.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-19 18:16:01 +01:00
Emil Gydesen
ba0bb89a70 Bluetooth: ISO: Fix conn_mtu for BT_CONN_TYPE_ISO
If the bt_dev.le.iso_mtu was 0, then we would report
bt_dev.le.acl_mtu if CONFIG_BT_CONN=y (which is often true when
CONFIG_BT_ISO=y). Thus if the ISO MTU is 0, we would often
return a non-0 value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-19 18:16:01 +01:00
Emil Gydesen
b245b023e1 Bluetooth: Audio: Always start BAP discovery at handle 0x0001
Instead of only conditionally starting the discovery at
0x0001, we now always start it at that handle. Since we are
reading by UUID, this should not really affect performance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-19 18:13:02 +01:00
Emil Gydesen
fd6e6601e0 Bluetooth: Audio: Fix logging of object ID in mcc.c
mcc.c used 0x%016x, but for some platforms we need to
be more explicit and use 0x%016llx to avoid compile
warnings.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-19 18:12:50 +01:00
Emil Gydesen
e3fcf8267a Bluetooth: Audio: Fix issue with non-bonded devices in has.c
The HAS implementation of the security_changed callback
expected all devices to have bonded, and thus always added them
to the ntf_bonded implementation.

This adds a check to whether the device is actually bonded.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-19 18:12:38 +01:00
Jonathan Rico
dc4d63e97b Bluetooth: host: adv: set the address in bt_le_adv_resume
The address could have changed. The issue linked (and bsim test in previous
commit) shows a scenario where that could happen:

- we start scanning, host will use NRPA
- we start advertising, host will use identity address
- a device connects (as a central)
-> advertising resume fails for some unrelated reason
- another device connects (as a peripheral)
- the central device disconnects, we resume scanning
- the peripheral disconnects, the stack resumes advertising
-> but it mistakenly advertises using the NRPA set by the scanner

Fixes #52059 .

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-12-19 09:37:25 +00:00
Jonathan Rico
5f98b1bea4 Bluetooth: host: adv: add adv_is_directed helper
Makes it more readable.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-12-19 09:37:25 +00:00
Emil Gydesen
c27db9ed90 Bluetooth: Shell: Move the name filter last
Moved the name filter last, as that it the most expensive
to use.

The address filter has almost been moved after the more
trivial checks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-16 11:05:24 +00:00
Emil Gydesen
bc1bb4f63c Bluetooth: Shell: Add pa_interval scan filter
Add filtering for the pa_interval. This can be used to
easier find devices that are advertising with periodic
advertising.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-16 11:05:04 +00:00
Troels Nilsson
c0a5b1ef7b bluetooth: controller: Reduce user ops status to uint8_t
The status field is currently a uint32_t even though there are only
3 possible values. Reducing it to a uint8_t allows status to fit in
existing padding in the struct, saving 4 bytes per ticker_user_op

Updated function signatures to match; ticker_op_func left as-is
to avoid having to update a whole bunch of files for no real benefit

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-12-16 11:02:30 +00:00
Mariusz Skamra
5fc2079963 Bluetooth: audio: ascs: Handle CIS failed to be established error
In case CIS failed to be established, leave the ASE in enabling state
waiting for peer to retry.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-12-15 14:31:11 +00:00
Jonathan Rico
ca51439cd1 Bluetooth: host: copy fragment data at the last minute
Only copy the data from the 'parent' buf into the segment buf if we
successfully acquired the HCI semaphore (ie there are available controller
buffers).

This way we avoid pulling and pushing back the data in the case where there
aren't any controller buffers available.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-12-15 09:58:07 +00:00
Jonathan Rico
ef19c64f1b Bluetooth: host: poll on CTLR buffers instead of host TX queue
When there are no buffers, it doesn't make sense to repeatedly try to send
the host TX queue.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-12-15 09:58:07 +00:00
Jonathan Rico
c3e5fabbf1 Bluetooth: host: make HCI fragmentation async
Make the ACL fragmentation asynchronous, freeing the TX thread for sending
commands when the ACL buffers are full.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-12-15 09:58:07 +00:00
Emil Gydesen
cbd1e67574 Bluetooth: Audio: Remove newlines from HAS log statements
Removes two log statements in HAS that added a newline,
which it shouldn't.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-15 10:45:37 +01:00
Emil Gydesen
7630161376 Bluetooth: Audio: Shell: Improve printing of incoming audio
Instead of printing every audio packet (typically
arriving every 7.5 or 10ms), we now only print every 100th.

Ideally we would add support for changing the number of
"skippe" audio packets at runtime in a shell command, but
that will be postponed.

Ideally we would also have a rx_cnt per stream, but that will
also be postponed to the future, and should be fixed with e.g.
the sequence number (seq_num) as well.

Finally this commit also adds a verification if the currently
incoming data packet contains the same ts or seq_num of the
previous one, and print if it does, as this indicates that
we are receiving some invalid data.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-15 10:44:56 +01:00
Emil Gydesen
b2a8fa1392 Bluetooth: Audio: Shell: Fix issue with restarting start_sine
The lc3_start_time and lc3_sdu_cnt were not reset properly,
causing it to fail when trying to do start_sine after calling
stop_sine.

This commit also ensures that the sending of the sine wave is
stopped once the stream is either released or stopped.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-15 10:44:11 +01:00
Emil Gydesen
366ddedeb6 Bluetooth: Host: Fix issue with setting 0/NULL data for PA
bt_le_per_adv_set_data would not accept the ad to be NULL or
the ad_len to be 0, making it impossible to set no data (which
effectively clears existing data).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-15 09:40:16 +01:00
Emil Gydesen
336d706f52 Bluetooth: Host: Add length values to malformed adv data warning
Add the advertised length, and the actual length, in the log statement
so it is more clear what the issue is.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-15 09:39:55 +01:00
Fredrik Danebjer
c5b270e7b0 Bluetooth: GATT: Fix missing endianess conversion on include end-handle
Added missing conversion to CPU endianess for the include service
end-handle.

Signed-off-by: Fredrik Danebjer <fredrik@danebjer.com>
2022-12-14 17:26:03 +01:00
Vinayak Kariappa Chettimada
5fab7a5173 Bluetooth: Controller: Fix MIC failure transmitting LL_CIS_REQ PDU
Fix MIC failure transmitting LL_CIS_REQ PDU.
The MAXPACKETSIZE value was not set with using Long Control
PDUs.

Relates to commit e895948047 ("Bluetooth: Controller: Add
Long Control PDU support").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:44:40 +01:00
Vinayak Kariappa Chettimada
88d94a5b8b Bluetooth: Controller: Remove duplicate code in nRF5 radio HAL
Remove duplicate PPI/DPPI configuration in
radio_tmr_start_now() which reuses radio_tmr_start_us().

And other minor refactor to remove unnecessary conditional
compilation of a define.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:44:22 +01:00
Vinayak Kariappa Chettimada
dfb5988da2 Bluetooth: Controller: Fix dynamic tx power for Broadcast ISO
Fix compilation error for ISO Broadcaster with dynamix Tx
power support, and remove setting tx power for ISO
Synchronized Receiver.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:44:06 +01:00
Vinayak Kariappa Chettimada
0dfa37b7e1 Bluetooth: Controller: Add internal comments in BIS LLL code
Add internal comments explaining the control flow in the
BIS synchronization in LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:43:47 +01:00
Vinayak Kariappa Chettimada
b5d089fb48 Bluetooth: Controller: Receive starting at selected BIS and skip others
Updated implementation to save power consumption by
scheduling BIG event starting at the first BIS selected for
synchronization. Also, skip reception of any unselected
BISes in between multiple BISes that the Broadcaster is
transmitting. Added advance calculation of next subevent
channel index.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:43:47 +01:00
Vinayak Kariappa Chettimada
9a51ece3fd Bluetooth: Controller: Fix BIS subevent channel indices
From Bluetooth Core Specification v5.3 Vol 6 Part B Section
4.4.6.8 Channel indices,

The subevent number se_n shall be set to the values 1 to
NSE, in order, for the subevents on a given BIS - the same
values shall be used for all the BISes in a BIG - and to 1
for the control subevent.

Hence, fix implementation to reset back to se_n to 1 when
next BIS PDUs are transmitted in the subevents.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:43:47 +01:00
Vinayak Kariappa Chettimada
9660f52dc7 Bluetooth: Controller: Fix Broadcast ISO PDU receive connection handle
Fix broadcast ISO PDU receive connection handle. The look up
was using BIS index instead of the index of the selected
stream that is being received.

Example, when receiving BISes 2 and 4, only the connection
handle for BIS 2 was correct and connection handle lookup
was out-of-bounds for BIS 4; symptoms being that Host
dropped the received ISO PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:43:47 +01:00
Vinayak Kariappa Chettimada
46ead9915d Bluetooth: Controller: One extra ISO rx buffer for empty PDU reception
Budget for one extra ISO Rx PDU buffer for empty/NULL PDU
reception that has to always remain free in order to be able
to setup radio h/w for new PDU receptions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:43:47 +01:00
Vinayak Kariappa Chettimada
554ea0bae3 Bluetooth: Controller: Fix missing cssn and cstf flag initialization
Fix missing cssn and cstf flag initialization in ISO
Broadcast LLL implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-12 18:43:47 +01:00
Mariusz Skamra
a68f78526d Bluetooth: audio: tbs_client: Fix misleading error log
This fixes error log that has been shown if number of calls in the list
was equal to CONFIG_BT_TBS_CLIENT_MAX_CALLS.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-12-12 14:55:41 +01:00
Hang Fan
ebcfa196fc Bluetooth: audio: fix invalid ase state transition
When Receiver Stop Ready operation has completed, the Unicast Server
may request to terminate a CIS and set source ASE state to Qos
configured state immediately. But after CIS disconnected completed,
it will transition source ASE state from Qos Configured to Disabling
state. It's invalid and will cause assert.

we should add Streaming and Enabling state check when CIS disconnected.

Signed-off-by: Hang Fan <fanhang@xiaomi.com>
2022-12-12 14:55:32 +01:00
Vinayak Kariappa Chettimada
a1b4896efe Bluetooth: Controller: Fix BT_LL_SW_LLCP_LEGACY compile error
Fix compile error building application with
BT_LL_SW_LLCP_LEGACY. Request Peer SCA command is not
supported in legacy control procedure implementation.

Relates to commit 76439d0ba4 ("Bluetooth: controller:
integrating SCA procedure and adding HCI API").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-12-11 18:29:02 +01:00
Erik Brockhoff
7c9d792211 Bluetooth: controller: refactor to remove duplicated functionality
Duplicated functionality used for tx handling is moved to local proxy
functions to avoid code overhead

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-09 12:44:39 +01:00
Erik Brockhoff
edef6f3b46 Bluetooth: controller: refactor conn update notify function
Reusing code between local/remote procedure

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-09 12:44:39 +01:00
Erik Brockhoff
2fcbdaf3ba Bluetooth: controller: refactor pdu encode/decode functions
Introducing common pdu struct declarations for conn param req/rsp and
data length req/rsp to utilize identicality for optimal pdu handling

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-09 12:44:39 +01:00
Erik Brockhoff
f5f0714c81 Bluetooth: controller: refactor to remove duplicated state function
Removing code for duplicate state handling in local  procedure

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-09 12:44:39 +01:00
Erik Brockhoff
7f0a801cdc Bluetooth: controller: refactor enc setup lll function
Reusing code between local/remote procedure

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-09 12:44:39 +01:00
Erik Brockhoff
1f97652998 Bluetooth: controller: refactor ull_rx_put/sched
Instead of calling both ull_rx_put and ull_rx_sched, combine into one
function

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-09 12:44:39 +01:00
Erik Brockhoff
ddeb0e9f6e Bluetooth: controller: refactor ll_rx_put/sched
Instead of calling both ll_rx_put and ll_rx_sched, combine into one
function

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-09 12:44:39 +01:00
Morten Priess
ee2a43b5dc Bluetooth: controller: Reject CIS_TERMINATE when unsupported for role
If a central or peripheral is not configured for ISO connected streams,
reject a remote LL_CIS_TERMINATE_IND procedure, responding with an
unsupported feature error (BT_HCI_ERR_UNSUPP_FEATURE).

This fixes EBQ test /LL/PAC/CEN/BV-01-C.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
a803588d2c Bluetooth: controller: Add handle to ll_data_path_sink_create
For making handle available in vendor sink creation, add ISO handle
to function prototype.
Expose datapath allocation via new ull_iso_datapath_alloc function.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
f1c9a02dd6 Bluetooth: controller: Minor ISO refactoring due to compiler issue
Function ll_setup_iso_path has a construction which causes proprietary
compiler to generate incorrect code. As a workaround, local data path
pointer variables are eliminated.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
a93a860231 Bluetooth: controller: Fix ISO Test Mode SDU counting for framed
For framed case, the internal RX SDU counter would increment regardless
of whether the first valid SDU was received or not. According to spec,
SDU counter synchronization is done from first valid SDU.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
fae2beba9d Bluetooth: controller: Don't consider CIS connected before established
Make sure ll_iso_stream_connected_get returns NULL until CIS is
established. Always return DISALLOWED when trying to disconnect a CIS
which is not connected.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
44030a9da7 Bluetooth: controller: Fix CIS restart state de-initialization
When a CIS is terminated, the associated link pool must be de-
initialized to be ready for next creation of the corresponding
instance in memory.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
6e2dea3e41 Bluetooth: controller: Reject CIS_REQ with invalid PHY
Send LL_REJECT_EXT_IND if a LL_CIS_REQ was recevied with invalid PHY
specification.

Fixes EBQ tests:
  /LL/CIS/PER/BI-02-C
  /LL/CIS/PER/BI-03-C
  /LL/CIS/PER/BI-05-C
  /LL/CIS/PER/BI-06-C

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
a9f855e2bf Bluetooth: controller: Fix error in ISO reset sequence
To avoid races, ull_conn_iso_reset must be performed before higher level
ull_iso_reset.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Morten Priess
613283548c Bluetooth: controller: Fix LL_CIS_TERMINATE RX node leak
Reusing NODE_RX_TYPE_TERMINATE for CIS requires special deallocation
handling to prevent memory leak.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-09 11:18:49 +01:00
Pavel Vasilyev
163c2bc316 Bluetooth: Mesh: Warn log mode incompatibility with friendship
Log modes other than the deferred may cause unintended delays during
processing of log messages. This in turns will affect scheduling of the
receive delay and receive window for both, Friend and LPN.

Adding a compilation warning instead of assert as a user may still want
to compile a code with friendship feature enabled without actually
establishing a friendship.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-12-09 11:18:18 +01:00
Pavel Vasilyev
37ab40f2f7 Bluetooth: Mesh: Calculate adv duration instead of using estimation
The duration value passed to `struct bt_mesh_adv_cb::start` is an
estimation.

When running mesh with BT_MESH_ADV_EXT option, the actual duration will
be shorter and the `struct bt_mesh_adv_cb::end` is called right after
the contorller finished advertising. Using the calculated duration the
lpn node can be configured for a shorter receive delay and receive
window and eventually use less power.

When running mesh with BT_MESH_ADV_LEGACY option, the time when adv will
be sent out by controller is unpredictable. But the time between start
and end `struct bt_mesh_adv_cb` callbacks is always 50ms for a single
advertisement. Therefore, the receive delay can't be less than 50ms.

With this change, adv duration is calculated between start and end
callbacks, but timers are started after end callback is called. Therefore
we need to consider time between two callbacks when setting timeouts for
timers.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-12-09 11:18:18 +01:00
Pavel Vasilyev
5b4b5c0d34 Bluetooth: Mesh: Call friendship callbacks at the end
If a user does some heavy operations in friendship callbacks
unintentionally, this may break friendship communication as timers will
be scheduled or messages will be queued only after code execution comes
back from these callbacks. To avoid this issue, call callbacks only after
required operations are done.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-12-09 11:18:18 +01:00
Erik Brockhoff
68ef1306fb Bluetooth: controller: proper handling of invalid pdu in CIS create
Do not assert on invalid PDU in CIS create procedure. Instead terminate
with reason BT_HCI_ERR_LMP_PDU_NOT_ALLOWED

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-07 10:30:11 +00:00
Nirosharn Amarasinghe
8510ecf6e3 Bluetooth: controller: corrected time stamps for unframed RX
Corrected an omission in the ISO-AL that required an SDU interval to
be added to the reconstructed RX time stamps for each SDU after the
first.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2022-12-07 10:15:17 +00:00
Pavel Vasilyev
5d059117fd bluetooth: mesh: Remove illegal use of NET_BUF_FRAG in friend.c
This commit removes illegal use of NET_BUF_FRAG in friend.c, which is an
internal flag.

Now `struct bt_mesh_friend_seg` keeps pointer to a first received
segment of a segmented message. The rest segments are added as fragments
using net_buf API. Friend Queue keeps only head of the fragments.
When one segment (currently head of fragments) is removed from Friend
Queue, the next segment is added to the queue. Head has always 2
references: one when allocated, another one when added as fragments
head.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-12-06 11:06:43 +02:00
Morten Priess
51ba6e9dd3 Bluetooth: controller: CIS Central fixes
- New calculation of Max_PDU for framed case according to BT Core 5.4
- Fix CIS_Offset calculation for multiple CIS usecase
- Fix resume ticker setup for central

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-05 15:48:39 +01:00
Emil Gydesen
abef3d3001 Bluetooth: Audio: Removed unused cmd_mcc_ots functions
The functions were not used, and MCC doen not use OTS, but
rather OTC.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-02 16:08:54 +01:00
Emil Gydesen
312b06a130 Bluetooth: Audio: Add missing static for MCC shell commands
Adds the `static` keyword to the MCC shell command functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-02 16:08:54 +01:00
Emil Gydesen
b12a09baa8 Bluetooth: Audio: Replace generic media "send cmd" with explicit commands
Rather than exposing shell commands that take an opcode and
an optional parameter, the shell commands are now explicit
so that it is easier for a person to use the shell.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-02 16:08:54 +01:00
Emil Gydesen
04092ac9a5 Bluetooth: Audio: Change shell print for default_stream == NULL checks
Change what is printed to the shell if the default_stream == NULL
check fails.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-02 11:32:18 +01:00
Emil Gydesen
ea448ed69a Bluetooth: Audio: add check for default_conn for audio qos shell command
Add a missing NULL check for the command.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-02 11:32:18 +01:00
Emil Gydesen
ff7f644aff Bluetooth: Audio: Remove audio connect command
The `audio connect` shell command did not really do
anything anymore, and has thus been removed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-02 11:32:18 +01:00
Emil Gydesen
34715022ef Bluetooth: Audio: Move some unicast shell commands to also support server
Some of the unicast audio shell commands were guarded by
CONFIG_BT_AUDIO_UNICAST_CLIENT and only usable by the client.

This moves some of the commands to a CONFIG_BT_AUDIO_UNICAST
guard instead, so that they are usable for builds with just
the server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-12-02 11:32:18 +01:00
Mariusz Skamra
795573c43f Bluetooth: audio: shell: Fix VCP Volume Renderer build
This fixes VCP Volume Renderer linker error that was seen if built
with VOCS and/or AICS support disabled.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-12-02 11:28:34 +01:00
Morten Priess
1d235189d5 Bluetooth: controller: Remove HCI_Read_Local_Supported_Codecs [v1]
An LE controller shall no longer support HCI_Read_Local_Supported_Codecs
[v1] according to BT Core 5.3.
Command bit and support code removed.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-12-01 15:49:25 +01:00
Erik Brockhoff
218da91211 Bluetooth: controller: Implementing CIS STO & establishment timeout
Adding a bit-mask to the 'extra' data structure allowing passing info
re. active CIS's to the ull_conn_iso_done handling. Per CIS storing
an expiration time counter, monitoring in done handling. Adding
establishment timeout monitor in CIS Create procedure, completing
and ntf'ing accordingly.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-01 10:32:34 +01:00
Erik Brockhoff
3c68fa45d2 Bluetooth: controller: fixing possible race re. termination vs. cis's
If a CIS is in teardown state, the data in structure should not be
trusted, so skip passing data to ISOAL

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-01 10:32:34 +01:00
Erik Brockhoff
0604a4d2f1 Bluetooth: controller: store STO value instead of pre-calculated reload
Instead of storing the calculated reload value (in conn intervals) in
the conn object, now store the timeout value, and perform calculation
when used. This allows using the timeout value across all CIS's without
having to re-calc and store on change of TO

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-12-01 10:32:34 +01:00
Kamil Piszczek
916e02563c bluetooth: host: smp: unauth bond overwrite on different identity
Added a new Kconfig option for the Bluetooth Host to allow
unauthenticated pairing attempts made by the peer where an
unauthenticated bond already exists on other local identity.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2022-12-01 09:48:02 +01:00
Théo Battrel
e4be91b0c4 Bluetooth: Update Bluetooth legacy logging Kconfig
Update the Bluetooth specific Kconfig legacy log template to use the new
log inheriting template.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-30 14:37:58 +01:00
Erik Brockhoff
9f5eb0f1a8 Bluetooth: controller: fixup to peripheral CIS Create check instant
In case a CIS is the first in a CIG, we should start ISO peripheral
early to allow small CIS offsets

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-30 13:39:44 +01:00
Erik Brockhoff
9b553c3eb2 Bluetooth: controller: fixup to peripheral CIS CREATE procedure
Missing decode of conn_event_count on CIS_IND
Peripheral Suggest update to conn_event_count in case of a delayed
CIS_IND, allowing CIS peripheral more time to setup

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-30 13:39:44 +01:00
Jonathan Rico
42e490917e Bluetooth: Host: l2cap: disconnect when PDU > MPS
The Bluetooth spec states that a K-frame exceeding the device's MPS
should trigger a disconnection of the channel.

Fixes two PTS tests that verify this behavior:
L2CAP/LE/CFC/BV-27-C
L2CAP/ECFC/BV-34-C

The current behavior is a silent truncation, which is not very nice for
the user, even if the spec would allow it.

Fixes #52228 and #51174.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-11-30 12:50:10 +01:00
Thomas Ebert Hansen
f192fccf3a Bluetooth: controller: Add lock around LLCP data
Add mayfly locking around the access to the local pending procedure list
as it is accessed by both thread and mayfly.

Fixes #45427

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2022-11-30 12:49:15 +01:00
Erik Brockhoff
83c380bfcd Bluetooth: controller: adding missing NTF wait state to SCA procedure
When generating notification for Sleep clock accuracy, check for
success on rx_node allocation was left out. This is added.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-30 12:48:52 +01:00
Erik Brockhoff
d99052b316 Bluetooth: controller: set bit to indicate support for Request Peer SCA
Setting bit to indicate that LE Request Peer SCA command is supported

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-30 12:31:26 +01:00
Emil Gydesen
e80c70fd05 Bluetooth: Audio: Fix MCC disconnect issue
When MCC disconnected, it would memset the entire instance.
This causes issues, because the subscription parameters
would also be memset, causing the `notify` callback to
be set to NULL. If this was done as part of a disconnect,
the GATT layer would attempt to call the notify callback
as part of cleaning up the ACL, but if the callback was
set to NULL (from the memset) this caused a fatal error.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-29 13:26:57 +01:00
Emil Gydesen
f3b0a8f478 Bluetooth: Audio: Fix broadcast assistant recv state pointer value
When reporting a receive state to the upper layers, the broadcast
assistant should report NULL if there is not a receive state
active. The "activeness" of a receive state is determined by
the length of the characteristic - If it is 0 then there
is no receive state active.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-29 09:50:22 +01:00
Emil Gydesen
bbc85e0b2c Bluetooth: Audio: Use bt_vcp_vol_ctlr instead of bt_vcp
Use the `bt_vcp_vol_ctlr` opaque type instead of the more
generic `bt_vcp`.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
914e96e6fe Bluetooth: Audio: Vol rend use bt_vcp_vol_rend instead of bt_vcp
Use the struct bt_vcp_vol_rend instead of the more generic
`bt_vcp`.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
ae11b5879b Bluetooth: Audio: Remove bt_vcp from vol rend API
Remove the struct bt_vcp pointer from the volume
renderer API, as there is only ever a single
Volume Renderer instance on a device.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
c82af2885e Bluetooth: Audio: Split vol_ctlr and vol_rend callback structure
Split the `bt_vcp_cb` struct into separate structure for
the volume controller and the volume renderer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
7f69b866f0 Bluetooth: Audio: Specify bt_vcp_vol_rend API
The VCP server, known as the volume renderer, has a
more explicity bt_vcp_vol_rend API naming scheme now.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
71bd487cc4 Bluetooth: Audio: Add separate API for VCP vol controller
Add a separate API for the VCP volume controller (client).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
966c9f80e7 Bluetooth: Audio: Remove the bt_vcp_vocs API
Remove the bt_vcp_vocs API as it did the same as the
bt_vocs API, and did not really any functionality.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
bfbb704c8e Bluetooth: Audio: Remove the bt_vcp_aics API
The AICS functionality can be exercised using the
bt_aics API instead. These functions did very little
besides cluttering up the bt_vcp API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
ce2b8f9fe1 Bluetooth: Audio: Rename VCS to VCP
Renames almost all occurences of VCS to VCP, as we want to
use the profile as the namespace for volume control.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Emil Gydesen
aaac86dada Bluetooth: Audio: Rename vcs.h to vcp.h as well as the Kconfig file
Rename vcs.h to vcp.h to better detail what the
file contains, as it is more than just VCS. This also
renames the Kconfig file.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-28 17:43:40 +01:00
Théo Battrel
f739f0b87c Bluetooth: Add legacy warning to Kconfig.template.log_config_bt
Add documentation to tell people to not use the file for new stuff.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-28 17:14:56 +01:00
Anders Storrø
52a39c0180 Bluetooth: Mesh: Only settings load post mesh init
Prevent mesh stored settings from triggering unless bt_mesh_init
has been called.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-11-25 20:02:53 +01:00
Théo Battrel
e458f5aae6 Bluetooth: Use Zephyr standard log system instead of bluetooth/common/log
The `bluetooth/common/log.h` and `bluetooth/common/log.c` files have been
removed. Files that were using them have been updated to use
`zephyr/logging/log.h` instead.

Those replacement have been done consequently:
- `/BT_DBG/LOG_DBG/`
- `/BT_ERR/LOG_ERR/`
- `/BT_WARN/LOG_WRN/`
- `/BT_INFO/LOG_INF/`
- `/BT_HEXDUMP_DBG/LOG_HEXDUMP_DBG/`
- `/BT_DBG_OBJ_ID/LOG_DBG_OBJ_ID/`

Also, some files were relying on the `common/log.h` include to include
`zephyr/bluetooth/hci.h`, in those cases the include of `hci.h` has
been added.

For files that were including `common/log.h` but not using any logs,
the include has been removed and not replaced.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-25 17:08:36 +01:00
Pavel Vasilyev
c32ee7199f Bluetooth: Mesh: Filter out unknown conns and disconns in pb-gatt srv
Ensure that another established connection with the mesh device don't
mess up pb-gatt server state.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-11-25 10:45:07 +01:00
Pavel Vasilyev
2b0fbd86a1 Bluetooth: Mesh: Limit number of Bluetooth connections used by mesh
When a remote devices establishes a ble connection with the mesh device
with default identity and there are more available connection slots, the
mesh stack will try to restart connectable advertisements (either
pb-gatt or proxy depending on the provisioning state). This makes
difficult for an application to advertise own connectable advertisements
as the mesh stack will not let a chance the app to start advertising.

This change adds a Kconfig option that limits number of connection slots
that the mesh stack can use for own connectable advertisements.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-11-25 10:45:07 +01:00
Mariusz Skamra
93b2205ff5 Bluetooth: tests: shell: Fix build error
This fixes build error that happens when shell is built without CAP
Acceptor Set Member support. The cap_acceptor.c contains shell commands
for Set Member only, thus it's OK to build the code if
CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER is set for now. This can be modified
in the future when shell will be extended with other
Set Member non-specific CAP commands.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-25 10:44:51 +01:00
Emil Gydesen
43e0a63996 Bluetooth: Audio: Fix CSIP compliance check with returns after else
The compliance check did not like the otherwise valid
way of returning from read_set_sirk.

The code has been slightly refactored to avoid the check
failing in CI.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-24 15:23:48 +01:00
Emil Gydesen
292db21a18 Bluetooth: Audio: Use svc_inst instead of bt_csip for set_member
Use the service instance struct instead of the more generic
`bt_csip` for the CSIP set member API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-24 15:23:48 +01:00
Emil Gydesen
1991fcaced Bluetooth: Audio: Use svc_inst instead of bt_csip for set coordinator
Use the bt_csip_set_coordinator_svc_inst struct in the
set coordinator implementation instead of the more
generic bt_csip.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-24 15:23:48 +01:00
Emil Gydesen
5ecaf5af1b Bluetooth: Audio: CSIP set coordinator API not using bt_csip
Modified the CSIP set coordinator slightly to not use the
bt_csip struct at all. For the use a void pointer works
equally well.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-24 15:23:48 +01:00
Emil Gydesen
87f86cebe2 Bluetooth: Audio: Rename bt_csip to bt_csip_set_member
Renamed remaining structs and functions that are not
for the set coordinator to use the set member CSIP
role name.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-24 15:23:48 +01:00
Emil Gydesen
93b3944a51 Bluetooth: Audio: Rename CSIS to CSIP
Renamed the coordinated set implementation to use the
profile (CSIP) name instead of the service (CSIS) name, as
the former is more general.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-24 15:23:48 +01:00
Mariusz Skamra
8c86595289 Bluetooth: audio: has: Fix HAS features dynamic presets value
If there is no support for presets, Dynamic Presets feature
flag should not be set.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-24 15:23:00 +01:00
Morten Priess
3915754ac3 Bluetooth: controller: Add support for Read/Write Conn. Accept Timeout
Implement HCI commands HCI_Read_Connection_Accept_Timeout and
HCI_Write_Connection_Accept_Timeout, and enable the feature in
supported commands.
Remove hardcoded use of default accept timeout in new LLCP code, and
use configurable value instead.

This makes EBQ test /HCI/CIN/BV-03-C pass.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-11-24 11:17:28 +01:00
Emil Gydesen
40e3930ebd Bluetooth: Audio: Broadcast source subgroup and BIS codec support
Updates the broadcast source API to create subgroups and
to set BIS specific codec configuration

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-24 10:21:36 +01:00
Ahmed Moheb
b86150ff0c tests: bluetooth: host: Add mocks for crypto.c
Add required mocks to be able to compile/test /bluetooth/host/crypto.c

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-11-24 10:06:05 +01:00
Aleksandr Khromykh
2411cf68ab Bluetooth: Mesh: fix adv counter in LPN
LPN should send Poll\Sub Add\Sub Del only once.
Sending multiple times breaks polling time parameters
(Figure 3.17: Friendship timing parameters).

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-11-24 10:03:04 +01:00
Vinayak Kariappa Chettimada
668505e778 Bluetooth: Controller: Fix periodic sync Skip value vs Sync_Timeout
Adjust skip value so that there is minimum of 6 events that can be
listened to before Sync_Timeout occurs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-24 09:37:00 +01:00
Emil Gydesen
1b2f57270a Bluetooth: Host: Add addr to bt_le_ext_adv_get_info
Add the local advertising address to bt_le_ext_adv_get_info.

This may help with debugging, but is also needed to
properly support something like the BAP Broadcast Assistant.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-23 16:12:52 +00:00
Vinayak Kariappa Chettimada
990d9a3abe Bluetooth: Controller: Fix BIS access address generation
Fix BIS access address generation to follow the requirements
in Bluetooth Core Specification v5.3, Vol 6, PartB, Section
2.1.2 Access Address.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-23 12:18:55 +01:00
Vinayak Kariappa Chettimada
1b023e5419 Bluetooth: Controller: Ensure ext header max size reservation
Ensure maximum size of common extended header format be
reserved when CONFIG_BT_CTLR_ADV_RESERVE_MAX=n is used so
that changes to ACAD, like channel map update does not need
frequent update to periodic advertising auxiliary channel
PDU time reservations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-23 12:18:55 +01:00
Vinayak Kariappa Chettimada
1164c327d6 Bluetooth: Controller: Revert T_MAFS change done for broadcasting roles
When calculating the offsets between primary advertising
PDU, auxiliary PDU, Periodic Advertising PDU, and BIS PDU,
the values used as anchor points for starting the periodic
interval for auxiliary, periodic and BIG events, should be
ensured to have the minimum auxiliary frame spacing T_MAFS
between the PDUs. EVENT_OVERHEAD_START_US has to be reduced
as this value is used to offset the start of the radio
event on air.

Reverts commit b867f0e8a6 ("Bluetooth: Controller: Fix
T_MAFS between broadcasting roles").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-23 12:18:55 +01:00
Lingao Meng
7668bd3b7c Bluetooth: Mesh: Add macro control whether adv main to relay
Enable advertiser main to support relay messages, this maximizes
theutilization efficiency of advertising sets, which is helpful for the
sending of dense relays, but for Friend and LPN, it delays the sending
of local messages a little, this may cause the time slot deviation between
friend and lpn, and the power consumption of lpn will increase.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-11-23 11:36:57 +01:00
Lingao Meng
a5ebad1e23 Bluetooth: Mesh: Fix missing check local match for mesh message
For Mesh Message, should only process by model layer when dst
is unicast address of this nodes or model subscrip on.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-11-23 11:36:57 +01:00
Andries Kruithof
7678cdaa10 Bluetooth: controller: llcp: increase memory for procedures
The default number of buffers (contexts) for locally initiated
procedures was 4. Per default the host initiates 3 procedures
when opening a connection, allowing the application to initiate
only 1 additional procedure in parallel.
This commit increases the default to 6, if auto phy-update and
dle is enabled, increasing the robustness for an application.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-11-23 11:32:49 +01:00
Emil Gydesen
02226d0352 Bluetooth: Audio: Fix mcc.c conn logging statements
mcc.c does not include `conn_internal.h` so it does not
know the `bt_conn` struct, causing logging issues when
trying to log a `bt_conn` pointer.

Fixed by casting the `conn` pointers to `(void *)`.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-22 11:05:33 +01:00
Emil Gydesen
0a570a25c9 Bluetooth: Audio: Fix null pointer access in mcc.c
One of the notification callback functions did not properly
get the `read_params` pointer, causing an invalid result of
CONTAINER_OF as it would use a NULL pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-21 20:11:13 +01:00
Joakim Andersson
51d510adc6 Bluetooth: host: Call RPA expired on disabled advertising sets
Call the RPA expired callback on advertising sets even when they are
not enabled.
The RPA expired callback will now be called on advertising sets
when the BT_ADV_RPA_VALID flag is cleared for the set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-11-21 12:36:50 +01:00
Joakim Andersson
d63ae607cc Bluetooth: host: Fix RPA timeout expiration
Fix RPA timeout expiration when BT_EXT_ADV has been enabled.

Always invalidate the device RPA on RPA timeout.
This RPA is used by the scan roles, and the advertiser that was started
using the bt_le_adv_start API.

Call the RPA expire callback only on advertising sets that are enabled
and not being limited by a timeout and not using the identity address.
On RPA timeout always invalidate the RPA of advertising sets that are
disabled.

Fixes: #51208
Fixes: #51228
Fixes: #51247

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-11-21 12:36:50 +01:00
Joakim Andersson
0a1a32841f Revert "Bluetooth: Host: Fix resolvable address update with Ext Adv enabled"
This reverts commit 6c40427931.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-11-21 12:36:50 +01:00
Joakim Andersson
ff36bd42d0 Bluetooth: shell: Add shell support for RPA expire callback and control
Add shell support for RPA expire callback.
This prints a message when the callback is called on the specific
advertising set.
Add a command to control the return value of this callback for a
specific advertising set.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-11-21 12:36:50 +01:00
Joakim Andersson
ba657c9570 Bluetooth: shell: Use a common help text for commands args on and off
Use a common help text for commands args on and off.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-11-21 12:36:50 +01:00
Morten Priess
afd14d6573 Bluetooth: controller: CIS Central fixes from EBQ run
Various fixes for issues found during EBQ run.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-11-18 12:48:13 +01:00
Morten Priess
745bf7297e Bluetooth: controller: Implement CIS Central in ULL
- Add CIS Create policy config choices
- Implemented CIS Central in ULL following proposed setup/commit flow
- Full support for HCI_LE_Set_CIG_Parameters_Test
- Extend ull_conn_iso_start and ull_conn_iso_ticker_cb to handle
  central role
- Partial support for HCI_LE_Set_CIG_Parameters. TODOs:
  * Drop suggested retransmissions if Max_Transmission_Latency is
    exceeded
  * Calculate ISO interval based on policy

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-11-18 12:48:13 +01:00
Morten Priess
07acdc9650 Bluetooth: controller: HCI fixes for ISO central role CIG/CIS creation
Fix issues with referencing invalid netbuf data and add missing
parameter. Removed returning of handle in setup functions, as handles
are  not available until commit.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-11-18 12:48:13 +01:00
Morten Priess
64ade9e01d Bluetooth: controller: Move CIS peripheral functionality to ull_conn_iso
Move ull_peripheral_iso_start ull_peripheral_iso_ticker_cb to
ull_conn_iso, to share code between CIS peripheral and central.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-11-18 12:48:13 +01:00
Morten Priess
38a4e58d1f Bluetooth: controller: Implement local CIS Creation procedure
Local procedure for CIS central establishment. Calls yet unimplemented
functions in ull_central. Changes are guarded by
CONFIG_BT_CTLR_CENTRAL_ISO.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-11-18 12:48:13 +01:00
Vinayak Kariappa Chettimada
a6beef4b26 Bluetooth: Controller: Replace Central connection spacing Kconfig
Replace the BT_CTLR_ADVANCED_SCHEDULING_CENTRAL_CONN_SPACING
Kconfig with BT_CTLR_CENTRAL_SPACING to configure the
the spacing from the beginning of a central connection event
to beginning of the next central connection when supporting
multiple simulataneous central connections.

If the BT_CTLR_CENTRAL_SPACING in microseconds is smaller
then the required time reservation for a connection event,
for given maximum data length and PHY in use, then the
calculated time reservation will be used as the spacing
between consecution central connection events.

The change fixes an issue wherein use of old Kconfig with
higher values causes new central connections to be placed
in between already connected central role if there was
free time space available to fit the new connections time
reservation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-17 14:44:17 +01:00
Omkar Kulkarni
7e3b509ae1 bluetooth: mesh: check id in connection callbacks
When application uses multiple identities mesh stack keeps reacting
on connection events not related to the own identity (BT_ID_DEFAULT)
causing it to trigger additional advertising and this leads to errors.
Though not harmful, this also leads to mesh stack counting connections
wrongly and consuming internal resources.

This commit fixes the issue described above by checking the
connection id before proceeding further.

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
2022-11-17 11:17:45 +01:00
Vinayak Kariappa Chettimada
465a96181d Bluetooth: Controller: Explicitly set all bits of used radio registers
Explicitly set all bits of used radio registers when
configuring radio events, removing the dependency on having
the power-on reset value and removing the need to ensuring
power-on reset values being set in the radio peripheral.

This will ensure the Controller has radio register value
correctly configured irrespective of changes across SoCs'
radio register power-on reset values.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-17 10:56:13 +01:00
Vinayak Kariappa Chettimada
316a999d95 Bluetooth: Controller: Fix to allow multiple connectable advertisers
Fix BT_CTLR_MAX_CONNECTABLE define to allow multiple
connectable advertising sets to be enabled simultaneously.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-17 10:56:00 +01:00
Aleksandr Khromykh
7e63139499 Bluetooth: Mesh: fix memory corruption if oob string is 16 bytes
strcpy copies string including terminating null character.
strlen returns length without terminating null symbol.
If oob string is 16 bytes length then strcpy will corrupt byte
after auth array.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-11-16 11:21:14 +01:00
Aleksandr Khromykh
fcfc47bf93 Bluetooth: Mesh: fix static oob zero padding
The sample in the Provisioning protocol spec chapter
is in big endian. Static OOB value should append
zeroes on the little endian platforms.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-11-16 11:21:14 +01:00
Emil Gydesen
ecb7591d6b Bluetooth: Audio: Rename BASS and BASS client
Rename BASS to BAP Scan Delegator and BASS Client
to BAP Broadcast Assistant. This is the first step towards
integrating the BASS with the rest of BAP.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-16 11:17:52 +01:00
Théo Battrel
b56823818d Bluetooth: Rename functions to satisfy CI
In file `subsys/bluetooth/mesh/net.c`:
renamed `loopback` to `net_loopback`.

In file `subsys/bluetooth/host/settings.c`:
Renamed `set` to `set_setting` and `commit` to `commit_settings`.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-15 12:20:56 +00:00
Emil Gydesen
1d83e561e6 Bluetooth: Audio: Refactor use of cur_mcs_inst
Removes the global cur_mcs_inst and replace it
with lookup functionality.

This fixes an issue with bt_mcc_discover_mcs not being able
to be called more than once, as well
as streamline the implementation significantly.

This is also the first step towards not only supporting
multipe MCS instances for a single device, but also a
step towards handling multiple devices.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-15 12:18:50 +00:00
Emil Gydesen
0c04cf3c8e Bluetooth: Audio: Fix issue with NULL instance for MCC notifications
It was possible that on re-connect, the MCC implementation
would receive notifications when cur_mcs_inst was NULL.

This is partially caused by a bug in gatt.c, but can
and should also be handled in MCC.

This commit ensures that we do not compare handles
on notifications with a NULL instance.

This commit also ensures that subscribe_mcs_char_func
is not called outside the context of the discovery
procedure by setting the subscribe callback
to NULL.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-15 12:18:50 +00:00
Emil Gydesen
0b4d33bcbb Bluetooth: Audio: Fix missing path_id for broadcast_sink
Adds support for using the path_id set by the capabilities
for the broadcast sink role.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-15 12:14:14 +00:00
Martin Tverdal
09b514a610 Bluetooth: Fix issue with adv_stop
If adv stop was called form connected callback,
it would continue and unref the wrong conn object
if there where 2 connectable advertisers running,
but with only one 1 id configured.

Fixes #52196

Signed-off-by: Martin Tverdal <martin.tverdal@nordicsemi.no>
2022-11-14 13:07:51 +01:00
Vinayak Kariappa Chettimada
b56a6906e2 Bluetooth: Controller: Fix advertising disable on connection complete
Fix advertising set's is_enabled flag to be reset when
connection complete is dequeued for connectable advertising
started using legacy advertising enable HCI commands. And
reset the is_enabled flag when advertising set terminated
is dequeued for connectable advertising enabled using
Extended Advertising HCI commands.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-14 13:06:38 +01:00
Vinayak Kariappa Chettimada
13c29940bf Bluetooth: Controller: Fix ticker ticks diff calculation
Fix ticks difference calculation to determine delayed
prepare callback. Without the use of masking by
ticker_ticks_diff_get, the diff value can be higher than
the supported 24-bit value. i.e. ticker_ticks_now_get()
rolls over in 24-bit value, whereas ticks_at_event is
free running value of 32-bits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-14 13:06:21 +01:00
Vinayak Kariappa Chettimada
e895948047 Bluetooth: Controller: Add Long Control PDU support
Add long control PDU size support, also the implementation
now allocates control PDU size restricted to the supported
biggest control PDU that is enabled in the application
build. Features that are covered based on the increasing
control PDU sizes are ClearText connections, Encrypted
Connections, Connection Parameter Request support and
Create CIS control Procedure (Connected Central ISO)
support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-11 08:46:26 +00:00
Carles Cufi
b90c27238a Bluetooth: crypto: Refactor a few items
After merging #51809, a few things were spotted that needed tweaking.
Among them:

- Rename the folder from bt_crypto to crypto, since the prefix is
  unnecesary
- Remove the include folder
- Remove the path from the global include paths

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-11-10 17:54:14 +02:00
Nirosharn Amarasinghe
bd74d27614 Bluetooth: controller: Time wrapping point used in ISO-AL calculations
-- Handle time calculations across the point at which the controller's
   time information from the controller's clock will wrap (in the
   microsecond range)
-- Use wrapped time in all ISO-AL time calculations

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2022-11-10 09:29:42 +01:00
Théo Battrel
e9c542ab5b Bluetooth: Add the cryptographic toolbox function h8
Add to the cryptographic toolbox the h8 function, defined in the Bluetooth
Core Vol. 6, part E 1.1.1.

Also add test and SMP self test for this function. The data used for those
are from the Bluetooth Core.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-10 09:28:28 +01:00
Théo Battrel
f16738b62b Bluetooth: Move crypto toolbox functions from smp.c to their own files
Move functions defined in the Cryptographic toolbox of the Bluetooth
specification inside their own files in the following folder:
`zephyr/subsys/bluetooth/bt_crypto`. The functions were previously
implemented in `zephyr/subsys/bluetooth/host/smp.c`.

The cryptographic toolbox functions can now be accessed from outside of the
host.

In addition to that, tests for each cryptographic toolbox functions have
been added.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-10 09:28:28 +01:00
Pavel Vasilyev
1629a2f4d1 Bluetooth: Mesh: Fix net and app keys commands in shell
Fix net and app keys commands in shell

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-11-09 10:50:31 -06:00
Mariusz Skamra
6148d8a39d Bluetooth: audio: Fix invalid assert in bt_audio_iso_unbind_ep
This should assert if iso argument does not match the one ep holds
reference to.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-09 10:45:12 +01:00
Emil Gydesen
03a4e1ae48 Bluetooth: Audio: Add missing unbind of audio_iso for broadcast sink
When a BIS disconnected, we removed the references between
the endpoint and the stream. This made it impossible
to later unbind the audio_iso when
broadcast_sink_cleanup_streams was called.

Fixed by unbind the audio_iso when we remove the reference.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-09 10:45:06 +01:00
Erik Brockhoff
b1c0bc0c0a Bluetooth: controller: add central anchor point move to new LLCP
Add central functionality re. anchor point move to refactored LLCP

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-09 10:43:17 +01:00
Erik Brockhoff
26df2db60a Bluetooth: controller: add handling of preferred periodicity to new LLCP
Port central functionality re. preferred periodicity to refactored LLCP

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-09 10:43:17 +01:00
Erik Brockhoff
c180afec11 Bluetooth: controller: Adding user ext. anchor point move to ctrl/CPR
Adding support for allowing user extension code to support deferring
anchor point moves. Refactored LLCP only.
Note: This is NOT supported by LEGACY LLCP impl.
KConfig'd by BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE
Modified ll_conn_update API, to accommodate passing offsets
Modified CPR/CU context data structure
Modified CPR/CU procedure to handle anchor point move wait state
Fixed up unit tests, adding anchor point move cases to CPR/CU test

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-09 10:43:17 +01:00
Erik Brockhoff
85354c405c Bluetooth: controller: refactoring pdu length validation
Using a macro instead of repeated identical code for validation
Use macro for pdu length field encoding

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-09 09:34:35 +00:00
Erik Brockhoff
2a236e52db Bluetooth: controller: rename pdu_data_llctr struct SCA member
Rename struct member to adhere to general naming pattern

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-09 09:34:35 +00:00
Emil Gydesen
64c2d86a64 Bluetooth: ISO: Replace CONFIG_BT_DEBUG_ISO_DATA guard with BT_ISO_DATA_DBG
Instead of guarding all BT ISO data log statements with
CONFIG_BT_DEBUG_ISO_DATA, a new macro, BT_ISO_DATA_DBG, is
implemented to handle the guarding.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-09 09:05:03 +00:00
Emil Gydesen
36c5dd4bca Bluetooth: ISO: Guard addition ISO debug with CONFIG_BT_DEBUG_ISO_DATA
Guard additional debug statements in ISO that deals
with TX/RX with CONFIG_BT_DEBUG_ISO_DATA to avoid spamming
the log.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-09 09:05:03 +00:00
Sean Madigan
a53446cd09 Bluetooth: Host: Check if EATT l2cap server is registered
bt_eatt_init currently registers a l2cap server, however should not
register a new one if it has already been registered - for example in
bt_enable previously.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-11-09 09:03:50 +00:00
Sean Madigan
f88b19a833 Bluetooth: Host: init bt_workq and cancel rpa_update work
Init bt_workq in bt_enable so it can be safely disabled.

Cancel rpa_update work upon disable as it is no longer required.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-11-09 09:03:50 +00:00
Sean Madigan
666990b6e4 Bluetooth: Host: add pub_key_hci_disrupted function
Add bt_pub_key_hci_disrupted function for when hci is disrupted during
a pub key hci command, to clear callbacks and BT_DEV_PUB_KEY_BUSY flag.

Call this from bt_disable for the case bt_disable disrupts the pub key
hci command.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-11-09 09:03:50 +00:00
Sean Madigan
a4fcf39a69 Bluetooth: Host: clean up after connections in bt_disable
Reset disconnected handles as is no longer needed after disable.

Created a destroy function to clear all connection states and cancel any
deferred work.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-11-09 09:03:50 +00:00
Sean Madigan
c80b6d8223 Bluetooth: Host: reset adv_pool in bt_disable
Reset the adv_pool in disable so that advertising can be started after
re-enabling without issue.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-11-09 09:03:50 +00:00
Sean Madigan
0e010e8744 Bluetooth: Host: init fifos and slists before use
In bt_att_init, bt_conn_init and bt_l2cap_init, init the fifos and
slists before use. This means that they can be used after disable
without memory leakage.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-11-09 09:03:50 +00:00
Sean Madigan
0ef4f9740a Bluetooth: Shell: Add bt_disable to bluetooth shell app
bt_disable can now be used with the bluetooth shell.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-11-09 09:03:50 +00:00
Emil Gydesen
a34c2cd90a Bluetooth: Audio: Fix ASE_{SNK,SRC}_COUNT=0 issues
Due to the LISTIFY macro for the counts, the value
cannot be 0.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-08 10:48:54 +01:00
Mariusz Skamra
529b4b2b1d Bluetooth: audio: ascs: Fix invalid error code returned
This fixes invalid error code that was returned in case remote requested
Disable operation with invalid ASE ID.

Fixes: BAP/USR/SPE/BI-01-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-08 10:48:47 +01:00
Pavel Vasilyev
f2ea6f2149 Bluetooth: Mesh: Check avail conn before restarting pb-gatt srv adv
When a provisioner connects to the device, gatt_connected callback is
called in pb_gatt_srv.c, then pb-gatt advertising is stopped and adv_sent
callback is triggered in adv_ext.c. adv_sent callback reschedules
advertising and eventually calls bt_mesh_adv_gatt_send. Since the device
is not provisioned yet, it tries to start pb-gatt advertising again. If
number of available connections is reached, this results in "Advertising
failed" error in adv_ext.c.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-11-08 10:47:24 +01:00
Vinayak Kariappa Chettimada
0f80133571 Bluetooth: Host: Add auto conn param update retry count and timeout
Add implementation to retry the automatic peripheral
perferred connection parameter request with a configurable
retry countdown and retry back-off timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-08 10:47:07 +01:00
Vinayak Kariappa Chettimada
073b2af808 Bluetooth: Host: Fix use of tabs inside struct and enum definitions
Fix use of tabs inside struct member of bt_conn_le and
bt_conn enum definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-08 10:47:07 +01:00
Mariusz Skamra
e4f0bcdd56 Bluetooth: audio: ascs: Fix audio ISO allocation in QoS->QoS transition
ASE in QoS state already have audio ISO object.
This will just skip the audio ISO allocation and binding in such case
if CIG and CIS parameters did not change.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-08 10:46:07 +01:00
Lingao Meng
93709a7359 Bluetooth: Mesh: Add specific number of keys & groups
Since Mesh Spec and Mesh model sayes, some model no need
groups and no need keys, such as Config Server, but the
current implementation, all model use same configuration,
which cause some ram ext comsume.

So that, change to specific way, but will consume more footprint size.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-11-08 10:45:15 +01:00
Erik Brockhoff
76439d0ba4 Bluetooth: controller: integrating SCA procedure and adding HCI API
Adding controller support for updating SCA in ACL and ISO peripherals
Adding HCI API support for le_request_peer_sca and complete event.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-08 10:44:54 +01:00
Erik Brockhoff
b3b4b9e322 Bluetooth: controller: implementing SCA update procedure PDU flow
Adding PDU flow and unittest for Sleep clock accuracy procedure

Signed-off-by: Erik Brockhoff <erbr@oticon.com>

wip kconf
2022-11-08 10:44:54 +01:00
Emil Gydesen
8dffa45e0c Bluetooth: Audio: Add support for multiple subgroups for BAP broadcast sink
The broadcast sink supports multiple subgroups, but was
not possible due to the Kconfig option.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-08 09:43:11 +00:00
Erik Brockhoff
6b324122e7 Bluetooth: controller: fix CIS REQ event generation and rejection
Check LE event mask state as well as host controlled feature mask state
and reject CIS request accordingly.
Release pre-allocated ISO resources on rejection of request

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-11-08 09:38:21 +00:00
Emil Gydesen
87eab711df Bluetooth: Audio: Add additional printing in CSIS client shell
The CSIS client shell did not print the pointers of the instances
discovered, which are needed for future commands.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-08 09:37:17 +00:00
Emil Gydesen
6d46472cfe Bluetooth: VCS: More explicit log for abs vol set opcode
When the set absolute volume opcode was received, we
logged the current volume, but without any explaining
text.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-08 09:36:04 +00:00
Emil Gydesen
7fb8f77103 Bluetooth: Audio: Shell: Fix metadata argument
The metadata in the presets are just defined
using the BT_AUDIO_LC3_PRESET which ultimately
uses BT_CODEC_LC3_CONFIG_META which correctly
sets the data pointer, but the `value` array is unused.

So we cannot just update the `value`, as that is actually
not used in those cases, and the `data` pointer is `const`.

The solution is to a copy of the metadata data, and use
the copy when calling the API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-08 09:35:25 +00:00
Mariusz Skamra
9054435a4a Bluetooth: ascs: Handle CIS disconnection in non-releasing state
Unbind ISO when goint to idle state if there's still reference kept.
It may happen that we get CIS disconnection being in non-releasing
state, so we have to handle that case. This fixes regression that was
introduced in 3fa456905d.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-07 09:50:18 +01:00
Pavel Vasilyev
d286bc4699 Bluetooth: Mesh: Fix args parsing in cmd_net_key_add function
cmd_net_key_add has only 2 arguments.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-11-05 19:56:50 +01:00
Mariusz Skamra
7a6581219d Bluetooth: gatt: Fix notification cleanup on disconnection
This fixes GATT notification buffer missing cleanup on ACL
disconnection. Fixes potential NULL pointer dereference trying to use
invalid conn object in `notify_mult_process` work queue task handler
and/or missing free of pending notification buffer.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-05 19:56:42 +01:00
Mariusz Skamra
fbeee206f2 Bluetooth: audio: pacs: Hotfix invalid PACS length
This fixes adding 2 redundant bytes... to the PAC records.
As a result we end up with broken PAC record.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 10:00:00 +01:00
Mariusz Skamra
7405f81db6 Bluetooth: audio: pacs: Remove unused structure member
The 'pacs' member was never referenced.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 10:00:00 +01:00
Mariusz Skamra
8f6fc38ca3 Bluetooth: audio: unicast_client: Remove redundant code
The unicast_client_ep_set_codec function that is called below
sets the codec id, cid, vid.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 10:00:00 +01:00
Mariusz Skamra
50b57056bd Bluetooth: iso: Fix calling wrong function to terminate BIG
The bt_iso_chan contains vaild pointers for Tx and Rx QoS parameters.
This unifies the implementation between different roles.
This fixes checking ISO type that is done based on ISO type that
is kept inside of conn.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 08:55:12 +00:00
Mariusz Skamra
0fa978508c Bluetooth: audio: unicast_client: Inform all related EP's about ISO state
This fixes application callbacks not being called on ISO connection
state change.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 08:55:12 +00:00
Mariusz Skamra
3fa456905d Bluetooth: audio: Factor out bt_audio_iso pool
This adds common bt_audio_iso pool that will be used across all the
roles/profiles. The pool range is dependent on the CONFIG_BT_ISO_MAX_CHAN
which is the maximum number of ISO connections the host can maintain.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 08:55:12 +00:00
Mariusz Skamra
1aaf1e522f Bluetooth: audio: unicast_client: Remove unused functions
This removes unused functions from unicast_client.c

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 08:55:12 +00:00
Mariusz Skamra
6fde7ae96d Bluetooth: audio: ascs: Move control point work to EP
Move the control point work to the EP. The aim is to cleanup the code so
that it there's no EP for ASE that means ASE is in idle state.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-11-04 08:55:12 +00:00
Vinayak Kariappa Chettimada
f35b9eb5cc Bluetooth: Shell: Select BT_TICKER_NEXT_SLOT_GET when BT_LL_SW_SPLIT
Select BT_TICKER_NEXT_SLOT_GET when BT_LL_SW_SPLIT enabled
and building applications with shell support (BT_SHELL).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-03 10:24:49 +01:00
Emil Gydesen
cdc3b332ba Bluetooth: Audio: Fix unicast client ep reset
The endpoint was only partially memset on disconnect,
which left the handles untouched. This meant that the
reset endpoint would still get returned by
unicast_client_ep_find.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-11-03 10:24:03 +01:00
Morten Priess
447c7390f5 Bluetooth: controller: Add window widening for CIS/CIG
Program CIG ticker with window widening drift. Introduce vendor specific
conversion macros allowing sub-microsecond resolution in the
accumulation of window widening drift per interval.

Calculation of window_widening_max_us is done for NSE<3, and must be
adjusted in the LLL before use, if the first CIS in the CIG has a
NSE>=3. In that case window_widening_max_us shall be limited to one sub
interval.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-11-03 08:56:58 +00:00
Théo Battrel
7d2b4e1917 Bluetooth: Remove unneeded macros
Remove the `bt_hex`, `bt_addr_str`, `bt_addr_le_str` and `bt_uuid_str`
macros from `bt_str.h` as they were just aliases for the `*_real` functions
in the same file.

The functions has been renamed without the `_real` suffix.

Some files were using the functions and not the macros, they have been
updated to use the new name of the functions.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-02 13:28:57 +01:00
Théo Battrel
c9d68a5a4f Bluetooth: Move out string related function of common/log.h
Functions related to string manipulation that were defined in
`common/log.h` has been moved to the `common/bt_str.h` file and their
implementation in `common/bt_str.c`.

Files that were using those functions has been updated consequently.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-02 13:28:57 +01:00
Vinayak Kariappa Chettimada
5cf47b1e7f Bluetooth: Controller: Fix ticker slot reserved check
Fix ticker slot reserved check to handle deferred execution
of ticker worker where ticks_elapsed is greater than
ticks_slot_previous. In which case, each ticker expiring be
checked for overlap with previous slot reservation.

This fixes:
ASSERTION FAIL [0] @ WEST_TOPDIR/zephyr/subsys/bluetooth/
controller/ll_sw/nordic/lll/lll.c:476
lll_preempt_calc: Actual EVENT_OVERHEAD_START_US = 3906

Flash erase operation exposed the assertion, CPU being
halted deferred the ticker_worker collision resolution and
ticker expiry was not individually checked for overlap with
previous expired ticker reservation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-02 10:33:22 +01:00
Vinayak Kariappa Chettimada
fbfa2b4631 Bluetooth: Controller: Fix missing first connection event
Fix missing first connection event due to first connection
event ticks_slot of central and peripheral overlapping with
the initiator window ticks_slot and advertising ticks_slot,
respectively.

Use ticker_stop_abs interface so that when the ticker is
stopped the ticks_slot_previous is truncated to the actual
ticks used as requested by the supplied absolute ticks.

Relates to commit 8a294a62d4 ("Bluetooth: controller:
legacy: Fix missing first conn event").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-02 10:33:22 +01:00
Vinayak Kariappa Chettimada
af9dd5cb26 Bluetooth: Controller: Fix ticks_current initialization
Fix ticker instance ticks_current initialization to be
acquired from the RTC counter value. The RTC counter may
have run in previous use of ticker before bt_disable hence
keep the instance ticks_current equal to RTC counter value
when ticker_init() is called again.

Relates to commit 4349a475a8 ("Bluetooth: Controller: Add
deinit() infrastructure").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-02 10:31:33 +01:00
Vinayak Kariappa Chettimada
943deca7c4 Bluetooth: Shell: Add back erroneously removed ll-addr command
Add back erroneously removed ll-addr command, when removing
legacy Controller, which is provided when using Zephyr
Bluetooth Low Energy Controller to read the random and
public address set by the Host, and used by the Controller.

Relates to commit b67a31e411 ("Bluetooth: controller:
Remove legacy LL").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-11-02 10:30:52 +01:00
Ingar Kulbrandstad
7367980bea Bluetooth: Mesh: Extended advertiser as default
Setting the extended advertiser as default advertiser
to improve both preformence and reliability.

Signed-off-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
2022-11-01 08:52:56 +00:00
Piotr Pryga
f24b5b4b43 Bluetooth: host: df: fix wrong connectionless CTE enable cmd length
There were a bug in a prepare_cl_cte_rx_enable_cmd_params function.
The size of command buffer was wrong when CTE enabled in AoD mode.
The command buffer was extended by param->num_ant_ids, that was
zero in case of AoD. Then a dummy antenna switch pattern was copied
into the command buffer.

That lead to: memory overwrite, and wrong command buffer length.
The command was rejected by Controller.

To fix, use cp->switch_pattern_len that was already assigned with
correct antenna pattern length.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-10-31 11:23:44 +01:00
Mariusz Skamra
3ea297960d Bluetooth: audio: Remove capablilities leftovers
Remove dead code that remained after
https://github.com/zephyrproject-rtos/zephyr/pull/51425 was merged.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-31 16:39:05 +09:00
Carles Cufi
8e4d499fa0 treewide: Use CONFIG_*_ENDIAN instead of __BYTE_ORDER__
In order to avoid using multiple sources of truth for the platfom's
endianness, convert the in-tree code to use the (BIG|LITTLE)_ENDIAN
Kconfig variables exclusively, instead of the compiler's
__BYTE_ORDER__.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-10-28 19:23:46 +09:00
Emil Gydesen
affd8da9a0 Bluetooth: Host: Fix wrong addr for PA term when using adv list
If using the advertiser list when syncing to a PA, then the
address address needs to be updated for the PA sync object.
This is a small optimization to avoid doing a copy when
the address and SID is already set.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-28 07:56:41 +00:00
Emil Gydesen
cba4b1828d Bluetooth: Host: Fix missing term callback for PA syncs
When deleting a PA sync with bt_le_per_adv_sync_delete
Zephyr should call the `term` callback for the PA sync
as per the documentation for the callback.

This was not done in the case that the PA sync was
terminated by local request.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-28 07:56:41 +00:00
Martin Tverdal
0cf6cac77e Bluetooth: extended adv reports with legacy content discardable
To avoid legacy extended adv repots blocking important
events or work, mark them as discaradble.

Signed-off-by: Martin Tverdal <martin.tverdal@nordicsemi.no>
2022-10-28 07:55:44 +00:00
Jonathan Rico
4b1585c23f Bluetooth: shell: fix compiler warning
Compiler thinks `err` is not initialized when
`CONFIG_DEBUG_OPTIMIZATIONS=y`.

Fixes #51521 .

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-10-27 17:23:36 +02:00
Andries Kruithof
5e360b81c2 Bluetooth: controller: llcp: update rx parameters upon receipt of PDU
According to specification, when executing a remote procedure the
rx parameters used need to be updated when the REQ from the peer
is received. Currently this is done only when an ACK is
received on the RSP PDU send out.
This commit updates the RX parameters upon receipt of the REQ PDU

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-10-27 16:57:27 +02:00
Aleksander Wasaznik
fd5fe6ca8e Bluetooth: Host: Add CONFIG_BT_ID_UNPAIR_MATCHING_BONDS
This commit prevents the assertion error added in the previous commit,
by introducing the following behavior.

When the Host detects that a pairing procedue would result in more than
one local identity having a bond with the same remote address, it will
try to abort the pairing. If the pairing procedure cannot be properly
aborted, it will remove the pairing locally and disconnect.

This commit also introduces a new kconfig `BT_ID_UNPAIR_MATCHING_BONDS`.
This config changes the above-described behavior to instead un-pair the
old bond and continue with the pairing (if the new bond has the same or
better security.)

The new kconfig is not enabled by default. See the help text of the new
kconfig option for more details.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-27 13:16:59 +02:00
Aleksander Wasaznik
6e926dcd83 Bluetooth: Prevent bonding to the same device more than once
This change prevents two local identities from having bonds to the same
device.

The Core specification is not well suited for Zephyr's multiple-local-
identities feature. The HCI specification seems written with intent that
a controller is used for only one GAP device. A GAP device has at most
one public address, and at most one random static address.

The Zephyr Bluetooth API, on the other hand, has a concept of local
identities. This feature allows the Zephyr Bluetooth stack to
simulatainously assume multiple local addresses. This does not mesh well
with the above intent in the specification.

In particular, the HCI specification for the resolve list does not allow
more than one entry for a remote address. The controller will deny any
attempts at doing this.

The current implementation of the Zephyr host will try the above and be
denied. But there is no handling for this situation and the host ends up
in a confused state. Some parts of the system are ok with the two bonds,
but other parts assume this situation never occurs behave badly.

The result is that the host confuses the multiple bonds to the same
device. Symtoms include:

- Directed advertisements have a different source address than what the
  host intended, in which case the two sides are confused about the
  address of the Zephyr advertiser, and as a result LTKs will not match.

- Errors in the log.

This commit simply asserts. This is not a solution, just a placeholder
for a fix. The next commit will implement a strategy for handling this
situation instead of failing this assert.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-27 13:16:59 +02:00
Aleksander Wasaznik
dfe03c1268 Bluetooth: Host: Define bt_irk_eq
This gives a well-defined method for determining if two IRKs are equal.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-27 13:16:59 +02:00
Emil Gydesen
326b2fdf15 Bluetooth: Audio: Fix issue with supporting bidir CIS in ASCS
If 2 ASEs shared the same CIS and the first ASE had the CIS
connected before the second ASE was QoS configured, then
the CIS was missing either the TX or RX pointer, causing
it to be considered unidirectional by the ISO layer.

This commit fixes this issue by configuring the (static)
pointers at an earlier time, so that the RX and TX QoS
pointers are always valid.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-26 12:01:52 +02:00
Hang Fan
756421b85e Bluetooth: Audio: Fix codec configuration parameter
Fix wrong Codec_Configuration and Codec_Configuration_Length
when setup ISO data path.

Signed-off-by: Hang Fan <fanhang@xiaomi.com>
2022-10-26 12:00:38 +02:00
Mariusz Skamra
2627063ab2 Bluetooth: audio: pacs: Replace capabilities API with pacs
This changes the API to use proper naming convention, as the code has
been moved out of capabilities.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Mariusz Skamra
e635d3aab6 Bluetooth: audio: pacs: Refactor capabilities related code
This simplifies and removes redundant code.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Mariusz Skamra
ce973edbd2 Bluetooth: audio: pacs: Refactor location related code
This simplifies and removes redundant code.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Mariusz Skamra
49f9119c99 Bluetooth: audio: pacs: Refactor context related code
This implifies and removes redundant code.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Mariusz Skamra
2a1cb0acd8 Bluetooth: audio: Fix building and reading PAC Records
This fixes missing checks, and invalid struct bt_pac definition that was
missing one mandatory metadata byte.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Mariusz Skamra
43ffe3cad9 Bluetooth: audio: pacs: Refactor PAC read handler
This makes use of bt_audio_foreach_capability fuction to
simplify building the PAC attribute value.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Mariusz Skamra
7c1f6d93dc Bluetooth: audio: pacs: Move capabilities to PACS
There is no point of having dedicated source file that is PACS
dependent. This moves all of the code from capabilities.c to pacs.c.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Mariusz Skamra
8500eb1335 Bluetooth: audio: pacs: Fix PACS notification
This fixes sending PACS notification with buffer containing invalid,
uninitialized data.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-26 08:49:00 +02:00
Théo Battrel
2d1d309936 Bluetooth: Move out BT_ASSERT of common/log.h
Macro that was defined in the `common/log.h` has been moved to the newly
created `common/assert.h` file.

Files that were using those macro has been updated consequently. Also, the
include of `common/log.h` has been removed of files that were actually not
using any logging methods.

Some `#include "common/log.h"` have been removed. Those were required
before when including `hal/debug.h`. With this change, `hal/debug.h` no
longer has this requirement, because the replacement, `common/assert.h`
includes what it uses.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-10-25 10:48:17 +02:00
Théo Battrel
fdd0a26348 Bluetooth: Remove BT_HEXDUMP_DBG
Replace unnecessary `BT_HEXDUMP_DBG` with `LOG_HEXDUMP_DBG`.

`BT_HEXDUMP_DBG` did an extra cast to `const uint8_t *` on its first
argument. This was probably the reason it was introduced. But the
current definition of `LOG_HEXDUMP_DBG` does this cast for us.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-10-25 10:48:17 +02:00
Ahmed Moheb
b8a957a0eb bluetooth: host: id: Fix copy BT_HCI_OP_VS_READ_STATIC_ADDRS response
Fix copying addresses returned in response to command
BT_HCI_OP_VS_READ_STATIC_ADDRS for reading controller static addresses.
The loop was iterating only over the destination locations while
keeping the source address pointing to the first location of
the command response.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-10-25 10:03:27 +03:00
Mariusz Skamra
0b825d0ee4 Bluetooth: audio: csis: Fix bt_conn_foreach function parameter
Exclude non-LE connections when sending notifications.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-25 09:53:23 +03:00
Emil Gydesen
d5499e6b87 Bluetooth: Audio: Add CAP stream
Add a new stream object, bt_cap_stream, which is an extension
of the BAP bt_audio_stream. The purpose of this stream
is that we can extend the data stored in the BAP stream for
CAP usage, as well as making it more explicit what type
of stream should be used for CAP.

The callbacks will be extended for CAP in specific use cases,
e.g. when starting one or more unicast audio streams.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
7a1e827a8b Bluetooth: Audio: Make CAP acceptor more explicit
Remove the generic CONFIG_BT_CAP and CONFIG_BT_DEBUG_CAP
and only use Kconfigs specific to the individual roles.

This also includes renaming cap.c to cap_acceptor.c.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
ce05cb5c2c Bluetooth: Audio: CAP initiator discover CSIS
The CAP initiator will now discover, or return a
known, CSIS instance included by CAS (if any).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
ed11295cf6 Bluetooth: Audio: CSIS client register multiple callbacks
Change the CSIS client callback to a slist so that
multiple applications can register it. An example of
such a case is that both the application and CAP initiator
want to get the callbacks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
2e42105df0 Bluetooth: Audio: CSIS: Refactor CSIS client discover API
The API will now take a simple bt_conn instead of a
set member struct. This is due to the set member struct
being moved to the stack. The reasoning for this is that
having the struct in the stack, rather than in the
application, the stack itself can initiate the CSIS
discovery which is useful if the remote device
has a service that includes a CSIS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
ee70dffc6d Bluetooth: Audio: CAP shell implementations
Implements the CAP shell functionality.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
7a49de12af Bluetooth: Audio: Implement CAP initiator discover
This is the primary discovery of the CAS on the remote device,
but does not include discovering the (optional) CSIS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
760177b1be Bluetooth: Audio: Add CAP initiator skeleton
Add skeleton for the expected APIs and
implementation. May be subject to change as
implementation progresses.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:39:11 +02:00
Emil Gydesen
31bf99cbd2 Bluetooth: ISO: Change ISO seq_num to 16-bit
The sequence number is by the core spec defined as 16-bit.
We had implemented a workaround for the wrapping of the
sequence number, which required the type to be larger
than 16-bit (32-bit).

However, since the definition of the sequence number,
and the use of, is poorly defined by the core spec, we
are reverting this workaround and reducing the sequence
number to 16-bit again. This way it is more in line
with the core spec, as well as more intuitive given the
other uses for the sequence number.

This change moves the responsibility of using the
right value to the upper layers, as the stack can
and will no longer provide any guarantees.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-24 10:38:49 +02:00
Ahmed Moheb
92c93ef3c4 bluetooth: host: crypto: Check input arguments with CHECKIF()
Check input arguments passed to APIs with CHECKIF().

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-10-21 20:30:47 +02:00
Emil Gydesen
37028ea0d0 Bluetooth: Shell: Add support for advertising appearance
Add support for advertising the appearance value in the
advertising data.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-20 17:00:26 +03:00
Emil Gydesen
135bcd339b Bluetooth: Shell: Remove ad_mode_parse
The function did not provide anything that could
not just as easily have been done in the existing
loops.

This just required moving the call to ad_init to
after the param parsing loop.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-20 17:00:26 +03:00
Mariusz Skamra
39dcde2b7e Bluetooth: audio: ascs: Do not store Bluetooth address
The struct bt_ascs holds the conn reference already,
thus it's not needed to store the device address.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-20 15:41:47 +02:00
Ahmed Moheb
07e22abb12 bluetooth: host: id: Fix flags updated by bt_id_del()
bt_id_del() was setting the bit 'BT_KEYS_ID_PENDING_ADD' instead
of setting the bit 'BT_KEYS_ID_PENDING_DEL'

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-10-20 10:00:48 +02:00
Ahmed Moheb
dcfd0220b4 bluetooth: host: id: Increment IDs count only on success
Increment the number of identities after a successful execution
of id_create() by checking if the return value is 0.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-10-20 10:00:48 +02:00
Ahmed Moheb
0a2388c5be bluetooth: host: id: Check input arguments with CHECKIF()
Check input arguments passed to APIs with CHECKIF().

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-10-20 10:00:48 +02:00
Aleksander Wasaznik
046f531a6e Bluetooth: Host: Document bt_irk.rpa
Document `bt_irk.rpa` as "Cache for `bt_keys_find_irk`. Not reliable as
"current RPA"!".

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-20 10:17:04 +03:00
Emil Gydesen
4f78655915 Bluetooth: Audio: Add check when registering media_proxy_pl_calls
Add NULL checks when registering the media_proxy_pl_calls.
Currently the media player expects all of them to be set.

In the future, ideally the callbacks would mostly be
optional and reflect which of the optional
characteristics that there is in the MCS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-19 16:05:46 +02:00
Emil Gydesen
e45eff3e10 Bluetooth: Audio: Add missing commands supported callback for MCS
When registering the media player, we were missing a callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-19 16:05:46 +02:00
Pavel Vasilyev
cf701acb94 Bluetooth: Mesh: Convert model_ackd_send and model_send to a common API
Convert model_ackd_send and model_send from health_cli.c to a common API
to get rid of code duplication in other client models that implement
synchronous messages' sending.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-10-19 16:05:16 +02:00
Mariusz Skamra
54d1e15b71 Bluetooth: audio: ascs: Make ascs_ep_set_metadata static
This changes ascs_ep_set_metadata to be static as it's not used outside
of ascs.c.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-19 16:00:33 +02:00
Mariusz Skamra
fc398ac33f Bluetooth: audio: pacs: Fix redundant CCCD attribute without location
This removes the CCCD that was added even if location attribute was not
there.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-19 16:00:21 +02:00
Aleksander Wasaznik
17fc4b811c Bluetooth: Replace 'bt_addr_le_cmp(x) != 0' with 'bt_addr_le_eq(x)'
These should be equivalent. The '_eq'-form is more readable.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-19 15:40:18 +03:00
Aleksander Wasaznik
ea558187b5 Bluetooth: Replace bt_addr_le_cmp in bool context with !bt_addr_le_eq
These should be equivalent. The new form is more readable.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-19 15:40:18 +03:00
Aleksander Wasaznik
21e5dcb42a Bluetooth: Replace 'bt_addr_le_cmp(x) == 0' with 'bt_addr_le_eq(x)'
These should be equivalent. The '_eq'-form is more readable.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-19 15:40:18 +03:00
Aleksander Wasaznik
9db3fa82d1 Bluetooth: Replace all '!bt_addr_le_cmp' with 'bt_addr_le_eq'
There should be functional equivalence between these two forms. And the
'_eq'-form is more readable.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-10-19 15:40:18 +03:00
Mariusz Skamra
9973d2f1f7 Bluetooth: audio: Factor out PACS related API to internal header
This moves the PACS API to internal header, as it duplicates the
bt_capabilities API.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-18 14:14:19 +02:00
Emil Gydesen
4321fef3b7 Bluetooth: Audio: Ensure that stream is in streaming state for ISO recv
Adds check to verify that the audio stream is actually
in the streaming state before handling the
audio data. As per the BAP spec, a stream that
is not in the streaming state shall not send
any data, and this check is to handle any
remote devices that are not working correctly.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-18 14:13:51 +02:00
Gerard Marull-Paretas
178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Pavel Vasilyev
93e6f73d62 Bluetooth: Mesh: Change linkage for ctx_shell and default_key in shell
Change linkage for ctx_shell and default_key in shell.c to external to
share their usage in other places.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-10-17 14:39:58 +02:00
Pavel Vasilyev
73c5568b5c Bluetooth: Mesh: Remove _cli postfix from models shell files
This commits renames `health_cli.c` and `cfg_cli.c` under `mesh/shell`
folder to `health.c` and `cfg.c` accordingly. This is to create a
generic pattern for the future, when not only clients, but server models
will also expose some API through shell commands. This means that server
models' shell commands should be located in the same file as client
commands to avoid cluttering `mesh models` subcommand.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-10-17 14:39:58 +02:00
Pavel Vasilyev
f93ab2769c Bluetooth: Mesh: Add macro for instance set/get-all mesh shell cmds
This code is a boulerplate that will be needed for many models in mesh
shell module. This commit adds a special macro designed to improve
readability of the code and helps to avoid potential bugs when
copy-pasting identical code.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-10-17 14:39:58 +02:00
Pavel Vasilyev
8e5ff49118 Bluetooth: Mesh: Make mesh features pluggable in shell
Not all shell commands may be needed for an end application even if a
certain feature is enabled. In that case they will just occupy flash
space without being used. This commit adds a separate Kconfig for each
feature to make possible to selectively disable some mesh shell commands.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-10-17 14:39:58 +02:00
Pavel Vasilyev
559e526708 Bluetooth: Mesh: Add options to disable health and cfg clients shell
Add Kconfig options to be able to disable Health and Config Client
models shell commands.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-10-17 14:39:58 +02:00
Pavel Vasilyev
f9c4872ce4 Bluetooth: Mesh: Move mesh shell Kconfig options to a separate file
Move mesh shell related options to a new file to avoid cluttering of
the main Bluetooth Mesh Kconfig file when extending it with new options.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-10-17 14:39:58 +02:00
Sean Madigan
5b1dd71f3e Bluetooth: kconfig: Add config options for PAST
Add config options specific for periodic advertising sync transfer.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2022-10-17 10:14:10 +02:00
Andy Ross
13f78fb005 bluetooth: Don't use k_sem internals
The "limit" field of struct k_sem was in use in two places in the BTLE
host code, in one it was being used as a duplicate placeholder for the
"iso_max_num" field received in read_buffer_size_v2_complete[1].  In
another, it was just being tested for zero[2].

Those are pretty clear abuses of internal data, provide minimal value
beyond a few bytes of memory in struct bt_dev_le, and in any case
won't work with zync, where that field doesn't have the same name and
may not even exist depending on app configuration.

Copy the limit value into the struct where it belongs, and use it from
there.

[1] I strongly suspect there is a bug lurking there if the semaphore
maximum is being used to implement the kind of "packet buffer" this
code looks like.  Calling k_sem_give() on a "full" semaphore WILL NOT
BLOCK.  It will just drop the increment on the floor and return
synchronously.  Semaphores aren't msgqs or ringbuffers!  But disabling
the max value feature in zync does not result in test failures, so
maybe this usage is safe.

[2] Again, this seems suspicious; a valid k_sem should never have a
zero in that field.  Presumably this is really a test for "is
initialized", and so implies there's a mixed up initialization path
somewhere?

Signed-off-by: Andy Ross <andyross@google.com>
2022-10-17 10:13:56 +02:00
Piotr Pryga
6a79c3deae Bluetooh: Host: conn: Resume adv after disconn for periph role only
Zephyrs Host has by default enabled automatic resume of advertising
in case of disconnection when peripheral role is enabled.

The feature becomes a bit problematic in case of multirole usage.
For example assume a use case where a device is working as peripheral
and central, where it may establish single connection for each role.

In case there are two connections established and connection in
central role is dropped by peer, Host will automatically resume
advertising. After that an application can resume scanning, e.g.
in disconnected callback. That should not happen.

If one of connections was used for central role, it should not
be stolen by Host to run peripheral role. Host should verify
if a disconnected connection role was peripheral and then resume
advertising.

This approach will not break backward compatibility and change
correct resume behavior. What more, Host will follow an application
decisions about use of connection objects.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-10-17 10:06:45 +02:00
Emil Gydesen
0af4aad4bf Bluetooth: Audio: Remove call to bt_enable in audio init
The `audio init` should only initialize the audio (BAP)
stack. Furthermore, given that the `bt init` may do more
than just calling `bt_enable` it is generally for the best,
and more future proof, to let that command be the exclusive
way of calling `bt_enable` in the shell.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 14:24:20 +02:00
Emil Gydesen
e4b640ff2b Bluetooth: Audio: Fix segmentation issue in BT Audio shell
It was possible to enter a state where setting the QoS
for a source stream after having released a sink stream
as the unicast client would cause a segmentation error.
This issue is related to how the unicast shell is using
the unicast group.

A fix has been added for it, and a check for
whether or not `audio init` (to register the needed
callback) has been added. This check has also been added
for the broadcast sink.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 14:24:20 +02:00
Troels Nilsson
06aa981611 Bluetooth: controller: Support split advertising PDU pools
Adds proper support for having more than one PDU pool for the advertising
PDUs (to save memory)

- Introduces lll_adv_aux_data_init, lll_adv_aux_scan_rsp_alloc and
  lll_adv_sync_data_init to indicate if the PDU is a primary/legacy PDU
  or secondary/auxillary PDU
- Scan response PDUs are initialized later, since the correct pool to draw
  from depends on whether the advertising is extended or legacy

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-10-14 09:56:00 +02:00
Kim Sekkelund
a83b4f9d06 Bluetooth: Audio: Fix endian conversion in PACS
Not all C compilers understands how to use the address of a return
value as an argument to a function call. At least not our compiler.
Fix the issue by adding a variable to hold the converted value
before passing it to the function call.

Signed-off-by: Kim Sekkelund <ksek@oticon.com>
2022-10-14 09:55:26 +02:00
Emil Gydesen
23562448dc Bluetooth: Audio: Fix reset PAC records on bt_audio_discover
When calling bt_audio_discover, the discovered PAC records
were just added to the pac_cache. If called multiple times,
the PAC records would just be duplicated.

This change reset the pac records for the direction when
called.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:53:57 +02:00
Emil Gydesen
f307c08331 Bluetooth: Audio: Add additional check and log for stream->conn
bt_audio_stream_config should not be called with a stream
that is already configured to another connection.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:53:43 +02:00
Emil Gydesen
bd773158e1 Bluetooth: PACS: Add PAC records to the debug log
Logs the PAC records with BT_DBG for easier debugging
of the values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:53:36 +02:00
Emil Gydesen
59a9dd6054 Bluetooth: Audio: Add misisng stream_count reset for broadcast sink
This caused the sink to attempt to sync to more stream
for each call to bt_audio_broadcast_sink_sync as the
stream count was stored in the struct bt_audio_broadcast_sink
but never reset.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:53:23 +02:00
Emil Gydesen
65f130b73e Bluetooth: Audio: add missing CONFIG_BT_AUDIO_DEBUG_STREAM_DATA guards
Some places did not properly guard debug messages for sending
ISO data.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:53:11 +02:00
Emil Gydesen
0f30fbec96 Bluetooth: Audio: Increase unicast client Kconfig ranges
There is no reason for the previous limitation.

The limit of 255 for the ASEs is based on the ASE IDs
which is a uint8_t, so there is a maximum of 255 of
each ASE type.

The limit of 73 * 2 = 146 is based on the maximum size of an
GATT attribute (512), and the minimum size of a PAC record (7)
makes it a total of 73 PAC records for each direction.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:52:56 +02:00
Andries Kruithof
eb78f9f808 Bluetooth: controller: llcp: fix access to context after release
There is access to the procedure context after a potential release
of the context, which (in theory) can lead to incorrect behaviour

There is no good way of testing this with a unittest without adding
specal debug code to the ull_llcp_local module
After code-inspection no other location has been found with
potential access after context release

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-10-14 09:52:41 +02:00
Emil Gydesen
7ab1cafbc2 Bluetooth: Audio: Add Broadcast source application AD
This refactors how the BAP broadcast source handles the
extended and periodic advertising.

First it removes the start and stop of the extended
advertising, and instead expects the application
(or upper layers) to do this.

Second it exposes API functions to get the
necessary advertising data from BAP (service data and
the BASE), which the upper layers will then also
be responsible for setting and updating.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:51:39 +02:00
Emil Gydesen
cb4541ae51 Bluetooth: Audio: Fix missing metadata_updated calls
The metadataa_updated callback has existed for a long
time, but was never actually used. The metadata is set
or updated in the enabling and streaming state.

Added checks to see if the state actually changes when going
into these states, and if not, then it means that the
metadata was updated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-14 09:51:23 +02:00
Mariusz Skamra
d44e112045 Bluetooth: audio: ascs: Remove unused bt_ascs member
Remove unused struct member.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-13 16:03:34 +02:00
Emil Gydesen
0dc9f57fa5 Bluetooth: Audio: Fix bad error check for bt_unicast_client_start
If bt_audio_stream_connect didn't fail, we would just return
without sending the receive start ready command.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-13 09:57:24 +02:00
Lingao Meng
4a2033a661 Bluetooth: Mesh: net cache uses reverse order traversal
Since the net cache is accumulated in positive order, the net
cache uses reverse order traversal, which can filter duplicate
messages more effectively.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-10-13 09:56:50 +02:00
Lingao Meng
5867492582 Bluetooth: Mesh: Fix missing clear dup cache
When lpn reject message, should clear dup cache to
avoid dup check next mesh message.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-10-13 09:56:50 +02:00
Lingao Meng
4f1e326f2a Bluetooth: Mesh: Remove msg_cache_next in rx ctx
Since in bt_mesh_net_recv will call msg_cache_add
and if lpn reject this message, should remove this cache.

But this function sequentially and will not be interrupt
by any thread so, we no need a copy var to save this value.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-10-13 09:56:50 +02:00
Piotr Pryga
c2ea0328fa Bluetooth: Controller: df: Fix spelling errors
Fix spelling errors in coments in ull_df.c source file.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-10-12 18:41:54 +02:00
Piotr Pryga
3987259888 Bluetooth: Controller: df: Relax cl CTE RX enable param check
According to Core 5.3 Vol 4, Part E, section 7.8.82 slot_durations,
switch_pattern_len and ant_ids are used only for AoA and do not affect
reception of AoD CTE.

To improve interoperability checking of correctness of these parameters
is not required. It will not affect lower link layer in case the AoA
CTE reception feature is not enabled in Kconfig.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-10-12 18:41:54 +02:00
Mariusz Skamra
9c3f190721 Bluetooth: audio: capabilities: Hide bt_audio_capability_get function
This function exposes list pointer, so that it allows the user to modify
the internal list. This adds bt_audio_foreach_capability iterator finction
that can be used instead.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-12 18:41:22 +02:00
Gerard Marull-Paretas
34a6848887 include: add missing arch/cpu.h include
The sys* ops like sys_clear_bit are indirectly included via arch CPU
header. Other stuff like find_msb_set end up included via this header as
well.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Troels Nilsson
28a9a79b98 Bluetooth: Controller: JIT fixes for ext. adv. duration handling
- Account for the added random delay when updating remaining duration
- Re-worked JIT re-scheduling update a bit to keep the random delay
  information and remaining duration correct

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-10-10 13:55:37 +02:00
Troels Nilsson
b6f5c75581 Bluetooth: Controller: Ext. adv. duration handling fix
- Remaining duration is now in us instead of ticks to avoid
  overflow when ticks have higher resolution
- First advertising event should not reduce remain duration

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-10-10 13:55:37 +02:00
Troels Nilsson
2a9cd8ffb1 Bluetooth: Controller: Add EVENT_OVERHEAD_START_US when enabling states
Add EVENT_OVERHEAD_START_US to ticks_anchor when enabling
advertising, so the first advertising event is not late due
to calculations for aux packets etc.

Signed-off-by: Troels Nilsson <trnn@demant.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-10 13:55:37 +02:00
Vinayak Kariappa Chettimada
236d0351e7 Bluetooth: Controller: EVENT_OVERHEAD_START_US for typical usecases
Tune the EVENT_OVERHEAD_START_US for typical usecases on
nRF52833 SoC using the central_gatt_write and
peripheral_gatt_write samples.

Manually run the samples for over 30 mins without any
assertions and use the actual profiled value that would
otherwise be printed on assertion.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-10 13:55:37 +02:00
Vinayak Kariappa Chettimada
a3b0ade9c6 Bluetooth: Controller: Explicit ticker worker trigger on expire in past
When ticks_to_expire is in the past, i.e. ticks_to_expire is
0, perform an explicit trigger of ticker worker instead of
setting up the compare which delays the trigger by the
minimum ticks offset margin. The changes reduce latencies
of the O(n) ticker_resolve_collision by upto the minimum
ticks offset margin (3 for nRF SoCs) for each resolution.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-10 13:55:37 +02:00
Vinayak Kariappa Chettimada
ebf7236267 Bluetooth: Controller: Add verbose assertion on delayed prepare
When an event's prepare is delayed due to ULL scheduling or
ISR latencies, check and have a verbose assertion that logs
the actual EVENT_OVERHEAD_START_US required.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-10 13:55:37 +02:00
Vinayak Kariappa Chettimada
7715fb40e2 Bluetooth: Controller: Add LL_ASSERT_MSG definition
Add LL_ASSERT_MSG definition to log a verbose message as
part of assertion check.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-10 13:55:37 +02:00
Vinayak Kariappa Chettimada
367004fd57 Bluetooth: Controller: Conditional compile optional ticker interfaces
Conditional compile ticker interfaces like ticker_update
which are not required when individual state or role samples
are build.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-07 14:46:38 +02:00
Vinayak Kariappa Chettimada
e48ea7e87b Bluetooth: Controller: Fix BIG event counter calc from payload count
Fix the BIG event counter calculation from stored payload
counter. Event latency should not be multiplied by burst
count.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-07 14:42:27 +02:00
Vinayak Kariappa Chettimada
36db43716a Bluetooth: Controller: Fix missing includes to build full feature set
Fix missing includes and rearrange header includes to be able
to build a full feature set Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-07 14:34:14 +02:00
Emil Gydesen
02d6661d71 Bluetooth: Shell: Add support for sending sine tone with the audio shell
added `audio start_sine` and `audio stop_sine` to start/stop
sending an LC3 encoded sine tone.

This code is heavily inspired from the sine tone implementation
from the unicast_client sample implementation.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-07 13:22:53 +02:00
Emil Gydesen
83d3a36f78 Bluetooth: Audio: Shell: Add broadcaster address in broadcast scan callback
Add printing of the broadcast source advertising address in the
scan callback. Also rename the scan callback to make
it more clear that it is for broadcast scanning.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-07 13:22:45 +02:00
Emil Gydesen
208f44722f Bluetooth: Audio: Clear received_base in audio shell on PA sync lost
When the PA sync is lost, we clear the received_base so
that once we resync to the PA, we get the BASE again.

This is to make it easier to decode and use the BASE again
if the sync was lost, as the previous BASE may have
been printed a long time before.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-07 13:22:39 +02:00
Emil Gydesen
1302e95647 Bluetooth: Audio: Modify log of non-found stream for config state callback
In the unicast client, it is possible for the unicast server
to send a notification for ASE when it is in the codec
configured state after a reconnect. In that case, the
unicast client does not have a coupling between the ASE
and the audio stream.

This caused a BT_ERR to trigger, but it is not really an
error, but rather a state that the current unicast client
cannot handle, so the BT_ERR has been replaced with
a BT_WARN.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-07 13:22:30 +02:00
Emil Gydesen
fa13e02320 Bluetooth: Audio: Use stream->conn instead of iso->acl for ISO disconnect
Use the stream->conn instead of the iso->acl, as the iso->acl
may already have been free'd by the ISO layer when the
disconnected callback is called.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-07 13:22:23 +02:00
Szymon Czapracki
ab45e31c7e Bluetooth: Audio: Fix ASE race condition
This patch fixes invalid ASE state transition,
ASE now waits for Receiver Start Ready before
going into Streaming state.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2022-10-07 10:10:32 +00:00
Emil Gydesen
384f3461ad Bluetooth: Audio: Fix bug where sink ep did not go to streaming state
If the CIS was connected before the sink endpoint was
in the enabling state, it never autonousmly went into
the streaming state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-07 10:09:58 +00:00
Mariusz Skamra
4eb7077978 Bluetooth: audio: ascs: Move control point pointer out of bt_ascs
bt_ascs is per connection, so the control point attribute pointer
should not be part of this structure.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-06 22:42:24 +00:00
Mariusz Skamra
28ce0a96b1 Bluetooth: audio: capabilities: Remove redundant direction parameter
The direction is used to identify the list to append the registered
capabilities. There is no need to keep it in the bt_audio_capabilities,
it can be provided as a function parameter instead.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-06 22:41:27 +00:00
Emil Gydesen
8673fab276 Bluetooth: Audio: Fix bad warning when creating MPL OTS objects
The return check for adding MPL objects in OTS with
bt_ots_obj_add was incorrect, as only negative values
indicate an error, and a positive value returns the ID.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-06 22:40:32 +00:00
Andries Kruithof
ce1580765d Bluetooth: controller: set Ctrl Tx buffers to non-zero
Set the correct number of Ctrl Tx buffers used for the new
implementation, so that the ACK-fifo gets the correct size

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-10-06 09:01:19 +02:00
Vinayak Kariappa Chettimada
6a9e7a2960 Bluetooth: Controller: Conditionally compile legacy Ctrl Tx buffers
Conditionally compile the legacy control procedure defined
control Tx buffers that is not required in the new control
procedure implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-06 09:01:19 +02:00
Emil Gydesen
7b0ba0f517 Bluetooth: Audio: Fix missing path_id for unicast server
The codec->path_id supplied to the capabilities
were not being used for the endpoint codec.

Important note: This only works if there is a single
capability per codec ID per direction. This limitation
is also an existing limitation in the current
implementation of capabilities.c.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-05 12:45:14 +02:00
Emil Gydesen
9e256681a4 Bluetooth: Audio: Fix syncing to multiple BIS for broadcast sink shell
Fixed an issue with syncing to multiple BIS as the broadcast
sink in the shell. Also changed a check in the broadcast
sink implementation from an assert to a `if` to provide
a better way of handling bad input.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-05 12:42:09 +02:00
Troels Nilsson
de8c19da5e Bluetooth: controller: Handle fragmented AD without chaining PDUs
Adds support for handling fragmented advertising data over HCI when
CONFIG_BT_CTLR_ADV_AUX_PDU_LINK is not enabled

- Added support for appending advertising data to ull_adv_aux_hdr_set_clear
  and ull_adv_aux_pdu_set_clear via ULL_ADV_PDU_HDR_FIELD_AD_DATA_APPEND
- Updated ll_adv_aux_ad_data_set and ll_adv_aux_sr_data_set to
  handle fragmentation ops without CONFIG_BT_CTLR_ADV_AUX_PDU_LINK

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-10-05 09:18:15 +00:00
Jakob Krantz
8cac1f5b2c Bluetooth: Host: Add function to retreive per_adv_sync obj from index.
Gives the application a two way mapping between array index
and a per_adv_sync object instead of current only per_adv_sync
obj -> index using bt_le_per_adv_sync_get_index.

Signed-off-by: Jakob Krantz <jakob.krantz@u-blox.com>
2022-10-04 19:17:27 +00:00
Jonathan Rico
a7537f527c Bluetooth: log: show function names by default
Show function names for all BT_xx logging levels when BT_DEBUG_LOG is
enabled. This makes it easier to find the problematic lines.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-10-04 14:09:04 +00:00
Jonathan Rico
afef6e2722 Bluetooth: att: precise warning messages
- Downgrade the warning emitted when we run out of channels.
- Only log a warning when failing to establish channels and the error is
  not -ENOMEM.
- Add a debug log message in that case to hint what might've happened.

This should make it less confusing to the average user not aware of the
stack internals.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-10-04 14:09:04 +00:00
Jonathan Rico
477c0fcb6e Bluetooth: l2cap: reword unknown pdu warning
This is a scary-looking warning for users, and should only really matter to
stack developers. It will eventually show up in the wild for embedded
devices that don't get updated to the latest and greatest.

Reword it to make it clear we are rejecting it, and it doesn't impact the
stack in any way.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-10-04 14:09:04 +00:00
Jonathan Rico
5d96b9e555 Bluetooth: smp: reword pairing failed error
This makes it more user-friendly, in case no failed cb has been
registered so this error is printed out of context.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-10-04 14:09:04 +00:00
Jonathan Rico
5cc0e8cdaa Bluetooth: hci_core: reword warning
Reword the scary-looking `bt_hci_core; Malformed data` warning to show
where it is originating from.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-10-04 14:09:04 +00:00
Mariusz Skamra
ae1ed41116 Bluetooth: audio: tbs_client: Fix GTBS index returned in API callbacks
This fixes GTBS index used in API. The index that is exposed to the
application is 255 in case of GTBS.
The code has been reworked to remove redundant booleans and index that
was kept inside instance.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-04 14:08:26 +00:00
Mariusz Skamra
1b310b26f3 Bluetooth: audio: tbs_client: Remove redundant checks
The CONTAINER_OF does not return NULL, thus the `inst == NULL` checks
are not needed.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-04 14:08:26 +00:00
Lingao Meng
61d6532014 Bluetooth: Mesh: Add missing adv_main for relay message
By design, adv main set can use to send relay mesh messages
but here adv main set is invoked.

Add in the ended, so, adv main set only can be used when all
relay adv sets busy.

and this way does not cause too much delay for adv main set,
due to local message will process firstly.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-10-04 10:21:18 +00:00
Anders Storrø
b9f776d2fb Bluetooth: Mesh: Shell: Clear CDB on local reset
Adds feature that clears the CDB entry on local reset.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-10-04 10:20:38 +00:00
Anders Storrø
c7621d7ea1 Bluetooth: Mesh: Shell: Del CDB node on node reset
Adds feature that deletes the shell CDB node after perfoming a config
client reset of another node.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-10-04 10:20:38 +00:00
Vinayak Kariappa Chettimada
630eb033ba Bluetooth: Controller: Remove redundant assertion check
Remove redundant assertion check, and minor indentation fix
to correct the alignment of function call.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-04 10:36:32 +02:00
Vinayak Kariappa Chettimada
d96aa6dd70 Bluetooth: Controller: Minor indentation fix
Minor indentation fix to keep within 80 columns when it is
possible.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-04 10:36:32 +02:00
Anders Storrø
bea54c5691 Bluetooth: Mesh: Shell: Make prov features dynamic
Alters several provisioning related features to allow commands to be
functional with application defined Provisioning properties &
capabilities.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-10-04 10:33:30 +02:00
Emil Gydesen
15ed8569ed Bluetooth: Audio: Update ASE EP state checks
Update the existing ASE EP state checks to be more correct
and aligned with the ASCS specification.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-10-04 10:33:13 +02:00
Vinayak Kariappa Chettimada
578cc10043 Bluetooth: Controller: Ticker window extension for broadcaster only
Enable ticker ticks slow window extensions implementation
when broadcaster role is enabled. This feature moves the
primary channel advertising event within the specified
window when overlapping with other roles.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-10-03 16:28:09 +02:00
Nirosharn Amarasinghe
8b0d695be5 Bluetooth: controller: Implemented PDU release timeout
Implemented:
-- Combining segments from multiple SDUs in a single PDU for TX
-- Release of PDU based on remaining capacity below threshold
-- Release of any PDUs in production on receiving a timeout for the
   upcoming event
-- Release of PDUs in production if source if destroyed
-- Synchronization flag to exclude multiple contexts in ISO-AL
-- New Kconfig BT_CTLR_ISO_TX_SEG_PLAYLOAD_MIN to allow definition of
   minimum TX segment size

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2022-10-03 13:22:13 +02:00
Nirosharn Amarasinghe
789628a4e3 Bluetooth: Controller: Implemented buffering of SDU fragments in ISO-AL
Implements:
-- SDU fragments can be buffered in the ISO-AL so that the correct size
   of the SDU can be computed such that it can be released for inclusion
   in the first fragment's header
-- Changed SDU emit interface to allow the same structure to be used to
   buffer as well as release fragments
-- New configuration BT_CTLR_ISO_RX_SDU_BUFFERS to specify the number of
   SDU buffers for each sink
   (Buffering disabled when BT_CTLR_ISO_RX_SDU_BUFFERS=0)

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2022-10-03 13:22:13 +02:00
Nirosharn Amarasinghe
6c855b43be Bluetooth: Controller: implemented HCI_LE_Read_ISO_TX_Sync in ISO-AL
Implemented:
-- Storing information required to service HCI_LE_Read_ISO_TX_Sync
   request
-- Implemented interface to retrieve information
-- Cleared ISO-AL source and sink state on deallocation
-- Renamed cig_ref_point to grp_ref_point as it serves a common purpose
   in both CIS and BIS

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2022-10-03 13:22:13 +02:00
Nirosharn Amarasinghe
68b7b36adf Bluetooth: controller: Included guard for lost data in framed PDUs
Improvement for IAL/CIS/FRA/PER/BI-01-C & IAL/CIS/FRA/PER/BI-02-C
-- Test appears to fail as the transmitted PDU is packed with less data
   than is indicated in the segment headers.
-- Guards were included to verify that sufficient data exists in the PDU
   before extracting the segment.

General
-- Updated timestamps in error SDUs to better approximate the expected
   timestamps if time information is missing.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2022-10-03 13:22:13 +02:00
Erik Brockhoff
bd3bc98847 Bluetooth: controller: correct parameters in conn update complete event
In case a connection update complete event reports an error, the
parameters reported should be the ones active on the connection and not
the ones requested

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-10-03 10:20:04 +02:00
Lingao Meng
83d129bc15 Bluetooth: Mesh: Add prefix bt_mesh_ for global variable
Some variables shadow global, which is difficult to handle when
porting to other platforms with shadow warnings turned on.

https://github.com/zephyrproject-rtos/zephyr/pull/50581

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-10-03 10:19:57 +02:00
Mariusz Skamra
9dae352007 Bluetooth: audio: ascs: Increase the number of supported ASEs
This increases the number of supported audio stream endpoints.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-03 10:19:39 +02:00
Mariusz Skamra
1432d05c29 Bluetooth: audio: pacs: Remove redundant code
Avoid unnecessary memcmp of UUID's.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-03 10:17:30 +02:00
Mariusz Skamra
9ecbee2587 Bluetooth: audio: capabilities: Remove callbacks
This removes the callbacks from capabilities. The callbacks are used for
unicast server role only, while the capabilities are used for the
broadcast sink role as well. Thus the callbacks can be removed as there
is another bt_audio_unicast_server_cb API that is specific for unicast
server role.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-03 10:17:21 +02:00
Mariusz Skamra
43f270ad11 Bluetooth: audio: tbs_client: Fix primary service discovery function
Fixes the discovery function that handles GTBS only discovery. The
discovery stops when there is no space left for another instance. The
function has been split to improve the code readability and avoid
unnecessary UUID comparison.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-03 10:15:03 +02:00
Mariusz Skamra
124d66e885 Bluetooth: audio: tbs_client: Make GTBS client only build option
Refactor Kconfig to add a way to enable GTBS only client.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-03 10:15:03 +02:00
Anders Storrø
901767a47a Bluetooth: Mesh: Shell: Add cfg opt for health srv
Adds Kconfig option for the Mesh Shell Health server.

The shell implementation of Health Server test commands is
dependent on the user adding and initializing the shell Health
Server instance in their application to make the commands functional.
To prevent any confussion about how these commands work, a Kconfig
option has been added to allow conditional compilation of these
commands. In this way the user must actively enable this feature, making
the conditional requirements more clear.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-10-03 10:12:25 +02:00
Mariusz Skamra
7cc5be0dcf bluetooth: audio: pacs: Remove duplicated code
Remove code duplicates

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-10-03 10:10:46 +02:00
Szymon Janc
6673cb1f60 Bluetooth: Controller: Fix DLE HCI params parsing
LE Write Suggested Default Data Length and LE Set Data Length commands
are suggestions from host and should be validated only as per HCI
specification regarding internal setting of LLCP.

LLCP is allowed to use other values if needed.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-10-03 10:08:34 +02:00
Andries Kruithof
5530ea0bd0 Bluetooth: controller: ensure memory access is aligned
The memory used for Tx buffers and procedure context must
be aligned on a word boundary, otherwise it is possible
to get unaligned memory access

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-09-30 11:12:19 +02:00
Aleksander Wasaznik
c90b4a4e52 Bluetooth: Shell: Fix GATT exchange mtu assertion fail
This change fixes a bug where the second use of shell command `gatt
exchange-mtu` would trigger an assertion failure in the stack. The BT
API `bt_gatt_exchange_mtu` asserts `params->func != NULL`.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-09-29 17:34:33 +02:00
Vinayak Kariappa Chettimada
48c21fab93 Bluetooth: Controller: Fix radio_tmr_start_us to be soft realtime
Fix radio_tmr_start_us to be soft realtime, if the requested
start in microseconds is in the past, setup the next
earliest expiry. This is to prevent radio not being started
and not let the LLL hanging. When setup to receive auxiliary
PDU in LLL scheduling, is_aux_sched is set and if radio does
not start and the window is requested to be pre-empted, then
it is blocked from being preempted due to the is_aux_sched
flag remaining to be set. This stalls the scanning
infinitely until explicit scan disable.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-29 16:42:36 +02:00
Vinayak Kariappa Chettimada
8b586ee5a4 Bluetooth: Controller: Fix missing is_aux_sched flag being reset
Fix missing is_aux_sched flag being reset before resuming to
scan for new advertising PDU in the same scan window after
having received an earlier primary channel PDU and auxiliary
channel PDU using LLL scheduling.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-29 16:42:36 +02:00
Vinayak Kariappa Chettimada
0eec434472 Bluetooth: Controller: Fix receiving spurious PDU in active scanning
Fix receiving spurious overlapping ADV_IND and SCAN_IND PDU
when LLL state expects to receive SCAN_RSP PDU. Explicitly
check that these PDUs are not processed when in active
scanning and waiting for SCAN_RSP PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-29 16:42:36 +02:00
Vinayak Kariappa Chettimada
1de70b575a Bluetooth: Controller: Fix node rx leak on extended scanning stop
If scan is being disabled, rx could already be enqueued
before coming to ull_scan_aux_rx_flush. Check if node rx is
not the last in the list of received PDUs then add it to the
list, else do not add it to the list to avoid duplicate
report generation, release and probable infinite loop
processing of the list. It is possible that node rx has not
be already added in case of last PDU in the chain, under
this case when scan is being stopped add it to the list
before auxiliary context is flushed.

Add the node rx to aux context list of node rx if not
already added when coming to ull_scan_aux_rx_flush. This is
handling a race condition wherein the last PDU in chain is
received and at the same time scan is being disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-29 16:42:36 +02:00
Vinayak Kariappa Chettimada
ba6cbc57e1 Bluetooth: Controller: Fix scan aux leak on periodic sync terminate
Fix scan aux context leak on Periodic Sync Terminate. On
Periodic Sync Terminate the `is_stop` flag is set to prevent
the ULL from assigning an aux context to the sync context,
but the acquired aux context was neither assigned to sync
context nor was being released back to the aux context pool.
Fixed by releasing the aux context if not assigned to the
sync context when `is_stop` flag is set.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-29 16:42:36 +02:00
Jonathan Rico
5f8e657a22 Bluetooth: att: limit EATT MTU to max buffer size
If a device sends an MTU that is bigger than our maximum tx buffer size,
that could cause assertion failures down the line.

This PR limits it to the maximum we support (CONFIG_BT_L2CAP_TX_MTU).

The issue has been observed with a gatt discovery procedure, but is likely
present in other places in att.c.

To reproduce it, we need two zephyr shell devices, with one having a larger
MTU than the other:
- connect
- do data length update to the bigger MTU
- set security to 2, EATT channels get connected
- launch a gatt discovery from the device with the larger MTU
- observe kernel panic on the other device when it attempts to add too much
memory to a net buf.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-29 10:16:57 +00:00
Joakim Andersson
cc74b3b977 Bluetooth: host: Log SC LTK in pairing procedure without bonding
Log the LE Secure Connection (SC) LTK in a pairing procedure without
bonding when CONFIG_BT_LOG_SNIFFER_INFO is enabled.

Fixes: #50691

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-09-29 10:15:08 +00:00
Emil Gydesen
715478fe8e Bluetooth: Shell: Add log of error code from bt_audio_stream_qos
Print the error code from calling bt_audio_stream_qos if it fails.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-28 14:06:06 +00:00
Erik Brockhoff
183370277b Bluetooth: controller: fixing slot reservation for connection setup
With introduction of refactored LLCP was also introduced an error
re. calculation of initial slot reservation in connection setups.

Due to this error a bigger slot was reserved, leading to failure due to
connection overlaps in multiple.sh test.
Also the removal of this 'overhead' in slot reservations calls for
bigger time-allowance for l2pcap_stress test.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-09-27 10:02:07 +00:00
Emil Gydesen
186181687b Bluetooth: Audio: Remove unicast client set state
The unicast client should never need to set the state of the
endpoints directly, without an notification from the server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-27 09:16:21 +00:00
Emil Gydesen
a59bc35235 Bluetooth: Audio: Ensure that ASEs don't get idled when CIS is connected
Ensure that the CIS for an ASE, if any, is disconnected before we
go into the idle state.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-27 09:16:21 +00:00
Emil Gydesen
874c45241e Bluetooth: Audio: Remove caching ASE on release
Remove the support for caching ASEs on release.

This is mainly due to the 2-stage design in Zephyr: We
have the bt_audio_stream and the bt_audio_ep, where the
the latter represents an ASE in most cases.

However, once the endpoint goes into the codec configured
state, then a stream must be bound to it. This would be fine
(although a stream is technically not established at this point),
except that a stream is also, for unicast, specified for a
specific ACL. Once the ACL disconnects, the stream technically
becomes invalid, and if the stream is invalid, so is the endpoint.

Based on that, there's no reason (or even option) to keep the
endpoint in a codec configured state, as it would not
have a valid stream associated with it.

If we want to support an ASE going into the codec
configured state on ASE release (or ACL disconnect),
the relationsship between ASEs and streams needs to
be redefined.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-27 09:16:21 +00:00
Jonathan Rico
1051607c7c Bluetooth: l2cap: prevent deadlock on chan timeout
When getting a channel timeout, l2cap_chan_destroy is called from the
rtx_work work item.

In that function we attempted to cancel the current work item, and sync on
it being cancelled. The kernel API says that this will block until the work
item completes execution, hence a deadlock.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-26 15:13:13 +00:00
Vinayak Kariappa Chettimada
744e5f4da4 Bluetooth: Controller: Fix ticks_slot_id_previous reset on ticker yield
Fix implementation to not reset the ticks_slot_id_previous
when ticker yields its reserved slot, only reset if ticker
was stopped.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-26 13:20:28 +02:00
Vinayak Kariappa Chettimada
245b1e0330 Bluetooth: Controller: Fix ticker worker check ticks_slot_previous
Fix ticker worker from checking the ticks_slot_id_previous,
only ticks_slot_previous be checked as previous slot id
would be assigned to TICKER_NULL if the ticker was stopped.
The ticks_slot_previous value should be used to check that
a slot is reserved even if the ticker has been stopped.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-26 13:20:28 +02:00
Ahmed Moheb
fab9c5a140 tests: bluetooth: host: Add UT for bt_keys_get_addr()
Unit test project for bt_keys_get_addr().
This part of subsys/bluetooth/host/buf.c unit testing

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-26 13:05:47 +02:00
Ahmed Moheb
fd888df41d tests: bluetooth: host: Add mocks for keys.c
Add required mocks to be able to compile and test /bluetooth/host/keys.c

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-26 13:05:47 +02:00
Vinayak Kariappa Chettimada
e348fe494a Bluetooth: Controller: Warn LLCP Legacy implementation as DEPRECATED
Add in Kconfig, select DEPRECATED, to warn at build time
that the LLCP legacy implementation is deprecated and the
refactored LLCP enabled by BT_LL_SW_LLCP Kconfig option be
used instead (which is the default now).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-26 11:07:17 +02:00
Jonathan Rico
109c47639e Bluetooth: l2cap: remove ambiguous naming
`l2cap_tx_meta_data` is also a function-like macro.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-26 11:05:04 +02:00
Jonathan Rico
77e1a9dcad Bluetooth: host: l2cap: add alloc_seg callback
This callback allows use-cases where the SDU is much larger than the l2cap
MPS. The stack will then try to allocate using this callback if specified,
and fall-back on using the buffer's pool (previous behavior).

This way one can define two buffer pools, one with a very large buffer
size, and one with a buffer size >= MPS, and the stack will allocate from
that instead.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-26 11:05:04 +02:00
Jonathan Rico
8e207fefad Bluetooth: host: l2cap: workaround SDU deadlock
See the code comments.

SDUs might enter a state where they will be blocked forever, as a
workaround, we nudge them when another SDU has been sent.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-26 11:05:04 +02:00
Jonathan Rico
3c1ca93fe8 Bluetooth: host: l2cap: don't send too much credits
There was an edge-case where we were sending back too much credits, add a
check so we can't do that anymore.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-26 11:05:04 +02:00
Jonathan Rico
1c8fe67a52 Bluetooth: host: l2cap: release segment in all cases
See code comment

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-26 11:05:04 +02:00
Vinayak Kariappa Chettimada
88705be89b Bluetooth: Controller: Fix BIS max PDU size used in calc of sub_interval
Fix BIS max PDU size used in calc of sub_interval, use the
minimum of supported maximum BIS PDU size and the requested
SDU size. This will avoid wasted air time between subevents
when SDU size is less than maximum supported PDU size, where
only 150 us tIFS is mandatory between subevents.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-23 12:47:17 +00:00
Anders Storrø
3cbb8315fc Bluetooth: Mesh: Shell: Fix cfgCli appkey arg conv
Rectifies incorrect conversion of appkey string in config client
appkey add command.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-09-23 13:13:59 +02:00
Vinayak Kariappa Chettimada
b867f0e8a6 Bluetooth: Controller: Fix T_MAFS between broadcasting roles
When calculating the offsets between primary advertising
PDU, auxiliary PDU, Periodic Advertising PDU, and BIS PDU,
the values used as anchor points for starting the periodic
interval for auxiliary, periodic and BIG events, should be
ensured to have the minimum auxiliary frame spacing T_MAFS
between the PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-23 11:51:52 +02:00
Vinayak Kariappa Chettimada
1bbe209a30 Bluetooth: Controller: Fix auxiliary scan stop assertion check
Use a local variable to assert check on auxiliary context's
release.
Add missing volatile qualifier to the parent field of the
auxiliary scan context.
Under race condition a released aux context can be allocated
for reception of chain PDU of a periodic sync role, hence
fix the assertion check to consider that the released
context can be allocated to other roles.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-23 08:11:39 +00:00
Vinayak Kariappa Chettimada
16e0e6607c Bluetooth: Controller: Increase BIS PDU access address receive timeout
Increase the BIS PDU access address receive timeout, use the
+/- 2 us jitter for each subevent.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-23 09:57:06 +02:00
Vinayak Kariappa Chettimada
24efea7ba1 Bluetooth: Controller: Fix infinite loop receiving ISO Data
Fix inifinite loop in ll_rx_get() when both ISO Broadcast
and ISO Receive features are enabled in a build. Missing
conditional compile prevented the ack_last index that
maintains a relation between number of packets complete and
the received data packets was unassigned.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-22 18:05:36 +02:00
Piotr Pryga
047b756e64 Bluetooth: df: Add ntf of insufficient resources for IQ samples
According to Bluetooth 5.3 Vol 4, Part E section 7.7.65.21 the
Controller should send an IQ report with Packet_Status set to 0xFF
and Sample_Count to 0x0, to inform Host that it is not able to
store IQ samples for all received Constant Tone Extensions and has
failed to sample at least once.

This commit adds handling of such situation for direction finding
in connectionless mode in lower link layer. It includes:
- lack of node_rx_iq_report to store IQ samples,
- lack of free node_rx to report received advertising data (generates
  an advertising data report with indication "incomplete, no more to
  come" and cancels reception of chained PDUs,
- cancellation of chained PDUs reception due to other scheduling
  reasons.
In all of these situations CTE reception must be enabled and number of
received CTEs is smaller than requested by Host.

If there is not sufficient number of node_rx_iq_report nodes and
report was generated, the CTE will not be samples in a given
periodic advertising synchronization event. The CTE will be
sampled again in next event if there are node_rx_iq_report available.

End user applications may check periodic advertising sync event
counter when use of the reports to be sure about sync event
the received report is connected with.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-09-22 18:04:00 +02:00
Vinayak Kariappa Chettimada
30823c6f56 Bluetooth: Controller: Fix stream index use in Broadcast ISO Tx
Fix incorrect use of stream handle instead of connection
handle to enqueue Tx ISO Data, and use stream index to get
stream instance.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-22 15:53:35 +02:00
Pavel Vasilyev
e4921cc84d Bluetooth: Mesh: Trigger GATT update when subnet is added
When the node is part of only one subnet, it starts Network ID
advertisements with infinite timeout. It is not an issue when using
legacy advertising and extended advertising with shared set for local
messages and GATT because any message will stop advertisements. However,
when a separate adv set is used for GATT advertisements,
`struct bt_le_ext_adv_cb.start` callback won't be called, but the
implementation relies on that callback to switch to a next subnet.
Calling `bt_mesh_adv_gatt_update()` stop GATT advertisement so that the
implementation can switch to the next subnet.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-22 10:03:39 +02:00
Pavel Vasilyev
20a3a83c9f Bluetooth: Mesh: Fix node identity interleave multiple subnets
Reduce advertising duration to `max_timeout` when advertising node
identity for multiple subnets. This will let the node to interleave
subnets for NODE_ID_TIMEOUT.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-22 10:03:39 +02:00
Pavel Vasilyev
326786efd6 Bluetooth: Mesh: Avoid indefinite timeout when duration less than zero
`struct bt_le_ext_adv_start_param.timeout` resolution is in 10ms. When
duration is less than 10ms, division will be evaluated to zero, which
will result in indefinite timeout. Set timeout to 10ms to avoid
indefinite timeout. The advertisement will end earlier anyway after the
event is finished.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-22 10:03:39 +02:00
Vinayak Kariappa Chettimada
d53d9fb6bf Bluetooth: Controller: Add error log for Advertising enable/disable
Add error message logging for Advertising enable/disable at
RPA timeout when the resolvable address is updated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-21 13:04:00 +00:00
Vinayak Kariappa Chettimada
6c40427931 Bluetooth: Host: Fix resolvable address update with Ext Adv enabled
Fix resolvable address update after RPA timeout with
Extended Advertising support enabled. As Extended
Advertising HCI Commands are being used to start legacy
advertising, incorrectly the local random address was being
used instead of using the random address populated in the
Extended Advertising set. BT_DEV_RPA_VALID is not cleared
when Extended Advertising HCI commands are used, hence the
local random address is not updated and the incorrect use
of it did not make any change to the advertising when
disabled and enabled at RPA timeout.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-21 13:04:00 +00:00
Vinayak Kariappa Chettimada
87b39c5975 Bluetooth: Controller: Fix repeated skip in ticker resolve collision
Enforce next_is_older only when current has equal force as
with the next ticker.

Added Kconfig to disable priority feature in ticker that is
currently not used by Zephyr Bluetooth Low Energy
Controller.

The priority feature if enabled then a custom ULL is needed
by vendors to avoid repeated skipping of overlapping events
as next_has_priority check uses lazy value that would be
always lazy_next > lazy_current as currently skipped event
becomes the next event with lazy value incremented by 1.

Regression in commit 3a9173afe1 ("bluetooth: controller:
Revised ticker for improved conflict resolution") due to
Zephyr Controller does not implement any vendor specific
priority logic.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-21 12:28:44 +02:00
Mariusz Skamra
933a987d75 Bluetooth: audio: Fix possible memory violation
This fixes possible memory violation by using the index outside of an
instance array by tbs_client_common_call_control.
This basically fixes the get_inst_by_index function to return NULL if
the index is invalid. The function calls have been guarded to catch the
returned NULL.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-09-21 12:25:44 +02:00
Vinayak Kariappa Chettimada
fca96cfe33 Bluetooth: Controller: Reduce cntr_cnt_get() calls in ticker
Reduce the number of times cntr_cnt_get() is called in
ticker implementation as call to this function halts the
CPU inorder to access the RTC count in the 32KHz clock
domain.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-21 08:53:03 +00:00
Vinayak Kariappa Chettimada
69fb2dced0 Bluetooth: Controller: Fix TICKER_LOW_LAT Ext. Scan assert check
Fix Extended Scanning assertion check when using Ticker
Low Latency Implementation where the failure to schedule
a ticker timeout is returned inline compared to deferred
failure in the operation callback.

Auxiliary PDU is received using a single-shot ticker
timeout with ticks_slot reservation. This single-shot
ticker is allowed to fail if it is overlapping another
event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-20 09:10:40 +00:00
Pavel Vasilyev
ef7f5226cf Bluetooth: Mesh: Fix description in BT_MESH_ADV_BUF_COUNT option
Fix description in BT_MESH_ADV_BUF_COUNT option.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-20 08:43:32 +00:00
Aleksander Wasaznik
7e11b98125 Bluetooth: Host: Add "assert non-null" to bt_conn_ref
Clearly `conn` must be non-null since it's dereferenced without checks.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-09-20 08:22:28 +00:00
Aleksander Wasaznik
a8f12ab690 Bluetooth: Host: Name enum bt_keys_type
Name annonymous enum with `BT_KEYS_` as `bt_keys_type`.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-09-20 08:22:06 +00:00
Mariusz Skamra
bc2414e094 Bluetooth: audio: ascs: Fix crash on source QoS config
This fixes crash that happened during source ASE QoS by setting
the tx path that was left uninitialized.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-09-20 09:40:17 +02:00
Wolfgang Puffitsch
06e7751303 Bluetooth: controller: Fix error codes for accept/reject CIS request
The LE Accept/Reject CIS Request commands shall return Unknown
Connection Identifier if the handle is not a CIS handle or does not
exist. If the CIS already has been established, the commands shall
return Command Disallowed.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2022-09-19 18:34:41 +02:00
Emil Gydesen
927df43092 Bluetooth: Audio: Fix bad BASE config check for broadcast sink
The broadcast sink did not allow codec config data to exist
in both the subgroup and in the individual BISes, which
not only doesn't make sense to not allow, but would
also cause interoperability issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-19 18:34:25 +02:00
Vinayak Kariappa Chettimada
d7b183d1da Bluetooth: Controller: Fix incorrect data type use
Fix incorrect data type int32_t local variable used for lazy
value which is uint16_t type.

Other minor code refactor done.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:27:38 +02:00
Vinayak Kariappa Chettimada
e8d1ed5d0d Bluetooth: Controller: Fix missing TICKER_SLOT_AGNOSTIC cond. compile
Fix missing conditional compile of structure members not
required with BT_TICKER_SLOT_AGNOSTIC is enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:18:12 +02:00
Vinayak Kariappa Chettimada
336013fe34 Bluetooth: Controller: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned
variable.
MISRA-C rule 7.2

Relates to commit b97db52de7 ("misra-c: Add 'U' to
unsigned variable assignments in subsys/").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
da2b1b615c Bluetooth: Controller: Fix incorrect use of stream instead of bis
Fix incorrect use of stream index (application selected list
of BIS stream) instead of BIS index when checking for
whether the received PDU is to be stored and to be
dispatched as ISO data to ULL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
be7a9ade7d Bluetooth: Controller: Fix missing terminate reason initialization
Fix missing Broadcast ISO Synchronized Receiver terminate
reason initialization that caused Sync Lost immediately on
a new Sync Establishment due to previous Sync terminate
reason not being reset.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
dfa3d959e0 Bluetooth: Controller: Initialize invalid ISO data packet
Initialize the invalid ISO data packet generated by LLL.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
75346a47f9 Bluetooth: Controller: Fix Rx chan idx when skipping BIS subevents
Fix missing implementation to correctly to use data channel
index for subevents when previous subevent of previous BIS
stream where skipped.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
3c92b25234 Bluetooth: Controller: Fix ISO broadcast to flush and ack for all BIS
Fix ISO broadcast implementation to flush stale ISO data for
all BIS streams and like wise generate acknowledgements for
all BIS streams that had its ISO data transmitted at its
reference anchor points.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
c8f5fbcf8d Bluetooth: Controller: Restrict maximum Pre-Transmissions to 1
Restrict the calculated possible Pre-Transmission subevents
count to a maximum of 1 so that the full ISO interval is
not fully occupied by the BIG event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
eff946a9ad Bluetooth: Controller: Fix leak in Num Completed Packets
Fix a leak in generation of Number of Completed Packets when
more than one handle has acknowledgements to be processed.

The loop exited for the current handle by dequeueing the
node tx element of the next handle leading to lost Number of
Completed Packets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:11:40 +02:00
Vinayak Kariappa Chettimada
f11fe69450 Bluetooth: Controller: Fix missing supervision/sync lost
When radio event prepare is cancelled due to preemption by
overlapping radio events, the extra done event processing
was missing and hence the use of accumulated prepares'
skip/latency count.
This caused the check for supervision timeout and sync
lost not be aware of the elapsed events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:02:28 +02:00
Vinayak Kariappa Chettimada
38905eb0ab Bluetooth: Controller: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned
variable.
MISRA-C rule 7.2

Relates to commit b97db52de7 ("misra-c: Add 'U' to
unsigned variable assignments in subsys/").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 18:02:28 +02:00
Vinayak Kariappa Chettimada
0feb34363f Bluetooth: Controller: Add missing margin to BIG ticks_anchor
Add the missing ticker resolution margin when calculating
the ticks_anchor to be used to get non-overlapping BIG
events.

Relates to commit fab4511164 ("Bluetooth: Controller: Fix
overlapping advertising events").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-19 17:55:56 +02:00
Pirun Lee
8e0f003112 Bluetooth: OTS - Object Write check parameter properly
Check sum of len and offset with properties.
Check offset with obj cur size.

Signed-off-by: Pirun Lee <pirun.lee@nordicsemi.no>
2022-09-19 10:57:10 +02:00
Jonas Woerner
6432e100aa Bluetooth: Host: Make adv error reporting more consistent
this changes adv_new_legacy to adv_get_legacy.
without this fix the function would return NULL if BT_EXT_ADV is enabled.

Signed-off-by: Jonas Woerner <jonas.woerner@online.de>
2022-09-16 10:53:31 +01:00
Pavel Vasilyev
24af6031e2 Bluetooth: Mesh: Use separate pool for relayed messages
Sharing the same pool for both, local and relayed messages has some
disadwantages. In a high-traffic environment the relayed messages may
occupy the whole pool without letting the node to send own messages,
neither to process segmented messages. The vice versa situation is
possible when local messages takes the whole pool so that the node is
not able to relay other messages. Another thing is that it doesn't let
to controll amount of local and relayed messages that the node can send
at once. Controlling the number of messages that the node can relay may
help to reduce the message latency.

This change adds separate net_buf_pool for the relayed messages that
helps to avoid problems described above.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-16 08:39:04 +00:00
Aleksander Wasaznik
a89d5edb92 Bluetooth: Shell: Remove a debug-print
I don't think it was intentional to leave this line.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-09-15 17:27:42 +01:00
Pavel Vasilyev
85e7818ff2 Bluetooth: Mesh: Don't process unprovisioned beacon without callback
If `struct bt_mesh_prov::unprovisioned_beacon` callback is not set,
don't process the beacon.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-14 14:37:54 +01:00
Herman Berget
372b7869df Bluetooth: Shell: Fix L2CAP ecred commands
The channel arrays must be null-terminated if it is less than 5 elements
long.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-09-14 09:38:39 +00:00
Erik Brockhoff
5951cd4c9b Bluetooth: controller: fixing missing reset of proc context greedy flag
For the encryption procedure exists a flag used to indicate that the
procedure expects all PDUs to be delivered to the procedure STM.
This flag was not cleared during creation of new procedure. This could
lead to unexpected PDUs being passed to local procedure STM

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-09-14 09:36:56 +00:00
Vinayak Kariappa Chettimada
8636766e57 Bluetooth: Controller: Fix compile error BT_CTLR_JIT_SCHEDULING enabled
Fix compile error when BT_CTLR_JIT_SCHEDULING is enabled but
BT_CTLR_ADV_EXT is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-14 09:36:28 +00:00
Pavel Vasilyev
cf953de484 Bluetooth: Mesh: Check pending_buf in bt_mesh_send_cb in friend.c
When friend entry is cleared by `friend_clear` after an adv buffer has
been sent to that friend in `friend_timeout`, another friend request
coming after this may reuse the same entry. It is possible that
`friend_timeout` will be scheduled twice: once by the friend request
and once by `buf_send_end` of the previously sent buffer.
In that case, the code will assert on line friend.c:1234. It is not
possible to cancel an adv buffer for the friendship that is to be
cleared, therefore, we need to ensure in correctness of the pending_buf
value in start and end callbacks.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-13 16:26:39 +00:00
Lingao Meng
fcbe88d598 Bluetooth: Mesh: Fix iv recovery unable clear replay list
When local node enter iv recovery procedure, should clear
replay list at first due to avoid possible wrong replay attack.

At present, `bt_mesh_rpl_clear` schedule a timer to clear rpl,
this would cause local node unable precess mesh message(IV Updated).

Also, in `bt_mesh_rpl_pending_store` also not clear rpl, which check
`BT_MESH_VALID` flag, always valid for iv recovery.

So, Add `rpl_clear_pending` work handler process rpl clear.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-09-13 16:24:46 +00:00
Szymon Czapracki
85639f78bd Bluetooth: audio: Fix error message in PACS
Change error code in PACS source/sink
write operation to Write Request Rejected.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2022-09-13 08:55:39 +00:00
Anders Storrø
97ed0061cb Bluetooth: Mesh: Remove experimental tag from CDB
The CDB module is a mandatory part of provisioning features in BTM, and
can not be regarded as experimental anymore.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-09-12 14:14:27 +00:00
Pavel Vasilyev
1357be36b0 Bluetooth: Mesh: Fix print of newly allocated node in CDB
Using the passed address is incorrect since the passed address can be
zero to find the lowest available address.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-12 10:52:50 +00:00
Pavel Vasilyev
33b9f3e361 Bluetooth: Mesh: Prevent CDB reusing address of deleted nodes
According to MshPRFv1.0.1, section 3.10.7, the Provisioner shall only
use reuse addresses of the deleted nodes after IV Index is updated.

This change prevents CDB reusing addresses of the deleted nodes until IV
Index is updated. Due to a high range of the unicast addresses, CDB only
stores the highest deleted address once a node is deleted. This creates
a limitation where allocating a node with the high primary unicast
address and then deleting it will make CDB skip big range of address
until next IV Index update.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-12 10:52:50 +00:00
Vinayak Kariappa Chettimada
0954185e81 Bluetooth: Controller: Fix periodic advertising re-enable assertion
When periodic advertising with chaining is re-enabled after
changing interval or just re-enabled then the chain PDUs
where not duplicated causing the LLL to assert detecting the
presence of aux pointer but no linked chain PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-09 16:29:28 -04:00
Michał Barnaś
dae8efa692 ztest: remove the obsolete NULL appended to zassert macros
This commit removes the usage of NULL parameter as message in
zassert_* macros after making it optional

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-09-09 07:05:38 -04:00
Szymon Czapracki
66e6572a0f Bluetooth: audio: shell: Add command to change contexts
Allow to change available audio contexts from shell

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2022-09-09 10:50:06 +00:00
Emil Gydesen
34d4501e8a Bluetooth: Shell: Add connect-name command
Add a new command, connect-name, which takes a string
as the single input and uses that to setup a scan filter
and connect to the first device that matches the name.

This command is thus basically shorthand for
bt scan-filter-set <name>
bt scan on
bt scan off
bt connect
bt scan-filter-clear-name

The idea of this command is to not only make it easier
find and connect to devices in a crowded environment,
but also to more easily connect to devices that changes
their advertised address.

The implementation is minimal as it uses existing
shell commands.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-09 10:10:52 +02:00
Hang Fan
fd4d18852d Bluetooth: Audio: Set transparent coding format for default ISO path
As per BAP_v1.0, Section 5.6.3.1:

If HCI is used when setting up their respective audio data paths,
and if the codec in use resides in the Bluetooth Host of the device
using the LE Setup ISO Data Path command, the Unicast Client and/or
Unicast Server shall:
* Write the LE Setup ISO Data Path command Codec_Configuration_Length
parameter with the value 0x00.
* Write octet 0 (Coding_Format) of the LE Setup ISO Data Path command
Codec_ID parameter with the value 0x03 (Transparent).

We can assume the codec in use resides in the Bluetooth Host default.

Signed-off-by: Hang Fan <fanhang@xiaomi.com>
2022-09-09 10:08:34 +02:00
Szymon Czapracki
35c0d5ef67 Bluetooth: audio: shell: Add command to set location
Allow to set audio locations from shell

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2022-09-09 10:07:49 +02:00
Ahmed Moheb
cb5ba5bea8 tests: bluetooth: host: Add mocks for buf.c
Add required mocks to be able to compile and test /bluetooth/host/buf.c

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-09 10:06:19 +02:00
Szymon Czapracki
ac6c35728a Bluetooth: Add IAS shell
This commit adds IAS functionality to the shell.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>

shell fixes
2022-09-09 10:05:46 +02:00
Szymon Czapracki
f4d23b6cd7 Bluetooth: Immediate Alert Client
Implement Immediate Alert Client
Move IAS into separate subdirectory

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>

general fixes
2022-09-09 10:05:46 +02:00
Vinayak Kariappa Chettimada
8191423950 Bluetooth: Controller: legacy: terminate condition to check role first
Refactor to revert back the terminate check condition to
check the connection role first.

Reverts legacy code changed in
commit 8b1d50b981 ("Bluetooth: controller: llcp: fix issue
 re. missing ack of terminate ind").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-08 15:12:22 +02:00
Vinayak Kariappa Chettimada
4da89756b3 Bluetooth: Controller: Dont prioritize ticker slot window that yield
Do not use lazy value to prioritize ticker with ticks slot
window that yield to other tickers. Primary channel PDUs
use ticks slow window to nudge themself after an
overlapping ticker within the ticks slot window, but such
ticker may be skipped to next interval. At the next
interval if they again overlap with other tickers then
lazy value shall not be used to prioritize but rather
continue to yield again. This is required to avoid BIG
events from being skipped.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-08 14:31:23 +02:00
Emil Gydesen
717b4fee56 Bluetooth: ISO: Remove TS size from SDU len check
The timestamp is not part of the SDU, and should
thus not be used to get the maximum SDU size.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-08 11:32:53 +00:00
Troels Nilsson
ba810303c5 Bluetooth: controller: Big-endian fix for aux_ptr offs and phy
pdu_adv_aux_ptr no longer uses a bitfield for offs and phy, so
we can properly adjust for BE

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-09-08 10:08:51 +00:00
Vinayak Kariappa Chettimada
b8a959ee47 Bluetooth: Controller: Fix BIG Create silently fail on RTN/SDU_interval
Fix BIG Create implementation from silently failing on
values of RTN and SDU_interval that lead to BIG events that
cannot be acheived when using sequential or interleaved
subevents by the Controller Implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-08 10:14:09 +02:00
Vinayak Kariappa Chettimada
b304eaa29b Bluetooth: Controller: Add Kconfig for experimental AD Data Chaining
Add a Kconfig for Advertising Data Chaining in Extended and
Periodic Advertising, permitting AD data lengths of upto
1650 bytes. The implementation is experimental and needs
further testing.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-08 10:12:56 +02:00
Vinayak Kariappa Chettimada
34154e3efe Bluetooth: Controller: Fix BT_CTLR_ADV_DATA_LEN_MAX Kconfig dependency
Fix BT_CTLR_ADV_DATA_LEN_MAX and other Kconfig dependencies,
and clean up the use of PDU_AC_LL_SIZE_MAX which is used to
allocate scratch packet to be atleast able to accommodate
the minimum 31 bytes AD data such that it is sufficient to
transmit and/or receive scan response PDUs when either
broadcaster or observer alone is supported.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-08 10:12:56 +02:00
Anders Storrø
bfb4e1bac4 Bluetooth: Mesh: Shell: Split out mdl shell feat
This commit splits out the model related commands from mesh shell to
separate shell modules. The purpose of this alteration is to make model
commands more flexible by letting the application itself define the
model instances.

- Move Health Client commands to separate shell module.
- Move Config Client commands to separate shell module.
- Remove Health Client instance from shell.c.
- Add Health Client instance to mesh_shell test application.
- Add util library for Mesh shell.
- Some refactoring of shell menu layout.
- Update Mesh shell documentation.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-09-07 15:02:58 +02:00
Anders Storrø
548f850192 Bluetooth: Mesh: Move shell.c to subfolder
Moves shell.c to shell subfolder. Done as a separate step to preserve
diff between previous and new revision of shell.c.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-09-07 15:02:58 +02:00
Timothy Keys
194cb8abab Bluetooth: Controller: Request any TX Power
Allow requesting any TX power in SDC via kconfig. This enables easily
setting higher TX values when using a FEM.

Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
2022-09-07 10:30:55 +02:00
Vinayak Kariappa Chettimada
61a44f1af2 Bluetooth: Controller: Use macros in num complt implementation
Use macros to encode the counting of number of completed
packets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-06 17:44:38 +02:00
Morten Priess
eb025d0497 Bluetooth: Controller: Fix ISO TX pool corruption and missing release
- Fix ISO TX data pool corruption due to multiple calls to
  tx_cmplt_get, without removing the nodes
- Added missing release of TX node link in case of ISOAL error

Signed-off-by: Morten Priess <mtpr@oticon.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-06 17:44:38 +02:00
Vinayak Kariappa Chettimada
4a74f97a9a Bluetooth: Controller: Fix ISO Tx PDU memory pool corruption
Fix ISO Tx PDU memory pool corruption due to duplicate ISO
Tx PDU buffers repeatedly released into the memory pool.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-06 17:44:38 +02:00
Vinayak Kariappa Chettimada
8eee8430d4 Bluetooth: Controller: Add implementation to flush Tx on BIG terminate
Add implementation to flush pending ISO Tx PDUs when BIG
events are terminated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-06 17:44:38 +02:00
Vinayak Kariappa Chettimada
73e0b415ce Bluetooth: Controller: Fix removal of BIG association with Periodic Adv
Move the removal of BIG context association with the
Periodic Advertising context to when the BIG streams are
release and BIG terminate message is generated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-06 17:44:38 +02:00
Anders Storrø
36e34fce41 Bluetooth: Mesh: Add CDB depend on to prov Kconfig
The current implementation of provisioning features is dependent on CDB
to compile, which is reflected poorly in the Kconfig options for mesh.

This commit alters the Kconfig options for provisioning to be dependent
on the CDB option to compile.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-09-06 12:35:48 +02:00
Vinayak Kariappa Chettimada
d5f94e632f Bluetooth: Controller: Support for multiple BIS sync selection
Added implementation to use the BIS array parameter and
selectively synchronize to subset of multiple Broadcast
Isochronous Streams in a Broadcast Isochronous Group.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-05 17:37:47 +02:00
Vinayak Kariappa Chettimada
4f02f05378 Bluetooth: Controller: BIG event timing reservations
Added implementation to calculate BIG event timing
reservations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-05 17:37:47 +02:00
Vinayak Kariappa Chettimada
1d4a5dd0ef Bluetooth: Controller: Fix calculation of BIS subevents
Fix calculation of BIS subevents that was missing num_bis
when calculating the PDU latency.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-05 17:37:47 +02:00
Vinayak Kariappa Chettimada
f738f494eb Bluetooth: Controller: Fix incorrect cond compile scheduling BIG
Fix incorrect conditional compile to disable Controller
advanced scheduling feature which is required for Broadcast
ISO implementation.

Regression in commit 6fe1299c33 ("Bluetooth: controller:
llcp: fix CI tests for new LLCP").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-05 17:37:12 +02:00
Vinayak Kariappa Chettimada
052136841e Bluetooth: Controller: Restrict max ISO Tx PDU size to ISO Tx MTU
In a Host plus Controller combined build for ISO feature
restrict the maximum ISO Tx PDU size to minimum of 251 bytes
and Host ISO Tx MTU. This will allow controller to use
reduced Tx time (subevent interval).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-05 17:37:01 +02:00
Gerard Marull-Paretas
79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Michal Narajowski
5c27067dcd Bluetooth: Mesh: Align Config Client API with Health Client API
This PR adds a `*_cli_*` infix to the Config Client API to match
the changes in Health Client. The old API is marked as deprecated.

Signed-off-by: Michal Narajowski <michal.narajowski@codecoup.pl>
2022-09-05 13:56:25 +03:00
Ahmed Moheb
c7d37d956e bluetooth: host: keys: Rename bt_keys_foreach() to bt_keys_foreach_type()
Use the name bt_keys_foreach_type() to be more descriptive.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Ahmed Moheb
f1884e5083 bluetooth: host: keys: Remove CONFIG_BT_MAX_CONN from key in use check
Eliminate key in use check dependency on (CONFIG_BT_MAX_CONN > 1).

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Ahmed Moheb
eea982e91e bluetooth: host: keys: Check if returned key matches keys pool item
bt_keys_find_addr() is used to find key by both ID and address.
Following checks must continue to compare ID and address as well.
Or, we can compare key references which is faster.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Ahmed Moheb
21882c5779 bluetooth: host: keys: Add assertions to check arguments
Check arguments passed to APIs with assertions.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Ahmed Moheb
ad5b154250 bluetooth: host: keys: Add APIs docs
Add API documentation to describe behavior, args and return value.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Emil Gydesen
68e17426ac Bluetooth: Audio: Support setting non-HCI data path for audio streams
Add support for setting a vendor specific data path using
the BAP API, instead of only support the HCI data path.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-02 14:16:49 +02:00
Emil Gydesen
1099030210 Bluetooth: ISO: Modify cc in bt_iso_chan_path
The CC/Codec Configuration in bt_iso_chan_path was
defined as an array of size 0. This meant that the
CC always had to be allocated right after the
bt_iso_chan_path struct.

This does not give a very flexible API, and also makes
it impossible for two bt_iso_chan_path to share the same
CC.

The API is modified so that the CC is simply a pointer
to a an array now.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-02 14:16:49 +02:00
Emil Gydesen
e2055e158c Bluetooth: Audio: Fix error check for bt_gatt_subscribe error log
We shouldn't log an error if we are already subscribed to the device.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-02 10:59:23 +00:00
Herman Berget
e65fdd4c5e Bluetooth: Host: Clean up buffer user data in case of error
`bt_l2cap_chan_send_cb()` overwrote the buffer user data for internal
use. In the case where sending fails, this would be visible for the
caller. If the caller relied on the buffer user data to be unchanged,
this could cause unexpected behavior.

L2CAP tx metadata was also not freed in the error case.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-09-01 14:58:08 +00:00
Vinayak Kariappa Chettimada
b294b6e648 Bluetooth: Controller: Fix prepare pipeline preempt timeout stop
Fix prepare pipeline preempt timeout stop from stopping a
a prevously started timeout for the next in pipeline event.

The preempt timeout started prior for the current event that
has its prepare that is invoked is to be not explicitly
stopped. If there is a next prepare event in pipeline, then
the prior preempt timeout if started will be stopped before
starting the new preempt timeout. Refer to implementation in
preempt_ticker_start().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-01 13:18:11 +02:00
Vinayak Kariappa Chettimada
ddf04997a5 Bluetooth: Controller: Add abort fairness in overlapping Periodic Sync
Add implementation in Periodic Sync LLL abort to use near
fair scheduling to ensure overlapping multiple Periodic
Sync set each get to use the radio and not lead to Sync
Loss.

The implementation is used when overlap in radio event
happens in unreserved time space of the event. An abort
count is maintain in each Periodic Sync instance and is
used to decide whether the current event or the next
event is to be aborted when they overlap.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-01 13:18:11 +02:00
Vinayak Kariappa Chettimada
1a1f347ad3 Bluetooth: Controller: Add Kconfig for minimal time reservation
Add Kconfig to use minimal time reservation for auxiliary
and sync PDU reception. A peer device could be scheduling
multiple advertising sets in a short duration with small
PDUs hence using the minimal time reservation would avoid
skipping closely scheduled reception of multiple auxiliary
PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-01 13:18:11 +02:00
Adam Augustyn
6986185c81 Bluetooth: Host: Clear random address field in bt_dev in bt_disable()
This commit clears cached random address in bt_dev when calling
bt_disable(). This change makes future calls of set_random_address()
function possible with previously used address value, after BLE stack
re-initialization. Without this change no HCI command was sent, see this
condition in set_random_address():

/* Do nothing if we already have the right address */
if (!bt_addr_cmp(addr, &bt_dev.random_addr.a)) {
	return 0;
}

Signed-off-by: Adam Augustyn <adam.augustyn@hidglobal.com>
2022-09-01 10:36:40 +02:00
Jonathan Rico
f10db5e5cb Bluetooth: smp: Fix SC with fixed passkey
passkey confirm should not be called when secure connections are enforced.

Fixes #49599

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-01 10:27:34 +02:00
Pavel Vasilyev
52b423e18c Bluetooth: Mesh: Replace segack tx delay with Kconfig options
Additional uncontrolled delay for transmitting segack affects throughput
of the segmented messages. Though the best throughput can be achieved
with the smallest allowed values, move them to Kconfig option so that
the segack delay can be controlled by a user.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-01 10:27:27 +02:00
Morten Priess
da402c0830 Bluetooth: controller: Implements ISO Test Mode HCI commands
Implements the flollowing HCI commands:
- HCI_LE_ISO_Transmit_Test
- HCI_LE_ISO_Receive_Test
- HCI_LE_ISO_Read_Test_Counters
- HCI_LE_ISO_Test_End

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-08-31 21:50:13 +00:00
Adam Wojasinski
47db797236 Bluetooth: controller: Replace deprecated nrfx API
This commit replaces API that became deprecated with the release
of nrfx2.9 - see CHANGELOG in zephyrproject-rtos:hal_nordic repository

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2022-08-31 10:43:14 +02:00
Pirun Lee
c4bd693d9a Bluetooth: OTS - Client APIs add Object Write sub-procedure
OTS client: Add object write function.
Also add write object callback.

Signed-off-by: Pirun Lee <pirun.lee@nordicsemi.no>
2022-08-31 10:39:33 +02:00
Vinayak Kariappa Chettimada
94710e0f6d Bluetooth: Controller: Kconfig to permit periodic sync event skip
When AUX_ADV_IND or AUX_CHAIN_IND auxiliary channel PDU scan
radio event overlaps Periodic Sync radio event in unreserved
time space, let the Periodic Sync radio event be aborted so
that the auxiliary channel PDU can be received to generate
Extended Advertising Reports. Added a new Kconfig to enable
this.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-30 10:30:16 +02:00
Emil Gydesen
32b2a3e218 Bluetooth: Audio: Update audio shell with location in cmd_init
Set the location in the init command. Also updates the
available context to the CONTEXT macro value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-30 10:27:00 +02:00
Hang Fan
5b8b3a74d6 Bluetooth: audio: mcc: add NULL check for mcs instance
Add NULL check for mcs instance to avoid access violation crash.

Signed-off-by: Hang Fan <fanhang@xiaomi.com>
2022-08-30 10:25:36 +02:00
Herman Berget
096fc3b826 Bluetooth: Increase RX thread stack size
Normal usage for Bluetooth applications are getting close to or
already overflowing the default BT RX stack size of 1024.

For example:
 - Discovery using the fixed ATT channel used 984 bytes.
 - Discovery using an enhanced ATT channel used 1048 bytes,
   which would lead to stack overflow using the default BT RX thread
   stack size.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-26 12:52:22 +02:00
Jakob Krantz
605d8c85d8 Bluetooth: Host: Fix invalid sync term callback params
When using periodic advertising list and receiving
hci_le_per_adv_sync_established event from controller with
an error code the bt_le_per_adv_sync_term_info would be
incorrectly populated with le_addr and sid. This is because
the current pending advertising sync object is not populated
with any le_addr and sid from bt_le_per_adv_sync_create as
those are not used when option
BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST is set.

Instead the bt_le_per_adv_sync_term_info shall be populated
with the le_addr and sid coming in the event from controller.

Signed-off-by: Jakob Krantz <jakob.krantz@u-blox.com>
2022-08-26 12:51:05 +02:00
Erik Brockhoff
7719bc6785 Bluetooth: controller: llcp: fix unhandled rsp in periph phy upd proc
Re. peripheral phy update procedure: UNKNOWN_RSP from central was not
handled, leading to stall of procedure and subsequent procedure timeout

Proper handle and unit test for case added.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-08-26 11:56:33 +02:00
Emil Gydesen
70dfbb6747 Bluetooth: Audio: Add missing NULL checks when looking up audio_iso streams
Multiple places we assumed that we could simply just do
sink_stream->iso == chan without checking if sink_stream
was NULL.

This commit fixes that by adding proper NULL checks for that,
as well as additional checks before defaulting to the
source_stream.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-26 11:56:15 +02:00
Stephanos Ioannidis
074b7f4ecd Bluetooth: Define global Bluetooth address constants
The Bluetooth address constants (BT_ADDR[_LE]_ANY, BT_ADDR[_LE]_NONE)
are currently defined as the address of the local anonymous structs
that are initialised to the corresponding address values, and assigning
them to a variable whose scope is greater than that of a function may
end up creating dangling pointers (for instance, as done in the
`bt_conn_get_info` function).

This commit defines the Bluetooth address constants as global constant
variables that are placed in the read-only data section, and modifies
the Bluetooth address constant macros to use the address of these
variables instead.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-25 12:18:09 +02:00
Stephanos Ioannidis
13885bd6d5 Bluetooth: Host: Monitor: Make addr param const in bt_monitor_new_index
This commit adds the `const` qualifier to the `addr` parameter of the
`bt_monitor_new_index` function because this parameter is and should
never be modified within this function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-25 12:18:09 +02:00
Stephanos Ioannidis
97f9a16ed1 Bluetooth: Host: GATT: Make addr param const in find_sc_cfg
This commit adds the `const` qualifier to the `addr` parameter of the
`find_sc_cfg` function because this parameter is and should never be
modified within this function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-25 12:18:09 +02:00
Vinayak Kariappa Chettimada
689bf9b015 Bluetooth: Controller: Fix uninitialized adv mode in scan rsp PDU
Fix uninitialized adv mode value in the scan response PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-24 12:41:21 +02:00
Vinayak Kariappa Chettimada
4938d2a0d4 Bluetooth: Controller: Fix regression in overlapping 1M and Coded Scan
Fix regression in overlapping 1M and Coded PHY scan window
by considering rounding margins when checking for same
interval and same window durations.

Relates to commit c14bde45b6 ("Bluetooth: Controller: Fix
overlapping 1M and Coded PHY scannning").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-24 10:04:20 +02:00
Emil Gydesen
d62223e930 Bluetooth: Audio: Fix unicast_client avail ctx dir check
The unicast_client_pacs_avail_ctx_notify_cb had a direction
check that was a leftover copy from the location notification.

However the context notification is always for both sink and
source, and thus does not need any direction checks (in fact
the dir variable was unused).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-23 16:24:24 +02:00
Mariusz Skamra
a120af8f33 Bluetooth: audio: ascs: Fix missing metadata reset before update
The old metadata shall be reset (simply set the couynt to zero) before
reuse or update.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-23 16:22:11 +02:00
Mariusz Skamra
c57ba529dc Bluetooth: audio: ascs: Remove invalid check
This fixes invalid check, which is redundant in fact as the length
is already checked in ascs_parse_metadata function.
The check be test 'greater than' only, as 'equal' condition is valid.
Moreover this fixes return value from ascs_verify_metadata function.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-23 16:22:11 +02:00
Anders Storrø
5f8168d5dd Bluetooth: Mesh: Health_cli: Fix fault test rsp
Swaps response scheme for Fault_test command so that it
aligns with description of the documentation.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-08-23 16:21:54 +02:00
Vinayak Kariappa Chettimada
ce0f65e768 Bluetooth: Controller: Enable back-to-back PDU chaining
When AD data length of greater than 191 bytes support is
enabled then default to using the back-to-back PDU chaining
feature in the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 16:21:00 +02:00
Vinayak Kariappa Chettimada
f736498b2a Bluetooth: Controller: Fix parent PDU's aux offset in aux ptr field
Fix Extended Advertising and Periodic Advertising's parent
PDU's aux ptr field to contain correct aux offset value to
its chain PDU.

Uninitialized pointer reference to aux ptr in the parent PDU
was used before the pointer reference was returned by the
function adding the aux ptr fields in the parent PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 16:21:00 +02:00
Vinayak Kariappa Chettimada
a08e8ef88d Bluetooth: Controller: Use local variable for current PDU's flags
Use local variable to update current PDU's Common Extended
Header Format flags instead of updating it directly in the
PDU buffer. This is required to be able to non-destructively
be able to manipulate the PDU's header flags and contents
many time before a final commit of the updated PDU.

In order to calculate overflowed AD data length, PDU is
manipulated couple of times to determine the overflow length
and next to be able to add aux ptr field when chain PDU is
appended.

The changes are now consistent with how Periodic Advertising
PDU's Common Extended Header Format is manipulated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 16:21:00 +02:00
Vinayak Kariappa Chettimada
5ed463008b Bluetooth: Controller: Fix regression in adding ADI in scan rsp PDU
Fix regression in adding ADI in scan response PDU introduced
in implementation adding support for AD data fragment
operation.

Setting scan response data with ADI failed with too long
data error. This was caused by a bug in calculating the
offset to the overflow length returned back by the call
to set_clear function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 14:50:17 +02:00
Anders Storrø
3dccd319b6 Bluetooth: Mesh: Cfg_cli: Fix appkey get rsp
Adds missing feature so that the config client is able to receive
odd number of app index entries.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-08-23 10:20:34 +00:00
Pavel Vasilyev
1659ac4392 Bluetooth: Mesh: Use mesh settings API only if settings are enabled
Don't call bt_mesh_settings_store_pending if CONFIG_BT_SETTINGS is not
enabled.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-08-22 16:38:02 +00:00
Piotr Pryga
2b57c0716b Bluetooth: Remove default n from common Kconfig
The commit is a minor refactor of the common Host and Controller
Kconfig. There were used "default n" that should be avoided.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Piotr Pryga
939578e79d Bluetooth: hci: df: Fix unnecessary IQ sample storage
In case Controller reports to Host insufficient resources to store IQ
samples, according to BT 5.3 Core spec. Vol 4, Part E, sections
7.7.65.21 and 7.7.65.22:
1) packet_status shall be set to BT_HCI_LE_CTE_INSUFFICIENT_RESOURCES
2) sample_count shall be set to zero.
That means there should be no IQ samples stored in IQ report.

HCI implementation stored single IQ sample with value BT_HCI_LE_CTE-
_REPORT_NO_VALID_SAMPLE.

The commit fixes that. No additional memory is added to event buffer
and no IQ sample is stored if sample_count is zero.

Also there is added code that handles situation where ULL provides
IQ report with packet_status indicating valid IQ samples report
but sample_count is zero. In such case Host event stores single IQ
sample with value BT_HCI_LE_CTE_REPORT_NO_VALID_SAMPLE.
In case of vendor specific counter part of the event the value is
BT_HCI_VS_LE_CTE_REPORT_NO_VALID_SAMPLE.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Piotr Pryga
56262f8207 Bluetooth: Host: Add common handling of VS IQ report
Bluetooth Controller has a vendor specific extensions that allows it
to send IQ report events with IQ samples that are 8 bits or 16 bits
signed integer. To use that functionality, there is added common
handler of vendor specific events.

Vendor specific events handling is prioritized to be done by user
provided event handler. If that is not available, then Host generic
implementation enters.

Added vendor specific events that are handled by common Host code
are BT_HCI_EVT_VS_LE_CONNECTIONLESS_IQ_REPORT and BT_HCI_EVT_VS_LE-
_CONNECTION_IQ_REPORT.

The only difference between regular IQ report events is size of
IQ samples, hence implementation of IQ report events is changed to
use the same user callback. To avoid differentiation of user callbacks
new member sample_type was added to bt_df_per_adv_sync_iq_samples-
_report. Also sample member is changed to be a union, to allow easy
access to IQ samples without type casting.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Piotr Pryga
d8d8ef74ce Bluetooth: hci: Add VS IQ samples report using 16 bit sign integer sampl
Add vendor specific IQ samples report that holds IQ data in 16 bits
signed integer format. Thanks to that we preserve complete accuracy of
IQ samples provided by Nordic Direction Finding Extension in Radio
peripheral. That helps to maintain better accuracy of evaluated
angles with use of reported IQ samples.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Jonathan Rico
43e1ae1452 Bluetooth: host: gatt: Properly check subscription status
We had two bugs:

- we didn't check the subscription, only the fact that the passed chrc can
be subscribed to.

- that check only worked if we passed the chrc descriptor handle, not its
value handle.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-19 14:09:43 +02:00
Jonathan Rico
fae5dd3643 Bluetooth: gatt: allow disabling subscription enforcement
This introduces a new option that allows the user to disable the
subscription checking when notifying or indicating.

Some users might have use-cases where they would like to send notifications
or indications without the peer having to go through the subscription
process, as that is allowed by the Bluetooth specification.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-19 12:14:21 +02:00
Mariusz Skamra
9c7ef8ea06 Bluetooth: audio: tbs: Fix List_Item_Length value in CCL
This fixes setting invalid List_Item_Length in Current Calls List.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:09:46 +02:00
Mariusz Skamra
3253ad2ab8 Bluetooth: audio: tbs: Make bt_tbs_client_call to contain URI pointer
To avoid compilation issues when including tbs.h header file when
CONFIG_BT_TBS_MAX_URI_LENGTH is not set, just pass the URI pointer
instead of an array in bt_tbs_client_call structure.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:09:46 +02:00
Mariusz Skamra
1b7aafc424 Bluetooth: audio: tbs: Factor out bearer_list_current_calls function
To avoid code duplicates, this factors out common code to separate
function.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:09:46 +02:00
Aleksandr Khromykh
5a0aa47383 Bluetooth: Mesh: fix adding in sublist the same addresses
If LPN loses Subscription List Add Confirmation it repeats
Subscription List Add frame. Friend doesn't check both
transaction number and presence addresses in the list.
That causes situation when Friend fills the same address
full list.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-08-19 12:08:27 +02:00
Aleksandr Khromykh
3f88dcaaff Bluetooth: Mesh: add more latency for scanner in lpn
With extended advertiser a precision of transmission becomes high.
The first frame is emitted quite quickly. The scanner latency
config option to enable scanner a bit in advance is not sufficient.
Sometimes replays on Friend Poll are lost.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-08-19 12:08:27 +02:00
Mariusz Skamra
ea5f59f896 Bluetooth: shell: Add LE Audio related advertisement data
This adds LE Audio related data to the shell advertisement data.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:07:31 +02:00
Mariusz Skamra
6219c12035 Bluetooth: csis: Expose bt_csis_generate_rsi function
The function will be used to update the RSI value. The returned value
can be later used in advertisement data for set identification. This
removes the need of specific bt_csis_advertise function so that the user
can call the API to generate new RSI once needed (e.g. on RPA change).
This allows the user to manage the advertisement data to fit it's needs.

< HCI Command: LE Set Extended Advertising Enable (0x08|0x0039) plen 6
        Extended advertising: Disabled (0x00)
        Number of sets: 1 (0x01)
        Entry 0
          Handle: 0x00
          Duration: 0 ms (0x00)
          Max ext adv events: 0
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Advertising Enable (0x08|0x0039) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Extended Advertising Data (0x08|0x0037) plen 33
        Handle: 0x00
        Operation: Complete extended advertising data (0x03)
        Fragment preference: Minimize fragmentation (0x01)
        Data length: 0x1d
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        Unknown EIR field 0x2e: 16e61d64dc45
        Name (complete): audio test shell
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Advertising Data (0x08|0x0037) ncmd 1
	Status: Success (0x00)
< HCI Command: LE Set Advertising Set Random Address (0x08|0x0035) plen 7
        Advertising handle: 0x00
        Advertising random address: 4E:21:29:F8:94:93 (Resolvable)
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Advertising Set Random Address (0x08|0x0035) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Extended Advertising Enable (0x08|0x0039) plen 6
        Extended advertising: Enabled (0x01)
        Number of sets: 1 (0x01)
        Entry 0
          Handle: 0x00
          Duration: 0 ms (0x00)
          Max ext adv events: 0
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Advertising Enable (0x08|0x0039) ncmd 1
        Status: Success (0x00)

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:07:31 +02:00
Herman Berget
62ff17df21 Bluetooth: Host: Get first packet matching channel
When sending an ATT packet, do not just try to send the first packet in
the queue, but find the first one that can be sent using the channel.
This makes sure that eg. packets that shall be sent on an unenhanced ATT
channel are not blocked by packets that shall be sent on enhanced ATT
channels.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-19 11:59:52 +02:00
Herman Berget
62218910a0 Bluetooth: Host: Move all sending from tx_queue to process_queue
Similar functionality was implemented in two places.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-19 11:59:52 +02:00
Herman Berget
cc81529d58 Bluetooth: Host: Fix bt_eatt_connect returning -EINVAL if conn is NULL
bt_eatt_connect was documented to return -EINVAL if conn is NULL, but
this was not the case. Instead it lead to undefined behavior.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-19 11:59:52 +02:00
Herman Berget
ccaa7b291e Bluetooth: Host: Check if channel option is valid
Disallow trying to send requests or notifications on only EATT channels
if no EATT channels are connected or the link is not encrypted. In these
cases the operation will always fail, so it should not be queued.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-19 11:59:52 +02:00
Herman Berget
7f740cbd46 Bluetooth: Shell: Use chan_opt BT_ATT_CHAN_ANY
The chan_opt field of GATT parameter structs must be set.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-19 11:59:52 +02:00
Herman Berget
741fe73f74 Bluetooth: Host: Add option to use GATT over EATT
A channel option field has been added to the bt_gatt_*_params structs.
This allows the application to choose wether Unenhanced ATT, Enhanced
ATT, or Any ATT channel shall be used for the
request/command/indication/notification.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-19 11:59:52 +02:00
Gerard Marull-Paretas
e0125d04af devices: constify statically initialized device pointers
It is frequent to find variable definitions like this:

```c
static const struct device *dev = DEVICE_DT_GET(...)
```

That is, module level variables that are statically initialized with a
device reference. Such value is, in most cases, never changed meaning
the variable can also be declared as const (immutable). This patch
constifies all such cases.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-19 11:51:26 +02:00
Gerard Marull-Paretas
0f2003eee6 bluetooth: host: initialize devices as compile time
Initialize monitor UART device at compile time so that device pointer
can be constified.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-19 11:51:26 +02:00
Szymon Czapracki
aa7533380c Bluetooth: audio: Add missing 'or' in service declaration
Fix missing or symbol in service declaration

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
2022-08-18 21:40:23 +00:00
Aleksander Wasaznik
cdfe085cfb Bluetooth: Host: Add CONFIG_BT_PRIVACY_RANDOMIZE_IR
This new option prevents the Host from using Controller-provided
identity roots. This potentially increases privacy.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-08-18 13:04:35 +02:00
Aleksander Wasaznik
058dc7c0bc Bluetooth: Host: Refactor bt_setup_public_id_addr
Move the flagging of `BT_DEV_STORE_ID` to a separate if-statement.

This clarifies the meaning of the code, and paves way for wrapping the
if-statement with the call to `bt_smp_irk_get` in another conditional.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-08-18 13:04:35 +02:00
Emil Gydesen
3dbc13c4ae Bluetooth: Audio: Fix issue with registering VOCS callbacks
When registering VOCS callbacks via bt_vcs_client_cb_register
it could fail if the application did not reset the
vocs_cb.discover as that is set internally.

This commit adds a simple check to also allow the
vocs_cb.discover to be the callback VCS expect/want it to be.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-18 12:50:19 +02:00
Emil Gydesen
2b0f98b4fc Bluetooth: Audio: Fix issue with registering AICS callbacks
When registering AICS callbacks via bt_vcs_client_cb_register
or bt_micp_mic_ctlr_cb_register it could fail if the application
did not reset the aics_cb.discover as that is set internally.

This commit adds a simple check to also allow the
aics_cb.discover to be the callback they expect/want it to be.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-18 12:50:19 +02:00
Emil Gydesen
2647bc0cf5 Bluetooth: Audio: Fix NULL pointer ref in bt_csis_lock
bt_csis_lock would call write_set_lock with `attr` set to
NULL, which was dereferenced to get the bt_csis instance.

This commit modified the functions such that we instead have
common function to handle changes to the lock value, called
from either the GATT write callback function, or the
bt_csis_lock, so that we have a clearer separation of what
the individual functions do.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-18 12:48:51 +02:00
Mariusz Skamra
541d946d10 Bluetooth: audio: Add HAS client support for preset switching
This adds client support for switching the active preset along with bsim
tests implementation.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-18 12:46:27 +02:00
Emil Gydesen
b8cdf9d0a6 Bluetooth: Audio: Fix issue with reset QoS on state change
The unicast client would simply reset all existing ISO QoS
when there was a state change to the QoS state (and only
update the stream QoS).

This caused issue with some ISO check later, as well
as wrongly resetting the data path too.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-18 12:33:44 +02:00
Emil Gydesen
9e9ea2146c Bluetooth: ISO: Add check for maximum ISO SDU size
Verify that the HCI ISO data packet is smaller than
the maximum SDU size we support, based on the group
settings.

Since we do not yet support fragmentation we also
verify that the data length is smaller than the
HCI ISO buffer size.

For the ISO peripheral is it not possible to know
the SDU, and we are forced to not send any value larger
than the PDU size.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-18 12:33:44 +02:00
Emil Gydesen
0277682a33 Bluetooth: ISO: Add check for pending ISO connections
Per the HCI spec it is not possible to send the
HCI_LE_Create_CIS command while an outstanding request
is pending. To avoid failing the command we can
check and verify if any ISO connections are in the
pending state.

Since multiple ISO channels can be connected
in a single request, the solution implemented was
to iterate over all ISO connections and see if there was
any unicast ISO channels in the connecting state.

It also checks for the encryption pending state, as
we should not start the encryption procedure if we know
that the connect ISO command cannot be completed afterwards.

This adds a new return value to bt_iso_chan_connect,
and decided to properly document the return values the
function can return.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-18 12:30:58 +02:00
Ahmed Moheb
807c715cec bluetooth: host: buf: Remove redundant 'evt_discardable_count' check
CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT is defined by default and the
value ranges from 1 to 255.
So, checking if this parameter is defined seems to be redundant

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-08-17 22:36:45 +03:00
Anders Storrø
348d977124 Bluetooth: Mesh: Health_cli: Fix async cmd rsp
Swaps response scheme for Fault_get & Fault_clear command so that it
aligns with description of the documentation.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-08-17 15:52:01 +00:00
Hang Fan
9d06245fe7 Bluetooth: audio: check MCS characteristic properties before subscribe
MCC need to check characteristic properties before subscribe as not all
MCS characteristics support notify.

Signed-off-by: Hang Fan <fanhang@xiaomi.com>
2022-08-17 17:05:23 +02:00
Mariusz Skamra
0175e23695 Bluetooth: shell: Fix Unicast Client Source endpoint pool size
Fix using proper Kconfig value for defining endpoint pool size.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-17 12:10:51 +02:00
Mariusz Skamra
bacc4953e9 Bluetooth: audio: Reject QoS if CIS is already is use in this direction
As per ASCS_v1.0
If a client requests a Config QoS operation for an ASE that would
result in more than one (Sink/Source) ASE having identical CIG_ID
and CIS_ID parameter values for that client, the server shall not
accept the Config QoS operation for that ASE.
The server shall send a notification of the ASE Control Point
characteristic to the client, the server shall set the Response_Code
value for that ASE to 0x09 (Invalid Parameter Value), and the server
shall set the Reason value for that ASE to 0x0A
(Invalid_ASE_CIS_Mapping).

Fixes: ASCS/SR/SPE/BI-{15,16}-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-17 12:10:51 +02:00
Mariusz Skamra
8b06f7a5e1 Bluetooth: shell: Add multi-cis support
Add support for multiple CIS.

Relates: ASCS/SR/SPE/BI-{15,16}-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-17 12:10:51 +02:00
Ivan Herrera Olivares
71b4dcf269 Bluetooth: L2CAP: Add check to see if device is not disconnected
Currently, if a bluetooth peripheral sends a connection parameter update
request to a Zephyr central while the central is in the process of
disconnecting and has sent a connection terminate command in the same
connection interval, the central will try to reply, resulting in an
error being printed in the console.

This commit adds a check in le_conn_param_update_req that catches this
state before the central considers this request, preventing the unneeded
error being printed.

Fixes #48813

Signed-off-by: Ivan Herrera Olivares <ivan.herreraolivares@uantwerpen.be>
2022-08-17 08:06:19 +00:00
Carles Cufi
26f5897819 Bluetooth: Mark Extended Adv as stable
Extended Advertising is no longer experimental, it has been now
extensively tested and is fully qualifiable and usable in production.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-16 18:10:59 +02:00
Mariusz Skamra
e0d36beb72 Bluetooth: audio: Add security requirements check
The LE Audio related profiles define specific security requirements that
client have to met to gain access to related characteristics. This
introduces internal wrapper API for GATT characteristics and CCC
descriptors to ensure the security.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-16 12:19:43 +02:00
Mariusz Skamra
2241efedfb Bluetooth: audio: Keep ASE pointer in bt_audio_ep
This makes the server endpoint to store the ASE pointer instead of
handle. This way, there will be no need to "mock" attribute when
notification is sent.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-16 12:19:43 +02:00
Mariusz Skamra
cc86b9213c Bluetooth: conn: Extend bt_conn_info with security information
This extends the bt_conn_info with security information. This is needed
by LE Audio profiles to check if security requirements are met.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-16 12:19:43 +02:00
Mariusz Skamra
cc37266742 Bluetooth: conn: Add const modifier to conn
The bt_conn_get_security and bt_conn_enc_key_size do not
modify the conn thus the parameter can be guarded with const modifier.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-16 12:19:43 +02:00
Mariusz Skamra
12010fafe6 Bluetooth: keys: Extend keys flags with OOB flag
Adds flag indicating the pairing that was completed using OOB method.
The flag is needed for checking 128bit entropy pairing required by LE
Audio services.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-16 12:19:43 +02:00
Mariusz Skamra
ffea5b6b54 Bluetooth: audio: ascs: Fix missing negative sign parameter
This fixes missing negative sign passed to ascs_cp_rsp_add_errno
that takes negative error argument.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-16 10:07:54 +00:00
Mariusz Skamra
778ed28ee2 Bluetooth: audio: ascs: Reject peer Release operation in Idle state
This fixes crash that happened when client initiated Release operation
on ASE in Idle state. In such case the operation shall be rejected with
Invalid ASE State Machine Response_Code.

Fixes: ASCS/SR/SPE/BI-10-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-16 10:07:54 +00:00
Andries Kruithof
6fe1299c33 Bluetooth: controller: llcp: fix CI tests for new LLCP
Setting the new LLCP as default exposed errors in CI tests, which
are fixed here
Note that advanced scheduling needs to be disabled. Work is in
progress for implementing this for the new LLCP

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-08-14 21:59:09 +02:00
Andries Kruithof
e1c2c36f56 Bluetooth: controller: llcp: set refactored as default
Set the new refactored LLCP the default

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-08-14 21:59:09 +02:00
Jonathan Rico
5b0ff0b35b Bluetooth: gatt: support having the CCCD in any location
Per spec, the CCCD doesn't necessarily have to be located immediately after
the characteristic value. This commit fixes that assumption when checking
for subscriptions.

Fixes #48880.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-14 17:14:41 +02:00
Matthias Hauser
c5155b2dbf Bluetooth: writing appearance to settings
avoid saving appearance in flash if it did not change

Signed-off-by: Matthias Hauser <Matthias.Hauser@we-online.de>
2022-08-12 14:17:44 +01:00
Matthias Hauser
c0e39711ac Bluetooth: bugfix in applying appearance from settings
The len parameter is the settings name length 'appearance'

Signed-off-by: Matthias Hauser <Matthias.Hauser@we-online.de>
2022-08-12 11:31:42 +02:00
Marek Pieta
f5560279f5 bluetooth: host: Increase long workqueue stack size
Change increases long workqueue stack size to prevent stack
overflows while processing GATT database hash.
CONFIG_BT_HCI_ECC_STACK_SIZE is removed, because the configured
stack was removed.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2022-08-11 17:01:08 +02:00
Marek Pieta
3a1d9735fc bluetooth: gatt: Fix value returned by db_hash_commit
Change fixes value returned by db_hash_commit. Returning positive
value leads to settings load failure.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2022-08-11 12:19:52 +02:00
Marek Pieta
d5a453efaf bluetooth: smp: Add authentication callbacks per connection
Change introduces authentication callbacks used only for specified
BLE connection. The feature can be used by devices that require
reporting specific bonding capabilities only when pairing using
vendor-specific procedures.

If per-connection authentication callbacks are defined for given
connection, they are used instead of global authentication
callbacks. SMP latches authentication callbacks during the first
access to prevent updating the callbacks while pairing.

Fixes: #38336

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2022-08-10 12:49:30 +02:00
Mariusz Skamra
f836dabb46 Bluetooth: audio: Handle Receiver Stop Ready on non-connected stream
This fixes state transition to QoS Configured state triggered by
client-initiated Receiver Stop Ready operation on ASE that has no ISO
attached.

Fixes: ASCS/SR/ACP/BV-12-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-09 12:30:10 +02:00
Gerard Marull-Paretas
a7c3e7e84a doxygen: remove redundant usages of def
The def command Indicates that a comment block contains documentation
for a #define macro. This is useful if the comment block documents a
macro not adjacent to it, e.g.

```c
/**
 * @def MAX(x,y)
 * @brief Computes the maximum of @a x and @a y.
 */
 #ifdef XXX
 #define MAX(x,y) ...
 #endif
```

However, it is not necessary if the comment is adjacent to the
definition, e.g.

```c
/**
 * @brief Computes the maximum of @a x and @a y.
 */
 #define MAX(x,y) ...
```

This patch removes all unnecessary def entries in-tree.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-09 12:29:28 +02:00
Mariusz Skamra
a618143b46 Bluetooth: audio: Add unavailable audio context warning
This logs warning if the stream is rejected due to unavailable
audio context.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-08 15:03:55 +02:00
Mariusz Skamra
17d7bd8219 Bluetooth: audio: Fix missing audio direction check
This fixes missing `dir` parameter check when setting the available
contexts value.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-08 15:03:55 +02:00
Mariusz Skamra
8ae28b796e Bluetooth: shell: Fix available contexts value
This fixes the available audio contexts that shall be a subset of
supported audio contexts.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-08 15:03:55 +02:00
Aleksandr Khromykh
56d67dfac8 Bluetooth: Mesh: don't send Friend Clear if Friend is lost
If LPN lost Friend node (all Poll attempts didn't succeed)
no reason to send Friend Clear to the Friend node.
This makes LPN powersupply  inefficient usage.
During Friend Clear sending LPN rejects any frame from
primary subnetwork.
Specificastion doesn't mandate that LPN would send Friend Clear
if polling didn't succeed.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-08-08 10:52:23 +02:00
Joakim Andersson
83d5402fe8 Bluetooth: host: Fix SMP local keys check when starting encryption
Fix SMP check of existing local keys when attempting to start security
with required security mode 1 level 4. The logic for checking the
conditions was wrong, leading to a situation where encryption would be
attempted to be started by the central instead of initiating a new
pairing procedure. This would fail when the connection was encrypted and
the connection would be disconnected.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-08-05 15:05:56 +02:00
Mariusz Skamra
42e372fc3e Bluetooth: audio: ascs: Fix sending invalid ATT_ERROR_RSP error code
This fixes sending invalid ATT Request Not Supported error code as a
response to Control Point write request.
ATT Request Not Supported error code is used to inform that
"ATT Server does not support the request received from the client",
so it should not be sent in this case.
If the requested opcode is unsupported, ASCS mandates to send ATT
Notification from Control Point with Unsupported opcode Response_Code
only. If the request received from the client is properly formatted,
ATT Write Response can be sent to complete the ATT transaction.

Fixes: ASCS/SR/SPE/BI-01-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-05 15:05:17 +02:00
Mariusz Skamra
a0ea971e9f Bluetooth: audio: ascs: Use BT_WARN to log peer invalid behavior
BT_ERR() should really be reserved for local errors only,
thus BT_WARN() is the right choice whenever a remote peer
sends something invalid that we cleanly handle.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-05 15:05:07 +02:00
Mariusz Skamra
c88b5dab61 Bluetooth: audio: ascs: Fix handling zero Number_of_ASEs parameter
As per ASCS_v1.0
"A client-initiated ASE Control operation shall be defined as an
invalid length operation if the Number_of_ASEs parameter value is
less than 1".

Fixes: ASCS/SR/SPE/BI-{02,03,04,05,06}-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-05 15:05:07 +02:00
Johan Hedberg
7ebaf1b10b Bluetooth: host: Fix scan info dangling pointer
Clear pointer to the le_adv_recv() stack frame before returning to the
calling function. This fixes a potential compiler warning newer gcc
versions.

zephyr/subsys/bluetooth/host/scan.c: In function ‘le_adv_recv’:
zephyr/subsys/bluetooth/host/scan.c:463:20: error: storing the address
of local variable ‘id_addr’ in ‘*info.addr’ [-Werror=dangling-pointer=]
  463 |         info->addr = &id_addr;
      |         ~~~~~~~~~~~^~~~~~~~~~
zephyr/subsys/bluetooth/host/scan.c:439:22: note: ‘id_addr’ declared here
  439 |         bt_addr_le_t id_addr;
      |                      ^~~~~~~

Fixes #48459

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2022-08-05 13:03:32 +02:00
Troels Nilsson
1c27b4353c bluetooth: controller: Expose prpa cache for LLL use
The prpa cache is now exposed through the ull_filter_lll_prpa_cache_get()
function (as the resolve list already is). This is needed to be
able to reply to AUX_CONNECT_REQ within the required time when
using SW-based RPA resolving

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-08-04 15:05:41 +02:00
Jonathan Rico
975fd4787b shell: Bluetooth: Fix auto-connect
The logic was still trying to parse the address even though one was already
stored.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-03 18:47:03 +02:00
Aleksandr Khromykh
678b003a50 Bluetooth: Mesh: Scanner is enabled during Friendship termination
Scanner was disabled after Friend Clear command. LNP didn't have
chance to receive Friend Clear Confirmation command back.
If option BT_MESH_LPN_ESTABLISHMENT is off then scanner is left
disabled and next Friend Offer after Friend Request
cannot be received.
PR fixes this.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-08-03 18:43:29 +02:00
Piotr Pryga
e9ea1b0e68 Bluetooth: df: fix ref antenna repeat after switch pattern exhausted
Direction finding functionality does antenna switching during CTE
reception in AoA mode and CTE transmission in AoD mode. Antennas are
switched according to user provided antenna switch pattern. If a CTE
length is enough to exhaust all antenna ids in a switch pattern then
Radio should loopback to reference antenna and continue from switching
from it.

Current implementation loops back to wrong antenna due to wrong index
used in GUARD_REF_ANTENNA_PATTERN_IDX. It was set to one instead of
zero. Zero is the index of reference antenna in Host provided antenna
switching pattern array.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-03 12:37:59 +02:00
Vinayak Kariappa Chettimada
6a41330650 Bluetooth: Controller: AD data fragment operation review rework
Added define PDU_AC_EXT_AD_DATA_LEN_MAX, maximum AD data
length possible in AUX_ADV_IND when all Common Extended
Header Format fields are populuted.

Updated function description to explain the added ADI and
Aux Ptr fields support in updating the auxiliary PDUs.

Remove the redundant CTE info population code unnecessary
for new chain PDU as a result of AD data overflow.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
76396496b6 Bluetooth: Controller: Minimal time reservation for aux and sync
Use minimal time reservation for auxiliary and sync PDU
reception. A peer device could be scheduling multiple
advertising sets in a short duration with small PDUs hence
using the minimal time reservation would avoid skipping
closely scheduled reception of multiple auxiliary PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
e6c8aaf629 Bluetooth: Controller: Refactor DF impl to add aux offset in ULL context
Refactor DF implementation to add aux offset in the aux
pointer field of the parent PDU when chain PDU is added
and/or is duplicated when PDU contents are updated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
d34cfb2929 Bluetooth: Controller: Add Extended Scan Resp Data fragment operation
Add implementation to support Extended Scan Response Data
fragment operation of first, intermediate, last, unchanged
and complete data operation using the HCI LE Set Extended
Scan Response Data Command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
1ed0ae3c81 Bluetooth: Controller: Minor scan response implementation refactor
Minor refactor of scan response implementation to rename sr_pdu
to sr_pdu_prev, and aux_pdu to sec_pdu_prev etc.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
97bb30ea59 Bluetooth: Controller: Add Extended Advertising Data fragment operation
Add implementation to support Extended Advertising AD Data
fragment operation of first, intermediate, last, unchanged
and complete AD data operation using the HCI LE Set Extended
Advertising Data Command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
aa5c0c0a90 Bluetooth: Controller: Rename Kconfig to BT_CTLR_ADV_AUX_PDU_BACK2BACK
Rename Kconfig BT_CTLR_ADV_PDU_BACK2BACK to
BT_CTLR_ADV_AUX_PDU_BACK2BACK to represent use of
back-to-back for Extended Advertising PDU chaining support
similar to BT_CTLR_ADV_SYNC_PDU_BACK2BACK that is used to
represent the use of back-to-back for Periodic Advertising
PDU chaining support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
efe1b1dda4 Bluetooth: Controller: Fix missing AD Data Set fragment operation
Fix missing AD data set fragment operation implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
349d27ebc7 Bluetooth: Controller: Fix sync set_clear to return aux_ptr reference
Update ull_adv_sync_pdu_set_clear() to return aux_ptr
reference so that aux_ptr field for chain PDUs can be
pupulated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
ccab45f9ad Bluetooth: Controller: Add defines for ext adv header field offsets
Add defines for Extended Advertising Common Extended Payload
Format field offsets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
4c94227b1d Bluetooth: Controller: Minor refactor to move ULL after LL functions
Minor refactor to reorder and move ULL functions after the
LL functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
84450d8981 Bluetooth: Controller: Duplicate and add aux offset to chain PDU in ULL
Refactor PDU chaining implementation to add aux offset in
the aux pointer field in the parent PDU when duplicating
chain PDUs.

By adding the aux offsets in the ULL execution context the
LLL prepare execution in Extended and Periodic Advertising
does not need to have a O(n) while loop in LLL execution
context.

This will reduce CPU use in the highest priority ISR
compared to current implementation where chain PDUs where
duplicated in ULL execution context and aux offset populated
in LLL execution context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
b689f18079 Bluetooth: Controller: Cleanup periodic adv chaining aux ptr population
Cleanup Periodic Advertising Chain PDUs auxiliary pointer
population, populate the back to back auxiliary pointer
field in thread context. Also, removed an unused code for
filling data.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
3edf487f6a Bluetooth: Controller: Set/Clear function to enqueue aux PDU in caller
Refactor the ull_adv_aux_hdr_set_clear function so that the
caller of the function will enqueue the auxiliary PDU when
enqueuing the primary PDU.

This change is required to support chaining of AD Data where
parent auxiliary PDU will be added with aux ptr fields when
chain PDUs are appended.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
49abc04d41 Bluetooth: Controller: Fix Periodic Adv Sync from preemption
Fix Periodic Advertising Synchronization from being
preempted by an overlapping Auxiliary PDU scan event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
a40a403a0d Bluetooth: Controller: Fix skipped Periodic Sync radio events
Fix skipped Periodic Advertising Sync radio events due to
increased CPU use during pre-emption in LLL from a Scan
radio event to Periodic Advertising Sync radio event by
increasing EVENT_OVERHEAD_START_US value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
5071ba4157 Bluetooth: Controller: Fix continuous scan initiator from being aborted
Fix to prevent a transmitted CONNECT_REQ PDU from being
aborted mid-air when initiator is using continuous scan
window that do not use time reservation. A different state
or role that overlaps the connection initiation requesting
for an abort should be denied when CONNECT_REQ PDU has been
enqueued for tranmission by the radio.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
3eb0c448be Bluetooth: Controller: Fix directed adv connection setup stall
When directed advertising and continuous scanning are
simultaneously active, and a connection request is received
by the directed advertising state then the connection was
not established due to the done event not being generated.

Done event from the directed advertising state was not
generated because the prepare pipeline only had resume
event which does not get scheduled when there is prepare
event of the continuous scan state.

The fix is to explicitly abort all pending prepare and
resume event in the pipeline for the directed advertising
state when connection request is received.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Vinayak Kariappa Chettimada
6b98d33ea6 Bluetooth: Controller: Minor refactor to move initialization
Minor refactor to move initialization close to locality of
reference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-03 12:02:47 +02:00
Troels Nilsson
e1e2c98abd bluetooth: Fix duration endianness issues
Added missing endianness conversion in controller and fixed double
conversion in host

Signed-off-by: Troels Nilsson <trnn@demant.com>
2022-08-03 05:04:53 +01:00
Piotr Pryga
dffbcb8146 Bluetooth: Controller: df: Add selectable IQ samples to 8 bit conversion
Nordic Radio Direction Finding Extension provides 12 bits wide IQ
samples. The Bluetooth Core Specification 5.3 Vol 4, Part E sections
7.7.65.21 and 7.7.65.22 limits IQ samples to be 8 bits wide.

There are other way to convert 12 bits IQ samples into Bluetooth Core
specification compliant 8 bits IQ samples than ordinary 4 bits right
shift. If one is sure that samples will never go over 10 bits or 8
bits then, it is allowed to use 2 bits right shift or even 8 least
significant bits of 12 bits IQ samples.

The commit introduces a possibility to choose which approach is used
for IQ samples conversion in HCI layer while Host IQ report events
are created.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-03 05:04:25 +01:00
Gerard Marull-Paretas
63aff01427 bluetooth: common: remove Enable from BT_HCI_VS_FATAL_ERROR prompt
Boolean options are not allowed to start with "Enable...".
BT_HCI_VS_FATAL_ERROR started with "Enable..." making some PRs fail due
to compliance checks.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-02 14:35:57 +02:00
Piotr Pryga
a0a8a12642 Bluetooth: hci: Use extended VS fatal error in hci and hci_rpmsg sample
Provide common helper functions to create extended extended Zephyr
Fatal Error functionality in HCI common code.

Use the implementation in hci_rpmsg sample.

The sample didn't provide an information about Controllers assert
or system fatal error to an application code while run with nRF5340
SoC. The goal for hci_rpmsg sample change is to enhance user experience
for conformance testing of the Bluetooth Controller while executed with
nRF5340.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-02 13:53:32 +02:00
Vinayak Kariappa Chettimada
f6a3da9c21 Bluetooth: Controller: Review rework of jitter in aux offset
Review rework of the fix to remove the jitter in aux offset
and sync offset values.

Force select BT_TICKER_REMAINDER_GET and BT_TICKER_LAZY_GET
features when Extended Advertising and Periodic Advertising
is supported.

Rename ticks and microsecond offset value struct members
for primary PDU event offset (to auxiliary PDU event).

Converted HAL_TICKER_REMOVE_JITTER and HAL_TICKER_ADD_JITTER
macro to functions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-02 12:54:31 +02:00
Vinayak Kariappa Chettimada
b6cf8bb580 Bluetooth: Controller: Use remainder in Ext and Periodic PDU offset
Use remainder value in scheduling the periodic auxiliary
PDUs and use the ticker next slot get interface with
remainder value to fill the auxiliary offsets with
microsecond precision in the primary channel PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-02 12:54:31 +02:00
Vinayak Kariappa Chettimada
aa73661b09 Bluetooth: Controller: Use macro to adjust ticks based on remainder
Use macro to adjust ticks for jitter stored in remainder
value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-02 12:54:31 +02:00
Vinayak Kariappa Chettimada
be7173a490 Bluetooth: Controller: Ticker next slot get to return remainder value
Updated ticker implementation to return remainder value for
a ticker when enumerating active tickers with time
reservations.

This is required to find offsets and to use the remainder
value to correctly calculate auxiliary offsets to the
microsecond resolution.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-02 12:54:31 +02:00
Vinayak Kariappa Chettimada
c14bde45b6 Bluetooth: Controller: Fix overlapping 1M and Coded PHY scannning
Fix overlapping 1M and Coded PHY scanning that caused idle
radio time when both PHY use same scan interval and sum of
their scan window duration equals the interval.
Implementation now will use continuous scanning and offset
the start of Coded PHY by the window duration of the 1M
scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-02 12:54:23 +02:00
Andries Kruithof
6d7a04a0ba Bluetooth: controller: llcp: initialise DLE parameters
The initialisation of DLE parameters for the peripheral
was done before the intialisation of the PHY settings.
Since the DLE parameters depend on PHY settings this
can result in incorrect parameters for tx/rx time and
octets
One scenario is where a previous connection set the PHY to
2M or CODED, then when a new connection is established
it uses the same memory-locations for connection settings as the
previous connection, and the (uninitialised) PHY settings will be
set to 2M or CODED, and thus the DLE parameters will be wrong
This PR moves the initialisation of DLE parameters after
that of PHY settings

EBQ tests effected include LL/CON/PER/BV-77-C.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-08-02 12:53:46 +02:00
Jonathan Rico
b0231e040d Bluetooth: host: invalidate tx context after destroying it
Now that we properly destroy the tx context in `bt_conn_process_tx`, we
need to make sure the context is really valid.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-01 18:13:35 +01:00
Jonathan Rico
00709e5fbb Bluetooth: host: add missing meta data destroy callback
Symptoms were that a disconnect happening when a buffer was enqueued but
not sent resulted in a meta-data memory leak.

This is problematic because it seemed (as per the OP) that it resulted in
the whole host getting locked up when a device sending long L2CAP packets
was prone to disconnect-reconnect cycles (e.g. in a bad RF environment).

Fixes #47649

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-01 18:13:35 +01:00
Aleksander Wasaznik
5a09325ba9 Bluetooth: Simplify predicate for host-based RPA resolution
The expression for the condition for using host-based RPA resolution now
simplifies to "Use host-based when we need to resolve more identities
than the controller can handle.".

Proof:
X=((bt_dev.le.rl_entries > 0) && (!bt_dev.le.rl_size ||
        bt_dev.le.rl_entries > bt_dev.le.rl_size))
X=(a > 0) && (!b || a > b)
a>=0, b>=0, because they are cardinal / size_t.
If a=0:
	// X evaluates to false. (0 > b)=(a > b) also always evaluates to false.
	X=false=(0 > b)=(a > b)
If a>0:
        X=(!b || a > b)
        If b=0: X=true=(a > 0)=(a > b)
        If b>0: X=(false || (a > b))=(a > b)
The expression is equivalent with (a > b) for all values of (a,b).
QED.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-08-01 18:11:57 +01:00
Michal Narajowski
fab8e29ee2 Bluetooth: Mesh: Add model publish support to Health Client
Mesh Profile Specification errata 11310
Section 4.4.4.1
"This model shall support model publication, as defined in Section
4.2.2 of the Mesh Profile specification and model subscription,
as defined in section 4.2.3 of the Mesh Profile specification."

Signed-off-by: Michal Narajowski <michal.narajowski@codecoup.pl>
2022-08-01 18:04:42 +01:00
Andries Kruithof
bd0a34c4d0 Bluetooth: controller: llcp: fix failing LL/CON/CEN/BV-55-C
The mandatory minimum PDU length conformance test was failing
because the LLCP did update the effective rx/tx times (and
corresponding notification to host).
This was due to a missing test condition.

This PR adds the missing conditions.

Note that with this change the refactored controller code is
similar to the legacy code; relevant code is in ull_conn.c,
in the function event_phy_upd_ind_prep

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2022-08-01 18:00:50 +02:00
Martin Tverdal
251a295d1a Bluetooth: Host: Don't read from buf after it is destroyed
Moving reading of index out of buf, to before buf is destroyed.

Signed-off-by: Martin Tverdal <martin.tverdal@nordicsemi.no>
2022-08-01 10:31:23 +02:00
Szymon Janc
f96f768532 Bluetooth: SMP: Fix min key size for LE Secure Connections Only mode
Secure Connection Only mode requires use of LE Security mode 1 level 4
which mandates 128 encryption key size.

Defaults in Kconfig are set from top-to-bottom and this resulted in
7 bytes key being forced. What is worse, user cannot override this
from prj.conf file since BT_SMP_MIN_ENC_KEY_SIZE is hidden config
if BT_SMP_SC_ONLY is enabled.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-08-01 10:30:16 +02:00
Mariusz Skamra
a0007f775f Bluetooth: audio: Fix server ASE Release in Codec Configured state
This fixes issue where the ASE state stuck in Releasing state instead of
going to Idle/Codec Configured as test requires.
Looks like there was a race condition possible where the ASE
notification work was run before the stream was detached, so there was
no transition to idle state triggered.

Fixes: ASCS/SR/ACP/BV-24-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-01 10:29:34 +02:00
Mariusz Skamra
55a70b97e6 Bluetooth: audio: Disallow Release operation on ASE in Releasing state
The server should not perform Release operation on ASE in Releasing
state. This fixes crash that might happen in ASCS when ACL gets
disconnected while ASE is in Releasing state so that server tries to
dereference NULL stream.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-01 10:29:29 +02:00
YanBiao Hao
e1e366c912 Bluetooth: Mesh: fix le addr string overflow
le addr string arry overflow

Signed-off-by: YanBiao Hao <haoyanbiao@xiaomi.com>
2022-07-29 14:11:11 +02:00
Vinayak Kariappa Chettimada
93728bf0ca Bluetooth: Add Periodic Advertising ADI support
Add support in Bluetooth Host to enable Periodic Advertising
ADI support feature when supported in the Controller to
include ADI in Periodic Advertising AUX_SYNC_IND PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-28 20:53:14 +02:00
Lingao Meng
e80161c86d Bluetooth: Mesh: Fix unable iv recovery 0 0 -> 1 0
According Mesh Spec 1.0.1:

Upon receiving and successfully authenticating to
Secure Network beacon for a primary subnet whose
IV Index is 1 or more higher than the current known IV
Index, the node shall set its current IV Index and its
current IV Update procedure state from the values in
this Secure Network beacon.

Look like test_iv_index.c:81
``` C

(bt_mesh_net_iv_update(TEST_IV_IDX + 1, BCN_IV_IN_IDLE));

```

This test case already exists, but the wrong testcase
to test wrong code.

Move `is_iv_recovery` into `bt_mesh_net_iv_update`.
First check whether it is IV recovery, and then carry out
the subsequent IV normal update procedure.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2022-07-28 19:47:36 +01:00
Emil Gydesen
d4b132a059 Bluetooth: Audio: Unicast client read available contexts
Read the available contexts during discovery and subscribe
for notifications.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-28 08:29:29 +02:00
Vinayak Kariappa Chettimada
a623ffb746 Bluetooth: Controller: Fix redundant node rx reservation
Fix redundant node rx reservation when receiving Periodic
Advertising Sync chain PDUs. Only the reception of first
pdu in chain, AUX_SYNC_IND PDU, needs extra node rx
reservation to be allocated for generation of incomplete
data status in case of incomplete reception of chain PDUs.

Co-authored-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-27 18:46:51 +02:00
Vinayak Kariappa Chettimada
08a9c295fa Bluetooth: Controller: Fix hang on chain PDU allocation
Fix hang on chain PDU allocation by replacing K_FOREVER use
by a timeout. Hang occurs when configured number of
advertising data buffers is low.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-27 18:46:01 +02:00
Piotr Pryga
a1963fccaf Bluetooth: llcp: Fix PHY UPD ntf send before instant on air
PHY update control procedure has to send a notification towards
Host when the PHY is actually changed, when the instant happens.
Control procedures are handled in a prepare phase of a connection
event, hence notifications are send towards host to early.

The fix for that is to postpone send of a notification.
New state has been introduced to remote requested PHY update
control procedure: RP_PU_STATE_WAIT_INSTANT_ON_AIR.
Also new event has been introduced: RP_PU_EVT_NTF, that is used
to inform the PHY update state machine that notification may
be send.

There are two places where the notification events may be generated
ull_conn_rx, just before first received PDU is send towards Host
or ull_conn_done, in case there were no PDU received.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-07-25 15:17:22 +02:00
Mariusz Skamra
6d85bd5a84 Bluetooth: gatt: Fix potential NULL pointer dereference
If the device was not paired, the conn->le.keys is NULL, so
conn->le.keys will cause NULL pointer dereference.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-07-25 09:39:39 +02:00
Hang Fan
8d06fd8d15 Bluetooth: Audio: Fix typo
Fix typo for CONFIG_BT_PAC_SRC_LOC_WRITEABLE

Signed-off-by: Hang Fan <fanhang@xiaomi.com>
2022-07-22 23:48:25 +02:00
Martin Tverdal
89780d715d Bluetooth: Host: Don't start scanner bt_conn_le_create
Starting the pasive scanner so host can resolve addresses
shouldn't be nessesary when the resolving list is empty.

Signed-off-by: Martin Tverdal <martin.tverdal@nordicsemi.no>
2022-07-22 14:05:21 +00:00
Mariusz Skamra
aa1771fb15 Bluetooth: shell: Remove redundant name parameter from adv-data cmd
The `name` parameter is redundant, as the `name` and `name-ad` options are
available already as `adv-create` and `adv-param` command parameters.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-07-22 10:33:45 +02:00
Aleksander Wasaznik
58c5e32e08 Bluetooth: Host: Disable host-based RPA resolution when !BT_PRIVACY
Change doc of CONFIG_BT_PRIVACY to explicitly say it's needed for both
generating and resolving RPAs.

Disable host-based RPA resolution in `bt_conn_le_create` when
!CONFIG_BT_PRIVACY.

Update doc of `bt_conn_le_create` to document that CONFIG_BT_PRIVACY is
a requirement for resolving RPAs. Also explictly say that this function
will resolve private identities. Also explain the expected effect of
Network Privacy on this function.

Reduce coupling to `bt_le_create_conn_ext` and
`bt_le_create_conn_legacy` in `bt_conn_le_create` by just use
`resp_addr` when it's set, instead of "knowing" when it had been set.
The alternative would be to also update `bt_le_create_conn_ext` and
`bt_le_create_conn_legacy` to have `(IS_ENABLED(CONFIG_BT_PRIVACY) &&
(!bt_dev.le.rl_size || bt_dev.le.rl_entries > bt_dev.le.rl_size))`

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-07-20 10:48:09 +02:00
Aleksander Wasaznik
2b68a7d391 Bluetooth: Host: Make function static
`bt_le_create_conn_legacy` is not used outside its file.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-07-20 10:48:09 +02:00
Emil Gydesen
df75bfd8f6 Bluetooth: Audio: Add PACS location read for unicast client
The unicast client will now read the PACS location value
during the discovery procedure, as well as subscribing to
it.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-19 12:27:00 +00:00
Emil Gydesen
5aa1ab9c1a Bluetooth: Audio: Remove redundant unicast client guard
The code in unicast_client.c was guarded by
CONFIG_BT_AUDIO_UNICAST_CLIENT but the file is only
compiled if CONFIG_BT_AUDIO_UNICAST_CLIENT is enabled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-19 12:27:00 +00:00
Emil Gydesen
dab588a23a Bluetooth: Audio: Rename unicast client PAC cache
Rename the cache from "cache" to "pac_cache" to avoid
name clashes with local cache variables.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-19 12:27:00 +00:00
Fredrik Danebjer
c0ab35a997 Bluetooth: GATT: Add LE Secure Connections Permission Check
Added possibility to enforce that a LE Secure Connection is required
for reading and writing characteristics, i.e. providing a more fine
grained check that allows services that requires secure connection
to co-exists with those that doesn't.

Signed-off-by: Lars Knudsen <larsgk@gmail.com>
Signed-off-by: Fredrik Danebjer <fredrik@danebjer.com>
2022-07-19 10:32:56 +02:00
Mariusz Skamra
31d3479c85 Bluetooth: shell: audio: Extend vcs init with opt params
Extend the `vcs init` command with optional parameters to set the
initial VCS state including volume level, mute state and step size.
This is needed to pass qualification test cases listed below:
VCS/SR/CP/BV-01-C,
VCS/SR/CP/BV-02-C,
VCS/SR/CP/BV-02-C,
VCS/SR/CP/BV-04-C

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-07-18 18:42:34 +02:00
Andreas Rudolf
422f98182c Bluetooth: shell: fix bt init sync command
Shell command "bt init sync" now correctly enables Bluetooth
synchronously, and "bt init" enables Bluetooth asynchronously.

Fixes #47860.

Signed-off-by: Andreas Rudolf <andreas.rudolf@husqvarnagroup.com>
2022-07-18 18:42:02 +02:00
Emil Gydesen
577caf774e Bluetooth: Audio: User _ prefix for sys_snode_t nodes
The sys_snode_t nodes are used internally, and we use the
convention of the "_" prefix to indicate that this is
an internally used value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 18:30:43 +02:00
Emil Gydesen
549a98acce Bluetooth: Audio: Modify broadcast sink to use list of streams
Modify the broadcast sink to use a list of streams instead
of an array. This removes the requirement that the array
of stream pointers shall be static, and makes the
broadcast sink API and implementation more similar
to the unicast group and broadcast source.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 18:30:43 +02:00
Emil Gydesen
468bd4d852 Bluetooth: Audio: Modify broadcast source to use a list of streams
Modify from array to list. The list approach is easily
implemented as it is used for the unicast groups, and
using the list approach instead of an array does not
require the array to be static.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 18:30:43 +02:00
Tomislav Milkovic
0fe2c1fe90 everywhere: Fix legacy include paths
Any project with Kconfig option CONFIG_LEGACY_INCLUDE_PATH set to n
couldn't be built because some files were missing zephyr/ prefix in
includes
Re-run the migrate_includes.py script to fix all legacy include paths

Signed-off-by: Tomislav Milkovic <milkovic@byte-lab.com>
2022-07-18 16:16:47 +00:00
Emil Gydesen
eab6d202ca Bluetooth: Audio: Add unicast server stream reconfigure
Add support for the reconfigure procedure for the unicast
server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 13:18:35 +00:00
Emil Gydesen
b74aa44df5 Bluetooth: Audio: Add unicast server stream start
Add support for the unicast server to start a stream.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 13:18:35 +00:00
Emil Gydesen
49c0074b81 Bluetooth: Audio: Add unicast server stream metadata
Add support for setting metadata as the unicast server role.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 13:18:35 +00:00
Emil Gydesen
a79318f627 Bluetooth: Audio: Add unicast server stream disable
Add support for disabling streams as the unicast
server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 13:18:35 +00:00
Emil Gydesen
a22bbee33a Bluetooth: Audio: Add unicast server stream release
Update bt_audio_stream_release to also support the unicast
server.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-18 13:18:35 +00:00
Mariusz Skamra
df5a535a5f Bluetooth: audio: Fix bt_pacs_context_available
This fixes bt_pacs_context_available so that it gets available
contexts from capabilities that hold the value.
This removes redundant available_context that were held
(and not updated) in pacs.c.

Fixes: HAP/HA/STR/BV-01-C
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-07-15 15:33:35 +02:00
Jonathan Rico
ffefce7745 Bluetooth: host: Rewrite bt_gatt_notify_multiple
This API now becomes a low-level API, in the sense that it should only be
used if the app developer knows what he is doing and wants to ensure a
ATT_MULTIPLE_HANDLE_VALUE_NTF PDU goes on-air.

For the other 99% of use cases, `bt_gatt_notify` should instead be used, as
it will automatically upgrade to ATT_MULTIPLE_HANDLE_VALUE_NTF when
possible.

One can disable the batching of notifications when using `bt_gatt_notify`
by setting CONFIG_BT_GATT_NOTIFY_MULTIPLE_FLUSH_MS=0 .

This API doesn't support lookup by UUID any more.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-15 12:17:29 +02:00
Jonathan Rico
7e9f652ee6 Bluetooth: host: Invoke GATT notify callback for each handle
In the case a call to `bt_gatt_notify_cb` gets its attribute data
batched with others to form an ATT_MULTIPLE_HANDLE_VALUE_NTF PDU, the
application developer would still expect one callback per API call.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-15 12:17:29 +02:00
Jonathan Rico
e6dfbe82fd Bluetooth: host: Don't send ATT_MULTIPLE_HANDLE_VALUE_NTF with one attr
Sending ATT_MULTIPLE_HANDLE_VALUE_NTF containing only one handle doesn't
seem forbidden by the spec, but peers might find it unexpected.

This change morphs a ATT_MULTIPLE_HANDLE_VALUE_NTF into a
ATT_HANDLE_VALUE_NTF right before sending it, if it detects this
condition.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-15 12:17:29 +02:00
Jonathan Rico
0218e9db18 Bluetooth: host: Fix gatt_notify_mult by using a delayed work item
The intended behavior is that calling `gatt_notify_mult` in a loop will
result in a `BT_ATT_OP_NOTIFY_MULT` containing all the handles and their
data.

What was happening instead is that the caller thread was a lower priority
than the system workqueue, and thus multiple `BT_ATT_OP_NOTIFY_MULT` PDUs
were being sent over the air instead of one.

Submitting the work item with a delay side-steps this particular issue.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-15 12:17:29 +02:00
Jonathan Rico
7411b451da Bluetooth; GATT: don't immediately cancel CCC write request
`bt_gatt_unsubscribe` was pending a write to the CCC and then immediately
canceling it.

Fixes #47682 .

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-15 10:01:15 +02:00
Omkar Kulkarni
43f3c8fb7e Bluetooth: Mesh: IV Index timer is not started
This fixes an issue where IV index stage counting timer is not
started after the node is provisioned. This would have prevented node
from performing IV index updates.

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
2022-07-14 17:51:31 +00:00
Fredrik Danebjer
04a080bf70 Bluetooth: Audio: TBS Client optional procedures actually optional
This change makes the optional procedures in the TBS Client optional
and configurable through Kconfig.

Signed-off-by: Fredrik Danebjer <fredrik@danebjer.com>
2022-07-14 15:48:28 +00:00
Piotr Pryga
e84cabf0d4 Bluetooth: Controller: fix mayfly unwanted re-init every bt_enable call
Mayfly by design uses a memq for storage of its jobs. The memq
requires head and tail to track the content. It is considered
empty is head equals tail.

When memq instance is initialized then there is a new link
instance stored in head and tail, nevertheless the memq is
still empty.

When new job is enqueued to a memq, the inilial link is used
to store the job. New link, provided by enqueue call, is stored
in the tail for future enqueue.

When enqueued job was served and is dequeued, the link it was
assigned to is returned and stored in the job object.
That link will be used in future for call to enqueue.

Now lets consider a situation when we are just after initalization.
Some default initial link is in empty memq. We enqueue and dequeue
a job. After dequeue, the job object stores the initial link object.
The one that was put into the memq during initialization.
Next Bluetooth stack is disabled and enabled again.

The job is enqueued again, but it still stores the initial link
address. After enqueue the memq head points to initial link object,
that stores new job. Tail points to link deliveded by enqueue call,
that is also the initial link object. The memq is considered to be
empty, nevertheless there was a successful enqueue operation.

The issue is casued by lack of re-initialization of a job object
on init. In most cases these objects are static members of some
functions, hence there is no re-initialization after bt_disable
and bt_enable calls.

The problem is fixed by re-initialization of mayfly only once
on bt_enable() call. Then it doesn't matter what links are stored
in dequeued objects and there is no need to re-initialized mayfly
job objects.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-07-13 16:13:57 +02:00
Piotr Pryga
9cd94277bf Bluetooth: Host: conn_change signal object not correclty initialied
The problem is visible after call to bt_disable when there was
a connection. On a next bt_enable call when hc_tx_thread starts
it is possible that the conn_change object internals are not
re-initialized entirely and the function fails during k_poll call.

The commit changes explicit assignment conn_change object to
a k_poll_signal_init that does proper initialization.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-07-13 16:13:57 +02:00
Piotr Pryga
2125a6494c Bluetooth: Host: add missing de-init of periodic sync pool
While execution of bt_disable there is missing de-initialization
of per_adv_sync_pool. If there was a sync in progress, (flags set
to BT_PER_ADV_SYNC_SYNCING) before bt_disable, then when the stack
is re-enabled by bt_enable new sync create fails.

The commit fixes the issue by new function that clears flags for
all per_adv_sync_pool entries. The function is executed by bt_disable.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-07-13 16:13:57 +02:00
Pavel Vasilyev
e492894a5e Bluetooth: Mesh: Call bt_mesh_reset in cfg srv from workqueue
Struct bt_mesh_send_cb.end is called from the mesh advertiser thread.
bt_mesh_reset now requires more stack size, thus can't be called from
the advertiser thread. k_work instance requires less memory than needed
for bt_mesh_reset.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-07-13 10:19:44 +02:00
Pavel Vasilyev
f4d1529947 Bluetooth: Mesh: Flush pending settings in bt_mesh_reset/_cdb_clear
Upon bt_mesh_reset call, all mesh modules has to clear the privisioning
and configuration data. None of the modules store or erase in settings
subsystem immediately, but put this on the mesh settings work. After the
settings work is scheduled, all stored data will be removed and the
device will eventually be unprovisioned. Until then, the device is not
completely unprovisioned, thus calling bt_mesh_prov_enable,
bt_mesh_provision (and bt_mesh_cdb_create) should not be allowed.

Struct bt_mesh_prov has a reset callback stating that after this
callback is called, the device has been reset and can be re-provisioned
again. Also, bt_mesh_reset API description states that after calling
bt_mesh_reset API, the device needs to reenable the provisioning layer
to be provisioned again. But this is not correct since the settings has
to be cleared before the device can be reprovisionined.

This commit makes bt_mesh_reset flush pending settings so that the
device can be reprovisioned immediately and the API will behave as
written in the description.

The same applies to bt_mesh_cdb_clear.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-07-13 10:19:44 +02:00
Emil Gydesen
c699ae5850 Bluetooth: Audio: Expose broadcast sink adv data to application
In the broadcast sink `scan_recv` which is called when we
scan for broadcast source, we now also provide the entire
AD struct to the application.

The reason for this is that the advertising data may
contain other information that is useful for the application
like the broadcaster device name or any other
vendor/application specific data.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-12 14:17:02 +02:00
Emil Gydesen
9b15426455 Bluetooth: Audio: Refactor ISO allocation endpoints
Modify how the ISO channels are allocated for the audio streams,
as well as how the CIG is allocated for the unicast group.

This fixes an issue where the unicast group could not be
fully allocated before _after_ the bt_audio_streams had been
configured by bt_audio_stream_config, thus making it impossible
to create a unicast group before the connections have been established.

This leaves us with 3 basic data types:
1) Streams allocated by the application
2) Endpoints that represent ASEs
3) Audio_iso which is used to couple streams and ISO channels.

The Unicast Group for the unicast client will now have the same
lifetime as the ISO CIG for the central.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-12 14:12:08 +02:00
Herman Berget
a0ce235d9b Bluetooth: Shell: Add bt security command to list current security level
The command could previously only set the security level.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Jonathan Rico
e797c69554 Bluetooth: shell: add l2cap ECRED commands
Add commands to connect to an l2cap channel using Enhanced Credit-based
Flow Control, and to reconfigure it.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Jonathan Rico
71bcab6335 Bluetooth: shell: add hexdump on GATT read
In order to actually see the data instead of just getting the length.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Jonathan Rico
7f88638e11 Bluetooth: shell: stop l2cap TX when channel is disconnected
Without this, the shell locks up when disconnected in the middle of a send
routine.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Jonathan Rico
92bd415750 Bluetooth: shell: add param-less connect command
When invoked without parameters, `bt connect` will now attempt to connect
to the last scanned device. Used in conjunction with the RSSI filter, this
makes the connection process somewhat scriptable.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Jonathan Rico
55179da0fc Bluetooth: shell: add RSSI filtering
This adds an RSSI cutoff, so any scanned devices that are below the given
value (in dB) will not get printed out. Very useful in noisy environments.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 12:24:43 +02:00
Jonathan Rico
e0f0f4ab45 Bluetooth: Host: add missing bt_conn_unref
conn is being referenced in `bt_conn_lookup_addr_le()`.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 11:14:29 +02:00
Jonathan Rico
38cd73d47d Bluetooth: gatt: check subscription before notifying
Check that the client has subscribed before sending a notification.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-07-12 11:14:29 +02:00
Asbjørn Sæbø
dbe8a3ff96 Bluetooth: Audio: Additional MEDIA_PROXY defines
Add two MEDIA_PROXY group type defines corresponding to the MCS ones.
Update the mpl.c to use the newly added names.

The purpose of the exercise is to get a complete set of MEDIA_PROXY
defines, so that the media player can be made fully independent
(define-wise) of the MCS.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2022-07-12 10:15:32 +02:00
Asbjørn Sæbø
704d5ee0bf Bluetooth: Auidio: Use MEDIA_PROXY_* defines in media player
Update the media player to use the MEDIA_PROXY_* defines rather than the
BT_MCS defines.  The media player should not know about the MCS (media
control service).

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
2022-07-12 10:15:32 +02:00
Mariusz Skamra
a3904bd991 Bluetooth: audio: Fix PACS location chrc properties
If the characteristic is non-writtable, the BT_GATT_CHRC_WRITE property
flag shall be unset. Moreover, threre is no point to set
BT_GATT_PERM_WRITE_ENCRYPT permission flag as well if the attribute has
no `write` callback set anyway.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-07-11 16:04:42 +00:00
Vinayak Kariappa Chettimada
b397a950c5 Bluetooth: Controller: Fix missing reset of coded PHY scanning
When switching from Extended Scanning by Extended
Advertising HCI commands back to Legacy Scanning after a
HCI reset it is required that the coded PHY scanning
context is reset.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-11 14:15:13 +02:00
Vinayak Kariappa Chettimada
265731b971 Bluetooth: Controller: Fix Extended Scan Address Resolution
Fix Extended Scanning Address Resolution that incorrectly
checked for Bit Count Comparison which is not to be checked
when explicit resolution is performed in the Rx ISR.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-11 13:53:19 +02:00
Vinayak Kariappa Chettimada
918585263e Bluetooth: Controller: Use maximum Adv PDU size time reservation
Use the maximum advertising PDU size time reservation
consider the Advertising Data could be updated from zero to
maximum support size. If maximum time reservation is
disabled then time reservation corresponding to the
Advertising Data present at the time of the start/enable
of Advertising is used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-11 13:34:29 +02:00
Vinayak Kariappa Chettimada
fab4511164 Bluetooth: Controller: Fix overlapping advertising events
When multiple advertising sets are support then use advanced
scheduling implementation to place multiple auxiliary PDUs
and periodic advertising PDUs in a non-overlapping schedule.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-11 13:34:29 +02:00
Vinayak Kariappa Chettimada
e027f0671a Bluetooth: Controller: Fix missing recv fifo reset
Fix missing recv fifo reset on HCI reset. This fix handles a
scenario where in Rx Prio thread has enqueued a node rx, Tx
thread handles HCI Reset Command, and Rx thread wakes up
from call to k_fifo_get to handle invalid node rx. The
changes here ensure Rx thread does not get any invalid node
rx post HCI Reset Command handled in Tx thread.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-07-11 11:28:07 +02:00
Kamil Piszczek
1eb9d36d46 bluetooth: add api for changing rpa timeout in runtime
Added a new Bluetooth API and Kconfig option for overriding the RPA
timeout in runtime.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2022-07-11 09:27:07 +00:00
Kamil Piszczek
8bdf363c0c bluetooth: adv: add rpa timeout callback to extended advertising api
Added a new callback to the Bluetooth Extended Advertising callback
structure. It notifies the application that the RPA validity of the
advertising set has timed out. The user can use this callback to
synchronize the advertising payload update with the RPA rotation.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2022-07-11 09:27:07 +00:00
Kamil Piszczek
4e924b6b1f bluetooth: id: sync advertising set start after rpa rotation
Synced the start of the advertising sets after each RPA rotation
in the Bluetooth identity module.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2022-07-11 09:27:07 +00:00
Emil Gydesen
4b953eabf8 Bluetooth: Audio: Moved ASCS metadata verification to higher layer
Instead of rejecting metadata at the BAP layer, we now
expect the higher layer to provide the verification.

The reason for this is that the higher layer may be better
equiped at determining which metadata it supports.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00
Emil Gydesen
e1114bf3dd Bluetooth: Audio: Add CAP acceptor set member support
The CAP acceptor can now be a set member. This allows
the CAP acceptor to register a CSIS instance and include
it in the CAS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00
Emil Gydesen
9298c0f96f Bluetooth: Audio: Add CAP acceptor CCID check for TBS
Add bt_cap_acceptor_ccid_exist that verifies that CCIDs
from the CAP initiator are valid on the initiator based
on what we have previously discovered.

Verification from MCS is still a TODO.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00
Emil Gydesen
e712a2462b Bluetooth: Audio: Add get_by_ccid for TBS
This is needed for the CAP acceptor to properly
verify the CCID_List in the metadata.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00
Emil Gydesen
539ffe296e Bluetooth: Audio: Add stream context validation for CAP acceptor
When the CAP acceptor role is enable, ASCS will verify
that the stream context type supplied by the client
matches the PACS available context.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00
Emil Gydesen
6eb67b9b6a Bluetooth: Audio: ASCS verify metadata type
Add a check to verify metadata type in the
update metadata procedure handler.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00
Emil Gydesen
aab98d6b1c Bluetooth: Audio: Add ASCS Metadata verification before copy
Verify the metadata before copying it. This will allow the
unicast server to verify the data and potentially
reject it without modifying existing metadata.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00
Emil Gydesen
2c6358c9c9 Bluetooth: Audio: Add CAP acceptor
Adding the CAP Acceptor role, which is a quite simple
role. The role instantiates the Common Audio Service (CAS)

The role will later be expanded to properly support
the use the Coordinated Set Member role via CSIS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-07-08 20:08:45 +00:00