@@ -56,9 +56,9 @@ BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* e
56
56
_wrcmd_sem = xSemaphoreCreateCounting (wrcmd_qsize, wrcmd_qsize);
57
57
58
58
_secured = false ;
59
+ _bonded = false ;
59
60
_hvc_sem = NULL ;
60
61
_hvc_received = false ;
61
- _pair_sem = NULL ;
62
62
63
63
_ediv = 0xFFFF ;
64
64
}
@@ -70,7 +70,6 @@ BLEConnection::~BLEConnection()
70
70
71
71
// ------------- on-the-fly data must be freed -------------//
72
72
if (_hvc_sem ) vSemaphoreDelete (_hvc_sem );
73
- if (_pair_sem ) vSemaphoreDelete (_pair_sem);
74
73
}
75
74
76
75
uint16_t BLEConnection::handle (void )
@@ -270,44 +269,7 @@ bool BLEConnection::requestPairing(void)
270
269
// skip if already paired
271
270
if ( _secured ) return true ;
272
271
273
- BLEPairing* secure = &Bluefruit.Pairing ;
274
-
275
- // on-the-fly semaphore
276
- _pair_sem = xSemaphoreCreateBinary ();
277
- VERIFY (_pair_sem);
278
-
279
- // bond_keys_t ltkey;
280
- //
281
- // if ( loadBondKey(<key) ) // central only
282
- // {
283
- // // We already bonded with this peer previously
284
- // // Encrypt the connection using stored Longterm Key
285
- // if ( secure->_encrypt(_conn_hdl, <key) )
286
- // {
287
- // xSemaphoreTake(_pair_sem, portMAX_DELAY);
288
- //
289
- // // Failed to pair using stored key, this happens when peer
290
- // // delete bonds while we did not --> let's remove the obsolete keyfile and retry
291
- // if ( !_paired )
292
- // {
293
- // bond_remove_key(_role, <key.peer_id.id_addr_info);
294
- //
295
- // // Re-try with a fresh session
296
- // secure->_authenticate(_conn_hdl);
297
- // xSemaphoreTake(_pair_sem, portMAX_DELAY);
298
- // }
299
- // }
300
- // }else
301
- {
302
- // start a fresh new authentication process
303
- secure->_authenticate (_conn_hdl);
304
- xSemaphoreTake (_pair_sem, portMAX_DELAY);
305
- }
306
-
307
- vSemaphoreDelete (_pair_sem);
308
- _pair_sem = NULL ;
309
-
310
- return _secured;
272
+ return Bluefruit.Pairing ._authenticate (_conn_hdl);
311
273
}
312
274
313
275
bool BLEConnection::waitForIndicateConfirm (void )
@@ -335,9 +297,7 @@ void BLEConnection::_eventHandler(ble_evt_t* evt)
335
297
336
298
case BLE_GAP_EVT_CONN_SEC_UPDATE:
337
299
{
338
- // Connection is secured, we have paired/bonded
339
300
const ble_gap_conn_sec_t * conn_sec = &evt->evt .gap_evt .params .conn_sec_update .conn_sec ;
340
- LOG_LV2 (" PAIR" , " Security Mode = %d, Level = %d" , conn_sec->sec_mode .sm , conn_sec->sec_mode .lv );
341
301
342
302
// Connection is secured (paired) if encryption level > 1
343
303
if ( !( conn_sec->sec_mode .sm == 1 && conn_sec->sec_mode .lv == 1 ) )
@@ -347,8 +307,6 @@ void BLEConnection::_eventHandler(ble_evt_t* evt)
347
307
// Try to restore CCCD with bonded peer, if it doesn't exist (newly bonded), initialize it
348
308
if ( !loadCccd () ) sd_ble_gatts_sys_attr_set (_conn_hdl, NULL , 0 , 0 );
349
309
}
350
-
351
- if (_pair_sem) xSemaphoreGive (_pair_sem);
352
310
}
353
311
break ;
354
312
0 commit comments