Skip to content

Commit 8df4dd0

Browse files
sean-madiganrlubos
authored andcommitted
[nrf fromtree] bluetooth: host: add frame space update support
This commit adds support for the frame space update feature to the bluetooth host. This is mainly just a wrapper around the frame space update HCI command and event. Signed-off-by: Sean Madigan <[email protected]> (cherry picked from commit 1b7b6af) Signed-off-by: Sean Madigan <[email protected]>
1 parent 6c44930 commit 8df4dd0

File tree

9 files changed

+391
-2
lines changed

9 files changed

+391
-2
lines changed

include/zephyr/bluetooth/conn.h

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,86 @@ struct bt_conn_le_read_all_remote_feat_complete {
273273
const uint8_t *features;
274274
};
275275

276+
#define BT_CONN_LE_FRAME_SPACE_TYPES_MASK_ACL_IFS \
277+
(BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_CP_MASK | \
278+
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_PC_MASK)
279+
280+
#define BT_CONN_LE_FRAME_SPACE_TYPES_MASK_ACL \
281+
(BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_CP_MASK | \
282+
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_PC_MASK | \
283+
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_MCES_MASK)
284+
285+
#define BT_CONN_LE_FRAME_SPACE_TYPES_MASK_CIS \
286+
(BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_CIS_MASK | \
287+
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_MSS_CIS_MASK)
288+
289+
/** Maximum frame space in microseconds.
290+
* As defined in Bluetooth Core Specification, Vol 4, Part E, Section 7.8.151.
291+
*/
292+
#define BT_CONN_LE_FRAME_SPACE_MAX (10000U)
293+
294+
/** Frame space update initiator. */
295+
enum bt_conn_le_frame_space_update_initiator {
296+
/** Initiated by local host */
297+
BT_CONN_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_HOST =
298+
BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_HOST,
299+
/** Initiated by local controller */
300+
BT_CONN_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_CONTROLLER =
301+
BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_CONTROLLER,
302+
/** Initiated by peer */
303+
BT_CONN_LE_FRAME_SPACE_UPDATE_INITIATOR_PEER =
304+
BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_PEER
305+
};
306+
307+
/** Frame space update params */
308+
struct bt_conn_le_frame_space_update_param {
309+
/** Phy mask of the PHYs to be updated.
310+
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_PHY_* for values.
311+
*/
312+
uint8_t phys;
313+
/** Spacing types mask of the spacing types to be updated.
314+
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_* and
315+
* BT_CONN_LE_FRAME_SPACE_TYPES_MASK_* for values.
316+
*/
317+
uint16_t spacing_types;
318+
/** Minimum frame space in microseconds.
319+
* Bluetooth Core Specification, Vol 4, Part E, Section 7.8.151
320+
* allows for a range of frame space from 0 to 10000 microseconds.
321+
* The actual supported frame space values will be dependent on
322+
* the controller's capabilities.
323+
*/
324+
uint16_t frame_space_min;
325+
/** Maximum frame space in microseconds.
326+
* Bluetooth Core Specification, Vol 4, Part E, Section 7.8.151
327+
* allows for a range of frame space from 0 to 10000 microseconds.
328+
* The actual supported frame space values will be dependent on
329+
* the controller's capabilities.
330+
*/
331+
uint16_t frame_space_max;
332+
};
333+
334+
/** Frame space updated callback params */
335+
struct bt_conn_le_frame_space_updated {
336+
/** HCI Status from LE Frame Space Update Complete event.
337+
* The remaining parameters will be invalid if status is not
338+
* @ref BT_HCI_ERR_SUCCESS.
339+
*/
340+
uint8_t status;
341+
/** Initiator of the frame space update. */
342+
enum bt_conn_le_frame_space_update_initiator initiator;
343+
/** Updated frame space in microseconds. */
344+
uint16_t frame_space;
345+
/** Phy mask of the PHYs updated.
346+
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_PHY_* for values.
347+
*/
348+
uint8_t phys;
349+
/** Spacing types mask of the spacing types updated.
350+
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_* and
351+
* BT_CONN_LE_FRAME_SPACE_TYPES_MASK_* for values.
352+
*/
353+
uint16_t spacing_types;
354+
};
355+
276356
/** Connection Type */
277357
enum __packed bt_conn_type {
278358
/** LE Connection Type */
@@ -1225,6 +1305,23 @@ int bt_conn_le_subrate_request(struct bt_conn *conn,
12251305
*/
12261306
int bt_conn_le_read_all_remote_features(struct bt_conn *conn, uint8_t pages_requested);
12271307

1308+
/** @brief Update frame space.
1309+
*
1310+
* Request a change to the frame space parameters of a connection.
1311+
* This function will trigger the frame_space_updated callback when the
1312+
* procedure is completed.
1313+
*
1314+
* @kconfig_dep{CONFIG_BT_FRAME_SPACE_UPDATE}.
1315+
*
1316+
* @param conn @ref BT_CONN_TYPE_LE connection object.
1317+
* @param params Frame Space Update parameters.
1318+
*
1319+
* @return Zero on success or (negative) error code on failure.
1320+
* @return -EINVAL @p conn is not a valid @ref BT_CONN_TYPE_LE connection.
1321+
*/
1322+
int bt_conn_le_frame_space_update(struct bt_conn *conn,
1323+
const struct bt_conn_le_frame_space_update_param *params);
1324+
12281325
/** @brief Update the connection parameters.
12291326
*
12301327
* If the local device is in the peripheral role then updating the connection
@@ -1935,6 +2032,26 @@ struct bt_conn_cb {
19352032
const struct bt_conn_le_read_all_remote_feat_complete *params);
19362033
#endif /* CONFIG_BT_LE_EXTENDED_FEAT_SET */
19372034

2035+
#if defined(CONFIG_BT_FRAME_SPACE_UPDATE)
2036+
/** @brief Frame Space Update Complete event.
2037+
*
2038+
* This callback notifies the application that the frame space of
2039+
* the connection may have changed.
2040+
* The frame space update parameters will be invalid
2041+
* if status is not @ref BT_HCI_ERR_SUCCESS.
2042+
*
2043+
* This callback can be triggered by calling @ref
2044+
* bt_conn_le_frame_space_update, by the procedure running
2045+
* autonomously in the controller or by the peer.
2046+
*
2047+
* @param conn Connection object.
2048+
* @param params New frame space update parameters.
2049+
*/
2050+
void (*frame_space_updated)(
2051+
struct bt_conn *conn,
2052+
const struct bt_conn_le_frame_space_updated *params);
2053+
#endif /* CONFIG_BT_FRAME_SPACE_UPDATE */
2054+
19382055
#if defined(CONFIG_BT_CHANNEL_SOUNDING)
19392056
/** @brief LE CS Read Remote Supported Capabilities Complete event.
19402057
*

include/zephyr/bluetooth/hci_types.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct bt_hci_cmd_hdr {
208208
#define BT_LE_FEAT_BIT_CHANNEL_SOUNDING_HOST 47
209209
#define BT_LE_FEAT_BIT_CHANNEL_SOUNDING_TONE_QUAL_IND 48
210210
#define BT_LE_FEAT_BIT_EXTENDED_FEAT_SET 63
211+
#define BT_LE_FEAT_BIT_FRAME_SPACE_UPDATE 65
211212

212213
#define BT_LE_FEAT_TEST(feat, n) (feat[(n) >> 3] & \
213214
BIT((n) & 7))
@@ -286,6 +287,8 @@ struct bt_hci_cmd_hdr {
286287
BT_LE_FEAT_BIT_CHANNEL_SOUNDING_HOST)
287288
#define BT_FEAT_LE_EXTENDED_FEAT_SET(feat) BT_LE_FEAT_TEST(feat, \
288289
BT_LE_FEAT_BIT_EXTENDED_FEAT_SET)
290+
#define BT_FEAT_LE_FRAME_SPACE_UPDATE_SET(feat) BT_LE_FEAT_TEST(feat, \
291+
BT_LE_FEAT_BIT_FRAME_SPACE_UPDATE)
289292

290293
#define BT_FEAT_LE_CIS(feat) (BT_FEAT_LE_CIS_CENTRAL(feat) | \
291294
BT_FEAT_LE_CIS_PERIPHERAL(feat))
@@ -2815,6 +2818,30 @@ struct bt_hci_cp_le_cs_remove_config {
28152818

28162819
#define BT_HCI_OP_LE_CS_TEST_END BT_OP(BT_OGF_LE, 0x0096) /* 0x2096 */
28172820

2821+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_PHY_1M_MASK BIT(0)
2822+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_PHY_2M_MASK BIT(1)
2823+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_PHY_CODED_MASK BIT(2)
2824+
2825+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_CP_MASK BIT(0)
2826+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_PC_MASK BIT(1)
2827+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_MCES_MASK BIT(2)
2828+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_CIS_MASK BIT(3)
2829+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_MSS_CIS_MASK BIT(4)
2830+
2831+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_HOST (0)
2832+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_CONTROLLER (1)
2833+
#define BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_PEER (2)
2834+
2835+
struct bt_hci_cp_le_frame_space_update {
2836+
uint16_t handle;
2837+
uint16_t frame_space_min;
2838+
uint16_t frame_space_max;
2839+
uint8_t phys;
2840+
uint16_t spacing_types;
2841+
} __packed;
2842+
2843+
#define BT_HCI_OP_LE_FRAME_SPACE_UPDATE BT_OP(BT_OGF_LE, 0x009D) /* 0x209D */
2844+
28182845
/* Event definitions */
28192846

28202847
#define BT_HCI_EVT_UNKNOWN 0x00
@@ -4004,6 +4031,16 @@ struct bt_hci_evt_le_cs_procedure_enable_complete {
40044031
uint16_t max_procedure_len;
40054032
} __packed;
40064033

4034+
#define BT_HCI_EVT_LE_FRAME_SPACE_UPDATE_COMPLETE 0x35
4035+
struct bt_hci_evt_le_frame_space_update_complete {
4036+
uint8_t status;
4037+
uint16_t handle;
4038+
uint8_t initiator;
4039+
uint16_t frame_space;
4040+
uint8_t phys;
4041+
uint16_t spacing_types;
4042+
} __packed;
4043+
40074044
/* Event mask bits */
40084045

40094046
#define BT_EVT_BIT(n) (1ULL << (n))
@@ -4105,6 +4142,8 @@ struct bt_hci_evt_le_cs_procedure_enable_complete {
41054142
#define BT_EVT_MASK_LE_CS_SUBEVENT_RESULT_CONTINUE BT_EVT_BIT(49)
41064143
#define BT_EVT_MASK_LE_CS_TEST_END_COMPLETE BT_EVT_BIT(50)
41074144

4145+
#define BT_EVT_MASK_LE_FRAME_SPACE_UPDATE_COMPLETE BT_EVT_BIT(52)
4146+
41084147
/** HCI Error Codes, BT Core Spec v5.4 [Vol 1, Part F]. */
41094148
#define BT_HCI_ERR_SUCCESS 0x00
41104149
#define BT_HCI_ERR_UNKNOWN_CMD 0x01

subsys/bluetooth/Kconfig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,18 @@ config BT_CONN_TX
115115
help
116116
Hidden configuration that is true if ACL or broadcast ISO is enabled
117117

118+
config BT_LE_LOCAL_MINIMUM_REQUIRED_FEATURE_PAGE
119+
int
120+
default 1 if BT_FRAME_SPACE_UPDATE
121+
default 0
122+
depends on BT_LE_EXTENDED_FEAT_SET
123+
help
124+
Minimum required feature page that must be supported.
125+
118126
config BT_LE_MAX_LOCAL_SUPPORTED_FEATURE_PAGE
119127
int "Maximum supported feature page"
120-
default 0
121-
range 0 10
128+
default BT_LE_LOCAL_MINIMUM_REQUIRED_FEATURE_PAGE
129+
range BT_LE_LOCAL_MINIMUM_REQUIRED_FEATURE_PAGE 10
122130
depends on BT_LE_EXTENDED_FEAT_SET
123131
help
124132
Maximum feature page that can be stored for local supported features.
@@ -212,6 +220,12 @@ config BT_SUBRATING
212220
Enable support for LE Connection Subrating feature that is defined in the
213221
Bluetooth Core specification, Version 5.4 | Vol 6, Part B, Section 4.6.35.
214222

223+
config BT_FRAME_SPACE_UPDATE
224+
bool "Frame Space Update"
225+
depends on (!HAS_BT_CTLR || BT_CTLR_FRAME_SPACE_UPDATE_SUPPORT) && BT_CONN && BT_LE_EXTENDED_FEAT_SET
226+
help
227+
Enable support for Bluetooth 6.0 Frame Space Update feature.
228+
215229
config BT_CHANNEL_SOUNDING
216230
bool "Channel Sounding [EXPERIMENTAL]"
217231
select EXPERIMENTAL

subsys/bluetooth/controller/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ config BT_CTLR_LE_PATH_LOSS_MONITORING_SUPPORT
125125
config BT_CTLR_SUBRATING_SUPPORT
126126
bool
127127

128+
config BT_CTLR_FRAME_SPACE_UPDATE_SUPPORT
129+
bool
130+
128131
config BT_CTLR_CHANNEL_SOUNDING_SUPPORT
129132
bool
130133

@@ -1170,6 +1173,14 @@ config BT_CTLR_SUBRATING
11701173
Enable support for Bluetooth v5.3 LE Connection Subrating
11711174
in the Controller.
11721175

1176+
config BT_CTLR_FRAME_SPACE_UPDATE
1177+
bool "Frame Space Update"
1178+
depends on BT_CTLR_FRAME_SPACE_UPDATE_SUPPORT
1179+
default y if BT_FRAME_SPACE_UPDATE
1180+
help
1181+
Enable support for Bluetooth 6.0 Frame Space Update
1182+
in the Controller.
1183+
11731184
config BT_CTLR_CHANNEL_SOUNDING
11741185
bool "Channel Sounding support"
11751186
depends on BT_CTLR_CHANNEL_SOUNDING_SUPPORT

subsys/bluetooth/host/conn.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,6 +3402,78 @@ int bt_conn_le_read_all_remote_features(struct bt_conn *conn, uint8_t pages_requ
34023402
}
34033403
#endif /* CONFIG_BT_LE_EXTENDED_FEAT_SET */
34043404

3405+
#if defined(CONFIG_BT_FRAME_SPACE_UPDATE)
3406+
void notify_frame_space_update_complete(struct bt_conn *conn,
3407+
struct bt_conn_le_frame_space_updated *params)
3408+
{
3409+
if (IS_ENABLED(CONFIG_BT_CONN_DYNAMIC_CALLBACKS)) {
3410+
struct bt_conn_cb *callback;
3411+
3412+
SYS_SLIST_FOR_EACH_CONTAINER(&conn_cbs, callback, _node) {
3413+
if (callback->frame_space_updated != NULL) {
3414+
callback->frame_space_updated(conn, params);
3415+
}
3416+
}
3417+
}
3418+
3419+
STRUCT_SECTION_FOREACH(bt_conn_cb, cb)
3420+
{
3421+
if (cb->frame_space_updated != NULL) {
3422+
cb->frame_space_updated(conn, params);
3423+
}
3424+
}
3425+
}
3426+
3427+
static bool frame_space_update_param_valid(const struct bt_conn_le_frame_space_update_param *param)
3428+
{
3429+
if (param->frame_space_min > BT_CONN_LE_FRAME_SPACE_MAX ||
3430+
param->frame_space_max > BT_CONN_LE_FRAME_SPACE_MAX ||
3431+
param->frame_space_min > param->frame_space_max) {
3432+
return false;
3433+
}
3434+
3435+
if (param->spacing_types == 0) {
3436+
return false;
3437+
}
3438+
3439+
if (param->phys == 0) {
3440+
return false;
3441+
}
3442+
3443+
return true;
3444+
}
3445+
3446+
int bt_conn_le_frame_space_update(struct bt_conn *conn,
3447+
const struct bt_conn_le_frame_space_update_param *param)
3448+
{
3449+
struct bt_hci_cp_le_frame_space_update *cp;
3450+
struct net_buf *buf;
3451+
3452+
if (!bt_conn_is_type(conn, BT_CONN_TYPE_LE)) {
3453+
LOG_DBG("Invalid connection type: %u for %p", conn->type, conn);
3454+
return -EINVAL;
3455+
}
3456+
3457+
if (!frame_space_update_param_valid(param)) {
3458+
return -EINVAL;
3459+
}
3460+
3461+
buf = bt_hci_cmd_alloc(K_FOREVER);
3462+
if (buf == NULL) {
3463+
return -ENOBUFS;
3464+
}
3465+
3466+
cp = net_buf_add(buf, sizeof(*cp));
3467+
cp->handle = sys_cpu_to_le16(conn->handle);
3468+
cp->frame_space_min = sys_cpu_to_le16(param->frame_space_min);
3469+
cp->frame_space_max = sys_cpu_to_le16(param->frame_space_max);
3470+
cp->spacing_types = sys_cpu_to_le16(param->spacing_types);
3471+
cp->phys = param->phys;
3472+
3473+
return bt_hci_cmd_send_sync(BT_HCI_OP_LE_FRAME_SPACE_UPDATE, buf, NULL);
3474+
}
3475+
#endif /* CONFIG_BT_FRAME_SPACE_UPDATE */
3476+
34053477
#if defined(CONFIG_BT_CHANNEL_SOUNDING)
34063478
void notify_remote_cs_capabilities(struct bt_conn *conn, uint8_t status,
34073479
struct bt_conn_le_cs_capabilities *params)

subsys/bluetooth/host/conn_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ void notify_subrate_change(struct bt_conn *conn,
517517
void notify_read_all_remote_feat_complete(struct bt_conn *conn,
518518
struct bt_conn_le_read_all_remote_feat_complete *params);
519519

520+
void notify_frame_space_update_complete(struct bt_conn *conn,
521+
struct bt_conn_le_frame_space_updated *params);
522+
520523
void notify_remote_cs_capabilities(struct bt_conn *conn,
521524
uint8_t status,
522525
struct bt_conn_le_cs_capabilities *params);

0 commit comments

Comments
 (0)