Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimble/gap: Fix storing CCC for bonded devices. #804

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5654,7 +5654,8 @@ ble_gap_passkey_event(uint16_t conn_handle,
}

void
ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
ble_gap_enc_event(uint16_t conn_handle, int status,
int security_restored, int bonded)
{
#if NIMBLE_BLE_SM
struct ble_gap_event event;
Expand All @@ -5667,12 +5668,24 @@ 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) {
if (security_restored) {
ble_gatts_bonding_restored(conn_handle);
} else {
ble_gatts_bonding_established(conn_handle);
}
if (status != 0) {
return;
}

/* If encryption succeded and encryption has been restored for bonded device,
* notify gatt server so it has chance to send notification/indication if needed.
*/
if (security_restored) {
ble_gatts_bonding_restored(conn_handle);
return;
}

/* If this is fresh pairing and bonding has been established,
* notify gatt server about that so previous subscriptions (before bonding)
* can be stored.
*/
if (bonded) {
ble_gatts_bonding_established(conn_handle);
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion nimble/host/src/ble_gap_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
struct ble_gap_upd_params *params);
void ble_gap_rx_phy_update_complete(const struct ble_hci_ev_le_subev_phy_update_complete *ev);
void ble_gap_enc_event(uint16_t conn_handle, int status,
int security_restored);
int security_restored, int bonded);
void ble_gap_passkey_event(uint16_t conn_handle,
struct ble_gap_passkey_params *passkey_params);
void ble_gap_notify_rx_event(uint16_t conn_handle, uint16_t attr_handle,
Expand Down
5 changes: 3 additions & 2 deletions nimble/host/src/ble_sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)

if (res->enc_cb) {
BLE_HS_DBG_ASSERT(proc == NULL || rm);
ble_gap_enc_event(conn_handle, res->app_status, res->restore);
ble_gap_enc_event(conn_handle, res->app_status, res->restore, res->bonded);
}

if (res->app_status == 0 &&
Expand Down Expand Up @@ -1190,6 +1190,7 @@ ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t evt_status, int encrypted)

ble_hs_unlock();

res.bonded = bonded;
ble_sm_process_result(conn_handle, &res);
}

Expand Down Expand Up @@ -2425,7 +2426,7 @@ ble_sm_timer(void)
* procedures without reconnect.
*/
while ((proc = STAILQ_FIRST(&exp_list)) != NULL) {
ble_gap_enc_event(proc->conn_handle, BLE_HS_ETIMEOUT, 0);
ble_gap_enc_event(proc->conn_handle, BLE_HS_ETIMEOUT, 0, 0);

STAILQ_REMOVE_HEAD(&exp_list, next);
ble_sm_proc_free(proc);
Expand Down
8 changes: 4 additions & 4 deletions nimble/host/src/ble_sm_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ struct ble_sm_result {
uint8_t sm_err;
struct ble_gap_passkey_params passkey_params;
void *state_arg;
unsigned execute:1;
unsigned enc_cb:1;
unsigned persist_keys:1;
unsigned restore:1;
unsigned execute : 1;
unsigned enc_cb : 1;
unsigned bonded : 1;
unsigned restore : 1;
};

#if MYNEWT_VAL(BLE_HS_DEBUG)
Expand Down