Commit graph

9523 commits

Author SHA1 Message Date
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