Commit graph

9523 commits

Author SHA1 Message Date
Andrzej Kaczmarek
45ebbbf04b Bluetooth: controller: Add helper to initialize adv PDU from scratch
This adds adv_sync_pdu_init helper which initializes pdu_adv buffer
with contents of AUX_SYNC_IND/AUX_CHAIN_IND PDU. Extended header flags
can be specified to reserve required space for corresponding fields if
necessary.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
7c81ed71d0 Bluetooth: controller: Enable back-to-back chaining for periodic adv
This enables chaining ota for periodic advertising. AUX_CHAIN_IND PDUs
will be sent automatically if AuxPtr is detected in preceding PDU.
AuxPtr offset is always set to achieve minimal required frame spacing,
i.e. 300us (T_mafs). AuxPtr in all PDUs in advertising train are
updated on enqueue since PDU spacing is already known at that time so
we do not need to waste time in LLL.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
21892eecf1 Bluetooth: controller: Add support for linked adv PDUs
This adds support to allow advertising PDUs to be linked which is
required to send advertising trains, i.e. AUX_CHAIN_IND.

PDUs are linked with a simple single-linked list, the pointer to next
PDU is stored at the very end of PDU buffer. This prevents it from
being overwritten if PDU is modified and allows for build time offset
calculation.

There are few helpers added to make handling easier, e.g.:
- get next linked PDU
- get last linked PDU
- link one PDU to another
- link PDU at the end
- release all linked PDUs (except for 1st)

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
1e02d400e2 Bluetooth: controller: Optimize lll_adv_pdu_and_extra_data_alloc
This function is the same as lll_adv_pdu_alloc except it also allocates
extra data at the end - it can just use lll_adv_pdu_alloc call to avoid
extensive c&p.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
5af3e39574 Bluetooth: controller: Add helper to allocate new pdu_adv
This adds helper to always allocate advertising PDU either from memory
pool or pdu_free queue and does not reuse existing PDU in adv_pdu.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Andrzej Kaczmarek
67bfb2fb56 Bluetooth: controller: Fix PKT_AC_US macro
Advertising channel packets do not have MIC, there's no need to have
extra parameter which always has to be set to 0 anyway.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2021-07-10 12:44:33 -04:00
Emil Gydesen
f18bebd9de Bluetooth: Iso: Do not remove iso data path on disconnect
We previously removed the iso data path when the iso channel
disconnected. Since the iso data path is unique for a given
iso channel (by handle), it does not make sense to remove
it for a disconnected channel, as the channel is, in
a sense, not existing anymore.

This update is to better comply with the bluetooth
core spec, and to avoid getting errors from the
controller on disconnect.

Rather than removing the implementation of being able
to remove the data path, the function was made non-static
and moved to the internal header file, in case we ever
want to use it. This should not affect compile size.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-10 12:41:48 -04:00
Emil Gydesen
f50574a6a0 Bluetooth: host: Move bt_data_parse to hci_core.c
Move the function from scan.c to hci_core.c.
When in scan.c, the function is only available if
CONFIG_BT_OBSERVER was enabled. Since the function
can be used in other scenarioes where we need to parse
LTV data, it has been moved to a more generic place.

hci_core.c might not be the ideal place, but it is
where most other common bluetooth functions
are located.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-07-10 12:41:18 -04:00
Lingao Meng
3d2ad8e653 Bluetooth: Mesh: Split proxy.h to proxy.h and proxy_msg.h
The Bluetooth proxy feature includes proxy client and proxy server.
In addition to the proxy pdu message used above, pb-gatt also uses
the same proxy pdu message.

Currently zephyr bluetooth mesh couples them in one file.

A file at the separation is called gatt_services.c,
which is used to contain Mesh Provisioning Service and
Mesh Proxy Service.

Another file in the separation is called proxy_msg.c,
which is used to process Proxy pdu messages.

Also according to Trond's suggestion:

Rename CONFIG_BT_MESH_PROXY to CONFIG_BT_MESH_GATT.
Create an additional promptless entry CONFIG_BT_MESH_GATT_SERVER
that selects CONFIG_BT_MESH_GATT and is selected by
CONFIG_BT_MESH_GATT_PROXY or CONFIG_BT_MESH_PB_GATT.

Create additional CONFIG_BT_MESH_PROXY used to represent
proxy feature (also include proxy client).

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-09 17:56:16 +03:00
Lingao Meng
7b2e51881c Bluetooth: Mesh: Rename proxy.c to proxy_msg.c
The Bluetooth proxy feature includes proxy client
and proxy server. In addition to the proxy pdu
message used above, pb-gatt also uses the same
proxy pdu message.

Currently zephyr bluetooth mesh couples them in one file.

A file at the separation is called gatt_services.c,
which is used to contain Mesh Provisioning Service and
Mesh Proxy Service.

Another file in the separation is called proxy_msg.c,
which is used to process Proxy pdu messages.

Also according to Trond's suggestion:

Rename CONFIG_BT_MESH_PROXY to CONFIG_BT_MESH_GATT.
Create an additional promptless entry CONFIG_BT_MESH_GATT_SERVER
that selects CONFIG_BT_MESH_GATT and is selected by
CONFIG_BT_MESH_GATT_PROXY or CONFIG_BT_MESH_PB_GATT.

Create additional CONFIG_BT_MESH_PROXY used to represent
proxy feature (also include proxy client).

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-09 17:56:16 +03:00
Lingao Meng
3a559e972a Bluetooth: Mesh: Modularizing the proxy
The Bluetooth proxy feature includes proxy client
and proxy server. In addition to the proxy pdu
message used above, pb-gatt also uses the same
proxy pdu message.

Currently zephyr bluetooth mesh couples them in one file.

A file at the separation is called gatt_services.c,
which is used to contain Mesh Provisioning Service
and Mesh Proxy Service.
Another file in the separation is called proxy_msg.c,
which is used to process Proxy pdu messages.

Also according to Trond's suggestion:

Rename `CONFIG_BT_MESH_PROXY` to `CONFIG_BT_MESH_GATT`.
Create an additional promptless entry
`CONFIG_BT_MESH_GATT_SERVER` that selects
`CONFIG_BT_MESH_GATT` and is selected by
`CONFIG_BT_MESH_GATT_PROXY` or `CONFIG_BT_MESH_PB_GATT`.

Create additional `CONFIG_BT_MESH_PROXY` used to represent
proxy feature (also include proxy client).

see #36343

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-07-09 17:56:16 +03:00
Vinayak Kariappa Chettimada
b81cecf8df Bluetooth: Controller: Use define for offset unit and SCA calculation
Use defines for offset unit and for calculation of Periodic
Advertising window widening using clock accuracy value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-06 18:51:51 -04:00
Vinayak Kariappa Chettimada
6684af11b9 Bluetooth: Controller: Fix clock accuracy calculation scanning Aux PDU
Fix clock accuracy value used in the calculation of window
widening applied when scanning for auxiliary PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-06 18:51:51 -04:00
Kamil Piszczek
bd7d28ef7d bluetooth: services: hrs: use template for logging configuration
Use template for logging configuration in Bluetooth HR service.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2021-07-05 14:34:25 +03:00
Kamil Piszczek
dd5a0d1997 bluetooth: services: hrs: add characteristic permission config
Added a configuration of characteristic access permissions for
Bluetooth Heart Rate service.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2021-07-05 14:34:25 +03:00
Abe Kohandel
d6314fa456 bluetooth: ots: Add object name write capability
Add the ability to perform a write on the object name GATT
Characteristic with a notification callback to the application
that the name has been written.

In order for this operation to work the memory backing the
object name must be modifiable. To prevent forcing the user
to always allocate 120 bytes for the name, the maximum name
length is changed from a define to a configuration parameter.

Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
2021-07-02 22:22:24 -04:00
Patrick Rathje
cb6ef1328b Bluetooth: L2CAP: Fix missing net_buf_unref()
In case of non-recoverable errors (e.g. the connection breaks while
transmitting), the l2cap_chan_tx_process deques the net_buf but does
not unreference it. As this is inside a work queue thread, the sending
thread gets no information on this error, relying on the tx_process to
ultimately free the buffer.

Signed-off-by: Patrick Rathje <git@patrickrathje.de>
2021-07-02 22:22:02 -04:00
Vinayak Kariappa Chettimada
3cc8f31744 Bluetooth: Controller: Fix auxiliary scan context leak
Fix an auxiliary scan context leak when initiator
establishes a connection while there is another pending
auxliary PDU scheduled to be received. In this case, the
pending auxliary scan LLL context does an early abort
without generating a scan aux done event. Missing scan aux
done event caused the auxiliary scan context leak.

Fixes #36131.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-02 13:05:36 -04:00
Pavel Vasilyev
6c9411656c Bluetooth: Mesh: Restore default device configuration on reset
This commit fixes an issue where bt_mesh_reset() call just erases all
mesh flags set at the initialization instead of restoring them and
thus disabling some features until the board reboot.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2021-07-02 16:58:21 +03:00
Vinayak Kariappa Chettimada
aab30dad6f Bluetooth: controller: Use S8 encoding Tx chain delay
Minor update to calls to get Tx chain delay in extended
advertising and scanning to use S8 encoding delays.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
c7dd004148 Bluetooth: controller: PA/LNA radio timing tuned
PA/LNA related timing calculations tuned for extended
advertising and scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
3f519fea17 Bluetooth: controller: Fix 1st connection event offset for peripheral
We need to take RX chain delay and PHY used to receive
CONNECT_IND into account when calculating 1st connection
event offset.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
abc573e0f5 Bluetooth: Controller: Define a macro for active clock jitter value
Define a macro for active clock jitter value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
d510351b4f Bluetooth: controller: Fix Tx-Rx switch delay calculation
In the Tx to Rx switch, fix the delay which should be the
Rx ready delay plus the Tx chain delay and plus 4 us active
clock jitter compensation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:31:16 -04:00
Vinayak Kariappa Chettimada
0bd05c0ed9 Bluetooth: Controller: Rename CPR mutual exclusion functions
Rename CPR mutual exclusion function to not sound similar to
OS mutex interfaces.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:30:50 -04:00
Vinayak Kariappa Chettimada
a8d4c062fa Bluetooth: Controller: Use inline functions for CPR mutex operations
Use inline functions for CPR mutex operations.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:30:50 -04:00
Vinayak Kariappa Chettimada
d518337835 Bluetooth: Controller: Cleanup mutual exclusion in CPR implementation
Minor cleanup of the implementation of mutual exclusion
of LE Connection Parameter Request amongst active
connections.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-07-01 13:30:50 -04:00
Lingao Meng
cc0abee3db Bluetooth: Mesh: Check the CID field before opcode compare
Bluetooth Mesh Vendor model hava company id field.

Accordin MeshPRFV1.0.1 3.7.3.1 Operation codes.

The 3-octet opcodes are used for manufacturer-specific opcodes.
The company identifiers are 16-bit values defined by the
Bluetooth SIG and are coded into the second and third octets of
the 3-octet opcodes.

Therefore, we can speed up the search process by checking whether
CID fields match, rather than comparing opcodes one by one.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2021-06-29 17:08:02 -04:00
Vinayak Kariappa Chettimada
d3c27aeb8f Bluetooth: Controller: Fix Data Length Update node Rx reservations
Reserve a minimum node rx of 2 that can happen when local
central initiated PHY Update reserves 2 node rx, one for PHY
Update complete and another for Data Length Update complete
notification. Otherwise, a peripheral only needs 1
additional node rx to generate Data Length Update complete
when PHY Update completes.

Relates to #36381.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-29 17:05:20 -04:00
Vinayak Kariappa Chettimada
6810facffa Bluetooth: Controller: Fix free rx buffer MFIFO enqueue
Replace the post decrement in loop's conditional into
explicit decrement inside the loop so as to avoid
decrementing the maximum count without enqueueing free rx
buffers into the free rx buffer MFIFO.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-29 17:05:20 -04:00
Vinayak Kariappa Chettimada
ecf7106177 Bluetooth: Controller: Minor change to use IS_ENABLED
Minor changes to use IS_ENABLED and updates to comments in
code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-29 17:05:20 -04:00
Emil Gydesen
50cea984b8 Bluetooth: ISO: Only remove CIG as central
The hci_le_remove_cig command shall only be sent as the
master/central. Implemented this by early termination in
bt_iso_cleanup as the slave/peripheral.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-29 10:38:14 -04:00
Vinayak Kariappa Chettimada
5627ce32c7 Bluetooth: Controller: Fix peripheral tx, rx and time reservations
Fix peripheral maximum transmit time, maximum receive time
and radio event length time reservations when connection
established using Extended Advertisements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-28 11:58:45 -04:00
Vinayak Kariappa Chettimada
bb50284676 Bluetooth: Controller: Fix central tx, rx and time reservations
Fix central maximum transmit time, maximum receive time
and radio event length time reservations when connection
established using Extended Advertisements.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-06-28 11:58:45 -04:00
Trond Einar Snekvik
534177b2ca Bluetooth: Mesh: Fix regression in PB-ADV
After #35702, the provisioner is unable to mark a link as closed, as
it depends on the send_end callback to be called, so it can start its
timer. PB-Adv keeps a reference to the buffers of reliable messages,
which prevents this callback to be invoked, as the buffer destructor is
never called.

Move scheduling of the retransmit timer to the initial transmission, and
replace the timer based LINK_CLOSE message tx duration with a message
counting solution.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-06-27 19:51:47 +03:00
Emil Gydesen
141620519b Bluetooth: Audio: AICS client add function to get conn pointer
Add a function that returns the bluetooth connection
pointer of a given AICS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 11:31:04 -04:00
Emil Gydesen
7e6d927467 Bluetooth: Audio: AICS remove need for bt_conn pointer
Remove the bt_conn pointer from the AICS API, as the
instance pointer is enough to determine if it is a client
and perform client operations on the cached connection pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 11:31:04 -04:00
Trond Einar Snekvik
c6945fbb1d Bluetooth: Mesh: Ensure proxy_send's attribute is always set
Initializes proxy_send's attr pointer, which in theory could be
uninitialized if neither gatt proxy or PB GATT is enabled while proxy.c
is enabled.

This scenario is not really possible with the current kconfig structure,
but is reported as a potential error by Coverity, and should be fixed
for future proofing purposes.

Fixes #36314.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2021-06-24 11:30:26 -04:00
Emil Gydesen
cefaba47f8 Bluetooth: Audio: Fix MICS client deref of null pointer
The mute_val pointer could be NULL when dereferenced in the
callback. Change to be a simple value which is just assigned
instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 11:29:34 -04:00
Emil Gydesen
c42a511d39 Bluetooth: Audio: VCS update client check in API functions
Update the check if the instance is a client to be
a more simple check.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
5d4992ae25 Bluetooth: Audio: VCS client add function to get conn pointer
Add a function for the VCS client that gets the bluetooth
connection pointer if a given VCS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
946013e25f Bluetooth: Audio: VCS register return if already registered
Change how bt_vcs_register works if VCS has already been
registered.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
0043c741a5 Bluetooth: Audio: Update VCS API to use bt_vcs
Update the VCS API to use the bt_vcs struct instead
of the bt_conn. This is create a more simple API
that uses a, remote or loca, instance pointer, rather
than a specified connection (for remote) or NULL (for
local) operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
a1c7a48ee3 Bluetooth: Audio: VCS client change to use bt_vcs instead of bt_vcs_client
Change to use the generic bt_vcs struct instead of the bt_vcs_client
struct, to align better with the future API change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
65f59e73dd Bluetooth: Audio: VCS use bt_vcs struct instead of bt_vcs_server
Change the type of the vcs_inst in vcs.c to bt_vcs instead
of bt_vcs_server to align better with the future API change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
c7375079cc Bluetooth: Audio: VCS client return pointer to instance on discover
Add return of instance pointer in bt_vcs_discover so that a client
will get a bt_vcs pointer when doing discover, which will be
used going forward in the API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
db025e26a6 Bluetooth: Audio: VCS introduce opaque bt_vcs struct
Add a bt_vcs struct that represents a VCS instance,
either a local (server) or remote (client) instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:35:07 +02:00
Emil Gydesen
973e88104f Bluetooth: Audio: MICS client add function to get conn pointer
Add a function that returns the bluetooth connection
pointer of a given MICS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
12103771af Bluetooth: Audio: MICS register return if already registered
Change how bt_mics_register works if MICS has already been
registered.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00
Emil Gydesen
3c9f943fa7 Bluetooth: Audio: Update MICS API to use bt_mics
Update the MICS API to use the bt_mics struct instead
of the bt_conn. This is create a more simple API
that uses a, remote or loca, instance pointer, rather
than a specified connection (for remote) or NULL (for
local) operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-06-24 12:34:37 +02:00