From 4a0c9e86f6a93e1cfb38394750eaef8bec816550 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 30 Nov 2016 14:47:17 +0200 Subject: [PATCH] Bluetooth: GATT: Update CCC addresses If connection destination address has been changed update the addresses stored by the time it disconnects since in case of RPA it is no longer mapping to the same device after it has been disconnected. Change-Id: I0ce966928f605a885125179eaa7b9093989825ab Signed-off-by: Luiz Augusto von Dentz --- subsys/bluetooth/host/gatt.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index dbf4b411738..1e376e5827d 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -688,6 +688,10 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, void *user_data) ccc->cfg[i].valid = false; memset(&ccc->cfg[i].value, 0, sizeof(ccc->cfg[i].value)); + } else { + /* Update address in case it has changed */ + bt_addr_le_copy(&ccc->cfg[i].peer, + &conn->le.dst); } } } @@ -1805,6 +1809,26 @@ static void add_subscriptions(struct bt_conn *conn) } } +static void update_subscriptions(struct bt_conn *conn) +{ + struct bt_gatt_subscribe_params *params, *prev; + + /* Update existing subscriptions */ + for (params = subscriptions, prev = NULL; params; + prev = params, params = params->_next) { + if (params->_peer.type == BT_ADDR_LE_PUBLIC) { + continue; + } + + if (bt_conn_addr_le_cmp(conn, ¶ms->_peer)) { + continue; + } + + /* Update address */ + bt_addr_le_copy(¶ms->_peer, &conn->le.dst); + } +} + #endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ void bt_gatt_connected(struct bt_conn *conn) @@ -1824,6 +1848,7 @@ void bt_gatt_disconnected(struct bt_conn *conn) #if defined(CONFIG_BLUETOOTH_GATT_CLIENT) /* If bonded don't remove subscriptions */ if (bt_addr_le_is_bonded(&conn->le.dst)) { + update_subscriptions(conn); return; }