Skip to content

Commit d53d59e

Browse files
committed
bond clean up
1 parent eb8b206 commit d53d59e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

libraries/Bluefruit52Lib/src/BLEGap.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool BLEGap::requestPairing(uint16_t conn_hdl)
181181

182182
xSemaphoreTake(peer->pair_sem, portMAX_DELAY);
183183

184-
// Failed to pair using central stored keys, this happens when
184+
// Failed to pair using central stored keys, this happens when
185185
// Prph delete bonds while we did not --> let's remove the obsolete keyfile and move on
186186
if ( !peer->paired && (cntr_ediv != 0xffff) )
187187
{
@@ -383,9 +383,12 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
383383
// Occurs if bonded + reconnection, or we initiate the pairing process
384384
if ( !( conn_sec->sec_mode.sm == 1 && conn_sec->sec_mode.lv == 1) )
385385
{
386-
// Previously bonded --> secure by re-connection process --> Load & Set Sys Attr (Apply Service Context)
387-
// Else Init Sys Attr
388-
bond_load_cccd(peer->role, conn_hdl, peer->ediv);
386+
// Previously bonded --> secure by re-connection process --> Load & Set SysAttr (Apply Service Context)
387+
// Else Init SysAttr (first bonded)
388+
if ( !bond_load_cccd(peer->role, conn_hdl, peer->ediv) )
389+
{
390+
sd_ble_gatts_sys_attr_set(conn_hdl, NULL, 0, 0);
391+
}
389392

390393
peer->paired = true;
391394
}

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ bool bond_save_cccd (uint8_t role, uint16_t conn_hdl, uint16_t ediv)
196196
return true;
197197
}
198198

199-
bool bond_load_cccd(uint8_t role, uint16_t cond_hdl, uint16_t ediv)
199+
bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, uint16_t ediv)
200200
{
201201
bool loaded = false;
202202

@@ -219,7 +219,7 @@ bool bond_load_cccd(uint8_t role, uint16_t cond_hdl, uint16_t ediv)
219219

220220
file.read(sys_attr, len);
221221

222-
if ( ERROR_NONE == sd_ble_gatts_sys_attr_set(cond_hdl, sys_attr, len, SVC_CONTEXT_FLAG) )
222+
if ( ERROR_NONE == sd_ble_gatts_sys_attr_set(conn_hdl, sys_attr, len, SVC_CONTEXT_FLAG) )
223223
{
224224
loaded = true;
225225
BOND_LOG("Loaded CCCD from file %s ( offset = %d, len = %d bytes )", filename, file.size() - (len + 1), len);
@@ -233,7 +233,6 @@ bool bond_load_cccd(uint8_t role, uint16_t cond_hdl, uint16_t ediv)
233233
if ( !loaded )
234234
{
235235
LOG_LV1("BOND", "CCCD setting not found");
236-
sd_ble_gatts_sys_attr_set(cond_hdl, NULL, 0, 0);
237236
}
238237

239238
return loaded;

0 commit comments

Comments
 (0)