diff options
-rw-r--r-- | api/direct_bt/DBTAdapter.hpp | 8 | ||||
-rw-r--r-- | api/direct_bt/DBTDevice.hpp | 29 | ||||
-rw-r--r-- | api/direct_bt/HCIComm.hpp | 7 | ||||
-rw-r--r-- | examples/direct_bt_scanner00/dbt_scanner00.cpp | 2 | ||||
-rw-r--r-- | examples/direct_bt_scanner01/dbt_scanner01.cpp | 2 | ||||
-rw-r--r-- | examples/direct_bt_scanner10/dbt_scanner10.cpp | 4 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTAdapter.cxx | 2 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTDevice.cxx | 12 | ||||
-rw-r--r-- | java/org/tinyb/BluetoothDevice.java | 3 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 31 | ||||
-rw-r--r-- | src/direct_bt/HCIComm.cpp | 9 |
11 files changed, 56 insertions, 53 deletions
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp index 18c48440..74055400 100644 --- a/api/direct_bt/DBTAdapter.hpp +++ b/api/direct_bt/DBTAdapter.hpp @@ -134,13 +134,11 @@ namespace direct_bt { friend void DBTDevice::releaseSharedInstance() const; friend std::shared_ptr<ConnectionInfo> DBTDevice::getConnectionInfo(); friend void DBTDevice::disconnect(const uint8_t reason); - friend uint16_t DBTDevice::le_connectHCI(HCIAddressType peer_mac_type, HCIAddressType own_mac_type, + friend 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 ); - friend uint16_t DBTDevice::connectHCI(const uint16_t pkt_type, const uint16_t clock_offset, const uint8_t role_switch); + uint16_t latency, uint16_t supervision_timeout); + friend uint16_t DBTDevice::connectBREDR(const uint16_t pkt_type, const uint16_t clock_offset, const uint8_t role_switch); friend std::vector<std::shared_ptr<GATTService>> DBTDevice::getGATTServices(); void addConnectedDevice(const std::shared_ptr<DBTDevice> & device); diff --git a/api/direct_bt/DBTDevice.hpp b/api/direct_bt/DBTDevice.hpp index a03a8fbb..7be4faa7 100644 --- a/api/direct_bt/DBTDevice.hpp +++ b/api/direct_bt/DBTDevice.hpp @@ -151,14 +151,15 @@ namespace direct_bt { * Default parameter values are chosen for using public address resolution * and usual connection latency, interval etc. * </p> + * <p> + * Set window to the same value as the interval, enables continuous scanning. + * </p> */ - uint16_t le_connectHCI(const HCIAddressType peer_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, - const HCIAddressType own_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, - const uint16_t interval=0x0004, const uint16_t window=0x0004, - const uint16_t min_interval=0x000F, const uint16_t max_interval=0x000F, - const uint16_t latency=0x0000, const uint16_t supervision_timeout=0x0C80, - const uint16_t min_ce_length=0x0001, const uint16_t max_ce_length=0x0001, - const uint8_t initiator_filter=0); + uint16_t connectLE(const HCIAddressType peer_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, + const HCIAddressType own_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, + const uint16_t interval=0x0004, const uint16_t window=0x0004, + const uint16_t min_interval=0x000F, const uint16_t max_interval=0x000F, + const uint16_t latency=0x0000, const uint16_t supervision_timeout=0x0C80); /** * Establish a HCI BDADDR_BREDR connection to this device. @@ -172,14 +173,14 @@ namespace direct_bt { * The device is tracked by the managing adapter. * </p> */ - uint16_t connectHCI(const uint16_t pkt_type=HCI_DM1 | HCI_DM3 | HCI_DM5 | HCI_DH1 | HCI_DH3 | HCI_DH5, - const uint16_t clock_offset=0x0000, const uint8_t role_switch=0x01); + uint16_t connectBREDR(const uint16_t pkt_type=HCI_DM1 | HCI_DM3 | HCI_DM5 | HCI_DH1 | HCI_DH3 | HCI_DH5, + const uint16_t clock_offset=0x0000, const uint8_t role_switch=0x01); /** * Establish a default HCI connection to this device, using certain default parameter. * <p> * Depending on this device's addressType, - * either a BDADDR_BREDR or BDADDR_LE_PUBLIC connection is attempted. + * either a BREDR (BDADDR_BREDR) or LE (BDADDR_LE_PUBLIC, BDADDR_LE_RANDOM) connection is attempted. * </p> * <p> * Returns the new connection handle or 0 if not successful. @@ -188,11 +189,11 @@ namespace direct_bt { * The device is tracked by the managing adapter. * </p> */ - uint16_t connectHCIDefault(); + uint16_t connectDefault(); /** Return the HCI connection handle to the LE or BREDR peer, 0 if not connected. */ - uint16_t getHCIConnectionHandle() const { return hciConnHandle; } + uint16_t getConnectionHandle() const { return hciConnHandle; } /** * Disconnect the LE or BREDR peer's GATT and HCI connection. @@ -222,8 +223,8 @@ namespace direct_bt { /** * Returns a newly established GATT connection or an already open GATT connection. * <p> - * The HCI le_connect or HCI connect shall be performed first, - * to produce best performance. See {@link #connectHCIDefault()}. + * The HCI connectLE(..) or connectBREDR(..) shall be performed first, + * to produce best performance. See {@link #connectDefault()}. * </p> * <p> * The returned GATTHandler is managed by this device instance diff --git a/api/direct_bt/HCIComm.hpp b/api/direct_bt/HCIComm.hpp index 13510b2f..c9474565 100644 --- a/api/direct_bt/HCIComm.hpp +++ b/api/direct_bt/HCIComm.hpp @@ -127,15 +127,16 @@ namespace direct_bt { * Even if not utilizing a HCI channel, it has been observed that maintaining such * enhanced performance on subsequent communication, i.e. GATT over L2CAP. * </p> + * <p> + * Set window to the same value as the interval, enables continuous scanning. + * </p> */ uint16_t le_create_conn(const EUI48 &peer_bdaddr, const HCIAddressType peer_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, const HCIAddressType own_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, const uint16_t interval=0x0004, const uint16_t window=0x0004, const uint16_t min_interval=0x000F, const uint16_t max_interval=0x000F, - const uint16_t latency=0x0000, const uint16_t supervision_timeout=0x0C80, - const uint16_t min_ce_length=0x0001, const uint16_t max_ce_length=0x0001, - const uint8_t initiator_filter=0); + const uint16_t latency=0x0000, const uint16_t supervision_timeout=0x0C80); /** * Establish a connection to the given BREDR (non LE). diff --git a/examples/direct_bt_scanner00/dbt_scanner00.cpp b/examples/direct_bt_scanner00/dbt_scanner00.cpp index db6337a1..1773097d 100644 --- a/examples/direct_bt_scanner00/dbt_scanner00.cpp +++ b/examples/direct_bt_scanner00/dbt_scanner00.cpp @@ -223,7 +223,7 @@ int main(int argc, char *argv[]) // (Without: Overall communication takes ~twice as long!!!) // if( doHCI_Connect ) { - if( 0 == device->connectHCIDefault() ) { + if( 0 == device->connectDefault() ) { fprintf(stderr, "Connect: Failed %s\n", device->toString().c_str()); } else { fprintf(stderr, "Connect: Success\n"); diff --git a/examples/direct_bt_scanner01/dbt_scanner01.cpp b/examples/direct_bt_scanner01/dbt_scanner01.cpp index da59468e..993a17ae 100644 --- a/examples/direct_bt_scanner01/dbt_scanner01.cpp +++ b/examples/direct_bt_scanner01/dbt_scanner01.cpp @@ -221,7 +221,7 @@ int main(int argc, char *argv[]) // (Without: Overall communication takes ~twice as long!!!) // if( doHCI_Connect ) { - if( 0 == device->connectHCIDefault() ) { + if( 0 == device->connectDefault() ) { fprintf(stderr, "Connect: Failed %s\n", device->toString().c_str()); } else { fprintf(stderr, "Connect: Success\n"); diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp index 14bc4853..940cda3a 100644 --- a/examples/direct_bt_scanner10/dbt_scanner10.cpp +++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp @@ -246,10 +246,10 @@ static void deviceConnectTask(std::shared_ptr<DBTDevice> device) { device->getAdapter().stopDiscovery(); bool res = false; if( !USE_WHITELIST ) { - res = device->connectHCIDefault(); + res = device->connectDefault(); } fprintf(stderr, "****** Device Connector: End result %d of %s\n", res, device->toString().c_str()); - if( !USE_WHITELIST && !BLOCK_DISCOVERY ) { + if( !USE_WHITELIST && ( !BLOCK_DISCOVERY || !res ) ) { device->getAdapter().startDiscovery(false); } } diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx index cdca300d..73cf8534 100644 --- a/java/jni/direct_bt/DBTAdapter.cxx +++ b/java/jni/direct_bt/DBTAdapter.cxx @@ -586,7 +586,7 @@ jobject Java_direct_1bt_tinyb_DBTAdapter_connectDevice(JNIEnv *env, jobject obj, std::shared_ptr<JavaAnonObj> jDeviceRef = device->getJavaObject(); JavaGlobalObj::check(jDeviceRef, E_FILE_LINE); - device->connectHCIDefault(); + device->connectDefault(); return JavaGlobalObj::GetObject(jDeviceRef); } } catch(...) { diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx index 073b1ee0..6968581e 100644 --- a/java/jni/direct_bt/DBTDevice.cxx +++ b/java/jni/direct_bt/DBTDevice.cxx @@ -291,7 +291,7 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_connectImpl(JNIEnv *env, jobject obj) try { DBTDevice *device = getInstance<DBTDevice>(env, obj); JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE); - uint16_t hciHandle = device->connectHCIDefault(); + uint16_t hciHandle = device->connectDefault(); if( 0 == hciHandle ) { return JNI_FALSE; } @@ -326,15 +326,15 @@ jboolean Java_direct_1bt_tinyb_DBTDevice_connectImpl(JNIEnv *env, jobject obj, uint16_t hciHandle; switch( device->addressType ) { case BDAddressType::BDADDR_LE_PUBLIC: - hciHandle = device->le_connectHCI(HCIAddressType::HCIADDR_LE_PUBLIC, HCIAddressType::HCIADDR_LE_PUBLIC, - interval, window, min_interval, max_interval, latency, timeout); + hciHandle = device->connectLE(HCIAddressType::HCIADDR_LE_PUBLIC, HCIAddressType::HCIADDR_LE_PUBLIC, + interval, window, min_interval, max_interval, latency, timeout); break; case BDAddressType::BDADDR_LE_RANDOM: - hciHandle = device->le_connectHCI(HCIAddressType::HCIADDR_LE_RANDOM, HCIAddressType::HCIADDR_LE_PUBLIC, - interval, window, min_interval, max_interval, latency, timeout); + hciHandle = device->connectLE(HCIAddressType::HCIADDR_LE_RANDOM, HCIAddressType::HCIADDR_LE_PUBLIC, + interval, window, min_interval, max_interval, latency, timeout); break; default: - hciHandle = device->connectHCIDefault(); + hciHandle = device->connectDefault(); break; } if( 0 == hciHandle ) { diff --git a/java/org/tinyb/BluetoothDevice.java b/java/org/tinyb/BluetoothDevice.java index 30710fb4..b2b4aab7 100644 --- a/java/org/tinyb/BluetoothDevice.java +++ b/java/org/tinyb/BluetoothDevice.java @@ -84,6 +84,9 @@ public interface BluetoothDevice extends BluetoothObject * The given LE connection parameter will be used instead of the Bluetooth implementation defaults, * if this device is of type {@link BluetoothAddressType#BDADDR_LE_PUBLIC} or {@link BluetoothAddressType#BDADDR_LE_RANDOM}. * </p> + * <p> + * Set window to the same value as the interval, enables continuous scanning. + * </p> * * @param interval default value 0x0004 * @param window default value 0x0004 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<ConnectionInfo> 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<std::recursive_mutex> lock(adapter.mtx_hci); // RAII-style acquire and relinquish via destructor std::shared_ptr<HCIComm> 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<DBTDevice> sharedInstance = getSharedInstance(); @@ -297,7 +294,7 @@ uint16_t DBTDevice::connectHCI(const uint16_t pkt_type, const uint16_t clock_off const std::lock_guard<std::recursive_mutex> lock(adapter.mtx_hci); // RAII-style acquire and relinquish via destructor std::shared_ptr<HCIComm> 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<std::recursive_mutex> 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); |