From 3021035aa42a8d8075615e5159e9ebd2d70b58ae Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 25 May 2020 21:34:38 +0200 Subject: DBTDevice/HCIComm: More 'snappy' connect method names and drop unused LE min/max ce_len,filter params Show device on connection failure. --- src/direct_bt/DBTDevice.cpp | 31 ++++++++++++++----------------- src/direct_bt/HCIComm.cpp | 9 ++++++--- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index 5fa9adfd..5e289bde 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -237,15 +237,13 @@ std::shared_ptr DBTDevice::getConnectionInfo() { return connInfo; } -uint16_t DBTDevice::le_connectHCI(HCIAddressType peer_mac_type, HCIAddressType own_mac_type, +uint16_t DBTDevice::connectLE(HCIAddressType peer_mac_type, HCIAddressType own_mac_type, uint16_t interval, uint16_t window, uint16_t min_interval, uint16_t max_interval, - uint16_t latency, uint16_t supervision_timeout, - uint16_t min_ce_length, uint16_t max_ce_length, - uint8_t initiator_filter ) + uint16_t latency, uint16_t supervision_timeout) { if( 0 < hciConnHandle ) { - ERR_PRINT("DBTDevice::le_connect: Already connected"); + ERR_PRINT("DBTDevice::le_connect: Already connected: %s", toString().c_str()); return 0; } @@ -256,7 +254,7 @@ uint16_t DBTDevice::le_connectHCI(HCIAddressType peer_mac_type, HCIAddressType o const std::lock_guard lock(adapter.mtx_hci); // RAII-style acquire and relinquish via destructor std::shared_ptr hciComm = adapter.getHCI(); if( nullptr == hciComm || !hciComm->isOpen() ) { - ERR_PRINT("DBTDevice::le_connect: Adapter's HCIComm not opened"); + ERR_PRINT("DBTDevice::le_connect: Adapter's HCIComm not opened: %s", toString().c_str()); return 0; } if( !isLEAddressType() ) { @@ -272,11 +270,10 @@ uint16_t DBTDevice::le_connectHCI(HCIAddressType peer_mac_type, HCIAddressType o hciConnHandle = hciComm->le_create_conn( address, peer_mac_type, own_mac_type, - interval, window, min_interval, max_interval, latency, supervision_timeout, - min_ce_length, max_ce_length, initiator_filter); + interval, window, min_interval, max_interval, latency, supervision_timeout); if ( 0 == hciConnHandle ) { - ERR_PRINT("DBTDevice::le_connect: Could not create connection"); + ERR_PRINT("DBTDevice::le_connect: Could not create connection: %s", toString().c_str()); return 0; } adapter.addConnectedDevice(sharedInstance); @@ -284,10 +281,10 @@ uint16_t DBTDevice::le_connectHCI(HCIAddressType peer_mac_type, HCIAddressType o return hciConnHandle; } -uint16_t DBTDevice::connectHCI(const uint16_t pkt_type, const uint16_t clock_offset, const uint8_t role_switch) +uint16_t DBTDevice::connectBREDR(const uint16_t pkt_type, const uint16_t clock_offset, const uint8_t role_switch) { if( 0 < hciConnHandle ) { - ERR_PRINT("DBTDevice::connect: Already connected"); + ERR_PRINT("DBTDevice::connect: Already connected: %s", toString().c_str()); return 0; } std::shared_ptr sharedInstance = getSharedInstance(); @@ -297,7 +294,7 @@ uint16_t DBTDevice::connectHCI(const uint16_t pkt_type, const uint16_t clock_off const std::lock_guard lock(adapter.mtx_hci); // RAII-style acquire and relinquish via destructor std::shared_ptr hciComm = adapter.getHCI(); if( nullptr == hciComm || !hciComm->isOpen() ) { - ERR_PRINT("DBTDevice::le_connect: Adapter's HCIComm not opened"); + ERR_PRINT("DBTDevice::le_connect: Adapter's HCIComm not opened: %s", toString().c_str()); return 0; } if( !isBREDRAddressType() ) { @@ -314,7 +311,7 @@ uint16_t DBTDevice::connectHCI(const uint16_t pkt_type, const uint16_t clock_off hciConnHandle = hciComm->create_conn(address, pkt_type, clock_offset, role_switch); if ( 0 == hciConnHandle ) { - ERR_PRINT("DBTDevice::connect: Could not create connection (yet)"); + ERR_PRINT("DBTDevice::connect: Could not create connection: %s", toString().c_str()); return 0; } adapter.addConnectedDevice(sharedInstance); @@ -322,15 +319,15 @@ uint16_t DBTDevice::connectHCI(const uint16_t pkt_type, const uint16_t clock_off return hciConnHandle; } -uint16_t DBTDevice::connectHCIDefault() +uint16_t DBTDevice::connectDefault() { switch( addressType ) { case BDAddressType::BDADDR_LE_PUBLIC: - return le_connectHCI(HCIAddressType::HCIADDR_LE_PUBLIC); + return connectLE(HCIAddressType::HCIADDR_LE_PUBLIC); case BDAddressType::BDADDR_LE_RANDOM: - return le_connectHCI(HCIAddressType::HCIADDR_LE_RANDOM); + return connectLE(HCIAddressType::HCIADDR_LE_RANDOM); case BDAddressType::BDADDR_BREDR: - return connectHCI(); + return connectBREDR(); default: ERR_PRINT("DBTDevice::defaultConnect: Not a valid address type: %s", toString().c_str()); return 0; diff --git a/src/direct_bt/HCIComm.cpp b/src/direct_bt/HCIComm.cpp index 1a89d853..3344830f 100644 --- a/src/direct_bt/HCIComm.cpp +++ b/src/direct_bt/HCIComm.cpp @@ -594,9 +594,7 @@ uint16_t HCIComm::le_create_conn(const EUI48 &peer_bdaddr, const HCIAddressType own_mac_type, const uint16_t interval, const uint16_t window, const uint16_t min_interval, const uint16_t max_interval, - const uint16_t latency, const uint16_t supervision_timeout, - const uint16_t min_ce_length, const uint16_t max_ce_length, - const uint8_t initiator_filter) + const uint16_t latency, const uint16_t supervision_timeout) { const std::lock_guard lock(mtx); // RAII-style acquire and relinquish via destructor if( 0 > _dd ) { @@ -606,6 +604,11 @@ uint16_t HCIComm::le_create_conn(const EUI48 &peer_bdaddr, hci_cp_le_create_conn cp; hci_ev_le_conn_complete rp; + const uint16_t min_ce_length = 0x0000; // 0x0001 ?? + const uint16_t max_ce_length = 0x0000; // 0x0001 ?? + const uint8_t initiator_filter = 0x00; + + bzero((void*)&cp, sizeof(cp)); cp.scan_interval = cpu_to_le(interval); cp.scan_window = cpu_to_le(window); -- cgit v1.2.3