This is an automated email from the ASF dual-hosted git repository. naraj pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
The following commit(s) were added to refs/heads/master by this push: new 778d2cb nimble/host: Persist CCCD values that were set before bonding 778d2cb is described below commit 778d2cb9a0a4aaf6f8adc73e04045c3f8a056a86 Author: MichaĆ Narajowski <michal.narajow...@codecoup.pl> AuthorDate: Thu Jan 31 12:56:52 2019 +0100 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 --- nimble/host/src/ble_gap.c | 8 ++++++-- nimble/host/src/ble_gatt_priv.h | 1 + nimble/host/src/ble_gatts.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 3c7d0a2..ef31da8 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -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); + } } } diff --git a/nimble/host/src/ble_gatt_priv.h b/nimble/host/src/ble_gatt_priv.h index a49e936..4a59635 100644 --- a/nimble/host/src/ble_gatt_priv.h +++ b/nimble/host/src/ble_gatt_priv.h @@ -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); diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c index f1a80ff..78980db 100644 --- a/nimble/host/src/ble_gatts.c +++ b/nimble/host/src/ble_gatts.c @@ -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: