Skip to content

Commit 8a22399

Browse files
committed
bluetooth: host: Add compatibility functions for conn interval with SCI
Since Shorter Connection Intervals changes the unit that connection intervals can be represented in. It is therefore necessary to change how they are stored and represented. Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
1 parent d343311 commit 8a22399

File tree

11 files changed

+96
-25
lines changed

11 files changed

+96
-25
lines changed

include/zephyr/bluetooth/conn.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,35 @@ enum bt_conn_auth_keypress {
12731273
BT_CONN_AUTH_KEYPRESS_ENTRY_COMPLETED = 0x04,
12741274
};
12751275

1276+
/** @brief Get the connection interval in microseconds
1277+
*
1278+
* @param conn_info pointer to a @ref bt_conn_info object
1279+
* @return The connection interval in microseconds
1280+
*/
1281+
static inline uint32_t bt_conn_le_get_interval_us(const struct bt_conn_info *conn_info)
1282+
{
1283+
#if defined(CONFIG_BT_SHORTER_CONNECTION_INTERVALS)
1284+
return conn_info->le.interval_us;
1285+
#else
1286+
return conn_info->le.interval * 1250;
1287+
#endif /* CONFIG_BT_SHORTER_CONNECTION_INTERVALS */
1288+
}
1289+
1290+
/** @brief Set the connection interval in units of 1250 microseconds
1291+
*
1292+
* @param conn_info pointer to a @ref bt_conn_info object
1293+
* @param interval Connection interval in units of 1250 microseconds
1294+
*/
1295+
static inline void bt_conn_le_set_interval_1250_us_units(struct bt_conn_info *conn_info,
1296+
uint16_t interval)
1297+
{
1298+
#if defined(CONFIG_BT_SHORTER_CONNECTION_INTERVALS)
1299+
conn_info->le.interval_us = interval * 1250;
1300+
#else
1301+
conn_info->le.interval = interval;
1302+
#endif /* CONFIG_BT_SHORTER_CONNECTION_INTERVALS */
1303+
}
1304+
12761305
/** @brief Get connection info
12771306
*
12781307
* @param conn Connection object.

subsys/bluetooth/audio/ascs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static void state_transition_work_handler(struct k_work *work)
533533
err = bt_conn_get_info(ase->conn, &info);
534534
__ASSERT_NO_MSG(err == 0);
535535

536-
retry_delay_ms = BT_CONN_INTERVAL_TO_MS(info.le.interval);
536+
retry_delay_ms = bt_conn_le_get_interval_us(&info) / 1000;
537537

538538
/* Reschedule the state transition */
539539
err = k_work_reschedule(d_work, K_MSEC(retry_delay_ms));

subsys/bluetooth/audio/bap_broadcast_assistant.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,12 @@ static void long_bap_read(struct bt_conn *conn, uint16_t handle)
453453
if (err != 0) {
454454
LOG_DBG("Failed to get conn info, use default interval");
455455

456-
conn_info.le.interval = BT_GAP_INIT_CONN_INT_MIN;
456+
bt_conn_le_set_interval_1250_us_units(&conn_info, BT_GAP_INIT_CONN_INT_MIN);
457457
}
458458

459459
/* Wait a connection interval to retry */
460460
err = k_work_reschedule(&inst->bap_read_work,
461-
K_USEC(BT_CONN_INTERVAL_TO_US(conn_info.le.interval)));
461+
K_USEC(bt_conn_le_get_interval_us(&conn_info)));
462462
if (err < 0) {
463463
LOG_DBG("Failed to reschedule read work: %d", err);
464464
bap_long_read_reset(inst);

subsys/bluetooth/audio/bap_scan_delegator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void receive_state_notify_cb(struct bt_conn *conn, void *data)
240240

241241
LOG_DBG("Could not notify receive state: %d", err);
242242
err = k_work_reschedule(&internal_state->notify_work,
243-
K_USEC(BT_CONN_INTERVAL_TO_US(conn_info.le.interval)));
243+
K_USEC(bt_conn_le_get_interval_us(&conn_info)));
244244
__ASSERT(err >= 0, "Failed to reschedule work: %d", err);
245245
}
246246
}

subsys/bluetooth/audio/bap_unicast_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,12 +1767,12 @@ static void long_ase_read(struct bt_bap_unicast_client_ep *client_ep)
17671767
if (err != 0) {
17681768
LOG_DBG("Failed to get conn info, use default interval");
17691769

1770-
conn_info.le.interval = BT_GAP_INIT_CONN_INT_MIN;
1770+
bt_conn_le_set_interval_1250_us_units(&conn_info, BT_GAP_INIT_CONN_INT_MIN);
17711771
}
17721772

17731773
/* Wait a connection interval to retry */
17741774
err = k_work_reschedule(&client_ep->ase_read_work,
1775-
K_USEC(BT_CONN_INTERVAL_TO_US(conn_info.le.interval)));
1775+
K_USEC(bt_conn_le_get_interval_us(&conn_info)));
17761776
if (err < 0) {
17771777
LOG_DBG("Failed to reschedule ASE long read work: %d", err);
17781778
}

subsys/bluetooth/audio/tbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ static void notify_handler_cb(struct bt_conn *conn, void *data)
10051005
LOG_DBG("Notify failed (%d), retrying next connection interval", err);
10061006
reschedule:
10071007
err = k_work_reschedule(&inst->notify_work,
1008-
K_USEC(BT_CONN_INTERVAL_TO_US(info.le.interval)));
1008+
K_USEC(bt_conn_le_get_interval_us(&info)));
10091009
__ASSERT(err >= 0, "Failed to reschedule work: %d", err);
10101010
}
10111011

subsys/bluetooth/host/att.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,9 @@ static k_timeout_t credit_based_connection_delay(struct bt_conn *conn)
35383538
* result in an overflow
35393539
*/
35403540
const uint32_t calculated_delay_us =
3541-
2 * (conn->le.latency + 1) * BT_CONN_INTERVAL_TO_US(conn->le.interval);
3541+
2 * (conn->le.latency + 1) *
3542+
BT_CONN_INTERVAL_TO_US(
3543+
bt_conn_internal_le_get_interval_1250_us_units(conn));
35423544
const uint32_t calculated_delay_ms = calculated_delay_us / USEC_PER_MSEC;
35433545

35443546
return K_MSEC(MAX(100, calculated_delay_ms + rand_delay));

subsys/bluetooth/host/conn.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,26 +1965,26 @@ void bt_conn_notify_le_param_updated(struct bt_conn *conn)
19651965
* parameters don't send peripheral conn param request anymore on timeout
19661966
*/
19671967
if (atomic_test_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_SET) &&
1968-
conn->le.interval >= conn->le.interval_min &&
1969-
conn->le.interval <= conn->le.interval_max &&
1968+
bt_conn_internal_le_get_interval_1250_us_units(conn) >= conn->le.interval_min &&
1969+
bt_conn_internal_le_get_interval_1250_us_units(conn) <= conn->le.interval_max &&
19701970
conn->le.latency == conn->le.pending_latency &&
19711971
conn->le.timeout == conn->le.pending_timeout) {
19721972
atomic_clear_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_SET);
19731973
}
19741974

1975-
19761975
BT_CONN_CB_DYNAMIC_FOREACH(callback) {
19771976
if (callback->le_param_updated) {
1978-
callback->le_param_updated(conn, conn->le.interval,
1979-
conn->le.latency, conn->le.timeout);
1977+
callback->le_param_updated(
1978+
conn, bt_conn_internal_le_get_interval_1250_us_units(conn),
1979+
conn->le.latency, conn->le.timeout);
19801980
}
19811981
}
19821982

19831983
STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
19841984
if (cb->le_param_updated) {
1985-
cb->le_param_updated(conn, conn->le.interval,
1986-
conn->le.latency,
1987-
conn->le.timeout);
1985+
cb->le_param_updated(conn,
1986+
bt_conn_internal_le_get_interval_1250_us_units(conn),
1987+
conn->le.latency, conn->le.timeout);
19881988
}
19891989
}
19901990
}

subsys/bluetooth/host/conn_internal.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ struct bt_conn_le {
108108
bt_addr_le_t init_addr;
109109
bt_addr_le_t resp_addr;
110110

111+
#if defined(CONFIG_BT_SHORTER_CONNECTION_INTERVALS)
112+
uint32_t interval_us;
113+
#else
111114
uint16_t interval;
115+
#endif /* CONFIG_BT_SHORTER_CONNECTION_INTERVALS */
112116
uint16_t interval_min;
113117
uint16_t interval_max;
114118

@@ -396,6 +400,35 @@ static inline bool bt_conn_is_sco(const struct bt_conn *conn)
396400
#define bt_conn_is_sco(conn) (false)
397401
#endif
398402

403+
/** @brief Set the connection interval in units of 1250 microseconds
404+
*
405+
* @param conn pointer to a connection object
406+
* @param interval Connection interval in units of 1250 microseconds
407+
*/
408+
static inline void bt_conn_internal_le_set_interval_1250_us_units(struct bt_conn *conn,
409+
uint16_t interval)
410+
{
411+
#if defined(CONFIG_BT_SHORTER_CONNECTION_INTERVALS)
412+
conn->le.interval_us = interval * 1250;
413+
#else
414+
conn->le.interval = interval;
415+
#endif /* CONFIG_BT_SHORTER_CONNECTION_INTERVALS */
416+
}
417+
418+
/** @brief Get the connection interval in units of 1250 microseconds
419+
*
420+
* @param conn pointer to a connection object
421+
* @return The connection interval in units of 1250 microseconds
422+
*/
423+
static inline uint16_t bt_conn_internal_le_get_interval_1250_us_units(struct bt_conn *conn)
424+
{
425+
#if defined(CONFIG_BT_SHORTER_CONNECTION_INTERVALS)
426+
return (uint16_t)(conn->le.interval_us / 1250);
427+
#else
428+
return conn->le.interval;
429+
#endif /* CONFIG_BT_SHORTER_CONNECTION_INTERVALS */
430+
}
431+
399432
void bt_conn_tx_notify(struct bt_conn *conn, bool wait_for_completion);
400433

401434
void bt_conn_reset_rx_state(struct bt_conn *conn);

subsys/bluetooth/host/hci_core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ static void update_conn(struct bt_conn *conn, const bt_addr_le_t *id_addr,
14091409
{
14101410
conn->handle = sys_le16_to_cpu(evt->handle);
14111411
bt_addr_le_copy(&conn->le.dst, id_addr);
1412-
conn->le.interval = sys_le16_to_cpu(evt->interval);
1412+
bt_conn_internal_le_set_interval_1250_us_units(conn, sys_le16_to_cpu(evt->interval));
14131413
conn->le.latency = sys_le16_to_cpu(evt->latency);
14141414
conn->le.timeout = sys_le16_to_cpu(evt->supv_timeout);
14151415
conn->role = evt->role;
@@ -2061,15 +2061,17 @@ static void le_conn_update_complete(struct net_buf *buf)
20612061
bt_l2cap_update_conn_param(conn, &param);
20622062
} else {
20632063
if (!evt->status) {
2064-
conn->le.interval = sys_le16_to_cpu(evt->interval);
2064+
bt_conn_internal_le_set_interval_1250_us_units(
2065+
conn, sys_le16_to_cpu(evt->interval));
20652066
conn->le.latency = sys_le16_to_cpu(evt->latency);
20662067
conn->le.timeout = sys_le16_to_cpu(evt->supv_timeout);
20672068

20682069
if (!IS_ENABLED(CONFIG_BT_CONN_PARAM_ANY)) {
2069-
if (!IN_RANGE(conn->le.interval, BT_HCI_LE_INTERVAL_MIN,
2070-
BT_HCI_LE_INTERVAL_MAX)) {
2070+
if (!IN_RANGE(bt_conn_internal_le_get_interval_1250_us_units(conn),
2071+
BT_HCI_LE_INTERVAL_MIN, BT_HCI_LE_INTERVAL_MAX)) {
20712072
LOG_WRN("interval exceeds the valid range 0x%04x",
2072-
conn->le.interval);
2073+
bt_conn_internal_le_get_interval_1250_us_units(
2074+
conn));
20732075
}
20742076
if (conn->le.latency > BT_HCI_LE_PERIPHERAL_LATENCY_MAX) {
20752077
LOG_WRN("latency exceeds the valid range 0x%04x",

0 commit comments

Comments
 (0)