@@ -357,7 +357,7 @@ static int stop_scanning() {
357
357
is_scanning = false;
358
358
359
359
int err = bt_le_scan_stop ();
360
- if (err ) {
360
+ if (err < 0 ) {
361
361
LOG_ERR ("Stop LE scan failed (err %d)" , err );
362
362
return err ;
363
363
}
@@ -370,7 +370,7 @@ static bool split_central_eir_found(const bt_addr_le_t *addr) {
370
370
371
371
// Stop scanning so we can connect to the peripheral device.
372
372
int err = stop_scanning ();
373
- if (err ) {
373
+ if (err < 0 ) {
374
374
return false;
375
375
}
376
376
@@ -382,25 +382,13 @@ static bool split_central_eir_found(const bt_addr_le_t *addr) {
382
382
383
383
struct peripheral_slot * slot = & peripherals [slot_idx ];
384
384
385
- slot -> conn = bt_conn_lookup_addr_le (BT_ID_DEFAULT , addr );
386
- if (slot -> conn ) {
387
- LOG_DBG ("Found existing connection" );
388
- split_central_process_connection (slot -> conn );
389
- err = bt_conn_le_phy_update (slot -> conn , BT_CONN_LE_PHY_PARAM_2M );
390
- if (err ) {
391
- LOG_ERR ("Update phy conn failed (err %d)" , err );
392
- }
393
- } else {
394
- struct bt_le_conn_param * param = BT_LE_CONN_PARAM (0x0006 , 0x0006 , 30 , 400 );
395
-
396
- LOG_DBG ("Initiating new connnection" );
397
-
398
- err = bt_conn_le_create (addr , BT_CONN_LE_CREATE_CONN , param , & slot -> conn );
399
- if (err ) {
400
- LOG_ERR ("Create conn failed (err %d) (create conn? 0x%04x)" , err ,
401
- BT_HCI_OP_LE_CREATE_CONN );
402
- start_scanning ();
403
- }
385
+ LOG_DBG ("Initiating new connnection" );
386
+ struct bt_le_conn_param * param = BT_LE_CONN_PARAM (0x0006 , 0x0006 , 30 , 400 );
387
+ err = bt_conn_le_create (addr , BT_CONN_LE_CREATE_CONN , param , & slot -> conn );
388
+ if (err < 0 ) {
389
+ LOG_ERR ("Create conn failed (err %d) (create conn? 0x%04x)" , err , BT_HCI_OP_LE_CREATE_CONN );
390
+ release_peripheral_slot (slot_idx );
391
+ start_scanning ();
404
392
}
405
393
406
394
return false;
@@ -484,7 +472,7 @@ static int start_scanning(void) {
484
472
// Start scanning otherwise.
485
473
is_scanning = true;
486
474
int err = bt_le_scan_start (BT_LE_SCAN_PASSIVE , split_central_device_found );
487
- if (err ) {
475
+ if (err < 0 ) {
488
476
LOG_ERR ("Scanning failed to start (err %d)" , err );
489
477
return err ;
490
478
}
0 commit comments