nimble/host: Persist CCCD values that were set before bonding

Before:

1. Nimble is a peripheral
2. A connection is established with a peer device
3. Peer device subscribes for notifications/indications on a CCCD
4. Bonding with a peer device
5. Peer device disconnects and reconnects
6. The indication setting is not restored

After:

1. Nimble is a peripheral
2. A connection is established with a peer device
3. Peer device subscribes for notifications/indications on a CCCD
4. Bonding with a peer device
5. CCCD values are persisted
6. Peer device disconnects and reconnects
7. The indication settings are restored

Fixes issue #319
This commit is contained in:
Michał Narajowski
2019-01-31 12:56:52 +01:00
parent 2d3705b94f
commit 778d2cb9a0
3 changed files with 42 additions and 2 deletions
+6 -2
View File
@@ -4495,8 +4495,12 @@ ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
ble_gap_event_listener_call(&event);
ble_gap_call_conn_event_cb(&event, conn_handle);
if (status == 0 && security_restored) {
ble_gatts_bonding_restored(conn_handle);
if (status == 0) {
if (security_restored) {
ble_gatts_bonding_restored(conn_handle);
} else {
ble_gatts_bonding_established(conn_handle);
}
}
}
+1
View File
@@ -176,6 +176,7 @@ struct ble_gatt_resources {
int ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle);
int ble_gatts_send_next_indicate(uint16_t conn_handle);
void ble_gatts_tx_notifications(void);
void ble_gatts_bonding_established(uint16_t conn_handle);
void ble_gatts_bonding_restored(uint16_t conn_handle);
void ble_gatts_connection_broken(uint16_t conn_handle);
void ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb, void *arg);
+35
View File
@@ -1661,6 +1661,41 @@ ble_gatts_tx_notifications(void)
}
}
void
ble_gatts_bonding_established(uint16_t conn_handle)
{
struct ble_store_value_cccd cccd_value;
struct ble_gatts_clt_cfg *clt_cfg;
struct ble_gatts_conn *gatt_srv;
struct ble_hs_conn *conn;
int i;
ble_hs_lock();
conn = ble_hs_conn_find(conn_handle);
BLE_HS_DBG_ASSERT(conn != NULL);
BLE_HS_DBG_ASSERT(conn->bhc_sec_state.bonded);
cccd_value.peer_addr = conn->bhc_peer_addr;
gatt_srv = &conn->bhc_gatt_svr;
for (i = 0; i < gatt_srv->num_clt_cfgs; ++i) {
clt_cfg = (gatt_srv->clt_cfgs + i);
if (clt_cfg == NULL) {
continue;
}
if (clt_cfg->flags != 0) {
cccd_value.chr_val_handle = clt_cfg->chr_val_handle;
cccd_value.flags = clt_cfg->flags;
cccd_value.value_changed = 0;
ble_store_write_cccd(&cccd_value);
}
}
ble_hs_unlock();
}
/**
* Called when bonding has been restored via the encryption procedure. This
* function: