Commit graph

9523 commits

Author SHA1 Message Date
Vinayak Kariappa Chettimada
79e3be3c63 Bluetooth: Controller: Fix extended scan rx flush for continous scan
Fix missing progression of the rx_last pointer when
appending rx buffers before flushing them towards Host.
Under continuous scanning, as the disabled_cb would only
be called when reference count reaches zero, the rx_last
pointer needs to progress when appending the rx buffers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-02-02 12:11:08 +01:00
Vinayak Kariappa Chettimada
5f4d6e34bc Bluetooth: Controller: Fix missing Periodic ULL sched incomplete report
Fix missing Periodic Advertising Report with incomplete
data status when ULL scheduled chain reception is aborted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-02-02 12:11:00 +01:00
Vinayak Kariappa Chettimada
03f74c7ec2 Bluetooth: Controller: Fix missing Periodic LLL sched incomplete report
Fix missing Periodic Advertising Report with incomplete
data status when LLL scheduled chain reception is aborted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-02-02 12:11:00 +01:00
Vinayak Kariappa Chettimada
d43435a727 Bluetooth: Controller: Fix Periodic Sync Aux context leak on -ENOMEM
Fix Controller implementation to release auxiliary context
when there is no node rx buffer available to receive
Periodic Advertising Sync AUX_CHAIN_IND PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-02-02 12:11:00 +01:00
Vinayak Kariappa Chettimada
ee8994ee42 Bluetooth: Controller: Refactor Periodic Advertising cond. compilation
Refactor Periodic Advertising conditional compilation to use
IS_ENABLED define.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-02-02 12:11:00 +01:00
Vinayak Kariappa Chettimada
1b3671005f Bluetooth: Controller: Fix to defer Periodic Report after ULL schedule
Fix Periodic Advertising Report data status when ULL
scheduling to receive auxiliary PDU fails. Defer the
dispatch of Periodic Advertising Report until ULL
scheduling status is comfirmed and assign the correct
value to aux_sched flag.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-02-02 12:11:00 +01:00
Piotr Pryga
fc208bb7eb Bluetooth: Controller: llcp: Add wait for nrf state in CTE REQ
There were no wait for free notification buffer (pdu object
used to send notifications to Host).
That may cause assertion in lp_comm_ntf function.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
dbf86b0359 Bluetooth: Controller: Add CTE REQ disable when change PHY to CODED
Accodring to BT 5.3 Core Vol 4, Part E section 7.8.85 the CTE request
procedure has to be disabled as if Host issued the HCI_LE_Connection-
CTE_Request_Enable with enable property set to 0. It means a Controller
should automaticall  disable the procedure.

There were no handling of this part of specification.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
9603e103b9 Bluetooth: Controller: llcp: Add missing CTE pause in remote PHY change
There were missing pause of CTE request in case remote PHY change
was handled. That may end in violation of BT 5.3 Core Vol 6, Part B
section 5.1.10.1 Packet transmission restrictions.
Without the change there was a possibility to transmitt CTE when
PHY is about to change to PHY CODED.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
ff45244928 Bluetooth: Controller: df: Add clarifying comment
Add comment to clarify what is a disable_cb callback purpose
and when it is set.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
c9431ee622 Bluetooth: Controller: df: Remove not needed if statement
Removes a if statement that was always true.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
d487476f4a Bluetooth: Controller: llcp: add complete evt handling in idle state
Add handling of complete event in idle state of localy innitiated
control procedures.
The transition will be used by CTE request disable if PHY changes
to CODED while the procedure is waiting in the waiting queue.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
9684dd6c48 Bluetooth: Controller: df: Fix wrong PHY type check in CTE req enable
CTE request may not be enabled when actual PHY does not support
transmission of constant tone extension. In case a connection is
asymetric, receive PHY is required to support transmission of CTE.
Receive PHY will be used by a device to get PDU with CTE.

In ll_df_set_conn_cte_req_enable was checking TX PHY type.
It should check RX PHY type.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
f79f9d155d Bluetooth: Controller: df: refactor CTE REQ set disable
Add a function that is responsible for set CTE request disabled.
It is a refactoring, to have a single place where CTE request
is_enabled and req_interval are zeroed.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Piotr Pryga
1856c6b23e Bluetooth: Controller: df: Add missing CTE request is_enabled set
There were missing set of is_enabled member of CTE request.
That allowed host to run HCI_LE_Connection_CTE_Request_Enable
command with enable parameter set to true sequently.
That violates BT 5.3 Core specification Vol 4 Part B section
7.8.8.85.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-02-02 10:53:51 +01:00
Joakim Andersson
743b0583fc Bluetooth: controller: Enable debug pins with TF-M enabled
Enable debug pins when TF-M has been enabled for the image.
This would otherwise produce an error message as the DEBUG_SETUP would
not have been defined for the non-secure image.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2022-02-01 11:31:36 +01:00
Vinayak Kariappa Chettimada
b5ab2f1353 Bluetooth: Controller: Fix missing ISO data packet receive
Fix missing ISO Data packet received by Synchronized
Receiver due to incorrect check on sink handle that did
not permit handle value of 0.

Fixed function to get ISO stream context to check for
valid ISO sync context, i.e. not being terminated.

Regression introduced in commit 7c89f1fe9f ("Bluetooth:
controller: Support for separate ISO RX data path").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-31 18:12:10 +01:00
Vinayak Kariappa Chettimada
3f37210cd6 Bluetooth: Controller: Fix parsing empty ADV_EXT_IND and ADV_SYNC_IND
Fix implementation to check for empty ADV_EXT_IND and
ADV_SYNC_IND PDUs, and not parse them incorrectly.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-31 12:13:08 +01:00
Vinayak Kariappa Chettimada
faa89c779c Bluetooth: Controller: Fix Periodic Adv Report to scan max data length
Fix implementation to limit Periodic Advertising data to a
configurable maximum length when generating HCI reports.

Bluetooth Test Specification defines Scan_Max_Data value
in IXIT. When HCI LE Periodic Advertising Report events are
generated by assembling the chain PDUs, the test cases
expect that if the data length is no more than
Scan_Max_Data, then at least once the IUT shall not
truncate the data in the advertising report.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-28 19:13:56 -05:00
Vinayak Kariappa Chettimada
93d6d1e114 Bluetooth: Controller: Minor fix isr_done context parameter passed
Remove redundant parameter pass of lll_aux to isr_done as
the auxiliary context use is always for scan context as the
parent.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-28 19:13:56 -05:00
Vinayak Kariappa Chettimada
1fe80ec62a Bluetooth: Controller: Minor refactor for consistent variable names
Minor refactor of auxiliary scanning implementation to use
consistent variable naming and assignment close to its
locality of reference.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-28 19:13:56 -05:00
Vinayak Kariappa Chettimada
3c1277b49d Bluetooth: Controller: Rename per_scan field to periodic
Rename per_scan field in scan context to periodic field to
avoid confusing with abbreviation for peripheral.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-28 19:13:56 -05:00
Vinayak Kariappa Chettimada
77e810e4b8 Bluetooth: Controller: Rename flag to sync_term to is_term
Rename the flag sync_term to is_term to be consistent with
other flags.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-28 19:13:56 -05:00
Rubin Gerritsen
4e88c91964 Bluetooth: Host: Fix address and SID in the sync established cb
When the periodic advertiser list is used,
the address and SID may not be identical to those passed in by
the application.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2022-01-28 15:42:25 +01:00
Aleksander Wasaznik
30098c881f Bluetooth: Host: Detect deadlock in bt_att_req_alloc
`gatt_req_alloc` will wait until a `req` is free (or until timeout).
`req`s are freed on the BT RX thread in calls into bt_att_recv.

When `gatt_req_alloc` called on the BT RX thread itself when there are
no free `req`s, it will block the BT RX thread and deadlock. The
deadlock lasts until timeout.

This change detects this condition and returns the failure early.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/39624 where
if `bt_gatt_write` is called from BT RX thread (as can happen if it is
called from a bluetooth callback), the BT RX thread can be blocked and
prevented from processing the request responses and unblocking itself.
This was the cause of a soft 30s deadlock until gatt_req_alloc timeouts.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-01-27 16:04:24 +01:00
Aleksander Wasaznik
8d5be19e0b Bluetooth: Host: Handle req alloc failure in bt_gatt_unsubscribe
`gatt_write_ccc` may fail if it is unable to allocate a `bt_att_req`.
This change adds handling of this case to `bt_gatt_unsubscribe`.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2022-01-27 16:04:24 +01:00
Vinayak Kariappa Chettimada
4e5290948e Bluetooth: Controller: Fix Periodic Advertising to setup Power Amp
Fix Periodic Advertising implementation to setup Power
Amplifier (PA) GPIO toggle for transmission instead of
incorrect Low Noise Amplifier (LNA) setup which is for
reception.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-27 14:02:01 +01:00
Vinayak Kariappa Chettimada
e1a3606391 Bluetooth: Controller: Define EVENT_SYNC_B2B_MAFS_US
Define EVENT_SYNC_B2B_MAFS_US to use the Kconfig option
used to configure the MAFS between Periodic Advertising
chain PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-27 14:02:01 +01:00
Vinayak Kariappa Chettimada
2d953b6b9e Bluetooth: Controller: Fix Periodic Advertising ADI feature bits
Fix Periodic Advertising ADI Support feature bits so that
it is return back in the Read Local Supported Features.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-27 14:01:54 +01:00
Vinayak Kariappa Chettimada
7bc3fdc856 Bluetooth: Controller: Fix Periodic Sync LLL scheduling flag
Fix Periodic Advertising Sync LLL scheduling flag to not be
set when chain PDUs use LLL scheduling, only set when
primary AUX_SYNC_IND PDU received use LLL scheduling.

Without the fix, spurious EVENT_DONE_EXTRA_TYPE_SYNC would
be generated when chain PDUs are failed to be received. This
can cause Sync Lost message to be generated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-27 14:01:41 +01:00
Andries Kruithof
54314322c9 Bluetooth: controller: llcp: update lll_scan_aux for new LLCP
The lll_scan_aux.c file does not compile when the new LLCP is
selected due to missing conditional compiles.
Conditional compile and proper tx_times are selected with this
commit

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2022-01-27 13:11:07 +01:00
Emil Gydesen
102dcca6a4 Bluetooth: Audio: Add BT_WARN for missing stream callbacks
If any specific stream callback is attempted
to be called but is missing, a BT_WARN log statement
is added.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-01-27 12:01:34 +02:00
Emil Gydesen
9140a8ac46 Bluetooth: shell: Add LE Audio shell commands
Adds audio.c which covers all the LE Audio shell commands.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-01-27 12:01:34 +02:00
Emil Gydesen
cf06fa85f2 Bluetooth: Audio: Add BAP broadcast sink support
Add support for the BAP broadcast sink role. This role
allows a device to sync to a broadcast ISO stream.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-01-27 12:01:34 +02:00
Emil Gydesen
ab87e0a2ba Bluetooth: Audio: Add BAP broadcast source support
Add the BAP broadcast source implementation. This role
allows a device to broadcast ISO data.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-01-27 12:01:34 +02:00
Emil Gydesen
59bafc430f Bluetooth: Audio: Add BAP unicast client support
Add the BAP unicast client implementation. This role
can discover BAP unicast server services and initiate
BAP audio streams.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-01-27 12:01:34 +02:00
Emil Gydesen
03862b3db5 Bluetooth: Audio: Add BAP unicast server support
Add the Basic Audio Profile (BAP) unicast server
functionality. This allows a device to act as the
unicast server role, which can accept unicast streams
initiated by a unicast client.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-01-27 12:01:34 +02:00
Vinayak Kariappa Chettimada
8a5f0b50eb Bluetooth: Controller: Restrict Extended Adv Report to max data length
Add implementation to limit Extended Scanned data to a
configurable maximum length when generating HCI reports.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-01-26 17:07:32 +01:00
Thomas Ebert Hansen
f10daf7c4a Bluetooth: host: Fix DB hash calculation
When hashing attributes for the UUID cases:
    BT_UUID_GATT_PRIMARY_VAL
    BT_UUID_GATT_SECONDARY_VAL
    BT_UUID_GATT_INCLUDE_VAL
    BT_UUID_GATT_CHRC_VAL
    BT_UUID_GATT_CEP_VAL

where (handle || UUID || value) is to be hashed, the worst case size of
attribute value can be deduced from the associated union that describes
all the attribute values in the given cases.

Update the data array to accommodate for the worst case size.

Fixes #39131

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2022-01-26 13:10:29 +01:00
Johann Fischer
0be729de8a bluetooth: hci_raw: avoid possible memory overflow in bt_buf_get_tx()
Function bt_buf_get_tx(), which is used to allocate buffer from
fixed-size pool, does not check size argument before copying
the data with the length size into fixed-size buffer, wich may
not be large enough.

Check immediately before copying if the tailroom of the buffer
is large enough.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-01-26 11:54:31 +01:00
Piotr Pryga
4d3985f93c Bluetooth: Controller: Enable PDU CP bit when CTE RX is enabled
The CP bit is read in DF connected mode while interpreting
LL_CTE_RSP PDU, hence it must be available in struct pdu_data
type.

There were missing two Kconfig options in new LLCP tests.
They were reponsbile for disable of CP bit instruct pdu_data.
That caused tests to fail during compilation.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
32c9a01680 Bluetooth: Controller: df: Add disable support for CTE REQ and RSP proc
Add missing implementation for disabling CTE request and resposne
control procedures.
If any of these commands is active in LLL then ULL context has
to wait before return. The wait mechanism is based on semaphore.
The semaphore is initialized in ULL context and given by code
responsible for command completion.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
7895c069c4 Bluetooth: Controller: Add missing LLCP collision resolve
When there is pending local control procedure that has instant
it should be possible to run remote control procedure without
instant because there is no collision.

There were missing code to run this case in rr_st_idle() of
refactored LLCPs.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
aa4819994e Bluetooth: Controller: Add packet TX restrictions for CTE REQ/RSP PDUs
There are packet restrictions imposed by PHY update procedure
for PDU that includes CTE (BT Core 5.3 :
- central/peripheral can't send PDU with CTE after receive or send
LLPHY_UPDATE_IND until instant if the PHY after instant is CODED
- peripheral can't send PDU including CTE after it sends LL_PHY_REQ
PDU until receive LL_PHY_UPDATE_IND, LL_UNKNOWN_RSP, LL_REJECTED_EXT_-
IND_PDU if there is a CODE PHY in TX_PHYS
- peripheral can't send PDU including CTE after it sends LL_PHY_RSP
PDU until receive LL_PHY_UPDATE_IND if there is a CODED PHY in TX_PHYS
of LL_PHY_RSP PDU or RX_PHYS of LL_PHY_REQ PDU.

The BT 5.3 Core spec defines only one PDU that may include CTE, that is
LL_CTE_RSP PDU. To avoid a situation that there is such PDU enqueued
for transmission in LLL when packet transmission restrictions should
be applied, both procedures in almost all cases will not be executed
in parallel.

Current implementation always handles remote procedurerequest first.

There are possible three scenarios:
1. Remotely requested PHY update. Locally initiated CTE REQ.
   In this case there is no problem with LL_CTE_RSP waiting in a TX
   queue in LLL. Both procedures may be executed one after another.
2. Remotely requested CTE REQ. Locally initiated PHY update.
   In this case the CTE REQ is handled first and it will pause the
   PHY update procedure until LL_CTE_RSP PDU is acknowledged by
   remote. Then the CTE REQ procedure will be completed and PHY update
   continued.
3. Locally initiated PHY update is pending. Arrives remote CTE REQ.
   In this case the CTE REQ will be paused until localy initiated PHY
   update is completed. Then the CTE REQ will be continued.

Thanks to that there should be no PDU including CTE in LLL TX quueue.
That releases us from a situation there is a LL_CTE_RSP PDU in the
LLL TX qeueue that must be changed into LL_REJECT_EXT_IND PDU due to
change of PHY to CODED PHY after PHY update procedure completes.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
bb8a2da1fe Bluetooth: Controller: llcp: Fix PHY update FSM stale after instant
In peripheral role when:
 - data length update is enabled
 - the CONFIG_BT_MAX_CONN is set to 1
the PHY update control procedure after reaching instant sends two
notifications to host. It notifies host about PHY update and data
length change. Both notifications are send one after another, so two
free node rx are required. The number of available node rx in
provided conditions is one. The PHY update FSM is stalled in waiting
state for enough empty node rx. At the same time remote device is
allowed to send new remote control procedures. Received request are
handled by PHY update FSM that asserts due to unknown procedure opcode.

The commit changes number of allocated nodes to be two times a number
of LLCP connections.

This is a workaround for the issue. The best solution seems to be
sharing nodsx between connections. Though this solution requires
buffering remote control procedures until host notification is done.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
30ebda34cf Bluetooth: Controller: radio: Fix error in pkt conf macros
Macros responsible for preparation of packet configuration flags in
regard of PHY and CTE were wrong. PHY flags are not used as regular
integer values but bits in a bitfield, hence size of the field in
packet configuration flags is three instead of two.
In such case CTE presen filed should be moved to bit 4th.

The problem was spot when testing implementation with CODED PHY
enabled. When device was sending PDUs that had attached CTE the
radio was configured to use CODED PHY due to wrong bit set in
packet configuration flags variable (overlapping of CTE bit
with CODED PHY bit).

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
29c6b6e4dc Bluetooth: host: df: Add missing bt_conn_unref
There were missing bt_conn_unref after reporting IQ samples to
an application.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
2feedecdac Bluetooth: host: df: Add handling of HCI_LE_CTE_Request_Failed
There were no handling of HCI_LE_CTE_Request_Failed event.
The commit adds missing implementation. An application will
be notified about failed request by cte_report_cb. It is the
same callback that is used for reporting collected CTE IQ
samples. The same callback was used to avoid creation new callback.
To give an application possibility to distinguish between regular
IQ samples report and request failed additional member err was added
to bf_df_conn_iq_samples_report structure.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
41ad4f6880 Bluetooth: host: df: Fix wrong arguments order
Function valid_cte_req_params was called with cte_length and
cte_type in wrong order.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00
Piotr Pryga
1f3a1448f4 Bluetooth: host: df: Fix to wrong variable passed to net_buf_add
Wrong variable was passed to net_buff_add call. In could lead to
memory overwrite.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-01-21 09:30:23 -05:00