diff --git a/include/zephyr/bluetooth/gatt.h b/include/zephyr/bluetooth/gatt.h index 4826e93e6fd..7d4ac72495b 100644 --- a/include/zephyr/bluetooth/gatt.h +++ b/include/zephyr/bluetooth/gatt.h @@ -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; }; diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index b75517c4cb6..069082ec67b 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -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); @@ -2050,34 +2049,6 @@ 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) { @@ -2085,7 +2056,8 @@ static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn, 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)) { @@ -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 */ @@ -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; } @@ -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; @@ -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; } @@ -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;