@@ -55,7 +55,7 @@ BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* e
55
55
_hvn_sem = xSemaphoreCreateCounting (hvn_qsize, hvn_qsize);
56
56
_wrcmd_sem = xSemaphoreCreateCounting (wrcmd_qsize, wrcmd_qsize);
57
57
58
- _paired = false ;
58
+ _secured = false ;
59
59
_hvc_sem = NULL ;
60
60
_hvc_received = false ;
61
61
_pair_sem = NULL ;
@@ -85,7 +85,12 @@ bool BLEConnection::connected(void)
85
85
86
86
bool BLEConnection::paired (void )
87
87
{
88
- return _paired;
88
+ return _secured;
89
+ }
90
+
91
+ bool BLEConnection::bonded (void )
92
+ {
93
+ return _bonded;
89
94
}
90
95
91
96
uint8_t BLEConnection::getRole (void )
@@ -236,50 +241,52 @@ bool BLEConnection::saveLongTermKey(bond_keys_t const* ltkey)
236
241
{
237
242
bond_save_keys (_role, _conn_hdl, ltkey);
238
243
_bond_id_addr = ltkey->peer_id .id_addr_info ;
239
- _paired = true ; // paired with new device
244
+ _secured = true ; // paired with new device
245
+ _bonded = true ;
240
246
return true ;
241
247
}
242
248
243
249
bool BLEConnection::loadLongTermKey (bond_keys_t * ltkey)
244
250
{
245
- VERIFY ( bond_load_keys (_role, &_peer_addr, ltkey) );
251
+ _bonded = bond_load_keys (_role, &_peer_addr, ltkey);
252
+ VERIFY (_bonded);
246
253
_bond_id_addr = ltkey->peer_id .id_addr_info ;
247
254
return true ;
248
255
}
249
256
250
257
bool BLEConnection::requestPairing (void )
251
258
{
252
259
// skip if already paired
253
- if ( _paired ) return true ;
260
+ if ( _secured ) return true ;
254
261
255
262
BLEPairing* secure = &Bluefruit.Pairing ;
256
263
257
264
// on-the-fly semaphore
258
265
_pair_sem = xSemaphoreCreateBinary ();
259
266
VERIFY (_pair_sem);
260
267
261
- bond_keys_t ltkey;
262
-
263
- if ( loadLongTermKey (<key) )
264
- {
265
- // We already bonded with this peer previously
266
- // Encrypt the connection using stored Longterm Key
267
- if ( secure->_encrypt (_conn_hdl, <key) )
268
- {
269
- xSemaphoreTake (_pair_sem, portMAX_DELAY);
270
-
271
- // Failed to pair using stored key, this happens when peer
272
- // delete bonds while we did not --> let's remove the obsolete keyfile and retry
273
- if ( !_paired )
274
- {
275
- bond_remove_key (_role, <key.peer_id .id_addr_info );
276
-
277
- // Re-try with a fresh session
278
- secure->_authenticate (_conn_hdl);
279
- xSemaphoreTake (_pair_sem, portMAX_DELAY);
280
- }
281
- }
282
- }else
268
+ // bond_keys_t ltkey;
269
+ //
270
+ // if ( loadLongTermKey(<key) ) // central only
271
+ // {
272
+ // // We already bonded with this peer previously
273
+ // // Encrypt the connection using stored Longterm Key
274
+ // if ( secure->_encrypt(_conn_hdl, <key) )
275
+ // {
276
+ // xSemaphoreTake(_pair_sem, portMAX_DELAY);
277
+ //
278
+ // // Failed to pair using stored key, this happens when peer
279
+ // // delete bonds while we did not --> let's remove the obsolete keyfile and retry
280
+ // if ( !_paired )
281
+ // {
282
+ // bond_remove_key(_role, <key.peer_id.id_addr_info);
283
+ //
284
+ // // Re-try with a fresh session
285
+ // secure->_authenticate(_conn_hdl);
286
+ // xSemaphoreTake(_pair_sem, portMAX_DELAY);
287
+ // }
288
+ // }
289
+ // }else
283
290
{
284
291
// start a fresh new authentication process
285
292
secure->_authenticate (_conn_hdl);
@@ -289,7 +296,7 @@ bool BLEConnection::requestPairing(void)
289
296
vSemaphoreDelete (_pair_sem);
290
297
_pair_sem = NULL ;
291
298
292
- return _paired ;
299
+ return _secured ;
293
300
}
294
301
295
302
bool BLEConnection::waitForIndicateConfirm (void )
@@ -324,7 +331,7 @@ void BLEConnection::_eventHandler(ble_evt_t* evt)
324
331
// Connection is secured (paired) if encryption level > 1
325
332
if ( !( conn_sec->sec_mode .sm == 1 && conn_sec->sec_mode .lv == 1 ) )
326
333
{
327
- _paired = true ;
334
+ _secured = true ;
328
335
329
336
// Try to restore CCCD with bonded peer, if it doesn't exist (newly bonded), initialize it
330
337
if ( !loadCccd () ) sd_ble_gatts_sys_attr_set (_conn_hdl, NULL , 0 , 0 );
0 commit comments