Skip to content

Commit 3e9b454

Browse files
Thalleykartben
authored andcommitted
Bluetooth: PACS: Do not use conn struct directly
Instead of using the bt_conn struct directly, only access the field via the public API. This ensures that changes to the struct won't affect PACS, unless it also affects the public API. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 80f62dd commit 3e9b454

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

subsys/bluetooth/audio/pacs.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <zephyr/bluetooth/conn.h>
2626
#include <zephyr/bluetooth/gatt.h>
2727
#include <zephyr/bluetooth/uuid.h>
28-
#include <zephyr/device.h>
2928
#include <zephyr/init.h>
3029
#include <zephyr/kernel.h>
3130
#include <zephyr/logging/log.h>
@@ -38,8 +37,7 @@
3837
#include <zephyr/sys/util.h>
3938
#include <zephyr/sys/util_macro.h>
4039

41-
#include "../host/conn_internal.h"
42-
#include "../host/hci_core.h"
40+
#include "host/hci_core.h"
4341
#include "common/bt_str.h"
4442

4543
#include "audio_internal.h"
@@ -102,11 +100,11 @@ struct pacs_client {
102100
#endif /* CONFIG_BT_PAC_SRC */
103101

104102
/* Pending notification flags */
105-
ATOMIC_DEFINE(flags, PACS_FLAG_NUM);
103+
ATOMIC_DEFINE(flags, FLAG_NUM);
106104
};
107105

108106
static struct pacs {
109-
ATOMIC_DEFINE(flags, BT_ADV_NUM_FLAGS);
107+
ATOMIC_DEFINE(flags, PACS_FLAG_NUM);
110108

111109
struct pacs_client clients[CONFIG_BT_MAX_PAIRED];
112110
} pacs;
@@ -272,7 +270,7 @@ static ssize_t available_contexts_read(struct bt_conn *conn,
272270
pacs_get_available_contexts_for_conn(conn, BT_AUDIO_DIR_SOURCE)),
273271
};
274272

275-
LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
273+
LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset);
276274

277275
return bt_gatt_attr_read(conn, attr, buf, len, offset, &context,
278276
sizeof(context));
@@ -317,7 +315,7 @@ static ssize_t supported_context_read(struct bt_conn *conn,
317315
.src = sys_cpu_to_le16(supported_context_get(BT_AUDIO_DIR_SOURCE)),
318316
};
319317

320-
LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
318+
LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset);
321319

322320
return bt_gatt_attr_read(conn, attr, buf, len, offset, &context,
323321
sizeof(context));
@@ -384,7 +382,7 @@ static ssize_t snk_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
384382
ssize_t ret_val;
385383
int err;
386384

387-
LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
385+
LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset);
388386

389387
err = k_sem_take(&read_buf_sem, READ_BUF_SEM_TIMEOUT);
390388
if (err != 0) {
@@ -420,7 +418,7 @@ static ssize_t snk_loc_read(struct bt_conn *conn,
420418
{
421419
uint32_t location = sys_cpu_to_le32(pacs_snk_location);
422420

423-
LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
421+
LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset);
424422

425423
return bt_gatt_attr_read(conn, attr, buf, len, offset, &location,
426424
sizeof(location));
@@ -491,7 +489,7 @@ static ssize_t src_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
491489
ssize_t ret_val;
492490
int err;
493491

494-
LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
492+
LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset);
495493

496494
err = k_sem_take(&read_buf_sem, READ_BUF_SEM_TIMEOUT);
497495
if (err != 0) {
@@ -527,7 +525,7 @@ static ssize_t src_loc_read(struct bt_conn *conn,
527525
{
528526
uint32_t location = sys_cpu_to_le32(pacs_src_location);
529527

530-
LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
528+
LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset);
531529

532530
return bt_gatt_attr_read(conn, attr, buf, len, offset, &location,
533531
sizeof(location));
@@ -1162,15 +1160,24 @@ static void pacs_bond_deleted(uint8_t id, const bt_addr_le_t *peer)
11621160
}
11631161

11641162
static void pacs_security_changed(struct bt_conn *conn, bt_security_t level,
1165-
enum bt_security_err err)
1163+
enum bt_security_err sec_err)
11661164
{
1165+
struct bt_conn_info info;
1166+
int err;
1167+
11671168
LOG_DBG("%s changed security level to %d", bt_addr_le_str(bt_conn_get_dst(conn)), level);
11681169

1169-
if (err != 0 || conn->encrypt == 0) {
1170+
if (sec_err != BT_SECURITY_ERR_SUCCESS || level <= BT_SECURITY_L1) {
1171+
return;
1172+
}
1173+
1174+
err = bt_conn_get_info(conn, &info);
1175+
if (err < 0) {
1176+
__ASSERT_NO_MSG(false);
11701177
return;
11711178
}
11721179

1173-
if (!bt_addr_le_is_bonded(conn->id, &conn->le.dst)) {
1180+
if (!bt_addr_le_is_bonded(info.id, info.le.dst)) {
11741181
return;
11751182
}
11761183

@@ -1225,7 +1232,7 @@ static void pacs_disconnected(struct bt_conn *conn, uint8_t reason)
12251232
#endif /* CONFIG_BT_PAC_SRC */
12261233
}
12271234

1228-
static struct bt_conn_cb conn_callbacks = {
1235+
BT_CONN_CB_DEFINE(conn_callbacks) = {
12291236
.security_changed = pacs_security_changed,
12301237
.disconnected = pacs_disconnected,
12311238
};
@@ -1295,7 +1302,6 @@ int bt_pacs_cap_register(enum bt_audio_dir dir, struct bt_pacs_cap *cap)
12951302
sys_slist_append(pac, &cap->_node);
12961303

12971304
if (!callbacks_registered) {
1298-
bt_conn_cb_register(&conn_callbacks);
12991305
bt_conn_auth_info_cb_register(&auth_callbacks);
13001306

13011307
callbacks_registered = true;

0 commit comments

Comments
 (0)