Skip to content

Commit

Permalink
Revert "Bluetooth: Host: Fix GATT server handling of CCC"
Browse files Browse the repository at this point in the history
This reverts commit cfd368f.

Signed-off-by: Théo Battrel <[email protected]>
  • Loading branch information
theob-pro authored and carlescufi committed Sep 28, 2023
1 parent 888a8c6 commit c2b99c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
5 changes: 0 additions & 5 deletions include/zephyr/bluetooth/gatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,11 +736,6 @@ struct bt_gatt_ccc_cfg {
uint8_t id;
/** Remote peer address. */
bt_addr_le_t peer;
/**
* Separate storage for encrypted and unencrypted context. This
* indicate that the link was encrypted when the CCC was written.
*/
bool link_encrypted;
/** Configuration value. */
uint16_t value;
};
Expand Down
43 changes: 7 additions & 36 deletions subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,6 @@ static void clear_ccc_cfg(struct bt_gatt_ccc_cfg *cfg)
bt_addr_le_copy(&cfg->peer, BT_ADDR_LE_ANY);
cfg->id = 0U;
cfg->value = 0U;
cfg->link_encrypted = false;
}

static void gatt_store_ccc_cf(uint8_t id, const bt_addr_le_t *peer_addr);
Expand Down Expand Up @@ -2050,42 +2049,15 @@ struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr)
return next;
}

static bool bt_gatt_ccc_cfg_is_matching_conn(const struct bt_conn *conn,
const struct bt_gatt_ccc_cfg *cfg)
{
bool conn_encrypted = bt_conn_get_security(conn) >= BT_SECURITY_L2;

if (cfg->link_encrypted && !conn_encrypted) {
return false;
}

return bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer);
}

static struct bt_conn *bt_gatt_ccc_cfg_conn_lookup(const struct bt_gatt_ccc_cfg *cfg)
{
struct bt_conn *conn;

conn = bt_conn_lookup_addr_le(cfg->id, &cfg->peer);
if (conn) {
if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) {
return conn;
}

bt_conn_unref(conn);
}

return NULL;
}

static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn,
struct _bt_gatt_ccc *ccc)
{
for (size_t i = 0; i < ARRAY_SIZE(ccc->cfg); i++) {
struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i];

if (conn) {
if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) {
if (bt_conn_is_peer_addr_le(conn, cfg->id,
&cfg->peer)) {
return cfg;
}
} else if (bt_addr_le_eq(&cfg->peer, BT_ADDR_LE_ANY)) {
Expand Down Expand Up @@ -2179,7 +2151,6 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,

bt_addr_le_copy(&cfg->peer, &conn->le.dst);
cfg->id = conn->id;
cfg->link_encrypted = (bt_conn_get_security(conn) >= BT_SECURITY_L2);
}

/* Confirm write if cfg is managed by application */
Expand Down Expand Up @@ -3259,7 +3230,8 @@ static uint8_t update_ccc(const struct bt_gatt_attr *attr, uint16_t handle,
struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i];

/* Ignore configuration for different peer or not active */
if (!cfg->value || !bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) {
if (!cfg->value ||
!bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer)) {
continue;
}

Expand Down Expand Up @@ -3333,11 +3305,11 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, uint16_t handle,
continue;
}

if (!bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) {
if (!bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer)) {
struct bt_conn *tmp;

/* Skip if there is another peer connected */
tmp = bt_gatt_ccc_cfg_conn_lookup(cfg);
tmp = bt_conn_lookup_addr_le(cfg->id, &cfg->peer);
if (tmp) {
if (tmp->state == BT_CONN_CONNECTED) {
value_used = true;
Expand Down Expand Up @@ -3427,7 +3399,7 @@ bool bt_gatt_is_subscribed(struct bt_conn *conn,
for (size_t i = 0; i < BT_GATT_CCC_MAX; i++) {
const struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i];

if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg) &&
if (bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer) &&
(ccc_type & ccc->cfg[i].value)) {
return true;
}
Expand Down Expand Up @@ -5581,7 +5553,6 @@ static uint8_t ccc_load(const struct bt_gatt_attr *attr, uint16_t handle,
}
bt_addr_le_copy(&cfg->peer, load->addr_with_id.addr);
cfg->id = load->addr_with_id.id;
cfg->link_encrypted = true;
}

cfg->value = load->entry->value;
Expand Down

0 comments on commit c2b99c0

Please sign in to comment.