Skip to content

Commit 6673cb1

Browse files
sjanccarlescufi
authored andcommitted
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 <[email protected]>
1 parent f7785f4 commit 6673cb1

File tree

2 files changed

+46
-4
lines changed
  • subsys/bluetooth/controller/ll_sw
  • tests/bluetooth/controller/mock_ctrl/include

2 files changed

+46
-4
lines changed

subsys/bluetooth/controller/ll_sw/ull_conn.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,30 @@ uint8_t ll_version_ind_send(uint16_t handle)
684684
}
685685

686686
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
687+
static bool ll_len_validate(uint16_t tx_octets, uint16_t tx_time)
688+
{
689+
/* validate if within HCI allowed range */
690+
if (!IN_RANGE(tx_octets, PDU_DC_PAYLOAD_SIZE_MIN,
691+
PDU_DC_PAYLOAD_SIZE_MAX)) {
692+
return false;
693+
}
694+
695+
/* validate if within HCI allowed range */
696+
if (!IN_RANGE(tx_time, PDU_DC_PAYLOAD_TIME_MIN,
697+
PDU_DC_PAYLOAD_TIME_MAX_CODED)) {
698+
return false;
699+
}
700+
701+
return true;
702+
}
703+
687704
uint32_t ll_length_req_send(uint16_t handle, uint16_t tx_octets,
688705
uint16_t tx_time)
689706
{
690707
struct ll_conn *conn;
691708

692709
if (IS_ENABLED(CONFIG_BT_CTLR_PARAM_CHECK) &&
693-
((tx_octets > LL_LENGTH_OCTETS_TX_MAX) ||
694-
(tx_time > PDU_DC_PAYLOAD_TIME_MAX_CODED))) {
710+
!ll_len_validate(tx_octets, tx_time)) {
695711
return BT_HCI_ERR_INVALID_PARAM;
696712
}
697713

@@ -778,7 +794,10 @@ void ll_length_default_get(uint16_t *max_tx_octets, uint16_t *max_tx_time)
778794

779795
uint32_t ll_length_default_set(uint16_t max_tx_octets, uint16_t max_tx_time)
780796
{
781-
/* TODO: parameter check (for BT 5.0 compliance) */
797+
if (IS_ENABLED(CONFIG_BT_CTLR_PARAM_CHECK) &&
798+
!ll_len_validate(max_tx_octets, max_tx_time)) {
799+
return BT_HCI_ERR_INVALID_PARAM;
800+
}
782801

783802
default_tx_octets = max_tx_octets;
784803
default_tx_time = max_tx_time;
@@ -8156,8 +8175,31 @@ uint8_t ull_dle_update_eff(struct ll_conn *conn)
81568175
return dle_changed;
81578176
}
81588177

8178+
static void ull_len_data_length_trim(uint16_t *tx_octets, uint16_t *tx_time)
8179+
{
8180+
#if defined(CONFIG_BT_CTLR_PHY_CODED)
8181+
uint16_t tx_time_max =
8182+
PDU_DC_MAX_US(LL_LENGTH_OCTETS_TX_MAX, PHY_CODED);
8183+
#else /* !CONFIG_BT_CTLR_PHY_CODED */
8184+
uint16_t tx_time_max =
8185+
PDU_DC_MAX_US(LL_LENGTH_OCTETS_TX_MAX, PHY_1M);
8186+
#endif /* !CONFIG_BT_CTLR_PHY_CODED */
8187+
8188+
/* trim to supported values */
8189+
if (*tx_octets > LL_LENGTH_OCTETS_TX_MAX) {
8190+
*tx_octets = LL_LENGTH_OCTETS_TX_MAX;
8191+
}
8192+
8193+
if (*tx_time > tx_time_max) {
8194+
*tx_time = tx_time_max;
8195+
}
8196+
}
8197+
81598198
void ull_dle_local_tx_update(struct ll_conn *conn, uint16_t tx_octets, uint16_t tx_time)
81608199
{
8200+
/* Trim to supported values */
8201+
ull_len_data_length_trim(&tx_octets, &tx_time);
8202+
81618203
conn->lll.dle.default_tx_octets = tx_octets;
81628204

81638205
#if defined(CONFIG_BT_CTLR_PHY)

tests/bluetooth/controller/mock_ctrl/include/kconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@
176176
#define CONFIG_BT_CTLR_SUBVERSION_NUMBER 0x5678
177177
#define CONFIG_BT_CTLR_ASSERT_HANDLER y
178178
#define CONFIG_BT_BUF_ACL_TX_COUNT 7
179-
#define CONFIG_BT_BUF_ACL_TX_SIZE 27
179+
#define CONFIG_BT_BUF_ACL_TX_SIZE 251
180180
#define CONFIG_BT_CTLR_RX_BUFFERS 7
181181
#define CONFIG_NET_BUF_USER_DATA_SIZE 8

0 commit comments

Comments
 (0)