Commit graph

162 commits

Author SHA1 Message Date
Flavio Ceolin
9fd4ea91b7 coccinelle: Remove extra semicolon
coccicheck --mode=patch --cocci=semicolon.cocci

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-25 11:35:30 -05:00
Vinayak Kariappa Chettimada
7f727ac322 Bluetooth: controller: Fix regression in ctrl tx queue handling
Fix control Tx buffer leak into data Tx pool that happens
after a cross-over control procedure response was paused due
to currently active encryption setup procedure, and a new
control Tx PDU in addition to the paused one is enqueued
thereafter.

When the control tx PDUs is resumed but not yet enqueued
towards the radio, if there is a new control Tx PDU enqueued
then the paused control Tx PDU is not set as the head of the
control PDUs in the Tx queue. This caused the paused control
Tx PDU to be associated with data Tx pool, hence causing the
incorrect release into data Tx pool.

Relates to the commit bff76b4cce ("Bluetooth: controller:
split: Fix control tx queue handling") and to the
commit 6991d09977 ("Bluetooth: controller: Fix control tx
queue handling").

Fixes #32898.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-18 11:52:23 -04:00
Wolfgang Puffitsch
010c5c2f20 Bluetooth: controller: Ignore connections from same peer
Ignore connection indications from peers that are already
connected. This is to bring the behavior of the controller in
accordance with [5.2, Vol 6, Part B, 4.5 Connection state]:
"If an advertiser receives a connection request from an initiator it
is already connected to, it shall ignore that request."

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-03-17 15:32:47 -04:00
Vinayak Kariappa Chettimada
dec6140685 Bluetooth: controller: Fix dev assert in CPR implementation
Replace a development assertion in the implementation of
Connection Parameter Request Procedure with an internal
comment and handle transaction violation be ignoring the
PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-16 10:02:05 +01:00
Vinayak Kariappa Chettimada
f9511079b2 Bluetooth: controller: Remove vendor specific internal LLL include
Remove inclusion of vendor specific internal LLL include
files in ULL source code.

Prefix `lll/` include file path to correctly include vendor
defined types and function implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-03-01 11:24:40 +01:00
Wolfgang Puffitsch
70f3e5a726 Bluetooth: controller: Add guards for feature_rsp_send
Add compilation guards for the feature_rsp_send function to avoid
compilation errors for some configurations.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-16 12:02:00 -05:00
Wolfgang Puffitsch
ef1f8c34f1 Bluetooth: controller: Add support for ISO feature bits
Add support for ISO feature bits. This includes extending fields that
hold features to 64 bits to be able to handle the host-controlled
"Isochronous Channels" feature.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Wolfgang Puffitsch
119d22a7b9 Bluetooth: controller: Refactor LLCP PDU length checks
Refactor LLCP PDU length checks to avoid constructing a look-up-table.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2021-02-15 17:33:46 -05:00
Vinayak Kariappa Chettimada
1af2b91c23 Bluetooth: controller: Fix Tx Buffer Overflow
Fix Tx Buffer Overflow caused by uninitialized node_tx
memory being used by ULL ISR context due to Compiler
Instructions Reordering in the use of MFIFO_ENQUEUE.

The MFIFO last index was committed before the data element
was stored in the MFIFO due to Compiler Instructions
Reordering.

This is fixed now by adding a Data Memory Barrier
instruction alongwith a compiler memory clobber.

Fixes #30378.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-02-02 14:00:57 -05:00
Vinayak Kariappa Chettimada
7712caa1a7 Bluetooth: controller: Fix peripheral conditional compilation
Fix regression in peripheral only build conditional
compilation introduced in commit 8a9bda307cc1 ("Bluetooth:
controller: Fix CPR conditional compilation").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
7295204af9 Bluetooth: controller: Fix CPR conditional compilation
Move the newly added Connection Parameter Request reject
state implementation under conditional compilation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
804419592f Bluetooth: controller: Fix incorrect reset of CPR reject state
Fix regression in adding the state for Connection Parameter
Request being rejected where in Connection Parameter Request
Procedure state machine was prematurely reset before the
reject PDU was enqueued.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
a8e25d9402 Bluetooth: controller: Fix deferred Conn Param Req offset population
Fix deferred Connection Parameter Request offset population
by introduction of explicit states waiting for the offset
calculations to complete in the ULL_LOW context.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
383e688e3f Bluetooth: controller: Fix deferred Conn Update offset population
Fix deferred Connection Update offset population by
introduction of explicit states waiting for the offset
calculation to complete in the ULL_LOW context.

Fixes #29636.

The problem was, in an encrypted connection the enqueued PDU
to be transmitted is encrypt in the prepare callback by the
hardware and swapped to a different buffer for transmission;
the deferred offset population did not reflect in the
transmitted PDU as it was filled in the cleartext buffer
while encryption completed into the encrypted buffer.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 13:35:48 -05:00
Vinayak Kariappa Chettimada
2919989ee9 Bluetooth: controller: Fix compilation error with encryption disabled
Fix compilation error with encryption support disabled in the
controller.

Fixes #31693.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-27 07:57:28 -05:00
Vinayak Kariappa Chettimada
8f537de8c4 Bluetooth: controller: Fix encryption and procedure with instant
Fix implementation to run local peripheral initiated control
procedure with instant in parallel with remote initiated
encryption procedure.

Relates to #28887.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-26 06:18:39 -05:00
Thomas Ebert Hansen
d4347339f5 Bluetooth: controller: Fix enc. setup during PHY update
If a PHY update is waiting for the instant to be reached and the master
starts the encryption procedure, store the pending PHY update procedure
and handle it simultaneously with the encryption setup.

This fix prevents the encryption setup from stalling and thereby timing
out after 40s, after which the master drops the link.

The ll_conn::llcp::encryption can not longer be unioned with the
ll_conn::llcp:phy_upd_ind as one would overwrite the other.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2021-01-26 06:18:39 -05:00
Vinayak Kariappa Chettimada
d2415fcfd0 Bluetooth: controller: Add peripheral/central conditional compilations
Add conditional compilation on peripheral and central
specific control procedure implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-26 06:18:39 -05:00
Vinayak Kariappa Chettimada
c2513eb993 Bluetooth: controller: Fix PHY update procedure cachability
Fix missing PHY update procedure cachability omitted in
commit 16dbb9a4fe ("Bluetooth: controller: split: Fix cmd
disallowed and collision disconnects").

Relates to #31473.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2021-01-25 11:49:28 +01:00
Nirosharn Amarasinghe
b2fcda8efb Bluetooth: Controller: re-factor magic constants
Defined 625 and 1250 as context specific interval common to ULL and LLL.
Checked with bluetooth sanity checks.

Fixes #23314.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2021-01-18 19:12:12 +01:00
Thomas Ebert Hansen
c3f557c12b Bluetooth: controller: User defined CPR intervals
Some proprietary protocols that reuse the Bluetooth LLCP logic requires
that the CPR interval has a valid range that differs from the Bluetooth
specification defined.

Vendor must implement the function (ull_vendor.h)
uint16_t ull_conn_interval_min_get(struct ll_conn *conn)
that returns the valid limit for the given connection.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2021-01-18 19:07:06 +01:00
Andrzej Kaczmarek
f8c8cac714 Bluetooth: controller: Use PHY_xxx symbols consistently
We have convenient PHY_1M, PHY_2M and PHY_CODED symbols defined but
they are not used too much in the code. This replaces all usages of
magic numbers and other symbols as PHY constants with those symbols.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-20 13:04:13 -05:00
Morten Priess
467fd155a8 Bluetooth: controller: Make must-expire runtime configurable
Under CONFIG_BT_TICKER_EXT configuration, the ticker interface has been
extended to support enabling/disabling must-expire scheduling. This
means that conn and slave ticker start calls can now omit must-expire
default-on configuration, relying on LLL updating the mode as needed.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-12-20 13:35:58 +01:00
Andrzej Kaczmarek
3fc74be7e7 Bluetooth: controller: Allow to simply release node allocated in LLL
If we allocate a node in LLL and it turns out that we don't need it
(e.g. allocated connection on AUX_CONNECT_REQ, but connection handshake
did not complete and we don't need it) we still need to send it to ULL
to be released. We can use existing NODE_RX_TYPE_DC_PDU_RELEASE node
type for this purpose, but we just need to make sure it's passed from
LLL to ULL properly.

Also, since this now does not only release DC PDUs, let's change its
name to a more generic one.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2020-12-17 11:36:25 +01:00
Joakim Andersson
39e14580e9 Bluetooth: controller: Validate disconnect reason in disconnect command
Validate the disconnect reason in the disconnect command, according
to the the core specification.

7.1.6 Disconnect command:
Authentication Failure error code (0x05), Other End Terminated Connec-
tion error codes (0x13 to 0x15), Unsupported Remote Feature error code
(0x1A), Pairing with Unit Key Not Supported error code (0x29) and Unac-
ceptable Connection Parameters error code (0x3B).

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-12-15 11:20:34 +01:00
Thomas Ebert Hansen
f0f25cfc32 Bluetooth: controller: Fix CUI/CPR lock during TO
Release the CUI/CPR lock if the connection owning the lock is
terminated.

This can happen if a device performing a CUI/CPR procedure gets a LSTO
before the procedeure completes or the procedure itself TO.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2020-12-10 12:58:35 +01:00
Morten Priess
392e044548 Bluetooth: controller: Fix ull_conn LSTO for must_expire
When CONFIG_BT_CTLR_CONN_META is enabled and the ticker "must_expire"
feature is used, collisions may cause incorrect decrement of the
supervision_expire counter, resulting in a too early link supervision
timeout.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-12-07 13:36:17 +01:00
Vinayak Kariappa Chettimada
e6911bc06c Bluetooth: controller: Fix Coded PHY S2 S8 coding use
Fix PHY Update control procedure to accept the preferred Tx
coding options (S2 or S8) requested even if there is no
actual PHY change happening on procedure completion.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-12-04 23:08:51 -05:00
Morten Priess
18c01ecae8 Bluetooth: controller: Make random force on lost anchor configurable
Legacy functionality in ull_conn will force scheduling of a connection
which has missed an anchor point due to lost RX. This kicks in either
for previously skipped events (latenzy_event != 0) or at random
depending on the randomness of the AA bit pattern.

This behavior is good at ensuring that a connection with errors or
aborted RX gets prioitized, and helps break locked round-robin
patterns with lost sync, but it also breaks the predictability of
the round-robin ticker scheduling.

With "must_expire" enabled, this feature also kicks in for scheduling
collisions, which may not be desirable.

This commit adds a configuration flag, BT_CTLR_CONN_RANDOM_FORCE, which
is default enabled (legacy behavior).

Signed-off-by: Morten Priess <mtpr@oticon.com>
2020-11-26 13:51:15 +01:00
Emil Gydesen
6b72bed967 Bluetooth: Controller: Add common ULL ticker stop with mark function
The same code block for marking an object with
ull_disable_mark, stopping the ticker and then unmarking
the object appeared multiple places; often with a regression
bug where instead of unmarking it in case of error, it would
be "remarked".

This commit fixes the bug, and moves the functionality to
a common function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2020-11-19 12:36:14 +01:00
Trond Einar Snekvik
86c793af3f sys: util: Replace MIN(MAX(a, b), c) with CLAMP
Replaces all existing variants of value clamping with the MIN and MAX
macros with the CLAMP macro.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-05 12:12:17 +01:00
Vinayak Kariappa Chettimada
f8889c1d87 Bluetooth: controller: Fix unused variable compiler warning
Fix unused variable compiler warning with asserts disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-29 14:31:38 +02:00
Vinayak Kariappa Chettimada
baef416d5d Bluetooth: controller: Added Periodic Sync Terminate and Sync Lost
Added implementation to perform Periodic Sync Terminate,
generation of Sync Lost on terminate and on remote device
termination of Periodic Advertising.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
732de50f67 Bluetooth: controller: Refactor out drift compensation code
Refactor out drift compensation implementation so as to
reuse it for Periodic Sync feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
2627524162 Bluetooth: controller: Refactor out clock ppm interface
Refactor out clock ppm interface so that it can be reused
for Periodic Advertising Sync feature.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-07 17:45:23 +02:00
Vinayak Kariappa Chettimada
c87c1a8890 Bluetooth: controller: Fix implicit declaration warning
Fix implicit declaration warning for peripheral_latency_cancel
by moving it to ull_slave file.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-06 13:47:18 +02:00
Vinayak Kariappa Chettimada
416d7ee32a Bluetooth: controller: Fix latency cancel on LLCP initiation
Fix controller implementation to cancel peripheral latency
when initiating new control procedures.

Fixes #28699.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 12:53:53 +02:00
Vinayak Kariappa Chettimada
b6fb074d6e Bluetooth: controller: Connection termination race condition
Add checks to abort connection radio event preparation and
start, if the connection terminates with a race condition
with new radio event being prepared or being in prepare
pipeline.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 11:47:35 +02:00
Vinayak Kariappa Chettimada
3e2dc0d706 Bluetooth: controller: Add branch prediction hints
Add branch prediction hints in critical control paths in the
code.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-10-01 11:47:35 +02:00
Vinayak Kariappa Chettimada
48a0c0c3a8 Bluetooth: controller: Fix undeclared identifier
Fix undeclared CONFIG_BT_CTLR_DATA_LENGTH_MAX when Force
MD bit automatic feature is enabled in nRF51 Series.

Fixes #28774.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-30 06:38:19 -05:00
Vinayak Kariappa Chettimada
e4fe7435d7 Bluetooth: controller: Added Force MD bit automatic feature
Added automatic runtime calculation of Forced MD bit count
based on incoming Tx buffer throughput.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
3bbe2c0a07 Bluetooth: controller: Add in-system Tx throughput measurement
Added feature to in-system measure incoming Tx throughput.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
6b1cfdda33 Bluetooth: controller: Fix premature connection event close
Fix premature connection event close due to the new Tx
buffers not being de-multiplexed and routed to connection's
Lower Link Layer context when they arrive while being
inside the connection's radio event.

Also, fix master prepare to demux and enqueue two Tx buffers
so that MD bit can be set correctly.

Relates to #27981.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
0096fca39d Bluetooth: controller: Refactor ull_conn_tx_ack function
Refactor ull_conn_tx_ack function as it no longer needs to
return the connection context back to caller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
41017478b1 Bluetooth: controller: Move tx_ull_dequeue to static functions
Move tx_ull_dequeue function to be placed alongwith other
static function definitions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-28 15:23:21 +02:00
Vinayak Kariappa Chettimada
a8ffc03f6e Bluetooth: controller: Fix REJECT_IND PDU handling
Fix for handling REJECT_IND PDU received for PHY Update,
Connection Parameter Request and Data Length Update control
procedures.

If a link layer control procedure collision occurs, example
with local initiated PHY Update Procedure, and peer sends a
REJECT_IND PDU, then the PHY Update Procedure is stalled.

Fixes #28282.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-09-21 14:52:41 +02:00
Flavio Ceolin
0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Andries Kruithof
7ecc55ac84 Bluetooth: controller: consistent HCI error messages
Return BT_HCI_ERR_INVALID_CONN_ID if an invalid handle is
given by the HCI; currently sometimes BT_HCI_ERR_CMD_DISALLOWED
is returned

Signed-off-by: Andries Kruithof <Andries.Kruithof@nordicsemi.no>
2020-08-19 12:10:33 -04:00
Vinayak Kariappa Chettimada
4bf2a0d520 Bluetooth: controller: Make coding style around ret_cb consistent
Updated implementation to have consistent initialization of
ret_cb use when passing it to ticker function calls.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-07-20 12:46:54 +02:00
Vinayak Kariappa Chettimada
1af8c136a7 Bluetooth: controller: Add explicit opcode check in unknown rsp PDU
Add explicit opcode check when handling received unknown
response PDU.

Without this, for example, an in progress Data Length Update
procedure state was reset when receiving an unknown response
to slave initiated feature request.

Fixes #26252.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2020-06-22 12:33:22 +02:00