Skip to content

Commit 32d9b68

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: controller: Implement LE Set Host Feature Command
Added implementation of HCI LE Set Host Feature command. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent ed59ceb commit 32d9b68

File tree

7 files changed

+72
-14
lines changed

7 files changed

+72
-14
lines changed

subsys/bluetooth/controller/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ zephyr_library_sources_ifdef(
2020

2121
if(CONFIG_BT_LL_SW_SPLIT)
2222
zephyr_library_sources(
23+
ll_sw/ll_feat.c
2324
ll_sw/ull.c
2425
ll_sw/lll_common.c
2526
)
@@ -85,12 +86,11 @@ if(CONFIG_BT_LL_SW_SPLIT)
8586
)
8687
endif()
8788
endif()
88-
if(CONFIG_BT_CTLR_SET_HOST_FEATURE)
89+
if(CONFIG_BT_CTLR_DF)
8990
zephyr_library_sources(
90-
ll_sw/ll_feat.c
91+
ll_sw/ull_df.c
9192
)
9293
endif()
93-
9494
if(CONFIG_BT_CTLR_CONN_ISO)
9595
zephyr_library_sources(
9696
ll_sw/ull_conn_iso.c
@@ -110,11 +110,6 @@ if(CONFIG_BT_LL_SW_SPLIT)
110110
ll_sw/lll_chan.c
111111
)
112112
endif()
113-
if(CONFIG_BT_CTLR_DF)
114-
zephyr_library_sources(
115-
ll_sw/ull_df.c
116-
)
117-
endif()
118113
zephyr_library_sources_ifdef(
119114
CONFIG_BT_CTLR_FILTER
120115
ll_sw/ull_filter.c

subsys/bluetooth/controller/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ config BT_CTLR_ADV_ISO
483483
bool "LE Broadcast Isochronous Channel advertising" if !BT_LL_SW_SPLIT
484484
depends on BT_BROADCASTER && BT_CTLR_ADV_ISO_SUPPORT
485485
select BT_CTLR_ADV_PERIODIC
486+
select BT_CTLR_SET_HOST_FEATURE
486487
help
487488
Enable support for Bluetooth 5.2 LE Isochronous Advertising in the
488489
Controller.
@@ -494,6 +495,7 @@ config BT_CTLR_SYNC_ISO
494495
bool "LE Broadcast Isochronous Channel advertising sync" if !BT_LL_SW_SPLIT
495496
depends on BT_OBSERVER && BT_CTLR_SYNC_ISO_SUPPORT
496497
select BT_CTLR_SYNC_PERIODIC
498+
select BT_CTLR_SET_HOST_FEATURE
497499
help
498500
Enable support for Bluetooth 5.2 LE Isochronous Advertising sync in
499501
the Controller.

subsys/bluetooth/controller/include/ll.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
int ll_init(struct k_sem *sem_rx);
1313
void ll_reset(void);
1414

15+
uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value);
1516
uint64_t ll_feat_get(void);
1617

1718
uint8_t *ll_addr_get(uint8_t addr_type, uint8_t *p_bdaddr);
@@ -191,7 +192,6 @@ uint8_t ll_read_iso_link_quality(uint16_t handle,
191192
uint32_t *crc_error_packets,
192193
uint32_t *rx_unreceived_packets,
193194
uint32_t *duplicate_packets);
194-
uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value);
195195
uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id,
196196
uint8_t coding_format, uint16_t company_id,
197197
uint16_t vs_codec_id, uint32_t controller_delay,

subsys/bluetooth/controller/include/ll_feat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@
177177
/* Mask to filter away octet 0 for feature exchange */
178178
#define LL_FEAT_FILTER_OCTET0 (LL_FEAT_BIT_MASK & ~0xFFULL)
179179

180+
/* Mask for host controlled features */
181+
#define LL_FEAT_HOST_BIT_MASK 0x100000000ULL
182+
180183
/* Feature bits of this controller */
181184
#define LL_FEAT (LL_FEAT_BIT_ENC | \
182185
LL_FEAT_BIT_CONN_PARAM_REQ | \
Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,79 @@
11
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
23
* Copyright (c) 2020 Demant
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

78
#include <zephyr.h>
89

10+
#include "util/memq.h"
11+
12+
#include "hal/ccm.h"
13+
14+
#include "pdu.h"
15+
16+
#include "lll.h"
17+
#include "lll_conn.h"
18+
19+
#include "ull_conn_internal.h"
20+
921
#include "ll_feat.h"
1022

1123
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
1224
#define LOG_MODULE_NAME bt_ctlr_ll_feat
1325
#include "common/log.h"
1426
#include "hal/debug.h"
1527

28+
#if defined(CONFIG_BT_CTLR_SET_HOST_FEATURE)
29+
static uint64_t host_features;
30+
1631
uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value)
1732
{
18-
ARG_UNUSED(bit_number);
19-
ARG_UNUSED(bit_value);
33+
uint64_t feature;
34+
35+
/* Check if Bit_Number is not controlled by the Host */
36+
feature = BIT64(bit_number);
37+
if (!(feature & LL_FEAT_HOST_BIT_MASK)) {
38+
return BT_HCI_ERR_UNSUPP_FEATURE_PARAM_VAL;
39+
}
40+
41+
#if defined(CONFIG_BT_CONN)
42+
/* Check if the Controller has an established ACL */
43+
uint16_t conn_free_count = ll_conn_free_count_get();
2044

21-
return BT_HCI_ERR_CMD_DISALLOWED;
45+
/* Check if any connection contexts where allocated */
46+
if (conn_free_count != CONFIG_BT_MAX_CONN) {
47+
uint16_t handle;
48+
49+
/* Check if there are established connections */
50+
for (handle = 0U; handle < CONFIG_BT_MAX_CONN; handle++) {
51+
if (ll_connected_get(handle)) {
52+
return BT_HCI_ERR_CMD_DISALLOWED;
53+
}
54+
}
55+
}
56+
#endif /* CONFIG_BT_CONN */
57+
58+
/* Set or Clear the Host feature bit */
59+
if (bit_value) {
60+
host_features |= feature;
61+
} else {
62+
host_features &= ~feature;
63+
}
64+
65+
return BT_HCI_ERR_SUCCESS;
66+
}
67+
68+
uint64_t ll_feat_get(void)
69+
{
70+
return LL_FEAT | (host_features & LL_FEAT_HOST_BIT_MASK);
2271
}
2372

73+
#else /* !CONFIG_BT_CTLR_SET_HOST_FEATURE */
2474
uint64_t ll_feat_get(void)
2575
{
2676
return LL_FEAT;
2777
}
78+
79+
#endif /* !CONFIG_BT_CTLR_SET_HOST_FEATURE */

subsys/bluetooth/controller/ll_sw/ull_conn.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2019 Nordic Semiconductor ASA
2+
* Copyright (c) 2018-2021 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -239,6 +239,11 @@ struct ll_conn *ll_connected_get(uint16_t handle)
239239
return conn;
240240
}
241241

242+
uint16_t ll_conn_free_count_get(void)
243+
{
244+
return mem_free_count_get(conn_free);
245+
}
246+
242247
void *ll_tx_mem_acquire(void)
243248
{
244249
return mem_acquire(&mem_conn_tx.free);

subsys/bluetooth/controller/ll_sw/ull_conn_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2019 Nordic Semiconductor ASA
2+
* Copyright (c) 2017-2021 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -9,6 +9,7 @@ void ll_conn_release(struct ll_conn *conn);
99
uint16_t ll_conn_handle_get(struct ll_conn *conn);
1010
struct ll_conn *ll_conn_get(uint16_t handle);
1111
struct ll_conn *ll_connected_get(uint16_t handle);
12+
uint16_t ll_conn_free_count_get(void);
1213
void ll_tx_ack_put(uint16_t handle, struct node_tx *node_tx);
1314
int ull_conn_init(void);
1415
int ull_conn_reset(void);

0 commit comments

Comments
 (0)