Skip to content

Commit 0d61173

Browse files
[xxx] nimble/host: Restore CCCD values after reconnection
This is required so peer can read the actual CCCD values even though we don't yet send updates.
1 parent 11ed5d1 commit 0d61173

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

nimble/host/src/ble_gap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,8 @@ ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance)
21462146
ble_gap_event_listener_call(&event);
21472147
ble_gap_call_conn_event_cb(&event, evt->connection_handle);
21482148

2149+
ble_gatts_restore_cccd_vals(evt->connection_handle);
2150+
21492151
ble_gap_rd_rem_sup_feat_tx(evt->connection_handle);
21502152

21512153
return 0;

nimble/host/src/ble_gatt_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ struct ble_gatt_resources {
190190
int ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle);
191191
int ble_gatts_send_next_indicate(uint16_t conn_handle);
192192
void ble_gatts_tx_notifications(void);
193+
void ble_gatts_restore_cccd_vals(uint16_t conn_handle);
193194
void ble_gatts_bonding_established(uint16_t conn_handle);
194195
void ble_gatts_bonding_restored(uint16_t conn_handle);
195196
void ble_gatts_connection_broken(uint16_t conn_handle);

nimble/host/src/ble_gatts.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,52 @@ ble_gatts_tx_notifications(void)
17501750
}
17511751
}
17521752

1753+
void
1754+
ble_gatts_restore_cccd_vals(uint16_t conn_handle)
1755+
{
1756+
struct ble_store_value_cccd cccd_value;
1757+
struct ble_store_key_cccd cccd_key;
1758+
struct ble_gatts_clt_cfg *clt_cfg;
1759+
struct ble_hs_conn *conn;
1760+
int rc;
1761+
1762+
ble_hs_lock();
1763+
1764+
conn = ble_hs_conn_find(conn_handle);
1765+
BLE_HS_DBG_ASSERT(conn != NULL);
1766+
BLE_HS_DBG_ASSERT(conn->bhc_sec_state.bonded);
1767+
1768+
cccd_key.peer_addr = conn->bhc_peer_addr;
1769+
cccd_key.peer_addr.type =
1770+
ble_hs_misc_peer_addr_type_to_id(conn->bhc_peer_addr.type);
1771+
cccd_key.chr_val_handle = 0;
1772+
cccd_key.idx = 0;
1773+
1774+
ble_hs_unlock();
1775+
1776+
while (1) {
1777+
rc = ble_store_read_cccd(&cccd_key, &cccd_value);
1778+
if (rc != 0) {
1779+
break;
1780+
}
1781+
1782+
ble_hs_lock();
1783+
1784+
conn = ble_hs_conn_find(conn_handle);
1785+
BLE_HS_DBG_ASSERT(conn != NULL);
1786+
1787+
clt_cfg = ble_gatts_clt_cfg_find(conn->bhc_gatt_svr.clt_cfgs,
1788+
cccd_value.chr_val_handle);
1789+
if (clt_cfg != NULL) {
1790+
clt_cfg->flags = cccd_value.flags;
1791+
}
1792+
1793+
ble_hs_unlock();
1794+
1795+
cccd_key.idx++;
1796+
}
1797+
}
1798+
17531799
void
17541800
ble_gatts_bonding_established(uint16_t conn_handle)
17551801
{

0 commit comments

Comments
 (0)